All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bidib.wizard.mvc.pom.view.PomConfirmDialog Maven / Gradle / Ivy

There is a newer version: 2.0.0-M1
Show newest version
package org.bidib.wizard.mvc.pom.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;

import org.bidib.wizard.dialog.EscapeDialog;
import org.bidib.wizard.locale.Resources;
import org.bidib.wizard.mvc.main.model.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jgoodies.forms.builder.ButtonBarBuilder;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.factories.Borders;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

public class PomConfirmDialog extends EscapeDialog {
    private static final long serialVersionUID = 1L;

    private static final Logger LOGGER = LoggerFactory.getLogger(PomConfirmDialog.class);

    private static final String ENCODED_DIALOG_COLUMN_SPECS = "pref, 10dlu, min(300dlu;pref)";

    private int result = JOptionPane.CANCEL_OPTION;

    public PomConfirmDialog(final Node node, boolean modal, Point itemPosition) {
        super(null, Resources.getString(PomConfirmDialog.class, "title"), modal);
        getContentPane().setLayout(new BorderLayout());

        // JPanel panel = new FormDebugPanel();
        DefaultFormBuilder builder =
            new DefaultFormBuilder(new FormLayout(ENCODED_DIALOG_COLUMN_SPECS,
                "pref, 10dlu, top:35dlu, 5dlu, pref, 5dlu, pref"));
        builder.border(Borders.DIALOG);

        JLabel iconLabel = new JLabel(UIManager.getIcon("OptionPane.warningIcon"));

        int row = 1;
        CellConstraints cc = new CellConstraints();
        builder.add(iconLabel, cc.xywh(1, row, 1, 2));

        JLabel messageLabel = new JLabel(Resources.getString(getClass(), "message-warn"));
        Font font = messageLabel.getFont();
        font = font.deriveFont(16.0f);
        messageLabel.setFont(font);
        messageLabel.setForeground(Color.RED);

        builder.add(messageLabel, cc.xy(3, row));
        row += 2;

        JLabel messageInfoLabel = new JLabel(Resources.getString(getClass(), "message"));
        builder.add(messageInfoLabel, cc.xy(3, row));
        row += 2;

        // buttons
        JButton continueButton = new JButton(Resources.getString(getClass(), "continue"));

        continueButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                fireContinue(node);
            }
        });

        JButton cancel = new JButton(Resources.getString(getClass(), "cancel"));

        cancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                fireCancel();
            }
        });

        JPanel buttons = new ButtonBarBuilder().addGlue().addButton(continueButton, cancel).build();

        builder.add(buttons, cc.xy(3, row));

        getContentPane().add(builder.build());

        pack();
        setLocation(itemPosition);
        setMinimumSize(getSize());
        setVisible(true);
    }

    private void fireContinue(Node node) {
        LOGGER.info("Continue operation selected.");

        result = JOptionPane.YES_OPTION;
    }

    private void fireCancel() {

    }

    public int getResult() {
        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy