import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
+import javax.swing.tree.TreePath;
import net.pterodactylus.jsite.i18n.I18n;
import net.pterodactylus.jsite.i18n.I18nable;
});
}
+ /**
+ * Returns the complete path for the given node.
+ *
+ * @param treeNode
+ * The node
+ * @return The complete path for the node, or the empty string (“”) for the
+ * root node
+ */
+ private String getPathForNode(TreeNode treeNode) {
+ TreeNode[] pathToNode = fileTreeModel.getPathToRoot(treeNode);
+ StringBuilder completePathBuilder = new StringBuilder();
+ boolean first = true;
+ for (TreeNode nodePathNode : pathToNode) {
+ if (first) {
+ first = false;
+ continue;
+ }
+ if (!(nodePathNode instanceof SortableTreeNode)) {
+ logger.log(Level.WARNING, "nodePathNode is not a SortableTreeNode!");
+ continue;
+ }
+ completePathBuilder.append(File.separatorChar).append(((SortableTreeNode) nodePathNode).getUserObject());
+ }
+ String completePath = (completePathBuilder.length() == 0) ? "" : completePathBuilder.substring(1);
+ return completePath;
+ }
+
//
// INTERFACE I18nable
//
* {@inheritDoc}
*/
public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
- /* TODO */
+ TreePath[] selectedPaths = fileTree.getSelectionPaths();
+ if ((selectedPaths != null) && (selectedPaths.length == 1)) {
+ Object lastPathComponent = selectedPaths[0].getLastPathComponent();
+ if (!(lastPathComponent instanceof SortableTreeNode)) {
+ logger.log(Level.WARNING, "lastPathComponent is not a SortableTreeNode!");
+ return;
+ }
+ SortableTreeNode node = (SortableTreeNode) lastPathComponent;
+ String completePath = getPathForNode(node);
+ int lastSeparator = completePath.lastIndexOf(File.separatorChar);
+ String filePath = "";
+ String fileName;
+ if (lastSeparator == -1) {
+ fileName = completePath;
+ } else {
+ filePath = completePath.substring(0, lastSeparator);
+ fileName = completePath.substring(lastSeparator + 1);
+ }
+ filePathTextField.setText(filePath);
+ fileNameTextField.setText(fileName);
+ return;
+ }
+ filePathTextField.setText("");
+ fileNameTextField.setText("");
}
//
SortableTreeNode node = (SortableTreeNode) value;
TreeNode[] pathToRoot = fileTreeModel.getPathToRoot(node);
if (pathToRoot.length > 1) {
- StringBuilder completePathBuilder = new StringBuilder();
- boolean first = true;
- for (TreeNode rootPathNode : pathToRoot) {
- if (first) {
- first = false;
- continue;
- }
- if (!(rootPathNode instanceof SortableTreeNode)) {
- logger.log(Level.WARNING, "rootPathNode is not a SortableTreeNode!");
- continue;
- }
- completePathBuilder.append(File.separatorChar).append(((SortableTreeNode) rootPathNode).getUserObject());
- }
- String completePath = completePathBuilder.substring(1);
+ String completePath = getPathForNode(node);
if (project.getDefaultFile().equals(completePath)) {
superCellRenderer.setFont(superCellRenderer.getFont().deriveFont(Font.BOLD));
} else {