1 10 11 12 package org.enhydra.jawe.misc; 13 14 import org.enhydra.jawe.*; 15 import org.enhydra.jawe.xml.*; 16 import org.enhydra.jawe.xml.panels.*; 17 18 import java.util.*; 19 import java.net.URL ; 20 import javax.swing.*; 21 import javax.swing.tree.*; 22 import javax.swing.event.*; 23 import java.awt.*; 24 25 28 public class PackageTreePanel extends XMLPanel { 29 30 private static Dimension treeDimension=new Dimension(300,300); 31 32 private PackageEditor packageEditor; 33 34 public PackageTreePanel ( 35 org.enhydra.jawe.xml.elements.Package myOwner, 36 PackageEditor pkgEditor,String title,boolean hasBorder) { 37 38 super(myOwner,2,title,XMLPanel.BOX_LAYOUT,true,hasBorder); 39 40 this.packageEditor=pkgEditor; 41 42 DefaultTreeModel model; 44 model=myOwner.getTreeModel(); 45 46 final JTree allItems=new JTree(model) { 47 public boolean isCellEditable(int row, int col) { 48 return false; 49 } 50 }; 51 52 allItems.getSelectionModel().setSelectionMode 54 (TreeSelectionModel.SINGLE_TREE_SELECTION); 55 allItems.setRootVisible(true); 56 DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); 57 allItems.setCellRenderer(renderer); 58 59 JScrollPane allItemsPane=new JScrollPane(); 61 allItemsPane.setViewportView(allItems); 62 allItemsPane.setPreferredSize(treeDimension); 63 64 add(allItemsPane); 65 add(Box.createVerticalGlue()); 66 67 allItems.addTreeSelectionListener(new TreeSelectionListener() { 68 public void valueChanged(TreeSelectionEvent e) { 69 DefaultMutableTreeNode node = (DefaultMutableTreeNode) 70 allItems.getLastSelectedPathComponent(); 71 if (node == null) return; 72 73 org.enhydra.jawe.xml.elements.Package pkg= 74 (org.enhydra.jawe.xml.elements.Package) 75 node.getUserObject(); 76 packageEditor.displayPackage(pkg); 77 } 78 }); 79 refreshPackageTreePanel(); 80 } 81 82 public void refreshPackageTreePanel () { 83 JTree jt=getTree(); 84 jt.setBackground(Utils.getColor(JaWEConfig.getInstance().getBackgroundColor())); 85 DefaultTreeCellRenderer dtcr=(DefaultTreeCellRenderer)jt.getCellRenderer(); 86 dtcr.setBackground(Utils.getColor(JaWEConfig.getInstance().getBackgroundColor())); 87 dtcr.setBackgroundNonSelectionColor(Utils.getColor(JaWEConfig.getInstance().getBackgroundColor())); 88 } 89 90 public JTree getTree () { 91 JScrollPane jsp=(JScrollPane)getComponent(0); 92 JViewport jvp=(JViewport)jsp.getComponent(0); 93 JTree jt=(JTree)jvp.getComponent(0); 94 return jt; 95 } 96 97 } 98 | Popular Tags |