Esempio n. 1
0
  public void actionPerformed(ActionEvent event) {
    JMenuItem source = (JMenuItem) (event.getSource());

    for (GraphView v : gp.getGraphViewList()) {
      if (v.getMenuText().equals(source.getText())) {
        v.view();
        repaint();
        return;
      }
    }

    for (GraphDrawer d : gp.getGraphDrawerList()) {
      if (d.getMenuText().equals(source.getText())) {
        d.layout();
        repaint();
        return;
      }
    }

    for (GraphUtility u : gp.getGraphUtilityList()) {
      if (u.getMenuText().equals(source.getText())) {
        u.apply();
        repaint();
        return;
      }
    }

    for (GraphExperiment ge : gp.getGraphExperimentList()) {
      if (ge.getMenuText().equals(source.getText())) {
        ge.experiment();
        repaint();
        return;
      }
    }
  }
Esempio n. 2
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() instanceof JMenuItem) {
     JMenuItem item = (JMenuItem) e.getSource();
     String name = item.getText();
     profiles.delete(name);
   }
 }
Esempio n. 3
0
  public void actionPerformed(ActionEvent e) {
    String cmd = (e.getActionCommand());

    if (cmd.equals(aboutItem.getText()))
      JOptionPane.showMessageDialog(
          this,
          "Simple Image Program for DB2004\nversion 0.1\nThanks to BvS",
          "About imageLab",
          JOptionPane.INFORMATION_MESSAGE);
    else if (cmd.equals(quitItem.getText())) System.exit(0);
    else if (cmd.equals(openItem.getText())) {
      int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2 = new Picture(chooser.getSelectedFile().getName());
          pic1 = new Picture(pic2.width(), pic2.height());
          lab.setIcon(pic2.getJLabel().getIcon());
          sliderPanel.setVisible(false);
          pack();
          repaint();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not open " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Open Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }

    } else if (cmd.equals(saveItem.getText())) {
      int returnVal = chooser.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
          pic2.save(chooser.getSelectedFile().getName());
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this,
              "Could not write " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(),
              "Save Error",
              JOptionPane.INFORMATION_MESSAGE);
        }
      }
    }
  }
Esempio n. 4
0
    public void actionPerformed(ActionEvent event) {

      JMenuItem mi;
      String label = "";

      if (warningPopup == null) {
        warningPopup = new WarningDialog(textViewerFrame);
      }
      if ((editor1 == null) || (editor1.getDocument() == null)) {
        String errstr = "TextViewer:editor1 or document is null";
        warningPopup.display(errstr);
        return;
      }
      String actionStr = event.getActionCommand(); // is not makeing anysense
      // when keystrokes typed
      if ((event.getSource() instanceof JMenuItem)) {
        mi = (JMenuItem) event.getSource();
        label = mi.getText();
      } else if ((event.getSource() instanceof JTextArea)) { // keystroke
        label = "FindAgain"; // just set it to findagain
      } else {
        System.err.println("Debug:TextViewer:" + actionStr);
        System.err.println("Debug:TextViewer:" + event.getSource().toString());
        String errstr =
            "TextViewer:FindAction: "
                + event.getSource().toString()
                + " not an instance of JMenuItem or JTextArea";
        warningPopup.display(errstr);
        return;
      }

      if (label.equals("FindAgain")) {
        isFindAgain = true;
        lastFindStr = lastFindStr;
      } else {
        isFindAgain = false;
        lastFindStr = "";
      }
      StringBoolean content = new StringBoolean(lastFindStr, forwardFindDirection);

      boolean okPressed = mySearchDialog.display(content);
      if (!okPressed) {
        return;
      }
      lastFindStr = content.mystring;
      forwardFindDirection = content.myboolean;

      if (forwardFindDirection) {
        lastFindIndex = searchForward(lastFindStr);
        //		System.out.println("Debug:TextViewer: lastFindIndex:"+lastFindIndex);

      } else {
        lastFindIndex = searchBackward(lastFindStr);
        //		System.out.println("Debug:TextViewer: lastFindIndex:"+lastFindIndex);
      }
    }
Esempio n. 5
0
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();
    if (o instanceof JMenuItem) {
      JMenuItem sender = (JMenuItem) o;
      String name = sender.getText();
      if (name.equals("close")) {
        tabbedPane.removeTabAt(tabbedPane.getSelectedIndex());
      } else if (name.equals("save")) {
        int index = tabbedPane.getSelectedIndex();
        Component c = tabbedPane.getComponent(index);
        Point p = c.getLocation();
        Component t = tabbedPane.getComponentAt(new Point(p.x + 20, p.y + 30));
        if (t instanceof TextView) {
          TextView text = (TextView) t;
          // String code = text.getText();
          // save the code
          // saveTab(code);
        }
        if (t instanceof HTMLTextView) {
          HTMLTextView text = (HTMLTextView) t;
          fileChooser.setSelectedFile(new File(text.node.getName()));
          int returnVal = fileChooser.showSaveDialog(this);

          if (returnVal == JFileChooser.APPROVE_OPTION) {
            File f = fileChooser.getSelectedFile();

            // save the code
            String fileType =
                f.getName().substring(f.getName().lastIndexOf("."), f.getName().length());
            if (fileType.indexOf("htm") != -1) {
              // save as html
              String code = text.getText();
              saveTab(code, f);
            } else if (fileType.indexOf("java") != -1) {
              // save as java
              String code = text.getUnModyfiedContent();
              saveTab(code, f);
            } else if (text.node.fileType.indexOf(FileTypes.MANIFEST) != -1
                || text.node.fileType.indexOf(FileTypes.MANIFEST2) != -1) {
              String code = text.getUnModyfiedContent();
              saveTab(code, f);
              System.out.println("Saved manifest");
            } else {
              System.out.println("FILETYPE UNKNOWN:" + text.node.fileType);
            }
          }
        }
      } else if (name.equals("close all")) {
        tabbedPane.removeAll();
      }
    }
  }
