KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > platform > NbPlatformCustomizerJavadoc


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 Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui.platform;
21
22 import java.io.File JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.Locale JavaDoc;
25 import javax.swing.JFileChooser JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27 import javax.swing.filechooser.FileFilter JavaDoc;
28 import org.netbeans.modules.apisupport.project.Util;
29 import org.netbeans.modules.apisupport.project.ui.ModuleUISettings;
30 import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizerSources.ListListener;
31 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
32 import org.openide.filesystems.FileUtil;
33 import org.openide.util.NbBundle;
34
35 /**
36  * Represents <em>Javadoc</em> tab in the NetBeans platforms customizer.
37  *
38  * @author Martin Krauskopf
39  */

40 final class NbPlatformCustomizerJavadoc extends JPanel JavaDoc {
41     
42     private NbPlatform plaf;
43     private PlatformComponentFactory.NbPlatformJavadocRootsModel model;
44     private final ListListener listListener;
45     
46     /** Creates new form NbPlatformCustomizerModules */
47     NbPlatformCustomizerJavadoc() {
48         initComponents();
49         initAccessibility();
50         this.listListener = new ListListener() {
51             void listChanged() {
52                 updateEnabled();
53             }
54         };
55         updateEnabled();
56     }
57     
58     public void addNotify() {
59         super.addNotify();
60         javadocList.addListSelectionListener(listListener);
61         javadocList.getModel().addListDataListener(listListener);
62     }
63     
64     public void removeNotify() {
65         javadocList.removeListSelectionListener(listListener);
66         javadocList.getModel().removeListDataListener(listListener);
67         super.removeNotify();
68     }
69     
70     private void updateEnabled() {
71         // update buttons enability appropriately
72
removeButton.setEnabled(javadocList.getModel().getSize() > 0 && javadocList.getSelectedIndex() != -1);
73         moveUpButton.setEnabled(javadocList.getSelectionModel().getMinSelectionIndex() > 0);
74         moveDownButton.setEnabled(plaf != null &&
75                 javadocList.getSelectionModel().getMaxSelectionIndex() < plaf.getJavadocRoots().length - 1);
76     }
77     
78     void setPlatform(NbPlatform plaf) {
79         this.plaf = plaf;
80         this.model = new PlatformComponentFactory.NbPlatformJavadocRootsModel(plaf);
81         javadocList.setModel(model);
82     }
83     
84     /** This method is called from within the constructor to
85      * initialize the form.
86      * WARNING: Do NOT modify this code. The content of this method is
87      * always regenerated by the Form Editor.
88      */

89     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
90
private void initComponents() {
91         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
92
93         javadocLabel = new javax.swing.JLabel JavaDoc();
94         javadocSP = new javax.swing.JScrollPane JavaDoc();
95         javadocList = new javax.swing.JList JavaDoc();
96         buttonPanel = new javax.swing.JPanel JavaDoc();
97         addFolderButton = new javax.swing.JButton JavaDoc();
98         removeButton = new javax.swing.JButton JavaDoc();
99         moveUpButton = new javax.swing.JButton JavaDoc();
100         moveDownButton = new javax.swing.JButton JavaDoc();
101
102         setLayout(new java.awt.GridBagLayout JavaDoc());
103
104         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 12, 12));
105         javadocLabel.setLabelFor(javadocList);
106         org.openide.awt.Mnemonics.setLocalizedText(javadocLabel, org.openide.util.NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, "LBL_PlatformJavadoc"));
107         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
108         gridBagConstraints.gridx = 0;
109         gridBagConstraints.gridy = 0;
110         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
111         add(javadocLabel, gridBagConstraints);
112
113         javadocList.setCellRenderer(PlatformComponentFactory.getURLListRenderer());
114         javadocSP.setViewportView(javadocList);
115
116         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
117         gridBagConstraints.gridx = 0;
118         gridBagConstraints.gridy = 1;
119         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
120         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
121         gridBagConstraints.weightx = 1.0;
122         gridBagConstraints.weighty = 1.0;
123         add(javadocSP, gridBagConstraints);
124
125         buttonPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
126
127         buttonPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 12, 0, 0));
128         org.openide.awt.Mnemonics.setLocalizedText(addFolderButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, "CTL_AddZipOrFolder"));
129         addFolderButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
130             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
131                 addZipFolder(evt);
132             }
133         });
134
135         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
136         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
137         buttonPanel.add(addFolderButton, gridBagConstraints);
138
139         org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, "CTL_Remove"));
140         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
141             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
142                 removeFolder(evt);
143             }
144         });
145
146         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
147         gridBagConstraints.gridx = 0;
148         gridBagConstraints.gridy = 1;
149         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
150         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 12, 0);
151         buttonPanel.add(removeButton, gridBagConstraints);
152
153         org.openide.awt.Mnemonics.setLocalizedText(moveUpButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, "CTL_MoveUp"));
154         moveUpButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
155             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
156                 moveUp(evt);
157             }
158         });
159
160         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
161         gridBagConstraints.gridx = 0;
162         gridBagConstraints.gridy = 2;
163         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
164         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 2, 0);
165         buttonPanel.add(moveUpButton, gridBagConstraints);
166
167         org.openide.awt.Mnemonics.setLocalizedText(moveDownButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, "CTL_MoveDown"));
168         moveDownButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
169             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
170                 moveDown(evt);
171             }
172         });
173
174         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175         gridBagConstraints.gridx = 0;
176         gridBagConstraints.gridy = 3;
177         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
178         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
179         gridBagConstraints.weighty = 1.0;
180         buttonPanel.add(moveDownButton, gridBagConstraints);
181
182         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
183         gridBagConstraints.gridx = 1;
184         gridBagConstraints.gridy = 1;
185         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
186         add(buttonPanel, gridBagConstraints);
187
188     }// </editor-fold>//GEN-END:initComponents
189

