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:pwr.lab5.Window.java

@Override
public void actionPerformed(ActionEvent e) {
    String str = e.getSource().toString();
    Matcher m = Pattern.compile("text=.*?(\\d+)").matcher(str);
    m.find();/* ww w  .  jav  a2 s . co  m*/
    System.out.println(str);
    int id = Integer.parseInt(m.group(1));
    System.out.println(id);
    //        String backup=System.getProperty("user.dir");
    //        String progDir = (new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath())).getAbsolutePath();
    //        try{
    //            System.setProperty("user.dir", progDir);
    //            File f=new File("./chess.xml");
    //            if(!f.exists()) 
    //                throw new FileNotFoundException("could not find chess.xml");
    //        } catch (Exception ex) {
    //            System.setProperty("user.dir", backup);
    //        }
    try {
        if (id == 1)
            new Task1();
        if (id == 2)
            new Task2();
        if (id == 3)
            new Task3();
        if (id == 4) {
            new Task4(new Task4.CallbbackNewMeasure() {

                @Override
                public void newMeasure(int n, long dom, long sax, long stax) {
                    series[0].add(n, dom);
                    series[1].add(n, sax);
                    series[2].add(n, stax);
                }
            });
            showChart(this);
        }
    } catch (Throwable ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + "\nCWD: " + System.getProperty("user.dir")
                + "\nIn case of problems with accessing files, try running from console: java -jar *.jar");
        throw new RuntimeException(ex);
    }
}

From source file:cl.almejo.vsim.gui.actions.preferences.ColorPreferences.java

private void addColorChooser(JPanel panel, final String item) {
    JLabel label = new JLabel();
    label.setText(Messages.t("preferences.color.scheme." + item + ".label"));
    panel.add(label);//from w w  w. j  av a  2  s . com
    JButton button = new JButton(Messages.t("default.change.label"));
    ActionListener actionListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JButton button = (JButton) e.getSource();
            String themeName = ColorScheme.getCurrent().getName();
            Color color = JColorChooser.showDialog(button, Messages.t("preferences.color.choose.title"),
                    ColorScheme.getScheme(themeName).get(item));
            if (color != null) {
                ColorScheme.getScheme(themeName).set(item, color);
            }
        }
    };

    button.addActionListener(actionListener);
    panel.add(button);
}

From source file:org.altusmetrum.altosuilib_2.AltosUIEnable.java

public void add_units() {
    /* Imperial units setting */

    /* Add label */
    JRadioButton imperial_units = new JRadioButton("Imperial Units", AltosUIPreferences.imperial_units());
    imperial_units.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JRadioButton item = (JRadioButton) e.getSource();
            boolean enabled = item.isSelected();
            AltosUIPreferences.set_imperial_units(enabled);
        }// ww  w  .j  a  v a2s.  c o  m
    });
    imperial_units.setToolTipText("Use Imperial units instead of metric");
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 1000;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = il;
    add(imperial_units, c);
}

From source file:PRC6.Graficos.java

