⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 knowledgeflowapp.java

📁 MacroWeka扩展了著名数据挖掘工具weka
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    //	  final JToggleButton tempButton2 = tempButton;
    tempButton.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent e) {
          boolean changeCursor = true;
	  try {
	    m_toolBarBean = null;
            if (metabean) {
              if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0) {
                changeCursor = false;
                m_toolBarGroup.remove(fButton);
                m_userBoxPanel.remove(tempP);
                m_userBoxPanel.revalidate();
                m_userComponents.remove(tempBN);
                if (m_firstUserComponentOpp) {
                  installWindowListenerForSavingUserBeans();
                  m_firstUserComponentOpp = false;
                }
                if (m_userComponents.size() == 0) {
                  m_toolBars.removeTabAt(m_toolBars.getTabCount() - 1);
                  m_userToolBar = null;
                }
              } else {
                SerializedObject so = new SerializedObject(tempBN);
                MetaBean copy = (MetaBean)so.getObject();
                ((Visible)copy).getVisual().
                  addPropertyChangeListener(KnowledgeFlowApp.this);
                copy.addPropertyChangeListenersSubFlow(KnowledgeFlowApp.this);
                m_toolBarBean = copy;
              }
            } else {
              m_toolBarBean = Beans.instantiate(null, tempName);
            }
            if (m_toolBarBean instanceof WekaWrapper) {
	      Object wrappedAlg = 
		((WekaWrapper)tempBN).getWrappedAlgorithm();
	      
	      ((WekaWrapper)m_toolBarBean).
                setWrappedAlgorithm(wrappedAlg.getClass().newInstance());
	      //		    tempButton2.setSelected(false);
	    }
            if (changeCursor) {
              setCursor(Cursor.
                        getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
              m_mode = ADDING;
            }
	  } catch (Exception ex) {
	    System.err.
	      println("Problem adding bean to data flow layout");
	  }
	}
      });
    
    if (tempBean instanceof MetaBean) {
      tempButton.setToolTipText("Hold down shift and click to remove");
      m_userComponents.add(tempBean);
    } else {
      // set tool tip text from global info if supplied
      String summary = getGlobalInfo(tempBean);
      if (summary != null) {
        int ci = summary.indexOf('.');
        if (ci != -1) {
          summary = summary.substring(0, ci + 1);
        }
        tempButton.setToolTipText(summary);
      }
    }

    //return tempBean;
    return tempP;
  }

  private JPanel multiLineLabelPanel(String sourceL,
				     int splitWidth) {
    JPanel jp = new JPanel();
    Vector v = new Vector();

    int labelWidth = m_fontM.stringWidth(sourceL);

    if (labelWidth < splitWidth) {
      v.addElement(sourceL);
    } else {
      // find mid point
      int mid = sourceL.length() / 2;
      
      // look for split point closest to the mid
      int closest = sourceL.length();
      int closestI = -1;
      for (int i = 0; i < sourceL.length(); i++) {
	if (sourceL.charAt(i) < 'a') {
	  if (Math.abs(mid - i) < closest) {
	    closest = Math.abs(mid - i);
	    closestI = i;
	  }
	}
      }
      if (closestI != -1) {
	String left = sourceL.substring(0, closestI);
	String right = sourceL.substring(closestI, sourceL.length());
	if (left.length() > 1 && right.length() > 1) {
	  v.addElement(left);
	  v.addElement(right);
	} else {
	  v.addElement(sourceL);
	}
      } else {
	v.addElement(sourceL);
      }
    }

    jp.setLayout(new GridLayout(v.size(), 1));
    for (int i = 0; i < v.size(); i++) {
      JLabel temp = new JLabel();
      temp.setFont(new Font("Monospaced", Font.PLAIN, 10));
      temp.setText(" "+((String)v.elementAt(i))+" ");
      temp.setHorizontalAlignment(JLabel.CENTER);
      jp.add(temp);
    }
    return jp;
  }

  private void setUpUserToolBar() {
    m_userBoxPanel = Box.createHorizontalBox();
    m_userBoxPanel.setBorder(javax.swing.BorderFactory.
                             createTitledBorder("User"));
    m_userToolBar = new JToolBar();
    m_userToolBar.add(m_userBoxPanel);
    JScrollPane tempJScrollPane = 
      createScrollPaneForToolBar(m_userToolBar);
    // ok, now create tabbed pane to hold this toolbar
    
    m_toolBars.addTab("User", null, 
                      tempJScrollPane,
                      "User created components");
  }

  /**
   * Pop up a help window
   */
  private void popupHelp() {
    final JButton tempB = m_helpB;
    try {
      tempB.setEnabled(false);
      InputStream inR = 
	ClassLoader.
        getSystemResourceAsStream("weka/gui/beans/README_KnowledgeFlow");
      StringBuffer helpHolder = new StringBuffer();
      LineNumberReader lnr = new LineNumberReader(new InputStreamReader(inR));
      
      String line;
      
      while ((line = lnr.readLine()) != null) {
	helpHolder.append(line+"\n");
      }
      
      lnr.close();
      final javax.swing.JFrame jf = new javax.swing.JFrame();
      jf.getContentPane().setLayout(new java.awt.BorderLayout());
      final JTextArea ta = new JTextArea(helpHolder.toString());
      ta.setFont(new Font("Monospaced", Font.PLAIN, 12));
      ta.setEditable(false);
      final JScrollPane sp = new JScrollPane(ta);
      jf.getContentPane().add(sp, java.awt.BorderLayout.CENTER);
      jf.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent e) {
	  tempB.setEnabled(true);
          jf.dispose();
        }
      });
      jf.setSize(600,600);
      jf.setVisible(true);
      
    } catch (Exception ex) {
      tempB.setEnabled(true);
    }
  }

  public void clearLayout() {
    BeanInstance.reset(m_beanLayout);
    BeanConnection.reset();
    m_beanLayout.revalidate();
    m_beanLayout.repaint();
  }
  
  /**
   * Popup a context sensitive menu for the bean component
   *
   * @param pt holds the panel coordinates for the component
   * @param bi the bean component over which the user right clicked the mouse
   * @param x the x coordinate at which to popup the menu
   * @param y the y coordinate at which to popup the menu
   */
  private void doPopup(Point pt, final BeanInstance bi,
		       int x, int y) {

    final JComponent bc = (JComponent)bi.getBean();
    final int xx = x;
    final int yy = y;
    int menuItemCount = 0;
    JPopupMenu beanContextMenu = new JPopupMenu();

    beanContextMenu.insert(new JLabel("Edit", 
				      SwingConstants.CENTER), 
			   menuItemCount);
    menuItemCount++;
    if (bc instanceof MetaBean) {
      JMenuItem ungroupItem = new JMenuItem("Ungroup");
      ungroupItem.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // ungroup
            bi.removeBean(m_beanLayout);
            Vector group = ((MetaBean)bc).getBeansInSubFlow();
            Vector associatedConnections = 
              ((MetaBean)bc).getAssociatedConnections();
            ((MetaBean)bc).restoreBeans();
            for (int i = 0; i < group.size(); i++) {
              BeanInstance tbi = (BeanInstance)group.elementAt(i);
              addComponent(tbi, false);
              tbi.addBean(m_beanLayout);
            }
            for (int i = 0; i < associatedConnections.size(); i++) {
              BeanConnection tbc = 
                (BeanConnection)associatedConnections.elementAt(i);
              tbc.setHidden(false);
            }
            m_beanLayout.repaint();
          }
        });
      beanContextMenu.add(ungroupItem);
      menuItemCount++;
      // Add to user tab
      JMenuItem addToUserTabItem = new JMenuItem("Add to user tab");
      addToUserTabItem.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            addToUserToolBar((MetaBean)bi.getBean(), true);
          }
        });
      beanContextMenu.add(addToUserTabItem);
      menuItemCount++;
    }
    JMenuItem deleteItem = new JMenuItem("Delete");
    deleteItem.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent e) {
	  BeanConnection.removeConnections(bi);
	  bi.removeBean(m_beanLayout);
	  revalidate();
	}
      });
    beanContextMenu.add(deleteItem);
    menuItemCount++;

    try {
      //BeanInfo [] compInfo = null;
      //JComponent [] associatedBeans = null;
      Vector compInfo = new Vector(1);
      Vector associatedBeans = null;
      Vector outputBeans = null;
      Vector compInfoOutputs = null;
      if (bc instanceof MetaBean) {
        compInfo = ((MetaBean)bc).getBeanInfoSubFlow();        
        associatedBeans = ((MetaBean)bc).getBeansInSubFlow();

        outputBeans = ((MetaBean)bc).getBeansInOutputs();
        compInfoOutputs = ((MetaBean)bc).getBeanInfoOutputs();
      } else {
        compInfo.add(Introspector.getBeanInfo(bc.getClass()));
        compInfoOutputs = compInfo;
      }
      final Vector tempAssociatedBeans = associatedBeans;
      if (compInfo == null) {
	System.err.println("Error");
      } else {
	//	System.err.println("Got bean info");
        for (int zz = 0; zz < compInfo.size(); zz++) {
          final int tt = zz;
          final Class custClass = 
            ((BeanInfo)compInfo.elementAt(zz)).getBeanDescriptor().
            getCustomizerClass();

          if (custClass != null) {
            //	  System.err.println("Got customizer class");
            //	  popupCustomizer(custClass, bc);
            JMenuItem custItem = null;
            if (!(bc instanceof MetaBean)) {
              custItem = new JMenuItem("Configure...");
            } else {
              String custName = custClass.getName();
              BeanInstance tbi = 
                (BeanInstance)associatedBeans.elementAt(zz);
              if (tbi.getBean() instanceof WekaWrapper) {
                custName = ((WekaWrapper)tbi.getBean()).
                  getWrappedAlgorithm().getClass().getName();
              } else {
                custName = custName.substring(0, custName.indexOf("Customizer"));
              }
              custName = custName.
                substring(custName.lastIndexOf('.')+1 , custName.length());
              custItem = new JMenuItem("Configure: "+ custName);
            }
            custItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  if (bc instanceof MetaBean) {
                    popupCustomizer(custClass, 
                                    (JComponent)((BeanInstance)tempAssociatedBeans.
                                                 elementAt(tt)).getBean());
                  } else {
                    popupCustomizer(custClass, bc);
                  }
                }
              });
            beanContextMenu.add(custItem);
            menuItemCount++;
         
          } else {
            System.err.println("No customizer class");
          }
        }
        Vector esdV = new Vector();
        for (int i = 0; i < compInfoOutputs.size(); i++) {
          EventSetDescriptor [] temp = 
            ((BeanInfo)compInfoOutputs.elementAt(i)).getEventSetDescriptors();
          if (temp != null && temp.length > 0) {
            esdV.add(temp);
          }
        }
        //        EventSetDescriptor [] esds = compInfo.getEventSetDescriptors();
        //        if (esds != null && esds.length > 0) {
        if (esdV.size() > 0) {
          beanContextMenu.insert(new JLabel("Connections", 
                                            SwingConstants.CENTER), 
                                 menuItemCount);
          menuItemCount++;
	}
        final Vector finalOutputs = outputBeans;
        for (int j = 0; j < esdV.size(); j++) {
          final int fj = j;
          String sourceBeanName="";
          if (bc instanceof MetaBean) {
            Object sourceBean = ((BeanInstance)outputBeans.elementAt(j)).getBean();
            if (sourceBean instanceof WekaWrapper) {
              sourceBeanName = ((WekaWrapper)sourceBean).
                getWrappedAlgorithm().getClass().getName();
            } else {
              sourceBeanName = sourceBean.getClass().getName();
            }
            sourceBeanName = sourceBeanName.
              substring(sourceBeanName.lastIndexOf('.')+1, sourceBeanName.length());
            sourceBeanName += ": ";
          }
          EventSetDescriptor [] esds = 
            (EventSetDescriptor [])esdV.elementAt(j);
          for (int i = 0; i < esds.length; i++) {
            //	  System.err.println(esds[i].getName());
            // add each event name to the menu
            JMenuItem evntItem = new JMenuItem(sourceBeanName
                                               +esds[i].getName());
            final EventSetDescriptor esd = esds[i];
            // Check EventConstraints (if any) here
            boolean ok = true;
            if (bc instanceof EventConstraints) {
              ok = ((EventConstraints) bc).eventGeneratable(esd.getName());
            }
            if (ok) {
              evntItem.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                    connectComponents(esd, (bc instanceof MetaBean)
                                      ? ((BeanInstance)finalOutputs.elementAt(fj))
                                      : bi, 
                                      xx, yy);
                  }
                });
            } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -