Permalink
Browse files

Changed method naming in unit utility classes. Removed some redundanc…

…y in its API.
  • Loading branch information...
1 parent 7791f0c commit a3bb93fccd36e3e1d1c0c589efff17ce2780c82d @jawi committed Feb 27, 2012
Showing with 478 additions and 413 deletions.
  1. +0 −5 api/pom.xml
  2. +59 −19 api/src/main/java/nl/lxtreme/ols/api/util/FrequencyUnit.java
  3. +56 −18 api/src/main/java/nl/lxtreme/ols/api/util/SizeUnit.java
  4. +62 −29 api/src/main/java/nl/lxtreme/ols/api/util/UnitOfTime.java
  5. +73 −0 api/src/test/java/nl/lxtreme/ols/api/util/FrequencyUnitTest.java
  6. +48 −0 api/src/test/java/nl/lxtreme/ols/api/util/SizeUnitTest.java
  7. +78 −0 api/src/test/java/nl/lxtreme/ols/api/util/UnitOfTimeTest.java
  8. +1 −1 client/src/main/java/nl/lxtreme/ols/client/ClientController.java
  9. +30 −2 client/src/main/java/nl/lxtreme/ols/client/action/GotoNthCursorAction.java
  10. +2 −2 client/src/main/java/nl/lxtreme/ols/client/diagram/laf/DiagramTimeLineUI.java
  11. +3 −3 client/src/main/java/nl/lxtreme/ols/client/diagram/laf/DiagramUI.java
  12. +2 −2 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/MeasurementInfo.java
  13. +1 −1 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/SignalDiagramComponent.java
  14. +5 −17 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/laf/TimeLineUI.java
  15. +2 −2 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/model/AbstractViewModel.java
  16. +2 −2 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/model/SignalDiagramModel.java
  17. +4 −4 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/view/CaptureDetailsView.java
  18. +1 −1 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/view/CursorDetailsView.java
  19. +2 −2 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/view/MeasurementView.java
  20. +2 −2 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/view/SignalDetailsView.java
  21. +1 −1 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/view/TimeLineView.java
  22. +2 −2 device.logicsniffer/src/main/java/org/sump/device/logicsniffer/LogicSnifferConfigDialog.java
  23. +6 −0 test.util/pom.xml
  24. +3 −2 tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireAnalyserDialog.java
  25. +1 −1 tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireAnalyserTask.java
  26. +0 −13 tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireDataSet.java
  27. +0 −13 tool.asm45/src/main/java/nl/lxtreme/ols/tool/asm45/Asm45DataSet.java
  28. +0 −13 tool.i2c/src/main/java/nl/lxtreme/ols/tool/i2c/I2CDataSet.java
  29. +5 −4 tool.i2c/src/main/java/nl/lxtreme/ols/tool/i2c/I2CProtocolAnalysisDialog.java
  30. +0 −13 tool.jtag/src/main/java/nl/lxtreme/ols/tool/jtag/JTAGDataSet.java
  31. +8 −7 tool.jtag/src/main/java/nl/lxtreme/ols/tool/jtag/JTAGProtocolAnalysisDialog.java
  32. +4 −5 tool.measure/src/main/java/nl/lxtreme/ols/tool/measure/ClockFrequencyMeasureTask.java
  33. +5 −6 tool.measure/src/main/java/nl/lxtreme/ols/tool/measure/MeasurementDialog.java
  34. +0 −13 tool.spi/src/main/java/nl/lxtreme/ols/tool/spi/SPIDataSet.java
  35. +5 −4 tool.spi/src/main/java/nl/lxtreme/ols/tool/spi/SPIProtocolAnalysisDialog.java
  36. +0 −13 tool.uart/src/main/java/nl/lxtreme/ols/tool/uart/UARTDataSet.java
  37. +5 −4 tool.uart/src/main/java/nl/lxtreme/ols/tool/uart/UARTProtocolAnalysisDialog.java
  38. +0 −85 util/src/main/java/nl/lxtreme/ols/util/DisplayUtils.java
  39. +0 −102 util/src/test/java/nl/lxtreme/ols/util/DisplayUtilsTest.java