@Override
public void actionPerformed(ActionEvent e) {

    Object fuente = e.getSource();

    if (fuente == das.getPlace())
        JOptionPane.showMessageDialog(null, "Cambio registrado en el Sitio");
    else if (fuente == das.getYear())
        JOptionPane.showMessageDialog(null, "Cambio registrado en el Ao");
    else if (fuente == das.getjComboBox1())
        JOptionPane.showMessageDialog(null, "Cambio registrado en el Grafico");

    int n = Integer.parseInt(das.getYear().getSelectedItem().toString());
    int ini = das.get_pos(n);

    if (das.getjComboBox1().getSelectedIndex() == 0)
        das.graph.PieGraphF(das.getDataset().getTmax(), ini, das.getjComboBox1().getSelectedItem().toString(),
                das.getYear().getSelectedItem().toString(), das.getjPanel2(),
                das.getPlace().getSelectedItem().toString());
    else if (das.getjComboBox1().getSelectedIndex() == 1)
        das.graph.PieGraphF(das.getDataset().getTmin(), ini, das.getjComboBox1().getSelectedItem().toString(),
                das.getYear().getSelectedItem().toString(), das.getjPanel2(),
                das.getPlace().getSelectedItem().toString());
    else if (das.getjComboBox1().getSelectedIndex() == 2)
        das.graph.PieGraphI(das.getDataset().getAfdays(), ini, das.getjComboBox1().getSelectedItem().toString(),
                das.getYear().getSelectedItem().toString(), das.getjPanel2(),
                das.getPlace().getSelectedItem().toString());
    else if (das.getjComboBox1().getSelectedIndex() == 3)
        das.graph.PieGraphF(das.getDataset().getRain(), ini, das.getjComboBox1().getSelectedItem().toString(),
                das.getYear().getSelectedItem().toString(), das.getjPanel2(),
                das.getPlace().getSelectedItem().toString());
    else if (das.getjComboBox1().getSelectedIndex() == 4)
        das.graph.PieGraphF(das.getDataset().getSun(), ini, das.getjComboBox1().getSelectedItem().toString(),
                das.getYear().getSelectedItem().toString(), das.getjPanel2(),
                das.getPlace().getSelectedItem().toString());

}

From source file:MainClass.java

public MainClass() {
    Container cp = new Box(BoxLayout.X_AXIS);
    setContentPane(cp);//from w  w  w .j a  va  2s.com
    JPanel firstPanel = new JPanel();
    propertyComboBox = new JComboBox();
    propertyComboBox.addItem("text");
    propertyComboBox.addItem("font");
    propertyComboBox.addItem("background");
    propertyComboBox.addItem("foreground");
    firstPanel.add(propertyComboBox);
    cp.add(firstPanel);
    cp.add(Box.createGlue());

    tf = new JTextField("Hello");
    tf.setForeground(Color.RED);
    tf.setDragEnabled(true);
    cp.add(tf);

    cp.add(Box.createGlue());

    l = new JLabel("Hello");
    l.setBackground(Color.YELLOW);
    cp.add(l);

    cp.add(Box.createGlue());

    JSlider stryder = new JSlider(SwingConstants.VERTICAL);
    stryder.setMinimum(10);
    stryder.setValue(14);
    stryder.setMaximum(72);
    stryder.setMajorTickSpacing(10);
    stryder.setPaintTicks(true);

    cp.add(stryder);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(500, 300);

    setMyTransferHandlers((String) propertyComboBox.getSelectedItem());

    MouseListener myDragListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            handler.exportAsDrag(c, e, TransferHandler.COPY);
        }
    };
    l.addMouseListener(myDragListener);

    propertyComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ce) {
            JComboBox bx = (JComboBox) ce.getSource();
            String prop = (String) bx.getSelectedItem();
            setMyTransferHandlers(prop);
        }
    });

    tf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            JTextField jtf = (JTextField) evt.getSource();
            String fontName = jtf.getText();
            Font font = new Font(fontName, Font.BOLD, 18);
            tf.setFont(font);
        }
    });

    stryder.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            JSlider sl = (JSlider) evt.getSource();
            Font oldf = tf.getFont();
            Font newf = oldf.deriveFont((float) sl.getValue());
            tf.setFont(newf);
        }
    });
}

From source file:guineu.modules.visualization.intensityboxplot.IntensityBoxPlotToolBar.java

