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.printing.model.impl;
16:
17: import java.awt.Color;
18: import java.awt.Graphics2D;
19:
20: import net.refractions.udig.printing.model.AbstractBoxPrinter;
21:
22: import org.eclipse.core.runtime.IProgressMonitor;
23: import org.eclipse.draw2d.geometry.Dimension;
24: import org.eclipse.ui.IMemento;
25:
26: /**
27: * Box printer for map labels.
28: *
29: * @author Jesse
30: * @since 1.1.0
31: */
32: public class LabelBoxPrinter extends AbstractBoxPrinter {
33:
34: private String text = "Set Text"; //$NON-NLS-1$
35:
36: public String getText() {
37: return text;
38: }
39:
40: public void setText(String text) {
41: this .text = text;
42: }
43:
44: public void draw(Graphics2D graphics, IProgressMonitor monitor) {
45: graphics.setColor(Color.BLACK);
46: graphics.drawString(getText(), 10, 10 + graphics.getFont()
47: .getSize());
48: }
49:
50: public void createPreview(Graphics2D graphics,
51: IProgressMonitor monitor) {
52: draw(graphics, monitor);
53: preview = getText();
54: previewSize = getBox().getSize();
55: }
56:
57: String preview;
58: private Dimension previewSize;
59:
60: public boolean isNewPreviewNeeded() {
61: return (preview != null && !preview.equals(getText()))
62: || (previewSize != null && !getBox().getSize().equals(
63: previewSize));
64: }
65:
66: public void save(IMemento memento) {
67: memento.putString("label", text); //$NON-NLS-1$
68: }
69:
70: public void load(IMemento value) {
71: text = value.getString("label"); //$NON-NLS-1$
72: }
73:
74: public String getExtensionPointID() {
75: return "net.refractions.udig.printing.ui.standardBoxes"; //$NON-NLS-1$
76: }
77:
78: }
|