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.refactoring.java.ui;
043:
044: import java.awt.Component;
045: import java.util.Collections;
046: import javax.lang.model.element.Modifier;
047: import javax.swing.DefaultComboBoxModel;
048: import javax.swing.DefaultListCellRenderer;
049: import javax.swing.Icon;
050: import javax.swing.JList;
051: import javax.swing.JPanel;
052: import javax.swing.ListSelectionModel;
053: import org.netbeans.api.java.source.ElementHandle;
054: import org.netbeans.api.java.source.TreePathHandle;
055: import org.netbeans.api.java.source.UiUtils;
056: import org.netbeans.modules.refactoring.java.RetoucheUtils;
057: import org.netbeans.modules.refactoring.java.api.UseSuperTypeRefactoring;
058: import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
059: import org.openide.util.NbBundle;
060:
061: /*
062: * UseSuperTypePanel.java
063: *
064: * Created on June 20, 2005
065: *
066: * @author Bharath Ravi Kumar
067: */
068:
069: /**
070: * The panel for the use super type refactoring
071: */
072: public class UseSuperTypePanel extends JPanel implements
073: CustomRefactoringPanel {
074:
075: private final UseSuperTypeRefactoring refactoring;
076:
077: /**
078: * Creates new form UseSuperTypePanel
079: * @param refactoring The use super type refactoring that is
080: * used by this panel
081: */
082: public UseSuperTypePanel(UseSuperTypeRefactoring refactoring) {
083: this .refactoring = refactoring;
084: initComponents();
085: TreePathHandle subType = (TreePathHandle) refactoring
086: .getTypeElement();
087: String title = null;
088: String className = RetoucheUtils.getSimpleName(subType);
089: title = NbBundle.getMessage(UseSuperTypePanel.class,
090: "LBL_UseSyperTypeTitle", className);
091: setName(title);
092: super TypeList.setCellRenderer(new DefaultListCellRenderer() {
093:
094: @Override
095: public Component getListCellRendererComponent(JList list,
096: Object value, int index, boolean isSelected,
097: boolean cellHasFocus) {
098:
099: super .getListCellRendererComponent(list,
100: ((ElementHandle) value).getBinaryName(), index,
101: isSelected, cellHasFocus);
102:
103: if (value instanceof ElementHandle) {
104: Icon i = UiUtils.getElementIcon(
105: ((ElementHandle) value).getKind(),
106: Collections.singleton(Modifier.PUBLIC));
107: setIcon(i);
108: }
109: return this ;
110:
111: }
112: });
113: super TypeList.setModel(new DefaultComboBoxModel(refactoring
114: .getCandidateSuperTypes()));
115: super TypeList
116: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
117: super TypeList.setSelectedIndex(0);
118: }
119:
120: public void initialize() {
121: }
122:
123: public Component getComponent() {
124: return this ;
125: }
126:
127: /**
128: * Returns the targer super type to be used
129: * @return The target super type Object
130: */
131: public ElementHandle getSuperType() {
132: return (ElementHandle) super TypeList.getSelectedValue();
133: }
134:
135: /** This method is called from within the constructor to
136: * initialize the form.
137: * WARNING: Do NOT modify this code. The content of this method is
138: * always regenerated by the Form Editor.
139: */
140: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
141: private void initComponents() {
142: java.awt.GridBagConstraints gridBagConstraints;
143:
144: label = new javax.swing.JLabel();
145: listScrollPane = new javax.swing.JScrollPane();
146: super TypeList = new javax.swing.JList();
147:
148: setMaximumSize(new java.awt.Dimension(600, 500));
149: setPreferredSize(new java.awt.Dimension(300, 200));
150: setLayout(new java.awt.GridBagLayout());
151:
152: label.setLabelFor(super TypeList);
153: org.openide.awt.Mnemonics.setLocalizedText(label,
154: org.openide.util.NbBundle.getBundle(
155: UseSuperTypePanel.class).getString(
156: "LBL_UseSuperType")); // NOI18N
157: gridBagConstraints = new java.awt.GridBagConstraints();
158: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
159: add(label, gridBagConstraints);
160:
161: super TypeList
162: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
163: listScrollPane.setViewportView(super TypeList);
164: super TypeList.getAccessibleContext().setAccessibleName(null);
165: super TypeList.getAccessibleContext().setAccessibleDescription(
166: null);
167:
168: gridBagConstraints = new java.awt.GridBagConstraints();
169: gridBagConstraints.gridx = 0;
170: gridBagConstraints.gridy = 1;
171: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
172: gridBagConstraints.weightx = 1.0;
173: gridBagConstraints.weighty = 1.0;
174: add(listScrollPane, gridBagConstraints);
175: }// </editor-fold>//GEN-END:initComponents
176:
177: // Variables declaration - do not modify//GEN-BEGIN:variables
178: private javax.swing.JLabel label;
179: private javax.swing.JScrollPane listScrollPane;
180: private javax.swing.JList super TypeList;
181: // End of variables declaration//GEN-END:variables
182:
183: }
|