Java Code Examples for com.intellij.ui.components.JBCheckBox#addActionListener()

The following examples show how to use com.intellij.ui.components.JBCheckBox#addActionListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphDatabaseSupportConfiguration.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public JComponent createComponent() {
    isModified = false;

    analytics = AnalyticsApplicationComponent.getInstance();
    analyticsCheckBox = new JBCheckBox("Send anonymous usage statistics",
            SettingsComponent.getInstance().isAnalyticEnabled());
    analyticsCheckBox.addActionListener(e -> isModified = true);

    invertZoomCheckBox = new JBCheckBox("Invert mouse wheel zoom controls in Graph View",
            SettingsComponent.getInstance().isGraphViewZoomInverted());
    invertZoomCheckBox.addActionListener(e -> isModified = true);

    JPanel rootPane = new JPanel();
    rootPane.setLayout(new BoxLayout(rootPane, BoxLayout.Y_AXIS));
    rootPane.add(analyticsCheckBox);
    rootPane.add(invertZoomCheckBox);

    return rootPane;
}
 
Example 2
Source File: BoolServiceExtensionCheckbox.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
BoolServiceExtensionCheckbox(
  FlutterApp app,
  @NotNull ToggleableServiceExtensionDescription extensionDescription,
  String tooltip) {
  checkbox = new JBCheckBox(extensionDescription.getDisabledText());
  checkbox.setHorizontalAlignment(JLabel.LEFT);
  checkbox.setToolTipText(tooltip);
  assert (app.getVMServiceManager() != null);
  app.hasServiceExtension(extensionDescription.getExtension(), checkbox::setEnabled, app);

  checkbox.addActionListener((l) -> {
    final boolean newValue = checkbox.isSelected();
    app.getVMServiceManager().setServiceExtensionState(
      extensionDescription.getExtension(),
      newValue,
      newValue);
    if (app.isSessionActive()) {
      app.callBooleanExtension(extensionDescription.getExtension(), newValue);
    }
  });

  currentValueSubscription = app.getVMServiceManager().getServiceExtensionState(extensionDescription.getExtension()).listen(
    (state) -> {
      if (checkbox.isSelected() != state.isEnabled()) {
        checkbox.setSelected(state.isEnabled());
      }
    }, true);
}
 
Example 3
Source File: BoolServiceExtensionCheckbox.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
BoolServiceExtensionCheckbox(
  FlutterApp app,
  @NotNull ToggleableServiceExtensionDescription extensionDescription,
  String tooltip) {
  checkbox = new JBCheckBox(extensionDescription.getDisabledText());
  checkbox.setHorizontalAlignment(JLabel.LEFT);
  checkbox.setToolTipText(tooltip);
  assert (app.getVMServiceManager() != null);
  app.hasServiceExtension(extensionDescription.getExtension(), checkbox::setEnabled, app);

  checkbox.addActionListener((l) -> {
    final boolean newValue = checkbox.isSelected();
    app.getVMServiceManager().setServiceExtensionState(
      extensionDescription.getExtension(),
      newValue,
      newValue);
    if (app.isSessionActive()) {
      app.callBooleanExtension(extensionDescription.getExtension(), newValue);
    }
  });

  currentValueSubscription = app.getVMServiceManager().getServiceExtensionState(extensionDescription.getExtension()).listen(
    (state) -> {
      if (checkbox.isSelected() != state.isEnabled()) {
        checkbox.setSelected(state.isEnabled());
      }
    }, true);
}
 
Example 4
Source File: PantsProjectSettingsControl.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private JBCheckBox newEnableIcrementalImportCheckbox(){
  JBCheckBox checkbox = new JBCheckBox(PantsBundle.message("pants.settings.text.with.incremental.import"));
  checkbox.addActionListener(evt -> {
    myImportDepthSpinner.setValue(((JBCheckBox) evt.getSource()).isSelected() ? getInitialSettings().incrementalImportDepth : 0);
    myImportDepthSpinner.setEnabled(((JBCheckBox) evt.getSource()).isSelected());
  });
  return checkbox;
}
 
Example 5
Source File: AlternativeJREPanel.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
public AlternativeJREPanel() {
    myCbEnabled = new JBCheckBox(ExecutionBundle.message("run.configuration.use.alternate.jre.checkbox"));

    myFieldWithHistory = new TextFieldWithHistory();
    myFieldWithHistory.setHistorySize(-1);
    final List<String> foundJDKs = new ArrayList<>();
    final Sdk[] allJDKs = ProjectJdkTable.getInstance().getAllJdks();

    String javaHomeOfCurrentProcess = System.getProperty("java.home");
    if (javaHomeOfCurrentProcess != null && !javaHomeOfCurrentProcess.isEmpty()) {
        foundJDKs.add(javaHomeOfCurrentProcess);
    }

    for (Sdk sdk : allJDKs) {
        String name = sdk.getName();
        if (!foundJDKs.contains(name)) {
            foundJDKs.add(name);
        }
    }

    for (Sdk jdk : allJDKs) {
        String homePath = jdk.getHomePath();

        if (!SystemInfo.isMac) {
            final File jre = new File(jdk.getHomePath(), "jre");
            if (jre.isDirectory()) {
                homePath = jre.getPath();
            }
        }

        if (!foundJDKs.contains(homePath)) {
            foundJDKs.add(homePath);
        }
    }

    myFieldWithHistory.setHistory(foundJDKs);
    myPathField = new ComponentWithBrowseButton<>(myFieldWithHistory, null);
    myPathField.addBrowseFolderListener(ExecutionBundle.message("run.configuration.select.alternate.jre.label"),
            ExecutionBundle.message("run.configuration.select.jre.dir.label"),
            null, BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR,
            TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);

    setLayout(new MigLayout("ins 0, gap 10, fill, flowx"));
    add(myCbEnabled, "shrinkx");
    add(myPathField, "growx, pushx");

    InsertPathAction.addTo(myFieldWithHistory.getTextEditor());

    myCbEnabled.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            enabledChanged();
        }
    });
    enabledChanged();

    setAnchor(myCbEnabled);

    updateUI();
}
 
Example 6
Source File: RepositoryWithBranchPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
public RepositoryWithBranchPanel(@Nonnull final Project project, @Nonnull String repoName,
                                 @Nonnull String sourceName, @Nonnull PushTargetPanel<T> destPushTargetPanelComponent) {
  super();
  setLayout(new BorderLayout());
  myRepositoryCheckbox = new JBCheckBox();
  myRepositoryCheckbox.setFocusable(false);
  myRepositoryCheckbox.setOpaque(false);
  myRepositoryCheckbox.setBorder(null);
  myRepositoryCheckbox.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(@Nonnull ActionEvent e) {
      fireOnSelectionChange(myRepositoryCheckbox.isSelected());
    }
  });
  myRepositoryLabel = new JLabel(repoName);
  myLocalBranch = new JBLabel(sourceName);
  myArrowLabel = new JLabel(" " + UIUtil.rightArrow() + " ");
  myDestPushTargetPanelComponent = destPushTargetPanelComponent;
  myTextRenderer = new ColoredTreeCellRenderer() {
    @RequiredUIAccess
    @Override
    public void customizeCellRenderer(@Nonnull JTree tree,
                                      Object value,
                                      boolean selected,
                                      boolean expanded,
                                      boolean leaf,
                                      int row,
                                      boolean hasFocus) {

    }
  };
  myTextRenderer.setOpaque(false);
  layoutComponents();

  setInputVerifier(new InputVerifier() {
    @Override
    public boolean verify(JComponent input) {
      ValidationInfo error = myDestPushTargetPanelComponent.verify();
      if (error != null) {
        //noinspection ConstantConditions
        PopupUtil.showBalloonForComponent(error.component, error.message, MessageType.WARNING, false, project);
      }
      return error == null;
    }
  });

  JCheckBox emptyBorderCheckBox = new JCheckBox();
  emptyBorderCheckBox.setBorder(null);
}
 
Example 7
Source File: MoveChangesDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
public MoveChangesDialog(final Project project, Collection<Change> selected, final Set<ChangeList> changeLists, VirtualFile current) {
  super(project, true);
  mySelected = selected;
  setTitle("Move Changes to Active Changelist");
  myTreeList = new ChangesTreeList<Change>(project, selected, true, false, null, null) {

    @Override
    protected DefaultTreeModel buildTreeModel(List<Change> changes, ChangeNodeDecorator changeNodeDecorator) {
      return TreeModelBuilder.buildFromChangeLists(project, isShowFlatten(), changeLists);
    }

    @Override
    protected List<Change> getSelectedObjects(ChangesBrowserNode<Change> node) {
      return node.getAllChangesUnder();
    }

    @Override
    protected Change getLeadSelectedObject(ChangesBrowserNode node) {
      final Object o = node.getUserObject();
      if (o instanceof Change) {
        return (Change) o;
      }
      return null;
    }
  };

  myChanges = new ArrayList<>();
  for (ChangeList list : changeLists) {
    myChanges.addAll(list.getChanges());
  }
  myTreeList.setChangesToDisplay(myChanges, current);

  myCheckBox = new JBCheckBox("Select current file only");
  myCheckBox.setMnemonic('c');
  myCheckBox.addActionListener(e -> setSelected(myCheckBox.isSelected()));

  boolean selectCurrent = PropertiesComponent.getInstance().getBoolean(MOVE_CHANGES_CURRENT_ONLY);
  myCheckBox.setSelected(selectCurrent);
  setSelected(selectCurrent);

  init();
}
 
Example 8
Source File: FileStructurePopup.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void addCheckbox(JPanel panel, TreeAction action) {
  String text = action instanceof FileStructureFilter
                ? ((FileStructureFilter)action).getCheckBoxText()
                : action instanceof FileStructureNodeProvider ? ((FileStructureNodeProvider)action).getCheckBoxText() : null;

  if (text == null) return;

  Shortcut[] shortcuts = extractShortcutFor(action);


  JBCheckBox checkBox = new JBCheckBox();
  checkBox.setOpaque(false);
  UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, checkBox);

  boolean selected = getDefaultValue(action);
  checkBox.setSelected(selected);
  boolean isRevertedStructureFilter = action instanceof FileStructureFilter && ((FileStructureFilter)action).isReverted();
  myTreeActionsOwner.setActionIncluded(action, isRevertedStructureFilter != selected);
  checkBox.addActionListener(__ -> {
    boolean state = checkBox.isSelected();
    if (!myAutoClicked.contains(checkBox)) {
      saveState(action, state);
    }
    myTreeActionsOwner.setActionIncluded(action, isRevertedStructureFilter != state);
    rebuild(false).onProcessed(ignore -> {
      if (mySpeedSearch.isPopupActive()) {
        mySpeedSearch.refreshSelection();
      }
    });
  });
  checkBox.setFocusable(false);

  if (shortcuts.length > 0) {
    text += " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")";
    DumbAwareAction.create(e -> checkBox.doClick()).registerCustomShortcutSet(new CustomShortcutSet(shortcuts), myTree);
  }
  checkBox.setText(StringUtil.capitalize(StringUtil.trimStart(text.trim(), "Show ")));
  panel.add(checkBox);

  myCheckBoxes.put(action.getClass(), checkBox);
}