From: <sh...@us...> - 2009-03-01 22:36:44
|
Revision: 14718 http://jedit.svn.sourceforge.net/jedit/?rev=14718&view=rev Author: shlomy Date: 2009-03-01 22:36:41 +0000 (Sun, 01 Mar 2009) Log Message: ----------- Added a history combo box to the Global results view dockable. Modified Paths: -------------- plugins/GlobalPlugin/trunk/browser/GlobalResultsView.java Modified: plugins/GlobalPlugin/trunk/browser/GlobalResultsView.java =================================================================== --- plugins/GlobalPlugin/trunk/browser/GlobalResultsView.java 2009-03-01 21:40:22 UTC (rev 14717) +++ plugins/GlobalPlugin/trunk/browser/GlobalResultsView.java 2009-03-01 22:36:41 UTC (rev 14718) @@ -19,6 +19,8 @@ package browser; import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -26,6 +28,8 @@ import java.io.File; import java.util.Vector; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -52,6 +56,9 @@ private GlobalTableModel model; private JTextField symbolTF; private JLabel statusLbl; + private JComboBox historyCB; + private DefaultComboBoxModel historyModel; + private Vector<HistoryItem> history; public GlobalResultsView(final View view, String param) { super(new BorderLayout()); @@ -109,9 +116,23 @@ } }); symbolPanel.add(symbolTF, BorderLayout.CENTER); - JPanel toolbar = new JPanel(); + JPanel toolbar = new JPanel(new BorderLayout(5, 0)); statusLbl = new JLabel(""); - toolbar.add(statusLbl); + toolbar.add(statusLbl, BorderLayout.EAST); + historyModel = new DefaultComboBoxModel(); + historyCB = new JComboBox(historyModel); + historyCB.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int index = historyCB.getSelectedIndex(); + if (index >= historyModel.getSize()) + return; + model.clear(); + HistoryItem item = (HistoryItem) historyModel.getElementAt(index); + for (GlobalReference ref: item.refs) + model.add(ref); + } + }); + toolbar.add(historyCB, BorderLayout.CENTER); symbolPanel.add(toolbar, BorderLayout.EAST); add(symbolPanel, BorderLayout.NORTH); } @@ -152,11 +173,18 @@ ", " + identifier + "' took " + (end - start) * .001 + " seconds."); SwingUtilities.invokeLater(new Runnable() { public void run() { - statusLbl.setText(""); + statusLbl.setText(model.getRowCount() + " results"); } }); + addToHistory(identifier); } } + private void addToHistory(String identifier) { + Vector<GlobalReference> refs = new Vector<GlobalReference>(); + for (int i = 0; i < model.getRowCount(); i++) + refs.add(model.getRef(i)); + historyModel.insertElementAt(new HistoryItem(identifier, refs), 0); + } public void show(View view, String identifier) { model.clear(); symbolTF.setText(identifier); @@ -167,4 +195,16 @@ public void focusOnDefaultComponent() { table.requestFocus(); } + + private class HistoryItem { + public HistoryItem(String identifier, Vector<GlobalReference> refs) { + this.refs = refs; + this.identifier = identifier; + } + public String toString() { + return identifier; + } + public Vector<GlobalReference> refs; + public String identifier; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |