/** Constructor. Sets up and shows the GUI */ public TextToolsSortDialog(View view, JEditTextArea textArea) { super(view, jEdit.getProperty("text-tools.sortadvanced.label"), false); this.view = view; this.textArea = textArea; // this.data = data; // this.selection = selection; view.showWaitCursor(); sortTableModel = new SortTableModel(); // preset sortTable if there is a rect selection boolean rectSel = false; int[] selRows = TextToolsSorting.getRectSelectionRows(textArea); if (selRows != null) { // we have rectangular selection: assign values to 1st row of table sortTableModel.setValueAt(new Integer(selRows[0] + 1), 0, 0); sortTableModel.setValueAt(new Integer(selRows[1] + 1), 0, 1); rectSel = true; } sortTable = new JTable(sortTableModel); TableColumnModel cMod = sortTable.getColumnModel(); sortTable.setTableHeader((new SortTableHeader(cMod))); sortTable.setRowHeight(25); sortTable.setPreferredScrollableViewportSize(new Dimension(430, 200)); JScrollPane scroll = new JScrollPane(sortTable); JPanel content = new JPanel(new BorderLayout()); content.setBorder(new EmptyBorder(5, 8, 8, 8)); content.setLayout(new BorderLayout()); setContentPane(content); content.add(scroll, BorderLayout.CENTER); JPanel buttons = new JPanel(); buttons.setBorder(new EmptyBorder(12, 0, 0, 0)); buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); buttons.add(Box.createGlue()); ok = new JButton(jEdit.getProperty("common.ok")); ok.addActionListener(this); buttons.add(ok); buttons.add(Box.createHorizontalStrut(6)); getRootPane().setDefaultButton(ok); cancel = new JButton(jEdit.getProperty("common.cancel")); cancel.addActionListener(this); buttons.add(cancel); buttons.add(Box.createHorizontalStrut(6)); clear = new JButton("Clear"); clear.addActionListener(this); buttons.add(clear); buttons.add(Box.createHorizontalStrut(6)); help = new JButton("Help"); help.addActionListener(this); buttons.add(help); buttons.add(Box.createHorizontalStrut(6)); buttons.add(Box.createGlue()); content.add(buttons, BorderLayout.SOUTH); delDupsCheckBox = new JCheckBox(jEdit.getProperty("text-tools.sortadvanced.delete-identic-lines")); onlySelectionCheckBox = new JCheckBox(jEdit.getProperty("text-tools.sortadvanced.sort-only-selection")); /* dontSortCheckBox = new JCheckBox( jEdit.getProperty("text-tools.sortadvanced.dont-sort")); delDupsCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { dontSortCheckBox.setEnabled(delDupsCheckBox.isSelected()); dontSortCheckBox.setSelected(false); } }); dontSortCheckBox.setEnabled(false); */ JPanel checkBoxes = new JPanel(); if (rectSel) checkBoxes.add(onlySelectionCheckBox); checkBoxes.add(delDupsCheckBox); // checkBoxes.add(dontSortCheckBox); not used, this is an extra action content.add(checkBoxes, BorderLayout.NORTH); view.hideWaitCursor(); pack(); GUIUtilities.loadGeometry(this, "texttools-sort-control"); setLocationRelativeTo(view); setVisible(true); } // }}}
/** run the sort */ public void ok(boolean dispose) { jsort = new JSort(delDupsCheckBox.isSelected()); Log.log(Log.DEBUG, this, " delDups is set to " + delDupsCheckBox.isSelected()); for (int i = 0; i < 10; i++) { int start = ((Integer) sortTableModel.getValueAt(i, 0)).intValue(); int end = ((Integer) sortTableModel.getValueAt(i, 1)).intValue(); if (onlySelectionCheckBox.isSelected()) { start = 0; end = 10000; // whole selection will be sorted } boolean ascending = !((Boolean) sortTableModel.getValueAt(i, 2)).booleanValue(); boolean ignoreCase = ((Boolean) sortTableModel.getValueAt(i, 3)).booleanValue(); boolean textType = ((Boolean) sortTableModel.getValueAt(i, 4)).booleanValue(); boolean trim = ((Boolean) sortTableModel.getValueAt(i, 5)).booleanValue(); boolean delDupRange = ((Boolean) sortTableModel.getValueAt(i, 6)).booleanValue(); if (end == 0 && ascending && !ignoreCase && !textType && !trim) { break; } Log.log( Log.DEBUG, this, "Sort constraint: " + start + " " + end + " " + ascending + " " + ignoreCase + " " + textType + " " + trim); jsort.addSortConstraint(start, end, ascending, ignoreCase, textType, trim, delDupRange); } if (!TextToolsSorting.sortAndInsertData(textArea, jsort, onlySelectionCheckBox.isSelected())) return; /* moved to textToolsSorting data = TextToolsPlugin.getData(textArea, onlySelectionCheckBox.isSelected()); // Macros.message(view,"data got"); if(data == null) { // an error occurred, so ditch return; } else if(data.size() == 1) { // lets not sort a single record return; } boolean selection = false; if(textArea.getSelectedLines().length > 1) { selection = true; } //display data Iterator di = data.iterator(); while(di.hasNext()) { Log.log(Log.DEBUG, BeanShell.class,"TextToolsSortDialog.231: di.next() = "+di.next()); } jsort.sort(data); Iterator iter = data.iterator(); StringBuffer sb = new StringBuffer(); while(iter.hasNext()) { sb.append(iter.next() + "\n"); } sb.deleteCharAt(sb.length() - 1); if(selection) { textArea.setSelectedText(sb.toString()); } else { textArea.setText(sb.toString()); } */ GUIUtilities.saveGeometry(this, "texttools-sort-control"); // get rid of this dialog if necessary if (dispose) dispose(); } // }}}