1 /*******************************************************************************
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * VTT Technical Research Centre of Finland - initial API and implementation
10 *******************************************************************************/
11 package org.simantics.trend.configuration;
13 import org.simantics.databoard.annotations.Identifier;
14 import org.simantics.databoard.annotations.Optional;
15 import org.simantics.databoard.util.Bean;
16 import org.simantics.utils.strings.AlphanumComparator;
19 * @author Toni Kalajainen
21 public class TrendItem extends Bean {
23 // Sorting and color index
27 public @Optional String label;
28 // Normal Label (eg. The label in CSV file)
29 public @Optional String simpleLabel;
30 // Variable reference in user friendly format
31 public @Optional String variableReference;
33 // GroupId in the history
34 public @Identifier String groupId;
35 // ItemId in the group
36 public @Identifier String groupItemId;
37 // Variable id in format understood by org.simantics.simulation.data.Datasource
38 public @Identifier String variableId;
42 // TODO Rename Binary to Bar
43 public enum Renderer { Analog, Binary } public Renderer renderer;
45 public @Optional String unit;
47 public DrawMode drawMode = DrawMode.getDefault();
49 // If true, the item shall not be shown in the chart.
50 public boolean hidden = false;
52 // Defines a custom stroke to be used when rendering this item.
53 public @Optional Float customStrokeWidth;
55 // Defines a custom color to be used when rendering this item.
56 // If not defined, color is calculated based on #index.
57 public @Optional float[] customColor;
59 public enum DrawMode {
67 public static DrawMode getDefault() {
68 return DeviationAndLine;
75 public TrendItem(int index, String label, String subscriptionId, String variableId, Scale scale) {
76 this(index, label, subscriptionId, variableId, scale, Renderer.Analog);
79 public TrendItem(int index, String label, String subscriptionId, String variableId, Scale scale, Renderer renderer) {
82 this.variableId = variableId;
84 this.renderer = renderer;
85 this.groupId = subscriptionId;
86 this.groupItemId = variableId;
89 public TrendItem(int index, String label, String subscriptionId, String variableId, Scale scale, Renderer renderer, double min, double max) {
92 this.variableId = variableId;
93 this.scale = new Scale.Manual(min, max);
94 this.renderer = renderer;
95 this.groupId = subscriptionId;
96 this.groupItemId = variableId;
99 public TrendItem(int index, String label, String subscriptionId, String variableId, Scale scale, Renderer renderer, double min, double max, DrawMode drawMode) {
102 this.variableId = variableId;
103 this.scale = new Scale.Manual(min, max);
104 this.renderer = renderer;
105 this.groupId = subscriptionId;
106 this.groupItemId = variableId;
107 this.drawMode = drawMode;
111 public int compareTo(Bean o) {
112 if ( o instanceof TrendItem == false ) return 0;
113 TrendItem other = (TrendItem) o;
115 int c = renderer.ordinal() - other.renderer.ordinal();
116 if ( c!=0 ) return c;
118 c = index - other.index;
119 if ( c!=0 ) return c;
121 String myLabel1 = label!=null?label:"";
122 String otLabel1 = other.label!=null?other.label:"";
123 c = AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(myLabel1, otLabel1);
124 if ( c!=0 ) return c;
126 String myLabel2 = simpleLabel!=null?simpleLabel:"";
127 String otLabel2 = other.simpleLabel!=null?other.simpleLabel:"";
128 c = AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(myLabel2, otLabel2);
129 if ( c!=0 ) return c;
131 String mySid = groupId!=null?groupId:"";
132 String otSid = other.groupId!=null?other.groupId:"";
133 c = mySid.compareTo(otSid);
134 if ( c!=0 ) return c;
136 String myGiid = groupItemId!=null?groupItemId:"";
137 String otGiid = other.groupItemId!=null?other.groupItemId:"";
138 c = myGiid.compareTo(otGiid);
139 if ( c!=0 ) return c;
141 String myVid = variableId!=null?variableId:"";
142 String otVid = other.variableId!=null?other.variableId:"";
143 c = myVid.compareTo(otVid);
144 if ( c!=0 ) return c;