KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > configuration > preview > PreviewOptions


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.configuration.preview;
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.configuration.*;
28 import org.openharmonise.him.swing.resourcetree.*;
29 import org.openharmonise.vfs.*;
30 import org.openharmonise.vfs.gui.*;
31 import org.openharmonise.vfs.servers.*;
32
33
34 /**
35  * Configuration options for the preview settings.
36  *
37  * @author matt treanor
38  * @version $Revision: 1.1 $
39  *
40  */

41 public class PreviewOptions
42     extends JPanel
43     implements LayoutManager, ActionListener, ApplyChangesListener {
44
45     /**
46      * Configuration dialog in which these options will appear.
47      */

48     private ConfigDialog m_dialog = null;
49     
50     /**
51      * Tree to choose paths from.
52      */

53     private ResourceTree m_tree = null;
54
55     /**
56      * Add path button.
57      */

58     private JButton m_addButton = null;
59     
60     /**
61      * Remove path button.
62      */

63     private JButton m_removeButton = null;
64
65     /**
66      * List of selected paths.
67      */

68     private JTextField m_textField = null;
69     
70     /**
71      * true if the values for this option have changed.
72      */

73     private boolean m_bChanged = false;
74     
75     private String JavaDoc DOC_PREVIEW_PAGE = "DOC_PREVIEW_PAGE";
76     private String JavaDoc m_sPage = null;
77
78     /**
79      * Constructs a new search in options.
80      *
81      * @param dialog Configuration dialog
82      */

83     public PreviewOptions(ConfigDialog dialog) {
84         super();
85         this.m_dialog = dialog;
86         this.setup();
87     }
88     
89     /**
90      * Configures this options class.
91      *
92      */

93     private void setup() {
94         this.m_dialog.addApplyChangesListener(this);
95         
96         this.setLayout(this);
97         
98         m_tree = new ResourceTree();
99         m_tree.setShowLeafNodes(true);
100         m_tree.setBorder(BorderFactory.createLineBorder(Color.BLACK));
101
102         this.m_addButton = new JButton();
103         this.m_addButton.setIcon(
104             IconManager.getInstance().getIcon("16-command-right.png"));
105         this.m_addButton.setActionCommand("ADD");
106         this.m_addButton.setToolTipText("Add");
107         this.m_addButton.addActionListener(this);
108         this.add(this.m_addButton);
109         this.m_removeButton = new JButton();
110         this.m_removeButton.setIcon(
111             IconManager.getInstance().getIcon("16-command-left.png"));
112         this.m_removeButton.setActionCommand("REMOVE");
113         this.m_removeButton.setToolTipText("Remove");
114         this.m_removeButton.addActionListener(this);
115         this.add(this.m_removeButton);
116
117         m_sPage = ConfigStore.getInstance().getPropertyValue(DOC_PREVIEW_PAGE);
118         Server server = ServerList.getInstance().getHarmoniseServer();
119
120         this.m_textField = new JTextField(m_sPage);
121         m_textField.setBorder(BorderFactory.createLineBorder(Color.BLACK));
122         this.add(this.m_textField);
123
124         this.add(m_tree);
125
126         String JavaDoc fontName = "Dialog";
127         int fontSize = 11;
128         Font font = new Font(fontName, Font.PLAIN, fontSize);
129
130         VirtualFile vfFile =
131             server.getVFS().getVirtualFile(
132                 "/webdav/Website/Page Definition").getResource();
133         this.m_tree.addCollection(vfFile);
134     }
135
136     /* (non-Javadoc)
137      * @see java.awt.Component#getPreferredSize()
138      */

139     public Dimension getPreferredSize() {
140         return new Dimension(this.getParent().getSize().width, 200);
141     }
142
143     /* (non-Javadoc)
144      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
145      */

146     public void actionPerformed(ActionEvent ae) {
147         if(ae.getActionCommand().equals("ADD")) {
148             VirtualFile vfFile = this.m_tree.getSelectedResource();
149             if(vfFile.isDirectory() == false){
150                 m_sPage = vfFile.getFullPath();
151                 this.m_textField.setText(vfFile.getFileName());
152             }
153     
154             this.revalidate();
155             this.m_bChanged = true;
156             this.m_dialog.changesMade();
157         } else if(ae.getActionCommand().equals("REMOVE")) {
158             this.m_textField.setText("");
159 //
160
this.revalidate();
161             this.m_bChanged = true;
162             this.m_dialog.changesMade();
163         }
164     }
165
166     /* (non-Javadoc)
167      * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
168      */

169     public boolean applyChanges() {
170         if(this.m_bChanged) {
171             ConfigStore.getInstance().setProperty(DOC_PREVIEW_PAGE, m_sPage);
172
173             this.m_bChanged = false;
174         }
175         return true;
176     }
177
178     /* (non-Javadoc)
179      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
180      */

181     public void layoutContainer(Container arg0) {
182         int nHeight = 0;
183         
184         this.m_tree.setSize(150, 200);
185         this.m_tree.setLocation(10, nHeight + 20);
186
187         this.m_addButton.setSize(this.m_addButton.getPreferredSize());
188         this.m_addButton.setLocation(170, nHeight + 40);
189         this.m_removeButton.setSize(this.m_addButton.getPreferredSize());
190         this.m_removeButton.setLocation(170, nHeight + 70);
191
192         this.m_textField.setSize(120, 20);
193         this.m_textField.setLocation(240, nHeight + 20);
194         this.m_textField.setEditable(false);
195         this.m_textField.setBackground(Color.WHITE);
196     }
197
198     /* (non-Javadoc)
199      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
200      */

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

208     public Dimension preferredLayoutSize(Container arg0) {
209         return this.getPreferredSize();
210     }
211
212     /* (non-Javadoc)
213      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
214      */

215     public void removeLayoutComponent(Component arg0) {
216     }
217
218     /* (non-Javadoc)
219      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
220      */

221     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
222     }
223
224     /**
225      * @param arg0
226      */

227     private PreviewOptions(boolean arg0) {
228         super(arg0);
229     }
230
231     /**
232      * @param arg0
233      */

234     private PreviewOptions(LayoutManager arg0) {
235         super(arg0);
236     }
237
238     /**
239      * @param arg0
240      * @param arg1
241      */

242     private PreviewOptions(LayoutManager arg0, boolean arg1) {
243         super(arg0, arg1);
244     }
245
246     /* (non-Javadoc)
247      * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
248      */

249     public void discardChanges() {
250
251     }
252
253 }
254
Popular Tags