01: /*
02: * uDig - User Friendly Desktop Internet GIS client
03: * http://udig.refractions.net
04: * (C) 2004, Refractions Research Inc.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package net.refractions.udig.printing.ui.internal.editor.parts;
18:
19: import java.util.List;
20:
21: import net.refractions.udig.printing.model.Page;
22: import net.refractions.udig.printing.model.PropertyListener;
23: import net.refractions.udig.printing.ui.internal.editor.figures.PageFigure;
24: import net.refractions.udig.printing.ui.internal.editor.policies.CustomXYLayoutEditPolicy;
25:
26: import org.eclipse.draw2d.Figure;
27: import org.eclipse.draw2d.FreeformLayout;
28: import org.eclipse.draw2d.IFigure;
29: import org.eclipse.draw2d.geometry.Dimension;
30: import org.eclipse.draw2d.geometry.Point;
31: import org.eclipse.draw2d.geometry.Rectangle;
32: import org.eclipse.gef.EditPolicy;
33: import org.eclipse.gef.GraphicalEditPart;
34: import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
35:
36: /**
37: * Controller (Part) for Printing Pages.
38: *
39: * @author Richard Gould
40: * @since 0.3
41: */
42: public class PagePart extends AbstractGraphicalEditPart {
43:
44: private InternalPropertyListener listener = new InternalPropertyListener();
45:
46: protected List getModelChildren() {
47: return ((Page) this .getModel()).getBoxes();
48: }
49:
50: protected IFigure createFigure() {
51: Figure figure = new PageFigure();
52: figure.setLayoutManager((new FreeformLayout()));
53: return figure;
54: }
55:
56: protected void createEditPolicies() {
57: installEditPolicy(EditPolicy.LAYOUT_ROLE,
58: new CustomXYLayoutEditPolicy());
59: }
60:
61: public void activate() {
62: if (isActive()) {
63: return;
64: }
65:
66: super .activate();
67: ((Page) getModel()).eAdapters().add(this .listener);
68: }
69:
70: public void deactivate() {
71: if (!isActive()) {
72: return;
73: }
74: super .deactivate();
75: ((Page) getModel()).eAdapters().remove(this .listener);
76: }
77:
78: protected void refreshVisuals() {
79: Page page = (Page) getModel();
80:
81: Point loc = new Point(0, 0);
82: Dimension size = page.getSize();
83: Rectangle rectangle = new Rectangle(loc, size);
84:
85: ((GraphicalEditPart) getParent()).setLayoutConstraint(this ,
86: getFigure(), rectangle);
87: }
88:
89: protected class InternalPropertyListener extends PropertyListener {
90:
91: protected void boxesChanged() {
92: refreshChildren();
93: }
94:
95: protected void sizeChanged() {
96: refreshVisuals();
97: }
98: }
99: }
|