コード例 #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;
      }
    }
  }
コード例 #2
0
  @Override
  public void actionPerformed(ActionEvent e) {
    JMenuItem item = (JMenuItem) e.getSource();

    if (item.getText().equals(DEFAULT_THEME)) {
      mainPanel.setBackground(Color.BLUE);
    } else if (item.getText().equals(CUSTOM_THEME)) {
      mainPanel.setBackground(Color.RED);
    }
  }
コード例 #3
0
ファイル: ControlPanel.java プロジェクト: johnperry/Geneva2
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() instanceof JMenuItem) {
     JMenuItem item = (JMenuItem) e.getSource();
     String name = item.getText();
     profiles.delete(name);
   }
 }
コード例 #4
0
ファイル: ImageLabFrame.java プロジェクト: per-ola/db2004
  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);
        }
      }
    }
  }
コード例 #5
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);
      }
    }
コード例 #6
0
 public void actionPerformed(ActionEvent e) {
   JMenuItem jmi = (JMenuItem) e.getSource();
   Iterator marks = mediator.getMarkerModel().getMarkersWithLabel(jmi.getText());
   if (marks.hasNext()) {
     ChronicleMarker marker = (ChronicleMarker) marks.next();
     Instant to = marker.getWhen();
     Instant from = mediator.getMajorMoment();
     viper.api.impl.Util.shiftDescriptors(new Descriptor[] {desc}, from, to);
   }
 }
コード例 #7
0
 public void actionPerformed(ActionEvent e) {
   Iterator toInterp = Collections.singleton(desc).iterator();
   JMenuItem jmi = (JMenuItem) e.getSource();
   Iterator marks = mediator.getMarkerModel().getMarkersWithLabel(jmi.getText());
   if (marks.hasNext()) {
     ChronicleMarker marker = (ChronicleMarker) marks.next();
     Instant to = marker.getWhen();
     Instant from = mediator.getMajorMoment();
     mediator.getPropagator().interpolateDescriptors(toInterp, from, to);
   }
 }
コード例 #8
0
ファイル: TabView.java プロジェクト: linvald/JarFileAnalyser
  /* (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();
      }
    }
  }
コード例 #9
0
ファイル: UIUtilities.java プロジェクト: pkdevbox/snapbackup
 public static void addFastKeys(JMenuBar menuBar) {
   for (Component menuComponent : menuBar.getComponents()) { // iterate over menus
     JMenu menu = (JMenu) menuComponent;
     menu.setMnemonic(menu.getText().charAt(menu.getText().indexOf('&') + 1));
     menu.setText(menu.getText().replace("&", ""));
     for (Component menuItemComponent : menu.getMenuComponents())
       if (menuItemComponent instanceof JMenuItem) { // skip separators
         JMenuItem menuItem = (JMenuItem) menuItemComponent;
         menuItem.setMnemonic(menuItem.getText().charAt(menuItem.getText().indexOf('&') + 1));
         menuItem.setText(menuItem.getText().replace("&", ""));
       }
     /*
     for (int count = 0; count < menu.getMenuComponentCount(); count++) {  //iterate over menu items
        Component menuItemComponent = menu.getMenuComponent(count);
        if (menuItemComponent instanceof JMenuItem) {   //skip separators
           JMenuItem menuItem = (JMenuItem)menuItemComponent;
           menuItem.setMnemonic(menuItem.getText().charAt(
                 menuItem.getText().indexOf('&') + 1));
           menuItem.setText(menuItem.getText().replace("&", ""));
           }
        }
     */
   }
 }
コード例 #10
0
ファイル: ControlPanel.java プロジェクト: johnperry/Geneva2
 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);
       }
     }
   }
 }
コード例 #11
0
 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);
   }
 }
コード例 #12
0
ファイル: ControlPanel.java プロジェクト: johnperry/Geneva2
 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);
   }
 }
コード例 #13
0
ファイル: MPopButton.java プロジェクト: timburrow/OpenVnmrJ
 /**
  * set text to the specified item index
  *
  * @param index index
  */
 public void setText(int index) {
   JMenuItem item = (JMenuItem) popup.getComponent(index);
   setText(item.getText());
 } // setText()
コード例 #14
0
ファイル: MPopButton.java プロジェクト: timburrow/OpenVnmrJ
 /** set default text */
 public void setDefaultText() {
   JMenuItem item = (JMenuItem) popup.getComponent(0);
   if (item != null) setText(item.getText());
 } // setDefaultText()
コード例 #15
0
ファイル: Menus.java プロジェクト: haomen/refs
 public void actionPerformed(ActionEvent e) {
   JMenuItem mi = (JMenuItem) e.getSource();
   l.setText(mi.getText());
   l.setIcon(mi.getIcon());
 }
コード例 #16
0
 public void actionPerformed(ActionEvent e) {
   JMenuItem selectedItem = (JMenuItem) e.getSource();
   addNote(selectedItem.getText());
 }
コード例 #17
0
ファイル: Game.java プロジェクト: Genki91/collapsing-puzzle
  /*
   * 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);
    }
  }