22package org .csstudio .display .extra .widgets .linearmeter ;
33
44import static org .csstudio .javafx .rtplot .Activator .logger ;
5+ import static org .csstudio .javafx .rtplot .internal .util .Log10 .log10 ;
56
67import java .awt .BasicStroke ;
78import java .awt .Canvas ;
@@ -91,7 +92,8 @@ public RTLinearMeter(double initialValue,
9192 Color needleColor ,
9293 int knobSize ,
9394 Color knobColor ,
94- boolean showWarnings )
95+ boolean showWarnings ,
96+ boolean logScale )
9597 {
9698 if (warningTriangle == null ) {
9799 try {
@@ -115,7 +117,8 @@ public RTLinearMeter(double initialValue,
115117 height ,
116118 isHorizontal ,
117119 min ,
118- max );
120+ max ,
121+ logScale );
119122
120123 this .minMaxTolerance = minMaxTolerance ;
121124 this .loLo = loLo ;
@@ -189,7 +192,8 @@ public void redrawLinearMeterScale() {
189192 linearMeterScale .getBounds ().height ,
190193 linearMeterScale .isHorizontal (),
191194 linearMeterScale .getValueRange ().getLow (),
192- linearMeterScale .getValueRange ().getHigh ());
195+ linearMeterScale .getValueRange ().getHigh (),
196+ linearMeterScale .isLogarithmic ());
193197 linearMeterScale .setHorizontal (isHorizontal );
194198 });
195199 }
@@ -295,6 +299,12 @@ public void setDisplayMode(DisplayMode newDisplayMode) {
295299
296300 private DisplayMode displayMode = DisplayMode .NEEDLE ;
297301
302+ public void setLogScale (boolean logScale ) {
303+ withWriteLock (() -> {
304+ linearMeterScale .setLogarithmic (logScale );
305+ });
306+ }
307+
298308 private void runOnJavaFXThread (Runnable runnable ) {
299309 if (Platform .isFxApplicationThread ()) {
300310 runnable .run ();
@@ -749,10 +759,20 @@ private Optional<Integer> computeIndicatorPosition(double value) {
749759 }
750760 return withReadLock (() -> {
751761 if (linearMeterScale .isHorizontal ()) {
752- 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 * (log10 (value ) - log10 (linearMeterScale .getValueRange ().getLow ()))));
764+ }
765+ else {
766+ return Optional .of ((int ) Math .round (marginLeft + pixelsPerScaleUnit * (value - linearMeterScale .getValueRange ().getLow ())));
767+ }
753768 }
754769 else {
755- 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 * (log10 (value ) - log10 (linearMeterScale .getValueRange ().getLow ()))));
772+ }
773+ else {
774+ return Optional .of ((int ) Math .round (linearMeterScale .getBounds ().height - marginBelow - pixelsPerScaleUnit * (value - linearMeterScale .getValueRange ().getLow ())));
775+ }
756776 }
757777 });
758778 }
@@ -1323,14 +1343,34 @@ private void layout() {
13231343 marginBelow += 1 + fontMetrics .getMaxAscent () + fontMetrics .getMaxDescent ();
13241344 }
13251345
1326- 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 ) / (log10 (linearMeterScale .getValueRange ().getHigh ()) - log10 (linearMeterScale .getValueRange ().getLow ()));
1348+ }
1349+ else {
1350+ pixelsPerScaleUnit = (linearMeterScale .getBounds ().width - marginLeft - marginRight - 1 ) / (linearMeterScale .getValueRange ().getHigh () - linearMeterScale .getValueRange ().getLow ());
1351+ }
13271352 meterBreadth = Math .round (linearMeterScale .getBounds ().height - marginAbove - marginBelow ) - 1 ;
13281353
1329- double x_loLoRectangle = marginLeft ;
1330- double x_lowRectangle = marginLeft + pixelsPerScaleUnit * (displayedLoLo - linearMeterScale .getValueRange ().getLow ());
1331- double x_normalRectangle = marginLeft + pixelsPerScaleUnit * (displayedLow - linearMeterScale .getValueRange ().getLow ());
1332- double x_highRectangle = marginLeft + pixelsPerScaleUnit * (displayedHigh - linearMeterScale .getValueRange ().getLow ());
1333- 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 * (log10 (displayedLoLo ) - log10 (linearMeterScale .getValueRange ().getLow ()));
1362+ x_normalRectangle = marginLeft + pixelsPerScaleUnit * (log10 (displayedLow ) - log10 (linearMeterScale .getValueRange ().getLow ()));
1363+ x_highRectangle = marginLeft + pixelsPerScaleUnit * (log10 (displayedHigh ) - log10 (linearMeterScale .getValueRange ().getLow ()));
1364+ x_hiHiRectangle = marginLeft + pixelsPerScaleUnit * (log10 (displayedHiHi ) - 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+ }
13341374
13351375 loLoRectangle = new Rectangle ((int ) Math .round (x_loLoRectangle ),
13361376 marginAbove ,
@@ -1352,9 +1392,16 @@ private void layout() {
13521392 (int ) (Math .round (x_hiHiRectangle ) - Math .round (x_highRectangle )),
13531393 meterBreadth );
13541394
1395+ int hihiWidth ;
1396+ if (linearMeterScale .isLogarithmic ()) {
1397+ hihiWidth = (int ) (Math .round (pixelsPerScaleUnit * (log10 (linearMeterScale .getValueRange ().getHigh ()) - log10 (displayedHiHi ))));
1398+ }
1399+ else {
1400+ hihiWidth = (int ) (Math .round (pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedHiHi )));
1401+ }
13551402 hiHiRectangle = new Rectangle ((int ) Math .round (x_hiHiRectangle ),
13561403 marginAbove ,
1357- ( int ) ( Math . round ( pixelsPerScaleUnit * ( linearMeterScale . getValueRange (). getHigh () - displayedHiHi ))) ,
1404+ hihiWidth ,
13581405 meterBreadth );
13591406 }
13601407 else {
@@ -1381,13 +1428,30 @@ private void layout() {
13811428 marginBelow += 1 + fontMetrics .getMaxAscent () + fontMetrics .getMaxDescent ();
13821429 }
13831430
1384- 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 ) / (log10 (linearMeterScale .getValueRange ().getHigh ()) - log10 (linearMeterScale .getValueRange ().getLow ()));
1433+ }
1434+ else {
1435+ pixelsPerScaleUnit = (linearMeterScale .getBounds ().height - marginAbove - marginBelow - 1 ) / (linearMeterScale .getValueRange ().getHigh () - linearMeterScale .getValueRange ().getLow ());
1436+ }
13851437 meterBreadth = Math .round (linearMeterScale .getBounds ().width - marginLeft - marginRight );
13861438
1387- double y_loLoRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedLoLo );
1388- double y_lowRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedLow );
1389- double y_normalRectangle = marginAbove + pixelsPerScaleUnit * (linearMeterScale .getValueRange ().getHigh () - displayedHigh );
1390- 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 * (log10 (linearMeterScale .getValueRange ().getHigh ()) - log10 (displayedLoLo ));
1445+ y_lowRectangle = marginAbove + pixelsPerScaleUnit * (log10 (linearMeterScale .getValueRange ().getHigh ()) - log10 (displayedLow ));
1446+ y_normalRectangle = marginAbove + pixelsPerScaleUnit * (log10 (linearMeterScale .getValueRange ().getHigh ()) - log10 (displayedHigh ));
1447+ y_highRectangle = marginAbove + pixelsPerScaleUnit * (log10 (linearMeterScale .getValueRange ().getHigh ()) - 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+ }
13911455
13921456 loLoRectangle = new Rectangle (marginLeft ,
13931457 (int ) Math .round (y_loLoRectangle ),
0 commit comments