Skip to content

Instantly share code, notes, and snippets.

@einnocent
Created July 24, 2013 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einnocent/6075609 to your computer and use it in GitHub Desktop.
Save einnocent/6075609 to your computer and use it in GitHub Desktop.
StackPaneLabelScaleExample -- Example of possible bug with use of StackPane and ScaleDecorator in Apache Pivot 2.0.2
<Window title="Labels" maximized="true" xmlns:bxml="http://pivot.apache.org/bxml"
xmlns="org.apache.pivot.wtk">
<StackPane bxml:id="mainContainer" styles="{backgroundColor:'#cccccc'}">
<!-- sample SVG available at http://upload.wikimedia.org/wikipedia/commons/5/59/Usa_counties_large.svg -->
<ImageView bxml:id="background" image="/Usa_counties_large.svg"
styles="{horizontalAlignment:'left', verticalAlignment:'top', fill:true, preserveAspectRatio:true}" />
<Label bxml:id="countyLabel" text="King County" x="0" y="0"
styles="{font:'Helvetica bold 24', color:'#ff0000', wrapText:true}" />
</StackPane>
</Window>
package com.einnocenttech.zoobac;
import org.apache.pivot.beans.BXMLSerializer;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.ApplicationContext;
import org.apache.pivot.wtk.ApplicationContext.ScheduledCallback;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.Label;
import org.apache.pivot.wtk.Window;
import org.apache.pivot.wtk.effects.ScaleDecorator;
public class StackPaneLabelScaleExample implements Application
{
private Window window = null;
private ScheduledCallback timerCallback = null;
public static void main(String[] args)
{
DesktopApplicationContext.main(StackPaneLabelScaleExample.class, args);
}
static void printLabelInfo(Label label)
{
System.out.println(String.format("Label position: (%d, %d)", label.getX(), label.getY()));
}
@Override
public void startup(Display display, Map<String, String> properties) throws Exception
{
final BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer
.readObject(StackPaneLabelScaleExample.class, "StackPaneLabelScaleExample.bxml");
window.open(display);
final Label label = (Label) bxmlSerializer.getNamespace().get("countyLabel");
printLabelInfo(label);
final ScaleDecorator sd = new ScaleDecorator();
label.getDecorators().add(sd);
timerCallback = ApplicationContext.scheduleRecurringCallback(new Runnable()
{
int count = 0;
@Override
public void run()
{
count++;
float scale = 1F - ((float) count / (float) 10);
System.out.println("count: " + count + "; scale: " + scale);
sd.setScale(scale);
// label.setLocation(100, 100);
label.repaint(true);
printLabelInfo(label);
if (count == 9)
{
timerCallback.cancel();
}
}
}, 1000, 1000);
}
@Override
public boolean shutdown(boolean optional)
{
if (window != null)
{
window.close();
}
return false;
}
@Override
public void suspend()
{
}
@Override
public void resume()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment