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