source: trunk/gli/src/org/greenstone/gatherer/gui/PreviewCommandDialog.java@ 7183

Last change on this file since 7183 was 7151, checked in by kjdon, 20 years ago

fixed some more static label sizes and deleted a lot of commented out stuff

  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.File;
42import java.util.*;
43import javax.swing.*;
44import javax.swing.event.*;
45import javax.swing.filechooser.*;
46import javax.swing.table.*;
47import org.greenstone.gatherer.Dictionary;
48import org.greenstone.gatherer.Gatherer;
49import org.greenstone.gatherer.gui.GComboBox;
50import org.greenstone.gatherer.gui.GLIButton;
51import org.greenstone.gatherer.gui.ModalDialog;
52import org.greenstone.gatherer.gui.NonWhitespaceField;
53import org.greenstone.gatherer.gui.OpenCollectionDialog;
54import org.greenstone.gatherer.gui.SimpleMenuBar;
55import org.greenstone.gatherer.util.TableUtils;
56import org.greenstone.gatherer.util.Utility;
57
58/** This dialog allows the user to choose which browser to use for the preview command
59 * @author Katherine Don, Greenstone Digital Library, University of Waikato
60 * @version 2.3
61 */
62public class PreviewCommandDialog
63 extends ModalDialog {
64
65 /** The default size for the dialog. */
66 static final private Dimension SIZE = new Dimension(500, 195);
67
68 private PreviewCommandDialog self;
69 private JButton browse_button;
70 private JButton cancel_button;
71 private JButton ok_button;
72 private JTextField command_field;
73 private String preview_command=null;
74 /** Create a new PreviewCommandDialog
75 */
76 public PreviewCommandDialog() {
77 super(Gatherer.g_man);
78 this.self = this;
79
80 // Creation
81 setModal(true);
82 setSize(SIZE);
83 setJMenuBar(new SimpleMenuBar("thepreviewview"));
84
85 JPanel content_pane = (JPanel) getContentPane();
86 content_pane.setBackground(Gatherer.config.getColor("coloring.collection_heading_background", false));
87
88 JTextArea instructions_area = new JTextArea();
89 instructions_area.setEditable(false);
90 instructions_area.setLineWrap(true);
91 instructions_area.setRows(5);
92 instructions_area.setWrapStyleWord(true);
93 Dictionary.setText(instructions_area, "PreviewCommandDialog.Instructions");
94
95 JPanel button_pane = new JPanel();
96 JPanel lower_pane = new JPanel();
97
98 JPanel command_pane = new JPanel();
99 command_field = new JTextField();
100 browse_button = new GLIButton();
101 browse_button.setEnabled(!Utility.isMac());
102 browse_button.setMnemonic(KeyEvent.VK_B);
103
104 ok_button = new GLIButton();
105 ok_button.setMnemonic(KeyEvent.VK_O);
106 cancel_button = new GLIButton();
107 cancel_button.setMnemonic(KeyEvent.VK_C);
108
109 // Connection
110 browse_button.addActionListener(new BrowseButtonListener());
111 ok_button.addActionListener(new OkButtonListener());
112 cancel_button.addActionListener(new CancelButtonListener());
113 if(Utility.isMac()) {
114 Dictionary.setBoth(browse_button, "FileAssociationDialog.Browse", "FileAssociationDialog.Browse_Tooltip_Mac");
115 }
116 else {
117 Dictionary.setBoth(browse_button, "FileAssociationDialog.Browse", "FileAssociationDialog.Browse_Tooltip");
118 }
119
120 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
121 Dictionary.setBoth(ok_button, "General.OK", "FileAssociationDialog.Close_Tooltip");
122 Dictionary.setText(this, "PreviewCommandDialog.Title");
123
124 // Layout
125 command_pane.setBorder(BorderFactory.createEmptyBorder(2,0,2,0));
126 command_pane.setLayout(new BorderLayout());
127 command_pane.add(command_field, BorderLayout.CENTER);
128 command_pane.add(browse_button, BorderLayout.EAST);
129
130 lower_pane.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
131
132 button_pane.setLayout(new GridLayout(1,2,5,0));
133 button_pane.add(ok_button);
134 button_pane.add(cancel_button);
135
136 lower_pane.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
137 lower_pane.setLayout(new BorderLayout());
138 lower_pane.add(command_pane, BorderLayout.CENTER);
139 lower_pane.add(button_pane, BorderLayout.SOUTH);
140
141
142 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
143 content_pane.setLayout(new BorderLayout());
144 content_pane.add(new JScrollPane(instructions_area), BorderLayout.NORTH);
145 content_pane.add(lower_pane, BorderLayout.CENTER);
146
147 Rectangle screen = Gatherer.g_man.getBounds(null);
148 setLocation((int)(screen.getX() + (screen.getWidth() - SIZE.width) / 2), (int)(screen.getY() + (screen.getHeight() - SIZE.height) / 2));
149 screen = null;
150 }
151
152 public void destroy() {
153 // Disconnect
154 // Clean up
155 self = null;
156 }
157
158 /** Redisplay the dialog
159 */
160 public String display() {
161 setVisible(true);
162 return preview_command;
163 }
164
165
166 private class OkButtonListener
167 implements ActionListener {
168
169 public void actionPerformed(ActionEvent event) {
170 preview_command = command_field.getText();
171 self.dispose();
172
173 }
174 }
175
176
177 /** Whenever the user clicks the browse button, we should open up a file browser to allow them to select an executable file from somewhere in the file system. */
178 private class BrowseButtonListener
179 implements ActionListener {
180 /** Open up a simple JFileChooser when the user clicks the button.
181 * @param event An <strong>ActionEvent</strong> containing information about the event.
182 */
183 public void actionPerformed(ActionEvent event) {
184 JFileChooser chooser = new JFileChooser(new File(Utility.BASE_DIR));
185 OpenCollectionDialog.disableRename(chooser);
186 chooser.setDialogTitle(Dictionary.get("FileAssociationDialog.Browse_Title"));
187 chooser.setFileFilter(new BatchFileFilter());
188 chooser.setFileFilter(new CoreObjectModelFileFilter());
189 chooser.setFileFilter(new ExecutableFileFilter());
190 chooser.setAcceptAllFileFilterUsed(true);
191 if(chooser.showOpenDialog(Gatherer.g_man) == JFileChooser.APPROVE_OPTION) {
192 command_field.setText(chooser.getSelectedFile().getAbsolutePath());
193 }
194 }
195 }
196
197
198 private class CancelButtonListener
199 implements ActionListener {
200 public void actionPerformed(ActionEvent event) {
201 self.dispose();
202 }
203 }
204
205 /** Batch filter shows only files ending in bat. Based on ImageFilter.java which is a 1.4 example used by FileChooserDemo2.java. */
206 private class BatchFileFilter
207 extends FileFilter {
208
209 /** Accept all .exe files
210 * @param file a File
211 * @return true is this file should be shown, false otherwise
212 */
213 public boolean accept(File file) {
214 return file.getName().toLowerCase().endsWith(".bat");
215 }
216
217 /** The description of this filter
218 * @return a String
219 */
220 public String getDescription() {
221 return Dictionary.get("FileAssociationDialog.Batch_File");
222 }
223 }
224
225 /** Command filter shows only files ending in com. Based on ImageFilter.java which is a 1.4 example used by FileChooserDemo2.java. */
226 private class CoreObjectModelFileFilter
227 extends FileFilter {
228
229 /** Accept all .com files
230 * @param file a File
231 * @return true is this file should be shown, false otherwise
232 */
233 public boolean accept(File file) {
234 return file.getName().toLowerCase().endsWith(".com");
235 }
236
237 /** The description of this filter
238 * @return a String
239 */
240 public String getDescription() {
241 return Dictionary.get("FileAssociationDialog.Command_File");
242 }
243 }
244
245
246 /** Executable filter shows only files ending in exe. Based on ImageFilter.java which is a 1.4 example used by FileChooserDemo2.java. */
247 private class ExecutableFileFilter
248 extends FileFilter {
249
250 /** Accept all .exe files
251 * @param file a File
252 * @return true is this file should be shown, false otherwise
253 */
254 public boolean accept(File file) {
255 return file.getName().toLowerCase().endsWith(".exe");
256 }
257
258 /** The description of this filter
259 * @return a String
260 */
261 public String getDescription() {
262 return Dictionary.get("FileAssociationDialog.Executable_File");
263 }
264 }
265
266
267}
268
269
270
271
272
273
Note: See TracBrowser for help on using the repository browser.