1 19 20 package org.netbeans.modules.form.palette; 21 22 import javax.swing.*; 23 24 import org.openide.nodes.Node; 25 import org.openide.explorer.view.ListView; 26 import org.openide.explorer.*; 27 import org.openide.*; 28 import org.openide.nodes.AbstractNode; 29 import org.openide.nodes.Children; 30 import org.openide.nodes.FilterNode; 31 32 37 38 class CategorySelector extends JPanel implements ExplorerManager.Provider { 39 40 private ExplorerManager explorerManager; 41 42 CategorySelector() { 43 explorerManager = new ExplorerManager(); 44 explorerManager.setRootContext(getCategoryRootNode()); 45 46 ListView listView = new ListView(); 47 JScrollPane scrollPane = new JScrollPane(); 49 listView.setBorder(scrollPane.getBorder()); 50 listView.getAccessibleContext().setAccessibleDescription( 51 PaletteUtils.getBundleString("ACSD_CTL_PaletteCategories")); listView.setPopupAllowed(false); 53 listView.setTraversalAllowed(false); 54 55 JLabel categoryLabel = new JLabel(); 56 org.openide.awt.Mnemonics.setLocalizedText(categoryLabel, 57 PaletteUtils.getBundleString("CTL_PaletteCategories")); categoryLabel.setLabelFor(listView); 59 60 getAccessibleContext().setAccessibleDescription( 61 PaletteUtils.getBundleString("ACSD_PaletteCategoriesSelector")); 63 setLayout(new java.awt.BorderLayout (0, 5)); 64 add(categoryLabel, java.awt.BorderLayout.NORTH); 65 add(listView, java.awt.BorderLayout.CENTER); 66 } 67 68 private Node getCategoryRootNode() { 69 Node root = new AbstractNode(new Children.Array()); 70 71 Node[] paleteCategories = PaletteUtils.getCategoryNodes(PaletteUtils.getPaletteNode(), false); 72 Node[] categoryNodes = new Node[paleteCategories.length]; 73 74 for (int i = 0; i < paleteCategories.length; i++) { 75 categoryNodes[i] = new FilterNode(paleteCategories[i], Children.LEAF); 76 } 77 78 root.getChildren().add(categoryNodes); 79 getExplorerManager().setRootContext(root); 80 81 return root; 82 } 83 84 public static String selectCategory() { 85 CategorySelector selector = new CategorySelector(); 86 selector.setBorder(new javax.swing.border.EmptyBorder (12, 12, 0, 11)); 87 DialogDescriptor dd = new DialogDescriptor( 88 selector, 89 PaletteUtils.getBundleString("CTL_SelectCategory_Title"), true, 91 null); 92 DialogDisplayer.getDefault().createDialog(dd).setVisible(true); 93 94 return dd.getValue() == DialogDescriptor.OK_OPTION ? 95 selector.getSelectedCategory() : null; 96 } 97 98 String getSelectedCategory() { 99 Node[] selected = explorerManager.getSelectedNodes(); 100 return selected.length == 1 ? selected[0].getName() : null; 101 } 102 103 public ExplorerManager getExplorerManager() { 105 return explorerManager; 106 } 107 108 public java.awt.Dimension getPreferredSize() { 109 return new java.awt.Dimension (400, 300); 110 } 111 } 112 | Popular Tags |