gui.java
来自「Weka」· Java 代码 · 共 2,050 行 · 第 1/5 页
JAVA
2,050 行
public ActionCenterVertical() {
super("Center Vertical", "Center Vertical", "centervertical", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
m_BayesNet.centerVertical(m_Selection.getSelected());
m_jStatusBar.setText(m_BayesNet.lastActionMsg());
a_undo.setEnabled(true);
a_redo.setEnabled(false);
repaint();
}
} // class ActionCenterVertical
class ActionSpaceHorizontal extends MyAction {
/** for serialization */
private static final long serialVersionUID = -9738642085935519L;
public ActionSpaceHorizontal() {
super("Space Horizontal", "Space Horizontal", "spacehorizontal", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
m_BayesNet.spaceHorizontal(m_Selection.getSelected());
m_jStatusBar.setText(m_BayesNet.lastActionMsg());
a_undo.setEnabled(true);
a_redo.setEnabled(false);
repaint();
}
} // class ActionSpaceHorizontal
class ActionSpaceVertical extends MyAction {
/** for serialization */
private static final long serialVersionUID = -838642085935519L;
public ActionSpaceVertical() {
super("Space Vertical", "Space Vertical", "spacevertical", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
m_BayesNet.spaceVertical(m_Selection.getSelected());
m_jStatusBar.setText(m_BayesNet.lastActionMsg());
a_undo.setEnabled(true);
a_redo.setEnabled(false);
repaint();
}
} // class ActionSpaceVertical
class ActionAddArc extends MyAction {
/** for serialization */
private static final long serialVersionUID = -2038913085935519L;
public ActionAddArc() {
super("Add Arc", "Add Arc", "addarc", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
try {
String[] options = new String[m_BayesNet.getNrOfNodes()];
for (int i = 0; i < options.length; i++) {
options[i] = m_BayesNet.getNodeName(i);
}
String sChild = (String) JOptionPane.showInputDialog(null, "Select child node", "Nodes", 0, null,
options, options[0]);
if (sChild == null || sChild.equals("")) {
return;
}
int iChild = m_BayesNet.getNode(sChild);
addArcInto(iChild);
} catch (Exception e) {
e.printStackTrace();
}
}
} // class ActionAddArc
class ActionDeleteArc extends MyAction {
/** for serialization */
private static final long serialVersionUID = -2038914085935519L;
public ActionDeleteArc() {
super("Delete Arc", "Delete Arc", "delarc", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
int nEdges = 0;
for (int iNode = 0; iNode < m_BayesNet.getNrOfNodes(); iNode++) {
nEdges += m_BayesNet.getNrOfParents(iNode);
}
String[] options = new String[nEdges];
int i = 0;
for (int iNode = 0; iNode < m_BayesNet.getNrOfNodes(); iNode++) {
for (int iParent = 0; iParent < m_BayesNet.getNrOfParents(iNode); iParent++) {
int nParent = m_BayesNet.getParent(iNode, iParent);
String sEdge = m_BayesNet.getNodeName(nParent);
sEdge += " -> ";
sEdge += m_BayesNet.getNodeName(iNode);
options[i++] = sEdge;
}
}
deleteArc(options);
}
} // class ActionDeleteArc
class ActionNew extends MyAction {
/** for serialization */
private static final long serialVersionUID = -2038911085935515L;
public ActionNew() {
super("New", "New Network", "new", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
m_sFileName = "";
m_BayesNet = new EditableBayesNet(true);
updateStatus();
layoutGraph();
a_datagenerator.setEnabled(false);
m_BayesNet.clearUndoStack();
m_jStatusBar.setText("New Network");
m_Selection = new Selection();
repaint();
}
} // class ActionNew
class ActionLoad extends MyAction {
/** for serialization */
private static final long serialVersionUID = -2038911085935515L;
public ActionLoad() {
super("Load", "Load Graph", "open", "ctrl O");
} // c'tor
public void actionPerformed(ActionEvent ae) {
JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
ExtensionFileFilter ef1 = new ExtensionFileFilter(".arff", "ARFF files");
ExtensionFileFilter ef2 = new ExtensionFileFilter(".xml", "XML BIF files");
fc.addChoosableFileFilter(ef1);
fc.addChoosableFileFilter(ef2);
fc.setDialogTitle("Load Graph");
int rval = fc.showOpenDialog(GUI.this);
if (rval == JFileChooser.APPROVE_OPTION) {
String sFileName = fc.getSelectedFile().toString();
if (sFileName.endsWith(ef1.getExtensions()[0])) {
initFromArffFile(sFileName);
} else {
try {
readBIFFromFile(sFileName);
} catch (Exception e) {
e.printStackTrace();
}
}
m_jStatusBar.setText("Loaded " + sFileName);
updateStatus();
}
}
} // class ActionLoad
class ActionViewStatusbar extends MyAction {
/** for serialization */
private static final long serialVersionUID = -20389330812354L;
public ActionViewStatusbar() {
super("View statusbar", "View statusbar", "statusbar", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
m_jStatusBar.setVisible(!m_jStatusBar.isVisible());
} // actionPerformed
} // class ActionViewStatusbar
class ActionViewToolbar extends MyAction {
/** for serialization */
private static final long serialVersionUID = -20389110812354L;
public ActionViewToolbar() {
super("View toolbar", "View toolbar", "toolbar", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
m_jTbTools.setVisible(!m_jTbTools.isVisible());
} // actionPerformed
} // class ActionViewToolbar
class ActionSave extends MyAction {
/** for serialization */
private static final long serialVersionUID = -20389110859355156L;
public ActionSave() {
super("Save", "Save Graph", "save", "ctrl S");
} // c'tor
public ActionSave(String sName, String sToolTipText, String sIcon, String sAcceleratorKey) {
super(sName, sToolTipText, sIcon, sAcceleratorKey);
} // c'tor
public void actionPerformed(ActionEvent ae) {
if (!m_sFileName.equals("")) {
saveFile(m_sFileName);
m_BayesNet.isSaved();
m_jStatusBar.setText("Saved as " + m_sFileName);
} else {
if (saveAs()) {
m_BayesNet.isSaved();
m_jStatusBar.setText("Saved as " + m_sFileName);
}
}
} // actionPerformed
ExtensionFileFilter ef1 = new ExtensionFileFilter(".xml", "XML BIF files");
boolean saveAs() {
JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
fc.addChoosableFileFilter(ef1);
fc.setDialogTitle("Save Graph As");
if (!m_sFileName.equals("")) {
// can happen on actionQuit
fc.setSelectedFile(new File(m_sFileName));
}
int rval = fc.showSaveDialog(GUI.this);
if (rval == JFileChooser.APPROVE_OPTION) {
// System.out.println("Saving to file \""+
// f.getAbsoluteFile().toString()+"\"");
String sFileName = fc.getSelectedFile().toString();
if (!sFileName.endsWith(".xml"))
sFileName = sFileName.concat(".xml");
saveFile(sFileName);
return true;
}
return false;
} // saveAs
protected void saveFile(String sFileName) {
try {
FileWriter outfile = new FileWriter(sFileName);
outfile.write(m_BayesNet.toXMLBIF03());
outfile.close();
m_sFileName = sFileName;
m_jStatusBar.setText("Saved as " + m_sFileName);
}
catch(IOException e) {
e.printStackTrace();
}
} // saveFile
} // class ActionSave
class ActionSaveAs extends ActionSave {
/** for serialization */
private static final long serialVersionUID = -20389110859354L;
public ActionSaveAs() {
super("Save As", "Save Graph As", "saveas", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
saveAs();
} // actionPerformed
} // class ActionSaveAs
class ActionPrint extends ActionSave {
/** for serialization */
private static final long serialVersionUID = -20389001859354L;
boolean m_bIsPrinting = false;
public ActionPrint() {
super("Print", "Print Graph", "print", "ctrl P");
} // c'tor
public void actionPerformed(ActionEvent ae) {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(m_GraphPanel);
if (printJob.printDialog())
try {
m_bIsPrinting = true;
printJob.print();
m_bIsPrinting = false;
} catch(PrinterException pe) {
m_jStatusBar.setText("Error printing: " + pe);
m_bIsPrinting = false;
}
m_jStatusBar.setText("Print");
} // actionPerformed
public boolean isPrinting() {return m_bIsPrinting;}
} // class ActionPrint
class ActionQuit extends ActionSave {
/** for serialization */
private static final long serialVersionUID = -2038911085935515L;
public ActionQuit() {
super("Exit", "Exit Program", "exit", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
if (m_BayesNet.isChanged()) {
int result = JOptionPane.showConfirmDialog(null, "Network changed. Do you want to save it?", "Save before closing?", JOptionPane.YES_NO_CANCEL_OPTION);
if (result == JOptionPane.CANCEL_OPTION) {
return;
}
if (result == JOptionPane.YES_OPTION) {
if (!saveAs()) {
return;
}
}
}
System.exit(0);
}
} // class ActionQuit
class ActionHelp extends MyAction {
/** for serialization */
private static final long serialVersionUID = -20389110859354L;
public ActionHelp() {
super("Help", "Bayesian Network Workbench Help", "help", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
JOptionPane.showMessageDialog(null, "See Weka Homepage\nhttp://www.cs.waikato.ac.nz/ml", "Help Message",
JOptionPane.PLAIN_MESSAGE);
}
} // class ActionHelp
class ActionAbout extends MyAction {
/** for serialization */
private static final long serialVersionUID = -20389110859353L;
public ActionAbout() {
super("About", "Help about", "about", "");
} // c'tor
public void actionPerformed(ActionEvent ae) {
JOptionPane.showMessageDialog(null, "Bayesian Network Workbench\nPart of Weka\n2007", "About Message",
JOptionPane.PLAIN_MESSAGE);
}
} // class ActionAbout
class ActionZoomIn extends MyAction {
/** for serialization */
private static final long serialVersionUID = -2038911085935515L;
public ActionZoomIn() {
super("Zoom in", "Zoom in", "zoomin", "+");
} // c'tor
public void actionPerformed(ActionEvent ae) {
int i = 0, s = (int) (m_fScale * 100);
if (s < 300)
i = s / 25;
else if (s < 700)
i = 6 + s / 50;
else
i = 13 + s / 100;
if (s >= 999) {
setEnabled(false);
return;
} else if (s >= 10) {
if (i >= 22) {
setEnabled(false);
}
if (s == 10 && !a_zoomout.isEnabled()) {
a_zoomout.setEnabled(true);
}
m_jTfZoom.setText(m_nZoomPercents[i + 1] + "%");
m_fScale = m_nZoomPercents[i + 1] / 100D;
} else {
if (!a_zoomout.isEnabled())
a_zoomout.setEnabled(true);
m_jTfZoom.setText(m_nZoomPercents[0] + "%");
m_fScale = m_nZoomPercents[0] / 100D;
}
setAppropriateSize();
m_GraphPanel.repaint();
m_GraphPanel.invalidate();
m_jScrollPane.revalidate();
m_jStatusBar.setText("Zooming in");
}
} // class ActionZoomIn
class ActionZoomOut extends MyAction {
/** for serialization */
private static final long serialVersionUID = -203891108593551L;
public ActionZoomOut() {
super("Zoom out", "Zoom out", "zoomout", "-");
} // c'tor
public void actionPerformed(ActionEvent ae) {
int i = 0, s = (int) (m_fScale * 100);
if (s < 300)
i = (int) Math.ceil(s / 25D);
else if (s < 700)
i = 6 + (int) Math.ceil(s / 50D);
else
i = 13 + (int) Math.ceil(s / 100D);
if (s <= 10) {
setEnabled(false);
} else if (s < 999) {
if (i <= 1) {
setEnabled(false);
}
m_jTfZoom.setText(m_nZoomPercents[i - 1] + "%");
m_fScale = m_nZoomPercents[i - 1] / 100D;
} else {
if (!a_zoomin.isEnabled())
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?