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.model;
19  
20  import org.vectomatic.dom.svg.impl.SVGElement;
21  import org.vectomatic.svg.edit.client.command.IFactoryInstantiator;
22  
23  /**
24   * Metadata class based on DOM attributes
25   * @author laaglu
26   */
27  public class AttrMetadata extends MetadataBase<String, SVGElement> {
28  	protected String attrName;
29  	public AttrMetadata(String propertyName, String description, IFieldFactory fieldFactory, String attrName, IFactoryInstantiator<?> factory, IValidator<String, SVGElement> validator) {
30  		super(propertyName, description, fieldFactory, factory, validator);
31  		this.attrName = attrName;
32  	}
33  
34  	@Override
35  	public String get(SVGElement element) {
36  		return element.getAttribute(attrName);
37  	}
38  
39  	@Override
40  	public String set(SVGElement element, String value) {
41  		String oldValue = element.getAttribute(attrName);
42  		element.setAttribute(attrName, value);
43  		return oldValue;
44  	}
45  
46  	@Override
47  	public String remove(SVGElement element) {
48  		String oldValue = element.getAttribute(attrName);
49  		element.removeAttribute(attrName);
50  		return oldValue;
51  	}
52  
53  	@Override
54  	public String toString() {
55  		StringBuilder builder = new StringBuilder("AttrMetadata(");
56  		builder.append(propertyName);
57  		builder.append(", ");
58  		builder.append(attrName);
59  		builder.append(")");
60  		return builder.toString();
61  	}
62  }