use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class IfCanBeSwitchInspection method createOptionsPanel.
@Override
public JComponent createOptionsPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
final JLabel label = new JLabel(InspectionGadgetsBundle.message("if.can.be.switch.minimum.branch.option"));
final NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
final JFormattedTextField valueField = new JFormattedTextField(formatter);
valueField.setValue(Integer.valueOf(minimumBranches));
valueField.setColumns(2);
final Document document = valueField.getDocument();
document.addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent e) {
try {
valueField.commitEdit();
minimumBranches = ((Number) valueField.getValue()).intValue();
} catch (ParseException ignore) {
// No luck this time
}
}
});
final GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets.bottom = 4;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.BASELINE_LEADING;
constraints.fill = GridBagConstraints.NONE;
constraints.insets.right = 10;
panel.add(label, constraints);
constraints.gridx = 1;
constraints.gridy = 0;
constraints.weightx = 1.0;
constraints.insets.right = 0;
panel.add(valueField, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 2;
final CheckBox checkBox1 = new CheckBox(InspectionGadgetsBundle.message("if.can.be.switch.int.option"), this, "suggestIntSwitches");
panel.add(checkBox1, constraints);
constraints.gridy = 2;
final CheckBox checkBox2 = new CheckBox(InspectionGadgetsBundle.message("if.can.be.switch.enum.option"), this, "suggestEnumSwitches");
panel.add(checkBox2, constraints);
constraints.gridy = 3;
constraints.weighty = 1.0;
final CheckBox checkBox3 = new CheckBox(InspectionGadgetsBundle.message("if.can.be.switch.null.safe.option"), this, "onlySuggestNullSafe");
panel.add(checkBox3, constraints);
return panel;
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class CreateClassDialog method createNorthPanel.
@Override
protected JComponent createNorthPanel() {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gbConstraints = new GridBagConstraints();
gbConstraints.insets = JBUI.insets(4, 8);
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.anchor = GridBagConstraints.WEST;
if (myClassNameEditable) {
gbConstraints.weightx = 0;
gbConstraints.gridwidth = 1;
panel.add(myInformationLabel, gbConstraints);
gbConstraints.insets = JBUI.insets(4, 8);
gbConstraints.gridx = 1;
gbConstraints.weightx = 1;
gbConstraints.gridwidth = 1;
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.anchor = GridBagConstraints.WEST;
panel.add(myTfClassName, gbConstraints);
myTfClassName.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
getOKAction().setEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(myTfClassName.getText()));
}
});
getOKAction().setEnabled(StringUtil.isNotEmpty(myClassName));
}
gbConstraints.gridx = 0;
gbConstraints.gridy = 2;
gbConstraints.weightx = 0;
gbConstraints.gridwidth = 1;
panel.add(myPackageLabel, gbConstraints);
gbConstraints.gridx = 1;
gbConstraints.weightx = 1;
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
myPackageComponent.getButton().doClick();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myPackageComponent.getChildComponent());
JPanel _panel = new JPanel(new BorderLayout());
_panel.add(myPackageComponent, BorderLayout.CENTER);
panel.add(_panel, gbConstraints);
gbConstraints.gridy = 3;
gbConstraints.gridx = 0;
gbConstraints.gridwidth = 2;
gbConstraints.insets.top = 12;
gbConstraints.anchor = GridBagConstraints.WEST;
gbConstraints.fill = GridBagConstraints.NONE;
final JBLabel label = new JBLabel(RefactoringBundle.message("target.destination.folder"));
panel.add(label, gbConstraints);
gbConstraints.gridy = 4;
gbConstraints.gridx = 0;
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.insets.top = 4;
panel.add(myDestinationCB, gbConstraints);
final boolean isMultipleSourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(myProject).size() > 1;
myDestinationCB.setVisible(isMultipleSourceRoots);
label.setVisible(isMultipleSourceRoots);
label.setLabelFor(myDestinationCB);
return panel;
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class CreateFieldFromParameterDialog method createNorthPanel.
@Override
protected JComponent createNorthPanel() {
if (myNames.length > 1) {
final ComboBox combobox = new ComboBox(myNames, 200);
myNameField = combobox;
combobox.setEditable(true);
combobox.setSelectedIndex(0);
combobox.setMaximumRowCount(8);
combobox.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (combobox.isPopupVisible()) {
combobox.setPopupVisible(false);
} else {
doCancelAction();
}
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
combobox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
updateOkStatus();
}
});
combobox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
updateOkStatus();
}
@Override
public void keyReleased(KeyEvent e) {
updateOkStatus();
}
@Override
public void keyTyped(KeyEvent e) {
updateOkStatus();
}
});
} else {
JTextField field = new JTextField() {
@Override
public Dimension getPreferredSize() {
Dimension size = super.getPreferredSize();
return new Dimension(200, size.height);
}
};
myNameField = field;
field.setText(myNames[0]);
field.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
updateOkStatus();
}
});
}
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints gbConstraints = new GridBagConstraints();
gbConstraints.insets = JBUI.insets(4);
gbConstraints.anchor = GridBagConstraints.EAST;
gbConstraints.fill = GridBagConstraints.BOTH;
gbConstraints.gridwidth = 1;
gbConstraints.weightx = 1;
gbConstraints.weighty = 1;
gbConstraints.gridx = 0;
gbConstraints.gridy = 0;
final JLabel typeLabel = new JLabel(CodeInsightBundle.message("dialog.create.field.from.parameter.field.type.label"));
panel.add(typeLabel, gbConstraints);
gbConstraints.gridx = 1;
if (myTypes.length > 1) {
myTypeSelector = new TypeSelector(myProject);
myTypeSelector.setTypes(myTypes);
} else {
myTypeSelector = new TypeSelector(myTypes[0], myProject);
}
panel.add(myTypeSelector.getComponent(), gbConstraints);
gbConstraints.gridwidth = 1;
gbConstraints.weightx = 0;
gbConstraints.weighty = 1;
gbConstraints.gridx = 0;
gbConstraints.gridy = 1;
JLabel namePrompt = new JLabel(CodeInsightBundle.message("dialog.create.field.from.parameter.field.name.label"));
panel.add(namePrompt, gbConstraints);
gbConstraints.gridwidth = 1;
gbConstraints.weightx = 1;
gbConstraints.gridx = 1;
gbConstraints.gridy = 1;
panel.add(myNameField, gbConstraints);
return panel;
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class SingleIntegerFieldOptionsPanel method setupIntegerFieldTrackingValue.
/**
* Sets integer number format to JFormattedTextField instance,
* sets value of JFormattedTextField instance to object's field value,
* synchronizes object's field value with the value of JFormattedTextField instance.
*
* @param textField JFormattedTextField instance
* @param owner an object whose field is synchronized with {@code textField}
* @param property object's field name for synchronization
*/
public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField, final InspectionProfileEntry owner, final String property) {
NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter)));
textField.setValue(getPropertyValue(owner, property));
final Document document = textField.getDocument();
document.addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent e) {
try {
textField.commitEdit();
setPropertyValue(owner, property, ((Number) textField.getValue()).intValue());
} catch (ParseException e1) {
// No luck this time
}
}
});
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class ProjectConfigurable method init.
private void init(final ProjectSdksModel model) {
myPanel = new JPanel(new GridBagLayout());
myPanel.setPreferredSize(JBUI.size(700, 500));
if (ProjectKt.isDirectoryBased(myProject)) {
final JPanel namePanel = new JPanel(new BorderLayout());
final JLabel label = new JLabel("<html><body><b>Project name:</b></body></html>", SwingConstants.LEFT);
namePanel.add(label, BorderLayout.NORTH);
myProjectName = new JTextField();
myProjectName.setColumns(40);
final JPanel nameFieldPanel = new JPanel();
nameFieldPanel.setLayout(new BoxLayout(nameFieldPanel, BoxLayout.X_AXIS));
nameFieldPanel.add(Box.createHorizontalStrut(4));
nameFieldPanel.add(myProjectName);
namePanel.add(nameFieldPanel, BorderLayout.CENTER);
final JPanel wrapper = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
wrapper.add(namePanel);
wrapper.setAlignmentX(0);
myPanel.add(wrapper, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.insets(4, 0, 10, 0), 0, 0));
}
myProjectJdkConfigurable = new ProjectJdkConfigurable(myProject, model);
myPanel.add(myProjectJdkConfigurable.createComponent(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.insetsTop(4), 0, 0));
myPanel.add(myWholePanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insetsTop(4), 0, 0));
myPanel.setBorder(new EmptyBorder(0, 10, 0, 10));
myProjectCompilerOutput.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
if (myFreeze)
return;
myModulesConfigurator.processModuleCompilerOutputChanged(getCompilerOutputUrl());
}
});
myProjectJdkConfigurable.addChangeListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myLanguageLevelCombo.sdkUpdated(myProjectJdkConfigurable.getSelectedProjectJdk(), myProject.isDefault());
LanguageLevelProjectExtensionImpl.getInstanceImpl(myProject).setCurrentLevel(myLanguageLevelCombo.getSelectedLevel());
}
});
myLanguageLevelCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
LanguageLevelProjectExtensionImpl.getInstanceImpl(myProject).setCurrentLevel(myLanguageLevelCombo.getSelectedLevel());
}
});
}
Aggregations