Search in sources :

Example 11 with Display

use of org.apache.pivot.wtk.Display in project pivot by apache.

the class TerraMenuPopupSkin method windowOpened.

@Override
public void windowOpened(Window window) {
    super.windowOpened(window);
    Display display = window.getDisplay();
    display.getContainerMouseListeners().add(displayMouseListener);
    MenuPopup menuPopup = (MenuPopup) window;
    Menu menu = menuPopup.getMenu();
    if (menu != null) {
        Menu.Item activeItem = menu.getActiveItem();
        if (activeItem != null) {
            activeItem.setActive(false);
        }
        menu.requestFocus();
    }
    panorama.setScrollTop(0);
    // Always ensure that the menu popup fits on the display.
    ApplicationContext.queueCallback(repositionCallback);
}
Also used : MenuPopup(org.apache.pivot.wtk.MenuPopup) Menu(org.apache.pivot.wtk.Menu) Display(org.apache.pivot.wtk.Display)

Example 12 with Display

use of org.apache.pivot.wtk.Display in project pivot by apache.

the class SheetTest method startup.

@SuppressWarnings("unused")
@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
    Picture picture = (Picture) Image.load(getClass().getResource("IMG_0767_2.jpg"));
    picture.resample(120);
    BoxPane windowContent = new BoxPane();
    PushButton button = new PushButton(picture);
    button.getStyles().put(Style.toolbar, true);
    windowContent.add(button);
    frame = new Frame(windowContent);
    frame.setPreferredSize(480, 360);
    frame.getStyles().put(Style.padding, 0);
    frame.open(display);
    final TablePane tablePane = new TablePane();
    tablePane.setPreferredSize(320, 240);
    new TablePane.Column(tablePane, 1, true);
    TablePane.Row row0 = new TablePane.Row(tablePane, 1, true);
    TablePane.Row row1 = new TablePane.Row(tablePane, -1);
    final Label sheetContent = new Label("Sheet Content");
    sheetContent.getStyles().put(Style.wrapText, true);
    sheetContent.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
    sheetContent.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    row0.add(sheetContent);
    Label promptBody = new Label("Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
    promptBody.getStyles().put(Style.wrapText, true);
    final Prompt prompt = new Prompt(MessageType.INFO, "Prompt", new ArrayList<>("OK"), promptBody);
    prompt.setTitle("Prompt");
    prompt.getStyles().put(Style.resizable, true);
    prompt.getComponentMouseListeners().add(new ComponentMouseListener() {

        @Override
        public void mouseOver(Component component) {
            System.out.println("Mouse Over");
        }

        @Override
        public void mouseOut(Component component) {
            System.out.println("Mouse out");
        }
    });
    Label alertBody = new Label("Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
    alertBody.getStyles().put(Style.wrapText, true);
    final Alert alert = new Alert(MessageType.INFO, "Alert", new ArrayList<>("OK"), alertBody);
    alert.setTitle("Alert");
    BoxPane boxPane = new BoxPane();
    row1.add(boxPane);
    boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.RIGHT);
    final PushButton closeButton = new PushButton("Close");
    closeButton.getStyles().put(Style.minimumAspectRatio, 3);
    boxPane.add(closeButton);
    sheet = new Sheet(tablePane);
    closeButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button buttonArgument) {
            buttonArgument.getWindow().close();
        }
    });
    button.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button buttonArgument) {
            prompt.open(frame);
            Display displayLocal = DesktopApplicationContext.createDisplay(640, 480, 100, 100, true, true, false, buttonArgument.getDisplay().getHostWindow(), null);
            Window window = new Window();
            window.setTitle("New Secondary Window");
            window.setMaximized(true);
            window.setContent(new Label("I am a secondary window!"));
            window.open(displayLocal);
        }
    });
    sheet.getWindowStateListeners().add(new WindowStateListener() {

        @Override
        public void windowOpened(Window window) {
            closeButton.requestFocus();
        }
    });
    DesktopApplicationContext.sizeHostToFit(frame);
}
Also used : Window(org.apache.pivot.wtk.Window) Frame(org.apache.pivot.wtk.Frame) WindowStateListener(org.apache.pivot.wtk.WindowStateListener) Label(org.apache.pivot.wtk.Label) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) Picture(org.apache.pivot.wtk.media.Picture) Prompt(org.apache.pivot.wtk.Prompt) Alert(org.apache.pivot.wtk.Alert) PushButton(org.apache.pivot.wtk.PushButton) Component(org.apache.pivot.wtk.Component) ComponentMouseListener(org.apache.pivot.wtk.ComponentMouseListener) Sheet(org.apache.pivot.wtk.Sheet) TablePane(org.apache.pivot.wtk.TablePane) Display(org.apache.pivot.wtk.Display)

Example 13 with Display

use of org.apache.pivot.wtk.Display in project pivot by apache.

the class SplashScreenTest method startup.

@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
    File splashFile = new File("org/apache/pivot/tests/splash.png");
    System.out.println("Startup the application at " + new Date());
    System.out.println("To show the Splash Screen, remember to run as a Standard Java Application this way:\n" + "java -splash:" + splashFile.getPath() + " <mainclassname> --preserveSplashScreen=true\n" + "or no splash screen will be shown.");
    // Create a Task that will load a BXML file and simulate some other
    // processing while updating a progress meter on the SplashScreen
    final Task<Void> prepareApplicationTask = new Task<Void>() {

        final SplashScreenProgressOverlay progressOverlay = new SplashScreenProgressOverlay();

        @Override
        public Void execute() throws TaskExecutionException {
            // Load the main BXML
            progressOverlay.increment(0);
            loadBXML(display, 0.1);
            // Simulate other tasks until the progress meter has been filled
            final Random random = new Random();
            while (progressOverlay.getPercentage() < 1.0) {
                // Short random sleep to simulate some processing
                try {
                    Thread.sleep(random.nextInt(50) + 100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                // Update the progress meter by a random amount
                progressOverlay.increment((1 + random.nextInt(10)) / 100.0);
            }
            return null;
        }

        // Load the Pivot UI
        private void loadBXML(final Display displayArgument, final double weight) {
            try {
                ApplicationContext.queueCallback(() -> {
                    Window window = null;
                    try {
                        window = (Window) new BXMLSerializer().readObject(this.getClass().getResource("splash.bxml"));
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    if (window != null) {
                        window.open(displayArgument);
                        progressOverlay.increment(weight);
                    }
                });
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    // Hide the SplashScreen when the Task finishes by making the Pivot host
    // window visible.
    final TaskListener<Void> taskListener = new TaskListener<Void>() {

        @Override
        public void taskExecuted(final Task<Void> task) {
            finished();
        }

        @Override
        public void executeFailed(final Task<Void> task) {
            System.err.println(String.format("Failed\n%s", task.getFault()));
            task.getFault().printStackTrace();
            finished();
        }

        private void finished() {
            DesktopApplicationContext.replaceSplashScreen(display);
        }
    };
    // Run the Task asynchronously
    prepareApplicationTask.execute(new TaskAdapter<>(taskListener));
}
Also used : Window(org.apache.pivot.wtk.Window) Task(org.apache.pivot.util.concurrent.Task) Date(java.util.Date) TaskExecutionException(org.apache.pivot.util.concurrent.TaskExecutionException) Random(java.util.Random) TaskListener(org.apache.pivot.util.concurrent.TaskListener) File(java.io.File) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) Display(org.apache.pivot.wtk.Display)

Example 14 with Display

use of org.apache.pivot.wtk.Display in project pivot by apache.

the class ComponentSkin method tooltipTriggered.

@Override
public void tooltipTriggered(Component componentArgument, int x, int y) {
    String tooltipText = component.getTooltipText();
    if (tooltipText != null) {
        Label tooltipLabel = new Label(tooltipText);
        boolean tooltipWrapText = component.getTooltipWrapText();
        tooltipLabel.getStyles().put(Style.wrapText, tooltipWrapText);
        Tooltip tooltip = new Tooltip(tooltipLabel);
        Display display = component.getDisplay();
        Point location = component.mapPointToAncestor(display, x, y);
        // Ensure that the tooltip stays on screen
        int tooltipX = location.x + 16;
        int tooltipY = location.y;
        int tooltipWidth = tooltip.getPreferredWidth();
        int tooltipHeight = tooltip.getPreferredHeight();
        if (tooltipX + tooltipWidth > display.getWidth()) {
            // the cursor
            if (tooltipY > tooltipHeight) {
                tooltipX = display.getWidth() - tooltipWidth;
            } else {
                tooltipX = location.x - tooltipWidth - 16;
            }
            if (tooltipX < 0) {
                tooltipX = 0;
            }
            // these x adjustments
            if (tooltipX < location.x && tooltipX + tooltipWidth > location.x) {
                tooltipY -= tooltipHeight;
                if (tooltipY < 0) {
                    tooltipY = 0;
                }
            }
        }
        if (tooltipY + tooltipHeight > display.getHeight()) {
            tooltipY -= tooltipHeight;
        }
        tooltip.setLocation(tooltipX, tooltipY);
        tooltip.open(component.getWindow());
    }
}
Also used : Tooltip(org.apache.pivot.wtk.Tooltip) Label(org.apache.pivot.wtk.Label) Point(org.apache.pivot.wtk.Point) Point(org.apache.pivot.wtk.Point) Display(org.apache.pivot.wtk.Display)

Example 15 with Display

use of org.apache.pivot.wtk.Display in project pivot by apache.

the class TableViewRowEditor method close.

@Override
public void close() {
    Display display = getDisplay();
    display.getContainerMouseListeners().remove(displayMouseHandler);
    super.close();
}
Also used : Display(org.apache.pivot.wtk.Display)

Aggregations

Display (org.apache.pivot.wtk.Display)20 Point (org.apache.pivot.wtk.Point)9 Window (org.apache.pivot.wtk.Window)5 Button (org.apache.pivot.wtk.Button)4 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)4 Component (org.apache.pivot.wtk.Component)4 Container (org.apache.pivot.wtk.Container)4 PushButton (org.apache.pivot.wtk.PushButton)4 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 Cursor (org.apache.pivot.wtk.Cursor)3 ListButton (org.apache.pivot.wtk.ListButton)3 Menu (org.apache.pivot.wtk.Menu)3 GradientPaint (java.awt.GradientPaint)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (org.apache.pivot.collections.ArrayList)2 List (org.apache.pivot.collections.List)2 Sequence (org.apache.pivot.collections.Sequence)2 SerializationException (org.apache.pivot.serialization.SerializationException)2 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)2