Example usage for java.awt.event ActionEvent getSource

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

Introduction

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

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:de.tud.kom.p2psim.impl.skynet.visualization.SkyNetVisualization.java

public void actionPerformed(ActionEvent arg0) {
    String name = arg0.getActionCommand();
    if (arg0.getSource() instanceof JCheckBoxMenuItem) {
        JCheckBoxMenuItem j = (JCheckBoxMenuItem) arg0.getSource();
        if (j.isSelected()) {
            createPlotInWindow(name);// w ww. j a  v  a 2 s . c  o  m
        } else {
            deletePlotInWindow(name);
        }
    } else {
        if (name.contains("Average Metrics")) {
            if (name.startsWith("Display")) {
                displayAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(0));
            } else {
                removeAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(0));
            }
        } else if (name.contains("General Metrics")) {
            if (name.startsWith("Display")) {
                displayAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(1));
            } else {
                removeAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(1));
            }
        } else if (name.contains("Metrics for Receiving")) {
            if (name.startsWith("Display")) {
                displayAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(2));
            } else {
                removeAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(2));
            }
        } else if (name.contains("Metrics for Sending")) {
            if (name.startsWith("Display")) {
                displayAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(3));
            } else {
                removeAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(3));
            }
        } else {
            for (int i = 0; i < mb.getMenu(1).getMenuComponentCount(); i++) {
                if (mb.getMenu(1).getMenuComponent(i) instanceof JMenu) {
                    if (name.startsWith("Display")) {
                        displayAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(i));
                    } else {
                        removeAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(i));
                    }
                }
            }
        }
    }
    validate();
    repaint();
    Runtime.getRuntime().gc();
}

From source file:gmgen.GMGenSystem.java

/**
 * Calls the appropriate methods depending on the actions that happened on
 * the GUI./*from   w  w  w.j  a  v a 2s  .  c  o m*/
 * 
 * @param event
 *            event that took place
 */
@Override
public void actionPerformed(ActionEvent event) {
    if (event.getSource() == openFileItem) {
        messageHandler.handleMessage(new FileMenuOpenMessage(this));
    } else if (event.getSource() == exitFileItem) {
        messageHandler.handleMessage(new GMGenBeingClosedMessage(this));
    } else if (event.getSource() == newFileItem) {
        messageHandler.handleMessage(new FileMenuNewMessage(this));
    } else if (event.getSource() == saveFileItem) {
        messageHandler.handleMessage(new FileMenuSaveMessage(this));
    } else if (event.getSource() == cutEditItem) {
        messageHandler.handleMessage(new EditMenuCutSelectionMessage(this));
    } else if (event.getSource() == copyEditItem) {
        messageHandler.handleMessage(new EditMenuCopySelectionMessage(this));
    } else if (event.getSource() == pasteEditItem) {
        messageHandler.handleMessage(new EditMenuPasteSelectionMessage(this));
    }
}

From source file:net.pandoragames.far.ui.swing.dialog.SettingsDialog.java

