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.OMSVGPaint;
22  import org.vectomatic.dom.svg.OMSVGRectElement;
23  import org.vectomatic.dom.svg.OMSVGSVGElement;
24  import org.vectomatic.dom.svg.impl.SVGPaintParser;
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  
29  /**
30   * Widget to display a paint value
31   * @author laaglu
32   */
33  public class PaintCell extends SVGImage {
34  	protected OMSVGRectElement rect;
35  	public PaintCell() {
36  		OMSVGDocument document = OMSVGParser.currentDocument();
37  		OMSVGSVGElement svg = document.createSVGSVGElement();
38  		rect = document.createSVGRectElement();
39  		rect.getWidth().getBaseVal().setValueAsString("100%");
40  		rect.getHeight().getBaseVal().setValueAsString("100%");
41  		rect.getStyle().setSVGProperty(SVGConstants.CSS_STROKE_PROPERTY, SVGConstants.CSS_BLACK_VALUE);
42  		svg.appendChild(rect);
43  		setSvgElement(svg);
44  	}
45  	public void setPaint(OMSVGPaint paint) {
46  		rect.getStyle().setSVGProperty(SVGConstants.CSS_FILL_PROPERTY, paint.getCssText());
47  	}
48  	public OMSVGPaint getPaint() {
49  		String cssText = rect.getStyle().getSVGProperty(SVGConstants.CSS_FILL_PROPERTY);
50  		return (cssText != null && cssText.length() > 0) ? OMSVGParser.parsePaint(cssText) : SVGPaintParser.NONE;
51  	}
52  	
53  }