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

studio.ui.EscapeDialog Maven / Gradle / Ivy

Go to download

Studio for kdb+ is a rapid development environment for the ultra-fast database kdb+ from Kx Systems: http://www.kx.com.

There is a newer version: dz4.1
Show newest version
package studio.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public abstract class EscapeDialog extends JDialog {

    public enum DialogResult {ACCEPTED, CANCELLED};

    private DialogResult result = DialogResult.CANCELLED;

    public EscapeDialog(Window owner,String title) {
        super(owner,title, ModalityType.APPLICATION_MODAL);
        initComponents();
    }

    public void align() {
        pack();
        Util.centerChildOnParent(this, getParent());
    }

    public void alignAndShow() {
        align();
        setVisible(true);
    }

    private void initComponents() {
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0);
        this.getRootPane().registerKeyboardAction(e->cancel(), stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    }

    public void cancel() {
        result = DialogResult.CANCELLED;
        dispose();
    }

    public void accept() {
        result = DialogResult.ACCEPTED;
        dispose();
    }

    public DialogResult getResult() {
        return result;
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy