metabean.java
来自「Weka」· Java 代码 · 共 578 行 · 第 1/2 页
JAVA
578 行
* an event that could be generated by this bean * * @param eventName the name of the event in question * @return true if the named event could be generated at this point in * time */ public boolean eventGeneratable(String eventName) { for (int i = 0; i < m_outputs.size(); i++) { BeanInstance output = (BeanInstance)m_outputs.elementAt(i); if (output.getBean() instanceof EventConstraints) { if (((EventConstraints)output.getBean()).eventGeneratable(eventName)) { return true; } } } return false; } /** * Returns true if, at this time, * the object will accept a connection with respect to the * supplied EventSetDescriptor * * @param esd the EventSetDescriptor * @return true if the object will accept a connection */ public boolean connectionAllowed(EventSetDescriptor esd) { Vector targets = getSuitableTargets(esd); for (int i = 0; i < targets.size(); i++) { BeanInstance input = (BeanInstance)targets.elementAt(i); if (input.getBean() instanceof BeanCommon) { if (((BeanCommon)input.getBean()).connectionAllowed(esd)) { return true; } } else { return true; } } return false; } public boolean connectionAllowed(String eventName) { return false; } /** * Notify this object that it has been registered as a listener with * a source with respect to the named event. This is just a dummy * method in this class to satisfy the interface. Specific code * in BeanConnection takes care of this method for MetaBeans * * @param eventName the event * @param source the source with which this object has been registered as * a listener */ public synchronized void connectionNotification(String eventName, Object source) { } /** * Notify this object that it has been deregistered as a listener with * a source with respect to the supplied event name. This is just a dummy * method in this class to satisfy the interface. Specific code * in BeanConnection takes care of this method for MetaBeans * * @param eventName the event * @param source the source with which this object has been registered as * a listener */ public synchronized void disconnectionNotification(String eventName, Object source) { } /** * Stop all encapsulated beans */ public void stop() { for (int i = 0; i < m_inputs.size(); i++) { Object temp = m_inputs.elementAt(i); if (temp instanceof BeanCommon) { ((BeanCommon)temp).stop(); } } } /** * Sets the visual appearance of this wrapper bean * * @param newVisual a <code>BeanVisual</code> value */ public void setVisual(BeanVisual newVisual) { m_visual = newVisual; } /** * Gets the visual appearance of this wrapper bean */ public BeanVisual getVisual() { return m_visual; } /** * Use the default visual appearance for this bean */ public void useDefaultVisual() { m_visual.loadIcons(BeanVisual.ICON_PATH+"DiamondPlain.gif", BeanVisual.ICON_PATH+"DiamondPlain.gif"); } /** * Return an enumeration of requests that can be made by the user * * @return an <code>Enumeration</code> value */ public Enumeration enumerateRequests() { Vector newVector = new Vector(); if (m_subFlowPreview != null) { String text = "Show preview"; if (m_previewWindow != null) { text = "$"+text; } newVector.addElement(text); } for (int i = 0; i < m_subFlow.size(); i++) { BeanInstance temp = (BeanInstance)m_subFlow.elementAt(i); if (temp.getBean() instanceof UserRequestAcceptor) { String prefix = (temp.getBean() instanceof WekaWrapper) ? ((WekaWrapper)temp.getBean()).getWrappedAlgorithm().getClass().getName() : temp.getBean().getClass().getName(); prefix = prefix.substring(prefix.lastIndexOf('.')+1, prefix.length()); prefix = ""+(i+1)+": ("+prefix+")"; Enumeration en = ((UserRequestAcceptor)temp.getBean()).enumerateRequests(); while (en.hasMoreElements()) { String req = (String)en.nextElement(); if (req.charAt(0) == '$') { prefix = '$'+prefix; req = req.substring(1, req.length()); } newVector.add(prefix+" "+req); } } } return newVector.elements(); } public void setSubFlowPreview(ImageIcon sfp) { m_subFlowPreview = sfp; } private void showPreview() { if (m_previewWindow == null) { JLabel jl = new JLabel(m_subFlowPreview); //Dimension d = jl.getPreferredSize(); jl.setLocation(0,0); m_previewWindow = new JWindow(); //popup.getContentPane().setLayout(null); m_previewWindow.getContentPane().add(jl); m_previewWindow.validate(); m_previewWindow.setSize(m_subFlowPreview.getIconWidth(), m_subFlowPreview.getIconHeight()); m_previewWindow.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { m_previewWindow.dispose(); m_previewWindow = null; } }); m_previewWindow.setLocation( getParent().getLocationOnScreen().x + getX() + getWidth() / 2 - m_subFlowPreview.getIconWidth() / 2, getParent().getLocationOnScreen().y + getY() + getHeight() / 2 - m_subFlowPreview.getIconHeight() / 2); //popup.pack(); m_previewWindow.setVisible(true); m_previewTimer = new javax.swing.Timer(8000, new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (m_previewWindow != null) { m_previewWindow.dispose(); m_previewWindow = null; m_previewTimer = null; } } }); m_previewTimer.setRepeats(false); m_previewTimer.start(); } } /** * Perform a particular request * * @param request the request to perform * @exception IllegalArgumentException if an error occurs */ public void performRequest(String request) { if (request.compareTo("Show preview") == 0) { showPreview(); return; } // first grab the index if any if (request.indexOf(":") < 0) { return; } String tempI = request.substring(0, request.indexOf(':')); int index = Integer.parseInt(tempI); index--; String req = request.substring(request.indexOf(')')+1, request.length()).trim(); UserRequestAcceptor target = (UserRequestAcceptor)(((BeanInstance)m_subFlow.elementAt(index)).getBean()); target.performRequest(req); } /** * Set a logger * * @param logger a <code>Logger</code> value */ public void setLog(Logger logger) { m_log = logger; } public void removePropertyChangeListenersSubFlow(PropertyChangeListener pcl) { for (int i = 0; i < m_subFlow.size(); i++) { BeanInstance temp = (BeanInstance)m_subFlow.elementAt(i); if (temp.getBean() instanceof Visible) { ((Visible)(temp.getBean())).getVisual(). removePropertyChangeListener(pcl); } if (temp.getBean() instanceof MetaBean) { ((MetaBean)temp.getBean()).removePropertyChangeListenersSubFlow(pcl); } } } public void addPropertyChangeListenersSubFlow(PropertyChangeListener pcl) { for (int i = 0; i < m_subFlow.size(); i++) { BeanInstance temp = (BeanInstance)m_subFlow.elementAt(i); if (temp.getBean() instanceof Visible) { ((Visible)(temp.getBean())).getVisual(). addPropertyChangeListener(pcl); } if (temp.getBean() instanceof MetaBean) { ((MetaBean)temp.getBean()).addPropertyChangeListenersSubFlow(pcl); } } } /** * Checks to see if any of the inputs to this group implements * the supplied listener class * * @param listenerClass the listener to check for */ public boolean canAcceptConnection(Class listenerClass) { for (int i = 0; i < m_inputs.size(); i++) { BeanInstance input = (BeanInstance)m_inputs.elementAt(i); if (listenerClass.isInstance(input.getBean())) { return true; } } return false; } /** * Return a list of input beans capable of receiving the * supplied event * * @param esd the event in question * @return a vector of beans capable of handling the event */ public Vector getSuitableTargets(EventSetDescriptor esd) { Class listenerClass = esd.getListenerType(); // class of the listener Vector targets = new Vector(); for (int i = 0; i < m_inputs.size(); i++) { BeanInstance input = (BeanInstance)m_inputs.elementAt(i); if (listenerClass.isInstance(input.getBean())) { targets.add(input); } } return targets; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?