source: trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/CSFrame.java@ 2225

Last change on this file since 2225 was 2225, checked in by daven, 23 years ago

added QueryHistory, tooltips on collectionInfoButton. Altered
CSModel to retain CollectionInfo objects and longCollectionNames
for performance. Added files for a BerryBasket - to be turned on
soon. Added sorting of the QueryHistory via the TableMap and TableSorter
files - from the Java Swing tutorial - not sure about GPL status
of these 2.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1
2/*
3 * CSFrame.java
4 * Copyright (C) 2001 New Zealand Digital Library Project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20package org.nzdl.gsdl.SimpleGraphicalClient;
21
22
23import javax.swing.JMenuItem;
24import javax.swing.JMenuBar;
25import javax.swing.JPanel;
26import javax.swing.JFrame;
27import javax.swing.JList;
28import javax.swing.JPopupMenu;
29import javax.swing.BoxLayout;
30import javax.swing.JMenu;
31import javax.swing.AbstractAction;
32import javax.swing.SwingUtilities;
33import javax.swing.KeyStroke;
34
35import java.awt.*;
36import java.awt.event.*;
37import java.util.Observer;
38import java.util.Observable;
39/**
40 * Class
41 *
42 * A class to
43 *
44 * @author Dave Nichols ([email protected])
45 * @author stuart yeates ([email protected])
46 * @version $Revision: 2225 $
47 * @see org.nzdl.gsdl.service.SimpleGraphicalClient.SimpleGraphicalClient
48 */
49
50public class CSFrame extends JFrame implements Observer, Constants
51
52{
53
54CSModel csModel;
55SearchPanel searchPanel;
56JPanel otherPanel;
57
58
59 // Constructor
60 public CSFrame(String title, CSModel newCSModel)
61 {
62 setTitle(title); // Set the window title
63
64 csModel = newCSModel;
65 Container content = getContentPane();
66
67 setJMenuBar(menuBar); // Add the menu bar to the window
68
69 JMenu fileMenu = new JMenu("File"); // Create File menu
70 JMenu editMenu = new JMenu("Edit"); // Create Edit menu
71
72 // File Menu
73
74 //fileMenu.addSeparator();
75 fileMenu.add( quitAction = new FileAction("Poll Server", POLL_ID, this)).setAccelerator(KeyStroke.getKeyStroke('P', Event.CTRL_MASK));
76 fileMenu.add( quitAction = new FileAction("Collect Garbage", GARBAGE_ID, this)).setAccelerator(KeyStroke.getKeyStroke('G', Event.CTRL_MASK));
77 fileMenu.add( quitAction = new FileAction("Quit", QUIT_ID, this)).setAccelerator(KeyStroke.getKeyStroke('Q', Event.CTRL_MASK));
78
79 // Edit Menu
80
81 editMenu.add( prefAction = new EditAction("Preferences", PREF_ID, this));
82
83
84 menuBar.add(fileMenu); // Add the file menu
85 menuBar.add(editMenu); // Add the edit menu
86
87
88 searchPanel = new SearchPanel(csModel, this);
89
90 JPanel centerPanel = new JPanel();
91 QueryHistoryPanel queryHistoryPanel = new QueryHistoryPanel(csModel);
92 centerPanel.add(queryHistoryPanel);
93
94 content.setLayout(new BoxLayout(content, BoxLayout.X_AXIS));
95 content.add(searchPanel);
96 content.add(centerPanel);
97
98 addWindowListener(new WindowHandler());
99
100 pack();
101 searchPanel.searchTextField.requestFocus();
102 } //end constructor
103
104
105public void update(Observable observedThing, Object o )
106 {
107 System.out.println("Updating...");
108 //jlist.setListData( ((CSModel)observedThing).getModel() );
109 }
110
111
112
113 // action objects
114
115 abstract class CSAction extends AbstractAction {
116 int menuItemID;
117 CSFrame frame;
118
119 CSAction( String name, int newMenuItemID, CSFrame f)
120 {
121 super(name);
122 menuItemID = newMenuItemID;
123 frame = f;
124 }
125
126 public abstract void actionPerformed(ActionEvent e);
127
128 } //end CSAction
129
130 class FileAction extends CSAction
131 {
132 FileAction(String name, int newMenuItemID, CSFrame frame)
133 {
134 super(name,newMenuItemID, frame );
135 }
136
137 public void actionPerformed(ActionEvent e)
138 {
139 switch (menuItemID) {
140 case GARBAGE_ID:
141 System.err.println("forcing gc...");
142 System.gc() ;
143 System.runFinalization();
144 System.err.println("forcing gc...");
145 System.gc() ;
146 System.runFinalization();
147 System.err.println("forced gc");
148 break;
149 case POLL_ID:
150 System.out.println("poll chosen from menu");
151 break;
152 case QUIT_ID:
153 System.out.println("quit chosen from menu");
154 dispose(); // free resources
155 System.exit(0); // exit program
156 break;
157 default:
158 System.out.println("unimplemented option chosen from FileAction");
159 break;
160 } // end switch
161 }//end actionPerformed
162 } // end FileAction
163
164 class EditAction extends CSAction
165 {
166 EditAction(String name, int newMenuItemID, CSFrame frame)
167 {
168 super(name,newMenuItemID, frame );
169 }
170
171 public void actionPerformed(ActionEvent e)
172 {
173 switch (menuItemID) {
174 case PREF_ID:
175 PreferencesDialog prefDialog = new PreferencesDialog(frame, "Preferences", false); // make this the instance of CSFrame
176 break;
177 default:
178 System.out.println("unimplemented option chosen from EditAction");
179 break;
180 } // end switch
181 } //end actionPerformed
182 } // end EditAction
183
184
185class WindowHandler extends WindowAdapter
186{
187
188 public void windowOpened(WindowEvent e) {
189
190 SwingUtilities.invokeLater(new Runnable() {
191 public void run() {
192 searchPanel.searchTextField.requestFocus();
193 searchPanel.searchTextField.setCaretPosition(
194 searchPanel.searchTextField.getText().length() );
195 searchPanel.searchTextField.selectAll();
196 }
197 });
198 } //end windowOpened
199
200
201
202 public void windowClosing(WindowEvent e)
203 {
204 dispose(); // free resources
205 System.exit(0); // exit program
206 }
207}// end WindowHandler
208
209
210class MouseHandler extends MouseAdapter
211{
212private Frame frame;
213
214 public MouseHandler( CSFrame f )
215 {
216 this.frame = f;
217 }
218
219 public void mouseClicked(MouseEvent e) {
220 //System.out.println("mouse event" );
221 if (e.getClickCount() == 2) {
222 System.out.println("double click - mouse event" );
223 int index = jlist.locationToIndex(e.getPoint());
224 System.out.println("index is " + index );
225 //psObject = (PeopleSpaceObject) jlist.getModel().getElementAt(index);
226 } //end if
227 } //end mouseClicked
228
229 public void mousePressed(MouseEvent e) {
230 maybeShowPopup(e);
231 }
232
233 public void mouseReleased(MouseEvent e) {
234 maybeShowPopup(e);
235 }
236
237 private void maybeShowPopup(MouseEvent e) {
238 if (e.isPopupTrigger()) {
239 contextPopup.show(e.getComponent(),
240 e.getX(), e.getY());
241 } //end if
242 } //end maybeShowPopup
243
244 } //end class MouseHandler
245
246 // private declarations
247 private JMenuBar menuBar = new JMenuBar(); // Window menu bar
248 private JMenuItem quitItem;
249
250 private JList jlist, peopleList;
251 private JPopupMenu contextPopup;
252
253 // FileActions
254 private FileAction newSpaceAction, newGroupAction, newPersonAction, quitAction;
255
256 // EditActions
257
258 private EditAction prefAction;
259
260 //Dialog
261
262 private PreferencesDialog newPreferencesDialog;
263
264} //end CSFrame
Note: See TracBrowser for help on using the repository browser.