source: gli/branches/rtl-gli/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java@ 18368

Last change on this file since 18368 was 18352, checked in by kjdon, 15 years ago

updated the rtl-gli branch with files from trunk. Result of a merge 14807:18318

  • Property svn:keywords set to Author Date Id Revision
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 content_pane.add(new JScrollPane(central_pane), BorderLayout.CENTER);
118 content_pane.add(button_pane, BorderLayout.SOUTH);
119
120 // Now generate a set of controls for each of the arguments.
121 generateControls();
122
123 // Display on screen.
124 Dimension screen_size = Configuration.screen_size;
125 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
126 screen_size = null;
127 }
128
129 /** 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.
130 * @param event An <strong>ActionEvent</strong> containing pertinant information about the event that fired this call.
131 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.ArgumentControl
132 * @see org.greenstone.gatherer.cdm.ArgumentContainer
133 */
134 public void actionPerformed(ActionEvent event) {
135 boolean cont = true;
136 if (event.getSource() == ok) {
137 // Clear the current focus to ensure components such as combobox have correctly updated
138 // Loop through each of the controls in the central pane, updating the matching argument as necessary.
139 for(int i = 0; i < central_pane.getComponentCount(); i++) {
140 Component component = central_pane.getComponent(i);
141 if(component instanceof ArgumentControl) {
142 cont = cont && ((ArgumentControl)component).updateArgument();
143 }
144 }
145 if(cont) {
146 success = true;
147 }
148 }
149 if(cont) {
150 dispose();
151 }
152 }
153
154
155 public void addOKButtonActionListener(ActionListener action_listener)
156 {
157 ok.addActionListener(action_listener);
158 }
159
160
161 /** Destructor. */
162 public void destroy() {
163 cancel = null;
164 central_pane = null;
165 //custom_pane = null;
166 //custom = null;
167 data = null;
168 ok = null;
169 self = null;
170 }
171
172 /** Method which actually forces the dialog to be shown on screen.
173 * @return <i>true</i> if the user completed configuration and pressed ok, <i>false</i> otherwise.
174 */
175 public boolean display() {
176 setVisible(true);
177 return success;
178 }
179
180 private void addHeader(String name, Color color) {
181 JPanel header = new JPanel();
182 header.setBackground(color);
183 JPanel inner_pane = new JPanel();
184 inner_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createRaisedBevelBorder()));
185 inner_pane.setBackground(color);
186 JLabel header_label = new JLabel("<html><strong>" + name + "</strong></html>");
187 header_label.setBackground(Configuration.getColor("coloring.collection_heading_background", false));
188 header_label.setHorizontalAlignment(JLabel.CENTER);
189 header_label.setOpaque(true);
190
191 // Layout
192 inner_pane.setLayout(new BorderLayout());
193 inner_pane.add(header_label, BorderLayout.CENTER);
194
195 header.setLayout(new BorderLayout());
196 header.add(inner_pane, BorderLayout.CENTER);
197 central_pane.add(header);
198 }
199
200 /** 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.
201 * @see org.greenstone.gatherer.cdm.Argument
202 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration.ArgumentControl
203 */
204 private void generateControls() {
205 // Alternating colours to show inheritance
206 Color colour_one = Configuration.getColor("coloring.collection_heading_background", false);
207 Color colour_two = Configuration.getColor("coloring.collection_tree_background", false);
208 boolean coloured = false;
209 ArrayList arguments = data.getArguments();
210 int total_height = 250;
211 int current_mode = Configuration.getMode();
212
213 String previous_owner = "";
214 if(arguments.size() > 0) {
215 previous_owner = ((Argument) arguments.get(0)).getOwner();
216 addHeader(previous_owner, colour_two);
217 }
218
219 for(int i = 0; i < arguments.size(); i++) {
220 Argument argument = (Argument) arguments.get(i);
221 String owner = argument.getOwner();
222 if(previous_owner != argument.getOwner()) {
223 ///ystem.err.println("previous owner is different from current owner");
224 coloured = !coloured;
225 previous_owner = argument.getOwner();
226 addHeader(previous_owner, (coloured ? colour_one : colour_two));
227 }
228 if(!argument.isHiddenGLI() && (current_mode > Configuration.LIBRARIAN_MODE || !(argument.getType() == Argument.REGEXP))) {
229 ArgumentControl argument_control = new ArgumentControl(argument, false, null);
230 total_height = total_height - argument_control.getPreferredSize().height;
231 // Create
232 if(coloured) {
233 argument_control.setBackground(colour_one);
234 }
235 else {
236 argument_control.setBackground(colour_two);
237 }
238
239 central_pane.add(argument_control);
240 }
241 }
242 if(total_height > 0) {
243 JPanel filler = new JPanel();
244 filler.setPreferredSize(new Dimension(100, total_height));
245 filler.setSize(new Dimension(100, total_height));
246 central_pane.add(filler);
247 }
248 }
249
250}
Note: See TracBrowser for help on using the repository browser.