Search in sources :

Example 26 with PushButton

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

the class BackgroundTasks method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    activityIndicator = (ActivityIndicator) namespace.get("activityIndicator");
    executeSynchronousButton = (PushButton) namespace.get("executeSynchronousButton");
    executeAsynchronousButton = (PushButton) namespace.get("executeAsynchronousButton");
    executeSynchronousButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            activityIndicator.setActive(true);
            System.out.println("Starting synchronous task execution.");
            SleepTask sleepTask = new SleepTask();
            String result = null;
            try {
                result = sleepTask.execute();
            } catch (TaskExecutionException exception) {
                System.err.println(exception);
            }
            System.out.println("Synchronous task execution complete: \"" + result + "\"");
            activityIndicator.setActive(false);
        }
    });
    executeAsynchronousButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            activityIndicator.setActive(true);
            setEnabled(false);
            System.out.println("Starting asynchronous task execution.");
            SleepTask sleepTask = new SleepTask();
            TaskListener<String> taskListener = new TaskListener<String>() {

                @Override
                public void taskExecuted(Task<String> task) {
                    activityIndicator.setActive(false);
                    setEnabled(true);
                    System.out.println("Synchronous task execution complete: \"" + task.getResult() + "\"");
                }

                @Override
                public void executeFailed(Task<String> task) {
                    activityIndicator.setActive(false);
                    setEnabled(true);
                    System.err.println(task.getFault());
                }
            };
            sleepTask.execute(new TaskAdapter<>(taskListener));
        }
    });
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TaskExecutionException(org.apache.pivot.util.concurrent.TaskExecutionException) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) TaskAdapter(org.apache.pivot.wtk.TaskAdapter) TaskListener(org.apache.pivot.util.concurrent.TaskListener)

Example 27 with PushButton

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

the class FileBrowserWithCharsetTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BoxPane windowContent = new BoxPane();
    windowContent.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    final Checkbox showHiddenCheckbox = new Checkbox("Show hidden files");
    windowContent.add(showHiddenCheckbox);
    PushButton button = new PushButton("Open File Browser");
    button.getStyles().put(Style.padding, "[2, 4, 2, 4]");
    button.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button buttonArgument) {
            final Window window = Window.getActiveWindow();
            final FileBrowserWithCharsetTest fileBrowserSheet = new FileBrowserWithCharsetTest(FileBrowserSheet.Mode.OPEN);
            fileBrowserSheet.getStyles().put(Style.showHiddenFiles, showHiddenCheckbox.isSelected());
            fileBrowserSheet.open(window, new SheetCloseListener() {

                @Override
                public void sheetClosed(Sheet sheet) {
                    if (sheet.getResult()) {
                        Sequence<File> selectedFiles = fileBrowserSheet.getSelectedFiles();
                        ListView listView = new ListView();
                        listView.setListData(new ArrayList<>(selectedFiles));
                        listView.setSelectMode(ListView.SelectMode.NONE);
                        listView.getStyles().put(Style.backgroundColor, null);
                        Alert.alert(MessageType.INFO, "You selected (charset " + fileBrowserSheet.getCharsetName() + "):", listView, window);
                    } else {
                        Alert.alert(MessageType.INFO, "You didn't select anything.", window);
                    }
                }
            });
        }
    });
    windowContent.add(button);
    frame = new Frame(windowContent);
    frame.setMaximized(true);
    frame.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Frame(org.apache.pivot.wtk.Frame) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) ListView(org.apache.pivot.wtk.ListView) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) Checkbox(org.apache.pivot.wtk.Checkbox) PushButton(org.apache.pivot.wtk.PushButton) Sheet(org.apache.pivot.wtk.Sheet) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) File(java.io.File)

Example 28 with PushButton

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

the class VFSBrowserTest method startup.

