use of com.mucommander.ui.layout.InformationPane 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.layout.InformationPane in project mucommander by mucommander.
the class CheckVersionDialog method run.
/**
* Checks for updates and notifies the user of the outcome.
*/
public void run() {
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
String message;
String title;
VersionChecker version;
URL downloadURL = null;
boolean downloadOption = false;
String jarURL = null;
try {
LOGGER.debug("Checking for new version...");
version = VersionChecker.getInstance();
// A newer version is available
if (version.isNewVersionAvailable()) {
LOGGER.info("A new version is available!");
title = Translator.get("version_dialog.new_version_title");
// Checks if the current platform can open a new browser window
downloadURL = new URL(version.getDownloadURL());
downloadOption = DesktopManager.isOperationSupported(DesktopManager.BROWSE, new Object[] { downloadURL });
// display the download URL.
if (downloadOption) {
message = Translator.get("version_dialog.new_version");
} else {
message = Translator.get("version_dialog.new_version_url", downloadURL.toString());
}
jarURL = version.getJarURL();
} else // We're already running latest version
{
LOGGER.debug("No new version.");
// we do not need to inform the user that he already has the latest version
if (!userInitiated) {
dispose();
return;
}
title = Translator.get("version_dialog.no_new_version_title");
message = Translator.get("version_dialog.no_new_version");
}
}// Check failed
catch (Exception e) {
// we do not need to inform the user that the check failed
if (!userInitiated) {
dispose();
return;
}
title = Translator.get("version_dialog.not_available_title");
message = Translator.get("version_dialog.not_available");
}
// Set title
setTitle(title);
List<DialogAction> actions = new ArrayList<>();
actions.add(CheckVersionAction.OK);
// 'Go to website' choice (if available)
if (downloadOption) {
actions.add(CheckVersionAction.GO_TO_WEBSITE);
}
// // 'Install and restart' choice (if available)
// if(jarURL!=null) {
// actionsV.add(new Integer(INSTALL_AND_RESTART_ACTION));
// labelsV.add(Translator.get("version_dialog.install_and_restart"));
// }
init(new InformationPane(message, null, Font.PLAIN, InformationPane.INFORMATION_ICON), actions, 0);
JCheckBox showNextTimeCheckBox = new JCheckBox(Translator.get("prefs_dialog.check_for_updates_on_startup"), MuConfigurations.getPreferences().getVariable(MuPreference.CHECK_FOR_UPDATE, MuPreferences.DEFAULT_CHECK_FOR_UPDATE));
addComponent(showNextTimeCheckBox);
setMinimumSize(MINIMUM_DIALOG_DIMENSION);
// Show dialog and get user action
DialogAction action = getActionValue();
if (action == CheckVersionAction.GO_TO_WEBSITE) {
try {
DesktopManager.executeOperation(DesktopManager.BROWSE, new Object[] { downloadURL });
} catch (Exception e) {
InformationDialog.showErrorDialog(this);
}
} else if (action == CheckVersionAction.INSTALL_AND_RESTART) {
ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("Installing new version"));
SelfUpdateJob job = new SelfUpdateJob(progressDialog, mainFrame, FileFactory.getFile(jarURL));
progressDialog.start(job);
}
// Remember user preference
MuConfigurations.getPreferences().setVariable(MuPreference.CHECK_FOR_UPDATE, showNextTimeCheckBox.isSelected());
}
use of com.mucommander.ui.layout.InformationPane in project mucommander by mucommander.
the class FileCollisionDialog method init.
private void init(int collisionType, AbstractFile sourceFile, AbstractFile destFile, boolean multipleFilesMode, boolean allowRename) {
// Init choices
List<DialogAction> actionChoices = new ArrayList<>();
actionChoices.add(FileCollisionAction.CANCEL);
if (multipleFilesMode) {
actionChoices.add(FileCollisionAction.SKIP);
}
// Add 'overwrite' / 'overwrite if older' / 'resume' actions only for 'destination file already exists' collision type
if (collisionType == FileCollisionChecker.DESTINATION_FILE_ALREADY_EXISTS && !destFile.isDirectory()) {
actionChoices.add(FileCollisionAction.OVERWRITE);
if (sourceFile != null) {
actionChoices.add(FileCollisionAction.OVERWRITE_IF_OLDER);
actionChoices.add(FileCollisionAction.OVERWRITE_IF_SIZE_DIFFERS);
// Give resume option only if destination file is smaller than source file
long destSize = destFile.getSize();
long sourceSize = sourceFile.getSize();
if (destSize != -1 && (sourceSize == -1 || destSize < sourceSize)) {
actionChoices.add(FileCollisionAction.RESUME);
}
if (allowRename) {
actionChoices.add(FileCollisionAction.RENAME);
}
}
}
// Init UI
String desc = null;
switch(collisionType) {
case FileCollisionChecker.DESTINATION_FILE_ALREADY_EXISTS:
desc = Translator.get("file_exists_in_destination");
break;
case FileCollisionChecker.SAME_SOURCE_AND_DESTINATION:
desc = Translator.get("same_source_destination");
break;
case FileCollisionChecker.SOURCE_PARENT_OF_DESTINATION:
desc = Translator.get("source_parent_of_destination");
break;
}
YBoxPanel yPanel = new YBoxPanel();
if (desc != null) {
yPanel.add(new InformationPane(desc, null, Font.PLAIN, InformationPane.QUESTION_ICON));
yPanel.addSpace(10);
}
// Add a separator before file details
yPanel.add(new JSeparator());
XAlignedComponentPanel tfPanel = new XAlignedComponentPanel(10);
// If collision type is 'same source and destination' no need to show both source and destination
if (collisionType == FileCollisionChecker.SAME_SOURCE_AND_DESTINATION) {
addFileDetails(tfPanel, sourceFile, Translator.get("name"));
} else {
if (sourceFile != null) {
addFileDetails(tfPanel, sourceFile, Translator.get("source"));
}
addFileDetails(tfPanel, destFile, Translator.get("destination"));
}
yPanel.add(tfPanel);
// Add a separator after file details
yPanel.add(new JSeparator());
init(yPanel, actionChoices, 3);
// TODO below there's workaround to accommodate texts within buttons - any idea to how to make it better?
// override to avoid FocusDialog#pack making the dialog box too small for some buttons
// so they won't display full texts (observe when Spanish lang pack is chosen - a lot of them have ellipsis)
setMinimumSize(null);
setMaximumSize(null);
// 'Apply to all' is available only for 'destination file already exists' collision type
if (multipleFilesMode && collisionType == FileCollisionChecker.DESTINATION_FILE_ALREADY_EXISTS) {
applyToAllCheckBox = new JCheckBox(Translator.get("apply_to_all"));
addComponent(applyToAllCheckBox);
}
// Send a system notification if a notifier is available and enabled
if (NotifierProvider.isAvailable() && NotifierProvider.getNotifier().isEnabled()) {
NotifierProvider.displayBackgroundNotification(NotificationType.JOB_ERROR, getTitle(), desc);
}
}
Aggregations