001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.legend.ui;
018:
019: import java.awt.Color;
020:
021: import net.refractions.udig.legend.internal.Messages;
022: import net.refractions.udig.project.IBlackboard;
023: import net.refractions.udig.project.internal.Layer;
024: import net.refractions.udig.project.internal.StyleBlackboard;
025: import net.refractions.udig.project.ui.internal.dialogs.ColorEditor;
026: import net.refractions.udig.style.IStyleConfigurator;
027:
028: import org.eclipse.swt.SWT;
029: import org.eclipse.swt.custom.ScrolledComposite;
030: import org.eclipse.swt.events.ModifyEvent;
031: import org.eclipse.swt.events.ModifyListener;
032: import org.eclipse.swt.events.SelectionEvent;
033: import org.eclipse.swt.events.SelectionListener;
034: import org.eclipse.swt.graphics.Point;
035: import org.eclipse.swt.graphics.RGB;
036: import org.eclipse.swt.layout.GridData;
037: import org.eclipse.swt.layout.GridLayout;
038: import org.eclipse.swt.widgets.Composite;
039: import org.eclipse.swt.widgets.Label;
040: import org.eclipse.swt.widgets.Text;
041:
042: public class LegendGraphicStyleConfigurator extends IStyleConfigurator
043: implements SelectionListener, ModifyListener {
044:
045: private Text verticalMargin;
046: private Text horizontalMargin;
047: private Text verticalSpacing;
048: private Text horizontalSpacing;
049: private Text indentSize;
050: private ColorEditor fontColour;
051: private ColorEditor backgroundColour;
052:
053: /*
054: * verticalMargin = 3;
055: horizontalMargin = 2;
056: verticalSpacing = 5;
057: horizontalSpacing = 3;
058: indentSize = 10;
059: imageHeight = 16;
060: imageWidth = 16;
061: maxWidth = -1;
062: maxHeight = -1;
063:
064: foregroundColour = Color.BLACK;
065: backgroundColour = Color.WHITE;
066:
067: location = new Point(30, 10);
068: */
069:
070: public void createControl(Composite parent) {
071: IBlackboard blackboard = getStyleBlackboard();
072: LegendStyle style = null;
073: if (blackboard != null) {
074: style = (LegendStyle) blackboard.get(LegendStyleContent.ID);
075: }
076:
077: if (style == null) {
078: style = LegendStyleContent.createDefault();
079: if (blackboard != null) {
080: blackboard.put(LegendStyleContent.ID, style);
081: ((StyleBlackboard) blackboard)
082: .setSelected(new String[] { LegendStyleContent.ID });
083: }
084: }
085:
086: ScrolledComposite scrollComposite = new ScrolledComposite(
087: parent, SWT.H_SCROLL | SWT.V_SCROLL);
088: Composite composite = new Composite(scrollComposite, SWT.BORDER);
089:
090: GridLayout layout = new GridLayout(2, true);
091: composite.setLayout(layout);
092:
093: GridData layoutData = null;
094:
095: Label verticalMarginLabel = new Label(composite, SWT.NONE);
096: verticalMarginLabel
097: .setText(Messages.LegendGraphicStyleConfigurator_vertical_margin);
098: verticalMarginLabel.setLayoutData(layoutData);
099: verticalMargin = new Text(composite, SWT.BORDER);
100: verticalMargin.setLayoutData(layoutData);
101:
102: Label horizontalMarginLabel = new Label(composite, SWT.NONE);
103: horizontalMarginLabel.setLayoutData(layoutData);
104: horizontalMarginLabel
105: .setText(Messages.LegendGraphicStyleConfigurator_horizontal_margin);
106: horizontalMargin = new Text(composite, SWT.BORDER);
107: horizontalMargin.setLayoutData(layoutData);
108:
109: Label verticalSpacingLabel = new Label(composite, SWT.NONE);
110: verticalSpacingLabel.setLayoutData(layoutData);
111: verticalSpacingLabel
112: .setText(Messages.LegendGraphicStyleConfigurator_vertical_spacing);
113: verticalSpacing = new Text(composite, SWT.BORDER);
114: verticalSpacing.setLayoutData(layoutData);
115:
116: Label horizontalSpacingLabel = new Label(composite, SWT.NONE);
117: horizontalSpacingLabel.setLayoutData(layoutData);
118: horizontalSpacingLabel
119: .setText(Messages.LegendGraphicStyleConfigurator_horizontal_spacing);
120: horizontalSpacing = new Text(composite, SWT.BORDER);
121: horizontalSpacing.setLayoutData(layoutData);
122:
123: Label indentSizeLabel = new Label(composite, SWT.NONE);
124: indentSizeLabel.setLayoutData(layoutData);
125: indentSizeLabel
126: .setText(Messages.LegendGraphicStyleConfigurator_indent_size);
127: indentSize = new Text(composite, SWT.BORDER);
128: indentSize.setLayoutData(layoutData);
129:
130: Label fontColourLabel = new Label(composite, SWT.NONE);
131: fontColourLabel.setLayoutData(layoutData);
132: fontColourLabel
133: .setText(Messages.LegendGraphicStyleConfigurator_font_colour);
134: fontColour = new ColorEditor(composite);
135:
136: Label backgroundColourLabel = new Label(composite, SWT.NONE);
137: backgroundColourLabel.setLayoutData(layoutData);
138: backgroundColourLabel
139: .setText(Messages.LegendGraphicStyleConfigurator_background_colour);
140: backgroundColour = new ColorEditor(composite);
141:
142: composite.layout();
143: Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
144: composite.setSize(size);
145: scrollComposite.setContent(composite);
146:
147: verticalMargin.setText(Integer.toString(style.verticalMargin));
148: horizontalMargin.setText(Integer
149: .toString(style.horizontalMargin));
150: verticalSpacing
151: .setText(Integer.toString(style.verticalSpacing));
152: horizontalSpacing.setText(Integer
153: .toString(style.horizontalSpacing));
154: indentSize.setText(Integer.toString(style.indentSize));
155: fontColour.setColorValue(new RGB(style.foregroundColour
156: .getRed(), style.foregroundColour.getGreen(),
157: style.foregroundColour.getBlue()));
158: backgroundColour.setColorValue(new RGB(style.backgroundColour
159: .getRed(), style.backgroundColour.getGreen(),
160: style.backgroundColour.getBlue()));
161:
162: verticalMargin.addModifyListener(this );
163: horizontalMargin.addModifyListener(this );
164: verticalSpacing.addModifyListener(this );
165: horizontalSpacing.addModifyListener(this );
166: indentSize.addModifyListener(this );
167: backgroundColour.addSelectionListener(this );
168: fontColour.addSelectionListener(this );
169: }
170:
171: @Override
172: public boolean canStyle(Layer aLayer) {
173: return aLayer.hasResource(LegendGraphic.class);
174: }
175:
176: @Override
177: protected void refresh() {
178: System.out.println("refresh"); //$NON-NLS-1$ //TODO erase this line
179: IBlackboard blackboard = getStyleBlackboard();
180: LegendStyle style = (LegendStyle) blackboard
181: .get(LegendStyleContent.ID);
182:
183: if (style == null) {
184: style = LegendStyleContent.createDefault();
185: blackboard.put(LegendStyleContent.ID, style);
186: ((StyleBlackboard) blackboard)
187: .setSelected(new String[] { LegendStyleContent.ID });
188: }
189: }
190:
191: private void updateBlackboard() {
192: IBlackboard blackboard = getStyleBlackboard();
193: LegendStyle style = (LegendStyle) blackboard
194: .get(LegendStyleContent.ID);
195:
196: if (style == null) {
197: style = LegendStyleContent.createDefault();
198: blackboard.put(LegendStyleContent.ID, style);
199: ((StyleBlackboard) blackboard)
200: .setSelected(new String[] { LegendStyleContent.ID });
201: }
202:
203: RGB bg = backgroundColour.getColorValue();
204: style.backgroundColour = new Color(bg.red, bg.green, bg.blue);
205:
206: RGB fg = fontColour.getColorValue();
207: style.foregroundColour = new Color(fg.red, fg.green, fg.blue);
208:
209: style.horizontalMargin = Integer.parseInt(horizontalMargin
210: .getText());
211: style.horizontalSpacing = Integer.parseInt(horizontalSpacing
212: .getText());
213: style.indentSize = Integer.parseInt(indentSize.getText());
214: style.verticalMargin = Integer.parseInt(verticalMargin
215: .getText());
216: style.verticalSpacing = Integer.parseInt(verticalSpacing
217: .getText());
218: }
219:
220: public void widgetSelected(SelectionEvent e) {
221: updateBlackboard();
222: }
223:
224: public void widgetDefaultSelected(SelectionEvent e) {
225: updateBlackboard();
226: }
227:
228: public void modifyText(ModifyEvent e) {
229: updateBlackboard();
230: }
231: }
|