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 java.util.ArrayList;
21  import java.util.List;
22  
23  import org.vectomatic.svg.edit.client.inspector.IInspectorSection;
24  import org.vectomatic.svg.edit.client.inspector.IInspectorSectionFactory;
25  
26  /**
27   * Class to group related metadata of a model into a logical abstraction
28   * @author laaglu
29   * @param <U>
30   * The model class
31   */
32  public class ModelCategory<U> {
33  	public static final String GLOBAL = "global";
34  	public static final String DISPLAY = "display";
35  	public static final String GEOMETRY = "geometry";
36  	public static final String TRANSFORM = "transform";
37  	public static final String STROKEFILL = "strokefill";
38  	private String name;
39  	private String description;
40  	private IInspectorSectionFactory sectionFactory;
41  	private List<IMetadata<?, U>> metadataList;
42  	public ModelCategory(String name, String description, IInspectorSectionFactory sectionFactory) {
43  		this.name = name;
44  		this.description = description;
45  		this.sectionFactory = sectionFactory;
46  		this.metadataList = new ArrayList<IMetadata<?, U>>();
47  	}
48  	public String getName() {
49  		return name;
50  	}
51  	public String getDescription() {
52  		return description;
53  	}
54  	public IInspectorSection getInspectorSection() {
55  		return sectionFactory != null ? sectionFactory.createSection(this) : null;
56  	}
57  	public List<IMetadata<?, U>> getMetadata() {
58  		return metadataList;
59  	}
60  	public <T> IMetadata<T, U> getMetadata(String name) {
61  		for (IMetadata<?, U> m : metadataList) {
62  			if (name.equals(m.getName())) {
63  				return (IMetadata<T, U>)m;
64  			}
65  		}
66  		return null;
67  	}
68  	public void addMetadata(MetadataBase<?,U> metadata) {
69  		metadata.category = this;
70  		metadataList.add(metadata);
71  	}
72  	@Override
73  	public String toString() {
74  		StringBuilder builder = new StringBuilder("ModelCategory(");
75  		builder.append(name);
76  		builder.append(", ");
77  		builder.append(metadataList);
78  		builder.append(")");
79  		return builder.toString();
80  	}
81  }