View Javadoc

1   /* OpenLogViewer
2    *
3    * Copyright 2011
4    *
5    * This file is part of the OpenLogViewer project.
6    *
7    * OpenLogViewer software is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation, either version 3 of the License, or
10   * (at your option) any later version.
11   *
12   * OpenLogViewer software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with any OpenLogViewer software.  If not, see http://www.gnu.org/licenses/
19   *
20   * I ask that if you make any changes to this file you fork the code on github.com!
21   *
22   */
23  package org.diyefi.openlogviewer.propertypanel;
24  
25  import java.awt.Color;
26  import org.diyefi.openlogviewer.genericlog.GenericDataElement;
27  
28  public class SingleProperty implements Comparable<SingleProperty> {
29  	private Color color;
30  	private String header;
31  	private double min;
32  	private double max;
33  	private int trackIndex;
34  	private boolean active;
35  
36  	public SingleProperty() {
37  		color = Color.GRAY;
38  		header = "";
39  		min = 0;
40  		max = 0;
41  		trackIndex = 0;
42  		active = false;
43  	}
44  
45  	public SingleProperty(final GenericDataElement gde) {
46  		color = gde.getDisplayColor();
47  		header = gde.getName();
48  		min = gde.getDisplayMinValue();
49  		max = gde.getDisplayMaxValue();
50  		trackIndex = gde.getTrackIndex();
51  		active = false;
52  	}
53  
54  	public final Color getColor() {
55  		return color;
56  	}
57  
58  	public final void setColor(final Color color) {
59  		this.color = color;
60  	}
61  
62  	public final String getHeader() {
63  		return header;
64  	}
65  
66  	public final void setHeader(final String header) {
67  		this.header = header;
68  	}
69  
70  	public final double getMax() {
71  		return max;
72  	}
73  
74  	public final void setMax(final double max) {
75  		this.max = max;
76  	}
77  
78  	public final double getMin() {
79  		return min;
80  	}
81  
82  	public final void setMin(final double min) {
83  		this.min = min;
84  	}
85  
86  	public final int getTrackIndex() {
87  		return trackIndex;
88  	}
89  
90  	public final void setTrackIndex(final int newIndex) {
91  		if (newIndex < 0) {
92  			trackIndex = 0;
93  		} else {
94  			trackIndex = newIndex;
95  		}
96  	}
97  
98  	public final boolean isActive() {
99  		return active;
100 	}
101 
102 	public final void setActive(final boolean active) {
103 		this.active = active;
104 	}
105 
106 	public final String toString() {
107 		final String seperator = ",";
108 		final StringBuilder output = new StringBuilder(header);
109 		output.append("=");
110 		output.append(color.getRed());
111 		output.append(seperator);
112 		output.append(color.getGreen());
113 		output.append(seperator);
114 		output.append(color.getBlue());
115 		output.append(seperator);
116 		output.append(min);
117 		output.append(seperator);
118 		output.append(max);
119 		output.append(seperator);
120 		output.append(trackIndex);
121 		output.append(seperator);
122 		output.append(Boolean.toString(active));
123 		return output.toString();
124 	}
125 
126 	public final int compareTo(final SingleProperty sp) {
127 		return this.getHeader().compareToIgnoreCase(sp.getHeader());
128 	}
129 
130 	/*
131 	 * TODO investigate this further:
132 	 *
133 	 * In real use, this gets a SingleProperty passed in, which therefore means
134 	 * that we're comparing header with toString output, when toString is header
135 	 * concatenated with other fields. IE, it seems as though this is always
136 	 * false, however in my second round of testing, it never got called, so I
137 	 * just don't know.
138 	 */
139 	public final boolean equals(final String otherHeader) {
140 		return getHeader().equalsIgnoreCase(otherHeader);
141 	}
142 }