Search in sources :

Example 1 with FocusDialog

use of com.mucommander.commons.util.ui.dialog.FocusDialog in project mucommander by mucommander.

the class InformationDialog method showDialog.

/**
 * Brings up a dialog of the specified type and with the specified title, main and caption messages, and stack trace
 * of the specified exception inside an expandable panel.
 *
 * @param dialogType type of dialog, see constant fields for allow values.
 * @param parentComponent determines the <code>Frame</code> in which the dialog is displayed; if <code>null</code>,
 * or if the parentComponent has no <code>Frame</code>, a default <code>Frame</code> is used
 * @param title the dialog's title, <code>null</code> for a generic localized title, if one exists for the
 * dialog type.
 * @param message the main message to display in the dialog, <code>null</code> for a generic localized message, if
 * one exists for the dialog type.
 * @param captionMessage the caption message to display underneath the main message, <code>null</code> for none.
 * @param throwable exception for which to show the stack trace, <code>null</code> for none.
 */
public static void showDialog(int dialogType, Component parentComponent, String title, String message, String captionMessage, Throwable throwable) {
    Window owner = DialogToolkit.getWindowForComponent(parentComponent);
    final FocusDialog dialog;
    if (owner instanceof Frame)
        dialog = new FocusDialog((Frame) owner, title, parentComponent);
    else
        dialog = new FocusDialog((Dialog) owner, title, parentComponent);
    dialog.setMinimumSize(MIN_DIALOG_SIZE);
    dialog.setMaximumSize(MAX_DIALOG_SIZE);
    YBoxPanel mainPanel = new YBoxPanel();
    InformationPane informationPane = new InformationPane(message, captionMessage, captionMessage == null ? Font.PLAIN : Font.BOLD, getInformationPaneIconId(dialogType));
    mainPanel.add(informationPane);
    mainPanel.addSpace(10);
    JButton okButton = new JButton(Translator.get("ok"));
    JPanel okPanel = DialogToolkit.createOKPanel(okButton, dialog.getRootPane(), new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    mainPanel.add(buttonPanel);
    // Show the exception's stack trace in an expandable/collapsible panel
    if (throwable != null) {
        JTextArea detailsArea = new JTextArea();
        detailsArea.setEditable(false);
        // Get the stack trace as a string
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        throwable.printStackTrace(pw);
        pw.close();
        // Fill the area with the stack trace.
        // Tabs by space characters to reduce the text's width
        detailsArea.setText(sw.toString().replace('\t', ' '));
        FontUtils.makeMini(detailsArea);
        JScrollPane scrollPane = new JScrollPane(detailsArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        buttonPanel.add(new CollapseExpandButton(Translator.get("details"), scrollPane, false));
        mainPanel.add(scrollPane);
    }
    buttonPanel.add(Box.createVerticalGlue());
    buttonPanel.add(okPanel);
    dialog.getContentPane().add(mainPanel);
    // Give initial keyboard focus to the 'OK' button
    dialog.setInitialFocusComponent(okButton);
    // Call dispose() when dialog is closed
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.showDialog();
}
Also used : Window(java.awt.Window) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Frame(java.awt.Frame) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) FocusDialog(com.mucommander.commons.util.ui.dialog.FocusDialog) InformationPane(com.mucommander.ui.layout.InformationPane) YBoxPanel(com.mucommander.commons.util.ui.layout.YBoxPanel) ActionListener(java.awt.event.ActionListener) StringWriter(java.io.StringWriter) CollapseExpandButton(com.mucommander.ui.button.CollapseExpandButton) PrintWriter(java.io.PrintWriter)

Example 2 with FocusDialog

use of com.mucommander.commons.util.ui.dialog.FocusDialog in project mucommander by mucommander.

the class BinaryBase method goToPosition.

public void goToPosition() {
    CodeArea codeArea = binaryComponent.getCodeArea();
    FocusDialog dialog = new FocusDialog(windowFrame, Translator.get("binary_viewer.go_to.dialog_title"), windowFrame);
    Container contentPane = dialog.getContentPane();
    GoToBinaryPanel goToPanel = new GoToBinaryPanel();
    goToPanel.setCursorPosition(codeArea.getDataPosition());
    goToPanel.setMaxPosition(codeArea.getDataSize());
    contentPane.add(goToPanel, BorderLayout.CENTER);
    final JButton okButton = new JButton(Translator.get("binary_viewer.go_to.ok"));
    JButton cancelButton = new JButton(Translator.get("cancel"));
    contentPane.add(DialogToolkit.createOKCancelPanel(okButton, cancelButton, dialog.getRootPane(), e -> {
        Object source = e.getSource();
        if (source == okButton) {
            goToPanel.acceptInput();
            long targetPosition = goToPanel.getTargetPosition();
            codeArea.setCaretPosition(targetPosition);
            codeArea.revealCursor();
        }
        dialog.dispose();
    }), BorderLayout.SOUTH);
    SwingUtilities.invokeLater(goToPanel::initFocus);
    dialog.showDialog();
}
Also used : Color(java.awt.Color) EditOperation(org.exbin.bined.EditOperation) CodeType(org.exbin.bined.CodeType) GoToBinaryPanel(com.mucommander.viewer.binary.ui.GoToBinaryPanel) FocusDialog(com.mucommander.commons.util.ui.dialog.FocusDialog) MenuToolkit(com.mucommander.commons.util.ui.helper.MenuToolkit) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) EditMode(org.exbin.bined.EditMode) SwingUtilities(javax.swing.SwingUtilities) Charset(java.nio.charset.Charset) JMenuItem(javax.swing.JMenuItem) MnemonicHelper(com.mucommander.commons.util.ui.helper.MnemonicHelper) CodeArea(org.exbin.bined.swing.basic.CodeArea) FontChangedEvent(com.mucommander.ui.theme.FontChangedEvent) CodeAreaCaretPosition(org.exbin.bined.CodeAreaCaretPosition) ThemeManager(com.mucommander.ui.theme.ThemeManager) EditModeCapable(org.exbin.bined.capability.EditModeCapable) Container(java.awt.Container) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) Translator(com.mucommander.text.Translator) Nonnull(javax.annotation.Nonnull) ColorChangedEvent(com.mucommander.ui.theme.ColorChangedEvent) KeyStroke(javax.swing.KeyStroke) JButton(javax.swing.JButton) DialogToolkit(com.mucommander.commons.util.ui.dialog.DialogToolkit) Theme(com.mucommander.ui.theme.Theme) ButtonGroup(javax.swing.ButtonGroup) JMenu(javax.swing.JMenu) BinaryStatusPanel(com.mucommander.viewer.binary.ui.BinaryStatusPanel) KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) Dimension(java.awt.Dimension) CodeCharactersCase(org.exbin.bined.CodeCharactersCase) ThemeListener(com.mucommander.ui.theme.ThemeListener) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JPanel(javax.swing.JPanel) Container(java.awt.Container) JButton(javax.swing.JButton) FocusDialog(com.mucommander.commons.util.ui.dialog.FocusDialog) GoToBinaryPanel(com.mucommander.viewer.binary.ui.GoToBinaryPanel) CodeArea(org.exbin.bined.swing.basic.CodeArea)

