Example usage for java.awt.event ActionEvent getActionCommand

List of usage examples for java.awt.event ActionEvent getActionCommand

Introduction

In this page you can find the example usage for java.awt.event ActionEvent getActionCommand.

Prototype

public String getActionCommand() 

Source Link

Document

Returns the command string associated with this action.

Usage

From source file:gda.util.userOptions.UserOptionsDialog.java

@Override
@SuppressWarnings("rawtypes")
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("Default")) {
        Iterator<Map.Entry<String, Component>> iter = components.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<String, Component> entry = iter.next();
            UserOption option = options.get(entry.getKey());
            if (option.defaultValue instanceof Boolean) {
                ((JCheckBox) entry.getValue()).setSelected((Boolean) option.defaultValue);
            }//from  w  w w.j  ava 2  s. c o  m
        }
        return;
    }
    if (e.getActionCommand().equals("Reset")) {
        Iterator<Map.Entry<String, Component>> iter = components.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<String, Component> entry = iter.next();
            UserOption option = options.get(entry.getKey());
            if (option.defaultValue instanceof Boolean) {
                ((JCheckBox) entry.getValue()).setSelected((Boolean) option.value);
            }
        }
        return;
    }
    if (e.getActionCommand().equals("OK")) {
        Iterator<Map.Entry<String, Component>> iter = components.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<String, Component> entry = iter.next();
            UserOption option = options.get(entry.getKey());
            if (option.defaultValue instanceof Boolean) {
                option.value = ((JCheckBox) entry.getValue()).isSelected();
            }
        }
    }
    ok = e.getActionCommand().equals("OK");
    setVisible(false);
    dispose();
}

From source file:InternalFrameEventDemo.java

public void actionPerformed(ActionEvent e) {
    if (SHOW.equals(e.getActionCommand())) {
        // They clicked the Show button.

        // Create the internal frame if necessary.
        if (listenedToWindow == null) {
            listenedToWindow = new JInternalFrame("Event Generator", true, // resizable
                    true, // closable
                    true, // maximizable
                    true); // iconifiable
            // We want to reuse the internal frame, so we need to
            // make it hide (instead of being disposed of, which is
            // the default) when the user closes it.
            listenedToWindow.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

            // Add an internal frame listener so we can see
            // what internal frame events it generates.
            listenedToWindow.addInternalFrameListener(this);

            // And we mustn't forget to add it to the desktop pane!
            desktop.add(listenedToWindow);

            // Set its size and location. We'd use pack() to set the size
            // if the window contained anything.
            listenedToWindow.setSize(300, 100);
            listenedToWindow.setLocation(desktopWidth / 2 - listenedToWindow.getWidth() / 2,
                    desktopHeight - listenedToWindow.getHeight());
        }//from www  . java  2  s .c o m

        // Show the internal frame.
        listenedToWindow.setVisible(true);

    } else { // They clicked the Clear button.
        display.setText("");
    }
}

From source file:ToggleButton.java

public void actionPerformed(ActionEvent e) {
    Color color = display.getBackground();
    int red = color.getRed();
    int green = color.getGreen();
    int blue = color.getBlue();

    if (e.getActionCommand() == "red") {
        if (red == 0) {
            red = 255;/*from w ww  .j  av a  2s  .  co  m*/
        } else {
            red = 0;
        }
    }

    if (e.getActionCommand() == "green") {
        if (green == 0) {
            green = 255;
        } else {
            green = 0;
        }
    }

    if (e.getActionCommand() == "blue") {
        if (blue == 0) {
            blue = 255;
        } else {
            blue = 0;
        }
    }

    Color setCol = new Color(red, green, blue);
    display.setBackground(setCol);
}

From source file:org.simbrain.plot.barchart.BarChartGui.java

/** @see ActionListener */
public void actionPerformed(final ActionEvent arg0) {
    if (arg0.getActionCommand().equalsIgnoreCase("dialog")) {
        ReflectivePropertyEditor editor = (new ReflectivePropertyEditor(getWorkspaceComponent().getModel()));
        JDialog dialog = editor.getDialog();
        dialog.setModal(true);//w w  w.  java  2s  .  c o m
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
    } else if (arg0.getActionCommand().equalsIgnoreCase("Delete")) {
        this.getWorkspaceComponent().getModel().removeColumn();
    } else if (arg0.getActionCommand().equalsIgnoreCase("Add")) {
        this.getWorkspaceComponent().getModel().addColumn();
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationReportPanel.java

public void actionPerformed(ActionEvent e) {

    String action = e.getActionCommand();

    if (action.equals("new"))
        theApplication.onNew(theDocument);

    else if (action.equals("print"))
        onPrint();/*from  ww w  . j a  v a 2s  .c om*/

    updateActions();
}

From source file:net.chaosserver.timelord.swingui.PreviousDayPanel.java

/**
 * Listens for action from this panel. If the pick date button is choosen
 * displays a Calendar allowing a user to select a date for display.
 *
 * @param evt the event triggering things
 *//* w ww  . j  a  v  a 2  s .c  o  m*/
public void actionPerformed(ActionEvent evt) {
    if (ACTION_PICK_DAY.equals(evt.getActionCommand())) {
        Frame ownerFrame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, this);
        JCalendarDialog calendarDialog = new JCalendarDialog(ownerFrame, getDisplayDate());

        calendarDialog.pack();

        Point ownerFrameLocation = ownerFrame.getLocation();
        ownerFrameLocation.setLocation(ownerFrameLocation.getX() + LayoutConstants.CHILD_FRAME_X_OFFSET,
                ownerFrameLocation.getY() + LayoutConstants.CHILD_FRAME_Y_OFFSET);

        calendarDialog.setLocation(ownerFrameLocation);
        calendarDialog.setVisible(true);

        Date choosenDate = calendarDialog.getChoosenDate();

        if (choosenDate != null) {
            setDisplayDate(choosenDate);
        }
    }
}

From source file:com.digitalgeneralists.assurance.ui.components.FilePickerTextField.java

public void actionPerformed(ActionEvent e) {
    if (AssuranceActions.chooseFilePathAction.equals(e.getActionCommand())) {
        this.filePicker.setDialogTitle("Choose " + this.fieldName);

        int returnVal = this.filePicker.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = filePicker.getSelectedFile();
            if (AssuranceActions.chooseFilePathAction.equals(e.getActionCommand())) {
                this.pathTextField.setText(file.getAbsolutePath());
            }//ww w .j  ava  2  s . c  o m
            file = null;
        } else {
        }
    }
}

