View Javadoc

1   /**********************************************
2    * Copyright (C) 2011 Lukas Laag
3    * This file is part of svgreal.
4    * 
5    * svgreal is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * svgreal 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
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with svgreal.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.svg.edit.client.command.path;
19  
20  import org.vectomatic.dom.svg.OMSVGPathSeg;
21  import org.vectomatic.dom.svg.OMSVGPathSegLinetoAbs;
22  import org.vectomatic.dom.svg.OMSVGPoint;
23  
24  import com.google.gwt.dom.client.Element;
25  
26  /**
27   * Class to represent a path linear segment 
28   * @author laaglu
29   */
30  public class SVGLineSegRep extends SVGSegRep {
31  	protected OMSVGPathSegLinetoAbs lineToSeg;
32  
33  	public SVGLineSegRep(IPathRepOwner owner, OMSVGPathSegLinetoAbs lineToSeg) {
34  		super(owner);
35  		this.lineToSeg = lineToSeg;
36  	}
37  	
38  	public OMSVGPathSeg getElement() {
39  		return lineToSeg;
40  	}
41  
42  	@Override
43  	public float getX() {
44  		return lineToSeg.getX();
45  	}
46  	@Override
47  	public void setX(float x) {
48  		lineToSeg.setX(x);
49  	}
50  	@Override
51  	public float getY() {
52  		return lineToSeg.getY();
53  	}
54  	@Override
55  	public void setY(float y) {
56  		lineToSeg.setY(y);
57  	}
58  	
59  	@Override
60  	public void update(float hs) {
61  		float x = lineToSeg.getX();
62  		float y = lineToSeg.getY();
63  		vertex.getX().getBaseVal().setValue(x - hs);
64  		vertex.getY().getBaseVal().setValue(y - hs);
65  		vertex.getWidth().getBaseVal().setValue(hs * 2);
66  		vertex.getHeight().getBaseVal().setValue(hs * 2);
67  	}
68  	
69  	@Override
70  	public void updateEnd(OMSVGPoint delta, float hs) {
71  		lineToSeg.setX(lineToSeg.getX() + delta.getX());
72  		lineToSeg.setY(lineToSeg.getY() + delta.getY());
73  		update(hs);
74  	}
75  
76  	@Override
77  	public void processMouseMove(OMSVGPoint delta, Element target, float hs, boolean isCtrlKeyDown) {
78  		if (target == null) {
79  			updateEnd(delta, hs);
80  			if (next != null) {
81  				next.updateStart(delta, hs);
82  			}
83  		}
84  	}
85  	
86  	@Override
87  	public String toString() {
88  		StringBuilder builder = new StringBuilder("L ");
89  		builder.append(lineToSeg.getX());
90  		builder.append(",");
91  		builder.append(lineToSeg.getY());
92  		return builder.toString();
93  	}
94  
95  }