001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project.ui.platform;
043:
044: import java.io.File;
045: import java.net.URL;
046: import java.util.Locale;
047: import javax.swing.JFileChooser;
048: import javax.swing.JPanel;
049: import javax.swing.filechooser.FileFilter;
050: import org.netbeans.modules.apisupport.project.Util;
051: import org.netbeans.modules.apisupport.project.ui.ModuleUISettings;
052: import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizerSources.ListListener;
053: import org.netbeans.modules.apisupport.project.universe.NbPlatform;
054: import org.openide.filesystems.FileUtil;
055: import org.openide.util.NbBundle;
056:
057: /**
058: * Represents <em>Javadoc</em> tab in the NetBeans platforms customizer.
059: *
060: * @author Martin Krauskopf
061: */
062: final class NbPlatformCustomizerJavadoc extends JPanel {
063:
064: private NbPlatform plaf;
065: private PlatformComponentFactory.NbPlatformJavadocRootsModel model;
066: private final ListListener listListener;
067:
068: /** Creates new form NbPlatformCustomizerModules */
069: NbPlatformCustomizerJavadoc() {
070: initComponents();
071: initAccessibility();
072: this .listListener = new ListListener() {
073: void listChanged() {
074: updateEnabled();
075: }
076: };
077: updateEnabled();
078: }
079:
080: public void addNotify() {
081: super .addNotify();
082: javadocList.addListSelectionListener(listListener);
083: javadocList.getModel().addListDataListener(listListener);
084: }
085:
086: public void removeNotify() {
087: javadocList.removeListSelectionListener(listListener);
088: javadocList.getModel().removeListDataListener(listListener);
089: super .removeNotify();
090: }
091:
092: private void updateEnabled() {
093: // update buttons enability appropriately
094: removeButton.setEnabled(javadocList.getModel().getSize() > 0
095: && javadocList.getSelectedIndex() != -1);
096: moveUpButton.setEnabled(javadocList.getSelectionModel()
097: .getMinSelectionIndex() > 0);
098: moveDownButton.setEnabled(plaf != null
099: && javadocList.getSelectionModel()
100: .getMaxSelectionIndex() < plaf
101: .getJavadocRoots().length - 1);
102: }
103:
104: void setPlatform(NbPlatform plaf) {
105: this .plaf = plaf;
106: this .model = new PlatformComponentFactory.NbPlatformJavadocRootsModel(
107: plaf);
108: javadocList.setModel(model);
109: }
110:
111: /** This method is called from within the constructor to
112: * initialize the form.
113: * WARNING: Do NOT modify this code. The content of this method is
114: * always regenerated by the Form Editor.
115: */
116: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
117: private void initComponents() {
118: java.awt.GridBagConstraints gridBagConstraints;
119:
120: javadocLabel = new javax.swing.JLabel();
121: javadocSP = new javax.swing.JScrollPane();
122: javadocList = new javax.swing.JList();
123: buttonPanel = new javax.swing.JPanel();
124: addFolderButton = new javax.swing.JButton();
125: removeButton = new javax.swing.JButton();
126: moveUpButton = new javax.swing.JButton();
127: moveDownButton = new javax.swing.JButton();
128:
129: setLayout(new java.awt.GridBagLayout());
130:
131: setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12,
132: 12, 12));
133: javadocLabel.setLabelFor(javadocList);
134: org.openide.awt.Mnemonics.setLocalizedText(javadocLabel,
135: org.openide.util.NbBundle.getMessage(
136: NbPlatformCustomizerJavadoc.class,
137: "LBL_PlatformJavadoc"));
138: gridBagConstraints = new java.awt.GridBagConstraints();
139: gridBagConstraints.gridx = 0;
140: gridBagConstraints.gridy = 0;
141: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
142: add(javadocLabel, gridBagConstraints);
143:
144: javadocList.setCellRenderer(PlatformComponentFactory
145: .getURLListRenderer());
146: javadocSP.setViewportView(javadocList);
147:
148: gridBagConstraints = new java.awt.GridBagConstraints();
149: gridBagConstraints.gridx = 0;
150: gridBagConstraints.gridy = 1;
151: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
152: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
153: gridBagConstraints.weightx = 1.0;
154: gridBagConstraints.weighty = 1.0;
155: add(javadocSP, gridBagConstraints);
156:
157: buttonPanel.setLayout(new java.awt.GridBagLayout());
158:
159: buttonPanel.setBorder(javax.swing.BorderFactory
160: .createEmptyBorder(0, 12, 0, 0));
161: org.openide.awt.Mnemonics.setLocalizedText(addFolderButton,
162: org.openide.util.NbBundle.getMessage(
163: NbPlatformCustomizerJavadoc.class,
164: "CTL_AddZipOrFolder"));
165: addFolderButton
166: .addActionListener(new java.awt.event.ActionListener() {
167: public void actionPerformed(
168: java.awt.event.ActionEvent evt) {
169: addZipFolder(evt);
170: }
171: });
172:
173: gridBagConstraints = new java.awt.GridBagConstraints();
174: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
175: buttonPanel.add(addFolderButton, gridBagConstraints);
176:
177: org.openide.awt.Mnemonics.setLocalizedText(removeButton,
178: org.openide.util.NbBundle
179: .getMessage(NbPlatformCustomizerJavadoc.class,
180: "CTL_Remove"));
181: removeButton
182: .addActionListener(new java.awt.event.ActionListener() {
183: public void actionPerformed(
184: java.awt.event.ActionEvent evt) {
185: removeFolder(evt);
186: }
187: });
188:
189: gridBagConstraints = new java.awt.GridBagConstraints();
190: gridBagConstraints.gridx = 0;
191: gridBagConstraints.gridy = 1;
192: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
193: gridBagConstraints.insets = new java.awt.Insets(12, 0, 12, 0);
194: buttonPanel.add(removeButton, gridBagConstraints);
195:
196: org.openide.awt.Mnemonics.setLocalizedText(moveUpButton,
197: org.openide.util.NbBundle
198: .getMessage(NbPlatformCustomizerJavadoc.class,
199: "CTL_MoveUp"));
200: moveUpButton
201: .addActionListener(new java.awt.event.ActionListener() {
202: public void actionPerformed(
203: java.awt.event.ActionEvent evt) {
204: moveUp(evt);
205: }
206: });
207:
208: gridBagConstraints = new java.awt.GridBagConstraints();
209: gridBagConstraints.gridx = 0;
210: gridBagConstraints.gridy = 2;
211: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
212: gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
213: buttonPanel.add(moveUpButton, gridBagConstraints);
214:
215: org.openide.awt.Mnemonics.setLocalizedText(moveDownButton,
216: org.openide.util.NbBundle.getMessage(
217: NbPlatformCustomizerJavadoc.class,
218: "CTL_MoveDown"));
219: moveDownButton
220: .addActionListener(new java.awt.event.ActionListener() {
221: public void actionPerformed(
222: java.awt.event.ActionEvent evt) {
223: moveDown(evt);
224: }
225: });
226:
227: gridBagConstraints = new java.awt.GridBagConstraints();
228: gridBagConstraints.gridx = 0;
229: gridBagConstraints.gridy = 3;
230: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
231: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
232: gridBagConstraints.weighty = 1.0;
233: buttonPanel.add(moveDownButton, gridBagConstraints);
234:
235: gridBagConstraints = new java.awt.GridBagConstraints();
236: gridBagConstraints.gridx = 1;
237: gridBagConstraints.gridy = 1;
238: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
239: add(buttonPanel, gridBagConstraints);
240:
241: }// </editor-fold>//GEN-END:initComponents
242:
243: private void moveDown(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDown
244: int[] selIndices = javadocList.getSelectedIndices();
245: model.moveJavadocRootsDown(selIndices);
246: for (int i = 0; i < selIndices.length; i++) {
247: selIndices[i] = ++selIndices[i];
248: }
249: javadocList.setSelectedIndices(selIndices);
250: }//GEN-LAST:event_moveDown
251:
252: private void moveUp(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUp
253: int[] selIndices = javadocList.getSelectedIndices();
254: model.moveJavadocRootsUp(selIndices);
255: for (int i = 0; i < selIndices.length; i++) {
256: selIndices[i] = --selIndices[i];
257: }
258: javadocList.setSelectedIndices(selIndices);
259: }//GEN-LAST:event_moveUp
260:
261: private void removeFolder(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeFolder
262: Object[] selVals = javadocList.getSelectedValues();
263: int toSelect = javadocList.getSelectedIndex() - 1;
264: URL[] selURLs = new URL[selVals.length];
265: System.arraycopy(selVals, 0, selURLs, 0, selVals.length);
266: model.removeJavadocRoots(selURLs);
267: javadocList.setSelectedIndex(toSelect);
268: }//GEN-LAST:event_removeFolder
269:
270: private void addZipFolder(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addZipFolder
271: JFileChooser chooser = new JFileChooser(ModuleUISettings
272: .getDefault().getLastUsedNbPlatformLocation());
273: chooser.setAcceptAllFileFilterUsed(false);
274: chooser
275: .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
276: chooser.setFileFilter(new FileFilter() {
277: public boolean accept(File f) {
278: return f.isDirectory()
279: || f.getName().toLowerCase(Locale.US).endsWith(
280: ".jar") || // NOI18N
281: f.getName().toLowerCase(Locale.US).endsWith(
282: ".zip"); // NOI18N
283: }
284:
285: public String getDescription() {
286: return getMessage("CTL_JavadocTab");
287: }
288: });
289: int ret = chooser.showOpenDialog(this );
290: if (ret == JFileChooser.APPROVE_OPTION) {
291: File javadocRoot = FileUtil.normalizeFile(chooser
292: .getSelectedFile());
293: ModuleUISettings.getDefault()
294: .setLastUsedNbPlatformLocation(
295: javadocRoot.getParentFile()
296: .getAbsolutePath());
297: URL newUrl = Util.urlForDirOrJar(javadocRoot);
298: model.addJavadocRoot(newUrl);
299: javadocList.setSelectedValue(newUrl, true);
300: }
301: }//GEN-LAST:event_addZipFolder
302:
303: // Variables declaration - do not modify//GEN-BEGIN:variables
304: private javax.swing.JButton addFolderButton;
305: private javax.swing.JPanel buttonPanel;
306: private javax.swing.JLabel javadocLabel;
307: private javax.swing.JList javadocList;
308: private javax.swing.JScrollPane javadocSP;
309: private javax.swing.JButton moveDownButton;
310: private javax.swing.JButton moveUpButton;
311: private javax.swing.JButton removeButton;
312:
313: // End of variables declaration//GEN-END:variables
314:
315: private void initAccessibility() {
316: addFolderButton.getAccessibleContext()
317: .setAccessibleDescription(
318: getMessage("ACS_CTL_addFolderButton"));
319: javadocList.getAccessibleContext().setAccessibleDescription(
320: getMessage("ACS_CTL_javadocList"));
321: moveDownButton.getAccessibleContext().setAccessibleDescription(
322: getMessage("ACS_CTL_moveDownButton"));
323: moveUpButton.getAccessibleContext().setAccessibleDescription(
324: getMessage("ACS_CTL_moveUpButton"));
325: removeButton.getAccessibleContext().setAccessibleDescription(
326: getMessage("ACS_CTL_removeButton"));
327: }
328:
329: private String getMessage(String key) {
330: return NbBundle.getMessage(NbPlatformCustomizerJavadoc.class,
331: key);
332: }
333:
334: }
|