source: trunk/gli/src/org/greenstone/gatherer/gui/NewMetaSetPrompt.java@ 8257

Last change on this file since 8257 was 8243, checked in by mdewsnip, 20 years ago

Removed all occurrences of classes explicitly importing other classes in the same package.

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