[6748] | 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 | */
|
---|
| 37 | package org.greenstone.gatherer.gui;
|
---|
| 38 |
|
---|
| 39 | import java.awt.*;
|
---|
| 40 | import java.awt.event.*;
|
---|
| 41 | import java.io.File;
|
---|
| 42 | import java.util.*;
|
---|
| 43 | import javax.swing.*;
|
---|
| 44 | import javax.swing.event.*;
|
---|
| 45 | import javax.swing.filechooser.*;
|
---|
| 46 | import javax.swing.table.*;
|
---|
[8231] | 47 | import org.greenstone.gatherer.Configuration;
|
---|
[6748] | 48 | import org.greenstone.gatherer.Dictionary;
|
---|
| 49 | import org.greenstone.gatherer.Gatherer;
|
---|
| 50 | import 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 | */
|
---|
| 56 | public 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 |
|
---|
| 79 | JPanel content_pane = (JPanel) getContentPane();
|
---|
[8231] | 80 | content_pane.setBackground(Configuration.getColor("coloring.collection_heading_background", false));
|
---|
[6748] | 81 |
|
---|
| 82 | JTextArea instructions_area = new JTextArea();
|
---|
| 83 | instructions_area.setEditable(false);
|
---|
| 84 | instructions_area.setLineWrap(true);
|
---|
| 85 | instructions_area.setRows(5);
|
---|
| 86 | instructions_area.setWrapStyleWord(true);
|
---|
| 87 | Dictionary.setText(instructions_area, "PreviewCommandDialog.Instructions");
|
---|
| 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();
|
---|
| 95 | browse_button.setEnabled(!Utility.isMac());
|
---|
| 96 | browse_button.setMnemonic(KeyEvent.VK_B);
|
---|
| 97 |
|
---|
| 98 | ok_button = new GLIButton();
|
---|
| 99 | ok_button.setMnemonic(KeyEvent.VK_O);
|
---|
| 100 | cancel_button = new GLIButton();
|
---|
| 101 | cancel_button.setMnemonic(KeyEvent.VK_C);
|
---|
| 102 |
|
---|
| 103 | // Connection
|
---|
| 104 | browse_button.addActionListener(new BrowseButtonListener());
|
---|
| 105 | ok_button.addActionListener(new OkButtonListener());
|
---|
| 106 | cancel_button.addActionListener(new CancelButtonListener());
|
---|
| 107 | if(Utility.isMac()) {
|
---|
| 108 | Dictionary.setBoth(browse_button, "FileAssociationDialog.Browse", "FileAssociationDialog.Browse_Tooltip_Mac");
|
---|
| 109 | }
|
---|
| 110 | else {
|
---|
| 111 | Dictionary.setBoth(browse_button, "FileAssociationDialog.Browse", "FileAssociationDialog.Browse_Tooltip");
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
|
---|
| 115 | Dictionary.setBoth(ok_button, "General.OK", "FileAssociationDialog.Close_Tooltip");
|
---|
| 116 | Dictionary.setText(this, "PreviewCommandDialog.Title");
|
---|
| 117 |
|
---|
| 118 | // Layout
|
---|
| 119 | command_pane.setBorder(BorderFactory.createEmptyBorder(2,0,2,0));
|
---|
| 120 | command_pane.setLayout(new BorderLayout());
|
---|
| 121 | command_pane.add(command_field, BorderLayout.CENTER);
|
---|
| 122 | command_pane.add(browse_button, BorderLayout.EAST);
|
---|
| 123 |
|
---|
| 124 | lower_pane.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
|
---|
| 125 |
|
---|
| 126 | button_pane.setLayout(new GridLayout(1,2,5,0));
|
---|
| 127 | button_pane.add(ok_button);
|
---|
| 128 | button_pane.add(cancel_button);
|
---|
| 129 |
|
---|
| 130 | lower_pane.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
|
---|
| 131 | lower_pane.setLayout(new BorderLayout());
|
---|
| 132 | lower_pane.add(command_pane, BorderLayout.CENTER);
|
---|
| 133 | lower_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 137 | content_pane.setLayout(new BorderLayout());
|
---|
| 138 | content_pane.add(new JScrollPane(instructions_area), 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(Utility.BASE_DIR));
|
---|
| 179 | OpenCollectionDialog.disableRename(chooser);
|
---|
| 180 | chooser.setDialogTitle(Dictionary.get("FileAssociationDialog.Browse_Title"));
|
---|
| 181 | chooser.setFileFilter(new BatchFileFilter());
|
---|
| 182 | chooser.setFileFilter(new CoreObjectModelFileFilter());
|
---|
| 183 | chooser.setFileFilter(new ExecutableFileFilter());
|
---|
| 184 | chooser.setAcceptAllFileFilterUsed(true);
|
---|
| 185 | if(chooser.showOpenDialog(Gatherer.g_man) == JFileChooser.APPROVE_OPTION) {
|
---|
| 186 | command_field.setText(chooser.getSelectedFile().getAbsolutePath());
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 | private class CancelButtonListener
|
---|
| 193 | implements ActionListener {
|
---|
| 194 | public void actionPerformed(ActionEvent event) {
|
---|
| 195 | self.dispose();
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | /** Batch filter shows only files ending in bat. Based on ImageFilter.java which is a 1.4 example used by FileChooserDemo2.java. */
|
---|
| 200 | private class BatchFileFilter
|
---|
| 201 | extends FileFilter {
|
---|
| 202 |
|
---|
| 203 | /** Accept all .exe files
|
---|
| 204 | * @param file a File
|
---|
| 205 | * @return true is this file should be shown, false otherwise
|
---|
| 206 | */
|
---|
| 207 | public boolean accept(File file) {
|
---|
| 208 | return file.getName().toLowerCase().endsWith(".bat");
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | /** The description of this filter
|
---|
| 212 | * @return a String
|
---|
| 213 | */
|
---|
| 214 | public String getDescription() {
|
---|
| 215 | return Dictionary.get("FileAssociationDialog.Batch_File");
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | /** Command filter shows only files ending in com. Based on ImageFilter.java which is a 1.4 example used by FileChooserDemo2.java. */
|
---|
| 220 | private class CoreObjectModelFileFilter
|
---|
| 221 | extends FileFilter {
|
---|
| 222 |
|
---|
| 223 | /** Accept all .com files
|
---|
| 224 | * @param file a File
|
---|
| 225 | * @return true is this file should be shown, false otherwise
|
---|
| 226 | */
|
---|
| 227 | public boolean accept(File file) {
|
---|
| 228 | return file.getName().toLowerCase().endsWith(".com");
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | /** The description of this filter
|
---|
| 232 | * @return a String
|
---|
| 233 | */
|
---|
| 234 | public String getDescription() {
|
---|
| 235 | return Dictionary.get("FileAssociationDialog.Command_File");
|
---|
| 236 | }
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 | /** Executable filter shows only files ending in exe. Based on ImageFilter.java which is a 1.4 example used by FileChooserDemo2.java. */
|
---|
| 241 | private class ExecutableFileFilter
|
---|
| 242 | extends FileFilter {
|
---|
| 243 |
|
---|
| 244 | /** Accept all .exe files
|
---|
| 245 | * @param file a File
|
---|
| 246 | * @return true is this file should be shown, false otherwise
|
---|
| 247 | */
|
---|
| 248 | public boolean accept(File file) {
|
---|
| 249 | return file.getName().toLowerCase().endsWith(".exe");
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | /** The description of this filter
|
---|
| 253 | * @return a String
|
---|
| 254 | */
|
---|
| 255 | public String getDescription() {
|
---|
| 256 | return Dictionary.get("FileAssociationDialog.Executable_File");
|
---|
| 257 | }
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 |
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 |
|
---|
| 264 |
|
---|
| 265 |
|
---|
| 266 |
|
---|
| 267 |
|
---|