KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > changelog > wizard > HtmlPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Ralph Krueger.
17  */

18 package org.netbeans.modules.changelog.wizard;
19
20 /**
21  *
22  * @author ralph
23  */

24
25 import org.openide.util.*;
26 import org.openide.*;
27 import org.openide.filesystems.*;
28 import org.openide.loaders.*;
29 import org.openide.modules.*;
30
31 import javax.swing.event.*;
32 import javax.swing.*;
33 import java.util.*;
34 import org.netbeans.modules.changelog.*;
35 import org.netbeans.modules.changelog.html.*;
36
37
38 public class HtmlPanel extends javax.swing.JPanel JavaDoc {
39
40     private HtmlPanelCustomizer customizer;
41     private ChangeLogHTMLService[] array;
42     private boolean loadingSemafore = false;
43     /** Creates new form FilterPanel */
44     public HtmlPanel() {
45         initComponents();
46         putClientProperty ("WizardPanel_contentSelectedIndex", new Integer JavaDoc (2)); // NOI18N
47
customizer = new HtmlPanelCustomizer();
48         customizer.disableEditing(true);
49         pnlCustom.add(customizer, java.awt.BorderLayout.CENTER);
50         
51         array = null;
52         
53         comServerDef.addActionListener(new java.awt.event.ActionListener JavaDoc() {
54             public void actionPerformed(java.awt.event.ActionEvent JavaDoc event) {
55                 if (!loadingSemafore) {
56                     changeItem();
57                 }
58             }
59         });
60         btnEdit.addActionListener(new java.awt.event.ActionListener JavaDoc() {
61             public void actionPerformed(java.awt.event.ActionEvent JavaDoc event) {
62                 doEdit();
63             }
64         });
65         btnSaveAs.addActionListener(new java.awt.event.ActionListener JavaDoc() {
66             public void actionPerformed(java.awt.event.ActionEvent JavaDoc event) {
67                 doSaveAs();
68             }
69         });
70     }
71     
72     /** This method is called from within the constructor to
73      * initialize the form.
74      * WARNING: Do NOT modify this code. The content of this method is
75      * always regenerated by the Form Editor.
76      */

77     private void initComponents() {//GEN-BEGIN:initComponents
78
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
79
80         lblServerDef = new javax.swing.JLabel JavaDoc();
81         comServerDef = new javax.swing.JComboBox JavaDoc();
82         btnEdit = new javax.swing.JButton JavaDoc();
83         btnSaveAs = new javax.swing.JButton JavaDoc();
84         pnlCustom = new javax.swing.JPanel JavaDoc();
85
86         setLayout(new java.awt.GridBagLayout JavaDoc());
87
88         setMinimumSize(new java.awt.Dimension JavaDoc(400, 200));
89         setPreferredSize(new java.awt.Dimension JavaDoc(600, 300));
90         getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACSN_HtmlPanel"));
91         getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACSD_HtmlPanel"));
92         lblServerDef.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACS_lblServerDef_mnc").charAt(0));
93         lblServerDef.setLabelFor(comServerDef);
94         lblServerDef.setText(org.openide.util.NbBundle.getBundle(HtmlPanel.class).getString("HtmlPanel.lblServerDef.text"));
95         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
96         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
97         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
98         add(lblServerDef, gridBagConstraints);
99
100         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
101         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
102         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 0);
103         add(comServerDef, gridBagConstraints);
104         comServerDef.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACSD_comServerDef"));
105
106         btnEdit.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACS_btnEdit_mnc").charAt(0));
107         btnEdit.setText(org.openide.util.NbBundle.getBundle(HtmlPanel.class).getString("HtmlPanel.btnEdit.text"));
108         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
109         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
110         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 0);
111         add(btnEdit, gridBagConstraints);
112         btnEdit.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACSD_btnEdit"));
113
114         btnSaveAs.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACS_btnSaveAs_mnc").charAt(0));
115         btnSaveAs.setText(org.openide.util.NbBundle.getBundle(HtmlPanel.class).getString("HtmlPanel.btnSave.text"));
116         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
117         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
118         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 12);
119         add(btnSaveAs, gridBagConstraints);
120         btnSaveAs.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/changelog/wizard/Bundle").getString("ACSD_btnSaveAs"));
121
122         pnlCustom.setLayout(new java.awt.BorderLayout JavaDoc());
123
124         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
125         gridBagConstraints.gridx = 0;
126         gridBagConstraints.gridy = 1;
127         gridBagConstraints.gridwidth = 4;
128         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
129         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
130         gridBagConstraints.weighty = 0.5;
131         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 12, 12);
132         add(pnlCustom, gridBagConstraints);
133
134     }//GEN-END:initComponents
135

