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.mapgraphic.scalebar;
018:
019: import java.awt.Color;
020: import java.awt.Rectangle;
021: import java.io.IOException;
022: import java.net.URL;
023:
024: import net.refractions.udig.catalog.IGeoResource;
025: import net.refractions.udig.mapgraphic.MapGraphic;
026: import net.refractions.udig.project.StyleContent;
027:
028: import org.eclipse.core.runtime.IProgressMonitor;
029: import org.eclipse.ui.IMemento;
030:
031: /**
032: * Rectangle indicating Location in device coordinates, w & h in 1/72 of an inch.
033: * <p>
034: * <b>Screen Coordinates</b> are used. This naturally changes to Page
035: * Coordinates when printed.
036: * </p>
037: * <p>
038: * The x,y position are considered in a realtive fashion.
039: * <ul>
040: * <li>x positive: measured from the left edge of the screen or paper
041: * <li>y positive: measured from the top edge of the screen or paper
042: * <li>x negative: measured from the bottom edge of the screen or paper
043: * <li>z negative: measured from the right edge of the screen or paper
044: * </ul>
045: * This allows a map graphic to be specified relative to any edge.
046: * </p>
047: * <p>
048: * The width and height of the Rectangle indicate the requested size in terms
049: * of Java's usual one pixel indicates 1/72 of an inch. Appropriate scaling
050: * will be needed when page output is requested.
051: * </p>
052: * @author Richard Gould
053: * @since 0.6.0
054: */
055: public class LocationStyleContent extends StyleContent {
056: /** extension id */
057: public static final String ID = "net.refractions.udig.printing.ui.locationStyle"; //$NON-NLS-1$
058:
059: /** padding constants */
060: public static final int YPAD_BOTTOM = 5;
061: public static final int YPAD_TOP = 15;
062: public static final int XPAD_LEFT = 5;
063: public static final int XPAD_RIGHT = 50;
064:
065: /**
066: * Location style holding a rectangle.
067: */
068: public LocationStyleContent() {
069: super (ID);
070: }
071:
072: public Class getStyleClass() {
073: return Rectangle.class;
074: }
075:
076: public Object load(IMemento memento) {
077: int x = memento.getInteger("x"); //$NON-NLS-1$
078: int y = memento.getInteger("y"); //$NON-NLS-1$
079: int width = memento.getInteger("w"); //$NON-NLS-1$
080: int height = memento.getInteger("h"); //$NON-NLS-1$
081:
082: return new Rectangle(x, y, width, height);
083: }
084:
085: public void save(IMemento memento, Object style) {
086: Rectangle rectangle = (Rectangle) style;
087: memento.putInteger("x", rectangle.x); //$NON-NLS-1$
088: memento.putInteger("y", rectangle.y); //$NON-NLS-1$
089: memento.putInteger("w", rectangle.width); //$NON-NLS-1$
090: memento.putInteger("h", rectangle.height); //$NON-NLS-1$
091: }
092:
093: /* (non-Javadoc)
094: * @see net.refractions.udig.project.StyleContent#createDefaultStyle(net.refractions.udig.catalog.IGeoResource)
095: */
096: public Object createDefaultStyle(IGeoResource resource,
097: Color colour, IProgressMonitor monitor) throws IOException {
098: if (!resource.canResolve(MapGraphic.class))
099: return null;
100:
101: return createDefaultStyle();
102: }
103:
104: /*
105: * @see net.refractions.udig.project.StyleContent#load(java.net.URL)
106: */
107: public Object load(URL url, IProgressMonitor monitor)
108: throws IOException {
109: return null;
110: }
111:
112: /**
113: * TODO summary sentence for createDefaultStyle ...
114: *
115: * @return
116: */
117: public static Rectangle createDefaultStyle() {
118: return new Rectangle(XPAD_LEFT, YPAD_TOP, 100, 10);
119: }
120:
121: }
|