X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fload%2FTextFileLoader.java;h=0d7ef481056d515595cedf2ea217f5c2ff66e54e;hb=52bf9e8686c916be37a26a0b75340393d4478b05;hp=b6926311a60f1f79ff0ec024c3808ca247e4370f;hpb=5625a1abadb5f2ca5f017fe7dbda1d5141cb637b;p=GpsPrune.git diff --git a/tim/prune/load/TextFileLoader.java b/tim/prune/load/TextFileLoader.java index b692631..0d7ef48 100644 --- a/tim/prune/load/TextFileLoader.java +++ b/tim/prune/load/TextFileLoader.java @@ -99,8 +99,8 @@ public class TextFileLoader /** - * Open the selected file and show the GUI dialog - * to select load options + * Open the selected file and show the GUI dialog to select load options + * @param inFile file to open */ public void openFile(File inFile) { @@ -267,6 +267,7 @@ public class TextFileLoader _cardPanel.setLayout(_layout); JPanel firstCard = new JPanel(); firstCard.setLayout(new BorderLayout()); + firstCard.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 15)); JPanel delimsPanel = new JPanel(); delimsPanel.setLayout(new GridLayout(0, 2)); @@ -310,6 +311,7 @@ public class TextFileLoader // Second screen, for field order selection JPanel secondCard = new JPanel(); secondCard.setLayout(new BorderLayout()); + secondCard.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 15)); // table for file contents _fileExtractTableModel = new FileExtractTableModel(); JTable extractTable = new JTable(_fileExtractTableModel); @@ -319,6 +321,8 @@ public class TextFileLoader secondCard.add(makeLabelledPanel("dialog.openoptions.tabledesc", tableScrollPane), BorderLayout.NORTH); JPanel innerPanel2 = new JPanel(); innerPanel2.setLayout(new BorderLayout()); + innerPanel2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + _fieldTable = new JTable(new FieldSelectionTableModel()); _fieldTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // add listener for selected table row @@ -364,7 +368,16 @@ public class TextFileLoader } }); innerPanel3.add(_moveDownButton); - innerPanel3.add(Box.createVerticalStrut(70)); + innerPanel3.add(Box.createVerticalStrut(60)); + JButton guessButton = new JButton(I18nManager.getText("button.guessfields")); + guessButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) + { + _lastSelectedFields = null; + prepareSecondPanel(); + } + }); + innerPanel3.add(guessButton); innerPanel2.add(innerPanel3, BorderLayout.EAST); secondCard.add(innerPanel2, BorderLayout.CENTER); @@ -418,7 +431,7 @@ public class TextFileLoader { fields = _delimiterInfos[i].getMaxFields(); _statusLabel.setText("" + numRecords + " " + I18nManager.getText("dialog.openoptions.deliminfo.records") - + fields + " " + I18nManager.getText("dialog.openoptions.deliminfo.fields")); + + " " + fields + " " + I18nManager.getText("dialog.openoptions.deliminfo.fields")); } } } @@ -458,11 +471,8 @@ public class TextFileLoader FileSplitter splitter = new FileSplitter(_fileCacher); // Check info makes sense - num fields > 0, num records > 0 // set "Finished" button to disabled if not ok - // TODO: Work out if there are header rows or not, save? - // Try to match header rows with fields - // Try to match data with fields // Add data to GUI elements - Object[][] tableData = splitter.splitFieldData(info.getDelimiter()); + String[][] tableData = splitter.splitFieldData(info.getDelimiter()); // possible to ignore blank columns here _currentDelimiter = info.getDelimiter(); _fileExtractTableModel.updateData(tableData); @@ -471,9 +481,15 @@ public class TextFileLoader // Check number of fields and use last ones if count matches Field[] startFieldArray = null; if (_lastSelectedFields != null && splitter.getNumColumns() == _lastSelectedFields.length) + { startFieldArray = _lastSelectedFields; + } else - startFieldArray = splitter.makeDefaultFields(); + { + // Take first full row of file and use it to guess fields + startFieldArray = FieldGuesser.guessFields(splitter.getFirstFullRow()); + } + _fieldTableModel.updateData(startFieldArray); _fieldTable.setModel(_fieldTableModel); // add dropdowns to second column