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

Last change on this file since 18376 was 18370, checked in by kjdon, 15 years ago

committed code submitted by Amin Hedjazi for making the GLI right to left. I worked on this code on the rtl-gli branch, then merged the branch back to the trunk at revision 18368. The branch code was slightly different in a couple of places where it shouldn't have been. So don't use the branch code next time. Start a new branch.

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