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:com.igormaznitsa.zxpoly.MainForm.java

@Override
public void actionPerformed(final ActionEvent e) {
    if (e.getSource() instanceof TapeFileReader) {
        updateTapeMenu();/* ww  w  .j  a  va  2s  .  com*/
    }
}

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

@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equalsIgnoreCase("dropDown")) {
        JPanel panel = (JPanel) comboBox.getParent().getComponent(4);
        String name = comboBox.getSelectedItem().toString();
        for (Item item : GameBean.weaponDetails) {
            if (item instanceof Weapon) {
                Weapon weapon = (Weapon) item;
                if (weapon.getName().equalsIgnoreCase(name)) {
                    ((JTextField) panel.getComponent(2)).setText(name);
                    ((JComboBox) panel.getComponent(4)).setSelectedItem(weapon.getWeaponType());
                    ((JTextField) panel.getComponent(6)).setText(Integer.toString(weapon.getAttackRange()));
                    ((JTextField) panel.getComponent(8)).setText(Integer.toString(weapon.getAttackPts()));
                    return;
                }//from   w  w w  .j  ava  2  s .co m
            }
        }
    } else {
        JButton btn = (JButton) ae.getSource();
        JPanel panel = (JPanel) btn.getParent();
        String name = ((JTextField) panel.getComponent(2)).getText();

        String weaponType = (String) (((JComboBox) panel.getComponent(4)).getSelectedItem());
        String attackRnge = ((JTextField) panel.getComponent(6)).getText();
        String attackPts = ((JTextField) panel.getComponent(8)).getText();
        //            JLabel message = ((JLabel) this.getComponent(5));
        validationMess.setText("");
        validationMess.setVisible(false);
        if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(weaponType)
                && StringUtils.isNotBlank(attackRnge) && StringUtils.isNotBlank(attackPts)) {
            validationMess.setVisible(false);
            Weapon weapon = new Weapon();
            weapon.setName(name);
            ;
            weapon.setAttackRange(Integer.parseInt(attackRnge));
            weapon.setAttackPts(Integer.parseInt(attackPts));
            weapon.setWeaponType(weaponType);
            boolean weaponAlrdyPresent = false;
            int position = GameUtils.getPositionOfWeaponItem(name);
            if (GameBean.weaponDetails == null) {
                GameBean.weaponDetails = new ArrayList<Item>();
            }
            if (position != -1) {
                GameBean.weaponDetails.remove(position);
            }
            GameBean.weaponDetails.add(weapon);
            try {
                GameUtils.writeItemsToXML(GameBean.weaponDetails, Configuration.PATH_FOR_WEAPONS);
                validationMess.setText("Saved Successfully..");
                validationMess.setVisible(true);
                if (!weaponAlrdyPresent) {
                    comboBox.removeActionListener(this);
                    comboBox.addItem(name);
                    comboBox.setSelectedItem(name);
                    comboBox.addActionListener(this);
                }
                TileInformation tileInfo = GameBean.mapInfo.getPathMap().get(location);
                if (tileInfo == null) {
                    tileInfo = new TileInformation();
                }
                tileInfo.setWeapon(weapon);
                GameBean.mapInfo.getPathMap().put(location, tileInfo);
                chkBox.setSelected(true);
                this.revalidate();
                return;
            } catch (Exception e) {
                System.out.println("WeaponEditorPanel : actionPerformed() : Some error occured " + e);
            }

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

From source file:edu.ucla.stat.SOCR.applications.demo.StockApplication.java

public void actionPerformed(ActionEvent evt) {

    if (evt.getSource() instanceof JComboBox) {
        JComboBox JCB = (JComboBox) evt.getSource();
        String JCB_Value = (String) JCB.getSelectedItem();
        choice = JCB_Value.substring(0, JCB_Value.indexOf(":"));
        setupInput(choice);//from w  w w.ja v a  2 s  .  com
        updateGraph();
        chartPanel.validate();
        inputPanel.validate();
    }
    for (int i = 0; i < numInput; i++)
        if (evt.getActionCommand().equals("Input" + (i + 1))) {
            input[i] = Double.parseDouble(in[i].getText());
            updateGraph();
            chartPanel.validate();
        }

    this.getMainPanel().validate();
}

From source file:edu.purdue.cc.bionet.ui.DistributionAnalysisDisplayPanel.java

/**
 * The actionPerformed method of the ActionListener interface.
 * //from   w w  w  . j  a va2s.  c  o m
 * @see ActionListener#actionPerformed( ActionEvent )
 * @param e The event which triggered this action.
 */
public void actionPerformed(ActionEvent e) {
    Logger logger = Logger.getLogger(getClass());
    Language language = Settings.getLanguage();
    Object source = e.getSource();
    if (source == this.chooseSampleGroupsMenuItem) {
        // Choose sample groups.
        Component frame = this;
        while (!(frame instanceof Frame) && frame != null) {
            frame = frame.getParent();
        }
        Collection<SampleGroup> groups = SampleGroupDialog.showInputDialog((Frame) frame,
                Settings.getLanguage().get("Choose groups"), this.samples);
        if (groups != null) {

            if (this.getSampleGroups() != null) {
                for (SampleGroup group : this.getSampleGroups()) {
                    logger.debug(group.toString());
                    for (Sample sample : group) {
                        logger.debug("\t" + sample.toString());
                    }
                }
            }
            this.setSampleGroups(groups);
        }
    } else if (source == this.removeSampleGroupsMenuItem) {
        Collection<SampleGroup> groups = new ArrayList<SampleGroup>();
        groups.add(new SampleGroup("", this.samples));
        this.setSampleGroups(groups);
    } else if (source == this.hideOutliersViewMenuItem) {
        this.deselectOutliers();
    }
}

From source file:geovista.network.gui.NodeLinkView.java

@Override
public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub

    AbstractButton source = (AbstractButton) e.getSource();

    if (source == v_small) {
        show_vertex.filterSmall(source.isSelected());
    } else if (source == e_labels) {
        if (source.isSelected()) {
            vv.getRenderContext().setEdgeLabelTransformer(edge_label);
        } else {/*ww w.  j  a v  a 2s.com*/
            vv.getRenderContext().setEdgeLabelTransformer(es_none);
        }
    }
    /*
     * if (source == v_shape) { vssa.useFunnyShapes(source.isSelected()); }
     * else
     */// if (source == v_size)
    {
        // vssa.setScaling(source.isSelected());
    }
    /*
     * else if (source == v_aspect) {
     * vssa.setStretching(source.isSelected()); }
     */
    vv.repaint();

}

