Created
July 24, 2013 23:33
StackPaneLabelScaleExample -- Example of possible bug with use of StackPane and ScaleDecorator in Apache Pivot 2.0.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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