001: /*
002: * Copyright (c) 2000, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: */
022:
023: package org.skunk.dav.client.gui;
024:
025: import java.awt.BorderLayout;
026: import java.awt.event.ActionEvent;
027: import java.awt.event.ActionListener; //import java.beans.PropertyChangeEvent;
028: //import java.beans.PropertyChangeListener;
029: import java.util.ArrayList;
030: import java.util.Iterator;
031: import javax.swing.Box;
032: import javax.swing.JButton;
033: import javax.swing.JDialog;
034: import javax.swing.JPanel;
035: import javax.swing.JTabbedPane;
036: import javax.swing.SwingConstants;
037: import javax.swing.SwingUtilities;
038: import javax.swing.event.ChangeEvent;
039: import javax.swing.event.ChangeListener;
040: import org.skunk.trace.Debug;
041:
042: public class PreferencesPanel extends JPanel {
043: private Explorer ex;
044: private JTabbedPane preferencesPane;
045: private JButton tryButton, revertButton, okButton, cancelButton,
046: defaultButton;
047: private JDialog prefDialog;
048: private ArrayList customizers;
049: private ChangeListener dirtListener;
050:
051: public PreferencesPanel() {
052: super ();
053: this .ex = ex;
054: customizers = new ArrayList();
055: dirtListener = new DirtListener();
056: initComponents();
057: }
058:
059: private void initComponents() {
060: setLayout(new BorderLayout());
061: preferencesPane = new JTabbedPane(SwingConstants.TOP);
062: add(preferencesPane, BorderLayout.CENTER);
063: Box buttonBox = Box.createHorizontalBox();
064: buttonBox.add(Box.createHorizontalGlue());
065:
066: tryButton = new JButton(ResourceManager
067: .getMessage(ResourceManager.TRY));
068: tryButton.addActionListener(new TryAction());
069: tryButton.setEnabled(false);
070: buttonBox.add(tryButton);
071: buttonBox.add(Box.createHorizontalGlue());
072:
073: revertButton = new JButton(ResourceManager
074: .getMessage(ResourceManager.REVERT));
075: revertButton.addActionListener(new RevertAction());
076: revertButton.setEnabled(false);
077: buttonBox.add(revertButton);
078: buttonBox.add(Box.createHorizontalGlue());
079:
080: defaultButton = new JButton(ResourceManager
081: .getMessage(ResourceManager.DEFAULT));
082: defaultButton.addActionListener(new DefaultAction());
083: buttonBox.add(defaultButton);
084: buttonBox.add(Box.createHorizontalGlue());
085:
086: okButton = new JButton(ResourceManager
087: .getMessage(ResourceManager.OK));
088: okButton.addActionListener(new OKAction());
089: buttonBox.add(okButton);
090: buttonBox.add(Box.createHorizontalGlue());
091:
092: cancelButton = new JButton(ResourceManager
093: .getMessage(ResourceManager.CANCEL));
094: cancelButton.addActionListener(new CancelAction());
095: buttonBox.add(cancelButton);
096: buttonBox.add(Box.createHorizontalGlue());
097:
098: add(buttonBox, BorderLayout.SOUTH);
099: }
100:
101: public void showDialog() {
102: if (prefDialog == null) {
103: prefDialog = new JDialog();
104: prefDialog.setTitle(ResourceManager
105: .getMessage(ResourceManager.PREFERENCES_KEY));
106: prefDialog.setContentPane(this );
107: prefDialog.pack();
108: }
109: prefDialog.setLocationRelativeTo(ex);
110: prefDialog.setVisible(true);
111: }
112:
113: public PreferencesCustomizer getCurrentCustomizer() {
114: return (PreferencesCustomizer) customizers.get(preferencesPane
115: .getSelectedIndex());
116: }
117:
118: public void setCurrentCustomizer(PreferencesCustomizer currentOne) {
119: if (customizers.contains(currentOne))
120: preferencesPane.setSelectedIndex(customizers
121: .indexOf(currentOne));
122: }
123:
124: public void setCurrentCustomizer(String customizerName) {
125: for (Iterator it = customizers.iterator(); it.hasNext();) {
126: PreferencesCustomizer pc = (PreferencesCustomizer) it
127: .next();
128: if (customizerName.equals(pc.getTitle())) {
129: setCurrentCustomizer(pc);
130: return;
131: }
132: }
133: }
134:
135: public void addPreferencesCustomizer(PreferencesCustomizer pc) {
136: if (!customizers.contains(pc)) {
137: pc.addDirtListener(dirtListener);
138: customizers.add(pc);
139: preferencesPane.addTab(pc.getTitle(), pc.getCustomizer());
140: }
141: }
142:
143: class OKAction implements ActionListener {
144: public void actionPerformed(ActionEvent e) {
145: getCurrentCustomizer().ok();
146: prefDialog.setVisible(false);
147: tryButton.setEnabled(false);
148: revertButton.setEnabled(false);
149: prefDialog.dispose();
150: }
151: }
152:
153: class CancelAction implements ActionListener {
154: public void actionPerformed(ActionEvent e) {
155: getCurrentCustomizer().cancel();
156: prefDialog.setVisible(false);
157: tryButton.setEnabled(false);
158: revertButton.setEnabled(false);
159: prefDialog.dispose();
160: }
161: }
162:
163: class TryAction implements ActionListener {
164: public void actionPerformed(ActionEvent e) {
165: getCurrentCustomizer().tryOn();
166: revertButton.setEnabled(true);
167: tryButton.setEnabled(false);
168: }
169: }
170:
171: class RevertAction implements ActionListener {
172: public void actionPerformed(ActionEvent e) {
173: SwingUtilities.invokeLater(new Runnable() {
174: public void run() {
175: getCurrentCustomizer().revert();
176: revertButton.setEnabled(false);
177: tryButton.setEnabled(false);
178: }
179: });
180: }
181: }
182:
183: class DefaultAction implements ActionListener {
184: public void actionPerformed(ActionEvent e) {
185: getCurrentCustomizer().revertToDefault();
186: }
187: }
188:
189: class DirtListener implements ChangeListener {
190: public void stateChanged(ChangeEvent cheese) {
191: Debug
192: .trace(this , Debug.DP3, "in stateChanged({0})",
193: cheese);
194: Object source = cheese.getSource();
195: if (!source.equals(getCurrentCustomizer())) {
196: Debug.trace(this , Debug.DP3,
197: "change event from weird place: {0}", source);
198: return;
199: }
200: tryButton.setEnabled(getCurrentCustomizer().isDirty());
201: }
202: }
203: }
204:
205: /* $Log: PreferencesPanel.java,v $
206: /* Revision 1.10 2001/07/26 18:35:33 smulloni
207: /* patched HTTPClient so jikes doesn't issue warnings about catching Exception;
208: /* replaced PropertyChangeEvents with ChangeEvents in PreferencesCustomizer and
209: /* related classes; incremented app version to 1.0.2.3.
210: /*
211: /* Revision 1.9 2001/02/06 00:11:18 smulloni
212: /* struggle, perhaps futile, with the TextEditorCustomizer and other implicated
213: /* classes
214: /*
215: /* Revision 1.8 2001/01/05 08:01:12 smulloni
216: /* changes to the connection gui for the Explorer; added depth configurability to
217: /* propfind in the jpython test script; added an experimental "allprop" system
218: /* property which affects the propfind query type
219: /*
220: /* Revision 1.7 2000/12/19 22:36:05 smulloni
221: /* adjustments to preamble.
222: /*
223: /* Revision 1.6 2000/12/03 23:53:26 smulloni
224: /* added license and copyright preamble to java files.
225: /*
226: /* Revision 1.5 2000/11/09 23:34:58 smullyan
227: /* log added to every Java file, with the help of python. Lock stealing
228: /* implemented, and treatment of locks made more robust.
229: /* */
|