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
.InvalidDataException
;
19 import com
.intellij
.openapi
.util
.JDOMExternalizable
;
20 import com
.intellij
.openapi
.util
.WriteExternalException
;
21 import org
.intellij
.images
.options
.EditorOptions
;
22 import org
.intellij
.images
.options
.GridOptions
;
23 import org
.intellij
.images
.options
.TransparencyChessboardOptions
;
24 import org
.intellij
.images
.options
.ZoomOptions
;
25 import org
.jdom
.Element
;
27 import java
.beans
.PropertyChangeSupport
;
30 * Editor options implementation.
32 * @author <a href="mailto:aefimov.box@gmail.com">Alexey Efimov</a>
34 final class EditorOptionsImpl
implements EditorOptions
, JDOMExternalizable
{
35 private final GridOptions gridOptions
;
36 private final TransparencyChessboardOptions transparencyChessboardOptions
;
37 private final ZoomOptions zoomOptions
;
39 EditorOptionsImpl(PropertyChangeSupport propertyChangeSupport
) {
40 gridOptions
= new GridOptionsImpl(propertyChangeSupport
);
41 transparencyChessboardOptions
= new TransparencyChessboardOptionsImpl(propertyChangeSupport
);
42 zoomOptions
= new ZoomOptionsImpl(propertyChangeSupport
);
45 public GridOptions
getGridOptions() {
49 public TransparencyChessboardOptions
getTransparencyChessboardOptions() {
50 return transparencyChessboardOptions
;
53 public ZoomOptions
getZoomOptions() {
57 public EditorOptions
clone() throws CloneNotSupportedException
{
58 return (EditorOptions
)super.clone();
61 public void inject(EditorOptions options
) {
62 gridOptions
.inject(options
.getGridOptions());
63 transparencyChessboardOptions
.inject(options
.getTransparencyChessboardOptions());
64 zoomOptions
.inject(options
.getZoomOptions());
67 public boolean setOption(String name
, Object value
) {
68 return gridOptions
.setOption(name
, value
) ||
69 transparencyChessboardOptions
.setOption(name
, value
) ||
70 zoomOptions
.setOption(name
, value
);
73 public void readExternal(Element element
) throws InvalidDataException
{
74 ((JDOMExternalizable
)gridOptions
).readExternal(element
);
75 ((JDOMExternalizable
)transparencyChessboardOptions
).readExternal(element
);
76 ((JDOMExternalizable
)zoomOptions
).readExternal(element
);
79 public void writeExternal(Element element
) throws WriteExternalException
{
80 ((JDOMExternalizable
)gridOptions
).writeExternal(element
);
81 ((JDOMExternalizable
)transparencyChessboardOptions
).writeExternal(element
);
82 ((JDOMExternalizable
)zoomOptions
).writeExternal(element
);
85 public boolean equals(Object obj
) {
89 if (!(obj
instanceof EditorOptions
)) {
92 EditorOptions otherOptions
= (EditorOptions
)obj
;
93 GridOptions gridOptions
= otherOptions
.getGridOptions();
94 TransparencyChessboardOptions chessboardOptions
= otherOptions
.getTransparencyChessboardOptions();
95 ZoomOptions zoomOptions
= otherOptions
.getZoomOptions();
96 return gridOptions
!= null && gridOptions
.equals(getGridOptions()) &&
97 chessboardOptions
!= null && chessboardOptions
.equals(getTransparencyChessboardOptions()) &&
98 zoomOptions
!= null && zoomOptions
.equals(getZoomOptions());
101 public int hashCode() {
103 result
= (gridOptions
!= null ? gridOptions
.hashCode() : 0);
104 result
= 29 * result
+ (transparencyChessboardOptions
!= null ? transparencyChessboardOptions
.hashCode() : 0);
105 result
= 29 * result
+ (zoomOptions
!= null ? zoomOptions
.hashCode() : 0);