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;
16:
17: import java.awt.Graphics2D;
18:
19: import org.eclipse.core.runtime.IProgressMonitor;
20: import org.eclipse.ui.IMemento;
21:
22: /**
23: * Provides simple/stupid implementation for the optional methods in BoxPrinter.
24: * <p>
25: * Nothing is saved when save is called. So everything must be hard coded. Preview simply calls
26: * draw() and only does so once.
27: * </p>
28: *
29: * @author Jesse
30: * @since 1.1.0
31: */
32: public abstract class AbstractBoxPrinter implements BoxPrinter {
33:
34: private Box box;
35: private boolean dirty = false;
36: private PropertyListener listener = new PropertyListener() {
37: @Override
38: protected void locationChanged() {
39: dirty = true;
40: }
41:
42: @Override
43: protected void sizeChanged() {
44: dirty = true;
45: }
46: };
47:
48: /**
49: * By default this method does nothing
50: */
51: public void save(IMemento memento) {
52: }
53:
54: /**
55: * By default this method does nothing
56: */
57: public void load(IMemento memento) {
58: }
59:
60: /**
61: * By default this method calls draw and sets dirty to be false.
62: */
63: public void createPreview(Graphics2D graphics,
64: IProgressMonitor monitor) {
65: draw(graphics, monitor);
66: dirty = false;
67: }
68:
69: /**
70: * By default this will return false when ever the size of location of the box has been changed.
71: */
72: public boolean isNewPreviewNeeded() {
73: return dirty;
74: }
75:
76: public Box getBox() {
77: return box;
78: }
79:
80: @SuppressWarnings("unchecked")
81: public void setBox(Box box2) {
82: if (box != null)
83: box.eAdapters().remove(listener);
84: this.box = box2;
85: if (box != null)
86: box.eAdapters().add(listener);
87: }
88:
89: }
|