KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > viewer > AbstractTestDialog


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * *
5  * This library is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or (at your option) any later version. *
9  * *
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  * You should have received a copy of the GNU Lesser General Public *
16  * License along with this library; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin St, Fifth Floor, *
19  * Boston, MA 02110-1301 USA *
20  * *
21  * Or get it online : *
22  * http://www.gnu.org/copyleft/lesser.html *
23  * *
24  * *
25  ******************************************************************************/

26
27 package org.nightlabs.editor2d.viewer;
28
29 import java.awt.Point JavaDoc;
30
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.events.SelectionEvent;
33 import org.eclipse.swt.events.SelectionListener;
34 import org.eclipse.swt.layout.GridData;
35 import org.eclipse.swt.layout.GridLayout;
36 import org.eclipse.swt.widgets.Button;
37 import org.eclipse.swt.widgets.Composite;
38 import org.eclipse.swt.widgets.Control;
39 import org.eclipse.swt.widgets.Label;
40 import org.eclipse.swt.widgets.Shell;
41 import org.eclipse.swt.widgets.Text;
42 import org.nightlabs.base.dialog.FullScreenDialog;
43 import org.nightlabs.editor2d.DrawComponent;
44 import org.nightlabs.editor2d.render.RenderModeManager;
45 import org.nightlabs.editor2d.viewer.event.IMouseChangedListener;
46
47 public abstract class AbstractTestDialog
48 extends FullScreenDialog
49 {
50     public AbstractTestDialog(Shell shell, DrawComponent dc)
51     {
52         super(shell);
53         setShellStyle(getShellStyle() | SWT.RESIZE);
54         this.dc = dc;
55         dc.setRenderModeManager(new RenderModeManager());
56     }
57     
58     protected DrawComponent dc;
59     protected AbstractCanvasComposite viewer;
60     protected Composite comp;
61     protected Text zoomText;
62     
63     protected Control createDialogArea(Composite parent)
64     {
65         GridLayout layout = new GridLayout(1, false);
66         parent.setLayout(layout);
67         
68         Composite buttonComp = new Composite(parent, SWT.BORDER);
69         GridLayout buttonCompLayout = new GridLayout(4, true);
70         buttonComp.setLayout(buttonCompLayout);
71         
72         GridData buttonCompData = new GridData(GridData.FILL_HORIZONTAL);
73         buttonComp.setLayoutData(buttonCompData);
74         
75         // refreshButton
76
Button refreshButton = new Button(buttonComp, SWT.NONE);
77         refreshButton.setText("Refresh");
78         refreshButton.addSelectionListener(refreshListener);
79         
80         // ZoomInButton
81
Button zoomInButton = new Button(buttonComp, SWT.NONE);
82         zoomInButton.setText("ZoomIn");
83         zoomInButton.addSelectionListener(zoomInListener);
84
85         // ZoomOutButton
86
Button zoomOutButton = new Button(buttonComp, SWT.NONE);
87         zoomOutButton.setText("ZoomOut");
88         zoomOutButton.addSelectionListener(zoomOutListener);
89                         
90         viewer = getViewer(parent);
91         GridData viewerData = new GridData(GridData.FILL_BOTH);
92         viewer.setLayoutData(viewerData);
93 // viewer.getCanvas().addMouseMoveListener(mouseListener);
94
viewer.getMouseManager().addMouseChangedListener(mouseListener);
95         
96         Composite bottomComp = new Composite(parent, SWT.BORDER);
97         GridLayout bottomLayout = new GridLayout(3, true);
98         bottomComp.setLayout(bottomLayout);
99         GridData bottmCompData = new GridData(GridData.FILL_HORIZONTAL);
100         bottomComp.setLayoutData(bottmCompData);
101         
102         mouseLabelX = new Label(bottomComp, SWT.NONE);
103         mouseLabelX.setText("X = "+10000);
104         mouseLabelY = new Label(bottomComp, SWT.NONE);
105         mouseLabelY.setText("Y = "+10000);
106         
107         // ZoomText
108
zoomText = new Text(buttonComp, SWT.BORDER);
109         zoomText.setText(""+(viewer.getZoom()*100)+"%");
110         viewer.getZoomSupport().addZoomListener(zoomListener);
111         
112         return parent;
113     }
114     
115     protected abstract AbstractCanvasComposite getViewer(Composite parent);
116     
117     protected Label mouseLabelX;
118     protected Label mouseLabelY;
119         
120     protected IMouseChangedListener mouseListener = new IMouseChangedListener()
121     {
122         public void mouseChanged(Point JavaDoc relative, Point JavaDoc absolute)
123         {
124             mouseLabelX.setText("X = "+relative.x);
125             mouseLabelY.setText("Y = "+relative.y);
126         }
127     };
128     
129     protected int x;
130     protected int y;
131     
132 // protected MouseMoveListener mouseListener = new MouseMoveListener()
133
// {
134
// public void mouseMove(MouseEvent e)
135
// {
136
//// double zoom = viewer.getZoomSupport().getZoom();
137
//// x = (int) (e.x / zoom);
138
//// y = (int) (e.y / zoom);
139
// x = viewer.getMouseManager().getAbsoluteX();
140
// y = viewer.getMouseManager().getAbsoluteY();
141
//
142
// mouseLabelX.setText("X = "+x);
143
// mouseLabelY.setText("Y = "+y);
144
// }
145
// };
146

147     protected SelectionListener refreshListener = new SelectionListener()
148     {
149         public void widgetDefaultSelected(SelectionEvent arg0) {
150             widgetSelected(arg0);
151         }
152         public void widgetSelected(SelectionEvent arg0) {
153             update();
154         }
155     };
156     
157     protected SelectionListener zoomInListener = new SelectionListener()
158     {
159         public void widgetDefaultSelected(SelectionEvent arg0) {
160             widgetSelected(arg0);
161         }
162         public void widgetSelected(SelectionEvent arg0) {
163             viewer.getZoomSupport().zoomIn();
164             update();
165         }
166     };
167
168     protected SelectionListener zoomOutListener = new SelectionListener()
169     {
170         public void widgetDefaultSelected(SelectionEvent arg0) {
171             widgetSelected(arg0);
172         }
173         public void widgetSelected(SelectionEvent arg0)
174         {
175             viewer.getZoomSupport().zoomOut();
176             update();
177         }
178     };
179         
180     protected IZoomListener zoomListener = new IZoomListener()
181     {
182         public void zoomChanged(double zoom) {
183             zoomText.setText(""+(zoom*100)+"%");
184         }
185     };
186     
187     protected void update()
188     {
189         viewer.updateCanvas();
190     }
191       
192 }
193
Popular Tags