X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fload%2FTextFileLoader.java;h=977845ae597152002a58eeba164d25c4adf0dede;hp=b6926311a60f1f79ff0ec024c3808ca247e4370f;hb=da0b1f449260a0b4a94318006382a9039726ef3e;hpb=5625a1abadb5f2ca5f017fe7dbda1d5141cb637b diff --git a/tim/prune/load/TextFileLoader.java b/tim/prune/load/TextFileLoader.java index b692631..977845a 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) { @@ -364,7 +364,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); @@ -458,11 +467,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 +477,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