From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java

/**
 * Creates the proper UI component for the Mapping item.
 * @param dbFieldType the field type/*from  w ww.  j  av  a 2s  . co m*/
 * @param caption the caption
 * @param fieldName the name of the field
 * @param dataFieldLength the length of the definition for that field
 * @param fieldType the field type
 * @return a UI component for editing
 */
protected JComponent createUIComp(final Class<?> dbFieldTypeArg, final String caption, final String fieldName,
        final Short fieldType, final Short fieldLength, final short columns, final short rows,
        final WorkbenchTemplateMappingItem wbtmi) {
    short uiType = WorkbenchTemplateMappingItem.UNKNOWN;
    //System.out.println(wbtmi.getCaption()+" "+wbtmi.getDataType()+" "+wbtmi.getFieldLength());
    Class<?> dbFieldType = dbFieldTypeArg;
    if (dbFieldType == null) {
        // if we can't find a class for the field (i.e. Genus Species, or other 'fake' fields), we say it's a string
        dbFieldType = String.class;
    }

    JComponent comp;
    Component focusComp;

    // handle dates
    if (dbFieldType.equals(Calendar.class) || dbFieldType.equals(Date.class)) {
        //ValFormattedTextField txt = new ValFormattedTextField("Date"); 
        //txt.setColumns(columns == -1 ? DEFAULT_TEXTFIELD_COLS : columns);
        ValTextField txt = new ValTextField(columns);
        txt.getDocument().addDocumentListener(docListener);
        comp = txt;
        focusComp = comp;
        uiType = WorkbenchTemplateMappingItem.TEXTFIELD_DATE;
    }
    //        else if (dbFieldType.equals(Boolean.class)) // strings
    //        {
    //            ValCheckBox checkBox = new ValCheckBox(caption, false, false);
    //            checkBox.addChangeListener(changeListener);
    //            comp      = checkBox;
    //            focusComp = comp;
    //            uiType = WorkbenchTemplateMappingItem.CHECKBOX;
    //        }
    else if (useComboBox(wbtmi)) {
        //ValComboBox comboBox = new ValComboBox(getValues(wbtmi), true);

        final JComboBox comboBox = new JComboBox(getValues(wbtmi));
        comboBox.setName("Form Combo");
        comboBox.setEditable(true);
        comboBox.addActionListener(new ActionListener() {

            /* (non-Javadoc)
             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
             */
            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (arg0.getSource() == comboBox) {
                    //System.out.println("ComboBox Action!" + ((JComboBox )arg0.getSource()).getName());
                    stateChange();
                }
            }

        });
        //           comboBox.getEditor().getEditorComponent().addFocusListener(new FocusListener() {
        //
        //            /* (non-Javadoc)
        //             * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
        //             */
        //            @Override
        //            public void focusGained(FocusEvent arg0) {
        //               System.out.println("FOCUS GAINED");
        //               
        //            }
        //
        //            /* (non-Javadoc)
        //             * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
        //             */
        //            @Override
        //            public void focusLost(FocusEvent arg0) {
        //               System.out.println("FOCUS LOST");
        //               
        //            }
        //              
        //           });
        comp = comboBox;
        focusComp = comp;
        uiType = WorkbenchTemplateMappingItem.COMBOBOX;
    } else if (useTextField(fieldName, fieldType, fieldLength)) {
        ValTextField txt = new ValTextField(columns);
        txt.getDocument().addDocumentListener(docListener);
        txt.setInputVerifier(new LengthInputVerifier(caption, fieldLength));
        comp = txt;
        focusComp = comp;
        uiType = WorkbenchTemplateMappingItem.TEXTFIELD;

    } else {
        JScrollPane taScrollPane = createTextArea(columns, rows);
        ((JTextArea) taScrollPane.getViewport().getView())
                .setInputVerifier(new LengthInputVerifier(caption, fieldLength));
        comp = taScrollPane;
        focusComp = taScrollPane.getViewport().getView();
        uiType = WorkbenchTemplateMappingItem.TEXTAREA;
    }

    wbtmi.setFieldType(uiType);

    focusComp.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            selectControl(e.getSource());
        }

        public void focusLost(FocusEvent e) {
            //stateChange();
        }
    });

    comp.setEnabled(!readOnly);
    focusComp.setEnabled(!readOnly);

    comp.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!readOnly) {
                if ((e.isControlDown() || e.isMetaDown()) && e.getKeyCode() == KeyEvent.VK_N) {
                    workbenchPane.addRowAfter();
                }
            }
            super.keyTyped(e);
        }

    });
    return comp;
}

