示例#1
0
 public void actionPerformed(ActionEvent ev) {
   if (ev.getSource() == newg) {
     dialog.hide();
     resetBoard();
   }
   if (ev.getSource() == quitg) System.exit(0);
 }
示例#2
0
 /**
  * Handle ui actions.
  *
  * @param event The action event
  */
 public void actionPerformed(ActionEvent event) {
   String action = event.getActionCommand();
   if (action.equals(GuiUtils.CMD_SAVE)) {
     doSave();
   } else if (action.equals(GuiUtils.CMD_SAVEAS)) {
     doSaveAs();
   } else if (action.equals(GuiUtils.CMD_RENAME)) {
     doRename();
   } else if (action.equals(GuiUtils.CMD_NEW)) {
     doNew();
   } else if (action.equals(GuiUtils.CMD_IMPORT)) {
     doImport();
   } else if (action.equals(GuiUtils.CMD_EXPORT)) {
     doExport();
   } else if (action.equals(GuiUtils.CMD_REMOVE)) {
     doRemove();
   } else if (action.equals(GuiUtils.CMD_CLOSE)) {
     doClose();
   } else if (action.equals(CMD_BLACKBG)) {
     setCanvasBackground(Color.BLACK);
   } else if (action.equals(CMD_WHITEBG)) {
     setCanvasBackground(Color.WHITE);
   } else {
     super.actionPerformed(event);
   }
 }
示例#3
0
 /** handle button events. */
 public void actionPerformed(ActionEvent e) {
   String cmd = e.getActionCommand();
   if (cmd.equals("run")) {
     if (animator.isAnimating()) stop();
     else start();
   } else if (cmd.equals("transparancy")) {
     if (drawable != null) drawable.setOpaque(!checkBox.isSelected());
   }
 }
示例#4
0
 public void actionPerformed(ActionEvent e) {
   // Invoked when an action occurs.
   if (e.getSource().equals(singleSizeUp)) {
     singleSize = singleSize * 2;
     singleSizeLabel.setText("Image height=" + singleSize);
   }
   if (e.getSource().equals(singleSizeDown)) {
     singleSize = Math.max(64, singleSize / 2);
     singleSizeLabel.setText("Image height=" + singleSize);
   }
   if (e.getSource().equals(seqSizeUp)) {
     seqSize = seqSize * 2;
     seqSizeLabel.setText("Image height=" + seqSize);
   }
   if (e.getSource().equals(seqSizeDown)) {
     seqSize = Math.max(64, seqSize / 2);
     seqSizeLabel.setText("Image height=" + seqSize);
   }
 }
示例#5
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == linkMenu
       || e.getSource() == edgeLinkMenu
       || e.getSource() == linkMissingMenu) {
     try {
       argument.linkVertices();
     } catch (LinkException ex) {
       displayFrame.controlFrame.setMessageLabelText(ex.getMessage());
     }
   } else if (e.getSource() == unlinkMenu
       || e.getSource() == edgeUnlinkMenu
       || e.getSource() == unlinkMissingMenu) {
     try {
       argument.unlinkVertices();
     } catch (LinkException ex) {
       displayFrame.controlFrame.setMessageLabelText(ex.getMessage());
     }
   }
   displayFrame.controlFrame.updateDisplays(true);
 }
示例#6
0
  public void actionPerformed(ActionEvent evt) {

    if (evt.getSource() == timer) {

      player.physics();

      k = 1;
      while (k <= ballCount) {

        ball[k].physics(player.x, player.y, player.size);
        if (ball[k].r < centery - 500 + ball[k].size / 2) {
          health = health - (int) ball[k].size;
          ball[k].r = centery;
          ball[k].t = -Math.PI / 2;
        }
        k++;

        if (grav) {

          k = 1;
          while (k <= ballCount) {
            ball[k].grav();
            k++;
          }

        } else {

          k = 1;
          while (k <= ballCount) {
            ball[k].antiGrav();
            k++;
          }
        }

        k = 1;
        while (k <= ballCount) {

          ball[k].physicsXY();
          k++;
        }

        healthStr = Integer.toString(health) + "%";
        label.setText("Planet Health: " + healthStr);

        repaint();
      }
    }
  }
