- return fileOK;
- }
-
-
- /**
- * Get the index of the best one in the list
- * @return the index of the maximum of the four given values
- */
- private static int getBestOption(int inOpt0, int inOpt1, int inOpt2, int inOpt3)
- {
- int bestIndex = -1;
- int maxScore = 1;
- if (inOpt0 > maxScore) {bestIndex = 0; maxScore = inOpt0;}
- if (inOpt1 > maxScore) {bestIndex = 1; maxScore = inOpt1;}
- if (inOpt2 > maxScore) {bestIndex = 2; maxScore = inOpt2;}
- if (inOpt3 > maxScore) {bestIndex = 3; maxScore = inOpt3;}
- return bestIndex;
- }
-
-
- /**
- * Make the components for the open options dialog
- * @return Component for all options
- */
- private Component makeDialogComponents()
- {
- JPanel wholePanel = new JPanel();
- wholePanel.setLayout(new BorderLayout());
-
- // add buttons to south
- JPanel buttonPanel = new JPanel();
- buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
- _backButton = new JButton(I18nManager.getText("button.back"));
- _backButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- _layout.previous(_cardPanel);
- _backButton.setEnabled(false);
- _nextButton.setEnabled(true);
- _finishButton.setEnabled(false);
- }
- });
- _backButton.setEnabled(false);
- buttonPanel.add(_backButton);
- _nextButton = new JButton(I18nManager.getText("button.next"));
- _nextButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- prepareSecondPanel();
- _layout.next(_cardPanel);
- _nextButton.setEnabled(false);
- _backButton.setEnabled(true);
- _finishButton.setEnabled(true);
- }
- });
- buttonPanel.add(_nextButton);
- _finishButton = new JButton(I18nManager.getText("button.finish"));
- _finishButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- finished();
- }
- });
- _finishButton.setEnabled(false);
- buttonPanel.add(_finishButton);
- JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
- cancelButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- _dialog.dispose();
- }
- });
- buttonPanel.add(cancelButton);
- wholePanel.add(buttonPanel, BorderLayout.SOUTH);
-
- // Make the two cards, for delimiter and fields
- _cardPanel = new JPanel();
- _layout = new CardLayout();
- _cardPanel.setLayout(_layout);
- JPanel firstCard = new JPanel();
- firstCard.setLayout(new BorderLayout());
-
- JPanel delimsPanel = new JPanel();
- delimsPanel.setLayout(new GridLayout(0, 2));
- delimsPanel.add(new JLabel(I18nManager.getText("dialog.delimiter.label")));
- delimsPanel.add(new JLabel("")); // blank label to go to next grid row
- // radio buttons
- _delimiterRadios = new JRadioButton[5];
- _delimiterRadios[0] = new JRadioButton(I18nManager.getText("dialog.delimiter.comma"));
- delimsPanel.add(_delimiterRadios[0]);
- _delimiterRadios[1] = new JRadioButton(I18nManager.getText("dialog.delimiter.tab"));
- delimsPanel.add(_delimiterRadios[1]);
- _delimiterRadios[2] = new JRadioButton(I18nManager.getText("dialog.delimiter.semicolon"));
- delimsPanel.add(_delimiterRadios[2]);
- _delimiterRadios[3] = new JRadioButton(I18nManager.getText("dialog.delimiter.space"));
- delimsPanel.add(_delimiterRadios[3]);
- JPanel otherPanel = new JPanel();
- otherPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
- _delimiterRadios[4] = new JRadioButton(I18nManager.getText("dialog.delimiter.other"));
- otherPanel.add(_delimiterRadios[4]);
- _otherDelimiterText = new JTextField(new OneCharDocument(), null, 2);
- otherPanel.add(_otherDelimiterText);
- // Group radio buttons
- ButtonGroup delimGroup = new ButtonGroup();
- DelimListener delimListener = new DelimListener();
- for (int i=0; i<_delimiterRadios.length; i++)
- {
- delimGroup.add(_delimiterRadios[i]);
- _delimiterRadios[i].addActionListener(delimListener);
- }
- _otherDelimiterText.getDocument().addDocumentListener(delimListener);
- delimsPanel.add(new JLabel(""));
- delimsPanel.add(otherPanel);
- _statusLabel = new JLabel("");
- delimsPanel.add(_statusLabel);
- firstCard.add(delimsPanel, BorderLayout.SOUTH);
- // load snippet to show first few lines
- _snippetBox = new JList(_fileCacher.getSnippet(SNIPPET_SIZE, MAX_SNIPPET_WIDTH));
- _snippetBox.setEnabled(false);
- firstCard.add(makeLabelledPanel("dialog.openoptions.filesnippet", _snippetBox), BorderLayout.CENTER);
-
- // Second screen, for field order selection
- JPanel secondCard = new JPanel();
- secondCard.setLayout(new BorderLayout());
- // table for file contents
- _fileExtractTableModel = new FileExtractTableModel();
- JTable extractTable = new JTable(_fileExtractTableModel);
- JScrollPane tableScrollPane = new JScrollPane(extractTable);
- extractTable.setPreferredScrollableViewportSize(new Dimension(350, 80));
- extractTable.getTableHeader().setReorderingAllowed(false);
- secondCard.add(makeLabelledPanel("dialog.openoptions.tabledesc", tableScrollPane), BorderLayout.NORTH);
- JPanel innerPanel2 = new JPanel();
- innerPanel2.setLayout(new BorderLayout());
- _fieldTable = new JTable(new FieldSelectionTableModel());
- _fieldTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- // add listener for selected table row
- _fieldTable.getSelectionModel().addListSelectionListener(
- new ListSelectionListener() {
- public void valueChanged(ListSelectionEvent e) {
- ListSelectionModel lsm = (ListSelectionModel) e.getSource();
- if (lsm.isSelectionEmpty()) {
- //no rows are selected
- selectField(-1);
- } else {
- selectField(lsm.getMinSelectionIndex());
- }
- }
- });
- JPanel tablePanel = new JPanel();
- tablePanel.setLayout(new BorderLayout());
- tablePanel.add(_fieldTable.getTableHeader(), BorderLayout.NORTH);
- tablePanel.add(_fieldTable, BorderLayout.CENTER);
- innerPanel2.add(tablePanel, BorderLayout.CENTER);
-
- JPanel innerPanel3 = new JPanel();
- innerPanel3.setLayout(new BoxLayout(innerPanel3, BoxLayout.Y_AXIS));
- _moveUpButton = new JButton(I18nManager.getText("button.moveup"));
- _moveUpButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- int currRow = _fieldTable.getSelectedRow();
- closeTableComboBox(currRow);
- _fieldTableModel.moveUp(currRow);
- _fieldTable.setRowSelectionInterval(currRow-1, currRow-1);
- }
- });
- innerPanel3.add(_moveUpButton);
- _moveDownButton = new JButton(I18nManager.getText("button.movedown"));
- _moveDownButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- int currRow = _fieldTable.getSelectedRow();
- closeTableComboBox(currRow);
- _fieldTableModel.moveDown(currRow);
- _fieldTable.setRowSelectionInterval(currRow+1, currRow+1);
- }
- });
- innerPanel3.add(_moveDownButton);
- innerPanel3.add(Box.createVerticalStrut(70));
-
- innerPanel2.add(innerPanel3, BorderLayout.EAST);
- secondCard.add(innerPanel2, BorderLayout.CENTER);
- JPanel altUnitsPanel = new JPanel();
- altUnitsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
- altUnitsPanel.add(new JLabel(I18nManager.getText("dialog.openoptions.altitudeunits")));
- String[] units = {I18nManager.getText("units.metres"), I18nManager.getText("units.feet")};
- _unitsDropDown = new JComboBox(units);
- altUnitsPanel.add(_unitsDropDown);
- secondCard.add(altUnitsPanel, BorderLayout.SOUTH);
- _cardPanel.add(firstCard, "card1");
- _cardPanel.add(secondCard, "card2");
-
- wholePanel.add(_cardPanel, BorderLayout.CENTER);
- return wholePanel;
- }
-
-
- /**
- * Close the combo box on the selected row of the field table
- * @param inRow currently selected row number
- */
- private void closeTableComboBox(int inRow)
- {
- TableCellEditor editor = _fieldTable.getCellEditor(inRow, 1);
- if (editor != null)