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