136     private void changeItem() {
137         int index = comServerDef.getSelectedIndex();
138         customizer.setObject(array[index]);
139         customizer.disableEditing(true);
140     }
141     
142     private void doEdit() {
143         customizer.disableEditing(false);
144     }
145     
146     private void doSaveAs() {
147         // optionally:
148
int index = comServerDef.getSelectedIndex();
149         NotifyDescriptor.InputLine dial = new NotifyDescriptor.InputLine("Name:", "Save As", NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE);
150         Object JavaDoc ret = TopManager.getDefault().notify(dial);
151         if (ret.equals(NotifyDescriptor.OK_OPTION)) {
152             ChangeLogHTMLService service = array[index];
153             service.setName(dial.getInputText());
154             DataFolder f = DataFolder.findFolder(
155                 Repository.getDefault().getDefaultFileSystem().findResource("Services/ChangeLogHtmlType")); //NOI18N
156
ModuleInfo m = null;
157             Iterator it = Lookup.getDefault().lookup(
158                 new Lookup.Template(ModuleInfo.class,
159                     null, null)).allInstances().iterator();
160             while (it.hasNext()) {
161                 ModuleInfo _m = (ModuleInfo)it.next();
162                 if (_m.getCodeNameBase().equals("org.netbeans.modules.changelog")) { //NOI18N
163
m = _m;
164                     break;
165                 }
166             }
167             if (m == null) throw new IllegalStateException JavaDoc();
168             try {
169                 InstanceDataObject ido = InstanceDataObject.create(f, null, service, m, true);
170             } catch (java.io.IOException JavaDoc exc) {
171                 ErrorManager.getDefault().log(ErrorManager.USER, "Cannot save new Server Info");
172                 return;
173             }
174         }
175         loadCombo();
176         comServerDef.setSelectedIndex(array.length - 1);
177         changeItem();
178     }
179     
180     private void loadCombo() {
181         //INIT combobox..
182
loadingSemafore = true;
183         Lookup.Template template = new Lookup.Template(ChangeLogHTMLService.class);
184         Lookup.Result result = Lookup.getDefault().lookup(template);
185         Collection coll = result.allInstances();
186         array = new ChangeLogHTMLService[coll.size() + 1];
187         String JavaDoc[] names = new String JavaDoc[coll.size() + 1];
188         Iterator it = coll.iterator();
189         int count = 1;
190         while (it.hasNext()) {
191             ChangeLogHTMLService serv = (ChangeLogHTMLService)it.next();
192             array[count] = (ChangeLogHTMLService)serv.createClone();
193             names[count] = serv.getName();
194             count = count + 1;
195         }
196         array[0] = new ChangeLogHTMLService();
197         names[0] = org.openide.util.NbBundle.getBundle(HtmlPanel.class).getString("No_server_specific_processing");
198         comServerDef.setModel(new DefaultComboBoxModel(names));
199         loadingSemafore = false;
200         
201     }
202     
203
204     
205     // Variables declaration - do not modify//GEN-BEGIN:variables
206
private javax.swing.JButton JavaDoc btnSaveAs;
207     private javax.swing.JComboBox JavaDoc comServerDef;
208     private javax.swing.JButton JavaDoc btnEdit;
209     private javax.swing.JPanel JavaDoc pnlCustom;
210     private javax.swing.JLabel JavaDoc lblServerDef;
211     // End of variables declaration//GEN-END:variables
212

