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.gxt.widget;
19  
20  import org.vectomatic.dom.svg.OMSVGDocument;
21  import org.vectomatic.dom.svg.OMSVGLineElement;
22  import org.vectomatic.dom.svg.OMSVGRectElement;
23  import org.vectomatic.dom.svg.OMSVGSVGElement;
24  import org.vectomatic.dom.svg.OMSVGStyle;
25  import org.vectomatic.dom.svg.ui.SVGImage;
26  import org.vectomatic.dom.svg.utils.OMSVGParser;
27  import org.vectomatic.dom.svg.utils.SVGConstants;
28  import org.vectomatic.svg.edit.client.AppBundle;
29  import org.vectomatic.svg.edit.client.model.svg.DashArray;
30  
31  import com.google.gwt.dom.client.Style.Unit;
32  
33  /**
34   * Widget to display a dash-array value
35   * @author laaglu
36   */
37  public class DashArrayCell extends SVGImage {
38  	protected OMSVGLineElement line;
39  	protected DashArray dashArray;
40  
41  	public DashArrayCell() {
42  		OMSVGDocument document = OMSVGParser.currentDocument();
43  		OMSVGSVGElement svg = document.createSVGSVGElement();
44  		svg.getStyle().setHeight(10, Unit.PX);
45  		svg.getStyle().setWidth(100, Unit.PCT);
46  		OMSVGRectElement rect = document.createSVGRectElement();
47  		rect.getX().getBaseVal().setValueAsString("0%");
48  		rect.getY().getBaseVal().setValueAsString("0%");
49  		rect.getWidth().getBaseVal().setValueAsString("100%");
50  		rect.getHeight().getBaseVal().setValueAsString("100%");
51  		line = document.createSVGLineElement();
52  		line.getX1().getBaseVal().setValueAsString("0%");
53  		line.getY1().getBaseVal().setValueAsString("50%");
54  		line.getX2().getBaseVal().setValueAsString("100%");
55  		line.getY2().getBaseVal().setValueAsString("50%");
56  		svg.setClassNameBaseVal(AppBundle.INSTANCE.css().dasharrayCell());
57  		svg.appendChild(rect);
58  		svg.appendChild(line);
59  		setSvgElement(svg);
60  	}
61  
62  	public void setDashArray(DashArray dashArray) {
63  		OMSVGStyle style = line.getStyle();
64  		String cssText = (dashArray != null) ? dashArray.toString() : "";
65  		if (cssText.length() > 0) {
66  			style.setSVGProperty(SVGConstants.CSS_STROKE_DASHARRAY_PROPERTY, cssText);
67  		} else {
68  			style.clearSVGProperty(SVGConstants.CSS_STROKE_DASHARRAY_PROPERTY);
69  		}
70  		this.dashArray = dashArray;
71  	}
72  	
73  	public DashArray getDashArray() {
74  		return dashArray;
75  	}
76  }