use of com.mucommander.ui.button.CollapseExpandButton 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.ui.button.CollapseExpandButton in project mucommander by mucommander.
the class ProgressDialog method initUI.
private void initUI() {
Container contentPane = getContentPane();
totalProgressBar = new JProgressBar();
totalProgressBar.setStringPainted(true);
totalProgressBar.setAlignmentX(LEFT_ALIGNMENT);
currentFileLabel = new JLabel(job.getStatusString());
currentFileLabel.setAlignmentX(LEFT_ALIGNMENT);
YBoxPanel yPanel = new YBoxPanel();
// 2 progress bars
if (transferFileJob != null) {
yPanel.add(currentFileLabel);
currentFileProgressBar = new JProgressBar();
currentFileProgressBar.setStringPainted(true);
yPanel.add(currentFileProgressBar);
yPanel.addSpace(10);
totalTransferredLabel = new JLabel(Translator.get("progress_dialog.starting"));
yPanel.add(totalTransferredLabel);
yPanel.add(totalProgressBar);
} else // Single progress bar
{
yPanel.add(currentFileLabel);
yPanel.add(totalProgressBar);
}
yPanel.addSpace(10);
elapsedTimeLabel = new JLabel(Translator.get("progress_dialog.elapsed_time") + ": ");
elapsedTimeLabel.setIcon(IconManager.getIcon(IconManager.STATUS_BAR_ICON_SET, StatusBar.WAITING_ICON));
yPanel.add(elapsedTimeLabel);
if (transferFileJob != null) {
JPanel tempPanel = new JPanel(new BorderLayout());
this.currentSpeedLabel = new JLabel();
updateCurrentSpeedLabel("");
currentSpeedLabel.setIcon(IconManager.getIcon(IconManager.PROGRESS_ICON_SET, CURRENT_SPEED_ICON));
tempPanel.add(currentSpeedLabel, BorderLayout.WEST);
YBoxPanel advancedPanel = new YBoxPanel();
this.speedGraph = new SpeedGraph();
speedGraph.setPreferredSize(new Dimension(0, SPEED_GRAPH_HEIGHT));
advancedPanel.add(speedGraph);
advancedPanel.addSpace(5);
JPanel tempPanel2 = new JPanel(new BorderLayout());
this.limitSpeedCheckBox = new JCheckBox(Translator.get("progress_dialog.limit_speed") + ":", false);
limitSpeedCheckBox.addItemListener(this);
tempPanel2.add(limitSpeedCheckBox, BorderLayout.WEST);
speedChooser = new SizeChooser(true);
speedChooser.setEnabled(false);
speedChooser.addChangeListener(this);
tempPanel2.add(speedChooser, BorderLayout.EAST);
advancedPanel.add(tempPanel2);
advancedPanel.addSpace(5);
this.collapseExpandButton = new CollapseExpandButton(Translator.get("progress_dialog.advanced"), advancedPanel, true);
collapseExpandButton.setExpandedState(MuConfigurations.getPreferences().getVariable(MuPreference.PROGRESS_DIALOG_EXPANDED, MuPreferences.DEFAULT_PROGRESS_DIALOG_EXPANDED));
tempPanel.add(collapseExpandButton, BorderLayout.EAST);
yPanel.add(tempPanel);
yPanel.addSpace(5);
yPanel.add(advancedPanel);
}
closeWhenFinishedCheckBox = new JCheckBox(Translator.get("progress_dialog.close_when_finished"));
closeWhenFinishedCheckBox.setSelected(MuConfigurations.getPreferences().getVariable(MuPreference.PROGRESS_DIALOG_CLOSE_WHEN_FINISHED, MuPreferences.DEFAULT_PROGRESS_DIALOG_CLOSE_WHEN_FINISHED));
yPanel.add(closeWhenFinishedCheckBox);
yPanel.add(Box.createVerticalGlue());
contentPane.add(yPanel, BorderLayout.CENTER);
pauseResumeButton = new JButton(Translator.get("pause"), IconManager.getIcon(IconManager.PROGRESS_ICON_SET, PAUSE_ICON));
pauseResumeButton.addActionListener(this);
if (transferFileJob != null) {
skipButton = new JButton(Translator.get("skip"), IconManager.getIcon(IconManager.PROGRESS_ICON_SET, SKIP_ICON));
skipButton.addActionListener(this);
}
stopButton = new JButton(Translator.get("stop"), IconManager.getIcon(IconManager.PROGRESS_ICON_SET, STOP_ICON));
stopButton.addActionListener(this);
hideButton = new JButton(Translator.get("progress_dialog.hide"), IconManager.getIcon(IconManager.PROGRESS_ICON_SET, HIDE_ICON));
hideButton.addActionListener(this);
this.buttonsChoicePanel = new ButtonChoicePanel(skipButton == null ? Arrays.asList(pauseResumeButton, stopButton, hideButton) : Arrays.asList(pauseResumeButton, skipButton, stopButton, hideButton), 0, getRootPane());
contentPane.add(buttonsChoicePanel, BorderLayout.SOUTH);
// Cancel button receives initial focus
setInitialFocusComponent(stopButton);
// Enter triggers cancel button
getRootPane().setDefaultButton(stopButton);
}
Aggregations