Search in sources :

Example 1 with MimeTypeEditorComponent

use of blue.ui.nbutilities.MimeTypeEditorComponent in project blue by kunstmusik.

the class InfoDialog method showInformationDialog.

public static final synchronized void showInformationDialog(Component parent, String information, String title) {
    if (infoText == null) {
        try {
            if (SwingUtilities.isEventDispatchThread()) {
                infoText = new MimeTypeEditorComponent("text/plain");
            } else {
                SwingUtilities.invokeAndWait(() -> infoText = new MimeTypeEditorComponent("text/plain"));
            }
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        } catch (InvocationTargetException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    infoText.setText(information);
    infoText.getJEditorPane().getCaret().setDot(0);
    final JDialog dlg = new JDialog(SwingUtilities.getWindowAncestor(parent));
    dlg.getContentPane().add(infoText);
    dlg.setModal(true);
    dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dlg.setTitle(title);
    final Preferences prefs = NbPreferences.forModule(InfoDialog.class);
    int w = prefs.getInt("infoDialogWidth", 760);
    int h = prefs.getInt("infoDialogHeight", 400);
    dlg.setSize(new Dimension(w, h));
    dlg.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            final Preferences prefs = NbPreferences.forModule(InfoDialog.class);
            prefs.putInt("infoDialogWidth", dlg.getWidth());
            prefs.putInt("infoDialogHeight", dlg.getHeight());
            prefs.putInt("infoDialogX", dlg.getX());
            prefs.putInt("infoDialogY", dlg.getY());
            try {
                prefs.sync();
            } catch (BackingStoreException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    });
    int x = prefs.getInt("infoDialogX", -1);
    int y = prefs.getInt("infoDialogY", -1);
    if (x > 0 && y > 0) {
        dlg.setLocation(x, y);
    } else {
        GUI.centerOnScreen(dlg);
    }
    dlg.setVisible(true);
    infoText.setText("");
}
Also used : WindowEvent(java.awt.event.WindowEvent) MimeTypeEditorComponent(blue.ui.nbutilities.MimeTypeEditorComponent) BackingStoreException(java.util.prefs.BackingStoreException) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) Preferences(java.util.prefs.Preferences) NbPreferences(org.openide.util.NbPreferences) InvocationTargetException(java.lang.reflect.InvocationTargetException) JDialog(javax.swing.JDialog)

Aggregations

MimeTypeEditorComponent (blue.ui.nbutilities.MimeTypeEditorComponent)1 Dimension (java.awt.Dimension)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BackingStoreException (java.util.prefs.BackingStoreException)1 Preferences (java.util.prefs.Preferences)1 JDialog (javax.swing.JDialog)1 NbPreferences (org.openide.util.NbPreferences)1