1 package org.simantics.spreadsheet.graph;
3 import java.util.Collection;
4 import java.util.Collections;
6 import java.util.Optional;
8 import org.simantics.datatypes.literal.Font;
9 import org.simantics.datatypes.literal.RGB;
11 public final class SpreadsheetStyle implements SheetNode, SpreadsheetElement<SpreadsheetStyle, SpreadsheetStyle> {
13 // public static final Binding BINDING = Bindings.getBindingUnchecked(SpreadsheetStyle.class);
15 private static final SpreadsheetStyle EMPTY = SpreadsheetStyle.newInstace().name("Style_E").build();
17 private static final long serialVersionUID = -4969920277489585741L;
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;
29 private transient int synchronizationId;
30 private transient final int hashCode;
32 public final String formatString;
33 public final int formatIndex;
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) {
40 this.foreground = foreground2;
41 this.background = background2;
42 this.locked = locked2;
43 this.rowSpan = rowSpan2;
44 this.columnSpan = columnSpan2;
46 this.formatString = formatString;
47 this.formatIndex = formatIndex;
50 this.hashCode = hashCode();
54 return synchronizationId;
57 public int getStyleId() {
62 public void accept(SpreadsheetVisitor v) {
67 public Optional<SpreadsheetStyle> getParent() {
68 return Optional.empty();
72 public Collection<SpreadsheetStyle> getSpreadsheetChildren() {
73 return Collections.emptyList();
77 public void remove(SpreadsheetStyle child) {
82 public String getName() {
87 public Map<?, ?> getChildren() {
88 return Collections.emptyMap();
92 public Map<?, ?> getProperties() {
93 return Collections.emptyMap();
97 public int hashCode() {
101 final int prime = 31;
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;
118 public boolean equals(Object obj) {
123 if (getClass() != obj.getClass())
125 SpreadsheetStyle other = (SpreadsheetStyle) obj;
126 if (align != other.align)
128 if (background == null) {
129 if (other.background != null)
131 } else if (!background.equals(other.background))
133 if (border != other.border)
135 if (columnSpan != other.columnSpan)
138 if (other.font != null)
140 } else if (!font.equals(other.font))
142 if (foreground == null) {
143 if (other.foreground != null)
145 } else if (!foreground.equals(other.foreground))
147 if (locked != other.locked)
149 if (rowSpan != other.rowSpan)
151 if (synchronizationId != other.synchronizationId)
153 if (formatIndex != other.formatIndex)
155 if (formatString == null) {
156 if (other.formatString != null)
158 } else if (!formatString.equals(other.formatString))
163 public static SpreadsheetStyleBuilder newInstace() {
164 return new SpreadsheetStyleBuilder();
167 public static SpreadsheetStyle empty() {
171 public static class SpreadsheetStyleBuilder {
174 private RGB.Integer foreground;
175 private RGB.Integer background;
179 private boolean locked;
180 private int rowSpan = 1;
181 private int columnSpan = 1;
182 private String formatString;
183 private short formatIndex;
185 private SpreadsheetStyleBuilder() {}
187 public SpreadsheetStyleBuilder name(String name) {
192 public SpreadsheetStyleBuilder foreground(RGB.Integer foreground) {
193 this.foreground = foreground;
197 public SpreadsheetStyleBuilder background(RGB.Integer background) {
198 this.background = background;
202 public SpreadsheetStyleBuilder border(Integer border) {
203 this.border = border == null ? 0 : border;
207 public SpreadsheetStyleBuilder align(Integer align) {
208 this.align = align == null ? 0 : align;
212 public SpreadsheetStyleBuilder font(Font font) {
217 public SpreadsheetStyleBuilder locked(boolean locked) {
218 this.locked = locked;
222 public SpreadsheetStyleBuilder rowSpan(int rowSpan) {
223 this.rowSpan = rowSpan;
227 public SpreadsheetStyleBuilder font(int columnSpan) {
228 this.columnSpan = columnSpan;
232 public SpreadsheetStyle build() {
233 SpreadsheetStyle style = new SpreadsheetStyle(name, border, align, font, foreground, background, locked, rowSpan, columnSpan, formatString, formatIndex);
237 public SpreadsheetStyleBuilder formatString(String formatString) {
238 this.formatString = formatString;
242 public SpreadsheetStyleBuilder formatIndex(short formatIndex) {
243 this.formatIndex = formatIndex;
247 public SpreadsheetStyleBuilder columnSpan(int columnSpan2) {
248 this.columnSpan = columnSpan2;
253 public void setSynchronizationId(int newId) {
254 this.synchronizationId = newId;