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
.ZoomOptions
;
21 import org
.jdom
.Element
;
24 import java
.beans
.PropertyChangeSupport
;
27 * Zoom options implementation.
29 * @author <a href="mailto:aefimov.box@gmail.com">Alexey Efimov</a>
31 final class ZoomOptionsImpl
implements ZoomOptions
, JDOMExternalizable
{
32 private boolean wheelZooming
;
33 private boolean smartZooming
= true;
34 private int prefferedWidth
= DEFAULT_PREFFERED_SIZE
.width
;
35 private int prefferedHeight
= DEFAULT_PREFFERED_SIZE
.height
;
36 private final PropertyChangeSupport propertyChangeSupport
;
38 ZoomOptionsImpl(PropertyChangeSupport propertyChangeSupport
) {
39 this.propertyChangeSupport
= propertyChangeSupport
;
42 public boolean isWheelZooming() {
46 public boolean isSmartZooming() {
50 public Dimension
getPrefferedSize() {
51 return new Dimension(prefferedWidth
, prefferedHeight
);
54 void setWheelZooming(boolean wheelZooming
) {
55 boolean oldValue
= this.wheelZooming
;
56 if (oldValue
!= wheelZooming
) {
57 this.wheelZooming
= wheelZooming
;
58 propertyChangeSupport
.firePropertyChange(ATTR_WHEEL_ZOOMING
, oldValue
, this.wheelZooming
);
62 void setSmartZooming(boolean smartZooming
) {
63 boolean oldValue
= this.smartZooming
;
64 if (oldValue
!= smartZooming
) {
65 this.smartZooming
= smartZooming
;
66 propertyChangeSupport
.firePropertyChange(ATTR_SMART_ZOOMING
, oldValue
, this.smartZooming
);
70 void setPrefferedSize(Dimension prefferedSize
) {
71 if (prefferedSize
== null) {
72 prefferedSize
= DEFAULT_PREFFERED_SIZE
;
74 setPrefferedWidth(prefferedSize
.width
);
75 setPrefferedHeight(prefferedSize
.height
);
78 void setPrefferedWidth(int prefferedWidth
) {
79 int oldValue
= this.prefferedWidth
;
80 if (oldValue
!= prefferedWidth
) {
81 this.prefferedWidth
= prefferedWidth
;
82 propertyChangeSupport
.firePropertyChange(ATTR_PREFFERED_WIDTH
, oldValue
, this.prefferedWidth
);
86 void setPrefferedHeight(int prefferedHeight
) {
87 int oldValue
= this.prefferedHeight
;
88 if (oldValue
!= prefferedHeight
) {
89 this.prefferedHeight
= prefferedHeight
;
90 propertyChangeSupport
.firePropertyChange(ATTR_PREFFERED_HEIGHT
, oldValue
, this.prefferedHeight
);
94 public void inject(ZoomOptions options
) {
95 setWheelZooming(options
.isWheelZooming());
96 setSmartZooming(options
.isSmartZooming());
97 setPrefferedSize(options
.getPrefferedSize());
100 public boolean setOption(String name
, Object value
) {
101 if (ATTR_WHEEL_ZOOMING
.equals(name
)) {
102 setWheelZooming((Boolean
)value
);
103 } else if (ATTR_SMART_ZOOMING
.equals(name
)) {
104 setSmartZooming((Boolean
)value
);
105 } else if (ATTR_PREFFERED_WIDTH
.equals(name
)) {
106 setPrefferedWidth((Integer
)value
);
107 } else if (ATTR_PREFFERED_HEIGHT
.equals(name
)) {
108 setPrefferedHeight((Integer
)value
);
115 public void readExternal(Element element
) {
116 setWheelZooming(JDOMExternalizer
.readBoolean(element
, ATTR_WHEEL_ZOOMING
));
117 setSmartZooming(JDOMExternalizer
.readBoolean(element
, ATTR_SMART_ZOOMING
));
118 setPrefferedWidth(JDOMExternalizer
.readInteger(element
, ATTR_PREFFERED_WIDTH
, DEFAULT_PREFFERED_SIZE
.width
));
119 setPrefferedHeight(JDOMExternalizer
.readInteger(element
, ATTR_PREFFERED_HEIGHT
, DEFAULT_PREFFERED_SIZE
.height
));
122 public void writeExternal(Element element
) {
123 JDOMExternalizer
.write(element
, ATTR_WHEEL_ZOOMING
, wheelZooming
);
124 JDOMExternalizer
.write(element
, ATTR_SMART_ZOOMING
, smartZooming
);
125 JDOMExternalizer
.write(element
, ATTR_PREFFERED_WIDTH
, prefferedWidth
);
126 JDOMExternalizer
.write(element
, ATTR_PREFFERED_HEIGHT
, prefferedHeight
);
129 public boolean equals(Object obj
) {
133 if (!(obj
instanceof ZoomOptions
)) {
137 ZoomOptions otherOptions
= (ZoomOptions
)obj
;
139 Dimension prefferedSize
= otherOptions
.getPrefferedSize();
140 return prefferedSize
!= null && prefferedHeight
== prefferedSize
.height
&&
141 prefferedWidth
== prefferedSize
.width
&&
142 smartZooming
== otherOptions
.isSmartZooming() &&
143 wheelZooming
== otherOptions
.isWheelZooming();
147 public int hashCode() {
149 result
= (wheelZooming ?
1 : 0);
150 result
= 29 * result
+ (smartZooming ?
1 : 0);
151 result
= 29 * result
+ prefferedWidth
;
152 result
= 29 * result
+ prefferedHeight
;