コード例 #1
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand().equals(mapEditor.getActionCommand())) {
     new MapEditor(getBoardWidget().getBoard());
     dispose();
   }
 }
コード例 #2
0
  /** When a new set of saved statements come in, refresh the menu of saved statements. */
  private void refreshSaveMenu() {
    ArrayList list;
    // first, delete what's already there
    for (; ; ) {
      Component comp = popup.getComponent(1);
      if (!(comp instanceof JMenuItem)) break;

      JMenuItem item = (JMenuItem) comp;
      if (item.getActionCommand().startsWith("save:")) popup.remove(1);
      else break;
    }
    StatementHistory history;
    history = sshare.statementHistory();
    // now insert the new list of saved statements
    list = history.getNamedStatementList();
    Color bgColor = Util.getBgColor();
    for (int i = 0; i < list.size(); i++) {
      ArrayList nameNlabel = (ArrayList) list.get(i);
      JMenuItem item = new JMenuItem("  " + (String) nameNlabel.get(1));
      item.setActionCommand("save:" + (String) nameNlabel.get(0));
      popup.add(item, 1);
      //	    item.setBackground(bgColor);
      item.addActionListener(popActionListener);
    }
  } // refreshSaveMenu()
コード例 #3
0
  /**
   * Receives events and calls methods depending on the event
   *
   * @param ActionEvent
   */
  @Override
  public void actionPerformed(ActionEvent e) {
    JMenuItem source = (JMenuItem) (e.getSource());

    if (source.getActionCommand().equals("import")) {
      int returnVal = fc.showOpenDialog(null);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        setChanged();
        notifyObservers(file);
        GUI.printToStatus("Opened file: " + file.toString());
        System.out.println("should've been notified");
        // This is where a real application would open the file.
        // log.append("Opening: " + file.getName() + "." + newline);
      } else {
        System.out.println("No file selected");
      }
    } else if (source.getActionCommand().equals("exit")) {
      // TODO prompt user to save work?
      System.exit(0);

    } else if (source.getActionCommand().equals("axesVis")) {
      JCheckBoxMenuItem checkBox = (JCheckBoxMenuItem) source;
      setChanged();
      notifyObservers(checkBox);
    } else if (source.getActionCommand().equals("gridVis")) {
      JCheckBoxMenuItem checkBox = (JCheckBoxMenuItem) source;
      setChanged();
      notifyObservers(checkBox);
    } else if (source.getActionCommand().equals("setComPort")) {
      JMenuItem checkBox = (JMenuItem) source;
      setChanged();
      notifyObservers(checkBox);
    } else if (source.getActionCommand().equals("doCalib")) {
      JMenuItem calibButton = (JMenuItem) source;
      setChanged();
      notifyObservers(calibButton);
    } else if (source.getActionCommand().equals("about")) {
      JOptionPane.showMessageDialog(
          null,
          "Bachelors Work @ Chalmers University Of Technology spring semester 2012\nAuthors: \nJohan Sandstrom\nDaniel Nicklasson\nChristian Fransson\nSimon Ivarsson");
    }
  }
コード例 #4
0
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    if (calculator != null && source == calculator.getOKButton()) {
      calculatorDialog.setVisible(false);
      setValue(new Money(calculator.convertOutput(), moneyField.getValue().getCurrency()));
    } else if (source == copyItem) {
      Clipboard clipboard = getToolkit().getSystemClipboard();
      Money value = getValue();

      if (value == null) {
        getToolkit().beep();
        return;
      }

      StringSelection contents = new StringSelection(value.toString());
      clipboard.setContents(contents, defaultClipboardOwner);
    } else if (source == pasteItem) {
      Clipboard clipboard = getToolkit().getSystemClipboard();
      Transferable content = clipboard.getContents(this);

      if (content == null) {
        setValue(null);
        getToolkit().beep();
        return;
      }

      try {
        String moneyData = (String) (content.getTransferData(DataFlavor.stringFlavor));
        int index = moneyData.indexOf(' ');

        if (index <= 0) {
          getToolkit().beep();
          return;
        }

        String value = moneyData.substring(0, index);
        String currencyAbbreviation = moneyData.substring(index + 1);

        value = value.replace(',', '.');
        Money money = new Money(value, Money.getCurrencyValueFor(currencyAbbreviation));
        setValue(money);
      } catch (Exception ex) {
        getToolkit().beep();
      }
    } else if (source == calculatorItem) {
      Dimension size = this.moneyField.getSize();

      runCalculatorDialog(
          new MouseEvent(
              this,
              0, // id
              System.currentTimeMillis(), // when
              0, // modifiers
              size.width, // x
              size.height, // y
              1, // clickCount
              true // popuptrigger
              ));
    } else if (source instanceof JMenuItem) {
      JMenuItem menuItem = (JMenuItem) source;

      // Perform 'changed currency' - action

      String actionText = menuItem.getActionCommand();

      // Cut off additional information from actionCommand

      int currencyDelimPos = actionText.indexOf(" ");

      if (currencyDelimPos > 0) {
        actionText = actionText.substring(0, currencyDelimPos);
      }

      // lastCurrencyItem will show any currency except the default ones

      boolean isNotDefault = true;

      for (int i = 0; i < defaultCurrencies.length; i++) {
        if (defaultCurrencies[i].equals(actionText)) {
          isNotDefault = false;
          break;
        }
      }

      // @todo ... check if lastCurrencyItem is needed or not [aj] seems to be old stuff
      if (isNotDefault && lastCurrencyItem != null) {
        lastCurrencyItem.setText(actionText);
      }

      // Change the currency

      changeCurrency(actionText, false);
    } else if ("popup".equals(e.getActionCommand())) // key: SHIFT+F10 <=> popup
    {
      Point point = getLocation();
      moneyPopup.doPopup(0, getHeight());
    }
  }