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.policies;
18:
19: import net.refractions.udig.printing.model.Box;
20: import net.refractions.udig.printing.model.BoxPrinter;
21: import net.refractions.udig.printing.model.Page;
22: import net.refractions.udig.printing.ui.internal.editor.commands.BoxCreateCommand;
23: import net.refractions.udig.printing.ui.internal.editor.commands.SetConstraintCommand;
24:
25: import org.eclipse.draw2d.geometry.Rectangle;
26: import org.eclipse.gef.EditPart;
27: import org.eclipse.gef.EditPolicy;
28: import org.eclipse.gef.Request;
29: import org.eclipse.gef.commands.Command;
30: import org.eclipse.gef.editpolicies.ResizableEditPolicy;
31: import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
32: import org.eclipse.gef.requests.CreateRequest;
33:
34: /**
35: * This is a policy for the Page. It allows new boxes to be created.
36: *
37: * @author Richard Gould
38: * @since 0.3
39: */
40: public class CustomXYLayoutEditPolicy extends XYLayoutEditPolicy {
41:
42: protected Command createAddCommand(EditPart child, Object constraint) {
43: return null;
44: }
45:
46: protected Command createChangeConstraintCommand(EditPart child,
47: Object constraint) {
48: if (!(constraint instanceof Rectangle)) {
49: return null;
50: }
51:
52: if (getHostFigure().getBounds()
53: .contains((Rectangle) constraint)) {
54:
55: SetConstraintCommand locationCommand = new SetConstraintCommand();
56: locationCommand.setNode((Box) child.getModel());
57: locationCommand.setLocation(((Rectangle) constraint)
58: .getLocation());
59: locationCommand.setSize(((Rectangle) constraint).getSize());
60: return locationCommand;
61: }
62: return null;
63: }
64:
65: protected Command getCreateCommand(CreateRequest request) {
66: Object child = request.getNewObjectType();
67: if (!(child instanceof Class)) {
68: return null;
69: }
70: Class childClass = (Class) child;
71: if (BoxPrinter.class.isAssignableFrom(childClass)) {
72: // return a command that can add a Shape to a ShapesDiagram
73: return new BoxCreateCommand((Box) request.getNewObject(),
74: (Page) getHost().getModel(),
75: (Rectangle) getConstraintFor(request));
76: }
77: return null;
78: }
79:
80: protected Command getDeleteDependantCommand(Request request) {
81: return null;
82: }
83:
84: /**
85: * TODO summary sentence for createChildEditPolicy ...
86: *
87: * @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createChildEditPolicy(org.eclipse.gef.EditPart)
88: * @param child
89: * @return
90: */
91: protected EditPolicy createChildEditPolicy(EditPart child) {
92: ResizableEditPolicy policy = new ResizableEditPolicy();
93: policy.setResizeDirections(-1);
94: return policy;
95: }
96: }
|