public void actionPerformed(ActionEvent e) {

    Object src = e.getSource();

    if (src == linesVisibleButton) {

        Plot plot = frame.getChart().getPlot();

        Boolean linesVisible;/*  w  w w  .j  a v  a2s. c om*/

        if (plot instanceof CategoryPlot) {
            LineAndShapeRenderer renderer = (LineAndShapeRenderer) ((CategoryPlot) plot).getRenderer();
            linesVisible = renderer.getBaseLinesVisible();
        } else {
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) ((XYPlot) plot).getRenderer();
            linesVisible = renderer.getBaseLinesVisible();
        }

        // check for null value
        if (linesVisible == null)
            linesVisible = false;

        // update the icon
        if (linesVisible) {
            linesVisibleButton.setIcon(linesIcon);
        } else {
            linesVisibleButton.setIcon(pointsIcon);
        }

        // switch the button
        linesVisible = !linesVisible;

        if (plot instanceof CategoryPlot) {
            LineAndShapeRenderer renderer = (LineAndShapeRenderer) ((CategoryPlot) plot).getRenderer();
            renderer.setBaseLinesVisible(linesVisible);
        } else {
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) ((XYPlot) plot).getRenderer();
            renderer.setBaseLinesVisible(linesVisible);
        }

    }

    if (src == setupAxesButton) {
        AxesSetupDialog dialog = new AxesSetupDialog(frame.getChart().getXYPlot());
        dialog.setVisible(true);
    }

}

From source file:components.FileChooserDemo.java

public void actionPerformed(ActionEvent e) {

    //Handle open button action.
    if (e.getSource() == openButton) {
        int returnVal = fc.showOpenDialog(FileChooserDemo.this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            //This is where a real application would open the file.
            log.append("Opening: " + file.getName() + "." + newline);
        } else {/*w  w  w .jav a2  s  .c  om*/
            log.append("Open command cancelled by user." + newline);
        }
        log.setCaretPosition(log.getDocument().getLength());

        //Handle save button action.
    } else if (e.getSource() == saveButton) {
        int returnVal = fc.showSaveDialog(FileChooserDemo.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            //This is where a real application would save the file.
            log.append("Saving: " + file.getName() + "." + newline);
        } else {
            log.append("Save command cancelled by user." + newline);
        }
        log.setCaretPosition(log.getDocument().getLength());
    }
}

From source file:org.csml.tommo.sugar.modules.heatmap.InteractiveHeatmapDialog.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == prevButton) {
        prevCycle();//from  w w w.  j  a  v  a  2 s  .  c om
    }
    if (e.getSource() == nextButton) {
        nextCycle();
    } else if (e.getSource() == animationButton) {
        if (timer.isRunning()) {
            timer.stop();
            animationButton.setText("Start Animation");
        } else {
            timer.start();
            animationButton.setText("Stop Animation");
        }
    } else if (e.getSource() == timer) {
        nextCycle();
    }
}

From source file:com.haulmont.cuba.desktop.sys.WindowBreadCrumbs.java

public void update() {
    removeAll();// w  ww.  j  av a  2  s  .c o m
    btn2win.clear();
    for (Iterator<Window> it = windows.iterator(); it.hasNext();) {
        Window window = it.next();
        JButton button = new JXHyperlink();
        button.setFocusable(false);
        button.setText(StringUtils.trimToEmpty(window.getCaption()));
        button.addActionListener(new ValidationAwareActionListener() {
            @Override
            public void actionPerformedAfterValidation(ActionEvent e) {
                JButton btn = (JButton) e.getSource();
                Window win = btn2win.get(btn);
                if (win != null) {
                    fireListeners(win);
                }
            }
        });

        btn2win.put(button, window);

        if (it.hasNext()) {
            add(button);
            JLabel separatorLab = new JLabel(">");
            add(separatorLab);
        } else {
            add(new JLabel(window.getCaption()));
        }
    }
}

From source file:ColorChooserMenu.java

protected JMenuBar createMenuBar() {
    final JMenuBar menuBar = new JMenuBar();

    ColorMenu cm = new ColorMenu("Foreground");
    cm.setMnemonic('f');
    ActionListener lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ColorMenu m = (ColorMenu) e.getSource();
            System.out.println(m.getColor());
        }/*from w w w  .  ja v  a 2  s .  co  m*/
    };
    cm.addActionListener(lst);
    menuBar.add(cm);

    return menuBar;
}