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 | this.setComponentOrientation(Dictionary.getOrientation());
|
---|
56 | setModal(true);
|
---|
57 | setSize(DIALOG_SIZE);
|
---|
58 | setTitle(Dictionary.get("MappingPrompt.Title"));
|
---|
59 |
|
---|
60 | // Creation
|
---|
61 | JPanel content_pane = (JPanel) getContentPane();
|
---|
62 | content_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
63 | JPanel center_pane = new JPanel();
|
---|
64 | center_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
65 | JPanel labels_pane = new JPanel();
|
---|
66 | labels_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
67 | JPanel fields_pane = new JPanel();
|
---|
68 | fields_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
69 |
|
---|
70 | JLabel file_label = new JLabel(Dictionary.get("MappingPrompt.File"));
|
---|
71 | file_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
72 | JLabel file_field = new JLabel(file.getAbsolutePath());
|
---|
73 | file_field.setComponentOrientation(Dictionary.getOrientation());
|
---|
74 |
|
---|
75 | JLabel name_label = new JLabel(Dictionary.get("MappingPrompt.Name"));
|
---|
76 | name_label.setComponentOrientation(Dictionary.getOrientation());
|
---|
77 | name_field = new JTextField(file.getName());
|
---|
78 | name_field.setComponentOrientation(Dictionary.getOrientation());
|
---|
79 |
|
---|
80 | JPanel button_pane = new JPanel();
|
---|
81 | button_pane.setComponentOrientation(Dictionary.getOrientation());
|
---|
82 | ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
|
---|
83 | ok_button.setEnabled(name_field.getText().length() > 0);
|
---|
84 | cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
|
---|
85 |
|
---|
86 | // Connection
|
---|
87 | cancel_button.addActionListener(this);
|
---|
88 | ok_button.addActionListener(this);
|
---|
89 | name_field.addKeyListener(this);
|
---|
90 |
|
---|
91 | // Layout
|
---|
92 | labels_pane.setLayout(new GridLayout(2,1,5,0));
|
---|
93 | labels_pane.add(file_label);
|
---|
94 | labels_pane.add(name_label);
|
---|
95 |
|
---|
96 | fields_pane.setLayout(new GridLayout(2,1,5,0));
|
---|
97 | fields_pane.add(file_field);
|
---|
98 | fields_pane.add(name_field);
|
---|
99 |
|
---|
100 | center_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
|
---|
101 | center_pane.setLayout(new BorderLayout(5,0));
|
---|
102 | center_pane.add(labels_pane, BorderLayout.LINE_START);
|
---|
103 | center_pane.add(fields_pane, BorderLayout.CENTER);
|
---|
104 |
|
---|
105 | button_pane.setLayout(new GridLayout(1,2,5,5));
|
---|
106 | button_pane.add(ok_button);
|
---|
107 | button_pane.add(cancel_button);
|
---|
108 |
|
---|
109 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
110 | content_pane.setLayout(new BorderLayout());
|
---|
111 | content_pane.add(center_pane, BorderLayout.CENTER);
|
---|
112 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
113 |
|
---|
114 | // Display
|
---|
115 | Dimension screen_size = Configuration.screen_size;
|
---|
116 | setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
|
---|
117 | setVisible(true);
|
---|
118 |
|
---|
119 | // If not cancelled create mapping.
|
---|
120 | if (!cancelled) {
|
---|
121 | workspace_tree.addDirectoryMapping(name_field.getText(), file);
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | public void actionPerformed(ActionEvent event)
|
---|
127 | {
|
---|
128 | if (event.getSource() == cancel_button) {
|
---|
129 | cancelled = true;
|
---|
130 | }
|
---|
131 | dispose();
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | public void destroy()
|
---|
136 | {
|
---|
137 | cancel_button = null;
|
---|
138 | ok_button = null;
|
---|
139 | name_field = null;
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | public void keyPressed(KeyEvent event) { }
|
---|
144 |
|
---|
145 | public void keyReleased(KeyEvent event)
|
---|
146 | {
|
---|
147 | ok_button.setEnabled(name_field.getText().length() > 0);
|
---|
148 | }
|
---|
149 |
|
---|
150 | public void keyTyped(KeyEvent event) { }
|
---|
151 | }
|
---|