use of com.mucommander.ui.dialog.DialogAction in project mucommander by mucommander.
the class EditorRegistrar method registerFileEditors.
/**
* Registers all available editor services for the given file type.
*
* @param file the file that will be displayed by the returned FileEditor
* @param presenter file editor presenter to register to
* @param frame the frame in which the FileEditor is shown
* @return number of editor services registered
* @throws UserCancelledException if the user has been asked to confirm the
* operation and canceled
*/
public static int registerFileEditors(AbstractFile file, FileEditorPresenter presenter, EditorFrame frame) throws UserCancelledException {
int counter = 0;
boolean editorCanceled = false;
List<FileEditorService> editorServices = FileEditorServiceTracker.getEditorServices();
for (FileEditorService service : editorServices) {
try {
if (service.canEditFile(file)) {
presenter.addEditorService(service);
counter++;
}
} catch (WarnUserException e) {
QuestionDialog dialog = new QuestionDialog((Frame) null, Translator.get("warning"), Translator.get(e.getMessage()), frame.getMainFrame(), Arrays.asList(EditorRegistrarAction.OPEN_ANYWAY, EditorRegistrarAction.CANCEL), 0);
DialogAction ret = dialog.getActionValue();
if (ret == EditorRegistrarAction.CANCEL || ret == DIALOG_DISPOSED_ACTION) {
// User canceled the operation
editorCanceled = true;
} else {
// User confirmed the operation
presenter.addEditorService(service);
counter++;
}
}
}
if (counter == 0 && editorCanceled) {
throw new UserCancelledException();
}
return counter;
}
use of com.mucommander.ui.dialog.DialogAction in project mucommander by mucommander.
the class ViewerRegistrar method registerFileViewers.
/**
* Registers all available viewer services for the given file type.
*
* @param file the file that will be displayed by the returned FileViewer
* @param presenter file viewer presenter to register to
* @return number of viewer services registered
* @throws UserCancelledException if the user has been asked to confirm the
* operation and canceled
*/
public static int registerFileViewers(AbstractFile file, FileViewerPresenter presenter, ViewerFrame viewerFrame) throws UserCancelledException {
int counter = 0;
boolean viewerCanceled = false;
List<FileViewerService> viewerServices = FileViewerServiceTracker.getViewerServices();
for (FileViewerService service : viewerServices) {
try {
if (service.canViewFile(file)) {
presenter.addViewerService(service);
counter++;
}
} catch (WarnUserException e) {
// TODO: question the user how does he want to open the file (as image, text..)
// Todo: display a proper warning dialog with the appropriate icon
QuestionDialog dialog = new QuestionDialog((Frame) null, Translator.get("warning"), Translator.get(e.getMessage()), viewerFrame.getMainFrame(), Arrays.asList(ViewerRegistrarAction.OPEN_ANYWAY, ViewerRegistrarAction.CANCEL), 0);
DialogAction ret = dialog.getActionValue();
if (ret == ViewerRegistrarAction.CANCEL || ret == DIALOG_DISPOSED_ACTION) {
// User canceled the operation
viewerCanceled = true;
} else {
// User confirmed the operation
presenter.addViewerService(service);
counter++;
}
}
}
if (counter == 0 && viewerCanceled) {
throw new UserCancelledException();
}
return counter;
}
use of com.mucommander.ui.dialog.DialogAction 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.dialog.DialogAction in project mucommander by mucommander.
the class AppearancePanel method importLookAndFeelLibrary.
/**
* Tries to import the specified library in the extensions folder.
* <p>
* If there is already a file with the same name in the extensions folder,
* this method will ask the user for confirmation before overwriting it.
* </p>
*
* @param library library to import in the extensions folder.
* @return <code>true</code> if the library was imported, <code>false</code> if the user cancelled the operation.
* @throws IOException if an I/O error occurred while importing the library
*/
private boolean importLookAndFeelLibrary(AbstractFile library) throws IOException {
// Tries to import the file, but if a version of it is already present in the extensions folder,
// asks the user for confirmation.
AbstractFile destFile = ExtensionManager.getExtensionsFile(library.getName());
int collision = FileCollisionChecker.checkForCollision(library, destFile);
if (collision != FileCollisionChecker.NO_COLLISION) {
// Do not offer the multiple files mode options such as 'skip' and 'apply to all'
DialogAction action = new FileCollisionDialog(parent, parent, collision, library, destFile, false, false).getActionValue();
// User chose to overwrite the file
if (action == FileCollisionDialog.FileCollisionAction.OVERWRITE) {
// Simply continue and file will be overwritten
} else if (action == FileCollisionDialog.FileCollisionAction.OVERWRITE_IF_OLDER) {
// Overwrite if the source is more recent than the destination
if (library.getDate() <= destFile.getDate()) {
return false;
}
// Simply continue and file will be overwritten
} else if (action == FileCollisionDialog.FileCollisionAction.OVERWRITE_IF_SIZE_DIFFERS) {
// Overwrite if the source and target file size differs
if (library.getSize() == destFile.getSize()) {
return false;
}
// Simply continue and file will be overwritten
} else // User chose to cancel or closed the dialog
{
return false;
}
}
return ExtensionManager.importLibrary(library, true);
}
use of com.mucommander.ui.dialog.DialogAction in project mucommander by mucommander.
the class AppearancePanel method exportTheme.
/**
* Exports the specified theme.
*
* @param theme theme to export.
*/
private void exportTheme(Theme theme) {
JFileChooser chooser;
AbstractFile file;
chooser = createFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.addChoosableFileFilter(new ExtensionFileFilter("xml", Translator.get("prefs_dialog.xml_file")));
chooser.setDialogTitle(Translator.get("prefs_dialog.export_theme", theme.getName()));
if (chooser.showDialog(parent, Translator.get("prefs_dialog.export")) == JFileChooser.APPROVE_OPTION) {
file = FileFactory.getFile(chooser.getSelectedFile().getAbsolutePath());
lastSelectedFolder = file.getParent();
// Makes sure the file's extension is .xml.
try {
if (// Note: getExtension() may return null if no extension
!"xml".equalsIgnoreCase(file.getExtension()))
file = lastSelectedFolder.getDirectChild(file.getName() + ".xml");
int collision = FileCollisionChecker.checkForCollision(null, file);
if (collision != FileCollisionChecker.NO_COLLISION) {
// Do not offer the multiple files mode options such as 'skip' and 'apply to all'
DialogAction action = new FileCollisionDialog(parent, parent, collision, null, file, false, false).getActionValue();
// User chose to overwrite the file
if (action == FileCollisionDialog.FileCollisionAction.OVERWRITE) {
// Simply continue and file will be overwritten
} else // User chose to cancel or closed the dialog
{
return;
}
}
// Exports the theme.
ThemeManager.exportTheme(theme, (java.io.File) file.getUnderlyingFileObject());
// changes.
if (lastSelectedFolder.equals(ThemeManager.getCustomThemesFolder()))
populateThemes(theme);
}// Notifies users of errors.
catch (Exception exception) {
InformationDialog.showErrorDialog(this, Translator.get("write_error"), Translator.get("cannot_write_file", file.getName()));
}
}
}
Aggregations