]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.trend/src/org/simantics/trend/configuration/TrendItem.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.trend / src / org / simantics / trend / configuration / TrendItem.java
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
7  *
8  * Contributors:
9  *     VTT Technical Research Centre of Finland - initial API and implementation
10  *******************************************************************************/
11 package org.simantics.trend.configuration;
12
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;
17
18 /**
19  * @author Toni Kalajainen
20  */
21 public class TrendItem extends Bean {
22         
23         // Sorting and color index
24         public int index;
25         
26         // Chart Label
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;
32         
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;
39         
40         public Scale scale;
41         
42         // TODO Rename Binary to Bar
43         public enum Renderer { Analog, Binary } public Renderer renderer;
44         
45         public @Optional String unit;
46         
47         public DrawMode drawMode = DrawMode.getDefault();
48
49         // If true, the item shall not be shown in the chart.
50         public boolean hidden = false;
51
52         // Defines a custom stroke to be used when rendering this item.
53         public @Optional Float customStrokeWidth;
54
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;
58
59         public enum DrawMode {
60                 DeviationAndLine,
61                 DeviationAndAverage,
62                 DeviationAndSample,
63                 Average,
64                 Line,
65                 Sample,
66                 Deviation;
67                 public static DrawMode getDefault() {
68                         return DeviationAndLine; 
69                 }
70         }
71         
72         public TrendItem() {
73         }
74
75         public TrendItem(int index, String label, String subscriptionId, String variableId, Scale scale) {
76                 this(index, label, subscriptionId, variableId, scale, Renderer.Analog);
77         }
78
79         public TrendItem(int index, String label, String subscriptionId, String variableId, Scale scale, Renderer renderer) {
80                 this.index = index;
81                 this.label = label;
82                 this.variableId = variableId;
83                 this.scale = scale;
84                 this.renderer = renderer;
85                 this.groupId = subscriptionId;
86                 this.groupItemId = variableId;
87         }       
88
89         public TrendItem(int index, String label, String subscriptionId, String variableId, Scale scale, Renderer renderer, double min, double max) {
90                 this.index = index;
91                 this.label = label;
92                 this.variableId = variableId;
93                 this.scale = new Scale.Manual(min, max);
94                 this.renderer = renderer;
95                 this.groupId = subscriptionId;
96                 this.groupItemId = variableId;
97         }
98         
99         public TrendItem(int index, String label, String subscriptionId, String variableId, Scale scale, Renderer renderer, double min, double max, DrawMode drawMode) {
100                 this.index = index;
101                 this.label = label;
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;
108         }
109         
110         @Override
111         public int compareTo(Bean o) {
112                 if ( o instanceof TrendItem == false ) return 0;
113                 TrendItem other = (TrendItem) o;
114                 
115                 int c = renderer.ordinal() - other.renderer.ordinal();
116                 if ( c!=0 ) return c;
117                 
118                 c = index - other.index;
119                 if ( c!=0 ) return c;
120                 
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;
125                 
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;
130                 
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;
135
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;
140
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;
145                 
146                 return c;               
147         }
148         
149 }
150