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;
}
}
};
+ overrideInsertDefaultAction.setEnabled(false);
insertOverrideAction = new AbstractAction() {
/**
ProjectFile projectFile = projectFileWrapper.getProjectFile();
FileOverride fileOverride = project.getFileOverride(projectFile);
fileOverride.setInsert(insertOverride);
+ fileTree.setShowsRootHandles(false);
+ fileTree.repaint();
}
};
insertOverrideAction.setEnabled(false);
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();
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())));
}
/**
* 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);
}
fileOverride.setInsert(insertCheckBox.isSelected());
}
+ /* HACK - Swing sucks a bit */
+ fileTree.setShowsRootHandles(false);
}
/**
*/
public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
List<ProjectFileWrapper> 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);
}
}
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();