From: David ‘Bombe’ Roden Date: Mon, 2 Jun 2008 11:59:53 +0000 (+0200) Subject: complete insert override stuff X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ee0cdc175e35b950f4a82a0c75b335cd338ed516;p=jSite2.git complete insert override stuff --- diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index 56cf245..33a07ce 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -44,6 +44,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; +import javax.swing.AbstractButton; import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.JButton; @@ -334,6 +335,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr } } }; + overrideInsertDefaultAction.setEnabled(false); insertOverrideAction = new AbstractAction() { /** @@ -346,6 +348,8 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr ProjectFile projectFile = projectFileWrapper.getProjectFile(); FileOverride fileOverride = project.getFileOverride(projectFile); fileOverride.setInsert(insertOverride); + fileTree.setShowsRootHandles(false); + fileTree.repaint(); } }; insertOverrideAction.setEnabled(false); @@ -520,6 +524,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr fileTree.setSelectionPath(clickedPath); selectedProjectFileWrappers = getSelectedProjectFileWrappers(false); } + logger.log(Level.FINEST, "selectedProjectFileWrappers.size(): " + selectedProjectFileWrappers.size()); if (selectedProjectFileWrappers.size() == 1) { ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); ProjectFile projectFile = projectFileWrapper.getProjectFile(); @@ -544,7 +549,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr ProjectFile projectFile = projectFileWrapper.getProjectFile(); FileOverride fileOverride = project.getFileOverrides().get(projectFile.getCompletePath()); logger.log(Level.FINEST, "fileOverride: " + fileOverride); - return ((fileOverride == null) && projectFile.isHidden()) || ((fileOverride != null) && (Boolean.TRUE.equals(fileOverride.isInsert()))); + return ((fileOverride == null) && projectFile.isHidden()) || ((fileOverride != null) && (fileOverride.isInsert() == null) && projectFile.isHidden()) || ((fileOverride != null) && (fileOverride.isInsert() != null) && (Boolean.FALSE.equals(fileOverride.isInsert()))); } /** @@ -552,7 +557,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr * override for the “insert” setting for multiple files. */ private void applyInsertOverride() { - JCheckBox insertCheckBox = new JCheckBox(I18n.get("fileManager.checkbox.insertFile.name")); + JCheckBox insertCheckBox = new JCheckBox(I18n.get("fileManager.menu.item.insert.name")); String okString = I18n.get("general.button.okay.name"); String cancelString = I18n.get("general.button.cancel.name"); int choice = JOptionPane.showOptionDialog(this, new Object[] { I18n.get("fileManager.dialog.insertOverride.message"), insertCheckBox }, I18n.get("fileManager.dialog.insertOverride.title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { okString, cancelString }, okString); @@ -571,6 +576,8 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr } fileOverride.setInsert(insertCheckBox.isSelected()); } + /* HACK - Swing sucks a bit */ + fileTree.setShowsRootHandles(false); } /** @@ -662,48 +669,75 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr */ public void valueChanged(TreeSelectionEvent treeSelectionEvent) { List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); - filePathTextField.setText(""); - fileNameTextField.setText(""); - fileSizeTextField.setText(""); + String filePathText = ""; + String fileNameText = ""; + String fileSizeText = ""; + boolean insertDefaultSelected = false; + boolean overrideInsertEnabled = false; + boolean overrideInsertSelected = false; + boolean insertOverrideEnabled = false; + boolean insertOverrideSelected = false; if (selectedProjectFileWrappers.size() == 1) { ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); ProjectFile projectFile = projectFileWrapper.getProjectFile(); if (projectFile.isFile()) { String completePath = projectFile.getCompletePath(); int lastSeparator = completePath.lastIndexOf(File.separatorChar); - if (lastSeparator == -1) { - filePathTextField.setText(""); - } else { - filePathTextField.setText(completePath.substring(0, lastSeparator)); + if (lastSeparator != -1) { + filePathText = completePath.substring(0, lastSeparator); } - fileNameTextField.setText(projectFile.getName()); - fileSizeTextField.setText(String.valueOf(projectFile.getSize())); - overrideInsertDefaultCheckBox.setEnabled(true); - insertDefaultCheckBox.setSelected(!projectFile.isHidden()); + fileNameText = projectFile.getName(); + fileSizeText = String.valueOf(projectFile.getSize()); + insertDefaultSelected = !projectFile.isHidden(); + overrideInsertEnabled = true; 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()); + overrideInsertSelected = overrideInsert != null; + insertOverrideEnabled = overrideInsertSelected; + insertOverrideSelected = overrideInsertSelected ? overrideInsert : !projectFile.isHidden(); } } } else if (selectedProjectFileWrappers.size() > 1) { - insertDefaultCheckBox.setEnabled(false); - insertDefaultCheckBox.setSelected(false); - overrideInsertDefaultAction.setEnabled(false); - overrideInsertDefaultCheckBox.setSelected(false); - insertOverrideAction.setEnabled(false); - insertOverrideCheckBox.setSelected(false); + /* TODO */ + } + filePathTextField.setText(filePathText); + fileNameTextField.setText(fileNameText); + fileSizeTextField.setText(fileSizeText); + setSelected(insertDefaultCheckBox, insertDefaultSelected); + setEnabled(overrideInsertDefaultAction, overrideInsertEnabled); + setSelected(overrideInsertDefaultCheckBox, overrideInsertSelected); + setEnabled(insertOverrideAction, insertOverrideEnabled); + setSelected(insertOverrideCheckBox, insertOverrideSelected); + } + + /** + * 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 + * The new enabled state of the action + */ + private void setEnabled(Action action, boolean enabled) { + if (action.isEnabled() != enabled) { + action.setEnabled(enabled); + } + } + + /** + * 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 + * The new selected state of the button + */ + private void setSelected(AbstractButton button, boolean selected) { + if (button.isSelected() != selected) { + button.setSelected(selected); } } @@ -1038,9 +1072,11 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr if (Project.PROPERTY_DEFAULT_FILE.equals(propertyChangeEvent.getPropertyName())) { if (propertyChangeEvent.getOldValue() != null) { String oldCompletePath = (String) propertyChangeEvent.getOldValue(); + logger.log(Level.FINEST, "oldCompletePath: " + oldCompletePath); ProjectFile oldProjectFile = pathProjectFiles.get(oldCompletePath); + logger.log(Level.FINEST, "oldProjectFile: " + oldProjectFile); ProjectFileWrapper oldProjectFileWrapper = projectFileWrappers.get(oldProjectFile); - System.out.println("oldProjectFileWrapper: " + oldProjectFileWrapper); + logger.log(Level.FINEST, "oldProjectFileWrapper: " + oldProjectFileWrapper); fireTreeNodesChanged(oldProjectFileWrapper); } String newCompletePath = (String) propertyChangeEvent.getNewValue();