KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > viewer > preview > PreviewPanel


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 package org.nightlabs.editor2d.viewer.preview;
27
28 import java.awt.Color JavaDoc;
29 import java.awt.Rectangle JavaDoc;
30 import java.beans.PropertyChangeEvent JavaDoc;
31 import java.beans.PropertyChangeListener JavaDoc;
32
33 import org.nightlabs.editor2d.DrawComponent;
34 import org.nightlabs.editor2d.RectangleDrawComponent;
35 import org.nightlabs.editor2d.impl.RectangleDrawComponentImpl;
36 import org.nightlabs.editor2d.j2d.GeneralShape;
37 import org.nightlabs.editor2d.viewer.IBufferedViewport;
38 import org.nightlabs.editor2d.viewer.awt.DisplayPanel;
39
40 /**
41  * Shows a preview of an viewport so that the whole content
42  * is visible and the viewBounds of the viewport are displayed
43  *
44  * <p> Project: org.nightlabs.editor2d.viewer </p>
45  * <p> Creation Date: 04.01.2006 </p>
46  * <p> Author: Daniel.Mazurek[AT]NightLabs[DOT]de </p>
47  */

48 public class PreviewPanel
49 extends DisplayPanel
50 {
51
52     /**
53      * @param dc The DrawComponent
54      */

55     public PreviewPanel(DrawComponent dc, IBufferedViewport viewport)
56     {
57         super(dc);
58         this.viewport = viewport;
59         init();
60     }
61     
62     protected IBufferedViewport viewport = null;
63     
64     protected RectangleDrawComponent viewSelector = null;
65     protected RectangleDrawComponent getViewSelector()
66     {
67         if (viewSelector == null) {
68             viewSelector = new RectangleDrawComponentImpl();
69             Rectangle JavaDoc r = viewport.getViewBounds();
70             viewSelector.setGeneralShape(new GeneralShape(r));
71             viewSelector.setFill(false);
72             viewSelector.setLineColor(Color.RED);
73             viewSelector.setLineWidth(2);
74         }
75         return viewSelector;
76     }
77     
78     protected void init()
79     {
80         viewport.addPropertyChangeListener(viewChangeListener);
81         viewport.addPropertyChangeListener(realChangeListener);
82     }
83     
84     /**
85      * gets notifyed when the viewBounds of the Viewport change
86      * @see IViewport.getViewBounds()
87      */

88     protected PropertyChangeListener JavaDoc viewChangeListener = new PropertyChangeListener JavaDoc()
89     {
90         public void propertyChange(PropertyChangeEvent JavaDoc evt)
91         {
92             if (evt.getPropertyName().equals(DisplayPanel.VIEW_CHANGE)) {
93                 Rectangle JavaDoc newViewBounds = (Rectangle JavaDoc) evt.getNewValue();
94                 setViewSelectorBounds(newViewBounds);
95             }
96         }
97     };
98
99     /**
100      * gets notifyed when the realBounds of the Viewport change
101      * @see IViewport.getRealBounds()
102      */

103     protected PropertyChangeListener JavaDoc realChangeListener = new PropertyChangeListener JavaDoc()
104     {
105         public void propertyChange(PropertyChangeEvent JavaDoc evt)
106         {
107             if (evt.getPropertyName().equals(DisplayPanel.REAL_CHANGE)) {
108                 Rectangle JavaDoc newViewBounds = (Rectangle JavaDoc) evt.getNewValue();
109                 setViewSelectorBounds(newViewBounds);
110             }
111         }
112     };
113                 
114     protected void setViewSelectorBounds(Rectangle JavaDoc newViewBounds)
115     {
116         
117     }
118     
119 }
120
Popular Tags