Populate the directory tree pane in DiskWindow
I've decided (for now) not to try and break a DiskExplorerTab out of the DiskWindow as was done with the SWT GUI just yet, mostly because it's easier to write code when you don't have as many files to edit at once (especially given java's really deeply nested trees!) TreeViews in JavaFX always have one and only one root. That's fine when we only have one disk to display, but if we ever have two or more (the only image I've got that I know has two disks is UniDOS's 800k image, and that's not supported by AppleCommander at this time.) When we have that, we need a container tree root. So what I did was create one unconditionally and hide it. This gives you a windows registry style interface with multiple roots, one for each disk in the file you've opened. That's fine. But it still looks dumb that the root of a ProDOS disk is not expanded. I've resolved this by checking for the single disk case an expanding the root directory in the tree. The toolbar and the right pane are still placeholders and there's only the first tab. This stuff should be broken out into separate files when there's more of it done.
This commit is contained in:
parent
31a949f0db
commit
f3aef8da94
|
@ -1,19 +1,110 @@
|
|||
/*
|
||||
* AppleCommander - An Apple ][ image utility.
|
||||
* Copyright (C) 2002-2007 by Robert Greene and others
|
||||
* robgreene at users.sourceforge.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.webcodepro.applecommander.ui.fx;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import com.webcodepro.applecommander.storage.DirectoryEntry;
|
||||
import com.webcodepro.applecommander.storage.FileEntry;
|
||||
import com.webcodepro.applecommander.storage.FormattedDisk;
|
||||
import com.webcodepro.applecommander.ui.UiBundle;
|
||||
import com.webcodepro.applecommander.util.TextBundle;
|
||||
|
||||
public class DiskWindow {
|
||||
private TextBundle textBundle = UiBundle.getInstance();
|
||||
private FormattedDisk[] disks;
|
||||
|
||||
// This won't take a File ultimately, probably a Disk. And obviously
|
||||
// it will, y'know, do something. :) All TODO!
|
||||
public DiskWindow(FormattedDisk[] disks) {
|
||||
this.disks = disks;
|
||||
Stage diskStage = new Stage();
|
||||
diskStage.setTitle(disks[0].getFilename());
|
||||
VBox diskWindow = new VBox();
|
||||
Scene diskScene = new Scene(diskWindow);
|
||||
|
||||
diskStage.setTitle(disks[0].getFilename());
|
||||
diskStage.getIcons().add(new Image("/com/webcodepro/applecommander/ui/images/diskicon.gif")); //$NON-NLS-1$
|
||||
|
||||
TabPane tabPane = new TabPane();
|
||||
tabPane.setSide(Side.BOTTOM);
|
||||
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
|
||||
|
||||
tabPane.getTabs().add(createFilesTab());
|
||||
|
||||
diskWindow.getChildren().add(tabPane);
|
||||
diskStage.setScene(diskScene);
|
||||
diskStage.show();
|
||||
}
|
||||
|
||||
public Tab createFilesTab() {
|
||||
Tab filesTab = new Tab(textBundle.get("FilesTab")); //$NON-NLS-1$
|
||||
VBox vbox = new VBox();
|
||||
ToolBar toolBar = new ToolBar();
|
||||
|
||||
toolBar.getItems().add(new Button("Placeholder"));
|
||||
|
||||
SplitPane splitPane = new SplitPane();
|
||||
TreeItem dummyRoot = new TreeItem("dummy");
|
||||
TreeView diskTreeView = new TreeView(dummyRoot);
|
||||
diskTreeView.setShowRoot(false); // Hide the dummy root node
|
||||
for (int i=0; i < disks.length; ++i) {
|
||||
TreeItem diskTree = new TreeItem(disks[i]);
|
||||
|
||||
if (disks[i].canHaveDirectories()) {
|
||||
addDirectoriesToTree(diskTree, (DirectoryEntry)disks[i]);
|
||||
}
|
||||
dummyRoot.getChildren().add(diskTree);
|
||||
}
|
||||
|
||||
// If there's only one disk, expand its top-level directory
|
||||
if (dummyRoot.getChildren().size() == 1) {
|
||||
TreeItem singleDir = (TreeItem) dummyRoot.getChildren().get(0);
|
||||
singleDir.setExpanded(true);
|
||||
}
|
||||
|
||||
TableView fileTable = new TableView();
|
||||
splitPane.getItems().addAll(diskTreeView, fileTable);
|
||||
vbox.getChildren().addAll(toolBar, splitPane);
|
||||
filesTab.setContent(vbox);
|
||||
return filesTab;
|
||||
}
|
||||
|
||||
protected void addDirectoriesToTree(TreeItem parent, DirectoryEntry dirEntry) {
|
||||
Iterator files = dirEntry.getFiles().iterator();
|
||||
while (files.hasNext()) {
|
||||
final FileEntry fileEntry = (FileEntry) files.next();
|
||||
if (fileEntry.isDirectory()) {
|
||||
TreeItem item = new TreeItem(fileEntry);
|
||||
parent.getChildren().add(item);
|
||||
addDirectoriesToTree(item, (DirectoryEntry)fileEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue