Example usage for javax.swing ButtonModel getActionCommand

List of usage examples for javax.swing ButtonModel getActionCommand

Introduction

In this page you can find the example usage for javax.swing ButtonModel getActionCommand.

Prototype

public String getActionCommand();

Source Link

Document

Returns the action command string for the button.

Usage

From source file:com.prezerak.windmill.gui.AveragesPanel.java

private void createChart() {

    ButtonModel btnModelAvg = WindMill.mainFrame.getAvgButtonGroup().getSelection();
    long pollInterval = Long.parseLong(btnModelAvg.getActionCommand()) * 1000;
    String pollString = null;/* w  ww  .java  2s. c o m*/

    if (pollInterval == 0)
        pollString = " (actual)";
    else
        pollString = "(" + String.valueOf(pollInterval / 60000) + " mins)";

    ButtonModel btnModelUnits = WindMill.mainFrame.getUnitsButtonGroup().getSelection();
    String unitsString = btnModelUnits.getActionCommand();

    chart = ChartFactory.createTimeSeriesChart(
            WindMill.propertyFile.getProperty("SHIP", "SHIP") + " wind velocity/ direction" + pollString,
            Utilities.createDateString(datasetVel.getDataItem(0).getPeriod().getLastMillisecond(),
                    datasetVel.getDataItem(datasetVel.getItemCount() - 1).getPeriod().getLastMillisecond()),
            "Velocity (" + unitsString + ")", null, true, true, true);
}

From source file:com.prezerak.windmill.gui.AveragesPanel.java

/**
 * Creates a sample chart.// w  w w  .  j av  a  2s.  c o m
 * 
 * @return a sample chart.
 */

@Override
public void actionPerformed(ActionEvent evt) {
    if (evt.getActionCommand().equals("Print Graph")) {
        PrintUtilities.printComponent(chartPanel);
    } else if (evt.getActionCommand().equals("Back to Real")) {
        backToRealTime();
    } else if (evt.getActionCommand().equals("Report")) {
        ButtonModel btnModel = WindMill.mainFrame.getAvgButtonGroup().getSelection();
        long pollInterval = Long.parseLong(btnModel.getActionCommand()) / 60;

        String titlePad;
        if (pollInterval == 0)
            titlePad = " (actual)";
        else
            titlePad = " (" + Long.toString(pollInterval) + " mins)";
        new ReportDialog(WindMill.mainFrame, "Wind Report" + titlePad, datasetVel, datasetDir,
                " " + WindMill.mainFrame.getButtonGroupUnits().getSelection().getActionCommand(), pollInterval,
                rsVelDir);
    } else if (evt.getActionCommand().equals("Alarm Report")) {
        new AlarmReportDialog(WindMill.mainFrame, "Alarm Report", true,
                WindMill.database.queryAllAlarms(startDate, endDate), datasetGust, datasetHigh, datasetHigher);
    }
}

From source file:com.prezerak.windmill.gui.AveragesPanel.java

@Override
public void run() {
    // TODO Auto-generated method stub
    ButtonModel btnModelAvg = WindMill.mainFrame.getAvgButtonGroup().getSelection();
    long pollInterval = Long.parseLong(btnModelAvg.getActionCommand()) * 1000;

    if (pollInterval != 0 && endDate - startDate < pollInterval) {

        waitDlg.setVisible(false);//from  w  ww .  j  ava2s  .c o m
        waitDlg.removeAll();
        waitDlg.dispose();

        JLabel lbl = new JLabel("Choose either a longer duration or a smaller average period !!!");
        lbl.setFont(new Font("Tahoma", Font.BOLD, 11));
        JOptionPane.showMessageDialog(null, lbl);
        if (WindMill.mainFrame.getMode() == MainFrameModes.REAL_TIME_MODE)
            WindMill.mainFrame.showRealTimeFrame();

    } else {

        cleanUp(true);
        runSequence();
        WindMill.mainFrame.addToDisplayPanel();
        waitDlg.setVisible(false);
        waitDlg.removeAll();
        waitDlg.dispose();
    }

}

From source file:com.prezerak.windmill.gui.AveragesPanel.java

