Author: rwhitcomb Date: Thu Feb 15 23:40:07 2018 New Revision: 1824382 URL: http://svn.apache.org/viewvc?rev=1824382&view=rev Log: PIVOT-1029: Updates to Meter code, including adding the first ever test of a "wtk" Component here: * Meter.setText was firing the listener every time, not only when the text actually changes. * TerraMeterSkin had no methods to set the colors via int indexes into the Theme colors. * Introduce "MeterTest" which basically only test for the listeners being fired at the proper times (that is, when things actually change). * Had to fix the "test" macro in the "build.xml" so that the built .jar files are included in the classpath so that this new Component test will work (otherwise the Theme doesn't get loaded).
Added: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MeterTest.java Modified: pivot/trunk/build.xml pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java Modified: pivot/trunk/build.xml URL: http://svn.apache.org/viewvc/pivot/trunk/build.xml?rev=1824382&r1=1824381&r2=1824382&view=diff ============================================================================== --- pivot/trunk/build.xml (original) +++ pivot/trunk/build.xml Thu Feb 15 23:40:07 2018 @@ -190,6 +190,7 @@ limitations under the License. <junit fork="true" failureproperty="unit.tests.failed"> <classpath> <path refid="classpath.general"/> + <fileset dir="${basedir}" includes="lib/*.jar"/> <dirset dir="${basedir}" includes="**/${folder.bin}"/> <dirset dir="@{project}" includes="test"/> <fileset dir="@{project}" includes="lib/**/*.jar"/> Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java?rev=1824382&r1=1824381&r2=1824382&view=diff ============================================================================== --- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java (original) +++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraMeterSkin.java Thu Feb 15 23:40:07 2018 @@ -300,6 +300,11 @@ public class TerraMeterSkin extends Comp setGridColor(GraphicsUtilities.decodeColor(gridColor, "gridColor")); } + public final void setGridColor(int gridColor) { + Theme theme = currentTheme(); + setGridColor(theme.getColor(gridColor)); + } + public Color getTextColor() { return textColor; } @@ -313,6 +318,11 @@ public class TerraMeterSkin extends Comp setTextColor(GraphicsUtilities.decodeColor(color, "textColor")); } + public final void setTextColor(int color) { + Theme theme = currentTheme(); + setTextColor(theme.getColor(color)); + } + public Color getTextFillColor() { return textFillColor; } @@ -327,6 +337,11 @@ public class TerraMeterSkin extends Comp setTextFillColor(GraphicsUtilities.decodeColor(color, "textFillColor")); } + public final void setTextFillColor(int color) { + Theme theme = currentTheme(); + setTextFillColor(theme.getColor(color)); + } + public float getGridFrequency() { return gridFrequency; } Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java?rev=1824382&r1=1824381&r2=1824382&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Meter.java Thu Feb 15 23:40:07 2018 @@ -60,8 +60,11 @@ public class Meter extends Component { public void setText(String text) { String previousText = this.text; - this.text = text; - meterListeners.textChanged(this, previousText); + if ((previousText == null && text != null) || + (previousText != null && !previousText.equals(text))) { + this.text = text; + meterListeners.textChanged(this, previousText); + } } public Orientation getOrientation() { Added: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MeterTest.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MeterTest.java?rev=1824382&view=auto ============================================================================== --- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MeterTest.java (added) +++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/MeterTest.java Thu Feb 15 23:40:07 2018 @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pivot.wtk.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import org.apache.pivot.wtk.Meter; +import org.apache.pivot.wtk.MeterListener; +import org.apache.pivot.wtk.Orientation; + + +public class MeterTest implements MeterListener { + private int percentChangeCount = 0; + private int textChangeCount = 0; + private int orientationChangeCount = 0; + + @Override + public void percentageChanged(Meter meter, double previousPercentage) { + percentChangeCount++; + } + + @Override + public void textChanged(Meter meter, String previousText) { + textChangeCount++; + } + + @Override + public void orientationChanged(Meter meter) { + orientationChangeCount++; + } + + @Test + public void testListeners() { + Meter meter = new Meter(); + meter.getMeterListeners().add(this); + + // Test all the listeners getting fired as they should + meter.setText("abc"); + meter.setText(null); + meter.setText(null); + meter.setText("123"); + meter.setText("123"); + meter.setOrientation(Orientation.HORIZONTAL); + meter.setOrientation(Orientation.VERTICAL); + meter.setOrientation(Orientation.HORIZONTAL); + meter.setPercentage(0.25); + meter.setPercentage(0.25); + meter.setPercentage(0.5); + meter.setPercentage(0.75); + meter.setPercentage(1.0); + + // Now check for proper listener event counts + assertEquals(percentChangeCount, 4); + assertEquals(textChangeCount, 3); + assertEquals(orientationChangeCount, 2); + } +}