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:edu.ku.brc.specify.plugins.latlon.LatLonUI.java

/**
 * Creates the UI.//from  ww  w  .  ja  v a2s.  co  m
 * @param localityCEP the locality object (can be null)
 */
protected void createEditUI() {
    loadAndPushResourceBundle("specify_plugins");

    PanelBuilder builder = new PanelBuilder(new FormLayout("p", "p, 2px, p"), this);

    Color bgColor = getBackground();
    bgColor = new Color(Math.min(bgColor.getRed() + 20, 255), Math.min(bgColor.getGreen() + 20, 255),
            Math.min(bgColor.getBlue() + 20, 255));
    //System.out.println(bgColor);
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(bgColor),
            BorderFactory.createEmptyBorder(4, 4, 4, 4)));

    for (int i = 0; i < types.length; i++) {
        typeMapper.put(types[i], typeStrs[i]);
    }

    currentType = LatLonUIIFace.LatLonType.LLPoint;

    pointImages = new ImageIcon[pointNames.length];
    for (int i = 0; i < pointNames.length; i++) {
        pointImages[i] = IconManager.getIcon(pointNames[i], IconManager.IconSize.Std16);
    }

    String[] formatLabels = new String[formats.length];
    for (int i = 0; i < formats.length; i++) {
        formatLabels[i] = getResourceString(formats[i]);
    }
    cardPanel = new JPanel(cardLayout);
    formatSelector = createComboBox(formatLabels);
    latLonPanes = new JComponent[formatLabels.length];

    formatSelector.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            swapForm(formatSelector.getSelectedIndex(), currentType);

            cardLayout.show(cardPanel, ((JComboBox) ae.getSource()).getSelectedItem().toString());

            //stateChanged(null);
        }
    });

    Dimension preferredSize = new Dimension(0, 0);
    cardSubPanes = new JPanel[formats.length * 2];
    panels = new DDDDPanel[formats.length * 2];
    int paneInx = 0;
    for (int i = 0; i < formats.length; i++) {
        cardSubPanes[i] = new JPanel(new BorderLayout());
        try {
            String packageName = "edu.ku.brc.specify.plugins.latlon.";
            DDDDPanel latLon1 = Class.forName(packageName + formatClass[i]).asSubclass(DDDDPanel.class)
                    .newInstance();
            latLon1.setIsRequired(isRequired);
            latLon1.setViewMode(isViewMode);
            latLon1.init();
            latLon1.setChangeListener(this);

            JPanel panel1 = latLon1;
            panel1.setBorder(panelBorder);
            panels[paneInx++] = latLon1;
            latLonPanes[i] = panel1;

            DDDDPanel latlon2 = Class.forName(packageName + formatClass[i]).asSubclass(DDDDPanel.class)
                    .newInstance();
            latlon2.setIsRequired(isRequired);
            latlon2.setViewMode(isViewMode);
            latlon2.init();
            latlon2.setChangeListener(this);

            panels[paneInx++] = latlon2;

            JTabbedPane tabbedPane = new JTabbedPane(
                    UIHelper.getOSType() == UIHelper.OSTYPE.MacOSX ? SwingConstants.BOTTOM
                            : SwingConstants.RIGHT);
            tabbedPane.addTab(null, pointImages[0], panels[paneInx - 2]);
            tabbedPane.addTab(null, pointImages[0], panels[paneInx - 1]);
            latLonPanes[i] = tabbedPane;

            Dimension size = tabbedPane.getPreferredSize();
            preferredSize.width = Math.max(preferredSize.width, size.width);
            preferredSize.height = Math.max(preferredSize.height, size.height);

            tabbedPane.removeAll();
            cardSubPanes[i].add(panel1, BorderLayout.CENTER);
            cardPanel.add(formatLabels[i], cardSubPanes[i]);

            /*if (locality != null)
            {
            latLon1.set(locality.getLatitude1(), locality.getLongitude1(), locality.getLat1text(), locality.getLong1text());
            latlon2.set(locality.getLatitude2(), locality.getLongitude2(), locality.getLat2text(), locality.getLong2text());
            }*/

        } catch (Exception e) {
            e.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(LatLonUI.class, e);
        }
    }

    // Makes they are all the same size
    for (int i = 0; i < formats.length; i++) {
        cardSubPanes[i].setPreferredSize(preferredSize);
    }

    //final LatLonPanel thisPanel = this;

    PanelBuilder botBtnBar = new PanelBuilder(new FormLayout("p:g,p,10px,p,10px,p,p:g", "p"));

    ButtonGroup btnGroup = new ButtonGroup();
    botBtns = new JToggleButton[typeNames.length];

    if (UIHelper.isMacOS()) {
        /*for (int i=0;i<botBtns.length;i++)
        {
        ImageIcon selIcon   = IconManager.getIcon(typeNames[i]+"Sel", IconManager.IconSize.Std16);
        ImageIcon unselIcon = IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16);
                
        MacIconRadioButton rb = new MacIconRadioButton(selIcon, unselIcon);
        botBtns[i] = rb;
        rb.setBorder(new MacBtnBorder());
                
        Dimension size = rb.getPreferredSize();
        int max = Math.max(size.width, size.height);
        size.setSize(max, max);
        rb.setPreferredSize(size);
        }*/

        BorderedRadioButton.setSelectedBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
        BorderedRadioButton.setUnselectedBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        for (int i = 0; i < botBtns.length; i++) {
            BorderedRadioButton rb = new BorderedRadioButton(
                    IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16));
            botBtns[i] = rb;
            rb.makeSquare();
            rb.setBorder(new MacBtnBorder());
        }
    } else {
        BorderedRadioButton.setSelectedBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
        BorderedRadioButton.setUnselectedBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        for (int i = 0; i < botBtns.length; i++) {
            BorderedRadioButton rb = new BorderedRadioButton(
                    IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16));
            botBtns[i] = rb;
            rb.makeSquare();
        }
    }

    for (int i = 0; i < botBtns.length; i++) {
        botBtns[i].setToolTipText(typeToolTips[i]);
        botBtnBar.add(botBtns[i], cc.xy((i * 2) + 2, 1));
        btnGroup.add(botBtns[i]);
        selectedTypeHash.put(botBtns[i], types[i]);

        botBtns[i].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ce) {
                stateChanged(null);
                currentType = selectedTypeHash.get(ce.getSource());
                swapForm(formatSelector.getSelectedIndex(), currentType);
            }
        });
    }
    botBtns[0].setSelected(true);

    if (isViewMode) {
        typeLabel = createLabel(" ");
    }

    ActionListener infoAL = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doPrefs();
        }
    };

    JButton infoBtn = UIHelper.createIconBtn("Preferences", IconManager.IconSize.Std16,
            getResourceString("PREFERENCES"), true, infoAL);
    infoBtn.setEnabled(true);

    PanelBuilder topPane = new PanelBuilder(
            new FormLayout("l:p, c:p:g" + (isViewMode ? "" : ",4px,p,8px"), "p"));
    topPane.add(formatSelector, cc.xy(1, 1));
    topPane.add(isViewMode ? typeLabel : botBtnBar.getPanel(), cc.xy(2, 1));
    if (!isViewMode)
        topPane.add(infoBtn, cc.xy(4, 1));

    builder.add(topPane.getPanel(), cc.xy(1, 1));
    builder.add(cardPanel, cc.xy(1, 3));

    prefsPanel = new PrefsPanel(false);
    prefsPanel.add(getResourceString("LatLonUI.LL_SEP"));
    prefsPanel.add(CompType.eCheckbox, getResourceString("LatLonUI.LATDEF_DIR"), LAT_PREF, Boolean.class, true);
    prefsPanel.add(CompType.eCheckbox, getResourceString("LatLonUI.LONDEF_DIR"), LON_PREF, Boolean.class, true);
    prefsPanel.add(CompType.eComboBox, getResourceString("LatLonUI.DEF_TYP"), TYP_PREF, Integer.class,
            typeNamesLabels, 0);
    prefsPanel.add(CompType.eComboBox, getResourceString("LatLonUI.DEF_FMT"), FMT_PREF, Integer.class,
            formatLabels, 0);
    prefsPanel.createForm(null, null);

    popResourceBundle();
}

From source file:com.sshtools.powervnc.PowerVNCPanel.java

public void actionPerformed(ActionEvent evt) {

    if (evt.getSource() == receiveTimer) {

        statusBar.setReceiving(false);//from   w  w  w .  ja  v  a  2  s .  c  o  m

    }

    else if (evt.getSource() == sendTimer) {

        statusBar.setSending(false);

    }

    if (sessionActions.containsKey(evt.getActionCommand())) {
        SessionProviderAction action = (SessionProviderAction) sessionActions.get(evt.getActionCommand());
        SessionProviderFrame frame;
        // Do we have an existing frame?
        for (Iterator it = sessionFrames.iterator(); it.hasNext();) {
            frame = (SessionProviderFrame) it.next();
            if (action.getProvider().getProviderClass().isInstance(frame)) {
                frame.show();
                return;
            }
        }

        try {
            frame = new SessionProviderFrame(getCurrentConnectionProfile(), ssh, action.getProvider());
            if (frame.initFrame(getApplication())) {
                frame.show();
                sessionFrames.add(frame);
            }

        } catch (Throwable ex) {
        }
    }

}

From source file:com.vgi.mafscaling.ClosedLoop.java

@Override
public void actionPerformed(ActionEvent e) {
    if (checkActionPerformed(e))
        return;/*from  w ww .ja  va  2s . c o  m*/
    if ("dvdt".equals(e.getActionCommand())) {
        JCheckBox checkBox = (JCheckBox) e.getSource();
        if (checkBox.isSelected()) {
            clearNotRunDataCheckboxes();
            clearRunDataCheckboxes();
            if (plotDvdtData())
                checkBox.setSelected(true);
        } else
            runData.clear();
        setRanges();
    } else if ("iat".equals(e.getActionCommand())) {
        JCheckBox checkBox = (JCheckBox) e.getSource();
        if (checkBox.isSelected()) {
            clearNotRunDataCheckboxes();
            clearRunDataCheckboxes();
            if (plotIatData())
                checkBox.setSelected(true);
        } else
            runData.clear();
        setRanges();
    } else if ("trpm".equals(e.getActionCommand())) {
        JCheckBox checkBox = (JCheckBox) e.getSource();
        if (checkBox.isSelected()) {
            clearNotRunDataCheckboxes();
            clearRunDataCheckboxes();
            if (plotTrimRpmData())
                checkBox.setSelected(true);
        } else {
            runData.clear();
            currMafData.clear();
        }
        setRanges();
    } else if ("mnmd".equals(e.getActionCommand())) {
        JCheckBox checkBox = (JCheckBox) e.getSource();
        if (checkBox.isSelected()) {
            clearNotRunDataCheckboxes();
            clearRunDataCheckboxes();
            if (plotMeanModeData())
                checkBox.setSelected(true);
        } else {
            currMafData.clear();
            corrMafData.clear();
            runData.clear();
        }
        setRanges();
    } else if ("corrdata".equals(e.getActionCommand())) {
        JCheckBox checkBox = (JCheckBox) e.getSource();
        if (checkBox.isSelected()) {
            clearRunDataCheckboxes();
            if (!plotCorrectionData())
                checkBox.setSelected(false);
        } else
            runData.clear();
        setRanges();
    } else if ("current".equals(e.getActionCommand())) {
        JCheckBox checkBox = (JCheckBox) e.getSource();
        if (checkBox.isSelected()) {
            clearRunDataCheckboxes();
            if (!plotCurrentMafData())
                checkBox.setSelected(false);
        } else
            currMafData.clear();
        setRanges();
    } else if ("corrected".equals(e.getActionCommand())) {
        JCheckBox checkBox = (JCheckBox) e.getSource();
        if (checkBox.isSelected()) {
            clearRunDataCheckboxes();
            if (!setCorrectedMafData())
                checkBox.setSelected(false);
        } else
            corrMafData.clear();
        setRanges();
    } else if ("smoothed".equals(e.getActionCommand())) {
        JCheckBox checkBox = (JCheckBox) e.getSource();
        if (checkBox.isSelected()) {
            clearRunDataCheckboxes();
            if (!setSmoothedMafData())
                checkBox.setSelected(false);
        } else
            smoothMafData.clear();
        setRanges();
    } else if ("smoothing".equals(e.getActionCommand())) {
        JCheckBox checkBox = (JCheckBox) e.getSource();
        if (checkBox.isSelected())
            enableSmoothingView(true);
        else
            enableSmoothingView(false);
        setRanges();
    }
}

