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