001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.ui.products.ad.drawengines;
043:
044: import java.awt.Color;
045: import java.awt.Font;
046: import java.awt.Rectangle;
047:
048: import org.netbeans.modules.uml.common.ETSystem;
049: import org.netbeans.modules.uml.core.support.umlsupport.IETRect;
050: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo;
051: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject;
052: import org.netbeans.modules.uml.ui.swing.drawingarea.diagramtools.ADDrawingAreaSelectState;
053: import com.tomsawyer.editor.TSEGraphWindow;
054: import com.tomsawyer.editor.graphics.TSEGraphics; //import com.tomsawyer.editor.state.TSEMoveSelectedState;
055: import com.tomsawyer.editor.tool.TSEMoveSelectedTool; //import com.tomsawyer.editor.state.TSESelectState;
056: import com.tomsawyer.editor.tool.TSESelectTool; //import com.tomsawyer.util.TSTransform;
057: import com.tomsawyer.editor.TSTransform;
058:
059: public class ETDrawInfo implements IDrawInfo {
060: private TSEGraphics graphics;
061: private boolean m_AlwaysSetFont = false;
062: private boolean m_IsTransparent = false;
063: private IETRect m_BoundingRect = null;
064: private IETRect m_DeviceRect = null;
065: private IETGraphObject m_graphObject = null;
066: private Color m_TextColor = Color.BLACK;
067: private boolean m_IsBorder = true;
068: private int m_MainDrawingArea = -1;
069: private double m_fontScaleFactor = -1.0;
070:
071: public ETDrawInfo() {
072: this .graphics = null;
073: }
074:
075: public ETDrawInfo(TSEGraphics graphics) {
076: this .graphics = graphics;
077: }
078:
079: public TSEGraphics getTSEGraphics() {
080: return this .graphics;
081: }
082:
083: public void setTSEGraphics(TSEGraphics newVal) {
084: this .graphics = newVal;
085: // Reset the font scale factor, the graphics have changed.
086: m_fontScaleFactor = -1.0;
087: }
088:
089: /* (non-Javadoc)
090: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getAlwaysSetFont()
091: */
092: public boolean getAlwaysSetFont() {
093: return m_AlwaysSetFont;
094: }
095:
096: /**
097: * The current text background color.
098: *
099: * @return the current background color
100: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getBackColor()
101: */
102: public Color getBackColor() {
103: return getTSEGraphics() != null ? getTSEGraphics()
104: .getBackground() : Color.white;
105: }
106:
107: /**
108: * The background drawing mode.
109: *
110: * @return 2 if opaque, 1 if transparent. If opaque the current brush is used to paint
111: * the background, otherwise the background is not changed.
112: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getBackgroundMode()
113: */
114: public boolean isTransparent() {
115: return m_IsTransparent;
116: }
117:
118: /* (non-Javadoc)
119: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getBoundingRect()
120: */
121: public IETRect getBoundingRect() {
122: return m_BoundingRect;
123: }
124:
125: /* (non-Javadoc)
126: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getDeviceBounds()
127: */
128: public IETRect getDeviceBounds() {
129: return m_DeviceRect;
130: }
131:
132: /* (non-Javadoc)
133: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getDrawingToMainDrawingArea()
134: */
135: public boolean getDrawingToMainDrawingArea() {
136: if (m_MainDrawingArea < 0 && getGraphObject() != null
137: && this .graphics != null) {
138: try {
139: // calculate it
140: return getGraphObject().getEngine().getDrawingArea()
141: .getGraphWindow() == graphics.getGraphWindow();
142: } catch (Exception e) {
143: e.printStackTrace();
144: return false;
145: }
146: } else
147: return m_MainDrawingArea > 0;
148: }
149:
150: /* (non-Javadoc)
151: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getFont()
152: */
153: public Font getFont() {
154: return getTSEGraphics() != null ? getTSEGraphics().getFont()
155: : null;
156: }
157:
158: /* (non-Javadoc)
159: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getGraphDisplay()
160: */
161: public TSEGraphWindow getGraphDisplay() {
162: return getTSEGraphics() != null ? getTSEGraphics()
163: .getGraphWindow() : null;
164: }
165:
166: /* (non-Javadoc)
167: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getGraphObject()
168: */
169: public IETGraphObject getGraphObject() {
170: return m_graphObject;
171: }
172:
173: /* (non-Javadoc)
174: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getOnDrawZoom()
175: */
176: public double getOnDrawZoom() {
177: return graphics != null ? graphics.getGraphWindow()
178: .getZoomLevel() : 1.0;
179: }
180:
181: /* (non-Javadoc)
182: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getTextColor()
183: */
184: public Color getTextColor() {
185: return m_TextColor;
186: }
187:
188: /**
189: * The viewport origin.
190: *
191: * @return The coordinate of the viewport origin.
192: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getViewportOrg(int, int)
193: */
194: public long getViewportOrg(int cx, int cy) {
195: // TODO Auto-generated method stub
196: return 0;
197: }
198:
199: /* (non-Javadoc)
200: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#printFontToOutputWindow()
201: */
202: public long printFontToOutputWindow() {
203: Font font = this .getFont();
204: if (font != null) {
205: ETSystem.out
206: .println("ETDrawInfo font = " + font.toString());
207: }
208: return 0;
209: }
210:
211: /* (non-Javadoc)
212: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#restoreSettings(int)
213: */
214: public long restoreSettings(int nCookie) {
215: // TODO Auto-generated method stub
216: return 0;
217: }
218:
219: /* (non-Javadoc)
220: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#saveSettings()
221: */
222: public int saveSettings() {
223: // TODO Auto-generated method stub
224: return 0;
225: }
226:
227: /* (non-Javadoc)
228: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setActualTSEDrawInfo(int)
229: */
230: public void setActualTSEDrawInfo(int value) {
231: // TODO Auto-generated method stub
232:
233: }
234:
235: /* (non-Javadoc)
236: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setAlwaysSetFont(boolean)
237: */
238: public void setAlwaysSetFont(boolean value) {
239: m_AlwaysSetFont = value;
240: }
241:
242: /* (non-Javadoc)
243: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setBackColor(long)
244: */
245: public void setBackColor(Color value) {
246: if (getTSEGraphics() != null) {
247: getTSEGraphics().setBackground(value);
248: }
249: }
250:
251: /* (non-Javadoc)
252: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setBackgroundMode(int)
253: */
254: public void isTransparent(boolean value) {
255: m_IsTransparent = value;
256: }
257:
258: /* (non-Javadoc)
259: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setBoundingRect(org.netbeans.modules.uml.core.support.umlsupport.IETRect)
260: */
261: public void setBoundingRect(IETRect value) {
262: m_BoundingRect = value;
263: }
264:
265: /* (non-Javadoc)
266: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setDeviceBounds(org.netbeans.modules.uml.core.support.umlsupport.IETRect)
267: */
268: public void setDeviceBounds(IETRect value) {
269: m_DeviceRect = value;
270: }
271:
272: /* (non-Javadoc)
273: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setDrawingToMainDrawingArea(boolean)
274: */
275: public void setDrawingToMainDrawingArea(boolean value) {
276: m_MainDrawingArea = value ? 1 : 0;
277: }
278:
279: /* (non-Javadoc)
280: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setFont(java.lang.Object)
281: */
282: public void setFont(Font value) {
283: if (getTSEGraphics() != null) {
284: getTSEGraphics().setFont(value);
285: }
286: }
287:
288: /* (non-Javadoc)
289: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setGraphDisplay(com.embarcadero.describe.gui.layout.TSGraphDisplay)
290: */
291: public void setGraphDisplay(TSEGraphWindow value) {
292: // no op
293: }
294:
295: /* (non-Javadoc)
296: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setGraphObject(com.tomsawyer.graph.TSGraphObject)
297: */
298: public void setGraphObject(IETGraphObject object) {
299: m_graphObject = object;
300: }
301:
302: /* (non-Javadoc)
303: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setOnDrawZoom(double)
304: */
305: public void setOnDrawZoom(double value) {
306: // we always get the zoom level from the graphics object.
307: // m_ZoomLevel = value;
308: }
309:
310: /* (non-Javadoc)
311: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setTextColor(long)
312: */
313: public void setTextColor(Color value) {
314: m_TextColor = value;
315: }
316:
317: /* (non-Javadoc)
318: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setViewportOrg(int, int)
319: */
320: public long setViewportOrg(int cx, int cy) {
321: // TODO Auto-generated method stub
322: return 0;
323: }
324:
325: /* (non-Javadoc)
326: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setIsTransparent(boolean)
327: */
328: public void setIsTransparent(boolean value) {
329: m_IsTransparent = value;
330: }
331:
332: /* (non-Javadoc)
333: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#isBorderDrawn()
334: */
335: public boolean isBorderDrawn() {
336: return m_IsBorder;
337: }
338:
339: /* (non-Javadoc)
340: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#setIsBorderDrawn(boolean)
341: */
342: public void setIsBorderDrawn(boolean value) {
343: m_IsBorder = value;
344: }
345:
346: /* (non-Javadoc)
347: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#getTSTransform()
348: */
349: public TSTransform getTSTransform() {
350: return this .graphics != null ? this .graphics.getTSTransform()
351: : null;
352: }
353:
354: /* (non-Javadoc)
355: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#clip()
356: */
357: public Rectangle clip() {
358: if (this .graphics != null) {
359: Rectangle prevClip = this .graphics.getClipRect();
360:
361: // Fix J1570: During selection & dragging of the node inside a container
362: // we don't want to use the clipping rect. We are not sure
363: // why this is necessary, but it cleans up some clipping problems.
364:
365: // This was turned off by kevin. It this causing major bugs, we need to find the true source of
366: // the containment drawing bug.
367:
368: //if( ! (getGraphDisplay().getCurrentState() instanceof TSESelectState) &&
369: // ! (getGraphDisplay().getCurrentState() instanceof TSEMoveSelectedState) )
370: {
371: graphics.setClip(calculateClippingRect());
372: }
373: return prevClip;
374: }
375: return null;
376: }
377:
378: /* (non-Javadoc)
379: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo#calculateClippingRect()
380: */
381: public Rectangle calculateClippingRect() {
382: IETRect deviceBounds = getDeviceBounds();
383: if (deviceBounds != null) {
384: // inflate the device rect by one in each direction.
385: IETRect deviceRect = (IETRect) deviceBounds.clone();
386: deviceRect.inflate(1, 1);
387: return deviceRect.getRectangle();
388: }
389: return null;
390: }
391:
392: public double getFontScaleFactor() {
393: if (m_fontScaleFactor == -1.0) {
394: TSTransform transform = this .getTSTransform();
395:
396: if (transform != null) {
397: m_fontScaleFactor = transform.getScaleX();
398: } else {
399: return 1.0;
400: }
401: }
402: return m_fontScaleFactor;
403:
404: //return this.getOnDrawZoom();
405: }
406: }
|