private void createSeries() {

    ButtonModel btnModel = WindMill.mainFrame.getAvgButtonGroup().getSelection();
    long pollInterval = Long.parseLong(btnModel.getActionCommand()) * 1000;
    float conversionFactor = getWindConversionFactor();

    datasetVel = new TimeSeries("Velocity");
    datasetDir = new TimeSeries("Direction");

    Velocity v = null;//ww  w  . j  a  v  a2s.  c  om

    if (conversionFactor == 0)
        v = new BeaufortVelocity(conversionFactor);
    else
        v = new RegularVelocity(conversionFactor);

    rsVelDir = WindMill.database.queryRecordsInTimePeriod(startDate, endDate);
    //In case of no values
    try {
        rsVelDir.beforeFirst();
        if (!rsVelDir.next()) {
            datasetVel.add(new FixedMillisecond(startDate), null);
            datasetDir.add(new FixedMillisecond(startDate), null);
            datasetVel.add(new FixedMillisecond(endDate), null);
            datasetDir.add(new FixedMillisecond(endDate), null);
            maxY = 150;
            rsVelDir.close();

            if (datasetGust != null)
                datasetGust.delete(0, datasetGust.getItemCount() - 1);

            if (datasetHigh != null)
                datasetHigh.delete(0, datasetHigh.getItemCount() - 1);

            if (datasetHigher != null)
                datasetHigher.delete(0, datasetHigher.getItemCount() - 1);

            return;
        }
    } catch (SQLException e) {
        Utilities.printSQLException(e);
    }

    //Graph display with actual values
    if (pollInterval == 0) {
        try {
            rsVelDir.beforeFirst();
            while (rsVelDir.next()) {
                long currentTime = rsVelDir.getLong(rsVelDir.findColumn("timeMills"));
                FixedMillisecond timePeriod = new FixedMillisecond(currentTime);
                v.setValueInMeters(rsVelDir.getFloat(rsVelDir.findColumn("vel")));
                datasetVel.add(timePeriod, v.getValue());
                datasetDir.add(timePeriod, rsVelDir.getFloat(rsVelDir.findColumn("dir")));
            }
        } catch (SQLException e) {
            Utilities.printSQLException(e);
        }
    } else {

        //Obviously pollInterval !=0 so we aim for average
        try {
            rsVelDir.first();
            long startT = startDate + (rsVelDir.getLong(rsVelDir.findColumn("timeMills")) - startDate)
                    / pollInterval * pollInterval;

            rsVelDir.last();
            long endT = startT + pollInterval;
            long endTime = rsVelDir.getLong(rsVelDir.findColumn("timeMills")) / pollInterval * pollInterval
                    + pollInterval;

            float sumVel = 0;
            float sumDir = 0;
            long counter = 0;

            rsVelDir.first();
            while (endT < endTime) {
                long time = 0;//set to UNIX epoch;
                if (!rsVelDir.isAfterLast())
                    time = rsVelDir.getLong(rsVelDir.findColumn("timeMills"));
                if (time >= startT && time < endT) {
                    sumVel += rsVelDir.getFloat(rsVelDir.findColumn("vel"));
                    sumDir += rsVelDir.getFloat(rsVelDir.findColumn("dir"));
                    rsVelDir.next();
                    counter++;
                } else {
                    FixedMillisecond timePeriod = new FixedMillisecond(endT);
                    if (counter != 0)
                        v.setValueInMeters(sumVel / counter);
                    else
                        v.setValueInMeters(0.0f);
                    datasetVel.add(timePeriod, v.getValue());
                    if (counter != 0)
                        datasetDir.add(timePeriod, sumDir / counter);
                    else
                        datasetDir.add(timePeriod, 0.0f);
                    startT = endT;
                    endT += pollInterval;
                    sumVel = 0;
                    sumDir = 0;
                    counter = 0;
                }
            }
            rsVelDir.close();
        } catch (SQLException e) {
            Utilities.printSQLException(e);
        }
    }

    datasetGust = queryAlarm(Gust.getInstance().GUST, "Gust");
    if (Gust.getInstance().isOn() && Gust.getInstance().getStartTime() >= startDate
            && Gust.getInstance().getStartTime() < endDate) {
        long t = 0;
        long currentT = System.currentTimeMillis();
        if (endDate < currentT)
            t = endDate;
        else
            t = currentT;
        SimpleTimePeriod timePeriod = new SimpleTimePeriod(Gust.getInstance().getStartTime(), t);
        TimePeriodValue timePeriodValue = new TimePeriodValue(timePeriod, 1);
        datasetGust.add(timePeriodValue);
    }

    datasetHigh = queryAlarm(High.getInstance().HIGH, "High");
    if (High.getInstance().isOn() && High.getInstance().getStartTime() >= startDate
            && High.getInstance().getStartTime() < endDate) {
        long t = 0;
        long currentT = System.currentTimeMillis();
        if (endDate < currentT)
            t = endDate;
        else
            t = currentT;

        SimpleTimePeriod timePeriod = new SimpleTimePeriod(High.getInstance().getStartTime(), t);
        TimePeriodValue timePeriodValue = new TimePeriodValue(timePeriod, 1);
        datasetHigh.add(timePeriodValue);
    }

    datasetHigher = queryAlarm(Higher.getInstance().HIGHER, "Higher");
    if (Higher.getInstance().isOn() && Higher.getInstance().getStartTime() >= startDate
            && Higher.getInstance().getStartTime() < endDate) {
        long t = 0;
        long currentT = System.currentTimeMillis();
        if (endDate < currentT)
            t = endDate;
        else
            t = currentT;

        SimpleTimePeriod timePeriod = new SimpleTimePeriod(Higher.getInstance().getStartTime(), t);
        TimePeriodValue timePeriodValue = new TimePeriodValue(timePeriod, 1);
        datasetHigher.add(timePeriodValue);
    }
}

From source file:org.nuclos.client.ui.OptionGroup.java

/**
 * @return the action command of the selected button or <code>null</code>, if none is selected.
 *///from w w w  .  j av a2 s.  c o  m
public String getValue() {
    final ButtonModel buttonmodelSelected = bg.getSelection();
    return buttonmodelSelected == null ? null : buttonmodelSelected.getActionCommand();
}