51
51
*/
52
52
53
53
public class JPruningBar extends JPanel implements MouseListener , MouseMotionListener {
54
- static final long serialVersionUID = 0x20070307 ;
54
+ private static final long serialVersionUID = 0x20070307 ;
55
55
56
56
private static final int cRedWaterRGB = Color .RED .getRGB ();
57
57
private static final int cBlueWaterRGB = 0x156be4 ;
@@ -60,9 +60,11 @@ public class JPruningBar extends JPanel implements MouseListener, MouseMotionLis
60
60
private static final int cBarWidth = cThumbSize - 2 * HiDPIHelper .scale (3 ); // even integer
61
61
private static final int cBorder = HiDPIHelper .scale (2 );
62
62
63
- private float [] mPosition ;
64
- private float mX1 ,mY1 ,mLowValue ,mMinValue ,mHighValue ,mMaxValue , mValuePerPixel ;
65
- private boolean mIsHorizontal ,mUpdateNeeded ,mUseRedColor ,mAllowDoubleClickChange ,mWasDragged ;
63
+ private final float [] mPosition ;
64
+ private float mX1 ,mY1 ;
65
+ private double mValuePerPixel ,mLowValue ,mMinValue ,mHighValue ,mMaxValue ;
66
+ private final boolean mIsHorizontal ,mAllowDoubleClickChange ;
67
+ private boolean mUpdateNeeded ,mUseRedColor ,mWasDragged ;
66
68
private int mID ,mMousePosition ,mClickedArea ,mActiveThumb ;
67
69
private ArrayList <PruningBarListener > mListener ;
68
70
@@ -78,11 +80,11 @@ public JPruningBar(boolean isHorizontal, int id) {
78
80
this (0 , 100 , isHorizontal , id , false );
79
81
}
80
82
81
- public JPruningBar (float min , float max , boolean isHorizontal , int id ) {
83
+ public JPruningBar (double min , double max , boolean isHorizontal , int id ) {
82
84
this (min , max , isHorizontal , id , false );
83
85
}
84
86
85
- public JPruningBar (float min , float max , boolean isHorizontal , int id , boolean allowDoubleClick ) {
87
+ public JPruningBar (double min , double max , boolean isHorizontal , int id , boolean allowDoubleClick ) {
86
88
init ();
87
89
mMinValue = min ;
88
90
mLowValue = min ;
@@ -131,15 +133,15 @@ public void paintComponent(Graphics g) {
131
133
g2D .fill (new Rectangle2D .Float (mX1 +(cThumbSize -cBarWidth )/2 , mY1 +cThumbSize -1 , cBarWidth , y2 -mY1 -2 *cThumbSize +2 ));
132
134
133
135
float zoomSpace = (mIsHorizontal ? x2 -mX1 : y2 -mY1 ) - 2 * cThumbSize ;
134
- float valueSpace = mMaxValue - mMinValue ;
136
+ double valueSpace = mMaxValue - mMinValue ;
135
137
mValuePerPixel = valueSpace / zoomSpace ;
136
138
if (mIsHorizontal ) {
137
- mPosition [0 ] = (mLowValue - mMinValue ) / mValuePerPixel ;
138
- mPosition [1 ] = (mHighValue - mMinValue ) / mValuePerPixel ;
139
+ mPosition [0 ] = (float )(( mLowValue - mMinValue ) / mValuePerPixel ) ;
140
+ mPosition [1 ] = (float )(( mHighValue - mMinValue ) / mValuePerPixel ) ;
139
141
}
140
142
else { // tribute to inverted Y-scale in java
141
- mPosition [0 ] = (mMaxValue - mHighValue ) / mValuePerPixel ;
142
- mPosition [1 ] = (mMaxValue - mLowValue ) / mValuePerPixel ;
143
+ mPosition [0 ] = (float )(( mMaxValue - mHighValue ) / mValuePerPixel ) ;
144
+ mPosition [1 ] = (float )(( mMaxValue - mLowValue ) / mValuePerPixel ) ;
143
145
}
144
146
145
147
int rgb = mUseRedColor ? cRedWaterRGB : HeaderPaintHelper .getThemeColors () == null ? cBlueWaterRGB : HeaderPaintHelper .getThemeColors ()[0 ];
@@ -196,19 +198,19 @@ public void update(Graphics g) {
196
198
paint (g );
197
199
}
198
200
199
- public float getLowValue () {
201
+ public double getLowValue () {
200
202
return mLowValue ;
201
203
}
202
204
203
- public float getHighValue () {
205
+ public double getHighValue () {
204
206
return mHighValue ;
205
207
}
206
208
207
- public float getMaximumValue () {
209
+ public double getMaximumValue () {
208
210
return mMaxValue ;
209
211
}
210
212
211
- public float getMinimumValue () {
213
+ public double getMinimumValue () {
212
214
return mMinValue ;
213
215
}
214
216
@@ -234,7 +236,7 @@ public void reset() {
234
236
* @param high
235
237
* @param silent if true, PruningBarEvents are suppressed
236
238
*/
237
- public void setLowAndHigh (float low , float high , boolean silent ) {
239
+ public void setLowAndHigh (double low , double high , boolean silent ) {
238
240
if (low < mMinValue )
239
241
low = mMinValue ;
240
242
if (high > mMaxValue )
@@ -255,7 +257,7 @@ public void setLowAndHigh(float low, float high, boolean silent) {
255
257
* Sends PruningBarEvents in case of a successful change.
256
258
* @param low
257
259
*/
258
- public void setLowValue (float low ) {
260
+ public void setLowValue (double low ) {
259
261
if (setLow (low )) {
260
262
informListeners (false );
261
263
mUpdateNeeded = true ;
@@ -272,7 +274,7 @@ public void setID(int id) {
272
274
* Sends PruningBarEvents in case of a successful change.
273
275
* @param high
274
276
*/
275
- public void setHighValue (float high ) {
277
+ public void setHighValue (double high ) {
276
278
if (setHigh (high )) {
277
279
informListeners (false );
278
280
mUpdateNeeded = true ;
@@ -285,7 +287,7 @@ public void setHighValue(float high) {
285
287
* Sends PruningBarEvents in case of a successful change.
286
288
* @param max
287
289
*/
288
- public void setMaximumValue (float max ) {
290
+ public void setMaximumValue (double max ) {
289
291
if (max < mMinValue )
290
292
max = mMinValue ;
291
293
@@ -307,7 +309,7 @@ public void setMaximumValue(float max) {
307
309
* Sends PruningBarEvents in case of a successful change.
308
310
* @param min
309
311
*/
310
- public void setMinimumValue (float min ) {
312
+ public void setMinimumValue (double min ) {
311
313
// changes the allowed min value; may update low and high to stay within limits
312
314
if (min > mMaxValue )
313
315
min = mMaxValue ;
@@ -331,7 +333,7 @@ public void setMinimumValue(float min) {
331
333
* @param min
332
334
* @param max
333
335
*/
334
- public void setMinAndMax (float min , float max ) {
336
+ public void setMinAndMax (double min , double max ) {
335
337
mLowValue = mMinValue = min ;
336
338
mHighValue = mMaxValue = max ;
337
339
mUpdateNeeded = true ;
@@ -450,7 +452,7 @@ public synchronized void mouseDragged(MouseEvent e) {
450
452
451
453
mWasDragged = true ;
452
454
453
- float change = mValuePerPixel * ( float ) (position - mMousePosition );
455
+ double change = mValuePerPixel * (position - mMousePosition );
454
456
if (!mIsHorizontal ) // tribute to inverted Y-scale in java
455
457
change = -change ;
456
458
if (e .isControlDown ())
@@ -543,7 +545,7 @@ private void init() {
543
545
mListener = new ArrayList <>();
544
546
}
545
547
546
- private boolean setHigh (float value ) {
548
+ private boolean setHigh (double value ) {
547
549
if (value < mLowValue )
548
550
value = mLowValue ;
549
551
else if (value > mMaxValue )
@@ -556,7 +558,7 @@ else if (value > mMaxValue)
556
558
return true ;
557
559
}
558
560
559
- private boolean setLow (float value ) {
561
+ private boolean setLow (double value ) {
560
562
if (value < mMinValue )
561
563
value = mMinValue ;
562
564
else if (value > mHighValue )
@@ -569,7 +571,7 @@ else if (value > mHighValue)
569
571
return true ;
570
572
}
571
573
572
- private void informListeners (float low , float high ) {
574
+ private void informListeners (double low , double high ) {
573
575
for (int i =0 ; i <mListener .size (); i ++)
574
576
mListener .get (i ).pruningBarChanged (
575
577
new PruningBarEvent (this , low , high , false , mID , PruningBarEvent .TYPE_TYPED ));
0 commit comments