From source file:com.openbravo.pos.sales.restaurant.JTicketsBagRestaurantRes.java

private void jButtonPlacesAddActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed

    try {//from www  . j  a v a2 s  .c  o m
        Date start = (Date) Formats.TIMESTAMPSHORT.parseValue(m_jFromDate.getText());
        Date end = (Date) Formats.TIMESTAMPSHORT.parseValue(m_jTillDate.getText());
        List<PlaceSplit> placesAvailable;
        placesAvailable = dlCustomers.getAvailablePlaces(start, end);
        placesAvailable.removeAll(placesReservation);

        JPlacesListDialog dialog = JPlacesListDialog.newJDialog(m_App, (JButton) evt.getSource());
        PlaceSplit place2Add = dialog.showPlacesList(placesAvailable);

        if (place2Add != null && !placesReservation.contains(place2Add)) {
            placesReservation.add(place2Add);
            RefreshPlaces();
            m_Dirty.setDirty(true);
        }

    } catch (BasicException e) {
        JConfirmDialog.showInformation(m_App, JTicketsBagRestaurantRes.this,
                AppLocal.getIntString("error.information"), AppLocal.getIntString("message.checkinput"));
    }

}

From source file:com.alvermont.terraj.fracplanet.ui.AbstractTerrainViewerFrame.java

private void showCameraDialogCheckboxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_showCameraDialogCheckboxActionPerformed
{//GEN-HEADEREND:event_showCameraDialogCheckboxActionPerformed

    final JCheckBoxMenuItem box = (JCheckBoxMenuItem) evt.getSource();

    this.cameraPosDialog.setVisible(box.isSelected());
}

From source file:com.alvermont.terraj.fracplanet.ui.AbstractTerrainViewerFrame.java

private void showControlsHelpCheckboxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_showControlsHelpCheckboxActionPerformed
{//GEN-HEADEREND:event_showControlsHelpCheckboxActionPerformed

    final JCheckBoxMenuItem box = (JCheckBoxMenuItem) evt.getSource();

    if (this.controlsHelpDialog == null) {
        this.controlsHelpDialog = new ControlsHelpDialog(this, false);
        this.controlsHelpDialog.addWindowListener(new MyWindowAdapter(showControlsHelpCheckbox));
    }//from ww  w .  java 2s.co  m

    this.controlsHelpDialog.setVisible(box.isSelected());
}

From source file:gdsc.smlm.ij.plugins.SpotAnalysis.java

public synchronized void actionPerformed(ActionEvent e) {
    Object actioner = e.getSource();

    if (actioner == null || runMode > 0)
        return;//from   w ww  . j  a v a 2  s  . co m

    synchronized (runLock) {
        if (runMode > 0)
            return;

        if (((Button) actioner == profileButton) && (parametersReady())) {
            runMode = 1;
        } else if ((Button) actioner == addButton) {
            runMode = 2;
        } else if ((Button) actioner == deleteButton) {
            runMode = 3;
        } else if ((Button) actioner == saveButton) {
            runMode = 4;
        } else if ((Button) actioner == saveTracesButton) {
            runMode = 5;
        }
    }

    if (runMode > 0) {
        Thread thread = new Thread(this, TITLE);
        thread.start();
    }
    super.notify();
}