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