示例#7
0
  public void actionPerformed(ActionEvent e) {
    final String command = e.getActionCommand();

    if (OPEN_CSV_FILE.equals(command)) {
      final JFileChooser chooser = new JFileChooser(System.getProperty("user.home"));
      final FileFilter filter = new CVSFileFilter();
      chooser.setFileFilter(filter);
      final int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        // setCvsFile(chooser.getSelectedFile().getPath());
      }

    } else if (EXIT.equals(command)) {
      windowClosingEvent(null);
    }

    if (EXIT.equals(command)) windowClosingEvent(null);
  }
示例#8
0
 public void actionPerformed(ActionEvent ev) {
   if (ev.getSource() == quitgame) System.exit(0);
   if (ev.getSource() == newgame) resetBoard();
 }
 /** @param e It is the type of action event the user pursues. */
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == apply) apply();
   else if (e.getSource() == close) close();
 }
示例#10
0
  public void actionPerformed(ActionEvent e) {
    String s = e.getActionCommand();

    diag.jpm = null;

    if (s.equals("Edit Upstream Port Name")) {

      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Edit upstream port name",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  upStreamPort);

      if (ans != null /* && ans.length() > 0 */) {
        Block b = diag.blocks.get(new Integer(fromId));
        // upStreamPort = ans;
        diag.changed = true;
        boolean found = false;
        for (Arrow a : diag.arrows.values()) {
          if (a.fromId == fromId
                  && a.upStreamPort != null
                  && a.upStreamPort.equals(ans)
                  && !(upStreamPort.equals(ans))
              || a.toId == fromId && a.downStreamPort != null && a.downStreamPort.equals(ans))
            found = true;
        }
        if (found) {
          MyOptionPane.showMessageDialog(driver.frame, "Duplicate port name: " + ans);
          // upStreamPort = "";
          // return;
        }
        upStreamPort = ans;

        if (b.type.equals(Block.Types.EXTPORT_IN_BLOCK) || b instanceof IIPBlock) {
          MyOptionPane.showMessageDialog(driver.frame, "Upstream port must be blank");
          upStreamPort = "";
        }
      }
      driver.frame.repaint();

    } else if (s.equals("Edit Downstream Port Name") && endsAtBlock) {
      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Edit downstream port name",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  downStreamPort);

      if (ans != null /* && ans.length() > 0 */) {

        Block b = diag.blocks.get(new Integer(toId));

        diag.changed = true;
        boolean found = false;
        for (Arrow a : diag.arrows.values()) {
          if (a.fromId == toId && a.upStreamPort != null && a.upStreamPort.equals(ans)
              || a.toId == toId
                  && a.downStreamPort != null
                  && a.downStreamPort.equals(ans)
                  && !(downStreamPort.equals(ans))) found = true;
        }
        if (found) {
          MyOptionPane.showMessageDialog(driver.frame, "Duplicate port name: " + ans);
          // downStreamPort = "";
          // return;
        }

        downStreamPort = ans;

        if (b.type.equals(Block.Types.EXTPORT_OUT_BLOCK)) {
          MyOptionPane.showMessageDialog(driver.frame, "Downstream port must be blank");
          downStreamPort = "";
        }
      }
      driver.frame.repaint();

    } else if (s.equals("Set Capacity")) {

      String capString = null;
      if (capacity == 0) capString = "";
      else capString = Integer.toString(capacity);
      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Set Capacity",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  capString);
      if ((ans != null) && (ans.length() > 0)) {
        capacity = Integer.parseInt(ans);
        if (capLegend == null) {
          diag.xa = 2; // get around fudge in DrawFBP
          diag.ya = 2; // get around fudge in DrawFBP
          capLegend = (LegendBlock) diag.driver.createBlock(Block.Types.LEGEND_BLOCK, false);

          int x = toX;
          int y = toY;
          if (bends != null) {
            Bend bd = bends.peek();
            x = bd.x;
            y = bd.y;
          }

          capLegend.cx = (fromX + x) / 2;
          capLegend.cy = (fromY + y) / 2 + 20;
          if (fromX == x) capLegend.cx -= 20;
        }
        capLegend.description = "(" + capacity + ")";
      }
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Remove Capacity")) {
      capacity = 0;
      diag.delBlock(capLegend, false);
      capLegend = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle Upstream Port Automatic / Normal")) {
      if (upStreamPort == null || !upStreamPort.equals("*")) upStreamPort = "*";
      else upStreamPort = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle Downstream Port Automatic / Normal")) {
      if (downStreamPort == null || !downStreamPort.equals("*")) downStreamPort = "*";
      else downStreamPort = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle DropOldest")) {
      dropOldest = !dropOldest;

    } else if (s.equals("Drag Tail")) {
      tailMarked = true;
      driver.arrowEndForDragging = this;

    } else if (s.equals("Drag Head")) {
      headMarked = true;
      driver.arrowEndForDragging = this;

    } else if (s.equals("Drag New or Existing Bend")) {
      createBend(driver.curx, driver.cury);

    } else if (s.equals("Add Extra Arrowhead")) {
      Point p = new Point(driver.curx, driver.cury);
      int fx = fromX;
      int fy = fromY;
      int tx, ty;
      if (bends != null) {
        for (Bend bend : bends) {
          tx = bend.x;
          ty = bend.y;
          if (pointInLine(p, fx, fy, tx, ty)) {
            extraArrowhead = new Arrowhead(fx, fy, driver.curx, driver.cury);
            return;
          }
          fx = tx;
          fy = ty;
        }
      }
      tx = toX;
      ty = toY;
      if (pointInLine(p, fx, fy, tx, ty))
        extraArrowhead = new Arrowhead(fx, fy, driver.curx, driver.cury);
      return;

    } else if (s.equals("Remove Extra Arrowhead")) {
      extraArrowhead = null;
      return;

    } else if (s.equals("Delete")) {

      if (JOptionPane.YES_OPTION
          == MyOptionPane.showConfirmDialog(
              driver.frame,
              "Do you want to delete this arrow?",
              "Delete arrow",
              JOptionPane.YES_NO_OPTION)) {
        diag.delArrow(this);

        diag.changed = true;
        diag.currentArrow = null;
      }

      driver.frame.repaint();
      diag.foundArrow = null;
    }
    // if (s.equals("Exit")) {
    //	diag.foundArrow = null;
    //	driver.frame.repaint();
    // }
  }
