use of java.awt.event.ItemListener in project intellij-community by JetBrains.
the class GrIntroduceParameterDialog method init.
@Override
protected void init() {
super.init();
JavaRefactoringSettings settings = JavaRefactoringSettings.getInstance();
initReplaceFieldsWithGetters(settings);
myDeclareFinalCheckBox.setSelected(hasFinalModifier());
myDelegateViaOverloadingMethodCheckBox.setVisible(myInfo.getToSearchFor() != null);
setTitle(RefactoringBundle.message("introduce.parameter.title"));
myTable.init(myInfo);
final GrParameter[] parameters = myInfo.getToReplaceIn().getParameters();
toRemoveCBs.forEachEntry(new TObjectIntProcedure<JCheckBox>() {
@Override
public boolean execute(JCheckBox checkbox, int index) {
checkbox.setSelected(true);
final GrParameter param = parameters[index];
final ParameterInfo pinfo = findParamByOldName(param.getName());
if (pinfo != null) {
pinfo.passAsParameter = false;
}
return true;
}
});
updateSignature();
if (myCanIntroduceSimpleParameter) {
mySignaturePanel.setVisible(false);
//action to hide signature panel if we have variants to introduce simple parameter
myTypeComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
mySignaturePanel.setVisible(myTypeComboBox.isClosureSelected());
pack();
}
});
}
final PsiType closureReturnType = inferClosureReturnType();
if (PsiType.VOID.equals(closureReturnType)) {
myForceReturnCheckBox.setEnabled(false);
myForceReturnCheckBox.setSelected(false);
} else {
myForceReturnCheckBox.setSelected(isForceReturn());
}
if (myInfo.getToReplaceIn() instanceof GrClosableBlock) {
myDelegateViaOverloadingMethodCheckBox.setEnabled(false);
myDelegateViaOverloadingMethodCheckBox.setToolTipText("Delegating is not allowed in closure context");
}
pack();
}
use of java.awt.event.ItemListener in project intellij-community by JetBrains.
the class ComponentItemDialog method showGroupChooser.
void showGroupChooser(GroupItem defaultGroup) {
myGroupLabel.setVisible(true);
myGroupComboBox.setVisible(true);
List<GroupItem> groups = Palette.getInstance(myProject).getGroups();
myGroupComboBox.setModel(new DefaultComboBoxModel(groups.toArray()));
myGroupComboBox.setSelectedItem(defaultGroup);
myGroupComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
updateOKAction();
}
});
updateOKAction();
}
use of java.awt.event.ItemListener in project kotlin by JetBrains.
the class KotlinExtractFunctionDialog method init.
@Override
protected void init() {
super.init();
ExtractableCodeDescriptor extractableCodeDescriptor = originalDescriptor.getDescriptor();
functionNameField = new NameSuggestionsField(ArrayUtil.toStringArray(extractableCodeDescriptor.getSuggestedNames()), project, KotlinFileType.INSTANCE);
functionNameField.addDataChangedListener(new NameSuggestionsField.DataChanged() {
@Override
public void dataChanged() {
update();
}
});
functionNamePanel.add(functionNameField, BorderLayout.CENTER);
functionNameLabel.setLabelFor(functionNameField);
List<KotlinType> possibleReturnTypes = ExtractableCodeDescriptorKt.getPossibleReturnTypes(extractableCodeDescriptor.getControlFlow());
if (possibleReturnTypes.size() > 1) {
DefaultComboBoxModel returnTypeBoxModel = new DefaultComboBoxModel(possibleReturnTypes.toArray());
returnTypeBox.setModel(returnTypeBoxModel);
returnTypeBox.setRenderer(new DefaultListCellRenderer() {
@NotNull
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
setText(IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType((KotlinType) value));
return this;
}
});
returnTypeBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(@NotNull ItemEvent e) {
update();
}
});
} else {
returnTypePanel.getParent().remove(returnTypePanel);
}
boolean enableVisibility = isVisibilitySectionAvailable();
visibilityBox.setEnabled(enableVisibility);
if (enableVisibility) {
String defaultVisibility = extractableCodeDescriptor.getVisibility();
if (defaultVisibility.isEmpty()) {
defaultVisibility = KtTokens.PUBLIC_KEYWORD.getValue();
}
visibilityBox.setSelectedItem(defaultVisibility);
}
visibilityBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(@NotNull ItemEvent e) {
update();
}
});
parameterTablePanel = new ExtractFunctionParameterTablePanel() {
@Override
protected void updateSignature() {
KotlinExtractFunctionDialog.this.update();
}
@Override
protected void onEnterAction() {
doOKAction();
}
@Override
protected void onCancelAction() {
doCancelAction();
}
};
parameterTablePanel.init(extractableCodeDescriptor.getReceiverParameter(), extractableCodeDescriptor.getParameters());
inputParametersPanel.setText("&Parameters");
inputParametersPanel.setLabelFor(parameterTablePanel.getTable());
inputParametersPanel.add(parameterTablePanel);
}
use of java.awt.event.ItemListener in project kotlin by JetBrains.
the class KotlinPullUpDialogBase method initClassCombo.
@SuppressWarnings("unchecked")
@Override
protected void initClassCombo(JComboBox classCombo) {
classCombo.setRenderer(new KotlinOrJavaClassCellRenderer());
classCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
if (myMemberSelectionPanel == null)
return;
AbstractMemberSelectionTable<KtNamedDeclaration, KotlinMemberInfo> table = myMemberSelectionPanel.getTable();
if (table == null)
return;
table.setMemberInfos(myMemberInfos);
table.fireExternalDataChange();
}
}
});
}
use of java.awt.event.ItemListener in project intellij-community by JetBrains.
the class PyChangeSignatureDialog method getTableEditor.
@Override
protected JBTableRowEditor getTableEditor(final JTable t, final ParameterTableModelItemBase<PyParameterInfo> item) {
return new JBTableRowEditor() {
private EditorTextField myNameEditor;
private EditorTextField myDefaultValueEditor;
private JCheckBox myDefaultInSignature;
@Override
public void prepareEditor(JTable table, int row) {
setLayout(new GridLayout(1, 3));
final JPanel parameterPanel = createParameterPanel();
add(parameterPanel);
final JPanel defaultValuePanel = createDefaultValuePanel();
add(defaultValuePanel);
final JPanel defaultValueCheckBox = createDefaultValueCheckBox();
add(defaultValueCheckBox);
final String nameText = myNameEditor.getText();
myDefaultValueEditor.setEnabled(!nameText.startsWith("*") && !PyNames.CANONICAL_SELF.equals(nameText));
myDefaultInSignature.setEnabled(!nameText.startsWith("*") && !PyNames.CANONICAL_SELF.equals(nameText));
}
private JPanel createDefaultValueCheckBox() {
final JPanel defaultValuePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
final JBLabel inSignatureLabel = new JBLabel(PyBundle.message("refactoring.change.signature.dialog.default.value.checkbox"), UIUtil.ComponentStyle.SMALL);
IJSwingUtilities.adjustComponentsOnMac(inSignatureLabel, myDefaultInSignature);
defaultValuePanel.add(inSignatureLabel, BorderLayout.WEST);
myDefaultInSignature = new JCheckBox();
myDefaultInSignature.setSelected(((PyParameterTableModelItem) item).isDefaultInSignature());
myDefaultInSignature.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent event) {
((PyParameterTableModelItem) item).setDefaultInSignature(myDefaultInSignature.isSelected());
}
});
myDefaultInSignature.addChangeListener(mySignatureUpdater);
myDefaultInSignature.setEnabled(item.parameter.getOldIndex() == -1);
defaultValuePanel.add(myDefaultInSignature, BorderLayout.EAST);
return defaultValuePanel;
}
private JPanel createDefaultValuePanel() {
final JPanel defaultValuePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(item.defaultValueCodeFragment);
myDefaultValueEditor = new EditorTextField(doc, getProject(), getFileType());
final JBLabel defaultValueLabel = new JBLabel(PyBundle.message("refactoring.change.signature.dialog.default.value.label"), UIUtil.ComponentStyle.SMALL);
IJSwingUtilities.adjustComponentsOnMac(defaultValueLabel, myDefaultValueEditor);
defaultValuePanel.add(defaultValueLabel);
defaultValuePanel.add(myDefaultValueEditor);
myDefaultValueEditor.setPreferredWidth(t.getWidth() / 2);
myDefaultValueEditor.addDocumentListener(mySignatureUpdater);
return defaultValuePanel;
}
private JPanel createParameterPanel() {
final JPanel namePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
myNameEditor = new EditorTextField(item.parameter.getName(), getProject(), getFileType());
final JBLabel nameLabel = new JBLabel(PyBundle.message("refactoring.change.signature.dialog.name.label"), UIUtil.ComponentStyle.SMALL);
IJSwingUtilities.adjustComponentsOnMac(nameLabel, myNameEditor);
namePanel.add(nameLabel);
namePanel.add(myNameEditor);
myNameEditor.setPreferredWidth(t.getWidth() / 2);
myNameEditor.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent event) {
fireDocumentChanged(event, 0);
myDefaultValueEditor.setEnabled(!myNameEditor.getText().startsWith("*"));
myDefaultInSignature.setEnabled(!myNameEditor.getText().startsWith("*"));
}
});
myNameEditor.addDocumentListener(mySignatureUpdater);
return namePanel;
}
@Override
public JBTableRow getValue() {
return new JBTableRow() {
@Override
public Object getValueAt(int column) {
switch(column) {
case 0:
return myNameEditor.getText().trim();
case 1:
return new Pair<>(item.defaultValueCodeFragment, ((PyParameterTableModelItem) item).isDefaultInSignature());
}
return null;
}
};
}
@Override
public JComponent getPreferredFocusedComponent() {
return myNameEditor.getFocusTarget();
}
@Override
public JComponent[] getFocusableComponents() {
final List<JComponent> focusable = new ArrayList<>();
focusable.add(myNameEditor.getFocusTarget());
if (myDefaultValueEditor != null) {
focusable.add(myDefaultValueEditor.getFocusTarget());
}
return focusable.toArray(new JComponent[focusable.size()]);
}
};
}
Aggregations