public void startup(final Display display, Dictionary<String, String> properties) throws Exception {
// pivot.wtk.Theme.setTheme(new pivot.wtk.skin.terra.TerraTheme("test"));
WTKXSerializer wtkxSerializer = new WTKXSerializer();
Component content = (Component)wtkxSerializer.readObject("pivot/tutorials/demo.wtkx");
// Text
PlainTextSerializer plainTextSerializer = new PlainTextSerializer("UTF-8");
InputStream inputStream = getClass().getResourceAsStream("text_area.txt");
Document document = null;
try {
document = plainTextSerializer.readObject(inputStream);
} catch(Exception exception) {
System.out.println(exception);
}
TextArea textArea = (TextArea)wtkxSerializer.getObjectByName("text.textArea");
textArea.setDocument(document);
final WatermarkDecorator watermarkDecorator = new WatermarkDecorator("Preview");
watermarkDecorator.setOpacity(0.1f);
watermarkDecorator.setFont(watermarkDecorator.getFont().deriveFont(Font.BOLD, 24));
textArea.getDecorators().add(watermarkDecorator);
textArea.getComponentStateListeners().add(new ComponentStateListener() {
public void enabledChanged(Component component) {
// No-op
}
public void focusedChanged(Component component, boolean temporary) {
component.getDecorators().remove(watermarkDecorator);
component.getComponentStateListeners().remove(this);
}
});
new Action("selectImageAction") {
public String getDescription() {
return "Select Image Action";
}
public void perform() {
Button.Group imageMenuGroup = Button.getGroup("imageMenuGroup");
Button selectedItem = imageMenuGroup.getSelection();
String imageName = (String)selectedItem.getUserData();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL imageURL = classLoader.getResource(imageName);
// If the image has not been added to the resource cache yet,
// add it
Image image = (Image)ApplicationContext.getResourceCache().get(imageURL);
if (image == null) {
image = Image.load(imageURL);
ApplicationContext.getResourceCache().put(imageURL, image);
}
// Update the image
menuImageView.setImage(image);
}
};
ListView iconListView = (ListView)wtkxSerializer.getObjectByName("lists.iconListView");
iconListView.setItemDisabled(3, true);
iconListView.setItemDisabled(4, true);
ListView checkedListView = (ListView)wtkxSerializer.getObjectByName("lists.checkedListView");
checkedListView.setItemChecked(0, true);
checkedListView.setItemChecked(2, true);
checkedListView.setItemChecked(3, true);
menuImageView = (ImageView)wtkxSerializer.getObjectByName("menus.imageView");
menuImageView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
if (button == Mouse.Button.RIGHT) {
menuPopup.open(display, component.mapPointToAncestor(display, x, y));
}
return false;
}
public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
return false;
}
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
return false;
}
});
// Spinners
Spinner numericSpinner = (Spinner)wtkxSerializer.getObjectByName("spinners.numericSpinner");
initializeNumericSpinner(numericSpinner);
Spinner dateSpinner = (Spinner)wtkxSerializer.getObjectByName("spinners.dateSpinner");
initializeDateSpinner(dateSpinner);
// Sliders
SliderValueListener sliderValueListener = new SliderValueListener() {
public void valueChanged(Slider slider, int previousValue) {
Color color = new Color(redSlider.getValue(), greenSlider.getValue(),
blueSlider.getValue());
colorBorder.getStyles().put("backgroundColor", color);
}
};
redSlider = (Slider)wtkxSerializer.getObjectByName("spinners.redSlider");
redSlider.getSliderValueListeners().add(sliderValueListener);
greenSlider = (Slider)wtkxSerializer.getObjectByName("spinners.greenSlider");
greenSlider.getSliderValueListeners().add(sliderValueListener);
blueSlider = (Slider)wtkxSerializer.getObjectByName("spinners.blueSlider");
blueSlider.getSliderValueListeners().add(sliderValueListener);
Color color = new Color(redSlider.getValue(), greenSlider.getValue(),
blueSlider.getValue());
colorBorder = (Border)wtkxSerializer.getObjectByName("spinners.colorBorder");
colorBorder.getStyles().put("backgroundColor", color);
sortableTableView = (TableView)wtkxSerializer.getObjectByName("tables.sortableTableView");
sortableTableViewHeader = (TableViewHeader)wtkxSerializer.getObjectByName("tables.sortableTableViewHeader");
customTableView = (TableView)wtkxSerializer.getObjectByName("tables.customTableView");
initializeTableViews();
DragSource imageDragSource = new DragSource() {
private Image image = null;
private Point offset = null;
private LocalManifest content = null;
public boolean beginDrag(Component component, int x, int y) {
ImageView imageView = (ImageView)component;
image = imageView.getImage();
if (image != null) {
imageView.setImage((Image)null);
content = new LocalManifest();
content.putImage(image);
offset = new Point(x - (imageView.getWidth() - image.getWidth()) / 2,
y - (imageView.getHeight() - image.getHeight()) / 2);
}
return (image != null);