/*******************************************************************************
* Copyright (c) 2006-2012
* Software Technology Group, Dresden University of Technology
* DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Software Technology Group - TU Dresden, Germany;
* DevBoost GmbH - Berlin, Germany
* - initial API and implementation
******************************************************************************/
/*
* @(#)SVGPathOutlineHandle.java 2.0 2008-05-22
*
* Copyright (c) 2007-2008 by the original authors of JHotDraw
* and all its contributors.
* All rights reserved.
*
* The copyright of this software is owned by the authors and
* contributors of the JHotDraw project ("the copyright holders").
* You may not use, copy or modify this software, except in
* accordance with the license agreement you entered into with
* the copyright holders. For details see accompanying license terms.
*/
package org.jhotdraw.samples.svg.figures;
import org.jhotdraw.draw.*;
import java.awt.*;
import static org.jhotdraw.samples.svg.SVGAttributeKeys.*;
/**
* SVGPathOutlineHandle.
*
* @author Werner Randelshofer
* @version 2.0 2008-05-22 Handle can be used to mark figure over which mouse is
* hovering.
* <br>1.1 2008-04-12 Improve visibility of the outline, by drawing it
* using two differently colored strokes.
* <br>1.0 13. Mai 2007 Created.
*/
public class SVGPathOutlineHandle extends AbstractHandle {
/**
* Set this to true, if the handle is used for marking a figure over
* which the mouse pointer is hovering.
*/
private boolean isHoverHandle = false;
/** Creates a new instance. */
public SVGPathOutlineHandle(SVGPathFigure owner) {
this(owner, false);
}
/** Creates a new instance. */
public SVGPathOutlineHandle(SVGPathFigure owner, boolean isHoverHandle) {
super(owner);
this.isHoverHandle = isHoverHandle;
}
public SVGPathFigure getOwner() {
return (SVGPathFigure) super.getOwner();
}
protected Rectangle basicGetBounds() {
return view.drawingToView(getOwner().getDrawingArea());
}
@Override
public boolean contains(Point p) {
return false;
}
public void trackStart(Point anchor, int modifiersEx) {
}
public void trackStep(Point anchor, Point lead, int modifiersEx) {
}
public void trackEnd(Point anchor, Point lead, int modifiersEx) {
}
@Override
public void draw(Graphics2D g) {
Shape bounds = getOwner().getPath();
if (TRANSFORM.get(getOwner()) != null) {
bounds = TRANSFORM.get(getOwner()).createTransformedShape(bounds);
}
bounds = view.getDrawingToViewTransform().createTransformedShape(bounds);
Stroke stroke1;
Color strokeColor1;
Stroke stroke2;
Color strokeColor2;
if (getEditor().getTool().supportsHandleInteraction()) {
if (isHoverHandle) {
stroke1 = (Stroke) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_STROKE_1_HOVER);
strokeColor1 = (Color) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_COLOR_1_HOVER);
stroke2 = (Stroke) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_STROKE_2_HOVER);
strokeColor2 = (Color) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_COLOR_2_HOVER);
} else {
stroke1 = (Stroke) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_STROKE_1);
strokeColor1 = (Color) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_COLOR_1);
stroke2 = (Stroke) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_STROKE_2);
strokeColor2 = (Color) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_COLOR_2);
}
} else {
stroke1 = (Stroke) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_STROKE_1_DISABLED);
strokeColor1 = (Color) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_COLOR_1_DISABLED);
stroke2 = (Stroke) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_STROKE_2_DISABLED);
strokeColor2 = (Color) getEditor().getHandleAttribute(HandleAttributeKeys.BEZIER_PATH_COLOR_2_DISABLED);
}
if (stroke1 != null && strokeColor1 != null) {
g.setStroke(stroke1);
g.setColor(strokeColor1);
g.draw(bounds);
}
if (stroke2 != null && strokeColor2 != null) {
g.setStroke(stroke2);
g.setColor(strokeColor2);
g.draw(bounds);
}
}
}