01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.mapgraphic.grid;
16:
17: import java.awt.Color;
18: import java.io.IOException;
19: import java.net.URL;
20:
21: import net.refractions.udig.catalog.IGeoResource;
22: import net.refractions.udig.mapgraphic.grid.GridStyle.Type;
23: import net.refractions.udig.project.StyleContent;
24:
25: import org.eclipse.core.runtime.IProgressMonitor;
26: import org.eclipse.ui.IMemento;
27:
28: public class GridStyleContent extends StyleContent {
29: private static final String LINE_STYLE_ID = "LINE_STYLE_ID";
30: private static final String LINE_WIDTH_ID = "LINE_WIDTH_ID";
31: private static final String RED_ID = "RED_ID";
32: private static final String GREEN_ID = "GREEN_ID";
33: private static final String BLUE_ID = "BLUE_ID";
34: private static final String ALPHA_ID = "ALPHA_ID";
35: private static final String TYPE_ID = "TYPE_ID";
36: private static final String DX_ID = "DX_ID";
37: private static final String DY_ID = "DY_ID";
38:
39: public GridStyleContent() {
40: super (GridStyle.ID);
41: }
42:
43: @Override
44: public Object createDefaultStyle(IGeoResource resource,
45: Color colour, IProgressMonitor monitor) throws IOException {
46: if (resource.canResolve(GridMapGraphic.class))
47: return GridStyle.DEFAULT_STYLE;
48:
49: return null;
50: }
51:
52: @Override
53: public Class getStyleClass() {
54: return GridStyle.class;
55: }
56:
57: @Override
58: public Object load(IMemento memento) {
59: int lineStyle = memento.getInteger(LINE_STYLE_ID);
60: int lineWidth = memento.getInteger(LINE_WIDTH_ID);
61: int red = memento.getInteger(RED_ID);
62: int green = memento.getInteger(GREEN_ID);
63: int blue = memento.getInteger(BLUE_ID);
64: int alpha = memento.getInteger(ALPHA_ID);
65: Color color = new Color(red, green, blue, alpha);
66:
67: Type type = Type.valueOf(memento.getString(TYPE_ID));
68: double dx = Double.parseDouble(memento.getString(DX_ID));
69: double dy = Double.parseDouble(memento.getString(DY_ID));
70: return new GridStyle(type, dx, dy, color, lineStyle, lineWidth);
71: }
72:
73: @Override
74: public Object load(URL url, IProgressMonitor monitor)
75: throws IOException {
76: return null;
77: }
78:
79: @Override
80: public void save(IMemento memento, Object value) {
81: if (value instanceof GridStyle) {
82: GridStyle style = (GridStyle) value;
83:
84: memento.putInteger(LINE_STYLE_ID, style.getLineStyle());
85: memento.putInteger(LINE_WIDTH_ID, style.getLineWidth());
86: memento.putInteger(RED_ID, style.getColor().getRed());
87: memento.putInteger(GREEN_ID, style.getColor().getGreen());
88: memento.putInteger(BLUE_ID, style.getColor().getBlue());
89: memento.putInteger(ALPHA_ID, style.getColor().getAlpha());
90: memento.putString(TYPE_ID, style.getType().name());
91: memento.putString(DX_ID, String
92: .valueOf(style.getGridSize()[0]));
93: memento.putString(DY_ID, String
94: .valueOf(style.getGridSize()[1]));
95: }
96: }
97: }
|