use of org.apache.pivot.wtk.Label in project pivot by apache.
the class NativeDragDropTest method startup.
@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
final Label label = new Label("http://pivot.apache.org/");
label.getStyles().put(Style.font, new Font("Arial", Font.PLAIN, 24));
label.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
label.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
label.setDragSource(new DragSource() {
private LocalManifest content = null;
@Override
public boolean beginDrag(Component component, int x, int y) {
content = new LocalManifest();
content.putText(label.getText());
return true;
}
@Override
public void endDrag(Component component, DropAction dropAction) {
content = null;
}
@Override
public boolean isNative() {
return true;
}
@Override
public LocalManifest getContent() {
return content;
}
@Override
public Visual getRepresentation() {
return null;
}
@Override
public Point getOffset() {
return null;
}
@Override
public int getSupportedDropActions() {
return DropAction.COPY.getMask();
}
});
label.setDropTarget(new DropTarget() {
@Override
public DropAction dragEnter(Component component, Manifest dragContent, int supportedDropActions, DropAction userDropAction) {
DropAction dropAction = null;
if (dragContent.containsText()) {
frame.getStyles().put(Style.backgroundColor, "#ffcccc");
dropAction = DropAction.COPY;
}
return dropAction;
}
@Override
public void dragExit(Component component) {
frame.getStyles().put(Style.backgroundColor, "#ffffff");
}
@Override
public DropAction dragMove(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
return (dragContent.containsText() ? DropAction.COPY : null);
}
@Override
public DropAction userDropActionChange(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
return (dragContent.containsText() ? DropAction.COPY : null);
}
@Override
public DropAction drop(Component component, Manifest dragContent, int supportedDropActions, int x, int y, DropAction userDropAction) {
DropAction dropAction = null;
if (dragContent.containsText()) {
Label labelLocal = (Label) component;
try {
labelLocal.setText(dragContent.getText());
} catch (IOException exception) {
System.err.println(exception);
}
}
dragExit(component);
return dropAction;
}
});
frame = new Frame(label);
frame.open(display);
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class LabelAntialiasTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) {
window = new Window();
showFontDesktopHints();
showFontFamilies();
TablePane content = new TablePane();
new TablePane.Column(content, 1, true);
BoxPane topBox = new BoxPane(Orientation.HORIZONTAL);
topBox.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
topBox.add(new Label("Rotation angle:"));
rotationAngleSpinner = new Spinner(new NumericSpinnerData(0, 359));
rotationAngleSpinner.setCircular(true);
rotationAngleSpinner.setPreferredWidth(40);
topBox.add(rotationAngleSpinner);
TablePane.Row topRow = new TablePane.Row(content, -1);
topRow.add(topBox);
labelRow = new TablePane.Row(content, 1, true);
window.setContent(content);
window.setTitle("Label Antialiasing Test");
window.setMaximized(true);
rotationAngleSpinner.getSpinnerSelectionListeners().add(new SpinnerSelectionListener() {
@Override
public void selectedItemChanged(Spinner spinner, Object previousSelectedItem) {
currentRotationAngle = (Integer) spinner.getSelectedItem();
if (labelRow.getLength() > 0) {
labelRow.remove(0, labelRow.getLength());
}
labelRow.add(buildLabel(currentRotationAngle));
}
});
rotationAngleSpinner.setSelectedItem(45);
window.open(display);
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class DataBindingTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window) bxmlSerializer.readObject(DataBindingTest.class, "data_binding_test.bxml");
window.open(display);
context.put("id1", "1");
context.put("id2", "2");
context.put("id3", "3");
window.getContent().load(context);
final Label textLabel = (Label) (bxmlSerializer.getNamespace().get("bindingDataText"));
textLabel.setText(JSONSerializer.toString(context));
Button storeButton = (Button) (bxmlSerializer.getNamespace().get("storeButton"));
storeButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
window.getContent().store(context);
try {
textLabel.setText(JSONSerializer.toString(context));
textLabel.getStyles().put(Style.color, getNextColor());
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class Pivot751WithoutGUI method main.
public static void main(String[] args) {
final TabPane tabPane = new TabPane();
tabPane.getTabPaneSelectionListeners().add(new TabPaneSelectionListener() {
@Override
public void selectedIndexChanged(TabPane tabPaneArgument, int previousSelectedIndex) {
System.out.println(String.format("tabs : %-16d actual selectedIndex : %d", tabPaneArgument.getTabs().getLength(), tabPaneArgument.getSelectedIndex()));
System.out.println(String.format("indirect : %-16s 'previousSelectedIndex' : %d", (previousSelectedIndex == tabPaneArgument.getSelectedIndex()), previousSelectedIndex));
}
});
System.out.println("Empty TabPane sequence");
System.out.println(String.format("tabs : %-16d actual selectedIndex : %d", tabPane.getTabs().getLength(), tabPane.getSelectedIndex()));
System.out.println("\nAdding first Label to the sequence");
tabPane.getTabs().add(new Label("1"));
System.out.println("\nAdding second Label at the end of the sequence");
tabPane.getTabs().add(new Label("2"));
System.out.println("\nInserting third Label at the start of the sequence");
tabPane.getTabs().insert(new Label("3"), 0);
System.out.println("\nAdding a fourth Label at the end of the sequence");
tabPane.getTabs().add(new Label("4"));
System.out.println("\nExplicitly select the last tab");
tabPane.setSelectedIndex(3);
System.out.println("\nRemoving the first 2 Labels from the start of the sequence");
tabPane.getTabs().remove(0, 2);
System.out.println("\nRemoving the tab at the end of the sequence");
tabPane.getTabs().remove(1, 1);
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class HelloJava method startup.
@Override
public void startup(Display display, Map<String, String> properties) {
this.window = new Window();
Label label = new Label();
label.setText("Hello World!");
label.getStyles().put(Style.font, new Font("Arial", Font.BOLD, 24));
label.getStyles().put(Style.color, Color.RED);
label.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
label.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
this.window.setContent(label);
this.window.setTitle("Hello World!");
this.window.setMaximized(true);
this.window.open(display);
}
Aggregations