source: trunk/gli/src/org/greenstone/gatherer/gui/BaseConfigPane.java@ 12730

Last change on this file since 12730 was 12143, checked in by kjdon, 18 years ago

removed some comments that weren't needed

  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 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: John Thompson, 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
39import java.awt.*;
40import java.io.*;
41import java.util.*;
42import javax.swing.*;
43import javax.swing.event.*;
44import javax.swing.tree.*;
45import org.greenstone.gatherer.Configuration;
46import org.greenstone.gatherer.DebugStream;
47import org.greenstone.gatherer.Dictionary;
48import org.greenstone.gatherer.Gatherer;
49import org.greenstone.gatherer.cdm.CollectionDesignManager;
50import org.greenstone.gatherer.cdm.Control;
51
52/** This class is responsible for generating the necessary GUI components. It does this by calling the getEditControls() method of the appropriate class (i.e. IndexManager for index related edits). It also is in charge of correctly adding (and removing) listeners, using phrases from the <strong>Dictionary</strong> rather than the text keys inserted in the component classes, and several other aspects of the design page, including the config file section tree.
53
54/** This is a base class for Design and Format panes, which are very similar except that they have different components. */
55public abstract class BaseConfigPane
56 extends JPanel {
57
58 /* This should list the contents of the contents */
59 protected String contents[];
60
61 /** The preferred size of the contents tree. */
62 static final private Dimension TREE_SIZE = new Dimension(200, 500);
63
64 /** The panel apon which is rendered the currently selected section screen. */
65 protected Control view = null;
66 protected String view_type = null;
67 /** The collection manager is responsible for parsing in, and allowing the editing of, a single collections configuration file. */
68 protected CollectionDesignManager cdm = null;
69 /** A tree to serve as a 'table of contents' for this design tool. We decided on a tree rather than a list, as it allows us to break sections into subsections if they become to complicated. */
70 protected DesignTree tree;
71 protected JPanel tree_pane;
72 /** The constructor. */
73 public BaseConfigPane() {
74 super();
75 DebugStream.println("BaseConfigPane: Main GUI components created.");
76 // Creation
77 tree_pane = new JPanel();
78
79 tree = new DesignTree();
80
81 // Connect
82 tree.addTreeSelectionListener(new TreeListener());
83
84 // Layout
85 tree_pane.setLayout(new BorderLayout());
86 tree_pane.setPreferredSize(TREE_SIZE);
87 tree_pane.add(new JScrollPane(tree), BorderLayout.CENTER);
88 setLayout(new BorderLayout());
89 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
90
91 add(tree_pane, BorderLayout.WEST);
92
93
94 }
95
96 abstract protected Control getSubControls(String type);
97
98 /** Called to cause the components to lay themselves out and be displayed.
99 */
100 public void display() {
101 }
102
103 public void gainFocus() {
104 if (cdm == null && Gatherer.c_man.ready()) {
105 // Retrieve the new config manager.
106 cdm = Gatherer.c_man.getCollection().cdm;
107 }
108 if (view != null) {
109 view.gainFocus();
110 }
111
112 }
113
114 public void loseFocus() {
115 if (cdm != null) {
116 cdm.save(false);
117 }
118 if (view != null) {
119 view.loseFocus();
120 }
121
122 }
123
124 public void destroy() {
125 tree = null;
126 view = null;
127
128 }
129
130 /** Called whenever the detail mode changes to ensure the filters are at an appropriate level (ie only editable by those that understand regular expression matching)
131 * @param mode the mode level as an int
132 */
133 public void modeChanged(int mode) {
134 if (cdm != null) {
135 cdm.modeChanged(mode);
136 }
137 }
138
139 /** This method is called whenever the state of the current collection changes.
140 */
141 public void refresh(int refresh_reason, boolean ready)
142 {
143 if (ready) {
144 // Retrieve the new config manager.
145 cdm = Gatherer.c_man.getCollection().cdm;
146 tree.resetModel(Configuration.getMode()); // does this set view??
147 }
148 }
149
150 public void saveConfiguration() {
151 if (cdm != null) {
152 cdm.save(true);
153 }
154 }
155
156
157 /** Force the display to show a certain pane of controls.
158 * @param type a String giving the name of the information manager or view we wish to display
159 */
160 public void setSelectedView(String type) {
161 tree.setSelectedView(type);
162 }
163
164 /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */
165 private class DesignTree
166 extends JTree {
167 private DesignNode root = null;
168 /** Constructor. Automatically generates all of the nodes, in the order of contents. */
169 public DesignTree() {
170 super();
171 }
172
173 /** Reset the model used by the design page contents tree. This is necessary to hide the partitions entry when in lower detail modes
174 * @param mode the current detail mode as an int
175 */
176 public void resetModel(int mode) {
177 root = new DesignNode("CDM.GUI.Root");
178 // Now add the design categories.
179 for(int i = 0; i < contents.length; i++) {
180 root.add(new DesignNode(contents[i]));
181 }
182 this.setModel(new DefaultTreeModel(root));
183 expandRow(0);
184 setRootVisible(false);
185 setSelectionRow(0);
186 updateUI();
187 }
188 /** Set the current view to the one specified.
189 * @param type the name of the desired view as a String
190 */
191 public void setSelectedView(String type) {
192 type = Dictionary.get(type);
193 for(int i = 0; i < root.getChildCount(); i++) {
194 DesignNode child = (DesignNode) root.getChildAt(i);
195 if(child.toString().equals(type)) {
196 TreePath path = new TreePath(child.getPath());
197 setSelectionPath(path);
198 }
199 }
200 }
201 }
202 /** A tree node that retains a reference to one of the possible design sub-views relating to the different sub-managers. */
203 private class DesignNode
204 extends DefaultMutableTreeNode {
205 /** Constructor.
206 * @param object The <strong>Object</strong> assigned to this node.
207 */
208 public DesignNode(String object) {
209 super(object);
210 }
211 /** Retrieve a textual representation of the object.
212 * @return a String
213 */
214 public String toString() {
215 // return Dictionary.get("CDM.GUI." + (String)getUserObject());
216 return Dictionary.get((String) getUserObject());
217 }
218 }
219 /** Listens for selection changes in the 'contents' tree, and switches to the appropriate view. */
220 private class TreeListener
221 implements TreeSelectionListener {
222 /** Called whenever the selection changes, we must update the view so it matches the node selected.
223 * @param event A <strong>TreeSelectionEvent</strong> containing more information about the tree selection.
224 */
225 public void valueChanged(TreeSelectionEvent event) {
226 if(!tree.isSelectionEmpty()) {
227 TreePath path = tree.getSelectionPath();
228 DesignNode node = (DesignNode)path.getLastPathComponent();
229 String type = (String)node.getUserObject();
230 // Wait begins
231 Gatherer.g_man.wait(true);
232 // Save information in current view
233 if (view != null) { // can we get rid of this??
234 view.loseFocus();
235 remove((JPanel)view);
236 }
237 view_type = type;
238 // Change panes.
239 view = getSubControls(type);
240 if (view != null) {
241 add((JPanel)view, BorderLayout.CENTER);
242 // Update information on visible pane
243 view.gainFocus();
244 }
245 repaint();
246 // Wait ends
247 Gatherer.g_man.wait(false);
248 }
249 }
250 }
251}
Note: See TracBrowser for help on using the repository browser.