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

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

retain state of non-explicit preferences (e.g. casfolding, stemming)

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 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: 2273 $
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 editMenu.add( prefAction = new EditAction("View Change Log", LOG_ID, this));
83
84
85 menuBar.add(fileMenu); // Add the file menu
86 menuBar.add(editMenu); // Add the edit menu
87
88
89 searchPanel = new SearchPanel(csModel, this);
90
91 JPanel centerPanel = new JPanel();
92 QueryHistoryPanel queryHistoryPanel = new QueryHistoryPanel(csModel);
93 centerPanel.add(queryHistoryPanel);
94
95 content.setLayout(new BoxLayout(content, BoxLayout.X_AXIS));
96 content.add(searchPanel);
97 content.add(centerPanel);
98
99 addWindowListener(new WindowHandler());
100
101 pack();
102 searchPanel.searchTextField.requestFocus();
103 } //end constructor
104
105
106public void update(Observable observedThing, Object o )
107 {
108 System.out.println("Updating...");
109 //jlist.setListData( ((CSModel)observedThing).getModel() );
110 }
111
112
113
114 // action objects
115
116 abstract class CSAction extends AbstractAction {
117 int menuItemID;
118 CSFrame frame;
119
120 CSAction( String name, int newMenuItemID, CSFrame f)
121 {
122 super(name);
123 menuItemID = newMenuItemID;
124 frame = f;
125 }
126
127 public abstract void actionPerformed(ActionEvent e);
128
129 } //end CSAction
130
131 class FileAction extends CSAction
132 {
133 FileAction(String name, int newMenuItemID, CSFrame frame)
134 {
135 super(name,newMenuItemID, frame );
136 }
137
138 public void actionPerformed(ActionEvent e)
139 {
140 switch (menuItemID) {
141 case GARBAGE_ID:
142 System.err.println("forcing gc...");
143 System.gc() ;
144 System.runFinalization();
145 System.err.println("forcing gc...");
146 System.gc() ;
147 System.runFinalization();
148 System.err.println("forced gc");
149 break;
150 case POLL_ID:
151 System.out.println("poll chosen from menu");
152 break;
153 case QUIT_ID:
154 System.out.println("quit chosen from menu");
155 //save preferences not in dialog
156 searchPanel.savePrefs();
157 dispose(); // free resources
158 System.exit(0); // exit program
159 break;
160 default:
161 System.out.println("unimplemented option chosen from FileAction");
162 break;
163 } // end switch
164 }//end actionPerformed
165 } // end FileAction
166
167 class EditAction extends CSAction
168 {
169 EditAction(String name, int newMenuItemID, CSFrame frame)
170 {
171 super(name,newMenuItemID, frame );
172 }
173
174 public void actionPerformed(ActionEvent e)
175 {
176 switch (menuItemID) {
177 case PREF_ID:
178 PreferencesDialog prefDialog = new PreferencesDialog(frame, "Preferences", false);
179 break;
180 case LOG_ID:
181 ChangeLogDialog logDialog = new ChangeLogDialog(frame, "ChangeLog", false);
182 break;
183 default:
184 System.out.println("unimplemented option chosen from EditAction");
185 break;
186 } // end switch
187 } //end actionPerformed
188 } // end EditAction
189
190
191class WindowHandler extends WindowAdapter
192{
193
194 public void windowOpened(WindowEvent e) {
195
196 SwingUtilities.invokeLater(new Runnable() {
197 public void run() {
198 searchPanel.searchTextField.requestFocus();
199 searchPanel.searchTextField.setCaretPosition(
200 searchPanel.searchTextField.getText().length() );
201 searchPanel.searchTextField.selectAll();
202 }
203 });
204 } //end windowOpened
205
206
207
208 public void windowClosing(WindowEvent e)
209 {
210 dispose(); // free resources
211 System.exit(0); // exit program
212 }
213}// end WindowHandler
214
215
216class MouseHandler extends MouseAdapter
217{
218private Frame frame;
219
220 public MouseHandler( CSFrame f )
221 {
222 this.frame = f;
223 }
224
225 public void mouseClicked(MouseEvent e) {
226 //System.out.println("mouse event" );
227 if (e.getClickCount() == 2) {
228 System.out.println("double click - mouse event" );
229 int index = jlist.locationToIndex(e.getPoint());
230 System.out.println("index is " + index );
231 //psObject = (PeopleSpaceObject) jlist.getModel().getElementAt(index);
232 } //end if
233 } //end mouseClicked
234
235 public void mousePressed(MouseEvent e) {
236 maybeShowPopup(e);
237 }
238
239 public void mouseReleased(MouseEvent e) {
240 maybeShowPopup(e);
241 }
242
243 private void maybeShowPopup(MouseEvent e) {
244 if (e.isPopupTrigger()) {
245 contextPopup.show(e.getComponent(),
246 e.getX(), e.getY());
247 } //end if
248 } //end maybeShowPopup
249
250 } //end class MouseHandler
251
252 // private declarations
253 private JMenuBar menuBar = new JMenuBar(); // Window menu bar
254 private JMenuItem quitItem;
255
256 private JList jlist, peopleList;
257 private JPopupMenu contextPopup;
258
259 // FileActions
260 private FileAction newSpaceAction, newGroupAction, newPersonAction, quitAction;
261
262 // EditActions
263
264 private EditAction prefAction;
265
266 //Dialog
267
268 private PreferencesDialog newPreferencesDialog;
269
270} //end CSFrame
Note: See TracBrowser for help on using the repository browser.