213
214     public static class Panel implements org.openide.WizardDescriptor.Panel {
215
216         private HtmlPanel panel;
217         private String JavaDoc name;
218
219
220         public Panel (String JavaDoc name) {
221             this.name = name;
222         }
223
224         /** Get the component displayed in this panel.
225          * @return the component
226          */

227         public synchronized java.awt.Component JavaDoc getComponent() {
228             if (this.panel == null) {
229                 this.panel = new HtmlPanel();
230                 this.panel.setName (this.name);
231             }
232             return this.panel;
233         }
234
235         /** Help for this panel.
236          * When the panel is active, this is used as the help for the wizard dialog.
237          * @return the help or <code>null</code> if no help is supplied
238          */

239         public HelpCtx getHelp() {
240             return new HelpCtx(this.getClass());
241         }
242
243         /** Add a listener to changes of the panel's validity.
244          * @param l the listener to add
245          * @see #isValid
246          */

247         public void addChangeListener(ChangeListener l) {
248         }
249
250         /** Remove a listener to changes of the panel's validity.
251          * @param l the listener to remove
252          */

253         public void removeChangeListener(ChangeListener l) {
254         }
255
256         public boolean isValid() {
257             return true;
258         }
259
260         /** Provides the wizard panel with the opportunity to update the
261          * settings with its current customized state.
262          * Rather than updating its settings with every change in the GUI, it should collect them,
263          * and then only save them when requested to by this method.
264          * Also, the original settings passed to {@link #readSettings} should not be modified (mutated);
265          * rather, the (copy) passed in here should be mutated according to the collected changes.
266          * This method can be called multiple times on one instance of <code>WizardDescriptor.Panel</code>.
267          * @param settings the object representing a settings of the wizard
268          */

269         public void storeSettings(Object JavaDoc settings) {
270             if (settings instanceof ChangeLogProcessor) {
271                 ChangeLogProcessor proces = (ChangeLogProcessor)settings;
272                 HtmlPanel p = (HtmlPanel) this.getComponent();
273                 if (p.comServerDef.getSelectedIndex() != 0) {
274                     int index = p.comServerDef.getSelectedIndex();
275                     proces.setHtmlSiteProcessor(p.array[index]);
276                 } else {
277                     proces.setHtmlSiteProcessor(null);
278                 }
279             }
280         }
281
282         /** Provides the wizard panel with the current data--either
283          * the default data or already-modified settings, if the user used the previous and/or next buttons.
284          * This method can be called multiple times on one instance of <code>WizardDescriptor.Panel</code>.
285          * @param settings the object representing wizard panel state, as originally supplied to {@link WizardDescriptor#WizardDescriptor(WizardDescriptor.Iterator,Object)}
286          * @exception IllegalStateException if the the data provided
287          * by the wizard are not valid.
288          */

289         public void readSettings(Object JavaDoc settings) {
290             if (settings instanceof ChangeLogProcessor) {
291                 HtmlPanel p = (HtmlPanel) this.getComponent();
292                 p.loadCombo();
293                 ChangeLogProcessor proces = (ChangeLogProcessor)settings;
294                 if (proces.getHtmlSiteProcessor() == null) {
295                     p.comServerDef.setSelectedIndex(0);
296                     p.changeItem();
297                 } else {
298                     ChangeLogHTMLService service = proces.getHtmlSiteProcessor();
299                     for (int i = 0; i < p.array.length; i++) {
300                         if (p.array[i].getName().equals(service.getName())) {
301                             p.comServerDef.setSelectedIndex(i);
302                             p.changeItem();
303                             break;
304                         }
305                     }
306                 }
307             }
308         }
309
310     }
311
312 }
313
Popular Tags