changedUpdate exception
[fedora-idea.git] / platform / platform-impl / src / com / intellij / ui / StateRestoringCheckBox.java
blobaa267c2f69df34f0b8dd39910b1b57b667eb6dab
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Eugene Zhuravlev
20 package com.intellij.ui;
22 import javax.swing.*;
24 /**
25 * When enabled the checkbox behaves like the ordinary checkbox
26 * If to use special methods to enable/disable it,
27 * it will manage different selected/unselected states for each mode - enabled or disabled
29 public class StateRestoringCheckBox extends JCheckBox {
30 private boolean myIsSelectedWhenSelectable;
32 public StateRestoringCheckBox() {
33 super();
34 myIsSelectedWhenSelectable = isSelected();
37 public StateRestoringCheckBox(Icon icon) {
38 super(icon);
39 myIsSelectedWhenSelectable = isSelected();
42 public StateRestoringCheckBox(Icon icon, boolean selected) {
43 super(icon, selected);
44 myIsSelectedWhenSelectable = isSelected();
47 public StateRestoringCheckBox(String text) {
48 super(text);
49 myIsSelectedWhenSelectable = isSelected();
52 public StateRestoringCheckBox(Action a) {
53 super(a);
54 myIsSelectedWhenSelectable = isSelected();
57 public StateRestoringCheckBox(String text, boolean selected) {
58 super(text, selected);
59 myIsSelectedWhenSelectable = isSelected();
62 public StateRestoringCheckBox(String text, Icon icon) {
63 super(text, icon);
64 myIsSelectedWhenSelectable = isSelected();
67 public StateRestoringCheckBox(String text, Icon icon, boolean selected) {
68 super(text, icon, selected);
69 myIsSelectedWhenSelectable = isSelected();
72 /**
73 * The method should be used instead of setEnabled(false) or disable() in order to support selected state saving/recovering
74 * Remembers the selected state of the checkbox when the checkbox is enabled, disables it
75 * and sets the selected state according to tha parameter pased
76 * @param isSelected the parameter telling whetheer the checkbox is selected when disabled
78 public void makeUnselectable(boolean isSelected) {
79 if (isEnabled()) {
80 myIsSelectedWhenSelectable = isSelected();
81 setEnabled(false);
83 setSelected(isSelected);
86 /**
87 * The method should be used instead of setEnabled(true) or enable() in order to support selected state saving/recovering
88 * Enables the checkbox and restores the selected state of the checkbox to the one, that it had before the makeUnselectable() method was called
89 * that was before the checkbox was disabled
91 public void makeSelectable() {
92 if (!isEnabled()) {
93 setEnabled(true);
94 setSelected(myIsSelectedWhenSelectable);
98 public boolean isSelectedWhenSelectable() {
99 if (isEnabled()) {
100 return isSelected();
102 return myIsSelectedWhenSelectable;