import java.awt.*;
|
import java.awt.event.*;
|
import javax.swing.*;
|
import javax.swing.tree.*;
|
|
import java.awt.dnd.*;
|
import java.awt.datatransfer.*;
|
|
import java.io.File;
|
|
import grafeme.ui.*;
|
|
public class cFileSystemPane extends cGridBag implements ActionListener, ItemListener, DragGestureListener,
|
//DragSourceListener,
|
DropTargetListener
|
{
|
cTree jTree = new cTree();
|
iCallBack owner;
|
|
JButton refreshButton;
|
JButton rootButton;
|
JButton loadButton;
|
JButton printButton;
|
JButton replaceButton;
|
JCheckBox normalsCB;
|
JCheckBox trimCB;
|
JCheckBox stripCB;
|
JCheckBox genUVCB;
|
|
cCheckBox mergeAttributesCB;
|
|
cFileSystemPane(iCallBack o)
|
{
|
owner = o;
|
|
setName("Files");
|
//System.out.println("layout : " + getLayout());
|
//setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
//setLayout(new GridBagLayout());
|
//ToolTipManager.sharedInstance().registerComponent(jTree);
|
jTree.setCellRenderer(new cFileSystemModel.Renderer());
|
|
ResetModel(true);
|
|
JScrollPane tree = new JScrollPane(jTree);
|
//jTree.addTreeSelectionListener(this);
|
//jTree.setRootVisible(false);
|
//jTree.setEditable(true);
|
jTree.setDragEnabled(true);
|
|
/*
|
JPanel jp = new JPanel(new GridBagLayout());
|
//System.out.println("layout : " + jp.getPreferredSize());
|
jp.add(refreshButton = new JButton("Refresh"));
|
jp.add(refreshButton = new JButton("Refresh"));
|
jp.add(refreshButton = new JButton("Refresh"));
|
//jp.add(refreshButton = new JButton("Refresh"));
|
//jp.add(refreshButton = new JButton("Refresh"));
|
//jp.setSize(new Dimension(20,20));
|
*/
|
GridBagConstraints aConstraints = new GridBagConstraints(0,0,1,1, 1.0,1.0,
|
GridBagConstraints.EAST,GridBagConstraints.HORIZONTAL,new Insets(1,1,1,1), 0,0);
|
|
cGridBag fileCommands = new cGridBag();
|
|
fileCommands.add(loadButton = new JButton("Load")); //, aConstraints);
|
loadButton.setToolTipText("Load selected file(s)");
|
loadButton.addActionListener(this);
|
fileCommands.add(refreshButton = new JButton("User")); //, aConstraints);
|
refreshButton.setToolTipText("Refresh user tree");
|
refreshButton.addActionListener(this);
|
fileCommands.add(rootButton = new JButton("Root")); //, aConstraints);
|
rootButton.setToolTipText("Refresh root tree");
|
rootButton.addActionListener(this);
|
|
if (Globals.ADVANCED)
|
{
|
fileCommands.add(printButton = new JButton("Print")); //, aConstraints);
|
printButton.setToolTipText("Print file path in terminal");
|
printButton.addActionListener(this);
|
fileCommands.add(mergeAttributesCB = new cCheckBox("Merge", cJME.mergeAttributes)); //, aConstraints);
|
mergeAttributesCB.setToolTipText("Merge common attributes (recommended)");
|
mergeAttributesCB.addItemListener(this);
|
// replaceButton.addActionListener(this);
|
// add(replaceButton = new JButton("Replace"), aConstraints);
|
}
|
|
// aConstraints.gridx += 1;
|
// add(trimCB = new cCheckBox("Trim", cJME.trim), aConstraints);
|
// trimCB.addItemListener(this);
|
// aConstraints.gridx += 1;
|
// add(normalsCB = new cCheckBox("Normal", cJME.gennormals), aConstraints);
|
// normalsCB.addItemListener(this);
|
// aConstraints.gridx += 1;
|
// add(stripCB = new cCheckBox("Strip", cJME.stripify), aConstraints);
|
// stripCB.addItemListener(this);
|
// aConstraints.gridx += 1;
|
// add(genUVCB = new cCheckBox("UV", cJME.genUV), aConstraints);
|
// genUVCB.addItemListener(this);
|
|
add(fileCommands);
|
fileCommands.preferredHeight = 1;
|
|
Return();
|
|
cGridBag treeBag = new cGridBag();
|
|
treeBag.add(tree);
|
|
treeBag.preferredHeight = 30;
|
|
add(treeBag); //, aConstraints);
|
|
GroupEditor oe = (GroupEditor) owner;
|
|
// DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(oe.cameraView, DnDConstants.ACTION_COPY_OR_MOVE, this); // ACTION_LINK ??
|
// /*DropTarget dropTarget =*/ new DropTarget(oe.cameraView, this);
|
}
|
|
void ResetModel(boolean user)
|
{
|
cFilter filter = new cFilter();
|
|
filter.add("3ds");
|
filter.add("dae");
|
filter.add("obj");
|
filter.add("gfd");
|
filter.add("bvh");
|
filter.add("wrl");
|
filter.add("vrml");
|
filter.add("x3d");
|
filter.add("jpg");
|
filter.add("jpeg");
|
filter.add("gif");
|
filter.add("png");
|
filter.add("tre");
|
filter.add("tga");
|
filter.add("bmp"); // not supported
|
|
File root = java.io.File.listRoots()[0];
|
File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
|
|
jTree.setModel(new cFileSystemModel(
|
user?defaultDirectory:root,
|
filter
|
));
|
}
|
|
public void itemStateChanged(ItemEvent e)
|
{
|
if(e.getSource() == normalsCB)
|
cJME.gennormals = (e.getStateChange() == ItemEvent.SELECTED);
|
else
|
if(e.getSource() == trimCB)
|
cJME.trim = (e.getStateChange() == ItemEvent.SELECTED);
|
else
|
if(e.getSource() == stripCB)
|
cJME.stripify = (e.getStateChange() == ItemEvent.SELECTED);
|
else
|
if(e.getSource() == genUVCB)
|
cJME.genUV = (e.getStateChange() == ItemEvent.SELECTED);
|
else
|
if(e.getSource() == mergeAttributesCB)
|
cJME.mergeAttributes = (e.getStateChange() == ItemEvent.SELECTED);
|
else
|
assert(false);
|
|
//preserveCB.setEnabled(cJME.gennormals || cJME.stripify);
|
}
|
|
public void actionPerformed(ActionEvent event)
|
{
|
if(event.getSource() == refreshButton)
|
{
|
ResetModel(true);
|
return;
|
}
|
|
if(event.getSource() == rootButton)
|
{
|
ResetModel(false);
|
return;
|
}
|
|
if(event.getSource() == loadButton)
|
{
|
TreePath[] paths = jTree.getSelectionPaths();
|
if (paths == null) // || (path.getPathCount() <= 1))
|
// We can't move the root node or an empty selection
|
return;
|
File[] files = new File[paths.length];
|
|
for(int i=0; i<paths.length; i++)
|
files[i] = (File) paths[i].getLastPathComponent();
|
|
owner.Callback(files);
|
}
|
|
if(event.getSource() == printButton)
|
{
|
TreePath[] paths = jTree.getSelectionPaths();
|
if (paths == null) // || (path.getPathCount() <= 1))
|
// We can't move the root node or an empty selection
|
return;
|
|
for(int i=0; i<paths.length; i++)
|
{
|
File file = (File) paths[i].getLastPathComponent();
|
|
//System.out.println("FILE");
|
System.err.println(file);
|
}
|
}
|
}
|
|
public void dragGestureRecognized(DragGestureEvent dge)
|
{
|
System.out.println("dragGestureRecognized (FileSystem) : " + dge);
|
|
// Patch for DnD failure (unselect first)
|
owner.DragGesture();
|
|
/**/
|
//DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveNoDrop, new StringSelection("Allo"), this);
|
TreePath[] path = jTree.getSelectionPaths();
|
if (path == null) // || (path.length <= 1))
|
// We can't move the root node or an empty selection
|
return;
|
File[] file = new File[path.length];
|
|
for(int i=0; i<path.length; i++)
|
file[i] = (File) path[i].getLastPathComponent();
|
TransferableFile transferable = new TransferableFile(file);
|
// boolean success;
|
// do
|
// {
|
// success = false;
|
//try
|
//{
|
System.out.println("startDrag (FileSystem) : " + dge);
|
DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop, transferable, null); // this);
|
// success = true;
|
//}catch(Exception e) {}
|
// } while(!success);
|
/**/
|
}
|
|
public void drop(DropTargetDropEvent dtde)
|
// The drag operation has terminated with a drop on this DropTarget.
|
{
|
GroupEditor objEditor = (GroupEditor) owner;
|
|
objEditor.location = dtde.getLocation();
|
Component target = dtde.getDropTargetContext().getDropTarget().getComponent();
|
|
System.out.println("drop2 = " + dtde + "; drop : " + target);
|
|
//assert dropTarget == dtde.getSource();
|
if (target instanceof iCameraPane)
|
{
|
Object object = null;
|
try
|
{
|
object = dtde.getTransferable().getTransferData(
|
dtde.getTransferable().getTransferDataFlavors()[0]);
|
}
|
catch(Exception e)
|
{
|
e.printStackTrace();
|
}
|
System.out.println("Transfer2 = " + object + "; drop : " + target);
|
|
owner.Callback(object);
|
}
|
}
|
|
public void dragEnter(DropTargetDragEvent dtde)
|
// Called when a drag operation has encountered the DropTarget.
|
{
|
System.out.println("dragEnter2 : " + dtde);
|
}
|
public void dragExit(DropTargetEvent dte)
|
// The drag operation has departed the DropTarget without dropping.
|
{
|
System.out.println("dragExit2 : " + dte);
|
}
|
public void dragOver(DropTargetDragEvent dtde)
|
// Called when a drag operation is ongoing on the DropTarget.
|
{
|
//System.out.println("dragOver : " + dtde.getSource());
|
}
|
|
public void dropActionChanged(DropTargetDragEvent dtde)
|
// Called if the user has modified the current drop gesture
|
{
|
System.out.println("dropActionChanged2 : " + dtde);
|
}
|
|
//
|
// public void dragDropEnd(DragSourceDropEvent dsde)
|
// // This method is invoked to signify that the Drag and Drop operation is complete.
|
// {
|
// System.out.println("dragDropEnd : " + dsde.getSource());
|
// /*
|
// if (//dsde.getDropSuccess() &&
|
// true) //(dsde.getDropAction() == DnDConstants.ACTION_MOVE))
|
// {
|
// //((DefaultTreeModel) jTree.getModel()).removeNodeFromParent(oldNode);
|
// loadClipboard(true);
|
// }
|
// */
|
// }
|
// public void dragEnter(DragSourceDragEvent dsde)
|
// // Called as the hotspot enters a platform dependent drop site.
|
// {
|
// System.out.println("dragEnter : " + dsde);
|
// }
|
// public void dragExit(DragSourceEvent dse)
|
// // Called as the hotspot exits a platform dependent drop site.
|
// {
|
// System.out.println("dragExit : " + dse);
|
// }
|
// public void dragOver(DragSourceDragEvent dsde)
|
// // Called as the hotspot moves over a platform dependent drop site.
|
// {
|
// //System.out.println("dragOver : " + dsde);
|
// }
|
// public void dropActionChanged(DragSourceDragEvent dsde)
|
// // Called when the user has modified the drop gesture.
|
// {
|
// System.out.println("dropActionChanged : " + dsde);
|
// System.out.println("Action: " + dsde.getDropAction());
|
// System.out.println("Target Action: " + dsde.getTargetActions());
|
// System.out.println("User Action: " + dsde.getUserAction());
|
// }
|
|
public static DataFlavor FILE_FLAVOR = new DataFlavor(File[].class,
|
"File");
|
|
static class TransferableFile implements Transferable {
|
|
DataFlavor flavors[] = {FILE_FLAVOR};
|
File[] file;
|
|
public TransferableFile(File[] f) {
|
file = f;
|
}
|
|
public synchronized DataFlavor[] getTransferDataFlavors() {
|
return flavors;
|
}
|
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
return (flavor.getRepresentationClass() == File[].class);
|
}
|
|
public synchronized Object getTransferData(DataFlavor flavor)
|
throws UnsupportedFlavorException, java.io.IOException {
|
if (isDataFlavorSupported(flavor)) {
|
return file;
|
} else {
|
throw new UnsupportedFlavorException(flavor);
|
}
|
}
|
}
|
}
|