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.configuration.preview;
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.configuration.*;
028: import org.openharmonise.him.swing.resourcetree.*;
029: import org.openharmonise.vfs.*;
030: import org.openharmonise.vfs.gui.*;
031: import org.openharmonise.vfs.servers.*;
032:
033: /**
034: * Configuration options for the preview settings.
035: *
036: * @author matt treanor
037: * @version $Revision: 1.1 $
038: *
039: */
040: public class PreviewOptions extends JPanel implements LayoutManager,
041: ActionListener, ApplyChangesListener {
042:
043: /**
044: * Configuration dialog in which these options will appear.
045: */
046: private ConfigDialog m_dialog = null;
047:
048: /**
049: * Tree to choose paths from.
050: */
051: private ResourceTree m_tree = null;
052:
053: /**
054: * Add path button.
055: */
056: private JButton m_addButton = null;
057:
058: /**
059: * Remove path button.
060: */
061: private JButton m_removeButton = null;
062:
063: /**
064: * List of selected paths.
065: */
066: private JTextField m_textField = null;
067:
068: /**
069: * true if the values for this option have changed.
070: */
071: private boolean m_bChanged = false;
072:
073: private String DOC_PREVIEW_PAGE = "DOC_PREVIEW_PAGE";
074: private String m_sPage = null;
075:
076: /**
077: * Constructs a new search in options.
078: *
079: * @param dialog Configuration dialog
080: */
081: public PreviewOptions(ConfigDialog dialog) {
082: super ();
083: this .m_dialog = dialog;
084: this .setup();
085: }
086:
087: /**
088: * Configures this options class.
089: *
090: */
091: private void setup() {
092: this .m_dialog.addApplyChangesListener(this );
093:
094: this .setLayout(this );
095:
096: m_tree = new ResourceTree();
097: m_tree.setShowLeafNodes(true);
098: m_tree.setBorder(BorderFactory.createLineBorder(Color.BLACK));
099:
100: this .m_addButton = new JButton();
101: this .m_addButton.setIcon(IconManager.getInstance().getIcon(
102: "16-command-right.png"));
103: this .m_addButton.setActionCommand("ADD");
104: this .m_addButton.setToolTipText("Add");
105: this .m_addButton.addActionListener(this );
106: this .add(this .m_addButton);
107: this .m_removeButton = new JButton();
108: this .m_removeButton.setIcon(IconManager.getInstance().getIcon(
109: "16-command-left.png"));
110: this .m_removeButton.setActionCommand("REMOVE");
111: this .m_removeButton.setToolTipText("Remove");
112: this .m_removeButton.addActionListener(this );
113: this .add(this .m_removeButton);
114:
115: m_sPage = ConfigStore.getInstance().getPropertyValue(
116: DOC_PREVIEW_PAGE);
117: Server server = ServerList.getInstance().getHarmoniseServer();
118:
119: this .m_textField = new JTextField(m_sPage);
120: m_textField.setBorder(BorderFactory
121: .createLineBorder(Color.BLACK));
122: this .add(this .m_textField);
123:
124: this .add(m_tree);
125:
126: String fontName = "Dialog";
127: int fontSize = 11;
128: Font font = new Font(fontName, Font.PLAIN, fontSize);
129:
130: VirtualFile vfFile = server.getVFS().getVirtualFile(
131: "/webdav/Website/Page Definition").getResource();
132: this .m_tree.addCollection(vfFile);
133: }
134:
135: /* (non-Javadoc)
136: * @see java.awt.Component#getPreferredSize()
137: */
138: public Dimension getPreferredSize() {
139: return new Dimension(this .getParent().getSize().width, 200);
140: }
141:
142: /* (non-Javadoc)
143: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
144: */
145: public void actionPerformed(ActionEvent ae) {
146: if (ae.getActionCommand().equals("ADD")) {
147: VirtualFile vfFile = this .m_tree.getSelectedResource();
148: if (vfFile.isDirectory() == false) {
149: m_sPage = vfFile.getFullPath();
150: this .m_textField.setText(vfFile.getFileName());
151: }
152:
153: this .revalidate();
154: this .m_bChanged = true;
155: this .m_dialog.changesMade();
156: } else if (ae.getActionCommand().equals("REMOVE")) {
157: this .m_textField.setText("");
158: //
159: this .revalidate();
160: this .m_bChanged = true;
161: this .m_dialog.changesMade();
162: }
163: }
164:
165: /* (non-Javadoc)
166: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
167: */
168: public boolean applyChanges() {
169: if (this .m_bChanged) {
170: ConfigStore.getInstance().setProperty(DOC_PREVIEW_PAGE,
171: 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
190: .setSize(this .m_addButton.getPreferredSize());
191: this .m_removeButton.setLocation(170, nHeight + 70);
192:
193: this .m_textField.setSize(120, 20);
194: this .m_textField.setLocation(240, nHeight + 20);
195: this .m_textField.setEditable(false);
196: this .m_textField.setBackground(Color.WHITE);
197: }
198:
199: /* (non-Javadoc)
200: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
201: */
202: public Dimension minimumLayoutSize(Container arg0) {
203: return this .getPreferredSize();
204: }
205:
206: /* (non-Javadoc)
207: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
208: */
209: public Dimension preferredLayoutSize(Container arg0) {
210: return this .getPreferredSize();
211: }
212:
213: /* (non-Javadoc)
214: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
215: */
216: public void removeLayoutComponent(Component arg0) {
217: }
218:
219: /* (non-Javadoc)
220: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
221: */
222: public void addLayoutComponent(String arg0, Component arg1) {
223: }
224:
225: /**
226: * @param arg0
227: */
228: private PreviewOptions(boolean arg0) {
229: super (arg0);
230: }
231:
232: /**
233: * @param arg0
234: */
235: private PreviewOptions(LayoutManager arg0) {
236: super (arg0);
237: }
238:
239: /**
240: * @param arg0
241: * @param arg1
242: */
243: private PreviewOptions(LayoutManager arg0, boolean arg1) {
244: super (arg0, arg1);
245: }
246:
247: /* (non-Javadoc)
248: * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
249: */
250: public void discardChanges() {
251:
252: }
253:
254: }
|