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.printing.ui;
018:
019: import java.awt.Rectangle;
020:
021: import net.refractions.udig.mapgraphic.MapGraphic;
022: import net.refractions.udig.printing.ui.internal.Messages;
023: import net.refractions.udig.project.internal.Layer;
024: import net.refractions.udig.project.internal.StyleBlackboard;
025: import net.refractions.udig.style.IStyleConfigurator;
026:
027: import org.eclipse.swt.SWT;
028: import org.eclipse.swt.layout.GridData;
029: import org.eclipse.swt.layout.GridLayout;
030: import org.eclipse.swt.widgets.Composite;
031: import org.eclipse.swt.widgets.Label;
032: import org.eclipse.swt.widgets.Text;
033:
034: /**
035: * Configures a "location style", which indicates that a particular layer can
036: * be relocated, such as a scalebar or a legend.
037: *
038: * @author Richard Gould
039: * @since 0.6.0
040: */
041: public class LocationStyleConfigurator extends IStyleConfigurator {
042:
043: private Text xText;
044: private Text yText;
045: private Text widthText;
046: private Text heightText;
047:
048: /**
049: * @see net.refractions.udig.style.StyleConfigurator#createControl(org.eclipse.swt.widgets.Composite)
050: */
051: public void createControl(Composite parent) {
052: GridData gridData;
053:
054: GridLayout gridLayout = new GridLayout();
055: int columns = 1;
056: gridLayout.numColumns = columns;
057: parent.setLayout(gridLayout);
058:
059: gridData = new GridData();
060: Label xLabel = new Label(parent, SWT.NONE);
061: xLabel.setText(Messages.LocationStyleConfigurator_x);
062: xLabel.setLayoutData(gridData);
063:
064: gridData = new GridData(GridData.FILL_HORIZONTAL);
065: xText = new Text(parent, SWT.BORDER);
066: xText.setLayoutData(gridData);
067:
068: gridData = new GridData();
069: Label yLabel = new Label(parent, SWT.NONE);
070: yLabel.setText(Messages.LocationStyleConfigurator_y);
071: yLabel.setLayoutData(gridData);
072:
073: gridData = new GridData(GridData.FILL_HORIZONTAL);
074: yText = new Text(parent, SWT.BORDER);
075: yText.setLayoutData(gridData);
076:
077: gridData = new GridData();
078: Label widthLabel = new Label(parent, SWT.NONE);
079: widthLabel.setText(Messages.LocationStyleConfigurator_width);
080: widthLabel.setLayoutData(gridData);
081:
082: gridData = new GridData(GridData.FILL_HORIZONTAL);
083: widthText = new Text(parent, SWT.BORDER);
084: widthText.setLayoutData(gridData);
085:
086: gridData = new GridData();
087: Label heightLabel = new Label(parent, SWT.NONE);
088: heightLabel.setText(Messages.LocationStyleConfigurator_height);
089: heightLabel.setLayoutData(gridData);
090:
091: gridData = new GridData(GridData.FILL_HORIZONTAL);
092: heightText = new Text(parent, SWT.BORDER);
093: heightText.setLayoutData(gridData);
094:
095: }
096:
097: /* (non-Javadoc)
098: * @see net.refractions.udig.style.IStyleConfigurator#init()
099: */
100: public void init() {
101: // do nothing
102:
103: }
104:
105: /*
106: * @see net.refractions.udig.style.IStyleConfigurator#init()
107: */
108: public void refresh() {
109: //do nothing
110: }
111:
112: public void apply() {
113: int x = Integer.parseInt(xText.getText());
114: int y = Integer.parseInt(yText.getText());
115: int width = Integer.parseInt(widthText.getText());
116: int height = Integer.parseInt(heightText.getText());
117:
118: Rectangle location = new Rectangle(x, y, width, height);
119: StyleBlackboard styleBlackboard = getLayer()
120: .getStyleBlackboard();
121: styleBlackboard.put(LocationStyleContent.ID, location);
122: styleBlackboard
123: .setSelected(new String[] { LocationStyleContent.ID });
124:
125: }
126:
127: /*
128: * @see net.refractions.udig.style.IStyleConfigurator#canStyle(net.refractions.udig.project.Layer)
129: */
130: public boolean canStyle(Layer layer) {
131: return layer.hasResource(MapGraphic.class);
132: /*
133: if (layer.getStyleBlackboard().get(LocationStyleContent.ID) != null) {
134: return true;
135: }
136:
137: if (Styles.getStyleIDs(layer).contains(LocationStyleContent.ID)) {
138: return true;
139: }
140:
141: return false;
142: */
143: }
144:
145: }
|