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.costache.calendar.JCalendar.java

/**
 * Binds listeners to the components/*from   w  w w . j a  va2  s .c  o  m*/
 */
private void bindListeners() {
    final ActionListener strategyActionListener = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            final boolean isDay = e.getSource().equals(headerPane.getDayButton());
            final boolean isWeek = e.getSource().equals(headerPane.getWeekButton());
            final DisplayStrategy.Type type = isDay ? Type.DAY : isWeek ? Type.WEEK : Type.MONTH;

            if (getDisplayStrategy() != type)
                setDisplayStrategy(type, getSelectedDay());
        }
    };

    headerPane.getDayButton().addActionListener(strategyActionListener);
    headerPane.getWeekButton().addActionListener(strategyActionListener);
    headerPane.getMonthButton().addActionListener(strategyActionListener);

    headerPane.getScrollLeft().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            final DisplayStrategy strategy = contentPane.getStrategy();
            strategy.moveIntervalLeft();
            headerPane.getIntervalLabel().setText(contentPane.getStrategy().getDisplayInterval());
            final IntervalChangedEvent event = new IntervalChangedEvent(JCalendar.this, strategy.getType(),
                    config.getIntervalStart().getTime(), config.getIntervalEnd().getTime());

            for (final IntervalChangedListener listener : intervalChangedListener) {
                listener.intervalChanged(event);
            }

        }
    });

    headerPane.getScrollRight().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            final DisplayStrategy strategy = contentPane.getStrategy();
            strategy.moveIntervalRight();
            headerPane.getIntervalLabel().setText(contentPane.getStrategy().getDisplayInterval());
            final IntervalChangedEvent event = new IntervalChangedEvent(JCalendar.this, strategy.getType(),
                    config.getIntervalStart().getTime(), config.getIntervalEnd().getTime());

            for (final IntervalChangedListener listener : intervalChangedListener) {
                listener.intervalChanged(event);
            }
        }
    });
}

From source file:de.interactive_instruments.ShapeChange.UI.DefaultDialog.java

public void actionPerformed(ActionEvent e) {
    if (startButton == e.getSource()) {
        mdl = mdlField.getText().trim();
        startButton.setEnabled(false);//w  ww  .  ja  v  a 2s .c o  m
        exitButton.setEnabled(false);
        try {
            options.setParameter("inputFile", mdl);
            if (mdl.toLowerCase().endsWith(".xmi") || mdl.toLowerCase().endsWith(".xml"))
                options.setParameter("inputModelType", "XMI10");
            else if (mdl.toLowerCase().endsWith(".eap"))
                options.setParameter("inputModelType", "EA7");
            else if (mdl.toLowerCase().endsWith(".mdb"))
                options.setParameter("inputModelType", "GSIP");

            options.setParameter("outputDirectory", outField.getText());
            options.setParameter("logFile", outField.getText() + "/log.xml");
            options.setParameter("appSchemaName", asField.getText());
            options.setParameter("reportLevel", reportGroup.getSelection().getActionCommand());
            options.setParameter(Options.TargetXmlSchemaClass, "defaultEncodingRule",
                    ruleGroup.getSelection().getActionCommand());
            if (docCB.isSelected())
                options.setParameter(Options.TargetXmlSchemaClass, "includeDocumentation", "true");
            else
                options.setParameter(Options.TargetXmlSchemaClass, "includeDocumentation", "false");
            if (!visCB.isSelected())
                options.setParameter("publicOnly", "true");
            else
                options.setParameter("publicOnly", "false");

            converter.convert();
        } catch (ShapeChangeAbortException ex) {
            Toolkit.getDefaultToolkit().beep();
        }
        logfile = new File(options.parameter("logFile").replace(".xml", ".html"));
        if (logfile != null && logfile.canRead())
            logButton.setEnabled(true);
        else {
            logfile = new File(options.parameter("logFile"));
            if (logfile != null && logfile.canRead())
                logButton.setEnabled(true);
        }
        exitButton.setEnabled(true);
    } else if (e.getSource() == logButton) {
        try {
            if (Desktop.isDesktopSupported())
                Desktop.getDesktop().open(logfile);
            else if (SystemUtils.IS_OS_WINDOWS)
                Runtime.getRuntime().exec("cmd /c start " + logfile.getPath());
            else
                Runtime.getRuntime().exec("open " + logfile.getPath());
        } catch (IOException e1) {
            e1.printStackTrace();
            System.exit(1);
        }
    } else if (e.getSource() == exitButton) {
        System.exit(0);
    } else if (e.getSource() == mdlButton) {
        int returnVal = fc.showOpenDialog(DefaultDialog.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            mdlField.setText(file.getAbsolutePath());
        }
    } else if (e.getSource() == cfgButton) {
        int returnVal = fc.showOpenDialog(DefaultDialog.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            cfgField.setText(file.getAbsolutePath());
        }
    } else if (e.getSource() == outButton) {
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showOpenDialog(DefaultDialog.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            outField.setText(file.getAbsolutePath());
        }
    }
}

