/*
* IsoFileBrowser.java
*
* Created on February 19, 2006, 4:29 AM
*/
package isoeditor;
import com.sun.corba.se.spi.activation._ActivatorImplBase;
import java.util.*;
import java.io.*;
import oCommon.*;
import oMathFP.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
public class IsoFileBrowserFrame extends IsoInternalFrame implements TreeSelectionListener, TreeModelListener, ComponentListener {
public static String baseDir = "../../data/editor/managed/";
public static String export_clientData_folder = "../../data/client/managed/";
public static boolean export_clientData = true;
public static String export_serverData_folder = "../../data/server/managed/";
public static boolean export_serverData = true;
public static IsoFileBrowserFrame instance;
public DefaultMutableTreeNode rootNode;
public DefaultTreeModel treeModel;
public IsoFileBrowserFrame_treeNode rootNode_obj;
public IsoExportTask exportTask = null;
public static final oEventId event_selected = new oEventId(IsoFileBrowserFrame.class, "selected");
Vector tmpSelectedPathStrings;
Vector tmpExpandedPathStrings;
public static final String filetypes[] = {
"png",
"bit",
"pal",
"til",
"ent",
"imp"};
public static final String fileicons_path[] = {
"fileicon_png",
"fileicon_bit",
"fileicon_pal",
"fileicon_til",
"fileicon_ent",
"fileicon_imp"
};
public static final String diricon_path = "fileicon_dir";
public static ImageIcon fileicons_img[];
public static ImageIcon diricon_img;
static {
fileicons_img = new ImageIcon[fileicons_path.length];
diricon_img = null;
try {
diricon_img = new ImageIcon(IsoMainFrame.class.getResource(IsoMainFrame.internalResource_folder + diricon_path + ".png"));
for (int i = 0; i < fileicons_path.length; i++) {
fileicons_img[i] = new ImageIcon(IsoMainFrame.class.getResource(IsoMainFrame.internalResource_folder + fileicons_path[i] + ".png"));
}
} catch (Exception e) {
System.out.println("Failed to load file icons");
System.out.println(e.toString());
}
oFileManager.baseDir = baseDir;
}
public class MyRenderer extends DefaultTreeCellRenderer {
public MyRenderer() {
}
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
try {
if (value != rootNode && leaf) {
IsoFileBrowserFrame_treeNode nodeobj = (IsoFileBrowserFrame_treeNode)((DefaultMutableTreeNode)value).getUserObject();
String path = nodeobj.path;
File file = new File(getSystemFilePath(path));
if (file.isDirectory()) {
setIcon(diricon_img);
} else {
int index = getIconIndex(path);
if (index >= 0)
setIcon(fileicons_img[index]);
if (isNodeDirty((DefaultMutableTreeNode)value)) {
if (sel) {
setForeground(new Color(175,175,255));
} else {
setForeground(new Color(0,0,255));
}
}
}
}
} catch (ClassCastException e) {
}
return this;
}
public int getIconIndex(String path) {
for (int i = 0; i < filetypes.length; i++) {
if (path.indexOf("." + filetypes[i]) >= 0) {
return i;
}
}
return -1;
}
}
public static boolean copyTransferFailed = false;
public static String copyDstPath = null;
public static final int COPY_KEYSTATE_NONE = 0;
public static final int COPY_KEYSTATE_COPY = 1;
public static final int COPY_KEYSTATE_CUT = 2;
public int copyKeyState = COPY_KEYSTATE_NONE;
public class MyTransferHandler extends TransferHandler {
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
for (int i = 0; i < transferFlavors.length; i++) {
if (transferFlavors[i].equals(IsoFileBrowserTransferable.dataflavor)
|| transferFlavors[i].equals(DataFlavor.stringFlavor))
return true;
}
return false;
}
public boolean isFileBrowserFlavor(DataFlavor[] transferFlavors) {
for (int i = 0; i < transferFlavors.length; i++) {
if (transferFlavors[i].equals(IsoFileBrowserTransferable.dataflavor))
return true;
}
return false;
}
public boolean isStringFlavor(DataFlavor[] transferFlavors) {
for (int i = 0; i < transferFlavors.length; i++) {
if (transferFlavors[i].equals(DataFlavor.stringFlavor))
return true;
}
return false;
}
protected Transferable createTransferable(JComponent c) {
Vector nodes = getSelectedNodes();
IsoFileBrowserTransferable transVec = new IsoFileBrowserTransferable();
for (int i = 0; i < nodes.size(); i++) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)nodes.elementAt(i);
transVec.v.addElement(node.getUserObject());
}
if (transVec.v.size() == 0) return null;
return transVec;
}
public int getSourceActions(JComponent c) {
return COPY_OR_MOVE;
}
public boolean importData(JComponent comp, Transferable t) {
if (t == null)
return false;
if (canImport(comp, t.getTransferDataFlavors())) {
if (isFileBrowserFlavor(t.getTransferDataFlavors())) {
try {
IsoFileBrowserTransferable transVec = (IsoFileBrowserTransferable)t.getTransferData(IsoFileBrowserTransferable.dataflavor);
Vector nodesToCopy = new Vector();
for (int i = 0; i < transVec.v.size(); i++) {
IsoFileBrowserFrame_treeNode nodeobj = (IsoFileBrowserFrame_treeNode)transVec.v.elementAt(i);
String path = getStringPathFromFilePath(nodeobj.path);
if (!stringPathExists(path)) {
continue;
}
nodesToCopy.addElement(getTreePathFromStringPath(path).getLastPathComponent());
}
copyDstPath = null;
if (nodesToCopy.size() > 0) {
DefaultMutableTreeNode copyDstNode = getNearestFolder((DefaultMutableTreeNode)fileTree.getLastSelectedPathComponent());