private void init() {
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
    this.setResizable(false);

    JPanel basePanel = new JPanel();
    basePanel.setLayout(new BoxLayout(basePanel, BoxLayout.Y_AXIS));
    basePanel.setBorder(//from   w w  w .  j a  v  a2s.  c o  m
            BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING));
    registerCloseWindowKeyListener(basePanel);

    // sink for error messages
    MessageLabel errorField = new MessageLabel();
    errorField.setMinimumSize(new Dimension(100, swingConfig.getStandardComponentHight()));
    errorField.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING));
    TwoComponentsPanel lineError = new TwoComponentsPanel(errorField,
            Box.createRigidArea(new Dimension(1, swingConfig.getStandardComponentHight())));
    lineError.setAlignmentX(Component.LEFT_ALIGNMENT);
    basePanel.add(lineError);

    // character set
    JLabel labelCharset = new JLabel(swingConfig.getLocalizer().localize("label.default-characterset"));
    labelCharset.setAlignmentX(Component.LEFT_ALIGNMENT);
    basePanel.add(labelCharset);

    JComboBox listCharset = new JComboBox(swingConfig.getCharsetList().toArray());
    listCharset.setAlignmentX(Component.LEFT_ALIGNMENT);
    listCharset.setSelectedItem(swingConfig.getDefaultCharset());
    listCharset.setEditable(true);
    listCharset.setMaximumSize(
            new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight()));

    listCharset.addActionListener(new CharacterSetListener(errorField));
    listCharset.setEditor(new CharacterSetEditor(errorField));
    basePanel.add(listCharset);

    basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));

    // select the group selector
    JPanel selectorPanel = new JPanel();
    selectorPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    selectorPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    // linePattern.setAlignmentX( Component.LEFT_ALIGNMENT );
    JLabel labelSelector = new JLabel(swingConfig.getLocalizer().localize("label.group-ref-indicator"));
    selectorPanel.add(labelSelector);
    JComboBox selectorBox = new JComboBox(FARConfig.GROUPREFINDICATORLIST);
    selectorBox.setSelectedItem(Character.toString(groupReference));
    selectorBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            JComboBox cbox = (JComboBox) event.getSource();
            String indicator = (String) cbox.getSelectedItem();
            groupReference = indicator.charAt(0);
        }
    });
    selectorPanel.add(selectorBox);
    basePanel.add(selectorPanel);

    basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));

    // checkbox DO BACKUP
    JCheckBox doBackupFlag = new JCheckBox(swingConfig.getLocalizer().localize("label.create-backup"));
    doBackupFlag.setAlignmentX(Component.LEFT_ALIGNMENT);
    doBackupFlag.setHorizontalTextPosition(SwingConstants.LEADING);
    doBackupFlag.setSelected(replaceForm.isDoBackup());
    doBackupFlag.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            doBackup = ItemEvent.SELECTED == event.getStateChange();
            backupFlagEvent = event;
        }
    });
    basePanel.add(doBackupFlag);

    JTextField backupDirPathTextField = new JTextField();
    backupDirPathTextField.setPreferredSize(
            new Dimension(SwingConfig.COMPONENT_WIDTH, swingConfig.getStandardComponentHight()));
    backupDirPathTextField.setMaximumSize(
            new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight()));
    backupDirPathTextField.setText(backupDirectory.getPath());
    backupDirPathTextField.setToolTipText(backupDirectory.getPath());
    backupDirPathTextField.setEditable(false);
    JButton openBaseDirFileChooserButton = new JButton(swingConfig.getLocalizer().localize("button.browse"));
    BrowseButtonListener backupDirButtonListener = new BrowseButtonListener(backupDirPathTextField,
            new BackUpDirectoryRepository(swingConfig, findForm, replaceForm, errorField),
            swingConfig.getLocalizer().localize("label.choose-backup-directory"));
    openBaseDirFileChooserButton.addActionListener(backupDirButtonListener);
    TwoComponentsPanel lineBaseDir = new TwoComponentsPanel(backupDirPathTextField,
            openBaseDirFileChooserButton);
    lineBaseDir.setAlignmentX(Component.LEFT_ALIGNMENT);
    basePanel.add(lineBaseDir);

    basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));

    JPanel fileInfoPanel = new JPanel();
    fileInfoPanel
            .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
                    swingConfig.getLocalizer().localize("label.default-file-info")));
    fileInfoPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    fileInfoPanel.setLayout(new BoxLayout(fileInfoPanel, BoxLayout.Y_AXIS));
    JLabel fileInfoLabel = new JLabel(swingConfig.getLocalizer().localize("message.displayed-in-info-column"));
    fileInfoLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    fileInfoPanel.add(fileInfoLabel);
    fileInfoPanel.add(Box.createHorizontalGlue());
    JRadioButton nothingRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.nothing"));
    nothingRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    nothingRadio.setActionCommand(SwingConfig.DefaultFileInfo.NOTHING.name());
    nothingRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.NOTHING);
    fileInfoOptions.add(nothingRadio);
    fileInfoPanel.add(nothingRadio);
    JRadioButton readOnlyRadio = new JRadioButton(
            swingConfig.getLocalizer().localize("label.read-only-warning"));
    readOnlyRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    readOnlyRadio.setActionCommand(SwingConfig.DefaultFileInfo.READONLY.name());
    readOnlyRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.READONLY);
    fileInfoOptions.add(readOnlyRadio);
    fileInfoPanel.add(readOnlyRadio);
    JRadioButton sizeRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.filesize"));
    sizeRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    sizeRadio.setActionCommand(SwingConfig.DefaultFileInfo.SIZE.name());
    sizeRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.SIZE);
    fileInfoOptions.add(sizeRadio);
    fileInfoPanel.add(sizeRadio);
    JCheckBox showPlainBytesFlag = new JCheckBox(
            "  " + swingConfig.getLocalizer().localize("label.show-plain-bytes"));
    showPlainBytesFlag.setAlignmentX(Component.LEFT_ALIGNMENT);
    showPlainBytesFlag.setHorizontalTextPosition(SwingConstants.LEADING);
    showPlainBytesFlag.setSelected(swingConfig.isShowPlainBytes());
    showPlainBytesFlag.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            showBytes = ItemEvent.SELECTED == event.getStateChange();
        }
    });
    fileInfoPanel.add(showPlainBytesFlag);
    JRadioButton lastModifiedRadio = new JRadioButton(
            swingConfig.getLocalizer().localize("label.last-modified"));
    lastModifiedRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    lastModifiedRadio.setActionCommand(SwingConfig.DefaultFileInfo.LAST_MODIFIED.name());
    lastModifiedRadio
            .setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.LAST_MODIFIED);
    fileInfoOptions.add(lastModifiedRadio);
    fileInfoPanel.add(lastModifiedRadio);
    basePanel.add(fileInfoPanel);

    // buttons
    JPanel buttonPannel = new JPanel();
    buttonPannel.setAlignmentX(Component.LEFT_ALIGNMENT);
    buttonPannel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    // cancel
    JButton cancelButton = new JButton(swingConfig.getLocalizer().localize("button.cancel"));
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            SettingsDialog.this.dispose();
        }
    });
    buttonPannel.add(cancelButton);
    // save
    JButton saveButton = new JButton(swingConfig.getLocalizer().localize("button.save"));
    saveButton.addActionListener(new SaveButtonListener());
    buttonPannel.add(saveButton);
    this.getRootPane().setDefaultButton(saveButton);

    this.add(basePanel);
    this.add(buttonPannel);
    placeOnScreen(swingConfig.getScreenCenter());
}