From source file:dk.dma.epd.common.prototype.gui.voct.VOCTAdditionalInfoPanel.java

/**
 * {@inheritDoc}/*  w w  w  .ja  v a  2s.c  o m*/
 */
@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getSource() == addBtn || ae.getSource() == messageText) {
        sendChatMessage();
    }
}

From source file:AlternateAppearanceBoundsTest.java

public void actionPerformed(ActionEvent e) {
    int i;//from www .ja v  a  2s .com

    Object target = e.getSource();
    if (target == altAppMaterialColor) {
        altMat.setDiffuseColor(colors[altAppMaterialColor.getSelectedIndex()]);
    } else if (target == useBoundingLeaf) {
        boundingLeafOn = useBoundingLeaf.isSelected();
        if (boundingLeafOn) {
            leafBounds.setRegion(allBounds[currentBounds]);
            altApp.setInfluencingBoundingLeaf(leafBounds);
        } else {
            altApp.setInfluencingBoundingLeaf(null);
            altApp.setInfluencingBounds(allBounds[currentBounds]);
        }

    } else if (target == boundsType) {
        currentBounds = boundsType.getSelectedIndex();
        if (boundingLeafOn) {
            leafBounds.setRegion(allBounds[currentBounds]);
            altApp.setInfluencingBoundingLeaf(leafBounds);
        } else {
            altApp.setInfluencingBoundingLeaf(null);
            altApp.setInfluencingBounds(allBounds[currentBounds]);
        }

    } else if (target == override) {
        for (i = 0; i < shapes1.length; i++)
            shapes1[i].setAppearanceOverrideEnable(override.isSelected());
    } else if (target == appMaterialColor) {
        mat1.setDiffuseColor(colors[appMaterialColor.getSelectedIndex()]);
    }

}

From source file:com.game.ui.views.CharachterEditorPanel.java

@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equalsIgnoreCase("dropDown")) {
        JComboBox comboBox = (JComboBox) ae.getSource();
        JPanel panel = (JPanel) comboBox.getParent().getComponent(4);
        String name = comboBox.getSelectedItem().toString();
        for (GameCharacter enemy : GameBean.enemyDetails) {
            if (enemy.getName().equalsIgnoreCase(name)) {
                ((JTextField) panel.getComponent(2)).setText(enemy.getName());
                ((JTextField) panel.getComponent(4)).setText(enemy.getImagePath());
                ((JTextField) panel.getComponent(6)).setText(new Integer(enemy.getHealth()).toString());
                ((JTextField) panel.getComponent(8)).setText(new Integer(enemy.getAttackPts()).toString());
                ((JTextField) panel.getComponent(10)).setText(new Integer(enemy.getArmor()).toString());
                ((JTextField) panel.getComponent(12)).setText(new Integer(enemy.getAttackRange()).toString());
                ((JTextField) panel.getComponent(14)).setText(new Integer(enemy.getMovement()).toString());
                return;
            }/*from   ww w .  j  a  v a2  s  .  co  m*/
        }
    } else {
        JButton btn = (JButton) ae.getSource();
        JPanel panel = (JPanel) btn.getParent();
        int indexOfBtn = btn.getAccessibleContext().getAccessibleIndexInParent();
        String name = ((JTextField) panel.getComponent(2)).getText();
        String image = ((JTextField) panel.getComponent(4)).getText();
        String health = ((JTextField) panel.getComponent(6)).getText();
        String attackPts = ((JTextField) panel.getComponent(8)).getText();
        String armourPts = ((JTextField) panel.getComponent(10)).getText();
        String attackRnge = ((JTextField) panel.getComponent(12)).getText();
        String movement = ((JTextField) panel.getComponent(14)).getText();
        System.out.println("Index : " + indexOfBtn);
        JLabel message = ((JLabel) this.getComponent(5));
        message.setText("");
        message.setVisible(false);
        if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(image) && StringUtils.isNotBlank(health)
                && StringUtils.isNotBlank(attackPts) && StringUtils.isNotBlank(armourPts)
                && StringUtils.isNotBlank(attackRnge) && StringUtils.isNotBlank(movement)) {
            message.setVisible(false);
            GameCharacter character = new GameCharacter();
            character.setName(name);
            character.setAttackPts(Integer.parseInt(attackPts));
            character.setAttackRange(Integer.parseInt(attackRnge));
            character.setHealth(Integer.parseInt(health));
            character.setImagePath(image);
            character.setMovement(Integer.parseInt(movement));
            character.setArmor(Integer.parseInt(armourPts));
            boolean characterAlrdyPresent = false;
            for (int i = 0; i < GameBean.enemyDetails.size(); i++) {
                GameCharacter charFromList = GameBean.enemyDetails.get(i);
                if (charFromList.getName().equalsIgnoreCase(name)) {
                    GameBean.enemyDetails.remove(i);
                    GameBean.enemyDetails.add(i, character);
                    characterAlrdyPresent = true;
                }
            }
            if (!characterAlrdyPresent) {
                GameBean.enemyDetails.add(character);
            }
            try {
                GameUtils.writeCharactersToXML(GameBean.enemyDetails, Configuration.PATH_FOR_ENEMY_CHARACTERS);
                message.setText("Saved Successfully..");
                message.setVisible(true);
                if (!characterAlrdyPresent) {
                    comboBox.addItem(name);
                    comboBox.setSelectedItem(name);
                }
                TileInformation tileInfo = GameBean.mapInfo.getPathMap().get(location);
                if (tileInfo == null) {
                    tileInfo = new TileInformation();
                }
                tileInfo.setEnemy(character);
                GameBean.mapInfo.getPathMap().put(location, tileInfo);
                chkBox.setSelected(true);
                this.revalidate();
                return;
            } catch (Exception e) {
                System.out.println("CharachterEditorPanel : actionPerformed() : Some error occured " + e);
                e.printStackTrace();
            }

        } else {
            message.setText("Pls enter all the fields or pls choose a character from the drop down");
            message.setVisible(true);
            this.revalidate();
        }
    }
}

From source file:PlayerOfMedia.java

/***************************************************************************
 * React to menu selections (quit or open) or one of the the buttons on the
 * dialog boxes./*from   w  w w  .  j  a v a  2s  .co  m*/
 **************************************************************************/
public void actionPerformed(ActionEvent e) {

    if (e.getSource() instanceof MenuItem) {
        //////////////////////////////////////////////////
        // Quit and free up any player acquired resources.
        //////////////////////////////////////////////////
        if (e.getActionCommand().equalsIgnoreCase("QUIT")) {
            if (player != null) {
                player.stop();
                player.close();
            }
            System.exit(0);
        }
        /////////////////////////////////////////////////////////
        // User to open/play media. Show the selection dialog box.
        /////////////////////////////////////////////////////////
        else if (e.getActionCommand().equalsIgnoreCase("OPEN")) {
            selectionDialog.show();
        }
    }
    //////////////////////
    // One of the Buttons.
    //////////////////////
    else {
        /////////////////////////////////////////////////////////////
        // User to browse the local file system. Popup a file dialog.
        /////////////////////////////////////////////////////////////
        if (e.getSource() == choose) {
            FileDialog choice = new FileDialog(this, "Media File Choice", FileDialog.LOAD);
            if (lastDirectory != null)
                choice.setDirectory(lastDirectory);
            choice.show();
            String selection = choice.getFile();
            if (selection != null) {
                lastDirectory = choice.getDirectory();
                mediaName.setText("file://" + choice.getDirectory() + selection);
            }
        }
        ///////////////////////////////////////////////
        // User chooses to cancel opening of new media.
        ///////////////////////////////////////////////
        else if (e.getSource() == cancel) {
            selectionDialog.hide();
        }
        ///////////////////////////////////////////////////////
        // User has selected the name of the media. Attempt to
        // create a Player.
        ///////////////////////////////////////////////////////
        else if (e.getSource() == open) {
            selectionDialog.hide();
            createAPlayer(mediaName.getText());
        }
        ////////////////////////////////////////////
        // User has seen error message. Now hide it.
        ////////////////////////////////////////////
        else if (e.getSource() == ok)
            errorDialog.hide();
    }
}

