📄 mainmenu.java
字号:
digraph.paramFile = loadChooser.getSelectedFile();
// read the parameters to file
//
digraph.read();
}
} else if(source.equals(saveStr)) {
// write the parameters to file
//
if (digraph.paramFile != null) {
digraph.write();
}
else {
// initialize the file chooser object
//
String cwd = System.getProperty("user.dir");
JFileChooser saveChooser = new JFileChooser(cwd);
// set the font and button text for the save chooser
//
saveChooser.setFont(newFont);
String saveApprove = new String("Save");
saveChooser.setApproveButtonText(saveApprove);
// display the file chooser object
//
int returnVal = saveChooser.showOpenDialog(digraph);
// check to see if a file was selected by the user
//
if (returnVal == JFileChooser.APPROVE_OPTION) {
// retrieve the selected file
//
digraph.paramFile = saveChooser.getSelectedFile();
// write the parameters to file
//
digraph.write();
}
}
} else if(source.equals(saveAsStr)) {
JFileChooser saveChooser = null;
// initialize the file chooser object
//
if(digraph.paramFile != null) {
saveChooser = new JFileChooser(digraph.paramFile);
}
else {
String cwd = System.getProperty("user.dir");
saveChooser = new JFileChooser(cwd);
}
// set the font and button text for the save chooser
//
saveChooser.setFont(newFont);
String saveApprove = new String("Save");
saveChooser.setApproveButtonText(saveApprove);
// display the file chooser object
//
int returnVal = saveChooser.showOpenDialog(digraph);
// check to see if a file was selected by the user
//
if (returnVal == JFileChooser.APPROVE_OPTION) {
// retrieve the selected file
//
digraph.paramFile = saveChooser.getSelectedFile();
// write the parameters to file
//
digraph.write();
}
} else if(source.equals(in_Config_Str)) {
// create and display the configuration panel
//
ConfigBoxIn systemInConfig = new ConfigBoxIn(digraph, digraph.data, digraph.inVertex, digraph.workArea, 0);
systemInConfig.pack();
systemInConfig.setVisible(true);
} else if(source.equals(clearStr)) {
// reset the param file name
//
digraph.paramFile = null;
// clear out all existing memory
//
digraph.clearAllMemory();
// refresh the work area
//
digraph.workArea.repaint();
} else if(source.equals(quitStr)) {
// exit without saving if nothing has changed
//
if (!digraph.saveWork) {
System.exit(0);
}
// popup a dialogue that prompts the user to save his/her changes
//
JFrame frame = new JFrame("Warning");
int ans = JOptionPane.showConfirmDialog(frame, "Would you like to save your current changes?", "Warning", JOptionPane.YES_NO_CANCEL_OPTION);
// get the users choice
//
if (ans == JOptionPane.YES_OPTION) {
// initialize the file chooser object
//
JFileChooser saveChooser = new JFileChooser();
// set the font and button text for the save chooser
//
saveChooser.setFont(newFont);
String saveApprove = new String("Save");
saveChooser.setApproveButtonText(saveApprove);
// display the file chooser object
//
int returnVal = saveChooser.showOpenDialog(digraph);
// check to see if a file was selected by the user
//
if (returnVal == JFileChooser.APPROVE_OPTION) {
// retrieve the selected file
//
digraph.paramFile = saveChooser.getSelectedFile();
// write the parameters to file
//
digraph.write();
}
// close the application
//
System.exit(0);
}
else if (ans == JOptionPane.NO_OPTION) {
// close the application
//
System.exit(0);
}
else {
return;
}
} else if (source.equals(updateStr)) {
// check to see if a vertex with this label exists
//
if (digraph.coeffLabels.contains(nameField.getText())) {
// display a warning message indicating that you cannot have
// two vertices with the same name
//
JFrame frame = new JFrame("Warning");
JOptionPane.showMessageDialog(frame, "A node with the label "
+ nameField.getText() +
" already exists");
return;
}
// remove the old label from the vector
//
digraph.coeffLabels.remove(digraph.currVertexFocus.getText());
digraph.coeffLabels.addElement(nameField.getText());
// update the vertex text with what the user entered
//
digraph.currVertexFocus.setText(nameField.getText());
// remove the frame from the screen
//
config.setVisible(false);
} else if (source.equals(cancelStr)) {
// remove the frame from the screen
//
config.setVisible(false);
} else if(source.equals(overviewStr)) {
// create a dismiss button for the text area
//
JButton dismiss = new JButton(dismissStr);
dismiss.setActionCommand(dismissStr);
dismiss.addActionListener(this);
// read the help file contents and append them to the text area
//
try {
// clear the text area
//
textArea.setText("");
// create a file object for I/O
//
File helpFile = new File(OVERVIEW_FILE);
// create a file reader object
//
FileReader fileReader = new FileReader(helpFile);
// initialize the buffer to read the contents of the help file
//
BufferedReader buff = new BufferedReader(fileReader);
// read each line fo the file
//
String document;
while((document = buff.readLine()) != null) {
// add the help message line to the text area
//
textArea.append(document+newline);
}
}
catch(IOException ioe) { }
// add the components to the frame
//
helpFrame.getContentPane().add(scrollPane, BorderLayout.CENTER);
helpFrame.getContentPane().add(dismiss, BorderLayout.SOUTH);
// display the text area and dismiss button
//
helpFrame.pack();
helpFrame.setVisible(true);
} else if(source.equals(tutorialStr)) {
// create a dismiss button for the text area
//
JButton dismiss = new JButton(dismissStr);
dismiss.setActionCommand(dismissStr);
dismiss.addActionListener(this);
// read the help file contents and append them to the text area
//
try {
// clear the text area
//
textArea.setText("");
// create a file object for I/O
//
File helpFile = new File(TUTORIAL_FILE);
// create a file reader object
//
FileReader fileReader = new FileReader(helpFile);
// initialize the buffer to read the contents of the help file
//
BufferedReader buff = new BufferedReader(fileReader);
// read each line fo the file
//
String document;
while((document = buff.readLine()) != null) {
// add the help message line to the text area
//
textArea.append(document+newline);
}
}
catch(IOException ioe) { }
// add the components to the frame
//
helpFrame.getContentPane().add(scrollPane, BorderLayout.CENTER);
helpFrame.getContentPane().add(dismiss, BorderLayout.SOUTH);
// display the text area and dismiss button
//
helpFrame.pack();
helpFrame.setVisible(true);
} else if(source.equals(dismissStr)) {
// remove the frame form the screen
//
helpFrame.setVisible(false);
} else if(source.equals(delBlkStr)) {
digraph.enableCompDeletion = true;
/*
// remove all children and parent edges
//
if (digraph.currVertexFocus != null) {
if (digraph.currVertexFocus.getClass().getName().equals("Vertex")) {
digraph.removeVertex(digraph.currVertexFocus);
}
}
*/
} else if(source.equals(cutStr)) {
digraph.cut();
} else if(source.equals(copyStr)) {
digraph.copy();
} else if(source.equals(pasteStr)) {
digraph.paste();
} else if(source.equals(contStr)) {
if (digraph.vertices.size() > 0) {
digraph.createIOData(CONTAINER, NONE);
}
} else if(source.equals(insArcStr)) {
digraph.enableArcInsertion = true;
} else if(source.equals(delArcStr)) {
digraph.enableArcDeletion = true;
} else if(source.equals(tutorialStr)) {
// not yet implemented
} else {
digraph.createAlgorithm(e.getActionCommand());
}
}
// method: constrain
//
// argument:
// Container container: (input) container to place the component
// Component component: (input) the component to be constrained
// int grid_x: (input) horizontal position of component
// int grid_y: (input) vertical position of component
// int grid_width: (input) number of horizontal grid spots to take
// int grid_height: (input) number of vertical grid spots to take
// int fill: (input) directions to fill when component space is resized
// int anchor: (input) anchor position when component space is resized
// double weight_x: (input)relative amount of horizontal space
// component should take when its space is resized
// double weight_y: (input) relative amount of vertical space component
// should take when its space is resized
// int top: (input) amount of inset space on top
// int left: (input) amount of inset space on left
// int bottom: (input) amount of inset space on bottom
// int right: (input) amount of inset space on right
//
// returns: boolean flag indicating status
//
// this method creates the constraints of a component in a container
// and then adds the component to the container. it is based on
// code from "Java in a Nutshell" by David Flanagan. published by
// O'Reilly and Associates incorporated.
//
public boolean constrain(Container container, Component component,
int grid_x, int grid_y, int grid_width,
int grid_height, int fill, int anchor,
double weight_x, double weight_y, int top,
int left, int bottom, int right) {
// set the constraints based on the input variables
//
GridBagConstraints c = new GridBagConstraints();
c.gridx = grid_x;
c.gridy = grid_y;
c.gridwidth = grid_width;
c.gridheight = grid_height;
c.fill = fill;
c.anchor = anchor;
c.weightx = weight_x;
c.weighty = weight_y;
// if any of the buffer insets are greater than zero, create a new
// Insets object
//
if (top + bottom + left + right > 0)
c.insets = new Insets(top, left, bottom, right);
// set the constraints of the component
//
((GridBagLayout) container.getLayout()).setConstraints(component, c);
// add the component to the container
//
container.add(component);
// exit gracefully
//
return true;
}
}
//
// end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -