001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.serverconfig;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023:
024: import javax.swing.*;
025:
026: import org.openharmonise.him.*;
027: import org.openharmonise.him.editors.preview.*;
028: import org.openharmonise.him.harmonise.*;
029: import org.openharmonise.him.swing.resourcetree.*;
030: import org.openharmonise.vfs.*;
031: import org.openharmonise.vfs.metadata.*;
032: import org.openharmonise.vfs.servers.ServerList;
033: import org.w3c.dom.*;
034: import org.xml.sax.*;
035:
036: /**
037: *
038: * @author matt treanor
039: * @version $Revision: 1.1 $
040: *
041: */
042: public class PagePreviewConfigOptions extends
043: AbstractPreviewConfigOptions implements TreeViewListener,
044: LayoutManager, ActionListener, MouseListener {
045:
046: private int m_nHeight = 30;
047:
048: private ResourceTree m_pageTree = null;
049:
050: private JButton m_addButton = null;
051:
052: private JButton m_removeButton = null;
053:
054: private JButton m_editButton = null;
055:
056: private JSpinner m_spinner = null;
057:
058: private JTextArea m_dialogLabel = null;
059:
060: private JTextArea m_pageLabel = null;
061:
062: private JTextArea m_stateLabel = null;
063:
064: private JList m_stateList = null;
065:
066: private StateContainer m_stateContainer = null;
067:
068: private StateXmlDialog m_xmlDialog = null;
069:
070: public PagePreviewConfigOptions(PreviewConfigDialog dialog) {
071: super (dialog);
072: m_stateContainer = new StateContainer();
073: setup();
074: }
075:
076: /**
077: *
078: */
079: private void setup() {
080: setLayout(this );
081:
082: String fontName = "Dialog";
083: int fontSize = 11;
084: Font font = new Font(fontName, Font.PLAIN, fontSize);
085:
086: m_pageTree = new ResourceTree();
087: m_pageTree.addListener(this );
088: m_pageTree.setBorder(BorderFactory.createEtchedBorder());
089: m_pageTree.setShowLeafNodes(true);
090: m_pageTree.setShowApprovedOnly(true);
091:
092: // Put back after layout editing finished
093: AbstractVirtualFileSystem vfs = ServerList.getInstance()
094: .getHarmoniseServer().getVFS();
095: m_pageTree.addCollection(vfs.getVirtualFile(
096: HarmonisePaths.PATH_PAGE_TEMPLATES).getResource());
097: add(m_pageTree);
098:
099: m_stateList = new JList();
100: refreshJList();
101: add(m_stateList);
102: m_stateList.addMouseListener(this );
103:
104: this .m_addButton = new JButton("Add");
105: this .m_addButton.setActionCommand("ADD");
106: this .m_addButton.addActionListener(this );
107: add(this .m_addButton);
108:
109: this .m_removeButton = new JButton("Delete");
110: this .m_removeButton.setActionCommand("REMOVE");
111: this .m_removeButton.addActionListener(this );
112: add(this .m_removeButton);
113:
114: this .m_editButton = new JButton("Edit");
115: this .m_editButton.setActionCommand("EDIT");
116: this .m_editButton.addActionListener(this );
117: m_editButton.setEnabled(false);
118: add(this .m_editButton);
119:
120: m_pageLabel = new JTextArea("Choose a page");
121: m_pageLabel.setOpaque(false);
122: add(m_pageLabel);
123:
124: m_stateLabel = new JTextArea("Choose a state");
125: m_stateLabel.setOpaque(false);
126: add(m_stateLabel);
127:
128: this .m_dialogLabel = new JTextArea("Edit the state");
129: m_dialogLabel.setOpaque(false);
130:
131: JFrame frame = new JFrame();
132: m_xmlDialog = new StateXmlDialog(frame, "State xml", this );
133:
134: }
135:
136: public void refreshJList() {
137: this .m_stateList.setListData(m_stateContainer.getStates()
138: .keySet().toArray());
139: }
140:
141: /**
142: * @return
143: */
144: private PropertyInstance getPropertyInstance() {
145: return null;
146: }
147:
148: /*
149: * (non-Javadoc)
150: *
151: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
152: */
153: public void layoutContainer(Container arg0) {
154: int width = getParent().getWidth();
155: int height = getParent().getHeight();
156: setSize(width, height);
157: setLocation(0, 20);
158: setBorder(BorderFactory.createEtchedBorder());
159:
160: m_pageLabel.setSize(150, 20);
161: m_pageLabel.setLocation(10, 10);
162:
163: this .m_pageTree.setSize(200, 230);
164: this .m_pageTree.setLocation(10, 30);
165:
166: m_stateLabel.setSize(150, 20);
167: m_stateLabel.setLocation(220, 10);
168:
169: m_stateList.setSize(230, 200);
170: m_stateList.setLocation(220, 30);
171: m_stateList.setBorder(BorderFactory.createEtchedBorder());
172:
173: this .m_addButton.setSize(70, 20);
174: this .m_addButton.setLocation(220, height - 50);
175:
176: this .m_removeButton.setSize(70, 20);
177: this .m_removeButton.setLocation(300, height - 50);
178:
179: m_editButton.setSize(70, 20);
180: m_editButton.setLocation(380, height - 50);
181:
182: this .m_dialogLabel.setSize(420, 20);
183: this .m_dialogLabel.setLocation(10, 10);
184:
185: }
186:
187: /*
188: * (non-Javadoc)
189: *
190: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
191: */
192: public Dimension minimumLayoutSize(Container arg0) {
193: return this .getPreferredSize();
194: }
195:
196: /*
197: * (non-Javadoc)
198: *
199: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
200: */
201: public Dimension preferredLayoutSize(Container arg0) {
202: return this .getPreferredSize();
203: }
204:
205: /*
206: * (non-Javadoc)
207: *
208: * @see java.awt.Component#getPreferredSize()
209: */
210: public Dimension getPreferredSize() {
211: int nWidth = this .getParent().getWidth() - 40;
212: int nHeight = 170;
213: return new Dimension(nWidth, nHeight);
214: }
215:
216: public void mouseClicked(MouseEvent me) {
217: if (me.getClickCount() > 0 && me.getComponent() == m_stateList) {
218: String scenario = (String) m_stateList.getSelectedValue();
219: m_stateContainer.removeMemberFromScenarios();
220: m_stateContainer.addMemberToScenario(scenario);
221: this .m_dialog.changesMade();
222: if (scenario.equalsIgnoreCase("None")) {
223: m_editButton.setEnabled(false);
224: } else {
225: this .m_editButton.setEnabled(true);
226: if (me.getClickCount() == 2) {
227: Document stateDoc = m_stateContainer
228: .getState(scenario);
229: m_xmlDialog.populateState(scenario, stateDoc);
230: m_xmlDialog.show();
231: }
232: }
233: }
234: }
235:
236: public void actionPerformed(ActionEvent ae) {
237: if (ae.getActionCommand().equals("ADD")) {
238: doAdd();
239: } else if (ae.getActionCommand().equals("REMOVE")) {
240: doRemove();
241: } else if (ae.getActionCommand().equals("EDIT")) {
242: doEdit();
243: }
244: }
245:
246: /**
247: *
248: */
249: private void doRemove() {
250: boolean success = m_stateContainer
251: .removeFromStates((String) m_stateList
252: .getSelectedValue());
253: if (success) {
254: refreshJList();
255: m_stateContainer.save();
256: setMessage("Removed");
257: }
258: }
259:
260: /**
261: *
262: */
263: private void doAdd() {
264: m_xmlDialog.clear();
265: m_xmlDialog.show();
266: }
267:
268: private void doEdit() {
269: String scenario = (String) m_stateList.getSelectedValue();
270: if (scenario != null && scenario.length() > 0) {
271: Document stateDoc = m_stateContainer.getState(scenario);
272: m_xmlDialog.populateState(scenario, stateDoc);
273: m_xmlDialog.show();
274: }
275: }
276:
277: public void addState(String name, String xml) throws SAXException {
278: boolean success = m_stateContainer.addToStates(name, xml);
279: if (success) {
280: m_stateContainer.save();
281: refreshJList();
282: }
283: }
284:
285: private void setMessage(String mess) {
286: m_dialogLabel.setForeground(Color.BLACK);
287: m_dialogLabel.setText(mess);
288: }
289:
290: private void setAlertMessage(String mess) {
291: m_dialogLabel.setForeground(Color.RED);
292: m_dialogLabel.setText(mess);
293: }
294:
295: /*
296: * (non-Javadoc)
297: *
298: * @see com.simulacramedia.contentmanager.displaycomponents.tree.TreeViewListener#virtualFileSelected(com.simulacramedia.vfs.AbstractVirtualFileSystem,
299: * java.lang.String)
300: */
301: public void virtualFileSelected(AbstractVirtualFileSystem vfs,
302: String sPath) {
303: m_stateContainer.setVFilePath(sPath);
304: String stateName = m_stateContainer.getScenario(sPath);
305: if (stateName != null) {
306: m_stateList.setSelectedValue(stateName, false);
307: } else {
308: m_stateList.clearSelection();
309: }
310: }
311:
312: public void save() {
313: m_stateContainer.save();
314: }
315:
316: /*
317: * (non-Javadoc)
318: *
319: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
320: */
321: public void removeLayoutComponent(Component arg0) {
322: }
323:
324: /*
325: * (non-Javadoc)
326: *
327: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String,
328: * java.awt.Component)
329: */
330: public void addLayoutComponent(String arg0, Component arg1) {
331: }
332:
333: /*
334: * (non-Javadoc)
335: *
336: * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
337: */
338: public void mouseEntered(MouseEvent arg0) {
339: }
340:
341: /*
342: * (non-Javadoc)
343: *
344: * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
345: */
346: public void mouseExited(MouseEvent arg0) {
347: }
348:
349: /*
350: * (non-Javadoc)
351: *
352: * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
353: */
354: public void mousePressed(MouseEvent arg0) {
355: }
356:
357: /*
358: * (non-Javadoc)
359: *
360: * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
361: */
362: public void mouseReleased(MouseEvent arg0) {
363: }
364: }
|