X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FFileManager.java;h=953e05dc894ee4e6f5c67510ba4d0b6cda743243;hb=a5fcf3cbb126fe4115ff32d5adc0026f2fcf9e7f;hp=30580236919c743be780434f570b12fad9a6c1c9;hpb=e1e349bae97feb779fc692eb03c2fea0e0e612c9;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index 3058023..953e05d 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -59,9 +59,11 @@ import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JSeparator; +import javax.swing.JSplitPane; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; import javax.swing.event.TreeSelectionEvent; @@ -70,9 +72,9 @@ import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; -import net.pterodactylus.jsite.core.project.FileOverride; -import net.pterodactylus.jsite.core.project.Project; -import net.pterodactylus.jsite.core.project.ProjectFile; +import net.pterodactylus.jsite.core.FileOverride; +import net.pterodactylus.jsite.core.Project; +import net.pterodactylus.jsite.core.ProjectFile; import net.pterodactylus.jsite.i18n.I18n; import net.pterodactylus.jsite.i18n.I18nable; import net.pterodactylus.jsite.i18n.gui.I18nAction; @@ -84,7 +86,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, TreeSelectionListener, MouseListener { @@ -202,7 +204,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Creates a new file manager. - * + * * @param swingInterface * The Swing interface * @param project @@ -254,16 +256,19 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe 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; + int selectedOption = JOptionPane.showOptionDialog(FileManager.this, I18n.get("fileManager.dialog.noDefaultFileSet.message"), I18n.get("fileManager.dialog.noDefaultFileSet.title"), 0, JOptionPane.WARNING_MESSAGE, null, new String[] { I18n.get("general.button.continue.name"), I18n.get("general.button.cancel.name") }, I18n.get("general.button.cancel.name")); + if (selectedOption == 1) { + return; + } + } else { + ProjectFile projectFile = project.getFile(defaultFile); + if (projectFile == null) { + /* TODO - i18n */ + JOptionPane.showMessageDialog(FileManager.this, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE); + return; + } + setVisible(false); } - setVisible(false); } }; rescanAction = new I18nAction("fileManager.button.rescan") { @@ -360,6 +365,8 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe project.removeFileOverride(projectFile); } } + fileTree.setShowsRootHandles(false); + fileTree.repaint(); } }; overrideInsertDefaultAction.setEnabled(false); @@ -399,7 +406,11 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe fileOverride = new FileOverride(); project.addFileOverride(projectFile, fileOverride); } - fileOverride.setContentType(MimeTypes.getMimeType(getFileExtension(projectFile.getName()))); + String projectFileName = projectFile.getName(); + String mimeType = MimeTypes.getMimeType(getFileExtension(projectFileName)); + fileOverride.setContentType(mimeType); + fillComboBox(projectFileName); + contentTypeOverrideComboBox.setSelectedItem(mimeType); } else { fileOverride.setContentType(null); if (fileOverride.isEmpty()) { @@ -408,6 +419,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe } } }; + overrideContentTypeDefaultAction.setEnabled(false); contentTypeOverrideAction = new AbstractAction() { /** @@ -464,15 +476,17 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Creates the main panel with the file tree and the file properties. - * + * * @return The mail panel */ private Component createFileManagerPanel() { - JPanel fileManagerPanel = new JPanel(new BorderLayout(12, 12)); + JSplitPane fileManagerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); + fileManagerPanel.setBorder(null); /* file tree panel */ JPanel fileTreePanel = new JPanel(new BorderLayout(12, 12)); - fileManagerPanel.add(fileTreePanel, BorderLayout.LINE_START); + fileTreePanel.setBorder(new EmptyBorder(0, 0, 0, 12)); + fileManagerPanel.setLeftComponent(fileTreePanel); fileTree = new JTree(fileTreeModel); fileTree.setShowsRootHandles(false); @@ -489,7 +503,8 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /* the right panel */ JPanel rightPanel = new JPanel(new BorderLayout(12, 12)); - fileManagerPanel.add(rightPanel, BorderLayout.CENTER); + rightPanel.setBorder(new EmptyBorder(0, 12, 0, 0)); + fileManagerPanel.setRightComponent(rightPanel); /* properties panel */ JPanel propertiesPanel = new JPanel(new GridBagLayout()); @@ -568,7 +583,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Creates the button panel. - * + * * @return The button panel */ private Component createButtonPanel() { @@ -610,7 +625,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * 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 */ @@ -640,7 +655,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * 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 @@ -726,7 +741,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Returns all currently selected {@link ProjectFileWrapper}s. - * + * * @param filesOnly * true to return only selected files, * false to include directories @@ -750,7 +765,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Sets the given action’s enabled state to the given enabled state if the * action’s current enabled state is not the given enabled state. - * + * * @param action * The action to set the enabled state on * @param enabled @@ -765,7 +780,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Sets the given button’s selected state to the given selected state if the * button’s current selected state is not the given selected state. - * + * * @param button * The button to set the selected state on * @param selected @@ -781,7 +796,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe * Returns the extension of the given filename. If the file name does not * have an extension, the name of the file (without any path components) is * returned. - * + * * @param fileName * The name of the file * @return The extension of the file @@ -794,7 +809,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Repopulates the content type combo box with all content types, putting * the most probably ones to the front of the list. - * + * * @param fileName * The name of the file */ @@ -845,7 +860,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe boolean overrideInsertSelected = false; boolean insertOverrideEnabled = false; boolean insertOverrideSelected = false; - String defaultContentType = MimeTypes.DEFAULT_CONTENT_TYPE; + String defaultContentType = ""; boolean overrideContentTypeEnabled = false; boolean overrideContentTypeSelected = false; boolean contentTypeOverrideEnabled = false; @@ -940,7 +955,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * 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 { @@ -1009,7 +1024,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * TreeModel that is based on {@link Project#getBaseFile()}. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ private class ProjectFileTreeModel implements TreeModel, PropertyChangeListener { @@ -1053,7 +1068,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Notifies all listeners that a node has changed. - * + * * @param changedProjectFileWrapper * The wrapper around the changed project file */ @@ -1075,7 +1090,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Notifies all listeners that the tree structure has changed * significantly. - * + * * @see TreeModelListener#treeStructureChanged(TreeModelEvent) * @param newRootNode */ @@ -1091,7 +1106,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Sets the new base project file. This causes the model to reload. - * + * * @param baseProjectFile * The new base project file */ @@ -1112,7 +1127,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * 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 @@ -1240,7 +1255,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * 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 { @@ -1253,7 +1268,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Creates a new wrapper around a project file. - * + * * @param projectFile * The project file to wrap */ @@ -1263,7 +1278,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * Returns the wrapped project file. - * + * * @return The wrapped project file */ public ProjectFile getProjectFile() { @@ -1273,7 +1288,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * 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 */ @@ -1294,7 +1309,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** * A cell renderer for combo boxes that converts the string “--” to a * separator. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ private class MimeTypeComboBoxRenderer extends DefaultListCellRenderer {