From 190ec25604e1befa4400b0dc3b0297f55f98397f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 30 May 2008 19:25:07 +0200 Subject: [PATCH] prevent closing when default file is invalid --- src/net/pterodactylus/jsite/gui/FileManager.java | 65 +++++++++++++++--------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index af1637e..c90614a 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -76,7 +76,7 @@ import net.pterodactylus.util.swing.SwingUtils; /** * Manages physical and virtual files in a project. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ public class FileManager extends JDialog implements I18nable, ActionListener, TreeSelectionListener, MouseListener { @@ -155,7 +155,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Creates a new file manager. - * + * * @param swingInterface * The Swing interface * @param project @@ -203,7 +203,19 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * {@inheritDoc} */ + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent e) { + String defaultFile = project.getDefaultFile(); + if ((defaultFile == null) || (defaultFile.length() == 0)) { + /* TODO - i18n */ + JOptionPane.showMessageDialog(FileManager.this, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE); + return; + } + ProjectFile projectFile = project.getFile(defaultFile); + if (projectFile == null) { + JOptionPane.showMessageDialog(FileManager.this, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE); + return; + } setVisible(false); } }; @@ -222,6 +234,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * {@inheritDoc} */ + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { TreePath selectedPath = fileTree.getSelectionPath(); if (selectedPath == null) { @@ -253,6 +266,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr } }; overrideAction = new I18nAction("fileManager.checkbox.overrideActive") { + /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @@ -282,7 +296,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Creates the main panel with the file tree and the file properties. - * + * * @return The mail panel */ private Component createFileManagerPanel() { @@ -361,7 +375,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Creates the button panel. - * + * * @return The button panel */ private Component createButtonPanel() { @@ -403,7 +417,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Checks whether the given mouse event is a popup trigger and occured over * a file. If so, the context menu is shown. - * + * * @param mouseEvent * The mouse event to check */ @@ -425,7 +439,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Finds whether the {@link ProjectFile} given by * projectFileWrapper is hidden. - * + * * @param projectFileWrapper * The wrapped project file * @return true if the file is hidden and should not be @@ -538,7 +552,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Tree cell renderer that takes care of certain display properties for * project-specific stuff. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ private class FileCellRenderer extends DefaultTreeCellRenderer { @@ -600,7 +614,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * TreeModel that is based on {@link Project#getBaseFile()}. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ private class ProjectFileTreeModel implements TreeModel, PropertyChangeListener { @@ -644,7 +658,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Notifies all listeners that a node has changed. - * + * * @param changedProjectFileWrapper * The wrapper around the changed project file */ @@ -658,7 +672,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr currentProjectFileParent = currentProjectFileParent.getParent(); } while (currentProjectFileParent != null); TreeModelEvent treeModelEvent = new TreeModelEvent(this, parentProjectFileWrappers.toArray(), new int[] { getIndexOfChild(projectFileWrappers.get(changedProjectFileParent), changedProjectFileWrapper) }, new Object[] { changedProjectFileWrapper }); - for (TreeModelListener treeModelListener : treeModelListeners) { + for (TreeModelListener treeModelListener: treeModelListeners) { treeModelListener.treeNodesChanged(treeModelEvent); } } @@ -666,12 +680,12 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Notifies all listeners that the tree structure has changed * significantly. - * + * * @see TreeModelListener#treeStructureChanged(TreeModelEvent) * @param newRootNode */ protected void fireTreeStructureChanged(ProjectFileWrapper newRootNode) { - for (TreeModelListener treeModelListener : treeModelListeners) { + for (TreeModelListener treeModelListener: treeModelListeners) { treeModelListener.treeStructureChanged(new TreeModelEvent(this, new Object[] { newRootNode })); } } @@ -682,7 +696,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Sets the new base project file. This causes the model to reload. - * + * * @param baseProjectFile * The new base project file */ @@ -703,7 +717,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Creates {@link ProjectFileWrapper}s for all files below the given * project file. - * + * * @param projectFile * The base project file for all project files to create * wrappers for @@ -711,7 +725,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private void createWrappers(ProjectFile projectFile) { projectFileWrappers.put(projectFile, new ProjectFileWrapper(projectFile)); pathProjectFiles.put(projectFile.getCompletePath(), projectFile); - for (ProjectFile projectFileChild : projectFile.getFiles()) { + for (ProjectFile projectFileChild: projectFile.getFiles()) { if (projectFileChild.isDirectory()) { createWrappers(projectFileChild); } @@ -804,17 +818,20 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ + @SuppressWarnings("synthetic-access") public void propertyChange(PropertyChangeEvent propertyChangeEvent) { if (Project.PROPERTY_DEFAULT_FILE.equals(propertyChangeEvent.getPropertyName())) { - String oldCompletePath = (String) propertyChangeEvent.getOldValue(); + if (propertyChangeEvent.getOldValue() != null) { + String oldCompletePath = (String) propertyChangeEvent.getOldValue(); + ProjectFile oldProjectFile = pathProjectFiles.get(oldCompletePath); + ProjectFileWrapper oldProjectFileWrapper = projectFileWrappers.get(oldProjectFile); + System.out.println("oldProjectFileWrapper: " + oldProjectFileWrapper); + fireTreeNodesChanged(oldProjectFileWrapper); + } String newCompletePath = (String) propertyChangeEvent.getNewValue(); - ProjectFile oldProjectFile = pathProjectFiles.get(oldCompletePath); ProjectFile newProjectFile = pathProjectFiles.get(newCompletePath); - ProjectFileWrapper oldProjectFileWrapper = projectFileWrappers.get(oldProjectFile); ProjectFileWrapper newProjectFileWrapper = projectFileWrappers.get(newProjectFile); - System.out.println("oldProjectFileWrapper: " + oldProjectFileWrapper); System.out.println("newProjectFileWrapper: " + newProjectFileWrapper); - fireTreeNodesChanged(oldProjectFileWrapper); fireTreeNodesChanged(newProjectFileWrapper); /* HACK - swing sucks a bit. */ fileTree.setShowsRootHandles(false); @@ -826,7 +843,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Wrapper around a {@link ProjectFile} that overwrites * {@link Object#toString()} to return the project file’s name. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ private static class ProjectFileWrapper { @@ -839,7 +856,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Creates a new wrapper around a project file. - * + * * @param projectFile * The project file to wrap */ @@ -849,7 +866,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Returns the wrapped project file. - * + * * @return The wrapped project file */ public ProjectFile getProjectFile() { @@ -859,7 +876,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Sets the name override. If the name override is not null * it will be shown insted of the project file’s name. - * + * * @param nameOverride * The name override */ -- 2.7.4