From source file:aurelienribon.gdxsetupui.ui.panels.LibrarySelectionPanel.java

private void buildLibraryPanel(final String libraryName) {
    ActionListener nameChkAL = new ActionListener() {
        @Override//from   w w w  . j a v a2 s  . c om
        public void actionPerformed(ActionEvent e) {
            if (((CompactCheckBox) e.getSource()).isSelected()) {
                if (!Ctx.cfgSetup.libraries.contains(libraryName))
                    Ctx.cfgSetup.libraries.add(libraryName);
                if (!Ctx.cfgUpdate.libraries.contains(libraryName))
                    Ctx.cfgUpdate.libraries.add(libraryName);
            } else {
                Ctx.cfgSetup.libraries.remove(libraryName);
                Ctx.cfgUpdate.libraries.remove(libraryName);
            }

            Ctx.fireCfgSetupChanged();
            Ctx.fireCfgUpdateChanged();
        }
    };

    Action infoAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            showInfo(libraryName);
        }
    };
    Action browseAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            browse(libraryName);
        }
    };
    Action getStableAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            getStable(libraryName);
        }
    };
    Action getLatestAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            getLatest(libraryName);
        }
    };

    LibraryDef def = Ctx.libs.getDef(libraryName);

    CompactCheckBox nameChk = new CompactCheckBox(def.name + " ");
    JLabel html5Label = new JLabel(Res.getImage("gfx/ic_html5.png"));
    JButton infoBtn = new JButton(infoAction);
    JButton browseBtn = new JButton(browseAction);
    JButton getStableBtn = new JButton(getStableAction);
    JButton getLatestBtn = new JButton(getLatestAction);

    nameChk.addActionListener(nameChkAL);
    nameChk.setForeground(LIB_NOTFOUND_COLOR);
    html5Label.setToolTipText("Compatible with HTML backend");
    infoBtn.setIcon(Res.getImage("gfx/ic_info.png"));
    browseBtn.setIcon(Res.getImage("gfx/ic_browse.png"));
    getStableBtn.setIcon(Res.getImage("gfx/ic_download_stable.png"));
    getLatestBtn.setIcon(Res.getImage("gfx/ic_download_nightlies.png"));
    infoBtn.setFocusable(false);
    browseBtn.setFocusable(false);
    getStableBtn.setFocusable(false);
    getLatestBtn.setFocusable(false);

    JToolBar toolBar = new JToolBar();
    toolBar.setOpaque(false);
    toolBar.setFloatable(false);
    toolBar.add(Box.createHorizontalGlue());
    toolBar.add(infoBtn);
    toolBar.add(browseBtn);
    if (def.stableUrl != null)
        toolBar.add(getStableBtn);
    else
        toolBar.add(Box.createHorizontalStrut(libgdxGetStableBtn.getPreferredSize().width));
    if (def.latestUrl != null)
        toolBar.add(getLatestBtn);
    else
        toolBar.add(Box.createHorizontalStrut(libgdxGetNightliesBtn.getPreferredSize().width));

    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.setOpaque(false);
    leftPanel.add(nameChk, BorderLayout.CENTER);
    if (def.gwtModuleName != null)
        leftPanel.add(html5Label, BorderLayout.EAST);

    JPanel panel = new JPanel(new BorderLayout());
    panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25));
    panel.setOpaque(false);
    panel.add(leftPanel, BorderLayout.WEST);
    panel.add(toolBar, BorderLayout.CENTER);

    librariesPanel.add(panel);

    Style.apply(librariesPanel, style);
    libsNamesCmps.put(libraryName, nameChk);
}

