Source code: openfuture/editxml/applet/RootPanel.java
1 package openfuture.editxml.applet;
2
3 /*
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.<p>
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.<p>
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br>
17 * http://www.gnu.org/copyleft/lesser.html
18 */
19
20 import java.awt.event.ActionEvent;
21 import java.net.MalformedURLException;
22 import java.net.URL;
23 import java.util.Locale;
24 import java.util.Vector;
25 import javax.swing.JButton;
26 import javax.swing.JSplitPane;
27 import javax.swing.text.Document;
28 import javax.swing.text.StyledEditorKit;
29 import openfuture.editxml.servlet.EditorServletProxy;
30 import openfuture.util.layout.XmFormLayout;
31 import openfuture.util.misc.DocumentHistory;
32
33 /**
34 * Configuration Management Information:
35 * -------------------------------------
36 * $Id: RootPanel.java,v 1.5 2001/09/29 18:05:12 wreissen Exp $
37 *
38 * Version History:
39 * ----------------
40 * $Log: RootPanel.java,v $
41 * Revision 1.5 2001/09/29 18:05:12 wreissen
42 * undo handling moved to class DocumentHistory
43 *
44 * Revision 1.4 2001/09/24 21:34:58 wreissen
45 * toolbar moved to TextEditorPanel
46 *
47 * Revision 1.3 2001/07/22 09:25:57 wreissen
48 * image directory URL and root controller added.
49 *
50 * Revision 1.2 2001/07/08 20:29:02 wreissen
51 * getContent added
52 *
53 * Revision 1.1.1.1 2001/07/08 18:29:29 wreissen
54 * initial version registered ad SourceForge
55 *
56 *
57 */
58
59 /**
60 * Main panel for the XML editor applet.<p>
61 *
62 *
63 * Created: Mon Jul 02 06:18:44 2001
64 *
65 * @author <a href="mailto: wolfgang@openfuture.de">Wolfgang Reissenberger</a>
66 * @version $Revision: 1.5 $
67 */
68
69 public class RootPanel extends AbsPanel {
70
71 protected JButton loadButton;
72 protected JButton saveAsButton;
73 protected JButton saveButton;
74 protected MainPanel main;
75
76 public static final String SAVE_BUTTON = "button.save";
77 public static final String SAVE_AS_BUTTON = "button.save.as";
78 public static final String LOAD_BUTTON = "button.load";
79
80 private NavigationPanel navigation;
81 private RootController rootController;
82
83 /**
84 * Creates a new <code>RootPanel</code> instance.
85 *
86 *
87 * @param servletProxy the proxy to the editor servlet
88 * @param imagedirURL URL of the image directory
89 * @param locale the current locale
90 */
91 public RootPanel (EditorServletProxy servletProxy, String imagedirURL,
92 Locale locale) {
93 super(locale);
94 init(imagedirURL, locale, servletProxy);
95 }
96
97 /**
98 * Initialize the panel.
99 *
100 * @param imagedirURL URL of the image directory
101 * @param locale the current locale
102 * @param servletProxy the proxy to the editor servlet
103 */
104 public void init(String imagedirURL, Locale locale, EditorServletProxy servletProxy) {
105
106 setRootController(new RootController(this, getResourceBundle(),
107 servletProxy));
108
109 super.init(getRootController());
110
111 String[] constraintsTable = {
112 "Root:Splitpane.top = form.top",
113 "Root:Splitpane.left = form.left",
114 "Root:Splitpane.right = form.right",
115 "Root:Splitpane.bottom = Save:Button.top - 10",
116
117 "Load:Button.bottom = Save:Button.bottom",
118 "Load:Button.left = form.left + 20",
119
120 "SaveAs:Button.bottom = Save:Button.bottom",
121 "SaveAs:Button.right = Save:Button.left - 20",
122
123 "Save:Button.bottom = form.bottom - 10",
124 "Save:Button.right = form.right - 20",
125 };
126
127 navigation = new NavigationPanel(getRootController());
128 main = new MainPanel(getRootController(), getResourceBundle(),
129 locale, imagedirURL);
130
131
132 setLayout(new XmFormLayout(constraintsTable));
133
134 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
135 navigation, main);
136 splitPane.setDividerLocation(200);
137
138 saveButton = createButton(SAVE_BUTTON);
139 saveAsButton = createButton(SAVE_AS_BUTTON);
140 loadButton = createButton(LOAD_BUTTON);
141
142 add(splitPane, "Root:Splitpane");
143 add(saveButton, "Save:Button");
144 add(saveAsButton, "SaveAs:Button");
145 add(loadButton, "Load:Button");
146
147 refreshView();
148 }
149
150
151 /**
152 * Activate the save buttons, if a file is loaded.
153 *
154 */
155 public void refreshView() {
156 if (getRootController().getFilename() == null) {
157 saveButton.setEnabled(false);
158 saveAsButton.setEnabled(false);
159 } else {
160 saveButton.setEnabled(true);
161 saveAsButton.setEnabled(true);
162 }
163 }
164
165
166
167 /**
168 * Set the list of keys in the navigation list.
169 *
170 * @param keys list of keys
171 */
172 public void setKeys(Vector keys) {
173 navigation.setKeys(keys);
174 }
175
176
177 /**
178 * Set the content of the editor panel.
179 *
180 * @param content editor content
181 */
182 public void setContent(String content) {
183 main.setContent(content);
184 }
185
186
187 /**
188 * Get the content of the text editor
189 *
190 * @return editor content
191 */
192 public String getContent() {
193 return main.getContent();
194 }
195
196
197
198 /**
199 * Get the value of documentHistory.
200 * @return document history of the main panel
201 */
202 public DocumentHistory getDocumentHistory() {
203 return main.getDocumentHistory();
204 }
205
206 /**
207 * Set the value of document history.
208 * @param v document history of the main panel
209 */
210 public void setDocumentHistory(DocumentHistory v) {
211 main.setDocumentHistory(v);
212 }
213
214
215 /**
216 * Get the main panel
217 *
218 * @return the main palel
219 */
220 public MainPanel getMainPanel() {
221 return main;
222 }
223
224
225
226 /**
227 * Get the value of rootController.
228 * @return value of rootController.
229 */
230 public RootController getRootController() {
231 return rootController;
232 }
233
234 /**
235 * Set the value of rootController.
236 * @param v Value to assign to rootController.
237 */
238 public void setRootController(RootController v) {
239 this.rootController = v;
240 }
241
242
243 }// RootPanel