From source file:de.huberlin.cuneiform.compiler.debug.DebugDispatcher.java

@Override
public void actionPerformed(ActionEvent e) {

    List<Integer> signatureList;
    Set<Invocation> readyInvocationSet;
    Set<JsonReportEntry> report;

    if (e.getSource() == exitItem) {

        frame.dispose();//from  w  w w.  java  2  s. c o m
        return;
    }

    if (e.getActionCommand().equals(PreInvocView.LABEL_STEP)) {

        signatureList = invocOverview.getSelectedPreInvocSignatureList();
        readyInvocationSet = getReadyInvocationSet();

        if (signatureList == null)
            throw new NullPointerException("Signature list must not be null.");

        if (signatureList.isEmpty())
            throw new RuntimeException("Signature list must not be empty.");

        invocOverview.setContentOld();

        try {

            for (Integer i : signatureList) {

                if (i == null)
                    throw new NullPointerException("Signature must not be null.");

                for (Invocation invoc : readyInvocationSet)

                    if (invoc.getSignature() == i) {

                        report = dispatch(invoc);

                        if (!invoc.isComputed())
                            throw new RuntimeException("Expected the invocation to be computed.");

                        evalReport(report);

                        readyInvocationSet.remove(invoc);

                        invocOverview.removePreInvocation(invoc);
                        invocOverview.insertPostInvocation(invoc);

                        break;
                    }

                updateView();
            }
        } catch (NotDerivableException e1) {

            e1.printStackTrace();

            JOptionPane.showMessageDialog(frame, e1.getMessage(), "NotDerivableException",
                    JOptionPane.ERROR_MESSAGE);

        } catch (IOException e1) {

            e1.printStackTrace();

            JOptionPane.showMessageDialog(frame, e1.getMessage(), "IOException", JOptionPane.ERROR_MESSAGE);

        } catch (InterruptedException e1) {

            e1.printStackTrace();

            JOptionPane.showMessageDialog(frame, e1.getMessage(), "InterruptedException",
                    JOptionPane.ERROR_MESSAGE);

        } catch (JSONException e1) {

            e1.printStackTrace();

            JOptionPane.showMessageDialog(frame, e1.getMessage(), "JSONException", JOptionPane.ERROR_MESSAGE);
        }

        return;
    }
}

From source file:es.emergya.ui.gis.popups.ListaCapas.java

@Override
public void actionPerformed(ActionEvent e) {
    for (Layer l : mapView.getAllLayers()) {
        if (l.name.equals(e.getActionCommand())) {
            l.visible = ((JCheckBox) e.getSource()).isSelected();
            mapView.repaint();//from www . j a v a  2s  . co  m
            return;
        }
    }
}

From source file:org.yccheok.jstock.gui.BuyPortfolioChartJDialog.java

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
    String selected = ((javax.swing.JComboBox) evt.getSource()).getSelectedItem().toString();

    final int selectedIndex = ((javax.swing.JComboBox) evt.getSource()).getSelectedIndex();
    JStock.instance().getJStockOptions().setLastSelectedBuyPortfolioChartIndex(selectedIndex);

    final JFreeChart freeChart = this.createChart(selected);
    org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart);
    chartPanel.setChart(freeChart);// ww w.j a va 2 s  .c o  m
}

From source file:de.tor.tribes.ui.components.DatePicker.java

private void firePrevNextAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_firePrevNextAction
    if (evt.getSource().equals(jButtonPrevious)) {
        selectedDate = DateUtils.addMonths(selectedDate, -1);
        buildCalendar();//from ww w. j  a v a 2  s  . c o  m
    } else if (evt.getSource().equals(jButtonNext)) {
        selectedDate = DateUtils.addMonths(selectedDate, 1);
        buildCalendar();
    }
}