From source file:com.vgi.mafscaling.LogView.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == loadButton)
        loadLogFile();//from   w ww.j  a v  a 2 s.  co m
    else if (e.getSource() == printButton)
        logDataTable.print(new PrintProperties());
    else if (e.getSource() == previewButton)
        logDataTable.printPreview(new PrintProperties());
    else if (e.getSource() == findButton) {
        if (findWindow != null)
            findWindow.dispose();
        findWindow = new DBTFindFrame(SwingUtilities.windowForComponent(this), logDataTable, true);
    } else if (e.getSource() == replaceButton) {
        if (findWindow != null)
            findWindow.dispose();
        findWindow = new DBTFindFrame(SwingUtilities.windowForComponent(this), logDataTable, false);
    } else if (e.getSource() == filterButton) {
        String filterString = filterText.getText();
        if (filterString != null && !"".equals(filterString)) {
            try {
                CompareFilter filter = new CompareFilter();
                filter.setCondition(CompareFilter.Condition.EQUAL);
                if (compareCombo.getSelectedItem().toString().equals(">"))
                    filter.setCondition(CompareFilter.Condition.GREATER);
                if (compareCombo.getSelectedItem().toString().equals(">="))
                    filter.setCondition(CompareFilter.Condition.GREATER_EQUAL);
                else if (compareCombo.getSelectedItem().toString().equals("<"))
                    filter.setCondition(CompareFilter.Condition.LESS);
                else if (compareCombo.getSelectedItem().toString().equals("<="))
                    filter.setCondition(CompareFilter.Condition.LESS_EQUAL);
                filter.setFilter(filterText.getText());
                filter.setColumn(selectionCombo.getSelectedIndex());
                logDataTable.filter(filter);
                updateChart();
            } catch (NumberFormatException ex) {
                JOptionPane.showMessageDialog(null, "Invalid numeric value: " + filterText.getText(),
                        "Invalid value", JOptionPane.ERROR_MESSAGE);
            }
        } else {
            logDataTable.filter(null);
            updateChart();
        }
    } else if (e.getSource() == viewButton) {
        GridBagLayout gbl = (GridBagLayout) logViewPanel.getLayout();
        if (viewButton.getText().startsWith("Headers")) {
            Dimension d = viewButton.getSize();
            viewButton.setMinimumSize(d);
            viewButton.setPreferredSize(d);
            viewButton.setMaximumSize(d);
            gbl.rowWeights = new double[] { 0.0, 1.0 };
            logDataTable.setVisible(false);
            headerScrollPane.setVisible(true);
            viewButton.setText("Grid View");
        } else {
            gbl.rowWeights = new double[] { 1.0, 0.0 };
            logDataTable.setVisible(true);
            headerScrollPane.setVisible(false);
            viewButton.setText("Headers View");
        }
    } else if (e.getSource() == logPlayButton) {
        if (logDataTable.getRowCount() > 1) {
            if (logPlayWindow != null)
                disposeLogView();
            logPlayWindow = new LogPlay(this);
            logPlayButton.setEnabled(false);
        }
    } else if ("view".equals(e.getActionCommand()))
        view3dPlots();
}

