public CheckBoxBinding(final ThreeStateCheckBox common, final List<JCheckBox> checkBoxesList) { LOG.assertTrue(!checkBoxesList.isEmpty()); myCommon = common; myCheckBoxesList = checkBoxesList; Boolean initialValue = checkBoxesList.get(0).isSelected(); myInitialValues = new ArrayList<Boolean>(); for (JCheckBox checkBox : checkBoxesList) { boolean value = checkBox.isSelected(); myInitialValues.add(value); if (initialValue != null && value != initialValue) { initialValue = null; } } if (initialValue != null) { common.setThirdStateEnabled(false); common.setSelected(initialValue); } else { common.setThirdStateEnabled(true); common.setState(ThreeStateCheckBox.State.DONT_CARE); } myCommon.addActionListener(this); }
@Override public void actionPerformed(final ActionEvent e) { ThreeStateCheckBox.State state = myCommon.getState(); for (int i = 0; i < myCheckBoxesList.size(); i++) { boolean value = state == ThreeStateCheckBox.State.SELECTED ? true : state == ThreeStateCheckBox.State.NOT_SELECTED ? false : myInitialValues.get(i); JCheckBox checkBox = myCheckBoxesList.get(i); if (value != checkBox.isSelected()) { ButtonModel model = checkBox.getModel(); model.setArmed(true); model.setPressed(true); model.setPressed(false); model.setArmed(false); } } }
public Renderer() { super(new BorderLayout()); myCheckbox = new ThreeStateCheckBox(); myTextRenderer = new ColoredTreeCellRenderer() { @Override public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { } }; myTextRenderer.setOpaque(true); add(myCheckbox, BorderLayout.WEST); add(myTextRenderer, BorderLayout.CENTER); }
public void updateShowContentCheckbox() { final ThreeStateCheckBox.State state; if (mySubstitutionParameters.isAllSubstituted()) { state = ThreeStateCheckBox.State.SELECTED; } else if (mySubstitutionParameters.isNoneSubstituted()) { state = ThreeStateCheckBox.State.NOT_SELECTED; } else { state = ThreeStateCheckBox.State.DONT_CARE; } myShowContentCheckBox.setThirdStateEnabled(state == ThreeStateCheckBox.State.DONT_CARE); myShowContentCheckBox.setState(state); onShowContentSettingsChanged(); }
@Override public void bind(@NotNull ThreeStateCheckBox common, @NotNull FacetEditor[] editors, @NotNull NotNullFunction<FacetEditor, JCheckBox> fun) { List<JCheckBox> checkBoxesList = new ArrayList<JCheckBox>(); for (FacetEditor editor : editors) { checkBoxesList.add(fun.fun(editor)); } CheckBoxBinding checkBoxBinding = new CheckBoxBinding(common, checkBoxesList); myBindings.add(checkBoxBinding); }
@Override public final Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (!(value instanceof UpdaterTreeNode)) { return null; } UpdaterTreeNode node = (UpdaterTreeNode)value; invalidate(); myCheckbox.setVisible(true); if (node.getCurrentState() == NodeStateHolder.SelectedState.MIXED) { myCheckbox.setState(ThreeStateCheckBox.State.DONT_CARE); } else { myCheckbox.setSelected(node.getCurrentState() == NodeStateHolder.SelectedState.INSTALLED); } myCheckbox.setOpaque(false); myCheckbox.setBackground(null); setBackground(null); myTextRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (UIUtil.isUnderGTKLookAndFeel()) { final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground(); UIUtil.changeBackGround(this, background); } else if (UIUtil.isUnderNimbusLookAndFeel()) { UIUtil.changeBackGround(this, UIUtil.TRANSPARENT_COLOR); } node.customizeRenderer(this, tree, selected, expanded, leaf, row, hasFocus); revalidate(); return this; }
public CheckboxTreeCellRendererBase(boolean opaque, final boolean usePartialStatusForParentNodes) { super(new BorderLayout()); myUsePartialStatusForParentNodes = usePartialStatusForParentNodes; myCheckbox = new ThreeStateCheckBox(); myCheckbox.setSelected(false); myCheckbox.setThirdStateEnabled(false); myTextRenderer = new ColoredTreeCellRenderer() { @RequiredDispatchThread @Override public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { } }; myTextRenderer.setOpaque(opaque); add(myCheckbox, BorderLayout.WEST); add(myTextRenderer, BorderLayout.CENTER); }
@Override public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (!(value instanceof DefaultMutableTreeNode)) { return; } myCheckbox.setBorder(null); //checkBox may have no border by default, but insets are not null, // it depends on LaF, OS and isItRenderedPane, see com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxBorder. // null border works as expected always. if (value instanceof RepositoryNode) { //todo simplify, remove instance of RepositoryNode valueNode = (RepositoryNode)value; myCheckbox.setVisible(valueNode.isCheckboxVisible()); if (valueNode.isChecked() && valueNode.isLoading()) { myCheckbox.setState(ThreeStateCheckBox.State.DONT_CARE); } else { myCheckbox.setSelected(valueNode.isChecked()); } } Object userObject = ((DefaultMutableTreeNode)value).getUserObject(); ColoredTreeCellRenderer renderer = getTextRenderer(); if (value instanceof CustomRenderedTreeNode) { if (tree.isEditing() && mySyncStrategy && value instanceof RepositoryNode) { //sync rendering all editable fields ((RepositoryNode)value).render(renderer, mySyncRenderedText); } else { ((CustomRenderedTreeNode)value).render(renderer); } } else { renderer.append(userObject == null ? "" : userObject.toString()); } }
private void createUIComponents() { myShowContentCheckBox = new ThreeStateCheckBox(); myShowSpecificContentOptionsButton = new FixedSizeButton(16); }
/** * Binds <code>common</code> 3-state checkbox to checkboxes in facet editors in such a way that all changes in it will be propogated to * target checkboxes. * @param common checkbox * @param editors editors * @param fun maps a facet editor to checkbox inside one of its tabs */ void bind(@NotNull ThreeStateCheckBox common, @NotNull FacetEditor[] editors, @NotNull NotNullFunction<FacetEditor, JCheckBox> fun);