]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetStyle.java
Introduce new DiagramViewer.getRuntimeFromManager()
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / SpreadsheetStyle.java
1 package org.simantics.spreadsheet.graph;
2
3 import java.util.Collection;
4 import java.util.Collections;
5 import java.util.Map;
6 import java.util.Optional;
7
8 import org.simantics.datatypes.literal.Font;
9 import org.simantics.datatypes.literal.RGB;
10
11 public final class SpreadsheetStyle implements SheetNode, SpreadsheetElement<SpreadsheetStyle, SpreadsheetStyle> {
12
13 //    public static final Binding BINDING = Bindings.getBindingUnchecked(SpreadsheetStyle.class);
14     
15     private static final SpreadsheetStyle EMPTY = SpreadsheetStyle.newInstace().name("Style_E").build();
16     
17     private static final long serialVersionUID = -4969920277489585741L;
18     
19     public final String name;
20         public final int border;
21         public final int align;
22         public final Font font;
23         public final RGB.Integer foreground;
24         public final RGB.Integer background;
25         public final boolean locked;
26         public final int rowSpan;
27         public final int columnSpan;
28
29         private transient int synchronizationId;
30     private transient final int hashCode;
31
32     public final String formatString;
33     public final int formatIndex;
34         
35         public SpreadsheetStyle(String name, int border, int align2, Font font2, RGB.Integer foreground2, RGB.Integer background2, boolean locked2, int rowSpan2, int columnSpan2, String formatString, short formatIndex) {
36             this.name = name;
37             this.border = border;
38             this.align = align2;
39             this.font = font2;
40             this.foreground = foreground2;
41             this.background = background2;
42             this.locked = locked2;
43             this.rowSpan = rowSpan2;
44             this.columnSpan = columnSpan2;
45             
46             this.formatString = formatString;
47             this.formatIndex = formatIndex;
48             
49             
50             this.hashCode = hashCode();
51     }
52         
53         public int getId() {
54             return synchronizationId;
55         }
56         
57         public int getStyleId() {
58             return hashCode();
59         }
60
61     @Override
62     public void accept(SpreadsheetVisitor v) {
63         
64     }
65
66     @Override
67     public Optional<SpreadsheetStyle> getParent() {
68         return Optional.empty();
69     }
70
71     @Override
72     public Collection<SpreadsheetStyle> getSpreadsheetChildren() {
73         return Collections.emptyList();
74     }
75
76     @Override
77     public void remove(SpreadsheetStyle child) {
78         
79     }
80
81     @Override
82     public String getName() {
83         return "style";
84     }
85
86     @Override
87     public Map<?, ?> getChildren() {
88         return Collections.emptyMap();
89     }
90
91     @Override
92     public Map<?, ?> getProperties() {
93         return Collections.emptyMap();
94     }
95
96     @Override
97     public int hashCode() {
98         if (hashCode != 0)
99             return hashCode;
100         
101         final int prime = 31;
102         int result = 1;
103         result = prime * result + align;
104         result = prime * result + ((formatString == null) ? 0 : formatString.hashCode());
105         result = prime * result + ((background == null) ? 0 : background.hashCode());
106         result = prime * result + border;
107         result = prime * result + formatIndex;
108         result = prime * result + columnSpan;
109         result = prime * result + ((font == null) ? 0 : font.hashCode());
110         result = prime * result + ((foreground == null) ? 0 : foreground.hashCode());
111         result = prime * result + (locked ? 1231 : 1237);
112         result = prime * result + rowSpan;
113         
114         return result;
115     }
116
117     @Override
118     public boolean equals(Object obj) {
119         if (this == obj)
120             return true;
121         if (obj == null)
122             return false;
123         if (getClass() != obj.getClass())
124             return false;
125         SpreadsheetStyle other = (SpreadsheetStyle) obj;
126         if (align != other.align)
127             return false;
128         if (background == null) {
129             if (other.background != null)
130                 return false;
131         } else if (!background.equals(other.background))
132             return false;
133         if (border != other.border)
134             return false;
135         if (columnSpan != other.columnSpan)
136             return false;
137         if (font == null) {
138             if (other.font != null)
139                 return false;
140         } else if (!font.equals(other.font))
141             return false;
142         if (foreground == null) {
143             if (other.foreground != null)
144                 return false;
145         } else if (!foreground.equals(other.foreground))
146             return false;
147         if (locked != other.locked)
148             return false;
149         if (rowSpan != other.rowSpan)
150             return false;
151         if (synchronizationId != other.synchronizationId)
152             return false;
153         if (formatIndex != other.formatIndex)
154             return false;
155         if (formatString == null) {
156             if (other.formatString != null)
157                 return false;
158         } else if (!formatString.equals(other.formatString))
159             return false;
160         return true;
161     }
162     
163     public static SpreadsheetStyleBuilder newInstace() {
164         return new SpreadsheetStyleBuilder();
165     }
166     
167     public static SpreadsheetStyle empty() {
168         return EMPTY;
169     }
170     
171     public static class SpreadsheetStyleBuilder {
172         
173         private String name;
174         private RGB.Integer foreground;
175         private RGB.Integer background;
176         private int border;
177         private int align;
178         private Font font;
179         private boolean locked;
180         private int rowSpan = 1;
181         private int columnSpan = 1;
182         private String formatString;
183         private short formatIndex;
184
185         private SpreadsheetStyleBuilder() {}
186         
187         public SpreadsheetStyleBuilder name(String name) {
188             this.name = name;
189             return this;
190         }
191         
192         public SpreadsheetStyleBuilder foreground(RGB.Integer foreground) {
193             this.foreground = foreground;
194             return this;
195         }
196         
197         public SpreadsheetStyleBuilder background(RGB.Integer background) {
198             this.background = background;
199             return this;
200         }
201         
202         public SpreadsheetStyleBuilder border(Integer border) {
203             this.border = border == null ? 0 : border;
204             return this;
205         }
206         
207         public SpreadsheetStyleBuilder align(Integer align) {
208             this.align = align == null ? 0 : align;
209             return this;
210         }
211         
212         public SpreadsheetStyleBuilder font(Font font) {
213             this.font = font;
214             return this;
215         }
216         
217         public SpreadsheetStyleBuilder locked(boolean locked) {
218             this.locked = locked;
219             return this;
220         }
221         
222         public SpreadsheetStyleBuilder rowSpan(int rowSpan) {
223             this.rowSpan = rowSpan;
224             return this;
225         }
226         
227         public SpreadsheetStyleBuilder font(int columnSpan) {
228             this.columnSpan = columnSpan;
229             return this;
230         }
231         
232         public SpreadsheetStyle build() {
233             SpreadsheetStyle style = new SpreadsheetStyle(name, border, align, font, foreground, background, locked, rowSpan, columnSpan, formatString, formatIndex);
234             return style;
235         }
236
237         public SpreadsheetStyleBuilder formatString(String formatString) {
238             this.formatString = formatString;
239             return this;
240         }
241
242         public SpreadsheetStyleBuilder formatIndex(short formatIndex) {
243             this.formatIndex = formatIndex;
244             return this;
245         }
246
247         public SpreadsheetStyleBuilder columnSpan(int columnSpan2) {
248             this.columnSpan = columnSpan2;
249             return this;
250         }
251     }
252
253     public void setSynchronizationId(int newId) {
254         this.synchronizationId = newId;
255     }
256     
257 }