From source file:org.peerfact.impl.service.aggregation.skyeye.visualization.SkyNetVisualization.java

@Override
public void actionPerformed(ActionEvent arg0) {
    String name = arg0.getActionCommand();
    if (arg0.getSource() instanceof JCheckBoxMenuItem) {
        JCheckBoxMenuItem j = (JCheckBoxMenuItem) arg0.getSource();
        if (j.isSelected()) {
            createPlotInWindow(name);//from   w w w  .j  a v a2 s.  c om
        } else {
            deletePlotInWindow(name);
        }
    } else {
        if (name.contains("Average Metrics")) {
            if (name.startsWith("Display")) {
                displayAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(0));
            } else {
                removeAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(0));
            }
        } else if (name.contains("General Metrics")) {
            if (name.startsWith("Display")) {
                displayAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(1));
            } else {
                removeAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(1));
            }
        } else if (name.contains("Metrics for Receiving")) {
            if (name.startsWith("Display")) {
                displayAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(2));
            } else {
                removeAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(2));
            }
        } else if (name.contains("Metrics for Sending")) {
            if (name.startsWith("Display")) {
                displayAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(3));
            } else {
                removeAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(3));
            }
        } else {
            for (int i = 0; i < mb.getMenu(1).getMenuComponentCount(); i++) {
                if (mb.getMenu(1).getMenuComponent(i) instanceof JMenu) {
                    if (name.startsWith("Display")) {
                        displayAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(i));
                    } else {
                        removeAllMetricsOfAGroup((JMenu) mb.getMenu(1).getMenuComponent(i));
                    }
                }
            }
        }
    }
    validate();
    repaint();
    // Runtime.getRuntime().gc();
}