View
5 api/pom.xml
@@ -16,11 +16,6 @@
<artifactId>org.osgi.compendium</artifactId>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>nl.lxtreme.ols</groupId>
- <artifactId>util</artifactId>
- <scope>compile</scope>
- </dependency>
<dependency>
<groupId>junit</groupId>
View
78 api/src/main/java/nl/lxtreme/ols/api/util/FrequencyUnit.java
@@ -23,22 +23,34 @@
/**
* Represents a frequency unit that has a displayable representation and a scale
- * factor.
+ * factor to convert it from/to Hertz.
*/
public enum FrequencyUnit
{
// CONSTANTS
- HZ( "", 1.0 ), //
- KHZ( "k", 1.0e3 ), //
- MHZ( "M", 1.0e6 ), //
- GHZ( "G", 1.0e9 ), //
- THZ( "T", 1.0e12 ); //
+ /** millihertz. */
+ MiHZ( "m", 1.0e-3 ),
+ /** hertz. */
+ HZ( "", 1.0 ),
+ /** kilohertz. */
+ KHZ( "k", 1.0e3 ),
+ /** megahertz. */
+ MHZ( "M", 1.0e6 ),
+ /** gigahertz. */
+ GHZ( "G", 1.0e9 ),
+ /** terahertz. */
+ THZ( "T", 1.0e12 );
+
+ /** Constant used to determine whether we should show "0Hz". */
+ public static final double ZERO_THRESHOLD = 1.0e-5;
+ /** All units are in Hertz. */
+ private static final String BASE_UNIT = "Hz";
// VARIABLES
- private String displayName;
- private double factor;
+ private final String displayName;
+ private final double factor;
// CONSTRUCTORS
@@ -47,7 +59,7 @@
*/
private FrequencyUnit( final String aPrefix, final double aFactor )
{
- this.displayName = aPrefix.concat( "Hz" );
+ this.displayName = aPrefix.concat( BASE_UNIT );
this.factor = aFactor;
}
@@ -56,17 +68,19 @@ private FrequencyUnit( final String aPrefix, final double aFactor )
/**
* Convenience method to directly get a displayable represention of a given
* frequency.
+ * <p>
+ * This method does the same as calling:
+ * <code>toUnit( aFrequency ).format( aFrequency, 3 );</code>.
+ * </p>
*
* @param aFrequency
* the frequency to get a displayable representation for.
* @return a string representation of the given frequency, never
* <code>null</code>.
*/
- public static String toString( final double aFrequency )
+ public static String format( final double aFrequency )
{
- final FrequencyUnit unit = valueOf( aFrequency );
- final Double f = Double.valueOf( aFrequency / unit.getFactor() );
- return String.format( "%.3f%s", f, unit.getDisplayName() );
+ return toUnit( aFrequency ).format( aFrequency, 3 );
}
/**
@@ -76,14 +90,15 @@ public static String toString( final double aFrequency )
* the frequency to convert to a {@link FrequencyUnit}.
* @return a {@link FrequencyUnit} instance, never <code>null</code>.
*/
- public static FrequencyUnit valueOf( final double aFrequency )
+ public static FrequencyUnit toUnit( final double aFrequency )
{
final FrequencyUnit[] freqs = values();
+ final double frequency = Math.abs( aFrequency );
int i = freqs.length - 1;
for ( ; i >= 0; i-- )
{
- if ( aFrequency >= freqs[i].getFactor() )
+ if ( frequency >= freqs[i].getFactor() )
{
break;
}
@@ -93,19 +108,44 @@ public static FrequencyUnit valueOf( final double aFrequency )
}
/**
- * Returns the current value of displayName.
+ * Returns the given frequency as string representation using this frequency
+ * unit's display name.
+ *
+ * @param aFrequency
+ * the frequency to convert to a string representation;
+ * @param aScale
+ * the scale (= number of digits after decimal separator) to use in
+ * the string representation.
+ * @return a string representation of the given frequency, like "1.234kHz",
+ * never <code>null</code>.
+ */
+ public String format( final double aFrequency, final int aScale )
+ {
+ // For *very* small frequencies, we simply always yield zero...
+ if ( ( Math.abs( aFrequency ) < ZERO_THRESHOLD ) && ( this != HZ ) )
+ {
+ return HZ.format( 0.0, aScale );
+ }
+
+ final Double frequency = Double.valueOf( aFrequency / getFactor() );
+ final String format = String.format( "%%.%df%%s", Integer.valueOf( aScale ) );
+ return String.format( format, frequency, getDisplayName() );
+ }
+
+ /**
+ * Returns display name of this frequency unit, like "Hz" or "MHz".
*
- * @return the displayName
+ * @return a display name, never <code>null</code>.
*/
public String getDisplayName()
{
return this.displayName;
}
/**
- * Returns the current value of factor.
+ * Returns the scale factor to get from Hertz to this frequency unit.
*
- * @return the factor
+ * @return a scale factor, >= 1.0.
*/
public double getFactor()
{
View
74 api/src/main/java/nl/lxtreme/ols/api/util/SizeUnit.java
@@ -29,16 +29,26 @@
{
// CONSTANTS
- B( "", 1.0 ), //
- KB( "k", 1024.0 ), //
- MB( "M", 1048576.0 ), //
- GB( "G", 1073741824.0 ), //
- TB( "T", 1099511627776.0 ); //
+ /** bytes. */
+ B( "", 1.0 ),
+ /** kilobytes. */
+ KB( "k", 1024.0 ),
+ /** megabytes. */
+ MB( "M", 1048576.0 ),
+ /** gigabytes. */
+ GB( "G", 1073741824.0 ),
+ /** terabytes. */
+ TB( "T", 1099511627776.0 );
+
+ /** Constant used to determine whether we should show "0B". */
+ public static final double ZERO_THRESHOLD = 1.0e-1;
+ /** All units are in bytes. */
+ private static final String BASE_UNIT = "B";
// VARIABLES
- private String displayName;
- private double factor;
+ private final String displayName;
+ private final double factor;
// CONSTRUCTORS
@@ -47,25 +57,27 @@
*/
private SizeUnit( final String aPrefix, final double aFactor )
{
- this.displayName = aPrefix.concat( "B" );
+ this.displayName = aPrefix.concat( BASE_UNIT );
this.factor = aFactor;
}
// METHODS
/**
- * Convenience method to convert a given size to a displayable representation.
+ * Convenience method to directly get a displayable represention of a given
+ * size.
+ * <p>
+ * This method does the same as calling:
+ * <code>toUnit( aSize ).format( aSize, 2 );</code>.
+ * </p>
*
* @param aSize
- * the size to convert to a displayable representation.
- * @return a displayable representation of the given size, never
- * <code>null</code>.
+ * the size to get a displayable representation for.
+ * @return a string representation of the given size, never <code>null</code>.
*/
- public static String toString( final double aSize )
+ public static String format( final double aSize )
{
- SizeUnit unit = valueOf( aSize );
- final Double s = Double.valueOf( aSize / unit.getFactor() );
- return String.format( "%.3f%s", s, unit.getDisplayName() );
+ return toUnit( aSize ).format( aSize, 2 );
}
/**
@@ -75,14 +87,15 @@ public static String toString( final double aSize )
* the size to convert to a {@link SizeUnit} instance.
* @return a {@link SizeUnit} instance, never <code>null</code>.
*/
- public static SizeUnit valueOf( final double aSize )
+ public static SizeUnit toUnit( final double aSize )
{
SizeUnit[] sizes = values();
+ double size = Math.abs( aSize );
int i = sizes.length - 1;
for ( ; i >= 0; i-- )
{
- if ( aSize >= sizes[i].getFactor() )
+ if ( size >= sizes[i].getFactor() )
{
break;
}
@@ -92,6 +105,31 @@ public static SizeUnit valueOf( final double aSize )
}
/**
+ * Returns the given size as string representation using this size unit's
+ * display name.
+ *
+ * @param aSize
+ * the size to convert to a string representation;
+ * @param aScale
+ * the scale (= number of digits after decimal separator) to use in
+ * the string representation.
+ * @return a string representation of the given size, like "1.44MB", never
+ * <code>null</code>.
+ */
+ public String format( final double aSize, final int aScale )
+ {
+ // For *very* small sizes, we simply always yield zero...
+ if ( ( Math.abs( aSize ) < ZERO_THRESHOLD ) && ( this != B ) )
+ {
+ return B.format( 0.0, aScale );
+ }
+
+ final Double size = Double.valueOf( aSize / getFactor() );
+ final String format = String.format( "%%.%df%%s", Integer.valueOf( aScale ) );
+ return String.format( format, size, getDisplayName() );
+ }
+
+ /**
* Returns the current value of displayName.
*
* @return the displayName
View
91 api/src/main/java/nl/lxtreme/ols/api/util/UnitOfTime.java
@@ -28,22 +28,28 @@
{
// CONSTANTS
- S( "", 1.0 ), //
- MS( "m", 1.0e-3 ), //
- US( "\u03BC", 1.0e-6 ), //
- NS( "n", 1.0e-9 ), //
- PS( "p", 1.0e-12 ), //
- FS( "f", 1.0e-15 ); //
-
- /**
- * Constant used to determine whether we should show "0.000 s".
- */
- public static final double ZERO_TIME_THRESHOLD = 1.0e-16;
+ /** seconds. */
+ S( "", 1.0 ),
+ /** milliseconds. */
+ MS( "m", 1.0e-3 ),
+ /** microseconds. */
+ US( "\u03BC", 1.0e-6 ),
+ /** nanoseconds. */
+ NS( "n", 1.0e-9 ),
+ /** picoseconds. */
+ PS( "p", 1.0e-12 ),
+ /** femtoseconds. */
+ FS( "f", 1.0e-15 );
+
+ /** Constant used to determine whether we should show "0.000 s". */
+ public static final double ZERO_THRESHOLD = 1.0e-16;
+ /** All units are in seconds. */
+ private static final String BASE_UNIT = "s";
// VARIABLES
- private String displayName;
- private double factor;
+ private final String displayName;
+ private final double factor;
// CONSTRUCTORS
@@ -52,23 +58,28 @@
*/
private UnitOfTime( final String aPrefix, final double aFactor )
{
- this.displayName = aPrefix.concat( "s" );
+ this.displayName = aPrefix.concat( BASE_UNIT );
this.factor = aFactor;
}
// METHODS
/**
- * @param aTimeValue
- * the time value to convert to a displayable representation.
- * @return a displayable representation of the given time value, never
- * <code>null</code>.
+ * Convenience method to directly get a displayable represention of a given
+ * time value.
+ * <p>
+ * This method does the same as calling:
+ * <code>toUnit( aTime ).format( aTime, 3 );</code>.
+ * </p>
+ *
+ * @param aTime
+ * the time value (in seconds) to get a displayable representation
+ * for.
+ * @return a string representation of the given time, never <code>null</code>.
*/
- public static String toString( final double aTimeValue )
+ public static String format( final double aTime )
{
- UnitOfTime unit = valueOf( aTimeValue );
- Double t = Double.valueOf( aTimeValue / unit.getFactor() );
- return String.format( "%.3f%s", t, unit.getDisplayName() );
+ return toUnit( aTime ).format( aTime, 2 );
}
/**
@@ -79,27 +90,49 @@ public static String toString( final double aTimeValue )
* the time value (in seconds) to return the unit of time for.
* @return a {@link UnitOfTime}, never <code>null</code>.
*/
- public static UnitOfTime valueOf( final double aTimeValue )
+ public static UnitOfTime toUnit( final double aTimeValue )
{
double absTime = Math.abs( aTimeValue );
final UnitOfTime[] values = values();
int i = 0;
- if ( absTime > ZERO_TIME_THRESHOLD )
+ for ( ; i < values.length; i++ )
{
- for ( ; i < values.length; i++ )
+ if ( absTime >= values[i].getFactor() )
{
- if ( absTime >= values[i].getFactor() )
- {
- break;
- }
+ break;
}
}
return values[Math.min( i, values.length - 1 )];
}
/**
+ * Returns the given time as string representation using this time unit's
+ * display name.
+ *
+ * @param aTime
+ * the time (in seconds) to convert to a string representation;
+ * @param aScale
+ * the scale (= number of digits after decimal separator) to use in
+ * the string representation.
+ * @return a string representation of the given time, like "1.453ms", never
+ * <code>null</code>.
+ */
+ public String format( final double aTime, final int aScale )
+ {
+ // For *very* small sizes, we simply always yield zero...
+ if ( ( Math.abs( aTime ) < ZERO_THRESHOLD ) && ( this != S ) )
+ {
+ return S.format( 0.0, aScale );
+ }
+
+ final Double time = Double.valueOf( aTime / getFactor() );
+ final String format = String.format( "%%.%df%%s", Integer.valueOf( aScale ) );
+ return String.format( format, time, getDisplayName() );
+ }
+
+ /**
* Returns the current value of displayName.
*
* @return the displayName
View
73 api/src/test/java/nl/lxtreme/ols/api/util/FrequencyUnitTest.java
@@ -0,0 +1,73 @@
+/*
+ * OpenBench LogicSniffer / SUMP project
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+ *
+ * Copyright (C) 2006-2010 Michael Poppitz, www.sump.org
+ * Copyright (C) 2010-2012 J.W. Janssen, www.lxtreme.nl
+ */
+package nl.lxtreme.ols.api.util;
+
+
+import static org.junit.Assert.*;
+
+import org.junit.*;
+
+
+/**
+ *
+ */
+public class FrequencyUnitTest
+{
+ // METHODS
+
+ /**
+ * Test method for
+ * {@link nl.lxtreme.ols.api.util.FrequencyUnit#format(double, int)}.
+ */
+ @Test
+ public void testFormatAutoScaleOk()
+ {
+ assertEquals( "0.000Hz", FrequencyUnit.format( 0 ) );
+ assertEquals( "1.000mHz", FrequencyUnit.format( 1.0e-3 ) );
+ assertEquals( "1.000Hz", FrequencyUnit.format( 1.0 ) );
+ assertEquals( "1.000kHz", FrequencyUnit.format( 1.0e3 ) );
+ assertEquals( "1.000MHz", FrequencyUnit.format( 1.0e6 ) );
+ assertEquals( "1.000GHz", FrequencyUnit.format( 1.0e9 ) );
+ assertEquals( "1.000THz", FrequencyUnit.format( 1.0e12 ) );
+ assertEquals( "-1.000THz", FrequencyUnit.format( -1.0e12 ) );
+ assertEquals( "100.000THz", FrequencyUnit.format( 1.0e14 ) );
+ assertEquals( "333.333kHz", FrequencyUnit.format( 333333.3333333333 ) );
+ }
+
+ /**
+ * Test method for
+ * {@link nl.lxtreme.ols.api.util.FrequencyUnit#format(double, int)}.
+ */
+ @Test
+ public void testFormatOk()
+ {
+ assertEquals( "0.000Hz", FrequencyUnit.GHZ.format( 0, 3 ) );
+ assertEquals( "1.000mHz", FrequencyUnit.MiHZ.format( 1.0e-3, 3 ) );
+ assertEquals( "0.001kHz", FrequencyUnit.KHZ.format( 1.0, 3 ) );
+ assertEquals( "1.000kHz", FrequencyUnit.KHZ.format( 1.0e3, 3 ) );
+ assertEquals( "1.000MHz", FrequencyUnit.MHZ.format( 1.0e6, 3 ) );
+ assertEquals( "1.000GHz", FrequencyUnit.GHZ.format( 1.0e9, 3 ) );
+ assertEquals( "1.000THz", FrequencyUnit.THZ.format( 1.0e12, 3 ) );
+ assertEquals( "100.000THz", FrequencyUnit.THZ.format( 1.0e14, 3 ) );
+ assertEquals( "333.333kHz", FrequencyUnit.KHZ.format( 333333.3333333333, 3 ) );
+ }
+
+}
View
48 api/src/test/java/nl/lxtreme/ols/api/util/SizeUnitTest.java
@@ -0,0 +1,48 @@
+/*
+ * OpenBench LogicSniffer / SUMP project
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+ *
+ * Copyright (C) 2006-2010 Michael Poppitz, www.sump.org
+ * Copyright (C) 2010-2012 J.W. Janssen, www.lxtreme.nl
+ */
+package nl.lxtreme.ols.api.util;
+
+
+import static org.junit.Assert.*;
+
+import org.junit.*;
+
+
+/**
+ * Test cases for {@link SizeUnit}.
+ */
+public class SizeUnitTest
+{
+ // METHODS
+
+ /**
+ * Test method for
+ * {@link nl.lxtreme.ols.api.util.SizeUnit#format(double, int)}.
+ */
+ @Test
+ public void testFormatAutoScaleOk()
+ {
+ assertEquals( "0.00B", SizeUnit.format( 0 ) );
+ assertEquals( "10.00kB", SizeUnit.format( 10240 ) );
+ assertEquals( "10.00MB", SizeUnit.format( 10240 * 1024 ) );
+ assertEquals( "-10.00MB", SizeUnit.format( -10240 * 1024 ) );
+ }
+}
View
78 api/src/test/java/nl/lxtreme/ols/api/util/UnitOfTimeTest.java
@@ -0,0 +1,78 @@
+/*
+ * OpenBench LogicSniffer / SUMP project
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+ *
+ * Copyright (C) 2006-2010 Michael Poppitz, www.sump.org
+ * Copyright (C) 2010-2012 J.W. Janssen, www.lxtreme.nl
+ */
+package nl.lxtreme.ols.api.util;
+
+
+import static org.junit.Assert.*;
+
+import org.junit.*;
+
+
+/**
+ * Test cases for {@link UnitOfTime}.
+ */
+public class UnitOfTimeTest
+{
+ // METHODS
+
+ /**
+ * Test method for
+ * {@link nl.lxtreme.ols.api.util.UnitOfTime#format(double, int)}.
+ */
+ @Test
+ public void testFormatAutoScaleOk()
+ {
+ assertEquals( "0.00s", UnitOfTime.format( 0 ) );
+ assertEquals( "1.00ms", UnitOfTime.format( 1.0e-3 ) );
+ assertEquals( "-1.00ms", UnitOfTime.format( -1.0e-3 ) );
+ assertEquals( "1.20ns", UnitOfTime.format( 1.2e-9 ) );
+ assertEquals( "1.00s", UnitOfTime.format( 1.0 ) );
+ assertEquals( "1000.00s", UnitOfTime.format( 1.0e3 ) );
+ }
+
+ /**
+ * Test method for {@link nl.lxtreme.ols.api.util.UnitOfTime#predecessor()}.
+ */
+ @Test
+ public void testPredecessor()
+ {
+ assertNull( UnitOfTime.S.predecessor() );
+ assertNotNull( UnitOfTime.MS.predecessor() );
+ assertNotNull( UnitOfTime.US.predecessor() );
+ assertNotNull( UnitOfTime.NS.predecessor() );
+ assertNotNull( UnitOfTime.PS.predecessor() );
+ assertNotNull( UnitOfTime.FS.predecessor() );
+ }
+
+ /**
+ * Test method for {@link nl.lxtreme.ols.api.util.UnitOfTime#successor()}.
+ */
+ @Test
+ public void testSuccessor()
+ {
+ assertNotNull( UnitOfTime.S.successor() );
+ assertNotNull( UnitOfTime.MS.successor() );
+ assertNotNull( UnitOfTime.US.successor() );
+ assertNotNull( UnitOfTime.NS.successor() );
+ assertNotNull( UnitOfTime.PS.successor() );
+ assertNull( UnitOfTime.FS.successor() );
+ }
+}
View
2 client/src/main/java/nl/lxtreme/ols/client/ClientController.java
@@ -319,7 +319,7 @@ else if ( aStatus.isFailed() )
long time = System.currentTimeMillis() - this.acquisitionStartTime;
setStatusOnEDT( "Capture finished at {0,date,medium} {0,time,medium}, and took {1}.", new Date(),
- UnitOfTime.toString( time / 1000.0 ) );
+ UnitOfTime.MS.format( time, 1 ) );
}
updateActionsOnEDT();
View
32 client/src/main/java/nl/lxtreme/ols/client/action/GotoNthCursorAction.java
@@ -32,7 +32,6 @@
import nl.lxtreme.ols.client.actionmanager.*;
import nl.lxtreme.ols.client.icons.*;
import nl.lxtreme.ols.client.signaldisplay.*;
-import nl.lxtreme.ols.util.*;
import nl.lxtreme.ols.util.swing.*;
@@ -72,7 +71,7 @@ public GotoNthCursorAction( final SignalDiagramController aController, final int
final String cursorStr = String.valueOf( aIndex + 1 );
putValue( NAME, "Go to cursor " + cursorStr );
- putValue( SHORT_DESCRIPTION, "Go to the " + DisplayUtils.getOrdinalNumber( aIndex + 1 ) + " cursor in the diagram" );
+ putValue( SHORT_DESCRIPTION, "Go to the " + getOrdinalNumber( aIndex + 1 ) + " cursor in the diagram" );
putValue( Action.LARGE_ICON_KEY, createOverlayIcon( IconLocator.ICON_GOTO_CURSOR, cursorStr ) );
int keyStroke = KeyEvent.VK_0 + ( ( aIndex + 1 ) % Ols.MAX_CURSORS );
@@ -105,6 +104,35 @@ public static String getID( final int aCursorIdx )
}
/**
+ * Returns the ordinal representation (in English) of the given value.
+ *
+ * @param aValue
+ * the value to get the ordinal value for, >= 0 && < 40.
+ * @return a ordinal number representation of the given value, like "1st".
+ */
+ private static String getOrdinalNumber( final int aValue )
+ {
+ String suffix = "";
+ if ( ( aValue == 1 ) || ( aValue == 21 ) || ( aValue == 31 ) )
+ {
+ suffix = "st";
+ }
+ else if ( ( aValue == 2 ) || ( aValue == 22 ) )
+ {
+ suffix = "nd";
+ }
+ else if ( ( aValue == 3 ) || ( aValue == 23 ) )
+ {
+ suffix = "rd";
+ }
+ else if ( ( aValue >= 0 ) && ( aValue < 40 ) )
+ {
+ suffix = "th";
+ }
+ return String.format( "%d%s", Integer.valueOf( aValue ), suffix );
+ }
+
+ /**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
View
4 client/src/main/java/nl/lxtreme/ols/client/diagram/laf/DiagramTimeLineUI.java
@@ -204,7 +204,7 @@ private String indexToTime( final DataContainer aDataContainer, final long aTime
timeValue -= aDataContainer.getTriggerPosition();
}
- return UnitOfTime.toString( timeValue / aDataContainer.getSampleRate() );
+ return UnitOfTime.format( timeValue / aDataContainer.getSampleRate() );
}
/**
@@ -249,7 +249,7 @@ private void paintCursorFlags( final DataContainer aDataContainer, final Graphic
final int cursorPos = ( int )( cursorPosition.longValue() * scale );
final Double cursorTimeValue = aDataContainer.getCursorTimeValue( i );
- final String cursorTime = UnitOfTime.toString( cursorTimeValue.doubleValue() );
+ final String cursorTime = UnitOfTime.format( cursorTimeValue.doubleValue() );
final Color cursorColor = settings.getCursorColor( i );
final Color cursorTextColor = ColorUtils.getContrastColor( cursorColor );
View
6 client/src/main/java/nl/lxtreme/ols/client/diagram/laf/DiagramUI.java
@@ -373,9 +373,9 @@ private void updateTooltipText( final Diagram aDiagram, final Point aMousePositi
sb.append( aAnnotation.getData() );
sb.append( " | Time: " );
- sb.append( UnitOfTime.toString( start ) );
+ sb.append( UnitOfTime.format( start ) );
sb.append( ".." );
- sb.append( UnitOfTime.toString( end ) );
+ sb.append( UnitOfTime.format( end ) );
}
else
{
@@ -392,7 +392,7 @@ private void updateTooltipText( final Diagram aDiagram, final Point aMousePositi
{
absMouseX -= triggerPosition;
}
- sb.append( "Time: " ).append( UnitOfTime.toString( absMouseX / sampleRate ) );
+ sb.append( "Time: " ).append( UnitOfTime.format( absMouseX / sampleRate ) );
}
}
View
4 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/MeasurementInfo.java
@@ -353,11 +353,11 @@ public String toHtmlString()
sb.append( ", " ).append( this.channelLabel );
}
sb.append( "<br>" );
- sb.append( "Time: " ).append( UnitOfTime.toString( getReferenceTime() ) ).append( "<br>" );
+ sb.append( "Time: " ).append( UnitOfTime.format( getReferenceTime() ) ).append( "<br>" );
sb.append( "Period: " );
if ( tt != null )
{
- sb.append( UnitOfTime.toString( tt.doubleValue() ) );
+ sb.append( UnitOfTime.format( tt.doubleValue() ) );
}
else
{
View
2 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/SignalDiagramComponent.java
@@ -391,7 +391,7 @@ public void paint( final Graphics aGraphics )
{
final long endTime = System.nanoTime();
final long renderTime = endTime - startTime;
- System.out.println( "Rendering time = " + UnitOfTime.toString( renderTime / 1.0e9 ) );
+ System.out.println( "Rendering time = " + UnitOfTime.format( renderTime ) );
}
}
else
View
22 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/laf/TimeLineUI.java
@@ -380,28 +380,16 @@ public void paint( final Graphics aGraphics, final JComponent aComponent )
*/
private String displayTime( final double aTime, final double aTimeScale, final int aPrecision )
{
- UnitOfTime timeScale = UnitOfTime.valueOf( aTimeScale );
- UnitOfTime time = UnitOfTime.valueOf( aTime );
-
- Double t;
- String s;
+ final UnitOfTime timeScale = UnitOfTime.toUnit( aTimeScale );
+ final UnitOfTime time = UnitOfTime.toUnit( aTime );
if ( ( timeScale != time ) && ( timeScale != time.successor() ) )
{
// More than a factor 1000 difference...
- UnitOfTime predecessor = timeScale.predecessor();
-
- t = Double.valueOf( aTime / predecessor.getFactor() );
- s = predecessor.getDisplayName();
- }
- else
- {
- t = Double.valueOf( aTime / time.getFactor() );
- s = time.getDisplayName();
+ return timeScale.predecessor().format( aTime, aPrecision );
}
- String format = String.format( "%%.%df%%s", Integer.valueOf( aPrecision ) );
- return String.format( format, t, s );
+ return time.format( aTime, aPrecision );
}
/**
@@ -428,7 +416,7 @@ private String getMinorTimestamp( final TimeLineViewModel aModel, final double a
{
if ( aModel.hasTimingData() )
{
- return UnitOfTime.toString( aTime );
+ return UnitOfTime.format( aTime );
}
return Integer.toString( ( int )aTime );
View
4 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/model/AbstractViewModel.java
@@ -354,11 +354,11 @@ private String getCursorFlagText( final int aCursorIdx, final long aCursorTimest
switch ( aStyle )
{
case LABEL_TIME:
- return label.concat( ": " ).concat( UnitOfTime.toString( aCursorTimestamp / sampleRate ) );
+ return label.concat( ": " ).concat( UnitOfTime.format( aCursorTimestamp / sampleRate ) );
case INDEX_LABEL:
return String.format( "%d: %s", index, label );
case TIME_ONLY:
- return UnitOfTime.toString( aCursorTimestamp / sampleRate );
+ return UnitOfTime.format( aCursorTimestamp / sampleRate );
case LABEL_ONLY:
return label;
case INDEX_ONLY:
View
4 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/model/SignalDiagramModel.java
@@ -33,8 +33,8 @@
import nl.lxtreme.ols.api.data.Cursor;
import nl.lxtreme.ols.client.signaldisplay.*;
import nl.lxtreme.ols.client.signaldisplay.signalelement.*;
-import nl.lxtreme.ols.client.signaldisplay.signalelement.SignalElementManager.*;
-import nl.lxtreme.ols.util.*;
+import nl.lxtreme.ols.client.signaldisplay.signalelement.SignalElementManager.SignalElementHeightProvider;
+import nl.lxtreme.ols.client.signaldisplay.signalelement.SignalElementManager.SignalElementMeasurer;
/**
View
8 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/view/CaptureDetailsView.java
@@ -111,9 +111,9 @@ public void dataModelChanged( final DataSet aDataSet )
{
final AcquisitionResult model = aDataSet.getCapturedData();
- this.sampleRate = FrequencyUnit.toString( model.getSampleRate() );
+ this.sampleRate = FrequencyUnit.format( model.getSampleRate() );
this.sampleCount = new DecimalFormat().format( model.getValues().length );
- this.totalWidth = UnitOfTime.toString( model.getAbsoluteLength() / ( double )model.getSampleRate() );
+ this.totalWidth = UnitOfTime.format( model.getAbsoluteLength() / ( double )model.getSampleRate() );
}
updateView();
@@ -162,7 +162,7 @@ protected void paintComponent( final Graphics aGraphics )
final Double timeInterval = model.getTimeInterval();
if ( timeInterval != null )
{
- this.tickInterval = UnitOfTime.toString( timeInterval.doubleValue() );
+ this.tickInterval = UnitOfTime.format( timeInterval.doubleValue() );
}
else
{
@@ -174,7 +174,7 @@ protected void paintComponent( final Graphics aGraphics )
final Double displayedTimeInterval = model.getDisplayedTimeInterval();
if ( displayedTimeInterval != null )
{
- this.displayedTime = UnitOfTime.toString( displayedTimeInterval.doubleValue() );
+ this.displayedTime = UnitOfTime.format( displayedTimeInterval.doubleValue() );
}
else
{
View
2 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/view/CursorDetailsView.java
@@ -228,7 +228,7 @@ private String asText()
sb.append( c + 1 ).append( ":" ).append( "</th>" );
sb.append( "<td>" ).append( label ).append( "</td>" );
sb.append( "<td align='right'><a href='#" ).append( cursor.getTimestamp() ).append( "'>" );
- sb.append( UnitOfTime.toString( cursor.getTimestamp() / ( double )model.getSampleRate() ) );
+ sb.append( UnitOfTime.format( cursor.getTimestamp() / ( double )model.getSampleRate() ) );
sb.append( "</a></td></tr>" );
}
sb.append( "</table></body></html>" );
View
4 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/view/MeasurementView.java
@@ -153,8 +153,8 @@ else if ( lastBitValue > bitValue )
double frequency = model.getSampleRate() / ( avgHighTime + avgLowTime );
double dutyCycle = avgHighTime / ( avgHighTime + avgLowTime );
- String timeText = UnitOfTime.toString( measureTime );
- String frequencyText = FrequencyUnit.toString( frequency );
+ String timeText = UnitOfTime.format( measureTime );
+ String frequencyText = FrequencyUnit.format( frequency );
String dutyCycleText = String.format( "%.3f%%", Double.valueOf( 100.0 * dutyCycle ) );
String pulseCountText = String.format( "%d (\u2191%d, \u2193%d)", Integer.valueOf( pulseCount ),
Integer.valueOf( lowCount ), Integer.valueOf( highCount ) );
View
4 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/view/SignalDetailsView.java
@@ -94,7 +94,7 @@ private static String asText( final MeasurementInfo aMeasurementInfo )
{
channelLabel = aMeasurementInfo.getChannelLabel();
channelIdx = Integer.toString( aMeasurementInfo.getChannelIndex() );
- timeValue = UnitOfTime.toString( aMeasurementInfo.getReferenceTime() );
+ timeValue = UnitOfTime.format( aMeasurementInfo.getReferenceTime() );
totalWidth = getTimeAsString( aMeasurementInfo.getTotalTime() );
pwHigh = getTimeAsString( aMeasurementInfo.getHighTime() );
pwLow = getTimeAsString( aMeasurementInfo.getLowTime() );
@@ -142,7 +142,7 @@ private static String getTimeAsString( final Double aTime )
{
if ( aTime != null )
{
- return UnitOfTime.toString( aTime.doubleValue() );
+ return UnitOfTime.format( aTime.doubleValue() );
}
return "-";
}
View
2 client/src/main/java/nl/lxtreme/ols/client/signaldisplay/view/TimeLineView.java
@@ -103,7 +103,7 @@ private String getToolTipText( final Point aPoint )
String toolTip;
if ( signalDiagramModel.hasTimingData() )
{
- toolTip = UnitOfTime.toString( refTime );
+ toolTip = UnitOfTime.toUnit( refTime ).format( refTime, 6 );
}
else
{
View
4 device.logicsniffer/src/main/java/org/sump/device/logicsniffer/LogicSnifferConfigDialog.java
@@ -73,7 +73,7 @@ public Component getListCellRendererComponent( final JList aList, final Object a
Object value = aValue;
if ( value instanceof Integer )
{
- value = SizeUnit.toString( ( ( Integer )aValue ).doubleValue() );
+ value = SizeUnit.format( ( ( Integer )aValue ).doubleValue() );
}
return super.getListCellRendererComponent( aList, value, aIndex, aIsSelected, aCellHasFocus );
}
@@ -93,7 +93,7 @@ public Component getListCellRendererComponent( final JList aList, final Object a
Object value = aValue;
if ( value instanceof Integer )
{
- value = FrequencyUnit.toString( ( ( Integer )value ).doubleValue() );
+ value = FrequencyUnit.format( ( ( Integer )value ).doubleValue() );
}
return super.getListCellRendererComponent( aList, value, aIndex, aIsSelected, aCellHasFocus );
}
View
6 test.util/pom.xml
@@ -16,6 +16,12 @@
<artifactId>api</artifactId>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>nl.lxtreme.ols</groupId>
+ <artifactId>util</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
View
5 tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireAnalyserDialog.java
@@ -34,6 +34,7 @@
import nl.lxtreme.ols.api.*;
import nl.lxtreme.ols.api.tools.*;
+import nl.lxtreme.ols.api.util.*;
import nl.lxtreme.ols.tool.base.*;
import nl.lxtreme.ols.tool.base.ToolUtils.RestorableAction;
import nl.lxtreme.ols.util.*;
@@ -435,7 +436,7 @@ else if ( "decoded-data".equals( aMacro ) )
tr = aParent.addChild( TR ).addAttribute( "style", "background-color: " + bgColor + ";" );
tr.addChild( TD ).addContent( String.valueOf( i ) );
- tr.addChild( TD ).addContent( aAnalysisResult.getDisplayTime( data.getStartSampleIndex() ) );
+ tr.addChild( TD ).addContent( UnitOfTime.format( aAnalysisResult.getTime( data.getStartSampleIndex() ) ) );
tr.addChild( TD ).addContent( event );
tr.addChild( TD );
tr.addChild( TD );
@@ -447,7 +448,7 @@ else if ( "decoded-data".equals( aMacro ) )
tr = aParent.addChild( TR );
tr.addChild( TD ).addContent( String.valueOf( i ) );
- tr.addChild( TD ).addContent( aAnalysisResult.getDisplayTime( data.getStartSampleIndex() ) );
+ tr.addChild( TD ).addContent( UnitOfTime.format( aAnalysisResult.getTime( data.getStartSampleIndex() ) ) );
tr.addChild( TD ).addContent( "0x" + StringUtils.integerToHexString( value, 2 ) );
tr.addChild( TD ).addContent( "0b" + StringUtils.integerToBinString( value, 8 ) );
tr.addChild( TD ).addContent( String.valueOf( value ) );
View
2 tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireAnalyserTask.java
@@ -180,7 +180,7 @@ private void decodeData( final AcquisitionResult aData, final OneWireDataSet aDa
if ( fallingEdge < 0 )
{
LOG.log( Level.INFO, "Decoding ended at {0}; no falling edge found...",
- UnitOfTime.toString( time / ( double )aData.getSampleRate() ) );
+ UnitOfTime.format( time / ( double )aData.getSampleRate() ) );
break;
}
long risingEdge = findEdge( aData, fallingEdge, endOfDecode, Edge.RISING );
View
13 tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireDataSet.java
@@ -23,7 +23,6 @@
import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.data.*;
-import nl.lxtreme.ols.api.util.*;
/**
@@ -79,18 +78,6 @@ public int getDecodedByteCount()
}
/**
- * Returns the time as display string.
- *
- * @param aSampleIdx
- * a sample index to return the time value for.
- * @return a time display value, never <code>null</code>.
- */
- public String getDisplayTime( final int aSampleIdx )
- {
- return UnitOfTime.toString( getTime( aSampleIdx ) );
- }
-
- /**
* Reports a bus error event.
*
* @param aChannelIdx
View
13 tool.asm45/src/main/java/nl/lxtreme/ols/tool/asm45/Asm45DataSet.java
@@ -23,7 +23,6 @@
import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.data.*;
-import nl.lxtreme.ols.api.util.*;
/**
@@ -63,18 +62,6 @@ public int getDecodedWordCount()
}
/**
- * Returns the time as display string.
- *
- * @param aSampleIdx
- * a sample index to return the time value for.
- * @return a time display value, never <code>null</code>.
- */
- public String getDisplayTime( final int aSampleIdx )
- {
- return UnitOfTime.toString( getTime( aSampleIdx ) );
- }
-
- /**
* @return the total time for all samples.
*/
public String getTotalTime()
View
13 tool.i2c/src/main/java/nl/lxtreme/ols/tool/i2c/I2CDataSet.java
@@ -23,7 +23,6 @@
import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.data.*;
-import nl.lxtreme.ols.api.util.*;
/**
@@ -80,18 +79,6 @@ public int getDecodedByteCount()
}
/**
- * Returns the time as display string.
- *
- * @param aSampleIdx
- * a sample index to return the time value for.
- * @return a time display value, never <code>null</code>.
- */
- public String getDisplayTime( final int aSampleIdx )
- {
- return UnitOfTime.toString( getTime( aSampleIdx ) );
- }
-
- /**
* @param aTime
*/
public void reportACK( final int aChannelIdx, final int aSampleIdx )
View
9 tool.i2c/src/main/java/nl/lxtreme/ols/tool/i2c/I2CProtocolAnalysisDialog.java
@@ -37,6 +37,7 @@
import nl.lxtreme.ols.api.*;
import nl.lxtreme.ols.api.tools.*;
+import nl.lxtreme.ols.api.util.*;
import nl.lxtreme.ols.tool.base.*;
import nl.lxtreme.ols.tool.base.ToolUtils.RestorableAction;
import nl.lxtreme.ols.util.*;
@@ -553,8 +554,8 @@ private void storeToCsvFile( final File aSelectedFile, final I2CDataSet aAnalysi
{
final I2CData ds = dataSet.get( i );
- final String startTime = aAnalysisResult.getDisplayTime( ds.getStartSampleIndex() );
- final String endTime = aAnalysisResult.getDisplayTime( ds.getEndSampleIndex() );
+ final String startTime = UnitOfTime.format( aAnalysisResult.getTime( ds.getStartSampleIndex() ) );
+ final String endTime = UnitOfTime.format( aAnalysisResult.getTime( ds.getEndSampleIndex() ) );
final String data = ds.isEvent() ? "" : Character.toString( ( char )ds.getValue() );
exporter.addRow( Integer.valueOf( i ), startTime, endTime, Boolean.valueOf( ds.isEvent() ), ds.getEventName(),
@@ -665,7 +666,7 @@ else if ( I2CDataSet.I2C_NACK.equals( event ) )
tr = aParent.addChild( TR ).addAttribute( "style", "background-color: " + bgColor + ";" );
tr.addChild( TD ).addContent( String.valueOf( i ) );
- tr.addChild( TD ).addContent( aAnalysisResult.getDisplayTime( data.getStartSampleIndex() ) );
+ tr.addChild( TD ).addContent( UnitOfTime.format( aAnalysisResult.getTime( data.getStartSampleIndex() ) ) );
tr.addChild( TD ).addContent( event );
tr.addChild( TD );
tr.addChild( TD );
@@ -677,7 +678,7 @@ else if ( I2CDataSet.I2C_NACK.equals( event ) )
tr = aParent.addChild( TR );
tr.addChild( TD ).addContent( String.valueOf( i ) );
- tr.addChild( TD ).addContent( aAnalysisResult.getDisplayTime( data.getStartSampleIndex() ) );
+ tr.addChild( TD ).addContent( UnitOfTime.format( aAnalysisResult.getTime( data.getStartSampleIndex() ) ) );
tr.addChild( TD ).addContent( "0x" + StringUtils.integerToHexString( value, 2 ) );
tr.addChild( TD ).addContent( "0b" + StringUtils.integerToBinString( value, 8 ) );
tr.addChild( TD ).addContent( String.valueOf( value ) );
View
13 tool.jtag/src/main/java/nl/lxtreme/ols/tool/jtag/JTAGDataSet.java
@@ -23,7 +23,6 @@
import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.data.*;
-import nl.lxtreme.ols.api.util.*;
/**
@@ -52,18 +51,6 @@ public JTAGDataSet( final int aStartOfDecode, final int aEndOfDecode, final Acqu
// METHODS
/**
- * Returns the time as display string.
- *
- * @param aSampleIdx
- * a sample index to return the time value for.
- * @return a time display value, never <code>null</code>.
- */
- public String getDisplayTime( final int aSampleIdx )
- {
- return UnitOfTime.toString( getTime( aSampleIdx ) );
- }
-
- /**
* @param aTimeValue
*/
public void reportJTAGState( final int aChannelIdx, final int aStartIdx, final int aEndIdx, final JTAGState aDataValue )
View
15 tool.jtag/src/main/java/nl/lxtreme/ols/tool/jtag/JTAGProtocolAnalysisDialog.java
@@ -33,10 +33,9 @@
import javax.swing.*;
-import org.osgi.framework.*;
-
import nl.lxtreme.ols.api.*;
import nl.lxtreme.ols.api.tools.*;
+import nl.lxtreme.ols.api.util.*;
import nl.lxtreme.ols.tool.base.*;
import nl.lxtreme.ols.tool.base.ToolUtils.RestorableAction;
import nl.lxtreme.ols.util.*;
@@ -47,6 +46,8 @@
import nl.lxtreme.ols.util.ExportUtils.HtmlFileExporter;
import nl.lxtreme.ols.util.swing.*;
+import org.osgi.framework.*;
+
/**
* The Dialog Class for configuring the JTAG protocol analysis settings.
@@ -413,12 +414,12 @@ private void storeToCsvFile( final File aFile, final JTAGDataSet aDataSet )
{
final JTAGData data = dataSet.get( i );
- final String Time = aDataSet.getDisplayTime( data.getStartSampleIndex() );
- final String Event = data.isEvent() ? data.getEventName() : data.getDataValue().getDisplayText();
+ final String time = UnitOfTime.format( aDataSet.getTime( data.getStartSampleIndex() ) );
+ final String event = data.isEvent() ? data.getEventName() : data.getDataValue().getDisplayText();
final String tdiDataValue = data.isTdiData() ? Integer.toString( data.getDataValue().ordinal() ) : null;
final String tdoDataValue = data.isTdoData() ? Integer.toString( data.getDataValue().ordinal() ) : null;
- exporter.addRow( Integer.valueOf( i ), Time, Event, tdiDataValue, tdoDataValue );
+ exporter.addRow( Integer.valueOf( i ), time, event, tdiDataValue, tdoDataValue );
}
exporter.close();
@@ -499,7 +500,7 @@ else if ( "decoded-data".equals( aMacro ) )
tr = aParent.addChild( TR ).addAttribute( "style", "background-color: " + bgColor + ";" );
tr.addChild( TD ).addContent( String.valueOf( i ) );
- tr.addChild( TD ).addContent( aAnalysisResult.getDisplayTime( data.getStartSampleIndex() ) );
+ tr.addChild( TD ).addContent( UnitOfTime.format( aAnalysisResult.getTime( data.getStartSampleIndex() ) ) );
tr.addChild( TD ).addContent( event );
tr.addChild( TD );
tr.addChild( TD );
@@ -511,7 +512,7 @@ else if ( "decoded-data".equals( aMacro ) )
tr = aParent.addChild( TR );
tr.addChild( TD ).addContent( String.valueOf( i ) );
- tr.addChild( TD ).addContent( aAnalysisResult.getDisplayTime( data.getStartSampleIndex() ) );
+ tr.addChild( TD ).addContent( UnitOfTime.format( aAnalysisResult.getTime( data.getStartSampleIndex() ) ) );
tr.addChild( TD ).addContent( value.getDisplayText() );
}
}
View
9 tool.measure/src/main/java/nl/lxtreme/ols/tool/measure/ClockFrequencyMeasureTask.java
@@ -21,7 +21,6 @@
package nl.lxtreme.ols.tool.measure;
-import static nl.lxtreme.ols.util.DisplayUtils.*;
import java.util.logging.*;
import nl.lxtreme.ols.api.acquisition.*;
@@ -174,14 +173,14 @@ public boolean hasError()
@Override
public String toString()
{
- String timeText = UnitOfTime.toString( this.measuringTime );
- String frequencyText = FrequencyUnit.toString( this.frequency );
+ String timeText = UnitOfTime.format( this.measuringTime );
+ String frequencyText = FrequencyUnit.format( this.frequency );
if ( hasError() )
{
- frequencyText = frequencyText.concat( " (error = \u00b1" ).concat( FrequencyUnit.toString( this.error ) )
+ frequencyText = frequencyText.concat( " (error = \u00b1" ).concat( FrequencyUnit.format( this.error ) )
.concat( ")" );
}
- String dutyCycleText = displayPercentage( this.dutycycle );
+ String dutyCycleText = String.format( "%.1f%%", Double.valueOf( this.dutycycle * 100.0 ) );
return String.format( "Measure time: %s; frequency: %s; dutycycle: %s; # of pulses: %d (\u2191%d, \u2193%d)",
timeText, frequencyText, dutyCycleText, Integer.valueOf( this.pulseCount ),
View
11 tool.measure/src/main/java/nl/lxtreme/ols/tool/measure/MeasurementDialog.java
@@ -36,7 +36,6 @@
import nl.lxtreme.ols.api.util.*;
import nl.lxtreme.ols.tool.base.*;
import nl.lxtreme.ols.tool.measure.ClockFrequencyMeasureTask.ClockStats;
-import nl.lxtreme.ols.util.*;
import nl.lxtreme.ols.util.swing.*;
import org.osgi.framework.*;
@@ -235,10 +234,10 @@ final void updateMeasurement()
final long diff = cursorA.getTimestamp() - cursorB.getTimestamp();
final double distance = Math.abs( diff / rate );
- distanceText = UnitOfTime.toString( distance );
+ distanceText = UnitOfTime.format( distance );
final double frequency = Math.abs( rate / diff );
- frequencyText = FrequencyUnit.toString( frequency );
+ frequencyText = FrequencyUnit.format( frequency );
}
this.distanceLabel.setText( distanceText );
@@ -251,8 +250,8 @@ final void updateMeasurement()
@Override
protected void onToolEnded( final ClockStats aClockStats )
{
- String frequency = FrequencyUnit.toString( aClockStats.getFrequency() );
- String dutycycle = DisplayUtils.displayPercentage( aClockStats.getDutyCycle() );
+ String frequency = FrequencyUnit.format( aClockStats.getFrequency() );
+ String dutycycle = String.format( "%.1f%%", Double.valueOf( aClockStats.getDutyCycle() * 100.0 ) );
if ( aClockStats.hasError() )
{
frequency = "\u2248".concat( frequency );
@@ -421,7 +420,7 @@ private String getCursorTimeDisplayValue( final int aIndex )
final Cursor cursor = context.getCursor( aIndex );
if ( cursor.isDefined() )
{
- return UnitOfTime.toString( cursor.getTimestamp() / ( double )data.getSampleRate() );
+ return UnitOfTime.format( cursor.getTimestamp() / ( double )data.getSampleRate() );
}
}
return "<not set>";
View
13 tool.spi/src/main/java/nl/lxtreme/ols/tool/spi/SPIDataSet.java
@@ -23,7 +23,6 @@
import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.data.*;
-import nl.lxtreme.ols.api.util.*;
/**
@@ -53,18 +52,6 @@ public SPIDataSet( final int aStartOfDecode, final int aEndOfDecode, final Acqui
// METHODS
/**
- * Returns the time as display string.
- *
- * @param aSampleIdx
- * a sample index to return the time value for.
- * @return a time display value, never <code>null</code>.
- */
- public String getDisplayTime( final int aSampleIdx )
- {
- return UnitOfTime.toString( getTime( aSampleIdx ) );
- }
-
- /**
* @param aTimeValue
*/
public void reportCSHigh( final int aChannelIdx, final int aSampleIdx )
View
9 tool.spi/src/main/java/nl/lxtreme/ols/tool/spi/SPIProtocolAnalysisDialog.java
@@ -36,6 +36,7 @@
import nl.lxtreme.ols.api.*;
import nl.lxtreme.ols.api.tools.*;
+import nl.lxtreme.ols.api.util.*;
import nl.lxtreme.ols.tool.base.*;
import nl.lxtreme.ols.tool.base.ToolUtils.RestorableAction;
import nl.lxtreme.ols.util.*;
@@ -613,8 +614,8 @@ private void storeToCsvFile( final File aFile, final SPIDataSet aDataSet )
{
final SPIData ds = decodedData.get( i );
- final String startTime = aDataSet.getDisplayTime( ds.getStartSampleIndex() );
- final String endTime = aDataSet.getDisplayTime( ds.getStartSampleIndex() );
+ final String startTime = UnitOfTime.format( aDataSet.getTime( ds.getStartSampleIndex() ) );
+ final String endTime = UnitOfTime.format( aDataSet.getTime( ds.getStartSampleIndex() ) );
final String mosiDataValue = ds.isMosiData() ? Integer.toString( ds.getDataValue() ) : null;
final String misoDataValue = ds.isMisoData() ? Integer.toString( ds.getDataValue() ) : null;
@@ -737,7 +738,7 @@ else if ( SPIDataSet.SPI_CS_HIGH.equals( ds.getEventName() ) )
tr = aParent.addChild( TR ).addAttribute( "style", "background-color: " + bgColor + ";" );
tr.addChild( TD ).addContent( String.valueOf( i ) );
- tr.addChild( TD ).addContent( aDataSet.getDisplayTime( ds.getStartSampleIndex() ) );
+ tr.addChild( TD ).addContent( UnitOfTime.format( aDataSet.getTime( ds.getStartSampleIndex() ) ) );
tr.addChild( TD ).addContent( event );
tr.addChild( TD );
tr.addChild( TD );
@@ -753,7 +754,7 @@ else if ( ds.isData() )
tr = aParent.addChild( TR );
tr.addChild( TD ).addContent( String.valueOf( i ) );
- tr.addChild( TD ).addContent( aDataSet.getDisplayTime( sampleIdx ) );
+ tr.addChild( TD ).addContent( UnitOfTime.format( aDataSet.getTime( sampleIdx ) ) );
int mosiValue = ds.isMosiData() ? ds.getDataValue() : 0;
int misoValue = ds.isMisoData() ? ds.getDataValue() : 0;
View
13 tool.uart/src/main/java/nl/lxtreme/ols/tool/uart/UARTDataSet.java
@@ -25,7 +25,6 @@
import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.data.*;
-import nl.lxtreme.ols.api.util.*;
/**
@@ -122,18 +121,6 @@ public int getDetectedErrors()
}
/**
- * Returns the time as display string.
- *
- * @param aSampleIdx
- * a sample index to return the time value for.
- * @return a time display value, never <code>null</code>.
- */
- public String getDisplayTime( final int aSampleIdx )
- {
- return UnitOfTime.toString( getTime( aSampleIdx ) );
- }
-
- /**
* Returns whether or not the bitlength is usable.
*
* @return <code>true</code> if a usable bitlength has been decoded,
View
9 tool.uart/src/main/java/nl/lxtreme/ols/tool/uart/UARTProtocolAnalysisDialog.java
@@ -36,6 +36,7 @@
import nl.lxtreme.ols.api.*;
import nl.lxtreme.ols.api.tools.*;
+import nl.lxtreme.ols.api.util.*;
import nl.lxtreme.ols.tool.base.*;
import nl.lxtreme.ols.tool.base.ToolUtils.RestorableAction;
import nl.lxtreme.ols.tool.uart.AsyncSerialDataDecoder.Parity;
@@ -652,8 +653,8 @@ private void storeToCsvFile( final File aFile, final UARTDataSet aDataSet )
{
final UARTData ds = decodedData.get( i );
- final String startTime = aDataSet.getDisplayTime( ds.getStartSampleIndex() );
- final String endTime = aDataSet.getDisplayTime( ds.getEndSampleIndex() );
+ final String startTime = UnitOfTime.format( aDataSet.getTime( ds.getStartSampleIndex() ) );
+ final String endTime = UnitOfTime.format( aDataSet.getTime( ds.getEndSampleIndex() ) );
String eventType = null;
String rxdEvent = null;
@@ -818,7 +819,7 @@ else if ( UARTData.UART_TYPE_TXEVENT == ds.getType() )
tr = aParent.addChild( TR ).addAttribute( "style", "background-color: " + bgColor + ";" );
tr.addChild( TD ).addContent( String.valueOf( i ) );
- tr.addChild( TD ).addContent( aDataSet.getDisplayTime( ds.getStartSampleIndex() ) );
+ tr.addChild( TD ).addContent( UnitOfTime.format( aDataSet.getTime( ds.getStartSampleIndex() ) ) );
tr.addChild( TD ).addContent( rxEventData );
tr.addChild( TD );
tr.addChild( TD );
@@ -862,7 +863,7 @@ else if ( UARTData.UART_TYPE_TXEVENT == ds.getType() )
tr = aParent.addChild( TR );
tr.addChild( TD ).addContent( String.valueOf( i ) );
- tr.addChild( TD ).addContent( aDataSet.getDisplayTime( ds.getStartSampleIndex() ) );
+ tr.addChild( TD ).addContent( UnitOfTime.format( aDataSet.getTime( ds.getStartSampleIndex() ) ) );
tr.addChild( TD ).addContent( rxDataHex );
tr.addChild( TD ).addContent( rxDataBin );
tr.addChild( TD ).addContent( rxDataDec );
View
85 util/src/main/java/nl/lxtreme/ols/util/DisplayUtils.java
@@ -1,85 +0,0 @@
-/*
- * OpenBench LogicSniffer / SUMP project
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
- *
- *
- * Copyright (C) 2010-2011 - J.W. Janssen, http://www.lxtreme.nl
- */
-package nl.lxtreme.ols.util;
-
-
-/**
- *
- */
-public final class DisplayUtils
-{
- // INNER TYPES
-
- // CONSTRUCTORS
-
- /**
- * Creates a new DisplayUtils instance (never used).
- */
- private DisplayUtils()
- {
- // NO-op
- }
-
- // METHODS
-
- /**
- * Returns a percentage as string value.
- *
- * @param aPercentage
- * the percentage, >= 0.0 and <= 1.0.
- * @return a percentage display value, like "59.3%", neer <code>null</code>.
- */
- public static String displayPercentage( final double aPercentage )
- {
- return String.format( "%.1f%%", Double.valueOf( aPercentage * 100.0 ) );
- }
-
- /**
- * Returns the ordinal representation (in English) of the given value.
- *
- * @param aValue
- * the value to get the ordinal value for, >= 0 && < 40.
- * @return a ordinal number representation of the given value, like "1st".
- */
- public static String getOrdinalNumber( final int aValue )
- {
- String suffix = "";
- if ( ( aValue == 1 ) || ( aValue == 21 ) || ( aValue == 31 ) )
- {
- suffix = "st";
- }
- else if ( ( aValue == 2 ) || ( aValue == 22 ) )
- {
- suffix = "nd";
- }
- else if ( ( aValue == 3 ) || ( aValue == 23 ) )
- {
- suffix = "rd";
- }
- else if ( ( aValue >= 0 ) && ( aValue < 40 ) )
- {
- suffix = "th";
- }
- return String.format( "%d%s", Integer.valueOf( aValue ), suffix );
- }
-}
-
-/* EOF */
View
102 util/src/test/java/nl/lxtreme/ols/util/DisplayUtilsTest.java
@@ -1,102 +0,0 @@
-/*
- * OpenBench LogicSniffer / SUMP project
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
- *
- *
- * Copyright (C) 2010-2011 - J.W. Janssen, http://www.lxtreme.nl
- */
-package nl.lxtreme.ols.util;
-
-
-import org.junit.*;
-
-import java.util.*;
-
-
-/**
- *
- */
-public class DisplayUtilsTest
-{
- // METHODS
-
- /**
- * Sets up the tests.
- */
- @Before
- public void setUp()
- {
- // To ensure formatting occurs deterministically...
- Locale.setDefault( Locale.ENGLISH );
- }
-
- /**
- * Test method for
- * {@link nl.lxtreme.ols.util.DisplayUtils#displayFrequency(double)}.
- */
- @Test
- public void testDisplayFrequency()
- {
- // assertEquals( "0.001 Hz", DisplayUtils.displayFrequency( 1.0e-3 ) );
- // assertEquals( "1.000 Hz", DisplayUtils.displayFrequency( 1.0 ) );
- // assertEquals( "1.000 kHz", DisplayUtils.displayFrequency( 1.0e3 ) );
- // assertEquals( "1.000 MHz", DisplayUtils.displayFrequency( 1.0e6 ) );
- // assertEquals( "1.000 GHz", DisplayUtils.displayFrequency( 1.0e9 ) );
- // assertEquals( "1.000 THz", DisplayUtils.displayFrequency( 1.0e12 ) );
- // assertEquals( "100.000 THz", DisplayUtils.displayFrequency( 1.0e14 ) );
- //
- // assertEquals( "333.333 kHz", DisplayUtils.displayFrequency(
- // 333333.3333333333 ) );
- // assertEquals( "0.000 Hz", DisplayUtils.displayFrequency( 0 ) );
- }
-
- /**
- * Test method for
- * {@link nl.lxtreme.ols.util.DisplayUtils#displayTime(double)}.
- */
- @Test
- public void testDisplayTime()
- {
- // assertEquals( "1000.000 s", DisplayUtils.displayTime( 1.0e3 ) );
- // assertEquals( "1.000 s", DisplayUtils.displayTime( 1.0 ) );
- // assertEquals( "1.000 ms", DisplayUtils.displayTime( 1.0e-3 ) );
- // assertEquals( "1.000 \u03BCs", DisplayUtils.displayTime( 1.0e-6 ) );
- // assertEquals( "1.000 ns", DisplayUtils.displayTime( 1.0e-9 ) );
- // assertEquals( "1.000 ps", DisplayUtils.displayTime( 1.0e-12 ) );
- // assertEquals( "10.000 fs", DisplayUtils.displayTime( 1.0e-14 ) );
- // assertEquals( "1.000 fs", DisplayUtils.displayTime( 1.0e-15 ) );
- //
- // assertEquals( "333.333 ms", DisplayUtils.displayTime( 0.3333333333333333
- // ) );
- // assertEquals( "-40.000 ns", DisplayUtils.displayTime( -4.0E-8 ) );
- // assertEquals( "0.000 s", DisplayUtils.displayTime( 1.0e-16 ) );
- }
-
- /**
- * Test method for
- * {@link nl.lxtreme.ols.util.DisplayUtils#displayTime(double,int)}.
- */
- @Test
- public void testDisplayTimeWithVariablePrecision()
- {
- // assertEquals( "1000.0 s", DisplayUtils.displayTime( 1.0e3, 1, " " ) );
- // assertEquals( "1s", DisplayUtils.displayTime( 1.0, 0, "" ) );
- // assertEquals( "1.000000 ms", DisplayUtils.displayTime( 1.0e-3, 6, " " )
- // );
- }
-}
-
-/* EOF */

0 comments on commit a3bb93f

Please sign in to comment.