KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > viewer > awt > AWTCanvasComposite


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.awt;
28
29 import java.awt.BorderLayout JavaDoc;
30 import java.awt.Component JavaDoc;
31 import java.awt.Frame JavaDoc;
32
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.awt.SWT_AWT;
35 import org.eclipse.swt.widgets.Composite;
36
37 import org.nightlabs.editor2d.DrawComponent;
38 import org.nightlabs.editor2d.viewer.AbstractCanvasComposite;
39 import org.nightlabs.editor2d.viewer.IAutoScrollSupport;
40 import org.nightlabs.editor2d.viewer.IBufferedCanvas;
41 import org.nightlabs.editor2d.viewer.ICanvas;
42 import org.nightlabs.editor2d.viewer.IMouseManager;
43 import org.nightlabs.editor2d.viewer.IViewer;
44 import org.nightlabs.editor2d.viewer.IViewport;
45
46 public class AWTCanvasComposite
47 extends AbstractCanvasComposite
48 implements IComponentViewer
49 {
50 // public static int styleFlag = SWT.EMBEDDED | SWT.DOUBLE_BUFFERED;
51
public static int styleFlag = SWT.EMBEDDED;
52     public AWTCanvasComposite(Composite parent, int style, DrawComponent dc)
53     {
54         super(parent, style | styleFlag, dc);
55     }
56
57     public AWTCanvasComposite(Composite parent, int style, DrawComponent dc, boolean autoScroll)
58     {
59         super(parent, style | styleFlag, dc, autoScroll);
60 // addDisposeListener(disposeListener);
61
}
62
63     public Component JavaDoc getComponent() {
64         return (Component JavaDoc) getCanvas();
65     }
66             
67     protected IAutoScrollSupport initAutoScrollSupport()
68     {
69         IAutoScrollSupport autoScrollSupport = new AWTCanvasAutoScrollSupport(getComponent());
70         autoScrollSupport.setScrollStep(10);
71         autoScrollSupport.setTimerDelay(5);
72         return autoScrollSupport;
73     }
74     
75     protected ICanvas createCanvas(Composite parent)
76     {
77         Frame JavaDoc frame = SWT_AWT.new_Frame(parent);
78         frame.setLayout(new BorderLayout JavaDoc());
79         DisplayPanel displayPanel = new DisplayPanel(drawComponent);
80         frame.add(displayPanel, BorderLayout.CENTER);
81         return displayPanel;
82     }
83   
84     public IMouseManager initMouseManager(IViewer viewer) {
85         return new AWTMouseManager(viewer, getComponent());
86     }
87     
88 // protected int timerDelay = 10;
89
// protected Timer repaintTimer;
90
//
91
// protected ActionListener repaintListener = new ActionListener()
92
// {
93
// public void actionPerformed(ActionEvent arg0)
94
// {
95
// scrollPanel.repaintScrollBars();
96
// System.out.println("Timer called!");
97
// }
98
// };
99
//
100
// protected DisposeListener disposeListener = new DisposeListener()
101
// {
102
// public void widgetDisposed(DisposeEvent e)
103
// {
104
// repaintTimer.stop();
105
// repaintTimer = null;
106
// }
107
// };
108
//
109
// protected ScrollPanel scrollPanel;
110
// protected ICanvas createCanvas(Composite parent)
111
// {
112
// Frame frame = SWT_AWT.new_Frame(parent);
113
// frame.setLayout(new BorderLayout());
114
// scrollPanel = new ScrollPanel(drawComponent);
115
// frame.add(scrollPanel, BorderLayout.CENTER);
116
// repaintTimer = new Timer(timerDelay, repaintListener);
117
// repaintTimer.restart();
118
// return scrollPanel.getDisplayPanel();
119
// }
120

121     public IBufferedCanvas getBufferedCanvas() {
122         return (IBufferedCanvas) getCanvas();
123     }
124     
125     public IViewport getViewport() {
126         return (IViewport) getCanvas();
127     }
128     
129     public void updateCanvas()
130     {
131         if (canvas != null)
132             getBufferedCanvas().notifyChange();
133     }
134
135 }
136
Popular Tags