From source file:MainClass.EquationSolver.java

@Override
public void actionPerformed(ActionEvent e) {

    this.setVisible(true);
    textArea.setText(null);//command to clear the textArea

    String decString = "0.";//block used to set the decimal point 

    if (decTextField.getText().hashCode() != 0) {
        for (int i = 0; i < (Integer.parseInt(decTextField.getText())); i++) {
            decString += "0";
        }/*ww w. j av  a 2s.c om*/
        decString += "1";
        decpoint = Double.parseDouble(decString);
    } else {
        decTextField.setText("0");
    }

    switch (methodComboBox.getSelectedItem().toString()) {//block used to show or hide the second textField coresponding the mothod selected
    case "Secant":
        sp2TextField.setVisible(true);
        this.setVisible(true);
        break;
    case "Bisection":
        sp2TextField.setVisible(true);
        this.setVisible(true);
        break;
    default:
        sp2TextField.setVisible(false);
        this.setVisible(true);
        break;
    }

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

        try {//Try used to test if the inserted starting point is not a numerical value
            switch (methodComboBox.getSelectedItem().toString()) {//Switch used to implement the limits of the function ploted on the graph accordingly the method selected

            case "Secant":
            case "Bisection":
                if (sp1TextField.getText().hashCode() == 0 || sp2TextField.getText().hashCode() == 0) {
                    JOptionPane.showMessageDialog(null, "Please insert two starting points");
                }
                if (Double.parseDouble(sp2TextField.getText()) > Double.parseDouble(sp1TextField.getText())) {
                    limitx = Math.abs(Double.parseDouble(sp2TextField.getText()));
                    limity = limitx * (-1);
                } else {
                    limitx = Math.abs(Double.parseDouble(sp1TextField.getText()));
                    limity = limitx * (-1);
                }
                break;
            case "Newton-Raphson":
                limitx = Math.abs(Double.parseDouble(sp1TextField.getText()));
                limity = limitx * (-1);
                break;
            case "Select a method:":
                JOptionPane.showMessageDialog(null, "Please select a method!");
                break;
            default:
                limitx = 50;
                limity = -50;
                break;
            }

            if (limitx == 0) {
                limitx = 50;
                limity = -50;
            } else if ("ln(x+1)+1".equals(equationComboBox.getSelectedItem().toString())
                    || "e^x-3x".equals(equationComboBox.getSelectedItem().toString())
                    || "x-x^2".equals(equationComboBox.getSelectedItem().toString())) {
                limitx *= 10;
                limity *= 10;
            }

            if (null != equationComboBox.getSelectedItem().toString()) {//Test if the comboBox was pressed 
                switch (equationComboBox.getSelectedItem().toString()) {//Swith implementing in a global variable a dataset accordingly the function selected
                case "x-x^2":
                    datasetFunction = DatasetUtilities.sampleFunction2D(v -> v - Math.pow(v, 2.0), limity,
                            limitx, 100, "Function x-x^2");
                    break;
                case "ln(x+1)+1":
                    datasetFunction = DatasetUtilities.sampleFunction2D(v -> Math.log(v + 1.0) + 1.0, limity,
                            limitx, 100, "Function ln(x+1)+1");
                    break;
                default:
                    datasetFunction = DatasetUtilities.sampleFunction2D(v -> (Math.exp(v)) - (3 * v), limity,
                            limitx, 100, "Function e^x-3x");
                    break;
                }
            }

            switch (equationComboBox.getSelectedItem().toString()) {// Switch used to verify what function and method was selected
            case "x-x^2":
                if (null != methodComboBox.getSelectedItem().toString()) {
                    switch (methodComboBox.getSelectedItem().toString()) {
                    case "Newton-Raphson":
                        CalculusNewtonRaphson.newtonRaphson1(Double.parseDouble(sp1TextField.getText()),
                                decpoint);
                        refreshTable(CalculusNewtonRaphson.createChartNewtonRapson(datasetFunction));
                        textArea.append(CalculusNewtonRaphson
                                .textDataNewtonRapson(Integer.parseInt(decTextField.getText())));
                        table.setModel(CalculusNewtonRaphson.getTableData());
                        break;
                    case "Secant":
                        CalculusSecant.secant1(Double.parseDouble(sp1TextField.getText()),
                                Double.parseDouble(sp2TextField.getText()), decpoint);
                        refreshTable(CalculusSecant.createChartSecant(datasetFunction));
                        textArea.append(
                                CalculusSecant.textDataSecant(Integer.parseInt(decTextField.getText())));
                        table.setModel(CalculusSecant.getTableData());
                        break;
                    case "Bisection":
                        CalculusBisection.bisection1(Double.parseDouble(sp1TextField.getText()),
                                Double.parseDouble(sp2TextField.getText()), decpoint);
                        refreshTable(CalculusBisection.createChartBisection(datasetFunction));
                        textArea.append(
                                CalculusBisection.textDataBisection(Integer.parseInt(decTextField.getText())));
                        table.setModel(CalculusBisection.getTableData());
                        break;
                    }
                }
                break;
            case "ln(x+1)+1":
                if (null != methodComboBox.getSelectedItem().toString()) {
                    switch (methodComboBox.getSelectedItem().toString()) {
                    case "Newton-Raphson":
                        CalculusNewtonRaphson.newtonRaphson2(Double.parseDouble(sp1TextField.getText()),
                                decpoint);
                        refreshTable(CalculusNewtonRaphson.createChartNewtonRapson(datasetFunction));
                        textArea.append(CalculusNewtonRaphson
                                .textDataNewtonRapson(Integer.parseInt(decTextField.getText())));
                        table.setModel(CalculusNewtonRaphson.getTableData());
                        break;
                    case "Secant":
                        CalculusSecant.secant2(Double.parseDouble(sp1TextField.getText()),
                                Double.parseDouble(sp2TextField.getText()), decpoint);
                        refreshTable(CalculusSecant.createChartSecant(datasetFunction));
                        textArea.append(
                                CalculusSecant.textDataSecant(Integer.parseInt(decTextField.getText())));
                        table.setModel(CalculusSecant.getTableData());
                        break;
                    case "Bisection":
                        CalculusBisection.bisection2(Double.parseDouble(sp1TextField.getText()),
                                Double.parseDouble(sp2TextField.getText()), decpoint);
                        refreshTable(CalculusBisection.createChartBisection(datasetFunction));
                        textArea.append(
                                CalculusBisection.textDataBisection(Integer.parseInt(decTextField.getText())));
                        table.setModel(CalculusBisection.getTableData());
                        break;
                    }
                }
                break;
            case "e^x-3x":
                if (null != methodComboBox.getSelectedItem().toString()) {
                    switch (methodComboBox.getSelectedItem().toString()) {
                    case "Newton-Raphson":
                        CalculusNewtonRaphson.newtonRaphson3(Double.parseDouble(sp1TextField.getText()),
                                decpoint);
                        refreshTable(CalculusNewtonRaphson.createChartNewtonRapson(datasetFunction));
                        textArea.append(CalculusNewtonRaphson
                                .textDataNewtonRapson(Integer.parseInt(decTextField.getText())));
                        table.setModel(CalculusNewtonRaphson.getTableData());
                        break;
                    case "Secant":
                        CalculusSecant.secant3(Double.parseDouble(sp1TextField.getText()),
                                Double.parseDouble(sp2TextField.getText()), decpoint);
                        refreshTable(CalculusSecant.createChartSecant(datasetFunction));
                        textArea.append(
                                CalculusSecant.textDataSecant(Integer.parseInt(decTextField.getText())));
                        table.setModel(CalculusSecant.getTableData());
                        break;
                    case "Bisection":
                        CalculusBisection.bisection3(Double.parseDouble(sp1TextField.getText()),
                                Double.parseDouble(sp2TextField.getText()), decpoint);
                        refreshTable(CalculusBisection.createChartBisection(datasetFunction));
                        textArea.append(
                                CalculusBisection.textDataBisection(Integer.parseInt(decTextField.getText())));
                        table.setModel(CalculusBisection.getTableData());
                        break;
                    }
                }
                break;
            }
        } catch (Exception x) {
            JOptionPane.showMessageDialog(null, "Please insert a numerical value!");
        }
    }
}

From source file:EnvironmentExplorer.java

Box lightPanel() {
    Box panel = new Box(BoxLayout.Y_AXIS);

    // add the ambient light checkbox to the panel
    JCheckBox ambientCheckBox = new JCheckBox("Ambient Light");
    ambientCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JCheckBox checkbox = (JCheckBox) e.getSource();
            lightAmbient.setEnable(checkbox.isSelected());
        }// w w w . j  a  v  a2 s .  com
    });
    ambientCheckBox.setSelected(true);
    panel.add(new LeftAlignComponent(ambientCheckBox));

    String[] lightTypeValues = { "None", "Directional", "Positional", "Spot" };
    IntChooser lightTypeChooser = new IntChooser("Light Type:", lightTypeValues);
    lightTypeChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            int value = event.getValue();
            switch (value) {
            case 0:
                lightDirectional.setEnable(false);
                lightPoint.setEnable(false);
                lightSpot.setEnable(false);
                break;
            case 1:
                lightDirectional.setEnable(true);
                lightPoint.setEnable(false);
                lightSpot.setEnable(false);
                break;
            case 2:
                lightDirectional.setEnable(false);
                lightPoint.setEnable(true);
                lightSpot.setEnable(false);
                break;
            case 3:
                lightDirectional.setEnable(false);
                lightPoint.setEnable(false);
                lightSpot.setEnable(true);
                break;
            }
        }
    });
    lightTypeChooser.setValueByName("Directional");
    panel.add(lightTypeChooser);

    // Set up the sliders for the attenuation

    // top row
    panel.add(new LeftAlignComponent(new JLabel("Light attenuation:")));

    FloatLabelJSlider constantSlider = new FloatLabelJSlider("Constant ", 0.1f, 0.0f, 3.0f, attenuation.x);
    constantSlider.setMajorTickSpacing(1.0f);
    constantSlider.setPaintTicks(true);
    constantSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            attenuation.x = e.getValue();
            lightPoint.setAttenuation(attenuation);
            lightSpot.setAttenuation(attenuation);
        }
    });
    panel.add(constantSlider);

    FloatLabelJSlider linearSlider = new FloatLabelJSlider("Linear   ", 0.1f, 0.0f, 3.0f, attenuation.y);
    linearSlider.setMajorTickSpacing(1.0f);
    linearSlider.setPaintTicks(true);
    linearSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            attenuation.y = e.getValue();
            lightPoint.setAttenuation(attenuation);
            lightSpot.setAttenuation(attenuation);
        }
    });
    panel.add(linearSlider);

    FloatLabelJSlider quadradicSlider = new FloatLabelJSlider("Quadradic", 0.1f, 0.0f, 3.0f, attenuation.z);
    quadradicSlider.setMajorTickSpacing(1.0f);
    quadradicSlider.setPaintTicks(true);
    quadradicSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            attenuation.z = e.getValue();
            lightPoint.setAttenuation(attenuation);
            lightSpot.setAttenuation(attenuation);
        }
    });
    panel.add(quadradicSlider);

    // Set up the sliders for the attenuation
    // top row
    panel.add(new LeftAlignComponent(new JLabel("Spot light:")));

    // spread angle is 0-180 degrees, no slider scaling
    FloatLabelJSlider spotSpreadSlider = new FloatLabelJSlider("Spread Angle ", 1.0f, 0.0f, 180.0f,
            spotSpreadAngle);
    spotSpreadSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            spotSpreadAngle = e.getValue();
            lightSpot.setSpreadAngle((float) Math.toRadians(spotSpreadAngle));
        }
    });
    panel.add(spotSpreadSlider);

    // concentration angle is 0-128 degrees
    FloatLabelJSlider spotConcentrationSlider = new FloatLabelJSlider("Concentration", 1.0f, 0.0f, 128.0f,
            spotConcentration);
    spotConcentrationSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            spotConcentration = e.getValue();
            lightSpot.setConcentration(spotConcentration);
        }
    });
    panel.add(spotConcentrationSlider);

    return panel;
}

