2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.refactoring.java.ui;
44
import java.awt.Component;
45
import java.util.Collections;
46
import javax.lang.model.element.Modifier;
47
import javax.swing.DefaultComboBoxModel;
48
import javax.swing.DefaultListCellRenderer;
49
import javax.swing.Icon;
50
import javax.swing.JList;
51
import javax.swing.JPanel;
52
import javax.swing.ListSelectionModel;
53
import org.netbeans.api.java.source.ElementHandle;
54
import org.netbeans.api.java.source.TreePathHandle;
55
import org.netbeans.api.java.source.UiUtils;
56
import org.netbeans.modules.refactoring.java.RetoucheUtils;
57
import org.netbeans.modules.refactoring.java.api.UseSuperTypeRefactoring;
58
import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
59
import org.openide.util.NbBundle;
62
* UseSuperTypePanel.java
64
* Created on June 20, 2005
66
* @author Bharath Ravi Kumar
70
* The panel for the use super type refactoring
72
public class UseSuperTypePanel extends JPanel implements CustomRefactoringPanel {
74
private final UseSuperTypeRefactoring refactoring;
76
* Creates new form UseSuperTypePanel
77
* @param refactoring The use super type refactoring that is
80
public UseSuperTypePanel(UseSuperTypeRefactoring refactoring) {
81
this.refactoring = refactoring;
83
TreePathHandle subType = (TreePathHandle) refactoring.getTypeElement();
85
String className = RetoucheUtils.getSimpleName(subType);
86
title = NbBundle.getMessage(UseSuperTypePanel.class, "LBL_UseSyperTypeTitle", className);
88
superTypeList.setCellRenderer(new DefaultListCellRenderer() {
91
public Component getListCellRendererComponent(JList list,
92
Object value, int index, boolean isSelected,
93
boolean cellHasFocus) {
95
super.getListCellRendererComponent(list,
96
((ElementHandle)value).getBinaryName(), index,
97
isSelected, cellHasFocus);
99
if (value instanceof ElementHandle) {
100
Icon i = UiUtils.getElementIcon(((ElementHandle) value).getKind(), Collections.singleton(Modifier.PUBLIC));
107
superTypeList.setModel(new DefaultComboBoxModel(refactoring.getCandidateSuperTypes()));
108
superTypeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
109
superTypeList.setSelectedIndex(0);
112
public void initialize() {
115
public Component getComponent(){
119
* Returns the targer super type to be used
120
* @return The target super type Object
122
public ElementHandle getSuperType(){
123
return (ElementHandle) superTypeList.getSelectedValue();
126
/** This method is called from within the constructor to
127
* initialize the form.
128
* WARNING: Do NOT modify this code. The content of this method is
129
* always regenerated by the Form Editor.
131
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
132
private void initComponents() {
133
java.awt.GridBagConstraints gridBagConstraints;
135
label = new javax.swing.JLabel();
136
listScrollPane = new javax.swing.JScrollPane();
137
superTypeList = new javax.swing.JList();
139
setMaximumSize(new java.awt.Dimension(600, 500));
140
setPreferredSize(new java.awt.Dimension(300, 200));
141
setLayout(new java.awt.GridBagLayout());
143
label.setLabelFor(superTypeList);
144
org.openide.awt.Mnemonics.setLocalizedText(label, org.openide.util.NbBundle.getBundle(UseSuperTypePanel.class).getString("LBL_UseSuperType")); // NOI18N
145
gridBagConstraints = new java.awt.GridBagConstraints();
146
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
147
add(label, gridBagConstraints);
149
superTypeList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
150
listScrollPane.setViewportView(superTypeList);
151
superTypeList.getAccessibleContext().setAccessibleName(null);
152
superTypeList.getAccessibleContext().setAccessibleDescription(null);
154
gridBagConstraints = new java.awt.GridBagConstraints();
155
gridBagConstraints.gridx = 0;
156
gridBagConstraints.gridy = 1;
157
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
158
gridBagConstraints.weightx = 1.0;
159
gridBagConstraints.weighty = 1.0;
160
add(listScrollPane, gridBagConstraints);
161
}// </editor-fold>//GEN-END:initComponents
164
// Variables declaration - do not modify//GEN-BEGIN:variables
165
private javax.swing.JLabel label;
166
private javax.swing.JScrollPane listScrollPane;
167
private javax.swing.JList superTypeList;
168
// End of variables declaration//GEN-END:variables