From source file:cc.siara.csv_ml_demo.MultiLevelCSVSwingDemo.java

public void actionPerformed(ActionEvent e) {
    Object src_obj = e.getSource();
    if (src_obj.equals(cbExamples))
        setInputText();//from ww w .  j av a2 s. c o  m
    if (src_obj.equals(cbDelimiter))
        setDelimiter();
    if (src_obj.equals(btnXML))
        toXML();
    if (src_obj.equals(btnJSON))
        toJSON();
    if (src_obj.equals(btnXPath))
        processXPath();
    if (src_obj.equals(btnDDLDML))
        toDDLDML();
    if (src_obj.equals(btnToCSV))
        xmlToCSV();
    if (src_obj.equals(btnRunDDL))
        runDDL();
    if (src_obj.equals(btnGetData))
        runSQL();
    if (src_obj.equals(btnAbout)) {
        JOptionPane.showMessageDialog(null, "Multi-level (nested) CSV Demo Application\n\n"
                + "(c) Siara Logics (cc)\n" + "http://siara.cc/csv_ml\n\n" + "License: Apache License 2.0");
    }
}

From source file:Human1.java

public void actionPerformed(ActionEvent e) {
    String action = e.getActionCommand();
    Object source = e.getSource();
    if (action == snapImageString) {
        Point loc = canvas.getLocationOnScreen();
        offScreenCanvas.setOffScreenLocation(loc);
        Dimension dim = canvas.getSize();
        dim.width *= offScreenScale;// www  .j  a  v  a 2  s.c om
        dim.height *= offScreenScale;
        nf.setMinimumIntegerDigits(3);
        offScreenCanvas.snapImageFile(outFileBase + nf.format(outFileSeq++), dim.width, dim.height);
        nf.setMinimumIntegerDigits(0);
    }
}

From source file:com.diversityarrays.kdxplore.trials.AddScoringSetDialog.java

private Box createWantSampleButtons(SampleGroup curatedSampleGroup) {
    Box result = null;/*  w  w  w  . j  a v  a2s.c  o  m*/
    ActionListener rbListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            wantSampleValues = noSampleValuesButton != e.getSource();
        }
    };

    result = Box.createHorizontalBox();
    String noSampleValues = Msg.OPTION_NO_SAMPLE_VALUES();
    ButtonGroup bg = new ButtonGroup();
    for (String rbname : new String[] { noSampleValues, Msg.OPTION_CURATED_SAMPLE_VALUES() }) {
        JRadioButton rb = new JRadioButton(rbname);
        result.add(rb);
        bg.add(rb);
        rb.addActionListener(rbListener);
        if (noSampleValues.equals(rbname)) {
            noSampleValuesButton = rb;
        } else {
            rb.doClick();
        }
    }
    result.add(Box.createHorizontalGlue());

    return result;
}

From source file:de.tor.tribes.ui.windows.ClockFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("RemoveTimer")) {
        removeTimer((TimerPanel) e.getSource());
    }//from w  w  w  .  j a  v a  2  s  .c  o  m
}

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

private void rebuildLegend() {
    legend.removeAll();//from  w  w w .  java 2 s . c  om
    for (int i = 0; i < enabled.size(); i++) {
        makeLegendEntry(legend, chart, sampler.getSeries(enabled.get(i)).getLabel(), i);
    }
    legend.add(new JLabel());
    legend.add(new JLabel());
    JButton newb = IconLoader.makeImageButton("gui/icons/plus.png", "New...");

    newb.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            displayAddPopup((JButton) e.getSource());
        }
    });

    legend.add(newb);
}