2 * Copyright 2004-2005 Alexey Efimov
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.
16 package org
.intellij
.images
.options
.impl
;
18 import com
.intellij
.openapi
.util
.JDOMExternalizable
;
19 import com
.intellij
.openapi
.util
.JDOMExternalizer
;
20 import org
.intellij
.images
.options
.TransparencyChessboardOptions
;
21 import org
.jdom
.Element
;
24 import java
.beans
.PropertyChangeSupport
;
27 * Background options implementation.
29 * @author <a href="mailto:aefimov.box@gmail.com">Alexey Efimov</a>
31 final class TransparencyChessboardOptionsImpl
implements TransparencyChessboardOptions
, JDOMExternalizable
{
32 private boolean showDefault
= true;
33 private int cellSize
= DEFAULT_CELL_SIZE
;
34 private Color whiteColor
= DEFAULT_WHITE_COLOR
;
35 private Color blackColor
= DEFAULT_BLACK_COLOR
;
36 private final PropertyChangeSupport propertyChangeSupport
;
38 TransparencyChessboardOptionsImpl(PropertyChangeSupport propertyChangeSupport
) {
39 this.propertyChangeSupport
= propertyChangeSupport
;
42 public boolean isShowDefault() {
46 public int getCellSize() {
50 public Color
getWhiteColor() {
54 public Color
getBlackColor() {
58 void setShowDefault(boolean showDefault
) {
59 boolean oldValue
= this.showDefault
;
60 if (oldValue
!= showDefault
) {
61 this.showDefault
= showDefault
;
62 propertyChangeSupport
.firePropertyChange(ATTR_SHOW_DEFAULT
, oldValue
, this.showDefault
);
66 void setCellSize(int cellSize
) {
67 int oldValue
= this.cellSize
;
68 if (oldValue
!= cellSize
) {
69 this.cellSize
= cellSize
;
70 propertyChangeSupport
.firePropertyChange(ATTR_CELL_SIZE
, oldValue
, this.cellSize
);
74 void setWhiteColor(Color whiteColor
) {
75 Color oldValue
= this.whiteColor
;
76 if (whiteColor
== null) {
77 this.whiteColor
= DEFAULT_WHITE_COLOR
;
79 if (!oldValue
.equals(whiteColor
)) {
80 this.whiteColor
= whiteColor
;
81 propertyChangeSupport
.firePropertyChange(ATTR_WHITE_COLOR
, oldValue
, this.whiteColor
);
85 void setBlackColor(Color blackColor
) {
86 Color oldValue
= this.blackColor
;
87 if (blackColor
== null) {
88 blackColor
= DEFAULT_BLACK_COLOR
;
90 if (!oldValue
.equals(blackColor
)) {
91 this.blackColor
= blackColor
;
92 propertyChangeSupport
.firePropertyChange(ATTR_BLACK_COLOR
, oldValue
, this.blackColor
);
96 public void inject(TransparencyChessboardOptions options
) {
97 setShowDefault(options
.isShowDefault());
98 setCellSize(options
.getCellSize());
99 setWhiteColor(options
.getWhiteColor());
100 setBlackColor(options
.getBlackColor());
103 public boolean setOption(String name
, Object value
) {
104 if (ATTR_SHOW_DEFAULT
.equals(name
)) {
105 setShowDefault((Boolean
)value
);
106 } else if (ATTR_CELL_SIZE
.equals(name
)) {
107 setCellSize((Integer
)value
);
108 } else if (ATTR_WHITE_COLOR
.equals(name
)) {
109 setWhiteColor((Color
)value
);
110 } else if (ATTR_BLACK_COLOR
.equals(name
)) {
111 setBlackColor((Color
)value
);
118 public void readExternal(Element element
) {
119 setShowDefault(JDOMExternalizer
.readBoolean(element
, ATTR_SHOW_DEFAULT
));
120 setCellSize(JDOMExternalizer
.readInteger(element
, ATTR_CELL_SIZE
, DEFAULT_CELL_SIZE
));
121 setWhiteColor(JDOMExternalizerEx
.readColor(element
, ATTR_WHITE_COLOR
, DEFAULT_WHITE_COLOR
));
122 setBlackColor(JDOMExternalizerEx
.readColor(element
, ATTR_BLACK_COLOR
, DEFAULT_BLACK_COLOR
));
125 public void writeExternal(Element element
) {
126 JDOMExternalizer
.write(element
, ATTR_SHOW_DEFAULT
, showDefault
);
127 JDOMExternalizer
.write(element
, ATTR_CELL_SIZE
, cellSize
);
128 JDOMExternalizerEx
.write(element
, ATTR_WHITE_COLOR
, whiteColor
);
129 JDOMExternalizerEx
.write(element
, ATTR_BLACK_COLOR
, blackColor
);
132 public boolean equals(Object o
) {
136 if (!(o
instanceof TransparencyChessboardOptions
)) {
140 TransparencyChessboardOptions otherOptions
= (TransparencyChessboardOptions
)o
;
142 return cellSize
== otherOptions
.getCellSize() &&
143 showDefault
== otherOptions
.isShowDefault() &&
144 (blackColor
!= null ?
145 blackColor
.equals(otherOptions
.getBlackColor()) :
146 otherOptions
.getBlackColor() == null) &&
147 (whiteColor
!= null ?
148 whiteColor
.equals(otherOptions
.getWhiteColor()) :
149 otherOptions
.getWhiteColor() == null);
153 public int hashCode() {
155 result
= (showDefault ?
1 : 0);
156 result
= 29 * result
+ cellSize
;
157 result
= 29 * result
+ (whiteColor
!= null ? whiteColor
.hashCode() : 0);
158 result
= 29 * result
+ (blackColor
!= null ? blackColor
.hashCode() : 0);