190     private void moveDown(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_moveDown
191
int[] selIndices = javadocList.getSelectedIndices();
192         model.moveJavadocRootsDown(selIndices);
193         for (int i = 0; i < selIndices.length; i++) {
194             selIndices[i] = ++selIndices[i];
195         }
196         javadocList.setSelectedIndices(selIndices);
197     }//GEN-LAST:event_moveDown
198

199     private void moveUp(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_moveUp
200
int[] selIndices = javadocList.getSelectedIndices();
201         model.moveJavadocRootsUp(selIndices);
202         for (int i = 0; i < selIndices.length; i++) {
203             selIndices[i] = --selIndices[i];
204         }
205         javadocList.setSelectedIndices(selIndices);
206     }//GEN-LAST:event_moveUp
207

208     private void removeFolder(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeFolder
209
Object JavaDoc[] selVals = javadocList.getSelectedValues();
210         int toSelect = javadocList.getSelectedIndex() - 1;
211         URL JavaDoc[] selURLs = new URL JavaDoc[selVals.length];
212         System.arraycopy(selVals, 0, selURLs, 0, selVals.length);
213         model.removeJavadocRoots(selURLs);
214         javadocList.setSelectedIndex(toSelect);
215     }//GEN-LAST:event_removeFolder
216

217     private void addZipFolder(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addZipFolder
218
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(ModuleUISettings.getDefault().getLastUsedNbPlatformLocation());
219         chooser.setAcceptAllFileFilterUsed(false);
220         chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
221         chooser.setFileFilter(new FileFilter JavaDoc() {
222             public boolean accept(File JavaDoc f) {
223                 return f.isDirectory() ||
224                         f.getName().toLowerCase(Locale.US).endsWith(".jar") || // NOI18N
225
f.getName().toLowerCase(Locale.US).endsWith(".zip"); // NOI18N
226
}
227             public String JavaDoc getDescription() {
228                 return getMessage("CTL_JavadocTab");
229             }
230         });
231         int ret = chooser.showOpenDialog(this);
232         if (ret == JFileChooser.APPROVE_OPTION) {
233             File JavaDoc javadocRoot = FileUtil.normalizeFile(chooser.getSelectedFile());
234             ModuleUISettings.getDefault().setLastUsedNbPlatformLocation(javadocRoot.getParentFile().getAbsolutePath());
235             URL JavaDoc newUrl = Util.urlForDirOrJar(javadocRoot);
236             model.addJavadocRoot(newUrl);
237             javadocList.setSelectedValue(newUrl, true);
238         }
239     }//GEN-LAST:event_addZipFolder
240

241     
242     // Variables declaration - do not modify//GEN-BEGIN:variables
243
private javax.swing.JButton JavaDoc addFolderButton;
244     private javax.swing.JPanel JavaDoc buttonPanel;
245     private javax.swing.JLabel JavaDoc javadocLabel;
246     private javax.swing.JList JavaDoc javadocList;
247     private javax.swing.JScrollPane JavaDoc javadocSP;
248     private javax.swing.JButton JavaDoc moveDownButton;
249     private javax.swing.JButton JavaDoc moveUpButton;
250     private javax.swing.JButton JavaDoc removeButton;
251     // End of variables declaration//GEN-END:variables
252

253     private void initAccessibility() {
254         addFolderButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_addFolderButton"));
255         javadocList.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_javadocList"));
256         moveDownButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_moveDownButton"));
257         moveUpButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_moveUpButton"));
258         removeButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_removeButton"));
259     }
260     
261     private String JavaDoc getMessage(String JavaDoc key) {
262         return NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, key);
263     }
264     
265 }
266
Popular Tags