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-2007 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.java.hints.options;
043:
044: import java.awt.Component;
045: import java.util.MissingResourceException;
046: import java.util.ResourceBundle;
047: import java.util.prefs.Preferences;
048: import javax.swing.DefaultComboBoxModel;
049: import javax.swing.JCheckBox;
050: import javax.swing.JTree;
051: import javax.swing.UIManager;
052: import javax.swing.tree.DefaultMutableTreeNode;
053: import javax.swing.tree.DefaultTreeCellRenderer;
054: import javax.swing.tree.TreeCellRenderer;
055: import javax.swing.tree.TreeSelectionModel;
056:
057: import org.openide.filesystems.FileObject;
058: import org.openide.util.NbBundle;
059:
060: import org.netbeans.modules.java.hints.infrastructure.RulesManager;
061: import org.netbeans.modules.java.hints.spi.AbstractHint;
062: import static org.netbeans.modules.java.hints.spi.AbstractHint.*;
063:
064: final class HintsPanel extends javax.swing.JPanel implements
065: TreeCellRenderer {
066:
067: private DefaultTreeCellRenderer dr = new DefaultTreeCellRenderer();
068: private JCheckBox renderer = new JCheckBox();
069: private HintsPanelLogic logic;
070:
071: HintsPanel() {
072: initComponents();
073:
074: descriptionTextArea.setContentType("text/html"); // NOI18N
075:
076: if ("Windows".equals(UIManager.getLookAndFeel().getID())) //NOI18N
077: setOpaque(false);
078:
079: errorTree.setCellRenderer(this );
080: errorTree.setRootVisible(false);
081: errorTree.setShowsRootHandles(true);
082: errorTree.getSelectionModel().setSelectionMode(
083: TreeSelectionModel.SINGLE_TREE_SELECTION);
084:
085: DefaultComboBoxModel model = new DefaultComboBoxModel();
086: model.addElement(NbBundle.getMessage(HintsPanel.class,
087: "CTL_AsError"));
088: model.addElement(NbBundle.getMessage(HintsPanel.class,
089: "CTL_AsWarning"));
090: model.addElement(NbBundle.getMessage(HintsPanel.class,
091: "CTL_WarningOnCurrentLine"));
092: severityComboBox.setModel(model);
093:
094: toProblemCheckBox.setVisible(false);
095:
096: update();
097:
098: errorTree.setModel(RulesManager.getInstance()
099: .getHintsTreeModel());
100:
101: }
102:
103: /** This method is called from within the constructor to
104: * initialize the form.
105: * WARNING: Do NOT modify this code. The content of this method is
106: * always regenerated by the Form Editor.
107: */
108: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
109: private void initComponents() {
110: java.awt.GridBagConstraints gridBagConstraints;
111:
112: jSplitPane1 = new javax.swing.JSplitPane();
113: treePanel = new javax.swing.JPanel();
114: jScrollPane1 = new javax.swing.JScrollPane();
115: errorTree = new javax.swing.JTree();
116: detailsPanel = new javax.swing.JPanel();
117: optionsPanel = new javax.swing.JPanel();
118: severityLabel = new javax.swing.JLabel();
119: severityComboBox = new javax.swing.JComboBox();
120: toProblemCheckBox = new javax.swing.JCheckBox();
121: customizerPanel = new javax.swing.JPanel();
122: descriptionPanel = new javax.swing.JPanel();
123: jScrollPane2 = new javax.swing.JScrollPane();
124: descriptionTextArea = new javax.swing.JEditorPane();
125: descriptionLabel = new javax.swing.JLabel();
126:
127: setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8,
128: 8));
129: setLayout(new java.awt.GridBagLayout());
130:
131: jSplitPane1.setBorder(null);
132: jSplitPane1.setDividerLocation(320);
133: jSplitPane1.setOpaque(false);
134:
135: treePanel.setOpaque(false);
136: treePanel.setLayout(new java.awt.BorderLayout());
137:
138: jScrollPane1.setViewportView(errorTree);
139: errorTree
140: .getAccessibleContext()
141: .setAccessibleName(
142: org.openide.util.NbBundle
143: .getMessage(HintsPanel.class,
144: "HintsPanel.errorTree.AccessibleContext.accessibleName")); // NOI18N
145: errorTree
146: .getAccessibleContext()
147: .setAccessibleDescription(
148: org.openide.util.NbBundle
149: .getMessage(HintsPanel.class,
150: "HintsPanel.errorTree.AccessibleContext.accessibleDescription")); // NOI18N
151:
152: treePanel.add(jScrollPane1, java.awt.BorderLayout.CENTER);
153:
154: jSplitPane1.setLeftComponent(treePanel);
155:
156: detailsPanel.setBorder(javax.swing.BorderFactory
157: .createEmptyBorder(0, 6, 0, 0));
158: detailsPanel.setOpaque(false);
159: detailsPanel.setLayout(new java.awt.GridBagLayout());
160:
161: optionsPanel.setOpaque(false);
162: optionsPanel.setLayout(new java.awt.GridBagLayout());
163:
164: severityLabel.setLabelFor(severityComboBox);
165: org.openide.awt.Mnemonics.setLocalizedText(severityLabel,
166: org.openide.util.NbBundle.getMessage(HintsPanel.class,
167: "CTL_ShowAs_Label")); // NOI18N
168: gridBagConstraints = new java.awt.GridBagConstraints();
169: gridBagConstraints.gridx = 0;
170: gridBagConstraints.gridy = 0;
171: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
172: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
173: optionsPanel.add(severityLabel, gridBagConstraints);
174: severityLabel
175: .getAccessibleContext()
176: .setAccessibleDescription(
177: org.openide.util.NbBundle
178: .getMessage(HintsPanel.class,
179: "HintsPanel.severityLabel.AccessibleContext.accessibleDescription")); // NOI18N
180:
181: severityComboBox
182: .setModel(new javax.swing.DefaultComboBoxModel(
183: new String[] { "Item 1", "Item 2", "Item 3",
184: "Item 4" }));
185: gridBagConstraints = new java.awt.GridBagConstraints();
186: gridBagConstraints.gridx = 1;
187: gridBagConstraints.gridy = 0;
188: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
189: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
190: optionsPanel.add(severityComboBox, gridBagConstraints);
191:
192: org.openide.awt.Mnemonics.setLocalizedText(toProblemCheckBox,
193: org.openide.util.NbBundle.getMessage(HintsPanel.class,
194: "CTL_InTasklist_CheckBox")); // NOI18N
195: toProblemCheckBox.setBorder(javax.swing.BorderFactory
196: .createEmptyBorder(0, 0, 0, 0));
197: toProblemCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
198: gridBagConstraints = new java.awt.GridBagConstraints();
199: gridBagConstraints.gridx = 0;
200: gridBagConstraints.gridy = 2;
201: gridBagConstraints.gridwidth = 3;
202: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
203: gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
204: optionsPanel.add(toProblemCheckBox, gridBagConstraints);
205:
206: customizerPanel.setOpaque(false);
207: customizerPanel.setLayout(new java.awt.BorderLayout());
208: gridBagConstraints = new java.awt.GridBagConstraints();
209: gridBagConstraints.gridx = 0;
210: gridBagConstraints.gridy = 3;
211: gridBagConstraints.gridwidth = 3;
212: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
213: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
214: gridBagConstraints.weightx = 1.0;
215: gridBagConstraints.weighty = 1.0;
216: gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
217: optionsPanel.add(customizerPanel, gridBagConstraints);
218:
219: gridBagConstraints = new java.awt.GridBagConstraints();
220: gridBagConstraints.gridx = 0;
221: gridBagConstraints.gridy = 0;
222: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
223: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
224: gridBagConstraints.weightx = 1.0;
225: gridBagConstraints.weighty = 0.7;
226: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
227: detailsPanel.add(optionsPanel, gridBagConstraints);
228:
229: descriptionPanel.setOpaque(false);
230: descriptionPanel.setLayout(new java.awt.GridBagLayout());
231:
232: descriptionTextArea.setEditable(false);
233: jScrollPane2.setViewportView(descriptionTextArea);
234:
235: gridBagConstraints = new java.awt.GridBagConstraints();
236: gridBagConstraints.gridx = 0;
237: gridBagConstraints.gridy = 1;
238: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
239: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
240: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
241: gridBagConstraints.weightx = 1.0;
242: gridBagConstraints.weighty = 1.0;
243: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
244: descriptionPanel.add(jScrollPane2, gridBagConstraints);
245:
246: descriptionLabel.setLabelFor(descriptionTextArea);
247: org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel,
248: org.openide.util.NbBundle.getMessage(HintsPanel.class,
249: "CTL_Description_Border")); // NOI18N
250: gridBagConstraints = new java.awt.GridBagConstraints();
251: gridBagConstraints.gridx = 0;
252: gridBagConstraints.gridy = 0;
253: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
254: descriptionPanel.add(descriptionLabel, gridBagConstraints);
255:
256: gridBagConstraints = new java.awt.GridBagConstraints();
257: gridBagConstraints.gridx = 0;
258: gridBagConstraints.gridy = 1;
259: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
260: gridBagConstraints.weightx = 1.0;
261: gridBagConstraints.weighty = 0.3;
262: detailsPanel.add(descriptionPanel, gridBagConstraints);
263:
264: jSplitPane1.setRightComponent(detailsPanel);
265:
266: gridBagConstraints = new java.awt.GridBagConstraints();
267: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
268: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
269: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
270: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
271: gridBagConstraints.weightx = 1.0;
272: gridBagConstraints.weighty = 1.0;
273: add(jSplitPane1, gridBagConstraints);
274:
275: getAccessibleContext().setAccessibleName(
276: org.openide.util.NbBundle.getMessage(HintsPanel.class,
277: "HintsPanel.AccessibleContext.accessibleName")); // NOI18N
278: getAccessibleContext()
279: .setAccessibleDescription(
280: org.openide.util.NbBundle
281: .getMessage(HintsPanel.class,
282: "HintsPanel.AccessibleContext.accessibleDescription")); // NOI18N
283: }// </editor-fold>//GEN-END:initComponents
284:
285: synchronized void update() {
286: if (logic != null) {
287: logic.disconnect();
288: }
289: logic = new HintsPanelLogic();
290: logic.connect(errorTree, severityComboBox, toProblemCheckBox,
291: customizerPanel, descriptionTextArea);
292: }
293:
294: void cancel() {
295: logic.disconnect();
296: logic = null;
297: }
298:
299: boolean isChanged() {
300: return logic != null ? logic.isChanged() : false;
301: }
302:
303: void applyChanges() {
304: logic.applyChanges();
305: logic.disconnect();
306: logic = null;
307: }
308:
309: public Component getTreeCellRendererComponent(JTree tree,
310: Object value, boolean selected, boolean expanded,
311: boolean leaf, int row, boolean hasFocus) {
312:
313: renderer.setBackground(selected ? dr
314: .getBackgroundSelectionColor() : dr
315: .getBackgroundNonSelectionColor());
316: renderer.setForeground(selected ? dr.getTextSelectionColor()
317: : dr.getTextNonSelectionColor());
318: renderer.setEnabled(true);
319:
320: Object data = ((DefaultMutableTreeNode) value).getUserObject();
321: if (data instanceof FileObject) {
322: FileObject fo = ((FileObject) data);
323: renderer.setText(getFileObjectLocalizedName(fo));
324: if (logic != null)
325: renderer.setSelected(logic
326: .isSelected((DefaultMutableTreeNode) value));
327: } else if (data instanceof AbstractHint) {
328: AbstractHint treeRule = (AbstractHint) data;
329: renderer.setText(treeRule.getDisplayName());
330:
331: Preferences node = logic.getCurrentPrefernces(treeRule);
332: renderer.setSelected(HintsSettings
333: .isEnabled(treeRule, node));
334: } else {
335: renderer.setText(value.toString());
336: }
337:
338: return renderer;
339: }
340:
341: private String getFileObjectLocalizedName(FileObject fo) {
342: Object o = fo.getAttribute("SystemFileSystem.localizingBundle"); // NOI18N
343: if (o instanceof String) {
344: String bundleName = (String) o;
345: try {
346: ResourceBundle rb = NbBundle.getBundle(bundleName);
347: String localizedName = rb.getString(fo.getPath());
348: return localizedName;
349: } catch (MissingResourceException ex) {
350: // Do nothing return file path;
351: }
352: }
353: return fo.getPath();
354: }
355:
356: // Variables declaration - do not modify
357:
358: // Variables declaration - do not modify//GEN-BEGIN:variables
359: private javax.swing.JPanel customizerPanel;
360: private javax.swing.JLabel descriptionLabel;
361: private javax.swing.JPanel descriptionPanel;
362: private javax.swing.JEditorPane descriptionTextArea;
363: private javax.swing.JPanel detailsPanel;
364: private javax.swing.JTree errorTree;
365: private javax.swing.JScrollPane jScrollPane1;
366: private javax.swing.JScrollPane jScrollPane2;
367: private javax.swing.JSplitPane jSplitPane1;
368: private javax.swing.JPanel optionsPanel;
369: private javax.swing.JComboBox severityComboBox;
370: private javax.swing.JLabel severityLabel;
371: private javax.swing.JCheckBox toProblemCheckBox;
372: private javax.swing.JPanel treePanel;
373: // End of variables declaration//GEN-END:variables
374:
375: }
|