Aggregations

FocusDialog (com.mucommander.commons.util.ui.dialog.FocusDialog)2 JButton (javax.swing.JButton)2 JPanel (javax.swing.JPanel)2 DialogToolkit (com.mucommander.commons.util.ui.dialog.DialogToolkit)1 MenuToolkit (com.mucommander.commons.util.ui.helper.MenuToolkit)1 MnemonicHelper (com.mucommander.commons.util.ui.helper.MnemonicHelper)1 YBoxPanel (com.mucommander.commons.util.ui.layout.YBoxPanel)1 Translator (com.mucommander.text.Translator)1 CollapseExpandButton (com.mucommander.ui.button.CollapseExpandButton)1 InformationPane (com.mucommander.ui.layout.InformationPane)1 ColorChangedEvent (com.mucommander.ui.theme.ColorChangedEvent)1 FontChangedEvent (com.mucommander.ui.theme.FontChangedEvent)1 Theme (com.mucommander.ui.theme.Theme)1 ThemeListener (com.mucommander.ui.theme.ThemeListener)1 ThemeManager (com.mucommander.ui.theme.ThemeManager)1 BinaryStatusPanel (com.mucommander.viewer.binary.ui.BinaryStatusPanel)1 GoToBinaryPanel (com.mucommander.viewer.binary.ui.GoToBinaryPanel)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Container (java.awt.Container)1