Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.PushButton


    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);

        PushButton windowContent = new PushButton(picture);
        windowContent.setPreferredSize(480, 360);

        frame = new Frame(windowContent);
        frame.getStyles().put("padding", 0);
        frame.open(display);

        final TablePane tablePane = new TablePane();
        tablePane.setPreferredSize(320, 240);
        tablePane.getColumns().add(new TablePane.Column(1, true));
        tablePane.getRows().add(new TablePane.Row(1, true));
        tablePane.getRows().add(new TablePane.Row(-1));

        final Label sheetContent = new Label("Sheet Content");
        sheetContent.getStyles().put("wrapText", true);
        sheetContent.getStyles().put("horizontalAlignment", HorizontalAlignment.CENTER);
        sheetContent.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);

        tablePane.getRows().get(0).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("wrapText", true);

        final Prompt prompt = new Prompt(MessageType.INFO, "Prompt", new ArrayList<String>("OK"), promptBody);
        prompt.setTitle("Prompt");

        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("wrapText", true);

        final Alert alert = new Alert(MessageType.INFO, "Alert", new ArrayList<String>("OK"), alertBody);
        alert.setTitle("Alert");

        BoxPane boxPane = new BoxPane();
        tablePane.getRows().get(1).add(boxPane);

        boxPane.getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);

        final PushButton closeButton = new PushButton("Close");
        closeButton.getStyles().put("minimumAspectRatio", 3);
        boxPane.add(closeButton);

        sheet = new Sheet(tablePane);

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

        windowContent.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                // sheet.open(frame);
                prompt.open(frame);
                // alert.open(frame);
            }
        });

        sheet.getWindowStateListeners().add(new WindowStateListener() {
            @Override
            public Vote previewWindowOpen(Window window, Display display) {
                return Vote.APPROVE;
            }

            @Override
            public void windowOpenVetoed(Window window, Vote reason) {
            }

            @Override
            public void windowOpened(Window window) {
                closeButton.requestFocus();
            }

            @Override
            public Vote previewWindowClose(Window window) {
                return Vote.APPROVE;
View Full Code Here


        int preferredWidth = 0;

        if (height == -1) {
            preferredWidth = getPreferredSize().width;
        } else {
            PushButton pushButton = (PushButton)getComponent();
            Button.DataRenderer dataRenderer = pushButton.getDataRenderer();

            dataRenderer.render(pushButton.getButtonData(), pushButton, false);

            // Include padding in constraint
            int contentHeight = height;
            if (contentHeight != -1) {
                contentHeight = Math.max(contentHeight - (padding.top + padding.bottom + 2), 0);
View Full Code Here

        int preferredHeight = 0;

        if (width== -1) {
            preferredHeight = getPreferredSize().height;
        } else {
            PushButton pushButton = (PushButton)getComponent();
            Button.DataRenderer dataRenderer = pushButton.getDataRenderer();

            dataRenderer.render(pushButton.getButtonData(), pushButton, false);

            // Include padding in constraint
            int contentWidth = width;
            if (contentWidth != -1) {
                contentWidth = Math.max(contentWidth - (padding.left + padding.right + 2), 0);
View Full Code Here

        return preferredHeight;
    }

    @Override
    public Dimensions getPreferredSize() {
        PushButton pushButton = (PushButton)getComponent();
        Button.DataRenderer dataRenderer = pushButton.getDataRenderer();

        dataRenderer.render(pushButton.getButtonData(), pushButton, false);

        Dimensions preferredContentSize = dataRenderer.getPreferredSize();

        int preferredWidth = preferredContentSize.width
            + padding.left + padding.right + 2;
View Full Code Here

        return new Dimensions(preferredWidth, preferredHeight);
    }

    @Override
    public void paint(Graphics2D graphics) {
        PushButton pushButton = (PushButton)getComponent();

        int width = getWidth();
        int height = getHeight();

        Color backgroundColor = null;
        Color bevelColor = null;
        Color borderColor = null;

        if (!toolbar
            || highlighted
            || pushButton.isFocused()) {
            if (pushButton.isEnabled()) {
                backgroundColor = this.backgroundColor;
                bevelColor = (pressed
                    || pushButton.isSelected()) ? pressedBevelColor : this.bevelColor;
                borderColor = this.borderColor;
            } else {
                backgroundColor = disabledBackgroundColor;
                bevelColor = disabledBevelColor;
                borderColor = disabledBorderColor;
            }
        }

        // Paint the background
        if (backgroundColor != null
            && bevelColor != null) {
            graphics.setPaint(new GradientPaint(width / 2, 0, bevelColor,
                width / 2, height / 2, backgroundColor));
            graphics.fillRect(0, 0, width, height);
        }

        // Paint the border
        if (borderColor != null) {
            graphics.setPaint(borderColor);
            GraphicsUtilities.drawRect(graphics, 0, 0, width, height);
        }

        // Paint the content
        Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
        dataRenderer.render(pushButton.getButtonData(), pushButton, highlighted);
        dataRenderer.setSize(Math.max(width - (padding.left + padding.right + 2), 0),
            Math.max(getHeight() - (padding.top + padding.bottom + 2), 0));

        Graphics2D contentGraphics = (Graphics2D)graphics.create();
        contentGraphics.translate(padding.left + 1, padding.top + 1);
        contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
        dataRenderer.paint(contentGraphics);
        contentGraphics.dispose();

        // Paint the focus state
        if (pushButton.isFocused()
            && !toolbar) {
            BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND, 1.0f, new float[] {0.0f, 2.0f}, 0.0f);

            graphics.setStroke(dashStroke);
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.PushButton

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.