40 super(
"dragdrop_test");
45 DefaultTreeModel treeModel = (DefaultTreeModel)
larch.getModel();
47 TreeSelectionModel selmod =
new DefaultTreeSelectionModel();
48 selmod.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
49 larch.setSelectionModel(selmod);
50 larch.addTreeSelectionListener(
this);
51 JScrollPane listScrollPane =
new JScrollPane(
larch);
53 String dirName = startPath +
"/";
55 String
filelist[] =
new File(dirName).list();
56 MutableTreeNode root_node = (MutableTreeNode) treeModel.getRoot();
57 if (root_node ==
null) {
58 logger.error(
"something is not right about tree. has null root.");
62 for (
int i = 0; i <
filelist.length; i++) {
63 String thisFileSt = dirName +
filelist[i];
64 File thisFile =
new File(thisFileSt);
66 if (thisFile.isDirectory())
73 DefaultMutableTreeNode newNode =
new DefaultMutableTreeNode(makeNode(
74 thisFile.getName(), thisFile.toURI().toURL().toString(),
75 thisFile.getAbsolutePath()));
76 treeModel.insertNodeInto(newNode, root_node, root_node.getChildCount());
77 }
catch (java.net.MalformedURLException e) {
78 logger.warn(
"caught an exception while trying to process path: "
79 + thisFile.getAbsolutePath());
84 fileName =
new JTextField(50);
86 larch.setSelectionPath(
larch.getPathForRow(0));
92 JPanel buttonPane =
new JPanel();
93 buttonPane.add(fileName);
95 Container contentPane = getContentPane();
96 contentPane.add(listScrollPane, BorderLayout.CENTER);
97 contentPane.add(buttonPane, BorderLayout.NORTH);
132 private static Hashtable<String, String> makeNode(String name, String url, String strPath)
134 Hashtable<String, String> hashtable =
new Hashtable<String, String>();
195 DefaultTreeCellRenderer defRend =
new DefaultTreeCellRenderer();
197 private String getValueString(Object value)
199 String returnString =
"empty";
200 Hashtable<String, String> table = NodeToTable(value);
202 returnString = table.get(
"name") +
" -> " + table.get(
"url");
204 returnString =
"??: " + value.toString();
211 boolean expanded,
boolean leaf,
int row,
boolean hasFocus)
213 defRend.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
215 defRend.setText(getValueString(value));