001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.tools.edit.preferences;
016:
017: import java.awt.Color;
018:
019: import net.refractions.udig.project.internal.ProjectPlugin;
020: import net.refractions.udig.tools.edit.EditPlugin;
021: import net.refractions.udig.tools.edit.support.SnapBehaviour;
022:
023: import org.eclipse.jface.preference.IPreferenceStore;
024: import org.eclipse.jface.preference.PreferenceConverter;
025: import org.eclipse.swt.graphics.RGB;
026:
027: /**
028: * Provides help for obtaining values that are preferences or will be.
029: *
030: * @author jones
031: * @since 1.1.0
032: */
033: public class PreferenceUtil {
034:
035: protected static PreferenceUtil instance = new PreferenceUtil();
036:
037: protected PreferenceUtil() {
038: //singleton class
039: // only tests should override this.
040: }
041:
042: public static PreferenceUtil instance() {
043: return instance;
044: }
045:
046: IPreferenceStore store = EditPlugin.getDefault()
047: .getPreferenceStore();
048:
049: /**
050: * Returns the radius of a vertex
051: *
052: * @return
053: */
054: public int getVertexRadius() {
055: return store.getInt(PreferenceConstants.P_VERTEX_SIZE);
056: }
057:
058: /**
059: * Returns the color used to draw the outline of geoms on the EditBlackboard.
060: *
061: * @return Returns the color used to draw the outline of geoms on the EditBlackboard.
062: */
063: public Color getDrawGeomsLine() {
064: return getDrawSelectionFillColor();
065: }
066:
067: /**
068: * Returns the color used to draw the boxes around vertices.
069: *
070: * @return the color used to draw the boxes around vertices.
071: */
072: public Color getDrawVertexLineColor() {
073: String preferenceID = PreferenceConstants.P_VERTEX_OUTLINE_COLOR;
074: return getColor(store, preferenceID);
075: }
076:
077: private Color getColor(IPreferenceStore store2, String preferenceID) {
078: RGB rgb = PreferenceConverter.getColor(store2, preferenceID);
079: Color color = new Color(rgb.red, rgb.green, rgb.blue);
080: return color;
081: }
082:
083: /**
084: * Returns the color used to fill selected vertices.
085: *
086: * @return the color used to fill selected vertices.
087: */
088: public Color getDrawSelectionFillColor() {
089: return getColor(
090: ProjectPlugin.getPlugin().getPreferenceStore(),
091: net.refractions.udig.project.preferences.PreferenceConstants.P_SELECTION_COLOR);
092: }
093:
094: /**
095: * Sets the radius used for post-snapping.
096: *
097: * @param newRadius
098: */
099: public void setSnappingRadius(int newRadius) {
100: store.setValue(PreferenceConstants.P_SNAP_RADIUS, newRadius);
101: }
102:
103: /**
104: * Gets the radius used for post-snapping.
105: * @return the radius used for post-snapping
106: */
107: public int getSnappingRadius() {
108: return store.getInt(PreferenceConstants.P_SNAP_RADIUS);
109: }
110:
111: /**
112: * Returns the color used to draw the shape to show the PostSnapping area.
113: *
114: * @return Returns the color used to draw the shape to show the PostSnapping area.
115: */
116: public Color getFeedbackColor() {
117: return getColor(store, PreferenceConstants.P_SNAP_CIRCLE_COLOR);
118: }
119:
120: /**
121: * Returns the color used to draw the selection area.
122: *
123: * @return the color used to draw the selection area.
124: */
125: public Color getSelectionColor() {
126: return getColor(
127: ProjectPlugin.getPlugin().getPreferenceStore(),
128: net.refractions.udig.project.preferences.PreferenceConstants.P_SELECTION_COLOR);
129: }
130:
131: Color drawGeomsFill = new Color(144, 255, 144, 100);
132:
133: /**
134: * Returns the color used to fill the geoms on the EditBlackboard.
135: *
136: * @return Returns the color used to fill the geoms on the EditBlackboard.
137: */
138: public Color getDrawGeomsFill() {
139: return drawGeomsFill;
140: }
141:
142: /**
143: * Returns the color used to fill the non-selected vertices.
144: *
145: * @return Returns the color used to fill the non-selected vertices.
146: */
147: public Color getDrawVertexFillColor() {
148: return drawGeomsFill;
149: }
150:
151: /**
152: * Returns the current preference for snap behaviour.
153: *
154: * @return the current preference for snap behaviour.
155: */
156: public SnapBehaviour getSnapBehaviour() {
157: String preference = store
158: .getString(PreferenceConstants.P_SNAP_BEHAVIOUR);
159: if (preference.equals(SnapBehaviour.OFF.toString()))
160: return SnapBehaviour.OFF;
161: if (preference.equals(SnapBehaviour.SELECTED.toString()))
162: return SnapBehaviour.SELECTED;
163: if (preference.equals(SnapBehaviour.CURRENT_LAYER.toString()))
164: return SnapBehaviour.CURRENT_LAYER;
165: if (preference.equals(SnapBehaviour.ALL_LAYERS.toString()))
166: return SnapBehaviour.ALL_LAYERS;
167: if (preference.equals(SnapBehaviour.GRID.toString()))
168: return SnapBehaviour.GRID;
169:
170: return SnapBehaviour.OFF;
171: }
172:
173: public void setSnapBehaviour(SnapBehaviour behaviour) {
174: store.putValue(PreferenceConstants.P_SNAP_BEHAVIOUR, behaviour
175: .toString());
176: }
177:
178: /**
179: * Returns true if selected features should be hidden upon selection. This can be quite expensive.
180: *
181: * @return
182: */
183: public boolean hideSelectedLayers() {
184: return store
185: .getBoolean(PreferenceConstants.P_HIDE_SELECTED_FEATURES);
186: }
187:
188: public boolean isAdvancedEditingActive() {
189: return store.getBoolean(PreferenceConstants.P_ADVANCED_ACTIVE);
190: }
191:
192: public void setAdvancedEditingActive(boolean b) {
193: store.setValue(PreferenceConstants.P_ADVANCED_ACTIVE, b);
194: }
195:
196: public short getMessageDisplayDelay() {
197: return 2000;
198: }
199:
200: }
|