blob: 56fa9996a2115954b81ce85067792426c6705bdc [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.refactoring.java.ui;
import java.awt.Dimension;
import java.awt.event.ItemEvent;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.swing.Icon;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeListener;
import org.netbeans.api.java.source.CompilationController;
import org.netbeans.api.java.source.ui.ElementIcons;
import org.netbeans.modules.refactoring.java.RefactoringModule;
/**
*
* @author Ralph Ruijs <ralphbenjamin@netbeans.org>
*/
public class WhereUsedPanelClass extends WhereUsedPanel.WhereUsedInnerPanel {
private final transient ChangeListener parent;
/**
* Creates new form WhereUsedPanelClass
*/
public WhereUsedPanelClass(ChangeListener parent) {
this.parent = parent;
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup = new javax.swing.ButtonGroup();
c_subclasses = new javax.swing.JRadioButton();
c_usages = new javax.swing.JRadioButton();
c_directOnly = new javax.swing.JRadioButton();
searchInComments = new javax.swing.JCheckBox();
label = new javax.swing.JLabel();
lbl_usagesof = new javax.swing.JLabel();
buttonGroup.add(c_subclasses);
org.openide.awt.Mnemonics.setLocalizedText(c_subclasses, org.openide.util.NbBundle.getMessage(WhereUsedPanelClass.class, "LBL_FindAllSubtypes")); // NOI18N
buttonGroup.add(c_usages);
c_usages.setSelected(true);
org.openide.awt.Mnemonics.setLocalizedText(c_usages, org.openide.util.NbBundle.getMessage(WhereUsedPanelClass.class, "LBL_FindUsages")); // NOI18N
buttonGroup.add(c_directOnly);
org.openide.awt.Mnemonics.setLocalizedText(c_directOnly, org.openide.util.NbBundle.getMessage(WhereUsedPanelClass.class, "LBL_FindDirectSubtypesOnly")); // NOI18N
searchInComments.setSelected(((Boolean) RefactoringModule.getOption("searchInComments.whereUsed", Boolean.FALSE)).booleanValue());
org.openide.awt.Mnemonics.setLocalizedText(searchInComments, org.openide.util.NbBundle.getBundle(WhereUsedPanelClass.class).getString("LBL_SearchInComents")); // NOI18N
searchInComments.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
searchInCommentsItemStateChanged(evt);
}
});
label.setIcon(org.openide.util.ImageUtilities.loadImageIcon("/org/netbeans/modules/refactoring/java/resources/warning_16.png", false)); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(label, "<<Element>>"); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(lbl_usagesof, org.openide.util.NbBundle.getMessage(WhereUsedPanelClass.class, "LBL_UsagesOfElement")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(lbl_usagesof)
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(searchInComments)
.addComponent(c_usages)
.addComponent(c_subclasses)
.addComponent(c_directOnly)
.addComponent(label, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE))
.addGap(0, 0, 0))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, 0)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbl_usagesof)
.addComponent(label))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(searchInComments)
.addGap(6, 6, 6)
.addComponent(c_usages)
.addGap(6, 6, 6)
.addComponent(c_subclasses)
.addGap(6, 6, 6)
.addComponent(c_directOnly)
.addGap(0, 0, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void searchInCommentsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_searchInCommentsItemStateChanged
// used for change default value for searchInComments check-box.
// The value is persisted and then used as default in next IDE run.
Boolean b = evt.getStateChange() == ItemEvent.SELECTED ? Boolean.TRUE : Boolean.FALSE;
RefactoringModule.setOption("searchInComments.whereUsed", b); // NOI18N
}//GEN-LAST:event_searchInCommentsItemStateChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup;
private javax.swing.JRadioButton c_directOnly;
private javax.swing.JRadioButton c_subclasses;
private javax.swing.JRadioButton c_usages;
private javax.swing.JLabel label;
private javax.swing.JLabel lbl_usagesof;
private javax.swing.JCheckBox searchInComments;
// End of variables declaration//GEN-END:variables
@Override
void initialize(final Element element, CompilationController info) {
final String labelText = UIUtilities.createHeader((TypeElement)element, info.getElements().isDeprecated(element), false, false, true);
final Icon labelIcon = ElementIcons.getElementIcon(element.getKind(), element.getModifiers());
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Dimension preferredSize = label.getPreferredSize();
label.setText(labelText);
label.setIcon(labelIcon);
label.setPreferredSize(preferredSize);
label.setMinimumSize(preferredSize);
}
});
}
public boolean isClassSubTypes() {
return c_subclasses.isSelected();
}
public boolean isClassSubTypesDirectOnly() {
return c_directOnly.isSelected();
}
public boolean isClassFindUsages() {
return c_usages.isSelected();
}
@Override
public boolean isSearchInComments() {
return searchInComments.isSelected();
}
}