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();
}
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();
}
Aggregations