KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > serverconfig > PagePreviewConfigOptions


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.serverconfig;
20
21 import java.awt.*;
22 import java.awt.event.*;
23
24 import javax.swing.*;
25
26 import org.openharmonise.him.*;
27 import org.openharmonise.him.editors.preview.*;
28 import org.openharmonise.him.harmonise.*;
29 import org.openharmonise.him.swing.resourcetree.*;
30 import org.openharmonise.vfs.*;
31 import org.openharmonise.vfs.metadata.*;
32 import org.openharmonise.vfs.servers.ServerList;
33 import org.w3c.dom.*;
34 import org.xml.sax.*;
35
36
37 /**
38  *
39  * @author matt treanor
40  * @version $Revision: 1.1 $
41  *
42  */

43 public class PagePreviewConfigOptions extends AbstractPreviewConfigOptions
44         implements TreeViewListener, LayoutManager, ActionListener,
45         MouseListener {
46
47     private int m_nHeight = 30;
48
49     private ResourceTree m_pageTree = null;
50
51     private JButton m_addButton = null;
52
53     private JButton m_removeButton = null;
54     
55     private JButton m_editButton = null;
56
57     private JSpinner m_spinner = null;
58
59     private JTextArea m_dialogLabel = null;
60
61     private JTextArea m_pageLabel = null;
62
63     private JTextArea m_stateLabel = null;
64     
65     private JList m_stateList = null;
66
67     private StateContainer m_stateContainer = null;
68     
69     private StateXmlDialog m_xmlDialog = null;
70
71     public PagePreviewConfigOptions(PreviewConfigDialog dialog) {
72         super(dialog);
73         m_stateContainer = new StateContainer();
74         setup();
75     }
76
77     /**
78      *
79      */

80     private void setup() {
81         setLayout(this);
82         
83         String JavaDoc fontName = "Dialog";
84         int fontSize = 11;
85         Font font = new Font(fontName, Font.PLAIN, fontSize);
86         
87         m_pageTree = new ResourceTree();
88         m_pageTree.addListener(this);
89         m_pageTree.setBorder(BorderFactory.createEtchedBorder());
90         m_pageTree.setShowLeafNodes(true);
91         m_pageTree.setShowApprovedOnly(true);
92         
93 // Put back after layout editing finished
94
AbstractVirtualFileSystem vfs = ServerList.getInstance()
95                 .getHarmoniseServer().getVFS();
96         m_pageTree.addCollection(vfs
97                 .getVirtualFile(HarmonisePaths.PATH_PAGE_TEMPLATES).getResource());
98         add(m_pageTree);
99
100         m_stateList = new JList();
101         refreshJList();
102         add(m_stateList);
103         m_stateList.addMouseListener(this);
104
105         this.m_addButton = new JButton("Add");
106         this.m_addButton.setActionCommand("ADD");
107         this.m_addButton.addActionListener(this);
108         add(this.m_addButton);
109
110         this.m_removeButton = new JButton("Delete");
111         this.m_removeButton.setActionCommand("REMOVE");
112         this.m_removeButton.addActionListener(this);
113         add(this.m_removeButton);
114
115         this.m_editButton = new JButton("Edit");
116         this.m_editButton.setActionCommand("EDIT");
117         this.m_editButton.addActionListener(this);
118         m_editButton.setEnabled(false);
119         add(this.m_editButton);
120         
121         m_pageLabel = new JTextArea("Choose a page");
122         m_pageLabel.setOpaque(false);
123         add(m_pageLabel);
124
125         m_stateLabel = new JTextArea("Choose a state");
126         m_stateLabel.setOpaque(false);
127         add(m_stateLabel);
128
129         this.m_dialogLabel = new JTextArea("Edit the state");
130         m_dialogLabel.setOpaque(false);
131         
132         JFrame frame = new JFrame();
133         m_xmlDialog = new StateXmlDialog(frame, "State xml", this);
134
135     }
136
137     public void refreshJList() {
138         this.m_stateList.setListData(m_stateContainer.getStates().keySet()
139                 .toArray());
140     }
141
142     /**
143      * @return
144      */

145     private PropertyInstance getPropertyInstance() {
146         return null;
147     }
148
149     /*
150      * (non-Javadoc)
151      *
152      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
153      */

154     public void layoutContainer(Container arg0) {
155         int width = getParent().getWidth();
156         int height = getParent().getHeight();
157         setSize(width, height);
158         setLocation(0, 20);
159         setBorder( BorderFactory.createEtchedBorder() );
160
161         m_pageLabel.setSize(150, 20);
162         m_pageLabel.setLocation(10, 10);
163
164         this.m_pageTree.setSize(200, 230);
165         this.m_pageTree.setLocation(10, 30);
166
167         m_stateLabel.setSize(150, 20);
168         m_stateLabel.setLocation(220, 10);
169
170         m_stateList.setSize(230, 200);
171         m_stateList.setLocation(220, 30);
172         m_stateList.setBorder(BorderFactory.createEtchedBorder());
173         
174         this.m_addButton.setSize(70, 20);
175         this.m_addButton.setLocation(220, height-50);
176
177         this.m_removeButton.setSize(70, 20);
178         this.m_removeButton.setLocation(300, height-50);
179         
180         m_editButton.setSize(70,20);
181         m_editButton.setLocation(380, height-50);
182         
183         this.m_dialogLabel.setSize(420, 20);
184         this.m_dialogLabel.setLocation(10, 10);
185
186     }
187
188     /*
189      * (non-Javadoc)
190      *
191      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
192      */

193     public Dimension minimumLayoutSize(Container arg0) {
194         return this.getPreferredSize();
195     }
196
197     /*
198      * (non-Javadoc)
199      *
200      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
201      */

202     public Dimension preferredLayoutSize(Container arg0) {
203         return this.getPreferredSize();
204     }
205
206     /*
207      * (non-Javadoc)
208      *
209      * @see java.awt.Component#getPreferredSize()
210      */

211     public Dimension getPreferredSize() {
212         int nWidth = this.getParent().getWidth() - 40;
213         int nHeight = 170;
214         return new Dimension(nWidth, nHeight);
215     }
216
217     public void mouseClicked(MouseEvent me) {
218         if (me.getClickCount() > 0 && me.getComponent() == m_stateList) {
219             String JavaDoc scenario = (String JavaDoc) m_stateList.getSelectedValue();
220             m_stateContainer.removeMemberFromScenarios();
221             m_stateContainer.addMemberToScenario(scenario);
222             this.m_dialog.changesMade();
223             if(scenario.equalsIgnoreCase("None")){
224                 m_editButton.setEnabled(false);
225             } else {
226                 this.m_editButton.setEnabled(true);
227                 if(me.getClickCount() == 2){
228                     Document stateDoc = m_stateContainer.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.removeFromStates((String JavaDoc) m_stateList.getSelectedValue());
251         if (success) {
252             refreshJList();
253             m_stateContainer.save();
254             setMessage("Removed");
255         }
256     }
257
258     /**
259      *
260      */

261     private void doAdd() {
262         m_xmlDialog.clear();
263         m_xmlDialog.show();
264     }
265     
266     private void doEdit() {
267         String JavaDoc scenario = (String JavaDoc) m_stateList.getSelectedValue();
268         if(scenario != null && scenario.length() > 0) {
269             Document stateDoc = m_stateContainer.getState(scenario);
270             m_xmlDialog.populateState(scenario, stateDoc);
271             m_xmlDialog.show();
272         }
273     }
274     
275     public void addState(String JavaDoc name, String JavaDoc xml) throws SAXException{
276         boolean success = m_stateContainer.addToStates(name, xml);
277         if (success) {
278             m_stateContainer.save();
279             refreshJList();
280         }
281     }
282     
283     private void setMessage(String JavaDoc mess) {
284         m_dialogLabel.setForeground(Color.BLACK);
285         m_dialogLabel.setText(mess);
286     }
287
288     private void setAlertMessage(String JavaDoc mess) {
289         m_dialogLabel.setForeground(Color.RED);
290         m_dialogLabel.setText(mess);
291     }
292
293     /*
294      * (non-Javadoc)
295      *
296      * @see com.simulacramedia.contentmanager.displaycomponents.tree.TreeViewListener#virtualFileSelected(com.simulacramedia.vfs.AbstractVirtualFileSystem,
297      * java.lang.String)
298      */

299     public void virtualFileSelected(AbstractVirtualFileSystem vfs, String JavaDoc sPath) {
300         m_stateContainer.setVFilePath(sPath);
301         String JavaDoc stateName = m_stateContainer.getScenario(sPath);
302         if(stateName != null ){
303             m_stateList.setSelectedValue(stateName, false);
304         } else {
305             m_stateList.clearSelection();
306         }
307     }
308     public void save(){
309         m_stateContainer.save();
310     }
311
312     /*
313      * (non-Javadoc)
314      *
315      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
316      */

317     public void removeLayoutComponent(Component arg0) {
318     }
319
320     /*
321      * (non-Javadoc)
322      *
323      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String,
324      * java.awt.Component)
325      */

326     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
327     }
328
329     /*
330      * (non-Javadoc)
331      *
332      * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
333      */

334     public void mouseEntered(MouseEvent arg0) {
335     }
336
337     /*
338      * (non-Javadoc)
339      *
340      * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
341      */

342     public void mouseExited(MouseEvent arg0) {
343     }
344
345     /*
346      * (non-Javadoc)
347      *
348      * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
349      */

350     public void mousePressed(MouseEvent arg0) {
351     }
352
353     /*
354      * (non-Javadoc)
355      *
356      * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
357      */

358     public void mouseReleased(MouseEvent arg0) {
359     }
360 }
Popular Tags