@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
    BoxPane windowContent = new BoxPane();
    windowContent.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    final Checkbox showHiddenCheckbox = new Checkbox("Show hidden files");
    windowContent.add(showHiddenCheckbox);
    PushButton button = new PushButton("Open File Browser");
    button.getStyles().put(Style.padding, "[2, 4, 2, 4]");
    button.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(final Button buttonArgument) {
            try {
                final VFSBrowserSheet vfsBrowserSheet = new VFSBrowserSheet(VFSBrowserSheet.Mode.OPEN);
                vfsBrowserSheet.getStyles().put(Style.showHiddenFiles, showHiddenCheckbox.isSelected());
                vfsBrowserSheet.open(frame, new SheetCloseListener() {

                    @Override
                    public void sheetClosed(final Sheet sheet) {
                        if (sheet.getResult()) {
                            Sequence<FileObject> selectedFiles = vfsBrowserSheet.getSelectedFiles();
                            ListView listView = new ListView();
                            listView.setListData(new ArrayList<>(selectedFiles));
                            listView.setSelectMode(ListView.SelectMode.NONE);
                            listView.getStyles().put(Style.backgroundColor, null);
                            Alert.alert(MessageType.INFO, "You selected:", listView, frame);
                        } else {
                            Alert.alert(MessageType.INFO, "You didn't select anything.", frame);
                        }
                    }
                });
            } catch (FileSystemException fse) {
                Alert.alert(MessageType.ERROR, String.format("File System Exception: %1$s", fse.getMessage()), frame);
            }
        }
    });
    windowContent.add(button);
    frame = new Frame(windowContent);
    frame.setMaximized(true);
    frame.open(display);
}
Also used : Frame(org.apache.pivot.wtk.Frame) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) FileSystemException(org.apache.commons.vfs2.FileSystemException) VFSBrowserSheet(org.apache.pivot.wtk.VFSBrowserSheet) ListView(org.apache.pivot.wtk.ListView) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) Checkbox(org.apache.pivot.wtk.Checkbox) FileObject(org.apache.commons.vfs2.FileObject) PushButton(org.apache.pivot.wtk.PushButton) Sheet(org.apache.pivot.wtk.Sheet) VFSBrowserSheet(org.apache.pivot.wtk.VFSBrowserSheet)

Example 29 with PushButton

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

the class DOMInteractionDemo method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BoxPane boxPane = new BoxPane();
    boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
    helloButton = new PushButton("Say Hello");
    boxPane.add(helloButton);
    helloButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            BrowserApplicationContext.eval("sayHello(\"Hello from Pivot!\")", DOMInteractionDemo.this);
        }
    });
    Border border = new Border(boxPane);
    border.getStyles().put(Style.color, 7);
    border.getStyles().put(Style.padding, 5);
    window = new Window(border);
    window.setMaximized(true);
    window.open(display);
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) Window(org.apache.pivot.wtk.Window) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) PushButton(org.apache.pivot.wtk.PushButton) Border(org.apache.pivot.wtk.Border)

Example 30 with PushButton

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

the class ButtonGroupTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.getButtonGroupListeners().add(new ButtonGroupListener() {

        @Override
        public void selectionChanged(ButtonGroup buttonGroupArgument, Button previousSelection) {
            System.out.println("selectionChanged(): previousSelection = " + previousSelection + ", selection = " + buttonGroupArgument.getSelection());
        }

        @Override
        public void buttonAdded(ButtonGroup buttonGroupArgument, Button button) {
            System.out.println("buttonAdded(): " + button);
        }

        @Override
        public void buttonRemoved(ButtonGroup buttonGroupArgument, Button button) {
            System.out.println("buttonRemoved(): " + button);
        }
    });
    BoxPane boxPane = new BoxPane();
    PushButton button1 = new PushButton("One");
    button1.setToggleButton(true);
    button1.setButtonGroup(buttonGroup);
    boxPane.add(button1);
    PushButton button2 = new PushButton("Two");
    button2.setToggleButton(true);
    button2.setButtonGroup(buttonGroup);
    boxPane.add(button2);
    PushButton button3 = new PushButton("Three");
    button3.setToggleButton(true);
    button3.setButtonGroup(buttonGroup);
    boxPane.add(button3);
    PushButton button4 = new PushButton("Four");
    button4.setToggleButton(true);
    button4.setButtonGroup(buttonGroup);
    boxPane.add(button4);
    // button1.setSelected(true);
    // buttonGroup.setSelection(button1);
    // buttonGroup.setSelection(null);
    window = new Window(boxPane);
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) ButtonGroupListener(org.apache.pivot.wtk.ButtonGroupListener)

Aggregations

PushButton (org.apache.pivot.wtk.PushButton)39 Button (org.apache.pivot.wtk.Button)29 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)23 Window (org.apache.pivot.wtk.Window)9 BoxPane (org.apache.pivot.wtk.BoxPane)8 Component (org.apache.pivot.wtk.Component)6 GradientPaint (java.awt.GradientPaint)5 ListButton (org.apache.pivot.wtk.ListButton)5 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)4 Path (org.apache.pivot.collections.Sequence.Tree.Path)3 Checkbox (org.apache.pivot.wtk.Checkbox)3 Frame (org.apache.pivot.wtk.Frame)3 ListView (org.apache.pivot.wtk.ListView)3 Sheet (org.apache.pivot.wtk.Sheet)3 TreeView (org.apache.pivot.wtk.TreeView)3 TreeViewSelectionListener (org.apache.pivot.wtk.TreeViewSelectionListener)3 TreeBranch (org.apache.pivot.wtk.content.TreeBranch)3 File (java.io.File)2 TaskExecutionException (org.apache.pivot.util.concurrent.TaskExecutionException)2 Alert (org.apache.pivot.wtk.Alert)2