[11612] | 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 | * Author: Michael Dewsnip, Greenstone Digital Library, University of Waikato
|
---|
| 9 | *
|
---|
| 10 | * Copyright (C) 2006 New Zealand Digital Library Project
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or modify
|
---|
| 13 | * it under the terms of the GNU General Public License as published by
|
---|
| 14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | * (at your option) any later version.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful,
|
---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | * GNU General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, write to the Free Software
|
---|
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | *########################################################################
|
---|
| 26 | */
|
---|
| 27 | package org.greenstone.gatherer.gui;
|
---|
| 28 |
|
---|
| 29 | import java.awt.*;
|
---|
| 30 | import java.awt.event.*;
|
---|
| 31 | import javax.swing.*;
|
---|
| 32 | import java.io.*;
|
---|
| 33 | import org.greenstone.gatherer.Dictionary;
|
---|
| 34 | import org.greenstone.gatherer.Configuration;
|
---|
| 35 | import org.greenstone.gatherer.Gatherer;
|
---|
| 36 | import org.greenstone.gatherer.file.WorkspaceTree;
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | public class CreateShortcutPrompt
|
---|
| 40 | extends JDialog
|
---|
| 41 | implements ActionListener, KeyListener
|
---|
| 42 | {
|
---|
| 43 | /** The default size of a special mapping dialog. */
|
---|
| 44 | static final Dimension DIALOG_SIZE = new Dimension(400, 120);
|
---|
| 45 |
|
---|
| 46 | private boolean cancelled = false;
|
---|
| 47 | private JButton cancel_button = null;
|
---|
| 48 | private JButton ok_button = null;
|
---|
| 49 | private JTextField name_field = null;
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | public CreateShortcutPrompt(WorkspaceTree workspace_tree, File file)
|
---|
| 53 | {
|
---|
| 54 | super(Gatherer.g_man);
|
---|
| 55 |
|
---|
| 56 | setModal(true);
|
---|
| 57 | setSize(DIALOG_SIZE);
|
---|
[12119] | 58 | setTitle(Dictionary.get("MappingPrompt.Title"));
|
---|
| 59 |
|
---|
[11612] | 60 | // Creation
|
---|
| 61 | JPanel content_pane = (JPanel) getContentPane();
|
---|
| 62 | JPanel center_pane = new JPanel();
|
---|
| 63 | JPanel labels_pane = new JPanel();
|
---|
| 64 | JPanel fields_pane = new JPanel();
|
---|
| 65 |
|
---|
[12119] | 66 | JLabel file_label = new JLabel(Dictionary.get("MappingPrompt.File"));
|
---|
[11612] | 67 | JLabel file_field = new JLabel(file.getAbsolutePath());
|
---|
| 68 |
|
---|
[12119] | 69 | JLabel name_label = new JLabel(Dictionary.get("MappingPrompt.Name"));
|
---|
[11612] | 70 | name_field = new JTextField(file.getName());
|
---|
| 71 |
|
---|
| 72 | JPanel button_pane = new JPanel();
|
---|
[12119] | 73 | ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
|
---|
[11612] | 74 | ok_button.setEnabled(name_field.getText().length() > 0);
|
---|
[12119] | 75 | cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
|
---|
| 76 |
|
---|
[11612] | 77 | // Connection
|
---|
| 78 | cancel_button.addActionListener(this);
|
---|
| 79 | ok_button.addActionListener(this);
|
---|
| 80 | name_field.addKeyListener(this);
|
---|
| 81 |
|
---|
| 82 | // Layout
|
---|
| 83 | labels_pane.setLayout(new GridLayout(2,1,5,0));
|
---|
| 84 | labels_pane.add(file_label);
|
---|
| 85 | labels_pane.add(name_label);
|
---|
| 86 |
|
---|
| 87 | fields_pane.setLayout(new GridLayout(2,1,5,0));
|
---|
| 88 | fields_pane.add(file_field);
|
---|
| 89 | fields_pane.add(name_field);
|
---|
| 90 |
|
---|
| 91 | center_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
|
---|
| 92 | center_pane.setLayout(new BorderLayout(5,0));
|
---|
| 93 | center_pane.add(labels_pane, BorderLayout.WEST);
|
---|
| 94 | center_pane.add(fields_pane, BorderLayout.CENTER);
|
---|
| 95 |
|
---|
| 96 | button_pane.setLayout(new GridLayout(1,2,5,5));
|
---|
| 97 | button_pane.add(ok_button);
|
---|
| 98 | button_pane.add(cancel_button);
|
---|
| 99 |
|
---|
| 100 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 101 | content_pane.setLayout(new BorderLayout());
|
---|
| 102 | content_pane.add(center_pane, BorderLayout.CENTER);
|
---|
| 103 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
| 104 |
|
---|
| 105 | // Display
|
---|
| 106 | Dimension screen_size = Configuration.screen_size;
|
---|
| 107 | setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
|
---|
| 108 | setVisible(true);
|
---|
| 109 |
|
---|
| 110 | // If not cancelled create mapping.
|
---|
| 111 | if (!cancelled) {
|
---|
| 112 | workspace_tree.addDirectoryMapping(name_field.getText(), file);
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 | public void actionPerformed(ActionEvent event)
|
---|
| 118 | {
|
---|
| 119 | if (event.getSource() == cancel_button) {
|
---|
| 120 | cancelled = true;
|
---|
| 121 | }
|
---|
| 122 | dispose();
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 | public void destroy()
|
---|
| 127 | {
|
---|
| 128 | cancel_button = null;
|
---|
| 129 | ok_button = null;
|
---|
| 130 | name_field = null;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 | public void keyPressed(KeyEvent event) { }
|
---|
| 135 |
|
---|
| 136 | public void keyReleased(KeyEvent event)
|
---|
| 137 | {
|
---|
| 138 | ok_button.setEnabled(name_field.getText().length() > 0);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | public void keyTyped(KeyEvent event) { }
|
---|
| 142 | }
|
---|