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

Last change on this file since 12119 was 12119, checked in by kjdon, 18 years ago

Changed text handling to use Dictionary.get rather than Dictionary.setText or Dictionary.registerBoth etc. also removed mnemonics cos they suck for other languages

  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 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.Configuration;
48import org.greenstone.gatherer.Dictionary;
49import org.greenstone.gatherer.Gatherer;
50import org.greenstone.gatherer.util.Utility;
51
52/** This dialog allows the user to choose which browser to use for the preview command
53 * @author Katherine Don, Greenstone Digital Library, University of Waikato
54 * @version 2.3
55 */
56public class PreviewCommandDialog
57 extends ModalDialog {
58
59 /** The default size for the dialog. */
60 static final private Dimension SIZE = new Dimension(500, 195);
61
62 private PreviewCommandDialog self;
63 private JButton browse_button;
64 private JButton cancel_button;
65 private JButton ok_button;
66 private JTextField command_field;
67 private String preview_command=null;
68 /** Create a new PreviewCommandDialog
69 */
70 public PreviewCommandDialog() {
71 super(Gatherer.g_man);
72 this.self = this;
73
74 // Creation
75 setModal(true);
76 setSize(SIZE);
77 setJMenuBar(new SimpleMenuBar("thepreviewview"));
78 setTitle(Dictionary.get("PreviewCommandDialog.Title"));
79
80 JPanel content_pane = (JPanel) getContentPane();
81 content_pane.setBackground(Configuration.getColor("coloring.collection_heading_background", false));
82
83 JTextArea instructions_area = new JTextArea(Dictionary.get("PreviewCommandDialog.Instructions"));
84 instructions_area.setEditable(false);
85 instructions_area.setLineWrap(true);
86 instructions_area.setRows(5);
87 instructions_area.setWrapStyleWord(true);
88
89 JPanel button_pane = new JPanel();
90 JPanel lower_pane = new JPanel();
91
92 JPanel command_pane = new JPanel();
93 command_field = new JTextField();
94 browse_button = new GLIButton(Dictionary.get("FileAssociationDialog.Browse"));
95 browse_button.setEnabled(!Utility.isMac());
96 if (Utility.isMac()) {
97 browse_button.setToolTipText(Dictionary.get("FileAssociationDialog.Browse_Tooltip_Mac"));
98 } else {
99 browse_button.setToolTipText(Dictionary.get("FileAssociationDialog.Browse", "FileAssociationDialog.Browse_Tooltip"));
100 }
101 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("FileAssociationDialog.Close_Tooltip"));
102 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip"));
103
104 // Connection
105 browse_button.addActionListener(new BrowseButtonListener());
106 ok_button.addActionListener(new OkButtonListener());
107 cancel_button.addActionListener(new CancelButtonListener());
108
109 // Layout
110 command_pane.setBorder(BorderFactory.createEmptyBorder(2,0,2,0));
111 command_pane.setLayout(new BorderLayout());
112 command_pane.add(command_field, BorderLayout.CENTER);
113 command_pane.add(browse_button, BorderLayout.EAST);
114
115 lower_pane.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
116
117 button_pane.setLayout(new GridLayout(1,2,5,0));
118 button_pane.add(ok_button);
119 button_pane.add(cancel_button);
120
121 lower_pane.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
122 lower_pane.setLayout(new BorderLayout());
123 lower_pane.add(command_pane, BorderLayout.CENTER);
124 lower_pane.add(button_pane, BorderLayout.SOUTH);
125
126
127 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
128 content_pane.setLayout(new BorderLayout());
129 content_pane.add(new JScrollPane(instructions_area), BorderLayout.NORTH);
130 content_pane.add(lower_pane, BorderLayout.CENTER);
131
132 Rectangle screen = Gatherer.g_man.getBounds(null);
133 setLocation((int)(screen.getX() + (screen.getWidth() - SIZE.width) / 2), (int)(screen.getY() + (screen.getHeight() - SIZE.height) / 2));
134 screen = null;
135 }
136
137 public void destroy() {
138 // Disconnect
139 // Clean up
140 self = null;
141 }
142
143 /** Redisplay the dialog
144 */
145 public String display() {
146 setVisible(true);
147 return preview_command;
148 }
149
150
151 private class OkButtonListener
152 implements ActionListener {
153
154 public void actionPerformed(ActionEvent event) {
155 preview_command = command_field.getText();
156 self.dispose();
157
158 }
159 }
160
161
162 /** 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. */
163 private class BrowseButtonListener
164 implements ActionListener {
165 /** Open up a simple JFileChooser when the user clicks the button.
166 * @param event An <strong>ActionEvent</strong> containing information about the event.
167 */
168 public void actionPerformed(ActionEvent event) {
169 JFileChooser chooser = new JFileChooser(new File(Gatherer.getGLIUserDirectoryPath()));
170 GUIUtils.disableRename(chooser);
171 chooser.setDialogTitle(Dictionary.get("FileAssociationDialog.Browse_Title"));
172 chooser.setFileFilter(new BatchFileFilter());
173 chooser.setFileFilter(new CoreObjectModelFileFilter());
174 chooser.setFileFilter(new ExecutableFileFilter());
175 chooser.setAcceptAllFileFilterUsed(true);
176 if(chooser.showOpenDialog(Gatherer.g_man) == JFileChooser.APPROVE_OPTION) {
177 command_field.setText(chooser.getSelectedFile().getAbsolutePath());
178 }
179 }
180 }
181
182
183 private class CancelButtonListener
184 implements ActionListener {
185 public void actionPerformed(ActionEvent event) {
186 self.dispose();
187 }
188 }
189
190 /** Batch filter shows only files ending in bat. Based on ImageFilter.java which is a 1.4 example used by FileChooserDemo2.java. */
191 private class BatchFileFilter
192 extends FileFilter {
193
194 /** Accept all .exe files
195 * @param file a File
196 * @return true is this file should be shown, false otherwise
197 */
198 public boolean accept(File file) {
199 return file.getName().toLowerCase().endsWith(".bat");
200 }
201
202 /** The description of this filter
203 * @return a String
204 */
205 public String getDescription() {
206 return Dictionary.get("FileAssociationDialog.Batch_File");
207 }
208 }
209
210 /** Command filter shows only files ending in com. Based on ImageFilter.java which is a 1.4 example used by FileChooserDemo2.java. */
211 private class CoreObjectModelFileFilter
212 extends FileFilter {
213
214 /** Accept all .com files
215 * @param file a File
216 * @return true is this file should be shown, false otherwise
217 */
218 public boolean accept(File file) {
219 return file.getName().toLowerCase().endsWith(".com");
220 }
221
222 /** The description of this filter
223 * @return a String
224 */
225 public String getDescription() {
226 return Dictionary.get("FileAssociationDialog.Command_File");
227 }
228 }
229
230
231 /** Executable filter shows only files ending in exe. Based on ImageFilter.java which is a 1.4 example used by FileChooserDemo2.java. */
232 private class ExecutableFileFilter
233 extends FileFilter {
234
235 /** Accept all .exe files
236 * @param file a File
237 * @return true is this file should be shown, false otherwise
238 */
239 public boolean accept(File file) {
240 return file.getName().toLowerCase().endsWith(".exe");
241 }
242
243 /** The description of this filter
244 * @return a String
245 */
246 public String getDescription() {
247 return Dictionary.get("FileAssociationDialog.Executable_File");
248 }
249 }
250
251
252}
253
254
255
256
257
258
Note: See TracBrowser for help on using the repository browser.