@@ -116,7 +116,8 @@ public RTLinearMeter(double initialValue,
116116 height ,
117117 isHorizontal ,
118118 min ,
119- max );
119+ max ,
120+ logScale );
120121
121122 this .minMaxTolerance = minMaxTolerance ;
122123 this .loLo = loLo ;
@@ -190,7 +191,8 @@ public void redrawLinearMeterScale() {
190191 linearMeterScale .getBounds ().height ,
191192 linearMeterScale .isHorizontal (),
192193 linearMeterScale .getValueRange ().getLow (),
193- linearMeterScale .getValueRange ().getHigh ());
194+ linearMeterScale .getValueRange ().getHigh (),
195+ linearMeterScale .isLogarithmic ());
194196 linearMeterScale .setHorizontal (isHorizontal );
195197 });
196198 }
@@ -296,6 +298,13 @@ public void setDisplayMode(DisplayMode newDisplayMode) {
296298
297299 private DisplayMode displayMode = DisplayMode .NEEDLE ;
298300
301+ public void setLogScale (boolean logScale ) {
302+ withWriteLock (() -> {
303+ linearMeterScale .setLogarithmic (true );
304+ redraw ();
305+ });
306+ }
307+
299308 private void runOnJavaFXThread (Runnable runnable ) {
300309 if (Platform .isFxApplicationThread ()) {
301310 runnable .run ();
@@ -750,10 +759,20 @@ private Optional<Integer> computeIndicatorPosition(double value) {
750759 }
751760 return withReadLock (() -> {
752761 if (linearMeterScale .isHorizontal ()) {
753- return Optional .of ((int ) Math .round (marginLeft + pixelsPerScaleUnit * (value - linearMeterScale .getValueRange ().getLow ())));
762+ if (linearMeterScale .isLogarithmic ()) {
763+ return Optional .of ((int ) Math .round (marginLeft + pixelsPerScaleUnit * (Math .log10 (value ) - Math .log10 (linearMeterScale .getValueRange ().getLow ()))));
764+ }
765+ else {
766+ return Optional .of ((int ) Math .round (marginLeft + pixelsPerScaleUnit * (value - linearMeterScale .getValueRange ().getLow ())));
767+ }
754768 }
755769 else {
756- return Optional .of ((int ) Math .round (linearMeterScale .getBounds ().height - marginBelow - pixelsPerScaleUnit * (value - linearMeterScale .getValueRange ().getLow ())));
770+ if (linearMeterScale .isLogarithmic ()) {
771+ return Optional .of ((int ) Math .round (linearMeterScale .getBounds ().height - marginBelow - pixelsPerScaleUnit * (Math .log10 (value ) - Math .log10 (linearMeterScale .getValueRange ().getLow ()))));
772+ }
773+ else {
774+ return Optional .of ((int ) Math .round (linearMeterScale .getBounds ().height - marginBelow - pixelsPerScaleUnit * (value - linearMeterScale .getValueRange ().getLow ())));
775+ }
757776 }
758777 });
759778 }
@@ -1324,14 +1343,34 @@ private void layout() {
13241343 marginBelow += 1 + fontMetrics .getMaxAscent () + fontMetrics .getMaxDescent ();
13251344 }
13261345
1327- pixelsPerScaleUnit = (linearMeterScale .getBounds ().width - marginLeft - marginRight - 1 ) / (linearMeterScale .getValueRange ().getHigh () - linearMeterScale .getValueRange ().getLow ());
1346+ if (linearMeterScale .isLogarithmic ()) {
1347+ pixelsPerScaleUnit = (linearMeterScale .getBounds ().width - marginLeft - marginRight - 1 ) / (Math .log10 (linearMeterScale .getValueRange ().getHigh ()) - Math .log10 (linearMeterScale .getValueRange ().getLow ()));
1348+ }
1349+ else {
1350+ pixelsPerScaleUnit = (linearMeterScale .getBounds ().width - marginLeft - marginRight - 1 ) / (linearMeterScale .getValueRange ().getHigh () - linearMeterScale .getValueRange ().getLow ());
1351+ }
13281352 meterBreadth = Math .round (linearMeterScale .getBounds ().height - marginAbove - marginBelow ) - 1 ;
13291353
1330- double x_loLoRectangle = marginLeft ;
1331- double x_lowRectangle = marginLeft + pixelsPerScaleUnit * (displayedLoLo - linearMeterScale .getValueRange ().getLow ());
1332- double x_normalRectangle = marginLeft + pixelsPerScaleUnit * (displayedLow - linearMeterScale .getValueRange ().getLow ());
1333- double x_highRectangle = marginLeft + pixelsPerScaleUnit * (displayedHigh - linearMeterScale .getValueRange ().getLow ());
1334- double x_hiHiRectangle = marginLeft + pixelsPerScaleUnit * (displayedHiHi - linearMeterScale .getValueRange ().getLow ());
1354+ double x_loLoRectangle ;
1355+ double x_lowRectangle ;
1356+ double x_normalRectangle ;
1357+ double x_highRectangle ;
1358+ double x_hiHiRectangle ;
1359+ if (linearMeterScale .isLogarithmic ()) {
1360+ x_loLoRectangle = marginLeft ;
1361+ x_lowRectangle = marginLeft + pixelsPerScaleUnit * (Math .log10 (displayedLoLo ) - Math .log10 (linearMeterScale .getValueRange ().getLow ()));
1362+ x_normalRectangle = marginLeft + pixelsPerScaleUnit * (Math .log10 (displayedLow ) - Math .log10 (linearMeterScale .getValueRange ().getLow ()));
1363+ x_highRectangle = marginLeft + pixelsPerScaleUnit * (Math .log10 (displayedHigh ) - Math .log10 (linearMeterScale .getValueRange ().getLow ()));
1364+ x_hiHiRectangle = marginLeft + pixelsPerScaleUnit * (Math .log10 (displayedHiHi ) - Math .log10 (linearMeterScale .getValueRange ().getLow ()));
1365+ }
1366+ else {
1367+ x_loLoRectangle = marginLeft ;
1368+ x_lowRectangle = marginLeft + pixelsPerScaleUnit * (displayedLoLo - linearMeterScale .getValueRange ().getLow ());
1369+ x_normalRectangle = marginLeft + pixelsPerScaleUnit * (displayedLow - linearMeterScale .getValueRange ().getLow ());
1370+ x_highRectangle = marginLeft + pixelsPerScaleUnit * (displayedHigh - linearMeterScale .getValueRange ().getLow ());
1371+ x_hiHiRectangle = marginLeft + pixelsPerScaleUnit * (displayedHiHi - linearMeterScale .getValueRange ().getLow ());
1372+
1373+ }
13351374
13361375 loLoRectangle = new Rectangle ((int ) Math .round (x_loLoRectangle ),
13371376 marginAbove ,
@@ -1353,9 +1392,16 @@ private void layout() {
13531392 (int ) (Math .round (x_hiHiRectangle ) - Math .round (x_highRectangle )),
13541393 meterBreadth );
13551394
1395+ int hihiWidth ;
1396+ if (linearMeterScale .isLogarithmic ()) {
1397+ hihiWidth = (int ) (Math .round (pixelsPerScaleUnit * (Math .log10 (linearMeterScale .getValueRange ().getHigh ()) - Math .log10 (displayedHiHi ))));
1398+ }
1399+ else {
1400+ hihiWidth = (int ) (Math .round (pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedHiHi )));
1401+ }
13561402 hiHiRectangle = new Rectangle ((int ) Math .round (x_hiHiRectangle ),
13571403 marginAbove ,
1358- ( int ) ( Math . round ( pixelsPerScaleUnit * ( linearMeterScale . getValueRange (). getHigh () - displayedHiHi ))) ,
1404+ hihiWidth ,
13591405 meterBreadth );
13601406 }
13611407 else {
@@ -1382,13 +1428,30 @@ private void layout() {
13821428 marginBelow += 1 + fontMetrics .getMaxAscent () + fontMetrics .getMaxDescent ();
13831429 }
13841430
1385- pixelsPerScaleUnit = (linearMeterScale .getBounds ().height - marginAbove - marginBelow - 1 ) / (linearMeterScale .getValueRange ().getHigh () - linearMeterScale .getValueRange ().getLow ());
1431+ if (linearMeterScale .isLogarithmic ()) {
1432+ pixelsPerScaleUnit = (linearMeterScale .getBounds ().height - marginAbove - marginBelow - 1 ) / (Math .log10 (linearMeterScale .getValueRange ().getHigh ()) - Math .log10 (linearMeterScale .getValueRange ().getLow ()));
1433+ }
1434+ else {
1435+ pixelsPerScaleUnit = (linearMeterScale .getBounds ().height - marginAbove - marginBelow - 1 ) / (linearMeterScale .getValueRange ().getHigh () - linearMeterScale .getValueRange ().getLow ());
1436+ }
13861437 meterBreadth = Math .round (linearMeterScale .getBounds ().width - marginLeft - marginRight );
13871438
1388- double y_loLoRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedLoLo );
1389- double y_lowRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedLow );
1390- double y_normalRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedHigh );
1391- double y_highRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedHiHi );
1439+ double y_loLoRectangle ;
1440+ double y_lowRectangle ;
1441+ double y_normalRectangle ;
1442+ double y_highRectangle ;
1443+ if (linearMeterScale .isLogarithmic ()) {
1444+ y_loLoRectangle = marginAbove + pixelsPerScaleUnit * (Math .log10 (linearMeterScale .getValueRange ().getHigh ()) - Math .log10 (displayedLoLo ));
1445+ y_lowRectangle = marginAbove + pixelsPerScaleUnit * (Math .log10 (linearMeterScale .getValueRange ().getHigh ()) - Math .log10 (displayedLow ));
1446+ y_normalRectangle = marginAbove + pixelsPerScaleUnit * (Math .log10 (linearMeterScale .getValueRange ().getHigh ()) - Math .log10 (displayedHigh ));
1447+ y_highRectangle = marginAbove + pixelsPerScaleUnit * (Math .log10 (linearMeterScale .getValueRange ().getHigh ()) - Math .log10 (displayedHiHi ));
1448+ }
1449+ else {
1450+ y_loLoRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedLoLo );
1451+ y_lowRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedLow );
1452+ y_normalRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedHigh );
1453+ y_highRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedHiHi );
1454+ }
13921455
13931456 loLoRectangle = new Rectangle (marginLeft ,
13941457 (int ) Math .round (y_loLoRectangle ),
0 commit comments