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

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

turned on the BerryBasket. Try right-clicking on a result in the results List
to add one - no delete yet. Re-sizing maybe improved as well - no
guarantees yet though.

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