forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxStylesheet.java
More file actions
213 lines (185 loc) · 4.97 KB
/
mxStylesheet.java
File metadata and controls
213 lines (185 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**
* Copyright (c) 2007, Gaudenz Alder
*/
package com.mxgraph.view;
import java.util.Hashtable;
import java.util.Map;
import com.mxgraph.util.mxConstants;
/**
* Defines the appearance of the cells in a graph. The following example
* changes the font size for all vertices by changing the default vertex
* style in-place:
* <code>
* getDefaultVertexStyle().put(mxConstants.STYLE_FONTSIZE, 16);
* </code>
*
* To change the default font size for all cells, set
* mxConstants.DEFAULT_FONTSIZE.
*/
public class mxStylesheet
{
/**
* Shared immutable empty hashtable (for undefined cell styles).
*/
public static final Map<String, Object> EMPTY_STYLE = new Hashtable<String, Object>();
/**
* Maps from names to styles.
*/
protected Map<String, Map<String, Object>> styles = new Hashtable<String, Map<String, Object>>();
/**
* Constructs a new stylesheet and assigns default styles.
*/
public mxStylesheet()
{
setDefaultVertexStyle(createDefaultVertexStyle());
setDefaultEdgeStyle(createDefaultEdgeStyle());
}
/**
* Returns all styles as map of name, hashtable pairs.
*
* @return All styles in this stylesheet.
*/
public Map<String, Map<String, Object>> getStyles()
{
return styles;
}
/**
* Sets all styles in the stylesheet.
*/
public void setStyles(Map<String, Map<String, Object>> styles)
{
this.styles = styles;
}
/**
* Creates and returns the default vertex style.
*
* @return Returns the default vertex style.
*/
protected Map<String, Object> createDefaultVertexStyle()
{
Map<String, Object> style = new Hashtable<String, Object>();
style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
style.put(mxConstants.STYLE_PERIMETER, mxPerimeter.RectanglePerimeter);
style.put(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE);
style.put(mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER);
style.put(mxConstants.STYLE_FILLCOLOR, "#C3D9FF");
style.put(mxConstants.STYLE_STROKECOLOR, "#6482B9");
style.put(mxConstants.STYLE_FONTCOLOR, "#774400");
return style;
}
/**
* Creates and returns the default edge style.
*
* @return Returns the default edge style.
*/
protected Map<String, Object> createDefaultEdgeStyle()
{
Map<String, Object> style = new Hashtable<String, Object>();
style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CONNECTOR);
style.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC);
style.put(mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE);
style.put(mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER);
style.put(mxConstants.STYLE_STROKECOLOR, "#6482B9");
style.put(mxConstants.STYLE_FONTCOLOR, "#446299");
return style;
}
/**
* Returns the default style for vertices.
*
* @return Returns the default vertex style.
*/
public Map<String, Object> getDefaultVertexStyle()
{
return styles.get("defaultVertex");
}
/**
* Sets the default style for vertices.
*
* @param value Style to be used for vertices.
*/
public void setDefaultVertexStyle(Map<String, Object> value)
{
putCellStyle("defaultVertex", value);
}
/**
* Returns the default style for edges.
*
* @return Returns the default edge style.
*/
public Map<String, Object> getDefaultEdgeStyle()
{
return styles.get("defaultEdge");
}
/**
* Sets the default style for edges.
*
* @param value Style to be used for edges.
*/
public void setDefaultEdgeStyle(Map<String, Object> value)
{
putCellStyle("defaultEdge", value);
}
/**
* Stores the specified style under the given name.
*
* @param name Name for the style to be stored.
* @param style Key, value pairs that define the style.
*/
public void putCellStyle(String name, Map<String, Object> style)
{
styles.put(name, style);
}
/**
* Returns the cell style for the specified cell or the given defaultStyle
* if no style can be found for the given stylename.
*
* @param name String of the form [(stylename|key=value);] that represents the
* style.
* @param defaultStyle Default style to be returned if no style can be found.
* @return Returns the style for the given formatted cell style.
*/
public Map<String, Object> getCellStyle(String name,
Map<String, Object> defaultStyle)
{
Map<String, Object> style = defaultStyle;
if (name != null && name.length() > 0)
{
String[] pairs = name.split(";");
if (style != null && !name.startsWith(";"))
{
style = new Hashtable<String, Object>(style);
}
else
{
style = new Hashtable<String, Object>();
}
for (int i = 0; i < pairs.length; i++)
{
String tmp = pairs[i];
int c = tmp.indexOf('=');
if (c >= 0)
{
String key = tmp.substring(0, c);
String value = tmp.substring(c + 1);
if (value.equals(mxConstants.NONE))
{
style.remove(key);
}
else
{
style.put(key, value);
}
}
else
{
Map<String, Object> tmpStyle = styles.get(tmp);
if (tmpStyle != null)
{
style.putAll(tmpStyle);
}
}
}
}
return style;
}
}