📄 knowledgeflowapp.java
字号:
m_toolBarBean = null;
m_mode = NONE;
setCursor(Cursor.
getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
});
m_toolBarGroup.add(m_pointerB);
fixedTools.add(m_newB);
fixedTools.add(m_saveB);
fixedTools.add(m_loadB);
Dimension dP = m_saveB.getPreferredSize();
Dimension dM = m_saveB.getMaximumSize();
fixedTools.setFloatable(false);
m_pointerB.setPreferredSize(dP);
m_pointerB.setMaximumSize(dM);
toolBarPanel.add(fixedTools, BorderLayout.WEST);
JToolBar fixedTools2 = new JToolBar();
fixedTools2.setOrientation(JToolBar.VERTICAL);
fixedTools2.setFloatable(false);
fixedTools2.add(m_pointerB);
fixedTools2.add(m_helpB);
fixedTools2.add(m_stopB);
m_helpB.setPreferredSize(dP);
m_helpB.setMaximumSize(dP);
toolBarPanel.add(fixedTools2, BorderLayout.EAST);
m_saveB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
saveLayout();
}
});
m_loadB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loadLayout();
}
});
m_stopB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Vector components = BeanInstance.getBeanInstances();
for (int i = 0; i < components.size(); i++) {
Object temp = ((BeanInstance)components.elementAt(i)).getBean();
if (temp instanceof BeanCommon) {
((BeanCommon)temp).stop();
}
}
}
});
m_helpB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
popupHelp();
}
});
m_newB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
clearLayout();
}
});
final int STANDARD_TOOLBAR = 0;
final int WEKAWRAPPER_TOOLBAR = 1;
int toolBarType = STANDARD_TOOLBAR;
// set up wrapper toolbars
for (int i = 0; i < TOOLBARS.size(); i++) {
Vector tempBarSpecs = (Vector)TOOLBARS.elementAt(i);
// name for the tool bar
String tempBarName = (String)tempBarSpecs.elementAt(0);
// Used for weka leaf packages
Box singletonHolderPanel = null;
// name of the bean component to handle this class of weka algorithms
String tempBeanCompName = (String)tempBarSpecs.elementAt(1);
// a JPanel holding an instantiated bean + label ready to be added
// to the current toolbar
JPanel tempBean;
// the root package for weka algorithms
String rootPackage = "";
weka.gui.HierarchyPropertyParser hpp = null;
Hashtable hpps = null;
// Is this a wrapper toolbar?
if (tempBeanCompName.compareTo("null") != 0) {
tempBean = null;
toolBarType = WEKAWRAPPER_TOOLBAR;
rootPackage = (String)tempBarSpecs.elementAt(2);
// hpp = (weka.gui.HierarchyPropertyParser)tempBarSpecs.elementAt(3);
hpps = (Hashtable)tempBarSpecs.elementAt(3);
try {
Beans.instantiate(null, tempBeanCompName);
} catch (Exception ex) {
// ignore
System.err.println("Failed to instantiate: "+tempBeanCompName);
break;
}
} else {
toolBarType = STANDARD_TOOLBAR;
}
// a toolbar to hold buttons---one for each algorithm
JToolBar tempToolBar = new JToolBar();
// System.err.println(tempToolBar.getLayout());
// tempToolBar.setLayout(new FlowLayout());
int z = 2;
if (toolBarType == WEKAWRAPPER_TOOLBAR) {
Enumeration enm = hpps.keys();
while (enm.hasMoreElements()) {
String root = (String) enm.nextElement();
String userPrefix = "";
hpp = (HierarchyPropertyParser) hpps.get(root);
if (!hpp.goTo(rootPackage)) {
System.err.println("**** Processing user package... ");
// System.exit(1);
userPrefix = root+".";
}
String [] primaryPackages = hpp.childrenValues();
for (int kk = 0; kk < primaryPackages.length; kk++) {
hpp.goToChild(primaryPackages[kk]);
// check to see if this is a leaf - if so then there are no
// sub packages
if (hpp.isLeafReached()) {
if (singletonHolderPanel == null) {
singletonHolderPanel = Box.createHorizontalBox();
singletonHolderPanel.setBorder(javax.swing.BorderFactory.
createTitledBorder(tempBarName));
}
String algName = hpp.fullValue();
tempBean = instantiateToolBarBean(true,
tempBeanCompName, algName);
if (tempBean != null) {
// tempToolBar.add(tempBean);
singletonHolderPanel.add(tempBean);
}
hpp.goToParent();
} else {
// make a titledborder JPanel to hold all the schemes in this
// package
// JPanel holderPanel = new JPanel();
Box holderPanel = Box.createHorizontalBox();
holderPanel.setBorder(javax.swing.BorderFactory.
createTitledBorder(userPrefix+primaryPackages[kk]));
processPackage(holderPanel, tempBeanCompName, hpp);
tempToolBar.add(holderPanel);
}
}
if (singletonHolderPanel != null) {
tempToolBar.add(singletonHolderPanel);
singletonHolderPanel = null;
}
}
} else {
Box holderPanel = Box.createHorizontalBox();
holderPanel.setBorder(javax.swing.BorderFactory.
createTitledBorder(tempBarName));
for (int j = z; j < tempBarSpecs.size(); j++) {
tempBean = null;
tempBeanCompName = (String)tempBarSpecs.elementAt(j);
tempBean =
instantiateToolBarBean((toolBarType == WEKAWRAPPER_TOOLBAR),
tempBeanCompName, "");
if (tempBean != null) {
// set tool tip text (if any)
// setToolTipText(tempBean)
holderPanel.add(tempBean);
}
}
tempToolBar.add(holderPanel);
}
JScrollPane tempJScrollPane =
createScrollPaneForToolBar(tempToolBar);
// ok, now create tabbed pane to hold this toolbar
m_toolBars.addTab(tempBarName, null,
tempJScrollPane,
tempBarName);
}
toolBarPanel.add(m_toolBars, BorderLayout.CENTER);
// add(m_toolBars, BorderLayout.NORTH);
add(toolBarPanel, BorderLayout.NORTH);
}
private JScrollPane createScrollPaneForToolBar(JToolBar tb) {
JScrollPane tempJScrollPane =
new JScrollPane(tb,
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
Dimension d = tb.getPreferredSize();
tempJScrollPane.setMinimumSize(new Dimension((int)d.getWidth(),
(int)(d.getHeight()+15)));
tempJScrollPane.setPreferredSize(new Dimension((int)d.getWidth(),
(int)(d.getHeight()+15)));
tempJScrollPane.getHorizontalScrollBar().setUnitIncrement(
m_ScrollBarIncrementComponents);
return tempJScrollPane;
}
private void processPackage(JComponent holderPanel,
String tempBeanCompName,
weka.gui.HierarchyPropertyParser hpp) {
if (hpp.isLeafReached()) {
// instantiate a bean and add it to the holderPanel
// System.err.println("Would add "+hpp.fullValue());
String algName = hpp.fullValue();
JPanel tempBean =
instantiateToolBarBean(true, tempBeanCompName, algName);
if (tempBean != null) {
holderPanel.add(tempBean);
}
hpp.goToParent();
return;
}
String [] children = hpp.childrenValues();
for (int i = 0; i < children.length; i++) {
hpp.goToChild(children[i]);
processPackage(holderPanel, tempBeanCompName, hpp);
}
hpp.goToParent();
}
/**
* Instantiates a bean for display in the toolbars
*
* @param wekawrapper true if the bean to be instantiated is a wekawrapper
* @param tempBeanCompName the name of the bean to instantiate
* @param algName holds the name of a weka algorithm to configure the
* bean with if it is a wekawrapper bean
* @return a JPanel holding the instantiated (and configured bean)
*/
private JPanel instantiateToolBarBean(boolean wekawrapper,
String tempBeanCompName,
String algName) {
Object tempBean;
if (wekawrapper) {
try {
tempBean = Beans.instantiate(null, tempBeanCompName);
} catch (Exception ex) {
System.err.println("Failed to instantiate :"+tempBeanCompName
+"KnowledgeFlowApp.instantiateToolBarBean()");
return null;
}
if (tempBean instanceof WekaWrapper) {
// algName = (String)tempBarSpecs.elementAt(j);
Class c = null;
try {
c = Class.forName(algName);
} catch (Exception ex) {
System.err.println("Can't find class called: "+algName);
return null;
}
try {
Object o = c.newInstance();
((WekaWrapper)tempBean).setWrappedAlgorithm(o);
} catch (Exception ex) {
System.err.println("Failed to configure "+tempBeanCompName
+" with "+algName);
return null;
}
}
} else {
try {
tempBean = Beans.instantiate(null, tempBeanCompName);
} catch (Exception ex) {
ex.printStackTrace();
System.err.println("Failed to instantiate :"+tempBeanCompName
+"KnowledgeFlowApp.setUpToolBars()");
return null;
}
}
if (tempBean instanceof BeanContextChild) {
m_bcSupport.add(tempBean);
}
if (tempBean instanceof Visible) {
((Visible)tempBean).getVisual().scale(3);
}
return makeHolderPanelForToolBarBean(tempBeanCompName, tempBean,
wekawrapper, algName, false);
}
/**
* Instantiates (by making a serialized copy) the supplied
* template meta bean for display in the user tool bar
*
* @param bean the prototype MetaBean to display in the toolbar
*/
private JPanel instantiateToolBarMetaBean(MetaBean bean) {
// copy the bean via serialization
((Visible)bean).getVisual().removePropertyChangeListener(this);
bean.removePropertyChangeListenersSubFlow(this);
Object copy = null;
try {
SerializedObject so = new SerializedObject(bean);
copy = (MetaBean)so.getObject();
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
((Visible)bean).getVisual().addPropertyChangeListener(this);
bean.addPropertyChangeListenersSubFlow(this);
String displayName ="";
//
if (copy instanceof Visible) {
((Visible)copy).getVisual().scale(3);
displayName = ((Visible)copy).getVisual().getText();
}
return makeHolderPanelForToolBarBean(displayName,
copy,
false,
null,
true);
}
private JPanel makeHolderPanelForToolBarBean(final String tempName,
Object tempBean,
boolean wekawrapper,
String algName,
final boolean metabean) {
// ---------------------------------------
JToggleButton tempButton;
final JPanel tempP = new JPanel();
JLabel tempL = new JLabel();
tempL.setFont(new Font("Monospaced", Font.PLAIN, 10));
String labelName = (wekawrapper == true)
? algName
: tempName;
labelName = labelName.substring(labelName.lastIndexOf('.')+1,
labelName.length());
tempL.setText(" "+labelName+" ");
tempL.setHorizontalAlignment(JLabel.CENTER);
tempP.setLayout(new BorderLayout());
if (tempBean instanceof Visible) {
BeanVisual bv = ((Visible)tempBean).getVisual();
tempButton =
new JToggleButton(bv.getStaticIcon());
int width = bv.getStaticIcon().getIconWidth();
int height = bv.getStaticIcon().getIconHeight();
JPanel labelPanel =
multiLineLabelPanel(labelName, width);
tempP.add(labelPanel, BorderLayout.SOUTH);
} else {
tempButton = new JToggleButton();
tempP.add(tempL, BorderLayout.SOUTH);
}
tempP.add(tempButton, BorderLayout.NORTH);
// tempP.add(tempL, BorderLayout.SOUTH);
// holderPanel.add(tempP);
// tempToolBar.add(tempP);
m_toolBarGroup.add(tempButton);
// add an action listener for the button here
final Object tempBN = tempBean;
final JToggleButton fButton = tempButton;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -