📄 beanpanel.java
字号:
/** * Called when the BeanPanel is added the BeanContext, or when * another object is added to the BeanContext after the * LayerHandler has been added. This allows the BeanPanel to keep * up-to-date with any objects that it may be interested in, * namely, the LayerHandler. If a LayerHandler has already been * added, the new LayerHandler will replace it. * * @param someObj the object being added to the BeanContext. */ public void findAndInit(Object someObj) { if (someObj instanceof LayerHandler) { // do the initializing that need to be done here } if (someObj instanceof PropertyHandler) { // do the initializing that need to be done here //if (Debug.debugging("beanbox")) Properties props = ((PropertyHandler) someObj).getProperties(); loadBeanPanelProperties(props); } } /** * Loads java beans from jar files. This method first gets the * locations of the jar files from the openmap properties file and * then loads the bean classes from them. */ private void loadBeans() { Vector jarNames = getJarNames(); for (int i = 0; i < jarNames.size(); i++) { String jarFileName = (String) jarNames.elementAt(i); try { JarLoader.loadJarDoOnBean(jarFileName, helper); } catch (Throwable th) { System.out.println("BP::loadBeans: jar load failed: " + jarFileName); th.printStackTrace(); } } } private Vector getJarNames() { Vector result = new Vector(); if (beanPaths == null || beanPaths.size() == 0) return result; for (int i = 0; i < beanPaths.size(); i++) { String path = (String) beanPaths.get(i); File dir = new File(path); if (!dir.isDirectory()) { System.out.println("BP::getJarNames: " + dir + " is not a directory!"); continue; } String names[] = dir.list(new FileExtension(".jar")); for (int j = 0; j < names.length; j++) result.add(dir.getPath() + File.separatorChar + names[j]); } return result; } private JList createTab(Vector beanClassNames) { final JList list = new JList(); if (beanClassNames == null || beanClassNames.size() == 0) return list; Vector labels = new Vector(); for (int i = 0; i < beanClassNames.size(); i++) { String beanClassName = (String) beanClassNames.get(i); int index = beanNames.indexOf(beanClassName); if (index < 0) { System.out.println("BP::createTab: could not locate beanClass=" + beanClassName); continue; } String label = (String) beanLabels.get(index); labels.add(label); } list.setListData(labels); list.setCellRenderer(new MyCellRenderer()); MouseEventForwarder forwarder = new MouseEventForwarder(); list.addMouseListener(forwarder); list.addMouseMotionListener(forwarder); return list; } private synchronized void showBeanPanel(boolean isVisible) { if (beanFrame != null) { beanFrame.setVisible(isVisible); if (isVisible) beanFrame.toFront(); return; } if (!isVisible) return; initGui(); beanFrame = new JFrame("Bean Box"); beanFrame.getContentPane() .setLayout(new BoxLayout(beanFrame.getContentPane(), BoxLayout.Y_AXIS)); beanFrame.getContentPane().add(this); beanFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { beanFrame.setVisible(false); } }); beanFrame.pack(); beanFrame.setVisible(true); } private synchronized void initGui() { loadBeans(); this.setLayout(new BorderLayout()); if (toolbarTabOrder != null && toolbarTabOrder.size() > 0) { MouseEventForwarder forwarder = new MouseEventForwarder(); tabbedPane.addMouseListener(forwarder); tabbedPane.addMouseMotionListener(forwarder); for (int i = 0; i < toolbarTabOrder.size(); i++) { String tabName = (String) toolbarTabOrder.get(i); Vector beanClassNames = (Vector) toolbarTabInfo.get(tabName); JList listTab = createTab(beanClassNames); tabbedPane.addTab(tabName, listTab); } JScrollPane sPane = new JScrollPane(tabbedPane); add(sPane, BorderLayout.CENTER); } setPreferredSize(new Dimension(400, 250)); setMinimumSize(new Dimension(400, 250)); } private synchronized void loadBeanPanelProperties(Properties props) { loadBeanPaths(props); loadToolBarTabInfo(props); } private void loadBeanPaths(Properties props) { if (Debug.debugging("beanpanel")) Debug.output("Enter> BP::loadBeanPaths"); String beanPathsStr = props.getProperty("beanpanel.beans.path"); if ((beanPathsStr != null) && ((beanPathsStr = beanPathsStr.trim()).length() != 0)) { StringTokenizer st = new StringTokenizer(beanPathsStr, " "); while (st.hasMoreTokens()) beanPaths.add(st.nextToken()); } if (Debug.debugging("beanpanel")) Debug.output("beanPaths=" + beanPaths); if (Debug.debugging("beanpanel")) Debug.output("Exit> BP::loadBeanPaths"); } private void loadToolBarTabInfo(Properties props) { if (Debug.debugging("beanpanel")) Debug.output("Enter> BP::loadToolBarTabInfo"); String tabsStr = props.getProperty("beanpanel.tabs"); if ((tabsStr != null) && ((tabsStr = tabsStr.trim()).length() != 0)) { StringTokenizer st = new StringTokenizer(tabsStr, " "); while (st.hasMoreTokens()) { String tab = st.nextToken(); String tabName = props.getProperty("beanpanel." + tab + ".name"); String beanClassesStr = props.getProperty("beanpanel." + tab + ".beans"); if ((beanClassesStr != null) && ((beanClassesStr = beanClassesStr.trim()).length() > 0)) { StringTokenizer st2 = new StringTokenizer(beanClassesStr, " "); Vector beanClassNames = new Vector(); while (st2.hasMoreTokens()) beanClassNames.add(st2.nextToken()); toolbarTabInfo.put(tabName, beanClassNames); toolbarTabOrder.add(tabName); } } } if (Debug.debugging("beanpanel")) Debug.output("toolbarTabInfo=" + toolbarTabInfo); if (Debug.debugging("beanpanel")) Debug.output("toolbarTabOrder=" + toolbarTabOrder); if (Debug.debugging("beanpanel")) Debug.output("Exit> BP::loadToolBarTabInfo"); } private void setDragCursor(int index) { ImageIcon icon = (ImageIcon) beanIcons.get(index); Point offset = new Point(0, 0); Image img = icon.getImage(); customCursor = Toolkit.getDefaultToolkit().createCustomCursor(img, offset, ""); } private class BeanHelper implements DoOnBean { public void action(JarInfo ji, BeanInfo bi, Class beanClass, String beanName) { if (Debug.debugging("beanpanel")) Debug.output("Enter> ACTION: " + beanName); if (Debug.debugging("beanpanel")) Debug.output("ACTION: " + beanName); if (Debug.debugging("beanpanel")) Debug.output("bi: " + bi); if (Debug.debugging("beanpanel")) Debug.output("bi.getClass(): " + bi.getClass()); String label; ImageIcon icon = null; if (beanName.equals(beanClass.getName())) { if (Debug.debugging("beanpanel")) Debug.output("beanName=" + beanName); BeanDescriptor bd = bi.getBeanDescriptor(); if (bd != null) label = bd.getDisplayName(); else { int index = beanName.lastIndexOf("."); if (index >= 0 && index < beanName.length() - 1) label = beanName.substring(index + 1, beanName.length()); else label = beanName; } if (Debug.debugging("beanpanel")) Debug.output("label=" + label); Image img = bi.getIcon(BeanInfo.ICON_COLOR_32x32); if (Debug.debugging("beanpanel")) Debug.output("img=" + img); if (img == null) { URL url = this.getClass().getResource("bluebean.gif"); icon = new ImageIcon(url); } else icon = new ImageIcon(img); } else { label = beanName; int ix = beanName.lastIndexOf('.'); if (ix >= 0) label = beanName.substring(ix + 1); } beanLabels.addElement(label); beanNames.addElement(beanClass.getName()); beanIcons.addElement(icon); beanJars.addElement(ji); beanInfos.addElement(bi); if (Debug.debugging("beanpanel")) Debug.output("Exit> ACTION: " + beanName); } public void error(String message, Exception e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -