/******************************************************************************* * 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 ******************************************************************************/ /* * @(#)LineFigure.java 2.1 2008-07-06 * * Copyright (c) 1996-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.draw; import javax.swing.undo.*; import java.awt.event.*; import java.awt.geom.*; import java.util.*; import org.jhotdraw.geom.*; /** * LineFigure. * * @author Werner Randelshofer * @version 2.1 2008-07-06 Create BezierOutlineHandle on mouse over. * <br>2.0 2006-02-27 Support point editing at handle level 0. * <br>2.0 2006-01-14 Changed to support double precison coordinates. * <br>1.0 2003-12-01 Derived from JHotDraw 5.4b1. */ public class LineFigure extends BezierFigure { /** Creates a new instance. */ public LineFigure() { addNode(new BezierPath.Node(new Point2D.Double(0,0))); addNode(new BezierPath.Node(new Point2D.Double(0,0))); } // DRAWING // SHAPE AND BOUNDS // ATTRIBUTES // EDITING @Override public Collection<Handle> createHandles(int detailLevel) { LinkedList<Handle> handles = new LinkedList<Handle>(); switch (detailLevel) { case -1 : // Mouse hover handles handles.add(new BezierOutlineHandle(this, true)); break; case 0 : handles.add(new BezierOutlineHandle(this)); for (int i=0, n = path.size(); i < n; i++) { handles.add(new BezierNodeHandle(this, i)); } break; } return handles; } // CONNECTING // COMPOSITE FIGURES // CLONING // EVENT HANDLING @Override public boolean canConnect() { return false; } /** * Handles a mouse click. */ @Override public boolean handleMouseClick(Point2D.Double p, MouseEvent evt, DrawingView view) { if (evt.getClickCount() == 2 && view.getHandleDetailLevel() == 0) { willChange(); final int index = splitSegment(p, (float) (5f / view.getScaleFactor())); if (index != -1) { final BezierPath.Node newNode = getNode(index); fireUndoableEditHappened(new AbstractUndoableEdit() { @Override public void redo() throws CannotRedoException { super.redo(); willChange(); addNode(index, newNode); changed(); } @Override public void undo() throws CannotUndoException { super.undo(); willChange(); removeNode(index); changed(); } }); changed(); return true; } } return false; } }