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: Katherine Don, 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.*;
|
---|
42 | import java.util.*;
|
---|
43 | import javax.swing.*;
|
---|
44 | import javax.swing.event.*;
|
---|
45 | import javax.swing.*;
|
---|
46 | import javax.swing.event.*;
|
---|
47 | import javax.swing.text.*;
|
---|
48 | import org.greenstone.gatherer.Dictionary;
|
---|
49 | import org.greenstone.gatherer.Gatherer;
|
---|
50 | import org.greenstone.gatherer.checklist.CheckList;
|
---|
51 | import org.greenstone.gatherer.checklist.Entry;
|
---|
52 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
53 | import org.greenstone.gatherer.gui.SimpleMenuBar;
|
---|
54 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
55 | import org.greenstone.gatherer.cdm.ElementWrapper;
|
---|
56 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
57 | import org.greenstone.gatherer.util.Utility;
|
---|
58 | import org.w3c.dom.*;
|
---|
59 |
|
---|
60 | /** this class is pretty much copied from an inner class of MEM - AddSetActionListener. At some stage the two should be merged so there is only one copy of the code. */
|
---|
61 | public class NewMetaSetPrompt
|
---|
62 | extends ModalDialog {
|
---|
63 |
|
---|
64 | private boolean cancelled = true;
|
---|
65 | private JTextField name_field = null;
|
---|
66 | private JTextField namespace_field = null;
|
---|
67 | private JDialog self;
|
---|
68 |
|
---|
69 | static private Dimension size = new Dimension(400,125);
|
---|
70 | static final private Dimension LABEL_SIZE = new Dimension(100,30);
|
---|
71 | static final private Dimension ADD_SET_SIZE = new Dimension(400,125);
|
---|
72 |
|
---|
73 | public NewMetaSetPrompt() {
|
---|
74 | super(Gatherer.g_man, true);
|
---|
75 | this.self = this;
|
---|
76 | setModal(true);
|
---|
77 | setSize(size);
|
---|
78 | Dictionary.setText(this, "MEM.AddSet");
|
---|
79 |
|
---|
80 | // Creation
|
---|
81 | JPanel content_pane = (JPanel) getContentPane();
|
---|
82 | content_pane.setBackground(Gatherer.config.getColor("coloring.collection_heading_background", false));
|
---|
83 | JPanel center_pane = new JPanel();
|
---|
84 | center_pane.setOpaque(false);
|
---|
85 |
|
---|
86 | JPanel name_pane = new JPanel();
|
---|
87 | name_pane.setOpaque(false);
|
---|
88 | JLabel name_label = new JLabel();
|
---|
89 | name_label.setOpaque(false);
|
---|
90 | name_label.setPreferredSize(LABEL_SIZE);
|
---|
91 | Dictionary.setText(name_label, "MEM.Name");
|
---|
92 | name_field = new JTextField();
|
---|
93 | name_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
|
---|
94 | name_field.setForeground(Gatherer.config.getColor("coloring.collection_tree_foreground", false));
|
---|
95 | name_field.setSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false));
|
---|
96 | name_field.setSelectedTextColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false));
|
---|
97 | Dictionary.setTooltip(name_field, "MEM.Set_Name_Tooltip");
|
---|
98 |
|
---|
99 | JPanel namespace_pane = new JPanel();
|
---|
100 | namespace_pane.setOpaque(false);
|
---|
101 | JLabel namespace_label = new JLabel();
|
---|
102 | namespace_label.setOpaque(false);
|
---|
103 | namespace_label.setPreferredSize(LABEL_SIZE);
|
---|
104 | Dictionary.setText(namespace_label, "MEM.Namespace");
|
---|
105 | namespace_field = new JTextField();
|
---|
106 | namespace_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
|
---|
107 | namespace_field.setForeground(Gatherer.config.getColor("coloring.collection_tree_foreground", false));
|
---|
108 | namespace_field.setSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false));
|
---|
109 | namespace_field.setSelectedTextColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false));
|
---|
110 | Dictionary.setTooltip(namespace_field, "MEM.Set_Namespace_Tooltip");
|
---|
111 |
|
---|
112 |
|
---|
113 | JPanel button_pane = new JPanel();
|
---|
114 | button_pane.setOpaque(false);
|
---|
115 |
|
---|
116 | JButton ok_button = new GLIButton();
|
---|
117 | ok_button.setMnemonic(KeyEvent.VK_O);
|
---|
118 | Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
|
---|
119 | ok_button.setEnabled(false);
|
---|
120 | JButton cancel_button = new GLIButton();
|
---|
121 | cancel_button.setMnemonic(KeyEvent.VK_C);
|
---|
122 | Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
|
---|
123 | TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
|
---|
124 |
|
---|
125 | // Connection
|
---|
126 | cancel_button.addActionListener(new OKButtonListener());
|
---|
127 | ok_button.addActionListener(new CancelButtonListener());
|
---|
128 | ok_button_enabler.add(name_field);
|
---|
129 | ok_button_enabler.add(namespace_field);
|
---|
130 |
|
---|
131 | // Layout
|
---|
132 | namespace_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
|
---|
133 | namespace_pane.setLayout(new BorderLayout());
|
---|
134 | namespace_pane.add(namespace_label, BorderLayout.WEST);
|
---|
135 | namespace_pane.add(namespace_field, BorderLayout.CENTER);
|
---|
136 |
|
---|
137 | name_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
|
---|
138 | name_pane.setLayout(new BorderLayout());
|
---|
139 | name_pane.add(name_label, BorderLayout.WEST);
|
---|
140 | name_pane.add(name_field, BorderLayout.CENTER);
|
---|
141 |
|
---|
142 | center_pane.setLayout(new GridLayout(2,1));
|
---|
143 | center_pane.add(name_pane);
|
---|
144 | center_pane.add(namespace_pane);
|
---|
145 |
|
---|
146 | button_pane.setLayout(new GridLayout(1,2,0,5));
|
---|
147 | button_pane.add(ok_button);
|
---|
148 | button_pane.add(cancel_button);
|
---|
149 |
|
---|
150 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
151 | content_pane.setLayout(new BorderLayout());
|
---|
152 | content_pane.add(center_pane, BorderLayout.CENTER);
|
---|
153 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
154 |
|
---|
155 | setLocation((Gatherer.config.screen_size.width - ADD_SET_SIZE.width) / 2, (Gatherer.config.screen_size.height - ADD_SET_SIZE.height) / 2);
|
---|
156 | setVisible(true);
|
---|
157 | }
|
---|
158 |
|
---|
159 | public boolean isCancelled() {
|
---|
160 | return cancelled;
|
---|
161 | }
|
---|
162 |
|
---|
163 | public String getNamespace() {
|
---|
164 | return namespace_field.getText();
|
---|
165 | }
|
---|
166 |
|
---|
167 | public String getName() {
|
---|
168 | return name_field.getText();
|
---|
169 | }
|
---|
170 |
|
---|
171 | private class CancelButtonListener
|
---|
172 | implements ActionListener {
|
---|
173 | public void actionPerformed(ActionEvent event) {
|
---|
174 | cancelled = true;
|
---|
175 | self.dispose();
|
---|
176 | }
|
---|
177 | }
|
---|
178 | public class OKButtonListener
|
---|
179 | implements ActionListener {
|
---|
180 | public void actionPerformed(ActionEvent event) {
|
---|
181 | cancelled = false;
|
---|
182 | self.dispose();
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | /** Used to enable a certain target component if and only if all the registered text fields contain non-zero length strings. */
|
---|
187 | private class TextFieldEnabler
|
---|
188 | implements DocumentListener {
|
---|
189 | private boolean ignore = false;
|
---|
190 | private Component target = null;
|
---|
191 | private JTextComponent[] fields = null;
|
---|
192 | public TextFieldEnabler(Component target) {
|
---|
193 | super();
|
---|
194 | this.target = target;
|
---|
195 | }
|
---|
196 | public void add(JTextComponent field) {
|
---|
197 | // Record this field as being one we depend upon
|
---|
198 | if(fields == null) {
|
---|
199 | fields = new JTextComponent[1];
|
---|
200 | fields[0] = field;
|
---|
201 | }
|
---|
202 | else {
|
---|
203 | JTextComponent[] temp = new JTextComponent[fields.length + 1];
|
---|
204 | System.arraycopy(fields, 0, temp, 0, fields.length);
|
---|
205 | temp[fields.length] = field;
|
---|
206 | fields = temp;
|
---|
207 | temp = null;
|
---|
208 | }
|
---|
209 | // Add the appropriate listener
|
---|
210 | field.getDocument().addDocumentListener(this);
|
---|
211 | }
|
---|
212 | /** Gives notification that an attribute or set of attributes changed. */
|
---|
213 | public void changedUpdate(DocumentEvent e) {
|
---|
214 | canEnable();
|
---|
215 | }
|
---|
216 | /** Gives notification that there was an insert into the document. */
|
---|
217 | public void insertUpdate(DocumentEvent e) {
|
---|
218 | canEnable();
|
---|
219 | }
|
---|
220 | /** Gives notification that a portion of the document has been removed. */
|
---|
221 | public void removeUpdate(DocumentEvent e) {
|
---|
222 | canEnable();
|
---|
223 | }
|
---|
224 | private void canEnable() {
|
---|
225 | if(!ignore) {
|
---|
226 | ignore = true;
|
---|
227 | boolean can_enable = true;
|
---|
228 | for(int i = 0; can_enable && i < fields.length; i++) {
|
---|
229 | can_enable = can_enable && (fields[i].getText().length() > 0);
|
---|
230 | }
|
---|
231 | target.setEnabled(can_enable);
|
---|
232 | ignore = false;
|
---|
233 | }
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | }
|
---|