1 package org.simantics.spreadsheet.solver;
3 import java.util.Collection;
4 import java.util.Collections;
6 import java.util.Optional;
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;
14 @SuppressWarnings("rawtypes")
15 public final class SpreadsheetStyle implements SheetNode, SpreadsheetElement<SpreadsheetStyle, SpreadsheetStyle> {
17 public static final Binding BINDING = Bindings.getBindingUnchecked(SpreadsheetStyle.class);
19 private static final SpreadsheetStyle EMPTY = SpreadsheetStyle.newInstace().name("Style_E").build();
21 private static final long serialVersionUID = -4969920277489585741L;
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;
33 private transient int synchronizationId;
34 private transient final int hashCode;
36 public final String formatString;
37 public final int formatIndex;
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) {
44 this.foreground = foreground2;
45 this.background = background2;
46 this.locked = locked2;
47 this.rowSpan = rowSpan2;
48 this.columnSpan = columnSpan2;
50 this.formatString = formatString;
51 this.formatIndex = formatIndex;
54 this.hashCode = hashCode();
58 return synchronizationId;
61 public int getStyleId() {
66 public void accept(SpreadsheetVisitor v) {
71 public Optional<SpreadsheetStyle> getParent() {
72 return Optional.empty();
76 public Collection<SpreadsheetStyle> getSpreadsheetChildren() {
77 return Collections.emptyList();
81 public void remove(SpreadsheetStyle child) {
86 public String getName() {
91 public Map<?, ?> getChildren() {
92 return Collections.emptyMap();
96 public Map<?, ?> getProperties() {
97 return Collections.emptyMap();
101 public int hashCode() {
105 final int prime = 31;
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;
122 public boolean equals(Object obj) {
127 if (getClass() != obj.getClass())
129 SpreadsheetStyle other = (SpreadsheetStyle) obj;
130 if (align != other.align)
132 if (background == null) {
133 if (other.background != null)
135 } else if (!background.equals(other.background))
137 if (border != other.border)
139 if (columnSpan != other.columnSpan)
142 if (other.font != null)
144 } else if (!font.equals(other.font))
146 if (foreground == null) {
147 if (other.foreground != null)
149 } else if (!foreground.equals(other.foreground))
151 if (locked != other.locked)
153 if (rowSpan != other.rowSpan)
155 if (synchronizationId != other.synchronizationId)
157 if (formatIndex != other.formatIndex)
159 if (formatString == null) {
160 if (other.formatString != null)
162 } else if (!formatString.equals(other.formatString))
167 public static SpreadsheetStyleBuilder newInstace() {
168 return new SpreadsheetStyleBuilder();
171 public static SpreadsheetStyle empty() {
175 public static class SpreadsheetStyleBuilder {
178 private RGB.Integer foreground;
179 private RGB.Integer background;
183 private boolean locked;
184 private int rowSpan = 1;
185 private int columnSpan = 1;
186 private String formatString;
187 private short formatIndex;
189 private SpreadsheetStyleBuilder() {}
191 public SpreadsheetStyleBuilder name(String name) {
196 public SpreadsheetStyleBuilder foreground(RGB.Integer foreground) {
197 this.foreground = foreground;
201 public SpreadsheetStyleBuilder background(RGB.Integer background) {
202 this.background = background;
206 public SpreadsheetStyleBuilder border(Integer border) {
207 this.border = border == null ? 0 : border;
211 public SpreadsheetStyleBuilder align(Integer align) {
212 this.align = align == null ? 0 : align;
216 public SpreadsheetStyleBuilder font(Font font) {
221 public SpreadsheetStyleBuilder locked(boolean locked) {
222 this.locked = locked;
226 public SpreadsheetStyleBuilder rowSpan(int rowSpan) {
227 this.rowSpan = rowSpan;
231 public SpreadsheetStyleBuilder font(int columnSpan) {
232 this.columnSpan = columnSpan;
236 public SpreadsheetStyle build() {
237 SpreadsheetStyle style = new SpreadsheetStyle(name, border, align, font, foreground, background, locked, rowSpan, columnSpan, formatString, formatIndex);
241 public SpreadsheetStyleBuilder formatString(String formatString) {
242 this.formatString = formatString;
246 public SpreadsheetStyleBuilder formatIndex(short formatIndex) {
247 this.formatIndex = formatIndex;
251 public SpreadsheetStyleBuilder columnSpan(int columnSpan2) {
252 this.columnSpan = columnSpan2;
257 public void setSynchronizationId(int newId) {
258 this.synchronizationId = newId;