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

📄 knowledgeflowapp.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	if (disabled) {	  custItem.setEnabled(false);	}	beanContextMenu.add(custItem);	menuItemCount++;      }    }    //    System.err.println("Just before showing menu");    // popup the menu    if (menuItemCount > 0) {      beanContextMenu.show(m_beanLayout, x, y);    }  }  /**   * Popup the customizer for this bean   *   * @param custClass the class of the customizer   * @param bc the bean to be customized   */  private void popupCustomizer(Class custClass, JComponent bc) {    try {      // instantiate      final Object customizer = custClass.newInstance();      ((Customizer)customizer).setObject(bc);      final javax.swing.JFrame jf = new javax.swing.JFrame();      jf.getContentPane().setLayout(new BorderLayout());      jf.getContentPane().add((JComponent)customizer, BorderLayout.CENTER);      if (customizer instanceof CustomizerCloseRequester) {	((CustomizerCloseRequester)customizer).setParentFrame(jf);      }      jf.addWindowListener(new java.awt.event.WindowAdapter() {	  public void windowClosing(java.awt.event.WindowEvent e) {	    if (customizer instanceof CustomizerClosingListener) {	      ((CustomizerClosingListener)customizer).customizerClosing();	    }	    jf.dispose();	  }	});      jf.pack();      jf.setVisible(true);    } catch (Exception ex) {      ex.printStackTrace();    }  }                                  /**   * Handles adding a custom MetaBean to the user toolbar   *   * @param bean the MetaBean   * @param installListener install a listener for window close   * events so as to save the user components   */  private void addToUserToolBar(MetaBean bean,                                 boolean installListener) {    if (m_userToolBar == null) {      // need to create the user tab and toolbar      setUpUserToolBar();    }    // Disconnect any beans connected to the inputs or outputs    // of this MetaBean (prevents serialization of the entire    // KnowledgeFlow!!)    Vector tempRemovedConnections = new Vector();    Vector allConnections = BeanConnection.getConnections();    Vector inputs = bean.getInputs();    Vector outputs = bean.getOutputs();    for (int i = 0; i < inputs.size(); i++) {      BeanInstance temp = (BeanInstance)inputs.elementAt(i);      // is this input a target for some event?      for (int j = 0; j < allConnections.size(); j++) {        BeanConnection tempC = (BeanConnection)allConnections.elementAt(j);        if (tempC.getTarget() == temp) {          tempRemovedConnections.add(tempC);        }      }    }    for (int i = 0; i < outputs.size(); i++) {      BeanInstance temp = (BeanInstance)outputs.elementAt(i);      // is this output a source for some target?      for (int j = 0; j < allConnections.size(); j++) {        BeanConnection tempC = (BeanConnection)allConnections.elementAt(j);        if (tempC.getSource() == temp) {          tempRemovedConnections.add(tempC);        }      }    }            for (int i = 0; i < tempRemovedConnections.size(); i++) {      BeanConnection temp =         (BeanConnection)tempRemovedConnections.elementAt(i);      temp.remove();    }        // now add to user tool bar    JPanel tempUser = instantiateToolBarMetaBean(bean);    m_userBoxPanel.add(tempUser);    if (installListener && m_firstUserComponentOpp) {      try {        installWindowListenerForSavingUserBeans();        m_firstUserComponentOpp = false;      } catch (Exception ex) {        ex.printStackTrace();      }    }    // Now reinstate any deleted connections to the original MetaBean    for (int i = 0; i < tempRemovedConnections.size(); i++) {      BeanConnection temp =         (BeanConnection)tempRemovedConnections.elementAt(i);      BeanConnection newC =         new BeanConnection(temp.getSource(), temp.getTarget(),                           temp.getSourceEventSetDescriptor());    }      }  /**   * Popup a menu giving choices for connections to delete (if any)   *   * @param closestConnections a vector containing 0 or more BeanConnections   * @param x the x coordinate at which to popup the menu   * @param y the y coordinate at which to popup the menu   */  private void deleteConnectionPopup(Vector closestConnections,				     int x, int y) {    if (closestConnections.size() > 0) {      int menuItemCount = 0;      JPopupMenu deleteConnectionMenu = new JPopupMenu();      deleteConnectionMenu.insert(new JLabel("Delete Connection", 					     SwingConstants.CENTER), 				  menuItemCount);      menuItemCount++;      for (int i = 0; i < closestConnections.size(); i++) {	final BeanConnection bc = 	  (BeanConnection)closestConnections.elementAt(i);	String connName = bc.getSourceEventSetDescriptor().getName();	JMenuItem deleteItem = new JMenuItem(connName);	deleteItem.addActionListener(new ActionListener() {	    public void actionPerformed(ActionEvent e) {	      bc.remove();	      m_beanLayout.revalidate();	      m_beanLayout.repaint();	    }	  });	deleteConnectionMenu.add(deleteItem);	menuItemCount++;      }      deleteConnectionMenu.show(m_beanLayout, x, y);    }  }  /**   * Initiates the connection process for two beans   *   * @param esd the EventSetDescriptor for the source bean   * @param bi the source bean   * @param x the x coordinate to start connecting from   * @param y the y coordinate to start connecting from   */  private void connectComponents(EventSetDescriptor esd, 				 BeanInstance bi,				 int x,				 int y) {    // record the event set descriptior for this event    m_sourceEventSetDescriptor = esd;    Class listenerClass = esd.getListenerType(); // class of the listener    JComponent source = (JComponent)bi.getBean();    // now determine which (if any) of the other beans implement this    // listener    int targetCount = 0;    Vector beanInstances = BeanInstance.getBeanInstances();    for (int i = 0; i < beanInstances.size(); i++) {      JComponent bean = 	(JComponent)((BeanInstance)beanInstances.elementAt(i)).getBean();      boolean connectable = false;      boolean canContinue = false;      if (bean != source) {        if (bean instanceof MetaBean) {          if (((MetaBean)bean).canAcceptConnection(listenerClass)) {            canContinue = true;          }        } else if (listenerClass.isInstance(bean) && bean != source) {          canContinue = true;        }      }      if (canContinue) {	if (!(bean instanceof BeanCommon)) {	  connectable = true; // assume this bean is happy to receive a connection	} else {	  // give this bean a chance to veto any proposed connection via	  // the listener interface	  if (((BeanCommon)bean).	      connectionAllowed(esd)) {	    connectable = true;	  }	}	if (connectable) {	  if (bean instanceof Visible) {	    targetCount++;	    ((Visible)bean).getVisual().setDisplayConnectors(true);	  }	}      }    }        // have some possible beans to connect to?    if (targetCount > 0) {      //      System.err.println("target count "+targetCount);      if (source instanceof Visible) {	((Visible)source).getVisual().setDisplayConnectors(true);      }      m_editElement = bi;      Point closest = ((Visible)source).getVisual().	getClosestConnectorPoint(new Point(x, y));      m_startX = (int)closest.getX();      m_startY = (int)closest.getY();      m_oldX = m_startX;      m_oldY = m_startY;      Graphics2D gx = (Graphics2D)m_beanLayout.getGraphics();      gx.setXORMode(java.awt.Color.white);      gx.drawLine(m_startX, m_startY, m_startX, m_startY);      gx.dispose();      m_mode = CONNECTING;    }  }  private void addComponent(BeanInstance comp, boolean repaint) {    if (comp.getBean() instanceof Visible) {      ((Visible)comp.getBean()).getVisual().addPropertyChangeListener(this);    }    if (comp.getBean() instanceof BeanCommon) {      ((BeanCommon)comp.getBean()).setLog(m_logPanel);    }    if (comp.getBean() instanceof MetaBean) {      // re-align sub-beans      Vector list;            list = ((MetaBean) comp.getBean()).getInputs();      for (int i = 0; i < list.size(); i++) {        ((BeanInstance) list.get(i)).setX(comp.getX());        ((BeanInstance) list.get(i)).setY(comp.getY());      }      list = ((MetaBean) comp.getBean()).getOutputs();      for (int i = 0; i < list.size(); i++) {        ((BeanInstance) list.get(i)).setX(comp.getX());        ((BeanInstance) list.get(i)).setY(comp.getY());      }    }    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));    if (repaint) {      m_beanLayout.repaint();    }    m_pointerB.setSelected(true);    m_mode = NONE;  }  private void addComponent(int x, int y) {    if (m_toolBarBean instanceof MetaBean) {      // need to add the MetaBean's internal connections      // to BeanConnection's vector      Vector associatedConnections =         ((MetaBean)m_toolBarBean).getAssociatedConnections();      BeanConnection.getConnections().addAll(associatedConnections);    }    if (m_toolBarBean instanceof BeanContextChild) {      m_bcSupport.add(m_toolBarBean);    }    BeanInstance bi = new BeanInstance(m_beanLayout, m_toolBarBean, x, y);    //    addBean((JComponent)bi.getBean());    m_toolBarBean = null;    addComponent(bi, true);  }  /**   * Handles the checking of a selected set of components   * for suitability for grouping. If suitable the user   * is prompted for a name and then a MetaBean is used   * group the components.   */  private void checkSubFlow(int startX, int startY,                            int endX, int endY) {    java.awt.Rectangle r =       new java.awt.Rectangle((startX < endX) ? startX : endX,                             (startY < endY) ? startY: endY,                             Math.abs(startX - endX),                             Math.abs(startY - endY));    Vector selected = BeanInstance.findInstances(r);    // check if sub flow is valid    Vector inputs = BeanConnection.inputs(selected);    Vector outputs = BeanConnection.outputs(selected);        // screen the inputs and outputs    if (inputs.size() == 0 || outputs.size() == 0) {      return;    }    // dissallow MetaBeans in the selected set (for the    // time being).    for (int i = 0; i < selected.size(); i++) {      BeanInstance temp = (BeanInstance)selected.elementAt(i);      if (temp.getBean() instanceof MetaBean) {        return;      }    }    // show connector dots for selected beans    for (int i = 0; i < selected.size(); i++) {      BeanInstance temp = (BeanInstance)selected.elementAt(i);      if (temp.getBean() instanceof Visible) {        ((Visible)temp.getBean()).getVisual().setDisplayConnectors(true);      }    }    // show connector dots for input beans    for (int i = 0; i < inputs.size(); i++) {      BeanInstance temp = (BeanInstance)inputs.elementAt(i);      if (temp.getBean() instanceof Visible) {        ((Visible)temp.getBean()).getVisual().          setDisplayConnectors(true, java.awt.Color.red);      }    }    // show connector dots for output beans    for (int i = 0; i < outputs.size(); i++) {      BeanInstance temp = (BeanInstance)outputs.elementAt(i);      if (temp.getBean() instanceof Visible) {        ((Visible)temp.getBean()).getVisual().          setDisplayConnectors(true, java.awt.Color.green);      }    }    // Confirmation pop-up    int result = JOptionPane.showConfirmDialog(KnowledgeFlowApp.this,                                               "Group this sub-flow?",                                               "Group Components",                                               JOptionPane.YES_NO_OPTION);    if (result == JOptionPane.YES_OPTION) {      Vector associatedConnections =         BeanConnection.associatedConnections(selected);      String name = JOptionPane.showInputDialog(KnowledgeFlowApp.this,                                                "Enter a name for this group",                                                "MyGroup");      if (name != null) {               MetaBean group = new MetaBean();        group.setSubFlow(selected);        group.setAssociatedConnections(associatedConnections);        group.setInputs(inputs);        group.setOutputs(outputs);        if (name.length() > 0) {          group.getVisual().setText(name);        }                if (group instanceof BeanContextChild) {          m_bcSupport.add(group);        }        BeanInstance bi = new BeanInstance(m_beanLayout, group,                                            (int)r.getX()+(int)(r.getWidth()/2),                                           (int)r.getY()+(int)(r.getHeight()/2));        for (int i = 0; i < selected.size(); i++) {          BeanInstance temp = (BeanInstance)selected.elementAt(i);          temp.removeBean(m_beanLayout);          if (temp.getBean() instanceof Visible) {       

⌨️ 快捷键说明

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