From source file:net.sf.jabref.groups.GroupSelector.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == refresh) {
        valueChanged(null);/*from   w  ww .ja va  2  s  .  c  o  m*/
    } else if (e.getSource() == newButton) {
        GroupDialog gd = new GroupDialog(frame, panel, null);
        gd.setVisible(true); // gd.show(); -> deprecated since 1.5
        if (gd.okPressed()) {
            AbstractGroup newGroup = gd.getResultingGroup();
            GroupTreeNode newNode = new GroupTreeNode(newGroup);
            groupsRoot.add(newNode);
            revalidateGroups();
            UndoableAddOrRemoveGroup undo = new UndoableAddOrRemoveGroup(GroupSelector.this, groupsRoot,
                    newNode, UndoableAddOrRemoveGroup.ADD_NODE);
            panel.undoManager.addEdit(undo);
            panel.markBaseChanged();
            frame.output(Localization.lang("Created group \"%0\".", newGroup.getName()));
        }
    } else if (e.getSource() == autoGroup) {
        AutoGroupDialog gd = new AutoGroupDialog(frame, panel, GroupSelector.this, groupsRoot,
                Globals.prefs.get(JabRefPreferences.GROUPS_DEFAULT_FIELD), " .,", ",");
        gd.setVisible(true); // gd.show(); -> deprecated since 1.5
        // gd does the operation itself
    } else if (e.getSource() instanceof JCheckBox) {
        valueChanged(null);
    } else if (e.getSource() instanceof JCheckBoxMenuItem) {
        valueChanged(null);
    } else if (e.getSource() instanceof JRadioButtonMenuItem) {
        valueChanged(null);
    }
}

From source file:com.codeasylum.liquibase.Liquidate.java

@Override
public synchronized void actionPerformed(ActionEvent actionEvent) {

    if (actionEvent instanceof GroupedActionEvent) {
        if (changeSensitive) {
            if (((GroupedActionEvent) actionEvent).getButtonGroup() == sourceButtonGroup) {
                config.setSource(Source.valueOf(sourceButtonGroup.getSelection().getActionCommand()));
            } else if (((GroupedActionEvent) actionEvent).getButtonGroup() == goalButtonGroup) {

                Goal goal;/*from  w w w .ja v  a2  s.co m*/

                config.setGoal(goal = Goal.valueOf(goalButtonGroup.getSelection().getActionCommand()));
                outputTextField.setEnabled(goal.equals(Goal.GENERATE) || goal.equals(Goal.DOCUMENT));
                browseButton.setEnabled(goal.equals(Goal.GENERATE) || goal.equals(Goal.DOCUMENT));

                outputTextField.setText("");
                config.setOutput("");
            }
        }
    } else if (actionEvent.getSource() == browseButton) {

        Goal goal;

        switch (goal = Goal.valueOf(goalButtonGroup.getSelection().getActionCommand())) {
        case NONE:
            throw new FormattedRuntimeException("There should be no browse functionality for goal(%s)",
                    goal.name());
        case PREVIEW:
            throw new FormattedRuntimeException("There should be no browse functionality for goal(%s)",
                    goal.name());
        case DOCUMENT:

            File directory;

            if ((directory = DirectoryChooserDialog.showDirectoryChooserDialog(this)) != null) {
                outputTextField.setText(directory.getAbsolutePath());
            }
            break;
        case GENERATE:

            File file;

            if ((file = FileChooserDialog.showFileChooserDialog(this, FileChooserState.OPEN)) != null) {
                outputTextField.setText(file.getAbsolutePath());
            }
            break;
        case UPDATE:
            throw new FormattedRuntimeException("There should be no browse functionality for goal(%s)",
                    goal.name());
        default:
            throw new UnknownSwitchCaseException(goal.name());
        }
    } else if (actionEvent.getSource() == startButton) {

        SpringLiquibase springLiquibase;
        Database database;
        Goal goal;
        boolean outputValidated = true;

        springLiquibase = new SpringLiquibase(extensionLoader.getClassLoader());
        springLiquibase.setGoal(goal = Goal.valueOf(goalButtonGroup.getSelection().getActionCommand()));

        switch (goal) {
        case NONE:
            break;
        case PREVIEW:
            break;
        case DOCUMENT:
            if ((config.getOutput() != null) && (config.getOutput().length() > 0)) {

                File file;

                if (!(file = new File(config.getOutput())).isDirectory()) {
                    outputValidated = false;
                    WarningDialog.showWarningDialog(this,
                            "Liquibase documentation requires that an output location be an existing folder");
                } else {
                    springLiquibase.setOutputDir(file.getAbsolutePath());
                }
            }
            break;
        case GENERATE:
            if ((config.getOutput() == null) || (config.getOutput().length() == 0)) {
                outputValidated = false;
                WarningDialog.showWarningDialog(this, "Liquibase state generation requires an output file");
            } else if (!config.getOutput().contains(System.getProperty("file.separator"))) {
                outputValidated = false;
                WarningDialog.showWarningDialog(this,
                        "Liquibase state generation requires that the output location refer to a file, and not just a folder");
            } else {

                File file = new File(config.getOutput());

                if (!file.getParentFile().isDirectory()) {
                    outputValidated = false;
                    WarningDialog.showWarningDialog(this,
                            "Liquibase state generation requires that an output location refer to an existing folder");
                } else {
                    springLiquibase.setOutputDir(file.getParent());
                    springLiquibase.setOutputLog(file.getName());
                }
            }
            break;
        case UPDATE:
            break;
        default:
            throw new UnknownSwitchCaseException(goal.name());
        }

        if (outputValidated) {

            if (goal.equals(Goal.PREVIEW)) {

                StenographWriter previewWriter;

                springLiquibase.setPreviewWriter(previewWriter = new StenographWriter());
                PreviewDialog.showPreviewDialog(this, previewWriter);
            }

            springLiquibase.setSource(Source.valueOf(sourceButtonGroup.getSelection().getActionCommand()));
            springLiquibase.setChangeLog(changeLogTextField.getText());

            database = (Database) databaseCombo.getSelectedItem();

            try {
                springLiquibase.setDataSource(new DriverManagerDataSource(database.getDriver().getName(),
                        database.getUrl(hostTextField.getText(), portTextField.getText(),
                                schemaTextField.getText()),
                        userTextField.getText(), new String(passwordField.getPassword())));
                springLiquibase.afterPropertiesSet();

                InfoDialog.showInfoDialog(this, "Liquibase update completed...");
            } catch (Exception exception) {
                JavaErrorDialog.showJavaErrorDialog(this, this, exception);
            }
        }
    }
}

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

@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equalsIgnoreCase("Save Map")) {
        UserDialog dialog = new UserDialog("Pls Enter the Map Name.", this);
        String mapName = dialog.getValue();
        if (StringUtils.isNotBlank(mapName)) {
            GameBean.mapInfo.setMapName(mapName);
            File file = new File(Configuration.PATH_FOR_MAP);
            MapInformationWrapper wrapper = null;
            if (file.exists()) {
                try {
                    wrapper = GameUtils.readMapInformation(Configuration.PATH_FOR_MAP);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }//from  w  w w  . j  a  v a2  s. c o  m
            } else {
                wrapper = new MapInformationWrapper();
            }
            if (wrapper != null) {
                try {
                    wrapper.getMapList().add(GameBean.mapInfo);
                    GameUtils.writeMapInformation(wrapper, Configuration.PATH_FOR_MAP);
                    JOptionPane.showMessageDialog(this, "Saved Successfully..");
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    } else {
        JButton src = (JButton) ae.getSource();
        String location = src.getActionCommand();
        GameBean.mapInfo.getPathMap().put(Integer.parseInt(location), null);
        GameBean.mapInfo.getStartPointInfo().remove(new Integer(location));
        new ComplexDialog(location);
        TileInformation info = GameBean.mapInfo.getPathMap().get(Integer.parseInt(location));
        if (info != null) {
            if (info.isStartTile()) {
                src.setBackground(Configuration.startPointColor);
            } else if (info.isEndTile()) {
                src.setBackground(Configuration.endPointColor);
            } else if (info.getEnemy() != null) {
                src.setBackground(Configuration.enemyColor);
            } else {
                src.setBackground(Configuration.pathColor);
            }
        } else {
            Color color = UIManager.getColor("Button.background");
            src.setBackground(color);
        }
    }
}

From source file:de.juwimm.cms.content.panel.PanDocuments.java

private void btnFileActionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("CLICK")) {
        Enumeration en = bgrp.getElements();
        while (en.hasMoreElements()) {
            PanDocumentSymbol.JToggleBtt btn = (PanDocumentSymbol.JToggleBtt) en.nextElement();
            if (!btn.isSelected()) {
                btn.unClick();//from w ww . ja v  a2 s  . co  m
            } else {
                btn.doClick();
            }
        }
        intDocId = new Integer(bgrp.getSelection().getActionCommand());
        selectDocument(intDocId);
    } else {
        ActionEvent ae = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "CLICK");
        ((PanDocumentSymbol.JToggleBtt) e.getSource()).fireActionPerformedT(ae);
    }
}