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 java.util.List;
21  
22  import org.vectomatic.dom.svg.OMSVGGElement;
23  import org.vectomatic.dom.svg.OMSVGRectElement;
24  import org.vectomatic.dom.svg.OMSVGSVGElement;
25  
26  /**
27   * Interface for classes which own a segment representation
28   * @author laaglu
29   */
30  public interface IPathRepOwner {
31  	/**
32  	 * Enum to represent the possible edition modes
33  	 */
34  	enum Mode {
35  		/**
36  		 * Display both vertices and tangents
37  		 */
38  		TANGENT,
39  		/**
40  		 * Display only vertices
41  		 */
42  		VERTEX;
43  		public void write(OMSVGGElement g) {
44  			g.setAttribute(MODE_ATTRIBUTE, name());
45  		}
46  		public static Mode read(OMSVGGElement g) {
47  			String mode = g.getAttribute(MODE_ATTRIBUTE);
48  			assert ! "".equals(mode);
49  			return Mode.valueOf(mode);
50  		}
51  		static final String MODE_ATTRIBUTE = "mode";
52  	}
53  
54  	
55  	/**
56  	 * Enum to represent the state of a path vertex
57  	 */
58  	public enum VertexState {
59  		NONE {
60  			@Override
61  			void write(OMSVGRectElement vertex) {
62  				vertex.removeAttribute(STATE_ATTRIBUTE);
63  			}
64  			@Override
65  			String getValue() {
66  				return ""; 
67  			}
68  		},
69  		SELECTED {
70  			@Override
71  			void write(OMSVGRectElement vertex) {
72  				vertex.setAttribute(STATE_ATTRIBUTE, getValue());
73  			}
74  			@Override
75  			String getValue() {
76  				return "S"; 
77  			}
78  		},
79  		CLOSING {
80  			@Override
81  			void write(OMSVGRectElement vertex) {
82  				vertex.setAttribute(STATE_ATTRIBUTE, getValue());
83  			}			
84  			@Override
85  			String getValue() {
86  				return "C"; 
87  			}
88  		};
89  		abstract void write(OMSVGRectElement vertex);
90  		abstract String getValue();
91  		
92  		public static VertexState read(OMSVGRectElement vertex) {
93  			String attr = vertex.getAttribute(STATE_ATTRIBUTE);
94  			if (VertexState.NONE.getValue().equals(attr)) {
95  				return VertexState.NONE;
96  			}
97  			if (VertexState.SELECTED.getValue().equals(attr)) {
98  				return VertexState.SELECTED;
99  			}
100 			if (VertexState.CLOSING.getValue().equals(attr)) {
101 				return VertexState.CLOSING;
102 			}
103 			assert false;
104 			return null;
105 		}
106 		static final String STATE_ATTRIBUTE = "state";
107 	}
108 	OMSVGSVGElement getSvg();
109 	List<SVGSegRep> getSegments();
110 	Mode getMode();
111 }
112 
113