Esempio n. 6
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() instanceof JMenuItem) {
     JMenuItem item = (JMenuItem) e.getSource();
     String name = item.getText();
     Profile profile = profiles.getProfile(name);
     Component[] components = selectorPanel.getComponents();
     for (int i = 0; i < components.length; i++) {
       Component comp = components[i];
       if (comp instanceof CPCheckBox) {
         CPCheckBox scb = (CPCheckBox) comp;
         String id = scb.element.id;
         boolean enb = profile.has(id);
         scb.setState(enb);
       }
     }
   }
 }
 public void actionPerformed(ActionEvent e) {
   JMenuItem source = (JMenuItem) (e.getSource());
   String text = source.getText();
   if (text.equals("Exit")) {
     System.exit(0);
   } else if (text.equals("Read Particle Location Data")) {
     File particleFile = null;
     if ((particleFile = getFileName(UintahGui.OPEN)) != null) {
       d_partList.readFromFile(particleFile);
     }
   } else if (text.equals("Save Uintah Input File")) {
     File uintahFile = null;
     if ((uintahFile = getFileName(UintahGui.SAVE)) != null) {
       writeUintah(uintahFile);
     }
   } else if (text.equals("About")) {
     helpAboutFrame.setVisible(true);
   }
 }
Esempio n. 8
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() instanceof JMenuItem) {
     JMenuItem item = (JMenuItem) e.getSource();
     String name = item.getText();
     if (name.equals("New...")) {
       name = JOptionPane.showInputDialog(selectorPanel, "Enter a name for the new profile.");
     }
     if ((name == null) || name.trim().equals("")) return;
     Profile profile = new Profile(name);
     Component[] components = selectorPanel.getComponents();
     for (int i = 0; i < components.length; i++) {
       Component comp = components[i];
       if (comp instanceof CPCheckBox) {
         CPCheckBox scb = (CPCheckBox) comp;
         String id = scb.element.id;
         if (scb.isSelected()) profile.add(id);
       }
     }
     profiles.add(profile);
   }
 }
Esempio n. 9
0
  /*
   * Controls what happens when an action is detected (a menu item is
   * selected).
   */
  public void actionPerformed(ActionEvent e) {

    /* The file to load from or save to. */
    File file;

    /* Cast the source of the ActionEvent into a menu item for selection. */
    JMenuItem source = (JMenuItem) (e.getSource());

    /* Detect which menu item was clicked. */
    if (source.getText().equals("Basic game")) {

      /* Upon selecting a new basic game, create a new basic game. */
      this.currentgame.newGame("Basic", 5);

    } else if (source.getText().equals("Easy feeding game")) {

      /*
       * Upon selecting an easy feeding game, create a new easy feeding
       * game.
       */
      this.currentgame.newGame("Feeding", 3);

    } else if (source.getText().equals("Moderate feeding game")) {

      /*
       * Upon selecting a moderate feeding game, create a new moderate
       * feeding game.
       */
      this.currentgame.newGame("Feeding", 4);

    } else if (source.getText().equals("Hard feeding game")) {

      /*
       * Upon selecting a hard feeding game, create a new hard feeding
       * game.
       */
      currentgame.newGame("Feeding", 10);

    } else if (source.getText().equals("Load...")) {

      /* Pause the game. */
      this.currentgame.stopFeedingRow();
      this.currentgame.pauseTimeLimit();
      this.currentgame.stopTimeLimit();

      /*
       * Present the user with a file chooser dialog to select the file
       * to load.
       */
      file = getInputFile("Choose game to load");

      if (file != null) {

        /* If the user chose a file, load it. */
        this.currentgame.loadGame(file);

      } else {

        /* If a user cancelled loading resume play. */
        this.currentgame.startFeedingRow();
        this.currentgame.resumeTimeLimit();
        this.currentgame.startTimeLimit();
      }

    } else if (source.getText().equals("Save...")) {

      /* If the game is still going on... */
      if (!this.currentgame.isGameOver()) {

        /* Pause the game. */
        this.currentgame.stopFeedingRow();
        this.currentgame.stopTimeLimit();
        this.currentgame.pauseTimeLimit();

        /*
         * Present the user with a file chooser dialog to choose where
         * they want to save to.
         */
        file = getOutputFile("Choose where to save");

        if (file != null) {

          /* If a file is selected, save to it. */
          this.currentgame.saveGame(file);
        }

        /* Resume play. */
        this.currentgame.startFeedingRow();
        this.currentgame.resumeTimeLimit();
        this.currentgame.startTimeLimit();

      } else {

        /*
         * Emit a system beep to alert the user that the game cannot
         * be saved at this time.
         */
        Toolkit.getDefaultToolkit().beep();
      }

    } else if (source.getText().equals("Quit")) {

      /* Quit the game. */
      System.exit(0);
    }
  }