source: trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java@ 12468

Last change on this file since 12468 was 12305, checked in by kjdon, 18 years ago

removed gui.ArgumentControl class and ArgumentConfiguration inner class Argument control, and added a new class cdm/ArgumentControl.

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