mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 14:37:13 -06:00
FlatSmoothScrollingTest: paint "temporary" scrollbar values in line chart using a lighter color
This commit is contained in:
@@ -350,7 +350,7 @@ public class FlatSmoothScrollingTest
|
||||
private final String name;
|
||||
private final Color chartColor;
|
||||
private int count;
|
||||
private long lastTime;
|
||||
private long lastTime = System.nanoTime() / 1000000;
|
||||
|
||||
ScrollBarChangeHandler( String name, Color chartColor ) {
|
||||
this.name = name;
|
||||
@@ -416,6 +416,12 @@ public class FlatSmoothScrollingTest
|
||||
this.value = value;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// for debugging
|
||||
return String.valueOf( value );
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<Color, List<Data>> color2dataMap = new HashMap<>();
|
||||
@@ -506,6 +512,7 @@ public class FlatSmoothScrollingTest
|
||||
for( Map.Entry<Color, List<Data>> e : color2dataMap.entrySet() ) {
|
||||
Color chartColor = e.getKey();
|
||||
List<Data> chartData = e.getValue();
|
||||
Color temporaryValueColor = new Color( (chartColor.getRGB() & 0xffffff) | 0x40000000, true );
|
||||
|
||||
long seqTime = 0;
|
||||
int seqX = 0;
|
||||
@@ -531,11 +538,18 @@ public class FlatSmoothScrollingTest
|
||||
px = seqX;
|
||||
pcount = 0;
|
||||
} else {
|
||||
boolean isTemporaryValue = isTemporaryValue( chartData, i ) || isTemporaryValue( chartData, i - 1 );
|
||||
if( isTemporaryValue )
|
||||
g.setColor( temporaryValueColor );
|
||||
|
||||
// line in sequence
|
||||
int dx = (int) (seqX + (((data.time - seqTime) / 1000.) * secondWidth));
|
||||
g.drawLine( px, py, dx, dy );
|
||||
px = dx;
|
||||
pcount++;
|
||||
|
||||
if( isTemporaryValue )
|
||||
g.setColor( chartColor );
|
||||
}
|
||||
|
||||
py = dy;
|
||||
@@ -544,6 +558,13 @@ public class FlatSmoothScrollingTest
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTemporaryValue( List<Data> chartData, int i ) {
|
||||
if( i == 0 || i == chartData.size() - 1 )
|
||||
return false;
|
||||
|
||||
return chartData.get( i - 1 ).value == chartData.get( i + 1 ).value;
|
||||
}
|
||||
|
||||
private int chartWidth() {
|
||||
int width = 0;
|
||||
for( List<Data> chartData : color2dataMap.values() )
|
||||
|
||||
Reference in New Issue
Block a user