From source file:Main.java

public void actionPerformed(ActionEvent ae) {
    DefaultMutableTreeNode dmtn, node;

    TreePath path = this.getSelectionPath();
    dmtn = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (ae.getActionCommand().equals("insert")) {
        node = new DefaultMutableTreeNode("children");
        dmtn.add(node);//from   w w  w.  j  a  v a  2s.  c o m
        ((DefaultTreeModel) this.getModel()).nodeStructureChanged((TreeNode) dmtn);
    }
    if (ae.getActionCommand().equals("remove")) {
        node = (DefaultMutableTreeNode) dmtn.getParent();
        int nodeIndex = node.getIndex(dmtn);
        dmtn.removeAllChildren();
        node.remove(nodeIndex);
        ((DefaultTreeModel) this.getModel()).nodeStructureChanged((TreeNode) dmtn);
    }
}

From source file:net.sf.firemox.ui.MdbListener.java

/**
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 *///from   www  .  j a v a2 s  .  c o m
public void actionPerformed(ActionEvent e) {
    if ("menu_options_tbs_more".equals(e.getActionCommand())) {
        // goto "more TBS" page
        try {
            WebBrowser.launchBrowser("http://sourceforge.net/project/showfiles.php?group_id="
                    + IdConst.PROJECT_ID + "&package_id=107882");
        } catch (Exception e1) {
            JOptionPane.showOptionDialog(MagicUIComponents.magicForm,
                    LanguageManager.getString("error") + " : " + e1.getMessage(),
                    LanguageManager.getString("web-pb"), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE,
                    UIHelper.getIcon("wiz_update_error.gif"), null, null);
        }
        return;
    }
    if ("menu_options_tbs_update".equals(e.getActionCommand())) {
        // update the current TBS
        XmlConfiguration.main(new String[] { "-g", MToolKit.tbsName });
        return;
    }
    if ("menu_options_tbs_rebuild".equals(e.getActionCommand())) {
        /*
         * rebuild completely the current TBS
         */
        XmlConfiguration.main(new String[] { "-f", "-g", MToolKit.tbsName });
        return;
    }

    // We change the TBS

    // Wait for confirmation
    if (JOptionPane.YES_OPTION == JOptionPane.showOptionDialog(MagicUIComponents.magicForm,
            LanguageManager.getString("warn-disconnect"), LanguageManager.getString("disconnect"),
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, UIHelper.getIcon("wiz_update.gif"), null,
            null)) {

        // Save the current settings before changing TBS
        Magic.saveSettings();

        // Copy this settings file to the profile directory of this TBS
        final File propertyFile = MToolKit.getFile(IdConst.FILE_SETTINGS);
        try {
            FileUtils.copyFile(propertyFile, MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false));

            // Delete the current settings file of old TBS
            propertyFile.delete();

            // Load the one of the new TBS
            abstractMainForm.setMdb(e.getActionCommand());
            Configuration.loadTemplateFile(
                    MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false).getAbsolutePath());

            // Copy the saved configuration of new TBS
            FileUtils.copyFile(MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false), propertyFile);
            Log.info("Successful TBS swith to " + MToolKit.tbsName);

            // Restart the game
            System.exit(IdConst.EXIT_CODE_RESTART);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

From source file:InternalFrameEventDemo.java

public void actionPerformed(ActionEvent e) {
    if (SHOW.equals(e.getActionCommand())) {
        //They clicked the Show button.

        //Create the internal frame if necessary.
        if (listenedToWindow == null) {
            listenedToWindow = new JInternalFrame("Event Generator", true, //resizable
                    true, //closable
                    true, //maximizable
                    true); //iconifiable
            //We want to reuse the internal frame, so we need to
            //make it hide (instead of being disposed of, which is
            //the default) when the user closes it.
            listenedToWindow.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

            //Add an internal frame listener so we can see
            //what internal frame events it generates.
            listenedToWindow.addInternalFrameListener(this);

            //And we mustn't forget to add it to the desktop pane!
            desktop.add(listenedToWindow);

            //Set its size and location. We'd use pack() to set the size
            //if the window contained anything.
            listenedToWindow.setSize(300, 100);
            listenedToWindow.setLocation(desktopWidth / 2 - listenedToWindow.getWidth() / 2,
                    desktopHeight - listenedToWindow.getHeight());
        }/*  ww  w . j  a v a 2s  .c  o  m*/

        //Show the internal frame.
        listenedToWindow.setVisible(true);

    } else { //They clicked the Clear button.
        display.setText("");
    }
}