示例#11
0
 public void actionPerformed(ActionEvent e) {
   atc_obj.getInputhandler().processActionCommand(e.getActionCommand());
 }
示例#12
0
文件: LJ3MDApp.java 项目: eskilj/mvp
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    if (src == timer) {
      for (int i = 0; i < speed; i++) // integrate a few steps
      md.vv();
      repaint();
      return;
    }

    boolean adjCanvasScale = false;

    if (src == bTstat) md.thermostat = !md.thermostat;

    if (src == bPot) {
      md.ljPotential = !md.ljPotential;
      md.clearData();

      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    if (src == tTemp || src == bReset) {
      double kT = Double.parseDouble(tTemp.getText().trim());
      if (kT < 1e-8) {
        kT = 1e-8;
        tTemp.setText("  " + kT);
      }
      md.kT = kT;
      md.clearData();
    }

    if (src == tRho || src == bReset) {
      double rho = Double.parseDouble(tRho.getText().trim());
      if (rho < 1e-3) {
        rho = 1e-3;
        tRho.setText("   " + rho);
      }
      if (rho > 1.2) {
        rho = 1.2;
        tRho.setText("   " + rho);
      }
      md.setDensity(rho);
      md.clearData();
      adjCanvasScale = true;
    }

    if (src == tSpeed || src == bReset) {
      speed = Integer.parseInt(tSpeed.getText().trim());
      if (speed < 1) {
        speed = 1;
        tSpeed.setText("   " + speed);
      }
    }

    if (src == bRetime) md.clearData();

    if (src == bStart) {
      boolean on = bStart.isSelected();
      if (on) {
        timer.restart();
        bStart.setText("Pause");
      } else {
        timer.stop();
        bStart.setText("Resume");
      }
    }

    if (src == tNum) {
      int n = Integer.parseInt(tNum.getText().trim());
      if (n < 2) {
        n = 2;
        tNum.setText(" " + n);
      }
      md.N = n;
      md.init(md.rho);
      adjCanvasScale = true;
    }

    if (src == bReset) {
      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    canvas.refresh(md.getXWrap(), md.N, true, adjCanvasScale);

    repaint();
  }
示例#13
0
  public void actionPerformed(ActionEvent e) {
    System.out.println("actionPerformed");
    if (e.getSource() == pen) // 画笔
    {
      System.out.println("pen");
      toolFlag = 0;
    }

    if (e.getSource() == eraser) // 橡皮
    {
      System.out.println("eraser");
      toolFlag = 1;
    }

    if (e.getSource() == clear) // 清除
    {
      System.out.println("clear");
      toolFlag = 2;
      paintInfo.removeAllElements();
      repaint();
    }

    if (e.getSource() == drLine) // 画线
    {
      System.out.println("drLine");
      toolFlag = 3;
    }

    if (e.getSource() == drCircle) // 画圆
    {
      System.out.println("drCircle");
      toolFlag = 4;
    }

    if (e.getSource() == drRect) // 画矩形
    {
      System.out.println("drRect");
      toolFlag = 5;
    }

    if (e.getSource() == colchooser) // 调色板
    {
      System.out.println("colchooser");
      Color newColor = JColorChooser.showDialog(this, "我的调色板", c);
      c = newColor;
    }

    if (e.getSource() == openPic) // 打开图画
    {

      openPicture.setVisible(true);

      if (openPicture.getFile() != null) {
        int tempflag;
        tempflag = toolFlag;
        toolFlag = 2;
        repaint();

        try {
          paintInfo.removeAllElements();
          File filein = new File(openPicture.getDirectory(), openPicture.getFile());
          picIn = new FileInputStream(filein);
          VIn = new ObjectInputStream(picIn);
          paintInfo = (Vector) VIn.readObject();
          VIn.close();
          repaint();
          toolFlag = tempflag;

        } catch (ClassNotFoundException IOe2) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read object");
        } catch (IOException IOe) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read file");
        }
      }
    }

    if (e.getSource() == savePic) // 保存图画
    {
      savePicture.setVisible(true);
      try {
        File fileout = new File(savePicture.getDirectory(), savePicture.getFile());
        picOut = new FileOutputStream(fileout);
        VOut = new ObjectOutputStream(picOut);
        VOut.writeObject(paintInfo);
        VOut.close();
      } catch (IOException IOe) {
        System.out.println("can not write object");
      }
    }
  }
  public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if (b.getText() == "PLAY") {
      if (scoreP != null) scoreP.playScale(sp.getScale(), tempoP.getValue());
    } else if (b.getText() == "New") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      sp.notes.removeAllElements();
      sp.repaint();
      nameTF.setText("");
      loadedFile = null;
    } else if (b.getText() == "Save") {
      if (nameTF.getText().equals("")) {
        JOptionPane.showMessageDialog(
            this,
            new JLabel("Please type in the Scale Name"),
            "Warning",
            JOptionPane.WARNING_MESSAGE);
        return;
      }
      fileChooser.setFileFilter(filter);
      int option = fileChooser.showSaveDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        File target = fileChooser.getSelectedFile();
        if (target.getName().indexOf(".scl") == -1) target = new File(target.getPath() + ".scl");
        try {
          PrintStream stream = new PrintStream(new FileOutputStream(target), true);
          save(stream);
          stream.close();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    } else if (b.getText() == "Load") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      fileChooser.setFileFilter(filter);
      int option = fileChooser.showOpenDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        loadedFile = fileChooser.getSelectedFile();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        ScaleParser handler = new ScaleParser(false);
        try {
          SAXParser parser = factory.newSAXParser();
          parser.parse(loadedFile, handler);
          // System.out.println("success");
        } catch (Exception ex) {
          // System.out.println("no!!!!!! exception: "+e);
          // System.out.println(ex.getMessage());
          ex.printStackTrace();
        }
        // -----now :P:P---------------
        System.out.println("name: " + handler.getName());
        nameTF.setText(handler.getName());
        sp.notes.removeAllElements();
        int[] scale = handler.getScale();
        for (int i = 0; i < scale.length; i++) {
          sp.addNote(scale[i]);
        }
        sp.repaint();
      } else loadedFile = null;
    }
  }