source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 9.7 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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 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 */
27package org.greenstone.gatherer.cdm;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.util.*;
32import javax.swing.*;
33import org.greenstone.gatherer.Configuration;
34import org.greenstone.gatherer.DebugStream;
35import org.greenstone.gatherer.Dictionary;
36import org.greenstone.gatherer.Gatherer;
37import org.greenstone.gatherer.gui.GComboBox;
38import org.greenstone.gatherer.gui.GLIButton;
39import org.greenstone.gatherer.gui.ModalDialog;
40import org.greenstone.gatherer.gui.SimpleMenuBar;
41import org.greenstone.gatherer.metadata.MetadataElement;
42import org.greenstone.gatherer.metadata.MetadataSetManager;
43import org.greenstone.gatherer.metadata.MetadataTools;
44import org.greenstone.gatherer.util.StaticStrings;
45import org.greenstone.gatherer.util.Utility;
46
47/** This class provides us with a dialog box which allows us to edit the arguments of either a Plugin or a Classifier.
48 * @author John Thompson, Greenstone Digital Library, University of Waikato
49 * @version 2.3
50 * @see org.greenstone.gatherer.cdm.Classifier
51 * @see org.greenstone.gatherer.cdm.Plugin
52 */
53public class ArgumentConfiguration
54 extends ModalDialog
55 implements ActionListener {
56 /** The data whose arguments we are editing. */
57 private ArgumentContainer data = null;
58 /** Whether we have successfully edited the arguments associated with the ArgumentContainer or if we have failed to enter required arguments and have instead cancelled (which would cause argument additions to roll back). */
59 private boolean success = false;
60 /** A button to cancel this dialog. */
61 private JButton cancel = null;
62 /** A button to accept the changes and close the dialog. */
63 private JButton ok = null;
64 /** A reference to the ourselves so our inner classes can dispose us like a dialog. */
65 private ArgumentConfiguration self = null;
66 /** The central pane where a list of known arguments is displayed. */
67 private JPanel central_pane = null;
68 /** The size used for an argument label. */
69 static final private Dimension LABEL_SIZE = new Dimension(225, 25);
70 /** Size of a list. */
71 static final private Dimension LIST_SIZE = new Dimension(380, 50);
72 /** The size used for the dialog. */
73 static final private Dimension SIZE = new Dimension(800, 425);
74
75 /** Constructor.
76 * @param data The plugin or classifier whose arguments we are configuring, in the form of its supported <strong>ArgumentContainer</strong> interface.
77 * @see org.greenstone.gatherer.Configuration
78 */
79 public ArgumentConfiguration(ArgumentContainer data) {
80 super(Gatherer.g_man);
81 this.data = data;
82 this.self = this;
83
84 // Create
85 setModal(true);
86 setSize(SIZE);
87 setJMenuBar(new SimpleMenuBar("designingacollection")); // can we tell whether we are doing a classifier or plugin, to make the help more specific??
88 setTitle(Dictionary.get("CDM.ArgumentConfiguration.Title"));
89
90 central_pane = new JPanel();
91 JPanel content_pane = (JPanel) getContentPane();
92
93 JLabel header = new JLabel(Dictionary.get("CDM.ArgumentConfiguration.Header", data.getName()));
94 header.setHorizontalAlignment(JLabel.CENTER);
95 header.setOpaque(true);
96
97 JPanel button_pane = new JPanel();
98 cancel = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip"));
99
100 ok = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
101
102 // Listeners
103 cancel.addActionListener(this);
104 ok.addActionListener(this);
105
106 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
107 button_pane.setLayout(new GridLayout(1,2));
108 button_pane.add(ok);
109 button_pane.add(cancel);
110
111 central_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
112 central_pane.setLayout(new BoxLayout(central_pane, BoxLayout.Y_AXIS));
113
114 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
115 content_pane.setLayout(new BorderLayout());
116 content_pane.add(header, BorderLayout.NORTH);
117 JScrollPane scrollPane = new JScrollPane(central_pane);
118 scrollPane.getVerticalScrollBar().setUnitIncrement(16);
119 content_pane.add(scrollPane, BorderLayout.CENTER);
120 content_pane.add(button_pane, BorderLayout.SOUTH);
121
122 // Now generate a set of controls for each of the arguments.
123 generateControls();
124
125 // Display on screen.
126 Dimension screen_size = Configuration.screen_size;
127 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
128 screen_size = null;
129 }
130
131 /** Any implementation of ActionListener must include this method so that we can be informed when an action has occured on one of the controls we are listening to.
132 * @param event An <strong>ActionEvent</strong> containing pertinant information about the event that fired this call.
133 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.ArgumentControl
134 * @see org.greenstone.gatherer.cdm.ArgumentContainer
135 */
136 public void actionPerformed(ActionEvent event) {
137 boolean cont = true;
138 if (event.getSource() == ok) {
139 // Clear the current focus to ensure components such as combobox have correctly updated
140 // Loop through each of the controls in the central pane, updating the matching argument as necessary.
141 for(int i = 0; i < central_pane.getComponentCount(); i++) {
142 Component component = central_pane.getComponent(i);
143 if(component instanceof ArgumentControl) {
144 cont = cont && ((ArgumentControl)component).updateArgument();
145 }
146 }
147 if(cont) {
148 success = true;
149 }
150 }
151 if(cont) {
152 dispose();
153 }
154 }
155
156
157 public void addOKButtonActionListener(ActionListener action_listener)
158 {
159 ok.addActionListener(action_listener);
160 }
161
162
163 /** Destructor. */
164 public void destroy() {
165 cancel = null;
166 central_pane = null;
167 //custom_pane = null;
168 //custom = null;
169 data = null;
170 ok = null;
171 self = null;
172 }
173
174 /** Method which actually forces the dialog to be shown on screen.
175 * @return <i>true</i> if the user completed configuration and pressed ok, <i>false</i> otherwise.
176 */
177 public boolean display() {
178 setVisible(true);
179 return success;
180 }
181
182 private void addHeader(String name, Color color) {
183 JPanel header = new JPanel();
184 header.setBackground(color);
185 JPanel inner_pane = new JPanel();
186 inner_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createRaisedBevelBorder()));
187 inner_pane.setBackground(color);
188 JLabel header_label = new JLabel("<html><strong>" + name + "</strong></html>");
189 header_label.setBackground(Configuration.getColor("coloring.collection_heading_background", false));
190 header_label.setHorizontalAlignment(JLabel.CENTER);
191 header_label.setOpaque(true);
192
193 // Layout
194 inner_pane.setLayout(new BorderLayout());
195 inner_pane.add(header_label, BorderLayout.CENTER);
196
197 header.setLayout(new BorderLayout());
198 header.add(inner_pane, BorderLayout.CENTER);
199 central_pane.add(header);
200 }
201
202 /** Method to iterate through the arguments associated with whatever argument container we are building an argument control view for, creating the appropriate controls for each.
203 * @see org.greenstone.gatherer.cdm.Argument
204 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.ArgumentControl
205 */
206 private void generateControls() {
207 // Alternating colours to show inheritance
208 Color colour_one = Configuration.getColor("coloring.collection_heading_background", false);
209 Color colour_two = Configuration.getColor("coloring.collection_tree_background", false);
210 boolean coloured = false;
211 ArrayList arguments = data.getArguments();
212 int total_height = 250;
213 // not currently used
214 //int current_mode = Configuration.getMode();
215
216 String previous_owner = "";
217 if(arguments.size() > 0) {
218 previous_owner = ((Argument) arguments.get(0)).getOwner();
219 addHeader(previous_owner, colour_two);
220 }
221
222 for(int i = 0; i < arguments.size(); i++) {
223 Argument argument = (Argument) arguments.get(i);
224 String owner = argument.getOwner();
225 if(previous_owner != argument.getOwner()) {
226 ///ystem.err.println("previous owner is different from current owner");
227 coloured = !coloured;
228 previous_owner = argument.getOwner();
229 addHeader(previous_owner, (coloured ? colour_one : colour_two));
230 }
231 if(!argument.isHiddenGLI()) {
232 ArgumentControl argument_control = new ArgumentControl(argument, false, null);
233 total_height = total_height - argument_control.getPreferredSize().height;
234 // Create
235 if(coloured) {
236 argument_control.setBackground(colour_one);
237 }
238 else {
239 argument_control.setBackground(colour_two);
240 }
241
242 central_pane.add(argument_control);
243 }
244 }
245 if(total_height > 0) {
246 JPanel filler = new JPanel();
247 filler.setPreferredSize(new Dimension(100, total_height));
248 filler.setSize(new Dimension(100, total_height));
249 central_pane.add(filler);
250 }
251 }
252
253}
Note: See TracBrowser for help on using the repository browser.