Search in sources :

Example 21 with Label

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);
}
Also used : Frame(org.apache.pivot.wtk.Frame) Label(org.apache.pivot.wtk.Label) DropAction(org.apache.pivot.wtk.DropAction) DragSource(org.apache.pivot.wtk.DragSource) Point(org.apache.pivot.wtk.Point) IOException(java.io.IOException) LocalManifest(org.apache.pivot.wtk.LocalManifest) Manifest(org.apache.pivot.wtk.Manifest) Font(java.awt.Font) LocalManifest(org.apache.pivot.wtk.LocalManifest) Point(org.apache.pivot.wtk.Point) DropTarget(org.apache.pivot.wtk.DropTarget) Component(org.apache.pivot.wtk.Component) Visual(org.apache.pivot.wtk.Visual)

Example 22 with Label

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);
}
Also used : Window(org.apache.pivot.wtk.Window) Spinner(org.apache.pivot.wtk.Spinner) SpinnerSelectionListener(org.apache.pivot.wtk.SpinnerSelectionListener) Label(org.apache.pivot.wtk.Label) NumericSpinnerData(org.apache.pivot.wtk.content.NumericSpinnerData) BoxPane(org.apache.pivot.wtk.BoxPane) TablePane(org.apache.pivot.wtk.TablePane)

Example 23 with Label

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);
            }
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) Button(org.apache.pivot.wtk.Button) Label(org.apache.pivot.wtk.Label) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 24 with Label

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);
}
Also used : TabPane(org.apache.pivot.wtk.TabPane) TabPaneSelectionListener(org.apache.pivot.wtk.TabPaneSelectionListener) Label(org.apache.pivot.wtk.Label)

Example 25 with Label

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);
}
Also used : Window(org.apache.pivot.wtk.Window) Label(org.apache.pivot.wtk.Label) Font(java.awt.Font)

Aggregations

Label (org.apache.pivot.wtk.Label)44 Component (org.apache.pivot.wtk.Component)20 BoxPane (org.apache.pivot.wtk.BoxPane)15 Point (org.apache.pivot.wtk.Point)13 Form (org.apache.pivot.wtk.Form)10 TextInput (org.apache.pivot.wtk.TextInput)8 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)7 FlowPane (org.apache.pivot.wtk.FlowPane)7 IntValidator (org.apache.pivot.wtk.validation.IntValidator)7 TablePane (org.apache.pivot.wtk.TablePane)6 FontRenderContext (java.awt.font.FontRenderContext)5 Rectangle2D (java.awt.geom.Rectangle2D)5 Dimensions (org.apache.pivot.wtk.Dimensions)5 Frame (org.apache.pivot.wtk.Frame)5 Separator (org.apache.pivot.wtk.Separator)5 Color (java.awt.Color)3 Font (java.awt.Font)3 LineMetrics (java.awt.font.LineMetrics)3 IOException (java.io.IOException)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3