X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FFileManager.java;h=56cf245ad369c3b6992095628d6abb28894b3951;hb=29a073fc5c874b55919e5140dcf477279cd8053f;hp=34b07a3f9e5543cd9919f7813543a1682734c7be;hpb=c53cabb68760b1c34a4af847cd83117dcf76a755;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index 34b07a3..56cf245 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -28,7 +28,6 @@ import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; @@ -44,6 +43,8 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -107,9 +108,6 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** The “set default file” action. */ private I18nAction setDefaultFileAction; - /** The “insert” action. */ - private I18nAction insertAction; - /** The “project files” label. */ private I18nLabel projectFilesLabel; @@ -141,13 +139,25 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private JTextField fileSizeTextField; /** The “override” label. */ - private I18nLabel overrideLabel; + private I18nLabel fileSettingsLabel; + + /** The “insert default” label. */ + private I18nLabel insertDefaultLabel; + + /** The “insert default” checkbox. */ + private JCheckBox insertDefaultCheckBox; + + /** The “override insert default” action. */ + private I18nAction overrideInsertDefaultAction; + + /** The “override insert default” checkbox. */ + private JCheckBox overrideInsertDefaultCheckBox; - /** The “override active” action. */ - private I18nAction overrideAction; + /** The “override insert” action. */ + private Action insertOverrideAction; - /** The “override action” checkbox. */ - private JCheckBox overrideCheckBox; + /** The “override insert” checkbox. */ + private JCheckBox insertOverrideCheckBox; /** The context menu for the tree. */ private JPopupMenu treeContextMenu; @@ -267,54 +277,78 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr project.setDefaultFile(completePath); } }; - insertAction = new I18nAction("fileManager.menu.item.insert") { + applyInsertOverrideAction = new I18nAction("fileManager.menu.item.applyInsertOverride") { /** * {@inheritDoc} */ - public void actionPerformed(ActionEvent e) { - /* TODO */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + applyInsertOverride(); } }; - overrideAction = new I18nAction("fileManager.checkbox.overrideActive") { + applyMimeTypeOverrideAction = new I18nAction("fileManager.menu.item.applyMimeTypeOverride") { /** - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + * {@inheritDoc} */ + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { - /* TODO */ + applyMimeTypeOverride(); } }; - applyInsertOverrideAction = new I18nAction("fileManager.menu.item.applyInsertOverride") { + removeOverrideAction = new I18nAction("fileManager.menu.item.removeOverride") { /** * {@inheritDoc} */ @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { - applyInsertOverride(); + removeOverride(); } }; - applyMimeTypeOverrideAction = new I18nAction("fileManager.menu.item.applyMimeTypeOverride") { + overrideInsertDefaultAction = new I18nAction("fileManager.checkbox.overrideInsertDefault") { /** * {@inheritDoc} */ @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { - applyMimeTypeOverride(); + boolean overrideInsert = overrideInsertDefaultCheckBox.isSelected(); + insertOverrideAction.setEnabled(overrideInsert); + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); + ProjectFile projectFile = projectFileWrapper.getProjectFile(); + FileOverride fileOverride = project.getFileOverride(projectFile); + if (overrideInsert) { + if (fileOverride == null) { + fileOverride = new FileOverride(); + project.addFileOverride(projectFile, fileOverride); + fileOverride.setInsert(!projectFile.isHidden()); + } + } else { + fileOverride.setInsert(null); + if (fileOverride.isEmpty()) { + project.removeFileOverride(projectFile); + } + } } }; - removeOverrideAction = new I18nAction("fileManager.menu.item.removeOverride") { + insertOverrideAction = new AbstractAction() { /** * {@inheritDoc} */ - @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { - removeOverride(); + boolean insertOverride = insertOverrideCheckBox.isSelected(); + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); + ProjectFile projectFile = projectFileWrapper.getProjectFile(); + FileOverride fileOverride = project.getFileOverride(projectFile); + fileOverride.setInsert(insertOverride); } }; + insertOverrideAction.setEnabled(false); } /** @@ -378,36 +412,43 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr filePropertiesLabel = new I18nLabel("fileManager.label.fileProperties"); filePropertiesLabel.setFont(filePropertiesLabel.getFont().deriveFont(Font.BOLD)); - propertiesPanel.add(filePropertiesLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + propertiesPanel.add(filePropertiesLabel, new GridBagConstraints(0, 0, 4, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); filePathLabel = new I18nLabel("fileManager.label.filePath"); filePathTextField = new JTextField(); filePathTextField.setEditable(false); propertiesPanel.add(filePathLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); - propertiesPanel.add(filePathTextField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + propertiesPanel.add(filePathTextField, new GridBagConstraints(1, 1, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); fileNameLabel = new I18nLabel("fileManager.label.fileName"); fileNameTextField = new JTextField(); fileNameTextField.setEditable(false); propertiesPanel.add(fileNameLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); - propertiesPanel.add(fileNameTextField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + propertiesPanel.add(fileNameTextField, new GridBagConstraints(1, 2, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); fileSizeLabel = new I18nLabel("fileManager.label.fileSize"); fileSizeTextField = new JTextField(); fileSizeTextField.setEditable(false); propertiesPanel.add(fileSizeLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); - propertiesPanel.add(fileSizeTextField, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); - - /* override settings. */ - overrideLabel = new I18nLabel("fileManager.label.override"); - overrideLabel.setFont(overrideLabel.getFont().deriveFont(Font.BOLD)); - propertiesPanel.add(overrideLabel, new GridBagConstraints(0, 4, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(24, 0, 0, 0), 0, 0)); - - overrideCheckBox = new JCheckBox(overrideAction); - propertiesPanel.add(overrideCheckBox, new GridBagConstraints(0, 5, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); + propertiesPanel.add(fileSizeTextField, new GridBagConstraints(1, 3, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + + /* file settings. */ + fileSettingsLabel = new I18nLabel("fileManager.label.fileSettings"); + fileSettingsLabel.setFont(fileSettingsLabel.getFont().deriveFont(Font.BOLD)); + propertiesPanel.add(fileSettingsLabel, new GridBagConstraints(0, 4, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(24, 0, 0, 0), 0, 0)); + + insertDefaultLabel = new I18nLabel("fileManager.label.insertDefault"); + propertiesPanel.add(insertDefaultLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); + insertDefaultCheckBox = new JCheckBox(); + insertDefaultCheckBox.setEnabled(false); + propertiesPanel.add(insertDefaultCheckBox, new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + overrideInsertDefaultCheckBox = new JCheckBox(overrideInsertDefaultAction); + propertiesPanel.add(overrideInsertDefaultCheckBox, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + insertOverrideCheckBox = new JCheckBox(insertOverrideAction); + propertiesPanel.add(insertOverrideCheckBox, new GridBagConstraints(3, 5, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); /* glue panel. */ - propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 6, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 6, 4, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); /* action button panel */ JPanel actionButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12)); @@ -472,27 +513,22 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr if (!mouseEvent.isPopupTrigger()) { return; } - Point eventLocation = mouseEvent.getPoint(); - TreePath[] selectedPaths = fileTree.getSelectionPaths(); - if ((selectedPaths == null) || (selectedPaths.length == 0)) { - /* try to find item under click. */ - TreePath clickedPath = fileTree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); - if (clickedPath != null) { - fileTree.setSelectionPath(clickedPath); - selectedPaths = new TreePath[] { clickedPath }; - } else { - logger.log(Level.FINER, "nothing selected for context menu"); - return; - } + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(false); + TreePath clickedPath = fileTree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); + ProjectFileWrapper clickedProjectFileWrapper = (ProjectFileWrapper) clickedPath.getLastPathComponent(); + if (!selectedProjectFileWrappers.contains(clickedProjectFileWrapper)) { + fileTree.setSelectionPath(clickedPath); + selectedProjectFileWrappers = getSelectedProjectFileWrappers(false); } - if (selectedPaths.length == 1) { - ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPaths[0].getLastPathComponent(); + if (selectedProjectFileWrappers.size() == 1) { + ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); ProjectFile projectFile = projectFileWrapper.getProjectFile(); setDefaultFileAction.setEnabled(!isHidden(projectFileWrapper) && projectFile.isFile() && !projectFile.getCompletePath().equals(project.getDefaultFile())); } else { setDefaultFileAction.setEnabled(false); } - treeContextMenu.show(fileTree, eventLocation.x, eventLocation.y); + overrideMenu.setVisible(selectedProjectFileWrappers.size() > 1); + treeContextMenu.show(fileTree, mouseEvent.getX(), mouseEvent.getY()); } /** @@ -625,18 +661,12 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr * {@inheritDoc} */ public void valueChanged(TreeSelectionEvent treeSelectionEvent) { - TreePath[] selectedPaths = fileTree.getSelectionPaths(); + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); filePathTextField.setText(""); fileNameTextField.setText(""); fileSizeTextField.setText(""); - overrideAction.setEnabled(false); - if ((selectedPaths != null) && (selectedPaths.length == 1)) { - Object lastPathComponent = selectedPaths[0].getLastPathComponent(); - if (!(lastPathComponent instanceof ProjectFileWrapper)) { - logger.log(Level.SEVERE, "lastPathComponent is not a ProjectFileWrapper!"); - return; - } - ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) lastPathComponent; + if (selectedProjectFileWrappers.size() == 1) { + ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); ProjectFile projectFile = projectFileWrapper.getProjectFile(); if (projectFile.isFile()) { String completePath = projectFile.getCompletePath(); @@ -648,9 +678,32 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr } fileNameTextField.setText(projectFile.getName()); fileSizeTextField.setText(String.valueOf(projectFile.getSize())); + overrideInsertDefaultCheckBox.setEnabled(true); + insertDefaultCheckBox.setSelected(!projectFile.isHidden()); + FileOverride fileOverride = project.getFileOverride(projectFile); + if (fileOverride != null) { + Boolean overrideInsert = fileOverride.isInsert(); + insertOverrideCheckBox.setEnabled(overrideInsert != null); + if (overrideInsert != null) { + overrideInsertDefaultCheckBox.setSelected(true); + insertOverrideCheckBox.setSelected(overrideInsert); + } else { + overrideInsertDefaultCheckBox.setSelected(false); + insertOverrideCheckBox.setSelected(!projectFile.isHidden()); + } + } else { + overrideInsertDefaultCheckBox.setSelected(false); + insertOverrideCheckBox.setEnabled(false); + insertOverrideCheckBox.setSelected(!projectFile.isHidden()); + } } - overrideAction.setEnabled(true); - } else if ((selectedPaths != null) && (selectedPaths.length > 1)) { + } else if (selectedProjectFileWrappers.size() > 1) { + insertDefaultCheckBox.setEnabled(false); + insertDefaultCheckBox.setSelected(false); + overrideInsertDefaultAction.setEnabled(false); + overrideInsertDefaultCheckBox.setSelected(false); + insertOverrideAction.setEnabled(false); + insertOverrideCheckBox.setSelected(false); } } @@ -737,11 +790,18 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr } ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) value; ProjectFile projectFile = projectFileWrapper.getProjectFile(); + FileOverride fileOverride = project.getFileOverride(projectFile); String completePath = projectFile.getCompletePath(); boolean paintBold = false; boolean paintHalfColor = false; - if (projectFile.isFile() && projectFile.isHidden()) { - /* TODO - check override */ + boolean showFile = !projectFile.isHidden(); + if (fileOverride != null) { + Boolean insertOverride = fileOverride.isInsert(); + if (insertOverride != null) { + showFile = insertOverride; + } + } + if (projectFile.isFile() && !showFile) { paintHalfColor = true; } else if (completePath.equals(project.getDefaultFile())) { paintBold = true;