public void actionPerformed(ActionEvent ae) {
   String cmd = ae.getActionCommand();
   if (JOkCancelPanel.OK.equals(cmd)) {
     // update evaluator
     evaluator.name = tfName.getText();
     evaluator.type = (byte) cbType.getSelectedIndex();
     evaluator.ignoreDiagonals = cbDiagonals.isSelected();
     evaluator.investments = (byte) cbInvestment.getSelectedIndex();
     evaluator.orgFile = orgFile;
     setVisible(false);
   } else if (JOkCancelPanel.CANCEL.equals(cmd)) {
     // don't update evaluator
     setVisible(false);
   } else if (CMD_CHOOSE_FILE.equals(cmd)) {
     // get a file dialog
     JFrame f = new JFrame();
     JFileChooser jfc = Application.getFileChooser();
     int res = jfc.showOpenDialog(f);
     Application.setWorkingDirectory(jfc.getCurrentDirectory());
     if (res == JFileChooser.CANCEL_OPTION) {
       return;
     }
     orgFile = jfc.getSelectedFile();
     lOrgFileName.setText("File: " + orgFile.getName());
   }
 }
示例#2
0
文件: Main.java 项目: orez-/520proj
  public static void main(String args[]) {
    try {
      System.out.println("Type in a tiny exp folowed by one or two Ctrl-d's:");
      Parser p = new Parser(new Lexer(new PushbackReader(new InputStreamReader(System.in), 1024)));

      Start tree = p.parse();
      NewEval.replaceUminus(tree);
      /* pretty-print */
      System.out.println("\nThe result of evaluating:");
      PrettyPrinter.print(tree);

      /* pre-eval to replace uminus */

      /* evaluate */
      System.out.print("\nis: ");
      PrettyPrinter.print(Evaluator.eval(tree));
      System.out.println("\n");

    } catch (Exception e) {
      System.out.println(e);
    }
  }
    public Editor(JFrame parent, Evaluator evaluator) {
      super(parent, "Structure");
      setModal(true);
      this.evaluator = evaluator;

      getContentPane().setLayout(new BorderLayout());

      // name and type
      JPanel pNameType = new JPanel(new GridLayout(2, 1));
      JPanel pName = new JPanel(new BorderLayout());
      pName.add(new JLabel("Name: "), BorderLayout.WEST);
      tfName = new JTextField(evaluator.getName());
      pName.add(tfName, BorderLayout.CENTER);
      pNameType.add(pName);
      JPanel pType = new JPanel(new BorderLayout());
      pType.add(new JLabel("Type: "), BorderLayout.WEST);
      cbType = new JComboBox(types);
      cbType.setEditable(false);
      cbType.setSelectedIndex(evaluator.type);
      cbType.addItemListener(this);
      pType.add(cbType, BorderLayout.CENTER);
      pNameType.add(pType);
      getContentPane().add(pNameType, BorderLayout.NORTH);

      // options panel
      this.clOptions = new CardLayout();
      this.pOptions = new JPanel(clOptions);

      JPanel pConstraintRoot = new JPanel(new BorderLayout());
      Box pConstraintOpts = new Box(BoxLayout.Y_AXIS);
      JPanel pDiagonals = new JPanel(new BorderLayout());
      cbDiagonals = new JCheckBox("Ignore Diagonals", evaluator.ignoreDiagonals);
      pDiagonals.add(cbDiagonals, BorderLayout.CENTER);
      pConstraintOpts.add(pDiagonals);
      JPanel pInvestment = new JPanel(new BorderLayout());
      pInvestment.add(new Label("Investments "), BorderLayout.WEST);
      cbInvestment = new JComboBox(investments);
      cbInvestment.setEditable(false);
      cbInvestment.setSelectedIndex(evaluator.investments);
      pInvestment.add(cbInvestment, BorderLayout.CENTER);
      pConstraintOpts.add(pInvestment);
      JPanel pOrganization = new JPanel(new GridLayout(2, 1));
      lOrgFileName = new JLabel("File: <none selected>");
      pOrganization.add(lOrgFileName);
      JPanel pFileChoose = new JPanel(new FlowLayout(FlowLayout.CENTER));
      JButton bFileChoose = new JButton("Choose File...");
      bFileChoose.addActionListener(this);
      bFileChoose.setActionCommand(CMD_CHOOSE_FILE);
      pFileChoose.add(bFileChoose);
      pOrganization.add(pFileChoose);
      pConstraintOpts.add(pOrganization);
      pConstraintRoot.add(pConstraintOpts, BorderLayout.NORTH);
      pOptions.add(pConstraintRoot, types[CONSTRAINT]);

      JPanel pSizeRoot = new JPanel(new BorderLayout());
      pOptions.add(pSizeRoot, types[EFFECTIVE_SIZE]);
      clOptions.first(pOptions);

      getContentPane().add(BorderLayout.CENTER, pOptions);

      // ok/cancel panel
      JOkCancelPanel okCancelPanel = new JOkCancelPanel();
      okCancelPanel.addActionListener(this);
      getContentPane().add(BorderLayout.SOUTH, okCancelPanel);

      pack();
    }