001package jmri.jmrit.display.layoutEditor;
002
003import java.awt.Color;
004import javax.annotation.Nonnull;
005import jmri.util.swing.JmriColorChooser;
006
007/*******************************************************************************
008 * Hold various values defining how to draw various LayoutTrack elements.
009 * 
010 * @since 4.15.6 blockDefaultColor, blockOccupiedColor and blockAlternativeColor added here
011 *
012 * @author George Warner Copyright (c) 2017-2018
013 */
014public class LayoutTrackDrawingOptions {
015
016    private String name;
017
018    public LayoutTrackDrawingOptions(String name) {
019        this.name = name;
020    }
021
022    public LayoutTrackDrawingOptions(LayoutTrackDrawingOptions ltdo) {
023        name = ltdo.getName();
024        mainBallastColor = ltdo.getMainBallastColor();
025        mainBallastWidth = ltdo.getMainBallastWidth();
026        mainBlockLineDashPercentageX10 = ltdo.getMainBlockLineDashPercentageX10();
027        mainBlockLineWidth = ltdo.getMainBlockLineWidth();
028        mainRailColor = ltdo.getMainRailColor();
029        mainRailCount = ltdo.getMainRailCount();
030        mainRailGap = ltdo.getMainRailGap();
031        mainRailWidth = ltdo.getMainRailWidth();
032        mainTieColor = ltdo.getMainTieColor();
033        mainTieGap = ltdo.getMainTieGap();
034        mainTieLength = ltdo.getMainTieLength();
035        mainTieWidth = ltdo.getMainTieWidth();
036        sideBallastColor = ltdo.getSideBallastColor();
037        sideBallastWidth = ltdo.getSideBallastWidth();
038        sideBlockLineDashPercentageX10 = ltdo.getSideBlockLineDashPercentageX10();
039        sideBlockLineWidth = ltdo.getSideBlockLineWidth();
040        sideRailColor = ltdo.getSideRailColor();
041        sideRailCount = ltdo.getSideRailCount();
042        sideRailGap = ltdo.getSideRailGap();
043        sideRailWidth = ltdo.getSideRailWidth();
044        sideTieColor = ltdo.getSideTieColor();
045        sideTieGap = ltdo.getSideTieGap();
046        sideTieLength = ltdo.getSideTieLength();
047        sideTieWidth = ltdo.getSideTieWidth();
048        blockDefaultColor = ltdo.getBlockDefaultColor();
049        blockOccupiedColor = ltdo.getBlockOccupiedColor();
050        blockAlternativeColor = ltdo.getBlockAlternativeColor();
051
052    }
053
054    public String getName() {
055        return name;
056    }
057
058    public void setName(String name) {
059        this.name = name;
060    }
061
062    private int sideBallastWidth = 0;   // defaults to zero (off)
063
064    public int getSideBallastWidth() {
065        return sideBallastWidth;
066    }
067
068    public void setSideBallastWidth(int val) {
069        sideBallastWidth = val;
070    }
071
072    private Color sideBallastColor = Color.BLACK;
073
074    public Color getSideBallastColor() {
075        return sideBallastColor;
076    }
077
078    public void setSideBallastColor(@Nonnull Color val) {
079        sideBallastColor = val;
080        JmriColorChooser.addRecentColor(val);
081    }
082
083    private int sideTieLength = 0;
084
085    public int getSideTieLength() {
086        return sideTieLength;
087    }
088
089    public void setSideTieLength(int val) {
090        sideTieLength = val;
091    }
092
093    private Color sideTieColor = Color.BLACK;
094
095    public Color getSideTieColor() {
096        return sideTieColor;
097    }
098
099    public void setSideTieColor(@Nonnull Color val) {
100        sideTieColor = val;
101        JmriColorChooser.addRecentColor(val);
102    }
103
104    private int sideTieWidth = 0;
105
106    public int getSideTieWidth() {
107        return sideTieWidth;
108    }
109
110    public void setSideTieWidth(int val) {
111        sideTieWidth = val;
112    }
113
114    private int sideTieGap = 0;
115
116    public int getSideTieGap() {
117        return sideTieGap;
118    }
119
120    public void setSideTieGap(int val) {
121        sideTieGap = val;
122    }
123
124    private int sideRailCount = 1;
125
126    public int getSideRailCount() {
127        return sideRailCount;
128    }
129
130    public void setSideRailCount(int val) {
131        sideRailCount = val;
132    }
133
134    private int sideRailWidth = 1;
135
136    public int getSideRailWidth() {
137        return sideRailWidth;
138    }
139
140    public void setSideRailWidth(int val) {
141        sideRailWidth = val;
142    }
143
144    private int sideRailGap = 0;
145
146    public int getSideRailGap() {
147        return sideRailGap;
148    }
149
150    public void setSideRailGap(int val) {
151        sideRailGap = val;
152    }
153
154    private Color sideRailColor = Color.GRAY;
155
156    public Color getSideRailColor() {
157        return sideRailColor;
158    }
159
160    public void setSideRailColor(@Nonnull Color val) {
161        sideRailColor = val;
162        JmriColorChooser.addRecentColor(val);
163    }
164
165    private int sideBlockLineDashPercentageX10 = 0;
166
167    public int getSideBlockLineDashPercentageX10() {
168        return sideBlockLineDashPercentageX10;
169    }
170
171    public void setSideBlockLineDashPercentageX10(int val) {
172        sideBlockLineDashPercentageX10 = val;
173    }
174
175    private int sideBlockLineWidth = 2;
176
177    public int getSideBlockLineWidth() {
178        return sideBlockLineWidth;
179    }
180
181    public void setSideBlockLineWidth(int val) {
182        sideBlockLineWidth = val;
183    }
184
185    private int mainBallastWidth = 0;   // defaults to zero (off)
186
187    public int getMainBallastWidth() {
188        return mainBallastWidth;
189    }
190
191    public void setMainBallastWidth(int val) {
192        mainBallastWidth = val;
193    }
194
195    private Color mainBallastColor = Color.BLACK;
196
197    public Color getMainBallastColor() {
198        return mainBallastColor;
199    }
200
201    public void setMainBallastColor(@Nonnull Color val) {
202        mainBallastColor = val;
203        JmriColorChooser.addRecentColor(val);
204    }
205
206    private int mainTieLength = 0;
207
208    public int getMainTieLength() {
209        return mainTieLength;
210    }
211
212    public void setMainTieLength(int val) {
213        mainTieLength = val;
214    }
215
216    private Color mainTieColor = Color.BLACK;
217
218    public Color getMainTieColor() {
219        return mainTieColor;
220    }
221
222    public void setMainTieColor(@Nonnull Color val) {
223        mainTieColor = val;
224        JmriColorChooser.addRecentColor(val);
225    }
226
227    private int mainTieWidth = 0;
228
229    public int getMainTieWidth() {
230        return mainTieWidth;
231    }
232
233    public void setMainTieWidth(int val) {
234        mainTieWidth = val;
235    }
236
237    private int mainTieGap = 0;
238
239    public int getMainTieGap() {
240        return mainTieGap;
241    }
242
243    public void setMainTieGap(int val) {
244        mainTieGap = val;
245    }
246
247    private int mainRailCount = 1;
248
249    public int getMainRailCount() {
250        return mainRailCount;
251    }
252
253    public void setMainRailCount(int val) {
254        mainRailCount = val;
255    }
256
257    private int mainRailWidth = 2;
258
259    public int getMainRailWidth() {
260        return mainRailWidth;
261    }
262
263    public void setMainRailWidth(int val) {
264        mainRailWidth = val;
265    }
266
267    private int mainRailGap = 0;
268
269    public int getMainRailGap() {
270        return mainRailGap;
271    }
272
273    public void setMainRailGap(int val) {
274        mainRailGap = val;
275    }
276
277    private Color mainRailColor = Color.GRAY;
278
279    public Color getMainRailColor() {
280        return mainRailColor;
281    }
282
283    public void setMainRailColor(@Nonnull Color val) {
284        mainRailColor = val;
285        JmriColorChooser.addRecentColor(val);
286    }
287
288    private int mainBlockLineDashPercentageX10 = 0;
289
290    public int getMainBlockLineDashPercentageX10() {
291        return mainBlockLineDashPercentageX10;
292    }
293
294    public void setMainBlockLineDashPercentageX10(int val) {
295        mainBlockLineDashPercentageX10 = val;
296    }
297
298    private int mainBlockLineWidth = 4;
299
300    public int getMainBlockLineWidth() {
301        return mainBlockLineWidth;
302    }
303
304    public void setMainBlockLineWidth(int val) {
305        mainBlockLineWidth = val;
306    }
307
308    private Color blockDefaultColor = Color.GRAY;
309
310    public Color getBlockDefaultColor() {
311        return blockDefaultColor;
312    }
313
314    public void setBlockDefaultColor(@Nonnull Color val) {
315        blockDefaultColor = val;
316        JmriColorChooser.addRecentColor(val);
317    }
318
319    private Color blockOccupiedColor = Color.red;
320
321    public Color getBlockOccupiedColor() {
322        return blockOccupiedColor;
323    }
324
325    public void setBlockOccupiedColor(@Nonnull Color val) {
326        blockOccupiedColor = val;
327        JmriColorChooser.addRecentColor(val);
328    }
329
330    private Color blockAlternativeColor = Color.GRAY;
331
332    public Color getBlockAlternativeColor() {
333        return blockAlternativeColor;
334    }
335
336    public void setBlockAlternativeColor(@Nonnull Color val) {
337        blockAlternativeColor = val;
338        JmriColorChooser.addRecentColor(val);
339    }
340
341    //
342    public boolean equalsAllButName(@Nonnull LayoutTrackDrawingOptions ltdo) {
343        boolean result = true;  // assume success (optimist!)
344        if (this != ltdo) {
345            result = false; // assume failure (pessimist!)
346            if (ltdo != null) {
347                String tempName = name;
348                name = ltdo.getName();
349                result = this.equals(ltdo);
350                name = tempName;
351            }
352        }
353        return result;
354    }
355
356    @Override
357    public boolean equals(Object obj) {
358        boolean result = true;  // assume success (optimist!)
359        if (obj != this) {
360            result = false; // assume failure (pessimist!)
361            if ((obj != null) && (getClass() == obj.getClass())) {
362                LayoutTrackDrawingOptions ltdo = (LayoutTrackDrawingOptions) obj;
363
364                do {
365                    if (!name.equals(ltdo.getName())) {
366                        break;
367                    }
368                    if (sideBallastWidth != ltdo.getSideBallastWidth()) {
369                        break;
370                    }
371                    if (!sideBallastColor.equals(ltdo.getSideBallastColor())) {
372                        break;
373                    }
374                    if (sideTieLength != ltdo.getSideTieLength()) {
375                        break;
376                    }
377                    if (!sideTieColor.equals(ltdo.getSideTieColor())) {
378                        break;
379                    }
380
381                    if (sideTieGap != ltdo.getSideTieGap()) {
382                        break;
383                    }
384                    if (sideRailCount != ltdo.getSideRailCount()) {
385                        break;
386                    }
387                    if (sideRailWidth != ltdo.getSideRailWidth()) {
388                        break;
389                    }
390                    if (sideRailGap != ltdo.getSideRailGap()) {
391                        break;
392                    }
393                    if (!sideRailColor.equals(ltdo.getSideRailColor())) {
394                        break;
395                    }
396
397                    if (sideBlockLineDashPercentageX10 != ltdo.getSideBlockLineDashPercentageX10()) {
398                        break;
399                    }
400
401                    if (sideBlockLineWidth != ltdo.getSideBlockLineWidth()) {
402                        break;
403                    }
404
405                    if (mainBallastWidth != ltdo.getMainBallastWidth()) {
406                        break;
407                    }
408                    if (!mainBallastColor.equals(ltdo.getMainBallastColor())) {
409                        break;
410                    }
411
412                    if (mainTieLength != ltdo.getMainTieLength()) {
413                        break;
414                    }
415                    if (!mainTieColor.equals(ltdo.getMainTieColor())) {
416                        break;
417                    }
418
419                    if (mainTieWidth != ltdo.getMainTieWidth()) {
420                        break;
421                    }
422                    if (mainTieGap != ltdo.getMainTieGap()) {
423                        break;
424                    }
425                    if (mainRailCount != ltdo.getMainRailCount()) {
426                        break;
427                    }
428                    if (mainRailWidth != ltdo.getMainRailWidth()) {
429                        break;
430                    }
431                    if (mainRailGap != ltdo.getMainRailGap()) {
432                        break;
433                    }
434                    if (!mainRailColor.equals(ltdo.getMainRailColor())) {
435                        break;
436                    }
437                    if (mainBlockLineDashPercentageX10 != ltdo.getMainBlockLineDashPercentageX10()) {
438                        break;
439                    }
440                    if (mainBlockLineWidth != ltdo.getMainBlockLineWidth()) {
441                        break;
442                    }
443                    if (!blockDefaultColor.equals(ltdo.getBlockDefaultColor())) {
444                        break;
445                    }
446                    if (!blockOccupiedColor.equals(ltdo.getBlockOccupiedColor())) {
447                        break;
448                    }
449                    if (!blockAlternativeColor.equals(ltdo.getBlockAlternativeColor())) {
450                        break;
451                    }
452                    result = true;
453                } while (false);
454            }
455        }
456        return result;
457    }   // equals
458
459    /**
460     * Hash on the header
461     */
462    @Override
463    public int hashCode() {
464        int result = 7;
465        result = (37 * result) + (name != null ? name.hashCode() : 0);
466
467        // sideline values
468        result = (37 * result) + sideBallastWidth;
469        result = (37 * result) + (sideBallastColor == null ? 0 : sideBallastColor.hashCode());
470        result = (37 * result) + sideTieLength;
471        result = (37 * result) + (sideTieColor == null ? 0 : sideTieColor.hashCode());
472        result = (37 * result) + sideTieGap;
473        result = (37 * result) + sideRailCount;
474        result = (37 * result) + sideRailWidth;
475        result = (37 * result) + sideRailGap;
476        result = (37 * result) + (sideRailColor == null ? 0 : sideRailColor.hashCode());
477        result = (37 * result) + sideBlockLineDashPercentageX10;
478        result = (37 * result) + sideBlockLineWidth;
479
480        // mainline values
481        result = (37 * result) + mainBallastWidth;
482        result = (37 * result) + (mainBallastColor == null ? 0 : mainBallastColor.hashCode());
483        result = (37 * result) + mainTieLength;
484        result = (37 * result) + (mainTieColor == null ? 0 : mainTieColor.hashCode());
485        result = (37 * result) + mainTieWidth;
486        result = (37 * result) + mainTieGap;
487        result = (37 * result) + mainRailCount;
488        result = (37 * result) + mainRailWidth;
489        result = (37 * result) + mainRailGap;
490        result = (37 * result) + (mainRailColor == null ? 0 : mainRailColor.hashCode());
491        result = (37 * result) + mainBlockLineDashPercentageX10;
492        result = (37 * result) + mainBlockLineWidth;
493
494        // block
495        result = (37 * result) + (blockDefaultColor == null ? 0 : blockDefaultColor.hashCode());
496        result = (37 * result) + (blockOccupiedColor == null ? 0 : blockOccupiedColor.hashCode());
497        result = (37 * result) + (blockAlternativeColor == null ? 0 : blockAlternativeColor.hashCode());
498
499        return result;
500    }
501}