source: gli/branches/rtl-gli/src/org/greenstone/gatherer/gui/BaseConfigPane.java@ 18297

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

interface updated to display right to left for rtl languages. This code is thanks to Amin Hejazi. It seems to be only partially complete. Amin was working with Greenstone 3 so might have missed some panels

  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 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 this.setComponentOrientation(Dictionary.getOrientation());
78 tree_pane = new JPanel();
79 tree_pane.setComponentOrientation(Dictionary.getOrientation());
80
81 tree = new DesignTree();
82 tree.setComponentOrientation(Dictionary.getOrientation());
83 // Connect
84 tree.addTreeSelectionListener(new TreeListener());
85
86 // Layout
87 tree_pane.setLayout(new BorderLayout());
88 tree_pane.setPreferredSize(TREE_SIZE);
89 JScrollPane scrol_tmp;
90 scrol_tmp = new JScrollPane(tree);
91 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
92 tree_pane.add(scrol_tmp, BorderLayout.CENTER);
93 setLayout(new BorderLayout());
94 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
95
96 add(tree_pane, BorderLayout.LINE_START);
97
98
99 }
100
101 abstract protected Control getSubControls(String type);
102
103 /** Called to cause the components to lay themselves out and be displayed.
104 */
105 public void display() {
106 }
107
108
109 public void gainFocus()
110 {
111 if (cdm == null && Gatherer.c_man.ready()) {
112 // Retrieve the new config manager.
113 cdm = Gatherer.c_man.getCollection().cdm;
114 }
115 if (view != null) {
116 view.gainFocus();
117 }
118 }
119
120
121 public void loseFocus()
122 {
123 if (view != null) {
124 view.loseFocus();
125 }
126 if (cdm != null) {
127 Gatherer.c_man.saveCollection();
128 }
129 }
130
131
132 public void destroy() {
133 tree = null;
134 view = null;
135 }
136
137 /** 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)
138 * @param mode the mode level as an int
139 */
140 public void modeChanged(int mode) {
141 if (cdm != null) {
142 cdm.modeChanged(mode);
143 }
144 }
145
146 /** This method is called whenever the state of the current collection changes.
147 */
148 public void refresh(int refresh_reason, boolean ready)
149 {
150 if (ready) {
151 // Retrieve the new config manager.
152 cdm = Gatherer.c_man.getCollection().cdm;
153 tree.resetModel(Configuration.getMode()); // does this set view??
154 }
155 }
156
157
158 /** Force the display to show a certain pane of controls.
159 * @param type a String giving the name of the information manager or view we wish to display
160 */
161 public void setSelectedView(String type) {
162 tree.setSelectedView(type);
163 }
164
165 /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */
166 private class DesignTree
167 extends JTree {
168 private DesignNode root = null;
169 /** Constructor. Automatically generates all of the nodes, in the order of contents. */
170 public DesignTree() {
171 super();
172 }
173
174 /** Reset the model used by the design page contents tree. This is necessary to hide the partitions entry when in lower detail modes
175 * @param mode the current detail mode as an int
176 */
177 public void resetModel(int mode) {
178 root = new DesignNode("CDM.GUI.Root");
179 // Now add the design categories.
180 for(int i = 0; i < contents.length; i++) {
181 root.add(new DesignNode(contents[i]));
182 }
183 this.setModel(new DefaultTreeModel(root));
184 expandRow(0);
185 setRootVisible(false);
186 setSelectionRow(0);
187 updateUI();
188 }
189 /** Set the current view to the one specified.
190 * @param type the name of the desired view as a String
191 */
192 public void setSelectedView(String type) {
193 type = Dictionary.get(type);
194 for(int i = 0; i < root.getChildCount(); i++) {
195 DesignNode child = (DesignNode) root.getChildAt(i);
196 if(child.toString().equals(type)) {
197 TreePath path = new TreePath(child.getPath());
198 setSelectionPath(path);
199 }
200 }
201 }
202 }
203 /** A tree node that retains a reference to one of the possible design sub-views relating to the different sub-managers. */
204 private class DesignNode
205 extends DefaultMutableTreeNode {
206 /** Constructor.
207 * @param object The <strong>Object</strong> assigned to this node.
208 */
209 public DesignNode(String object) {
210 super(object);
211 }
212 /** Retrieve a textual representation of the object.
213 * @return a String
214 */
215 public String toString() {
216 // return Dictionary.get("CDM.GUI." + (String)getUserObject());
217 return Dictionary.get((String) getUserObject());
218 }
219 }
220 /** Listens for selection changes in the 'contents' tree, and switches to the appropriate view. */
221 private class TreeListener
222 implements TreeSelectionListener {
223 /** Called whenever the selection changes, we must update the view so it matches the node selected.
224 * @param event A <strong>TreeSelectionEvent</strong> containing more information about the tree selection.
225 */
226 public void valueChanged(TreeSelectionEvent event) {
227 if(!tree.isSelectionEmpty()) {
228 TreePath path = tree.getSelectionPath();
229 DesignNode node = (DesignNode)path.getLastPathComponent();
230 String type = (String)node.getUserObject();
231 // Wait begins
232 Gatherer.g_man.wait(true);
233 // Save information in current view
234 if (view != null) { // can we get rid of this??
235 view.loseFocus();
236 remove((JPanel)view);
237 }
238 view_type = type;
239 // Change panes.
240 view = getSubControls(type);
241 if (view != null) {
242 add((JPanel)view, BorderLayout.CENTER);
243 // Update information on visible pane
244 view.gainFocus();
245 }
246 repaint();
247 // Wait ends
248 Gatherer.g_man.wait(false);
249 }
250 }
251 }
252}
Note: See TracBrowser for help on using the repository browser.