Example usage for com.google.gwt.user.client.ui HasVerticalAlignment ALIGN_MIDDLE

List of usage examples for com.google.gwt.user.client.ui HasVerticalAlignment ALIGN_MIDDLE

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui HasVerticalAlignment ALIGN_MIDDLE.

Prototype

VerticalAlignmentConstant ALIGN_MIDDLE

To view the source code for com.google.gwt.user.client.ui HasVerticalAlignment ALIGN_MIDDLE.

Click Source Link

Document

Specifies that the widget's contents should be aligned in the middle.

Usage

From source file:gov.nist.spectrumbrowser.admin.SessionManagement.java

License:Open Source License

@Override
public void draw() {
    try {// w  w  w. j a va 2  s.c  om
        verticalPanel.clear();
        HTML title = new HTML("<h2>Active Sessions </h2>");
        verticalPanel.add(title);
        if (frozen) {
            HTML subtitle = new HTML("<h3>New session creation is temporarily suspended by " + freezeRequester
                    + ". Users cannot use the system.</h3>");
            verticalPanel.add(subtitle);
        }

        int nrows = userSessions.size() + adminSessions.size();
        Grid grid = new Grid(nrows + 1, 5);
        for (int i = 0; i < grid.getRowCount(); i++) {
            for (int j = 0; j < grid.getColumnCount(); j++) {
                grid.getCellFormatter().setHorizontalAlignment(i, j, HasHorizontalAlignment.ALIGN_CENTER);
                grid.getCellFormatter().setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE);
            }
        }

        for (int i = 0; i < grid.getColumnCount(); i++) {
            grid.getCellFormatter().setStyleName(0, i, "textLabelStyle");
        }
        grid.setBorderWidth(2);
        grid.setCellSpacing(2);
        grid.setCellPadding(2);
        grid.setText(0, 0, "Email Address");
        grid.setText(0, 1, "Remote IP Address");
        grid.setText(0, 2, "Session Start Time");
        grid.setText(0, 3, "Session End Time");
        grid.setText(0, 4, "User Privilege");

        for (int i = 0; i < userSessions.size(); i++) {
            JSONObject jsonObj = userSessions.get(i).isObject();
            String userName = jsonObj.get(Defines.USER_NAME).isString().stringValue();
            int row = i + 1;
            grid.setText(row, 0, userName);
            String ipAddr = jsonObj.get(Defines.REMOTE_ADDRESS).isString().stringValue();
            grid.setText(row, 1, ipAddr);
            String startTime = jsonObj.get(Defines.SESSION_LOGIN_TIME).isString().stringValue();
            grid.setText(row, 2, startTime);
            String expiryTime = jsonObj.get(Defines.EXPIRE_TIME).isString().stringValue();
            grid.setText(row, 3, expiryTime);
            grid.setText(row, 4, "user");

        }
        for (int i = 0; i < adminSessions.size(); i++) {
            JSONObject jsonObj = adminSessions.get(i).isObject();
            int row = i + userSessions.size() + 1;
            String userName = jsonObj.get(Defines.USER_NAME).isString().stringValue();
            grid.setText(row, 0, userName);
            String ipAddr = jsonObj.get(Defines.REMOTE_ADDRESS).isString().stringValue();
            grid.setText(row, 1, ipAddr);
            String startTime = jsonObj.get(Defines.SESSION_LOGIN_TIME).isString().stringValue();
            grid.setText(row, 2, startTime);
            String expiryTime = jsonObj.get(Defines.EXPIRE_TIME).isString().stringValue();
            grid.setText(row, 3, expiryTime);
            grid.setText(row, 4, "admin");
        }
        verticalPanel.add(grid);

        HorizontalPanel hpanel = new HorizontalPanel();

        Button freezeButton = new Button("Freeze Sessions");
        hpanel.add(freezeButton);
        freezeButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                boolean yesno = Window.confirm("Warning! No new sessions will be allowed.\n "
                        + "Email will be sent to the administrator when all active sessions are terminated.\n Proceed?");
                if (yesno) {
                    SessionManagement.this.redraw = true;
                    Admin.getAdminService().freezeSessions(SessionManagement.this);
                }
            }
        });

        Button unfreezeButton = new Button("Cancel Freeze");

        hpanel.add(unfreezeButton);
        unfreezeButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                SessionManagement.this.redraw = true;
                Admin.getAdminService().unfreezeSessions(SessionManagement.this);

            }
        });

        Button logoffButton = new Button("Log Off");
        hpanel.add(logoffButton);
        logoffButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                timer.cancel();
                admin.logoff();
            }
        });
        verticalPanel.add(hpanel);
        timer = new Timer() {
            @Override
            public void run() {
                if (Admin.getSessionToken() != null) {
                    SessionManagement.this.redraw = true;
                    Admin.getAdminService().getSessions(SessionManagement.this);
                }
            }

        };

        timer.schedule(5 * 1000);
    } catch (Throwable th) {
        logger.log(Level.SEVERE, "Error drawing", th);
        admin.logoff();
    }

}

From source file:gov.nist.spectrumbrowser.admin.SweptFrequencySensorBands.java

License:Open Source License

public void draw() {

    verticalPanel.clear();/*from  w  w  w  .j ava2s  . c  o m*/
    HTML html = new HTML("<H2>Bands for sensor : " + sensor.getSensorId() + "</H2>");
    verticalPanel.add(html);
    JSONObject sensorThresholds = sensor.getThresholds();

    Grid grid = new Grid(sensorThresholds.keySet().size() + 1, 8);
    grid.setBorderWidth(2);
    grid.setCellPadding(2);
    grid.setCellSpacing(2);
    grid.setText(0, 0, "System To Detect");
    grid.setText(0, 1, "Min Freq (Hz)");
    grid.setText(0, 2, "Max Freq (Hz)");
    grid.setText(0, 3, "Channel Count");
    grid.setText(0, 4, "Occupancy Threshold (dBm/Hz)");
    grid.setText(0, 5, "Occupancy Threshold (dBm)");
    grid.setText(0, 6, "Enabled?");
    grid.setText(0, 7, "Delete Band");
    grid.setBorderWidth(2);
    grid.setCellPadding(2);
    grid.setCellSpacing(2);
    CellFormatter formatter = grid.getCellFormatter();

    for (int i = 0; i < grid.getRowCount(); i++) {
        for (int j = 0; j < grid.getColumnCount(); j++) {
            formatter.setHorizontalAlignment(i, j, HasHorizontalAlignment.ALIGN_CENTER);
            formatter.setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE);
        }
    }
    for (int i = 0; i < grid.getColumnCount(); i++) {
        grid.getCellFormatter().setStyleName(0, i, "textLabelStyle");
    }

    int row = 1;
    for (String key : sensorThresholds.keySet()) {
        final SweptFrequencyBand threshold = new SweptFrequencyBand(sensorThresholds.get(key).isObject());
        grid.setText(row, 0, threshold.getSystemToDetect());
        grid.setText(row, 1, Long.toString(threshold.getMinFreqHz()));
        grid.setText(row, 2, Long.toString(threshold.getMaxFreqHz()));
        final TextBox channelCountTextBox = new TextBox();
        channelCountTextBox.setText(Long.toString(threshold.getChannelCount()));
        channelCountTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

            @Override
            public void onValueChange(ValueChangeEvent<String> event) {
                Long oldValue = Long.parseLong(channelCountTextBox.getValue());
                try {
                    long newValue = Long.parseLong(event.getValue());
                    threshold.setChannelCount((long) newValue);
                } catch (Exception ex) {
                    Window.alert(ex.getMessage());
                    channelCountTextBox.setValue(Double.toString(oldValue));
                }
            }

        });
        grid.setWidget(row, 3, channelCountTextBox);

        final Label thresholdLabel = new Label();

        final TextBox thresholdTextBox = new TextBox();
        thresholdTextBox.setText(Double.toString(threshold.getThresholdDbmPerHz()));
        thresholdTextBox.addValueChangeHandler(new ValueChangeHandler<String>() {

            @Override
            public void onValueChange(ValueChangeEvent<String> event) {
                Double oldThreshold = Double.parseDouble(thresholdTextBox.getValue());
                try {
                    double newThreshold = Double.parseDouble(event.getValue());
                    threshold.setThresholdDbmPerHz(newThreshold);
                    thresholdLabel.setText(Float.toString(threshold.getThresholdDbm()));
                } catch (Exception ex) {
                    Window.alert(ex.getMessage());
                    thresholdTextBox.setValue(Double.toString(oldThreshold));
                }
            }

        });
        grid.setWidget(row, 4, thresholdTextBox);
        thresholdLabel.setText(Float.toString(threshold.getThresholdDbm()));
        grid.setWidget(row, 5, thresholdLabel);
        CheckBox activeCheckBox = new CheckBox();
        grid.setWidget(row, 6, activeCheckBox);
        activeCheckBox.setValue(threshold.isActive());
        activeCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

            @Override
            public void onValueChange(ValueChangeEvent<Boolean> event) {

                if (event.getValue()) {
                    for (String key : sensor.getThresholds().keySet()) {
                        SweptFrequencyBand th = new SweptFrequencyBand(sensor.getThreshold(key));
                        th.setActive(false);
                    }
                }
                threshold.setActive(event.getValue());
                draw();

            }
        });

        Button deleteButton = new Button("Delete Band");
        deleteButton.addClickHandler(new DeleteThresholdClickHandler(threshold));
        grid.setWidget(row, 7, deleteButton);
        row++;

    }
    verticalPanel.add(grid);
    HorizontalPanel horizontalPanel = new HorizontalPanel();
    Button addButton = new Button("Add Band");
    addButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            new AddSweptFrequencySensorBand(admin, SweptFrequencySensorBands.this, sensorConfig, sensor,
                    verticalPanel).draw();

        }
    });
    horizontalPanel.add(addButton);

    Button recomputeButton = new Button("Recompute Occupancies");
    recomputeButton.setTitle("Recomputes per message summary occupancies.");
    recomputeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            boolean yes = Window.confirm(
                    "Ensure no users are using the system. Update sensor before proceeding. This can take a long time. Proceed?");
            if (yes) {

                final HTML html = new HTML(
                        "<h3>Recomputing thresholds - this can take a while. Please wait. </h3>");
                verticalPanel.add(html);

                Admin.getAdminService().recomputeOccupancies(sensor.getSensorId(),
                        new SpectrumBrowserCallback<String>() {

                            @Override
                            public void onSuccess(String result) {
                                verticalPanel.remove(html);

                            }

                            @Override
                            public void onFailure(Throwable throwable) {
                                Window.alert("Error communicating with server");
                                admin.logoff();

                            }
                        });
            }
        }
    });
    horizontalPanel.add(recomputeButton);

    Button doneButton = new Button("Done");
    doneButton.setTitle("Return to sensors screen");
    doneButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            sensorConfig.redraw();
        }
    });

    horizontalPanel.add(doneButton);

    Button updateButton = new Button("Update");
    updateButton.setTitle("Update sensor on server");
    updateButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Admin.getAdminService().updateSensor(sensor.toString(), sensorConfig);
        }
    });

    horizontalPanel.add(updateButton);

    Button logoffButton = new Button("Log Off");
    logoffButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            admin.logoff();
        }
    });

    horizontalPanel.add(logoffButton);

    verticalPanel.add(horizontalPanel);

}

From source file:gov.nist.spectrumbrowser.client.DailyStatsChart.java

License:Open Source License

public void draw() {
    ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);

    try {/*from   ww  w . ja  va  2s  . c o m*/
        chartLoader.loadApi(new Runnable() {
            @Override
            public void run() {
                buttonGrid = new Grid(1, 2);
                horizontalPanel = new HorizontalPanel();
                horizontalPanel.setWidth(SpectrumBrowser.SPEC_WIDTH + "px");
                horizontalPanel.setHeight(SpectrumBrowser.SPEC_HEIGHT + "px");
                lineChart = new LineChart();
                horizontalPanel.add(lineChart);
                verticalPanel.clear();
                //waitImage.setVisible(false);
                drawNavigation();
                String startDate = jsonValue.isObject().get("startDate").isString().stringValue();
                HTML title = new HTML("<h2>" + END_LABEL + "</h2>");

                verticalPanel.add(title);

                double fmin = jsonValue.isObject().get("minFreq").isNumber().doubleValue() / 1E6;
                double fmax = jsonValue.isObject().get("maxFreq").isNumber().doubleValue() / 1E6;
                int nchannels = (int) jsonValue.isObject().get(Defines.CHANNEL_COUNT).isNumber().doubleValue();
                int cutoff = (int) jsonValue.isObject().get("cutoff").isNumber().doubleValue();

                HTML infoTitle = new HTML("<h3>Start Date= " + startDate + ";Detected System = " + sys2detect
                        + "; minFreq = " + fmin + " MHz; maxFreq = " + fmax + " MHz" + "; channelCount = "
                        + nchannels + "; Occupancy Threshold = " + cutoff + " dBm </h3>");
                verticalPanel.add(infoTitle);
                String helpText = " Click on a point to see detail.";
                helpLabel = new Label();
                helpLabel.setText(helpText);
                verticalPanel.add(helpLabel);
                verticalPanel.add(buttonGrid);
                int buttonCount = 0;
                if (prevMinTime < mMinTime) {
                    Button prevIntervalButton = new Button("<< Previous " + days + " Days");
                    prevIntervalButton.setTitle("Click to see previous interval");
                    buttonGrid.setWidget(0, 0, prevIntervalButton);
                    verticalPanel.add(buttonGrid);
                    buttonCount++;
                    prevIntervalButton.addClickHandler(new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            mMinTime = prevMinTime;
                            helpLabel.setText("Computing Occupancy please wait");
                            spectrumBrowser.showWaitImage();
                            spectrumBrowser.getSpectrumBrowserService().getDailyMaxMinMeanStats(mSensorId, lat,
                                    lon, alt, mMinTime, days, sys2detect, mMinFreq, mMaxFreq, mSubBandMinFreq,
                                    mSubBandMaxFreq, DailyStatsChart.this);
                        }

                    });
                }

                if (nextMinTime > mMinTime) {
                    Button nextIntervalButton = new Button("Next " + days + " Days >>");
                    nextIntervalButton.setTitle("Click to see next interval");
                    buttonGrid.setWidget(0, 1, nextIntervalButton);
                    buttonCount++;

                    nextIntervalButton.addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            mMinTime = nextMinTime;
                            spectrumBrowser.showWaitImage();
                            helpLabel.setText("Computing Occupancy please wait");
                            spectrumBrowser.getSpectrumBrowserService().getDailyMaxMinMeanStats(mSensorId, lat,
                                    lon, alt, mMinTime, days, sys2detect, mMinFreq, mMaxFreq, mSubBandMinFreq,
                                    mSubBandMaxFreq, DailyStatsChart.this);
                        }

                    });
                }

                if (buttonCount != 0) {
                    buttonGrid.setStyleName("selectionGrid");
                }
                for (int i = 0; i < buttonGrid.getRowCount(); i++) {
                    for (int j = 0; j < buttonGrid.getColumnCount(); j++) {
                        buttonGrid.getCellFormatter().setHorizontalAlignment(i, j,
                                HasHorizontalAlignment.ALIGN_CENTER);
                        buttonGrid.getCellFormatter().setVerticalAlignment(i, j,
                                HasVerticalAlignment.ALIGN_MIDDLE);
                    }
                }

                verticalPanel.add(horizontalPanel);
                DataTable dataTable = DataTable.create();
                dataTable.addColumn(ColumnType.NUMBER, " Days");
                dataTable.addColumn(ColumnType.NUMBER, " Min");
                dataTable.addColumn(ColumnType.NUMBER, " Max");
                dataTable.addColumn(ColumnType.NUMBER, " Mean");
                /* if (mMeasurementType.equals("Swept-frequency")) {
                   dataTable.addColumn(ColumnType.NUMBER, " Median");
                }*/

                lineChart.addSelectHandler(new SelectHandler() {
                    @Override
                    public void onSelect(SelectEvent event) {
                        JsArray<Selection> selections = lineChart.getSelection();
                        int length = selections.length();
                        for (int i = 0; i < length; i++) {
                            Selection selection = selections.get(i);
                            logger.finer("Selected Row : " + selection.getRow());
                            logger.finer("selected col : " + selection.getColumn());
                            // If the measurement type is of type FFT-Power
                            // then drill down.
                            DailyStat ds = selectionProperties.get(selection.getRow());
                            if (ds.mType.equals("FFT-Power")) {
                                spectrumBrowser.showWaitImage();
                                spectrumBrowser.showWaitImage();

                                new FftPowerOneDayOccupancyChart(spectrumBrowser, navigation, mSensorId, lat,
                                        lon, alt, ds.startTime, sys2detect, mMinFreq, mMaxFreq, verticalPanel);
                            } else {
                                spectrumBrowser.showWaitImage();
                                new SweptFrequencyOneDaySpectrogramChart(mSensorId, lat, lon, alt, ds.startTime,
                                        sys2detect, mMinFreq, mMaxFreq, mSubBandMinFreq, mSubBandMaxFreq,
                                        verticalPanel, spectrumBrowser, navigation);

                            }
                        }

                    }
                });

                JSONObject jsonObject = jsonValue.isObject();
                try {
                    JSONObject values = jsonObject.get("values").isObject();
                    int dayCount = values.size();
                    logger.finer("dayCount " + dayCount);

                    dataTable.addRows(dayCount);

                    int rowIndex = 0;
                    for (String dayString : values.keySet()) {
                        JSONObject statsObject = values.get(dayString).isObject();
                        double mean = statsObject.get("meanOccupancy").isNumber().doubleValue() * 100;
                        double max = statsObject.get("maxOccupancy").isNumber().doubleValue() * 100;
                        double min = statsObject.get("minOccupancy").isNumber().doubleValue() * 100;
                        long count = (long) statsObject.get("count").isNumber().doubleValue();
                        int dayOffset = Integer.parseInt(dayString) / 24;
                        long time = (long) statsObject.get("dayBoundaryTimeStamp").isNumber().doubleValue();

                        DailyStat dailyStat = new DailyStat(mSensorId, time, mMeasurementType, count,
                                round2(max), round2(min), round2(mean));
                        selectionProperties.put(rowIndex, dailyStat);

                        dataTable.setCell(rowIndex, 0, dayOffset,
                                count + " acquisitions ; " + dayOffset + " days from start");
                        dataTable.setCell(rowIndex, 1, round2(min), round2(min) + "%");
                        dataTable.setCell(rowIndex, 2, round2(max), round2(max) + "%");
                        dataTable.setCell(rowIndex, 3, round2(mean), round2(mean) + "%");
                        /* if (statsObject.containsKey("medianOccupancy") ) {
                           double median = statsObject
                                 .get("medianOccupancy").isNumber()
                                 .doubleValue() * 100;
                           dataTable.setCell(rowIndex, 4, round2(median),
                                 round2(median) + "%");
                           dailyStat.setMedianOccupancy(round2(median));
                        } */
                        rowIndex++;
                    }
                } catch (Throwable ex) {
                    logger.log(Level.SEVERE, "problem generating chart ", ex);
                }
                LineChartOptions options = LineChartOptions.create();
                options.setBackgroundColor("#f0f0f0");
                options.setPointSize(5);
                HAxis haxis = HAxis.create("Days from start date.");
                Gridlines gridLines = Gridlines.create();
                gridLines.setCount(days);
                haxis.setGridlines(gridLines);
                haxis.setMaxValue(days - 1);
                haxis.setMinValue(0);

                if (days < 10) {
                    haxis.setShowTextEvery(1);
                } else if (days < 20) {
                    haxis.setShowTextEvery(2);
                } else {
                    haxis.setShowTextEvery(4);
                }

                options.setHAxis(haxis);
                options.setVAxis(VAxis.create("Occupancy %"));
                lineChart.setTitle("Click on data point to see detail");

                lineChart.draw(dataTable, options);
                lineChart.setVisible(true);
                lineChart.setHeight(SpectrumBrowser.SPEC_HEIGHT + "px");
                lineChart.setWidth(SpectrumBrowser.SPEC_WIDTH + "px");
                /* override with style if it exists */
                lineChart.setStyleName("lineChart");
                spectrumBrowserShowDatasets.unFreeze();
                spectrumBrowser.hideWaitImage();
            }
        });
    } catch (Throwable ex) {
        logger.log(Level.SEVERE, "Error in processing result ", ex);
        spectrumBrowser.logoff();
    }
}

From source file:gov.nist.spectrumbrowser.client.FftPowerOneAcquisitionSpectrogramChart.java

License:Open Source License

public void draw() {
    try {/*from  ww w .ja  v  a 2s  .  c om*/
        vpanel.clear();

        super.drawNavigation();
        HTML pageTitle = new HTML("<h2>" + getEndLabel() + "</h2>");
        vpanel.add(pageTitle);

        title = new HTML("<H3>Acquisition Start Time : " + localDateOfAcquisition + "; Occupancy Threshold : "
                + cutoff + " dBm; Measurements Per Acquisition = " + measurementsPerAcquisition + "</H3>");

        vpanel.add(title);

        double timeResolution = (double) (timeDelta + 1) / (double) measurementCount;

        int freqResolution = (int) round((this.mMaxFreq - this.mMinFreq) / this.binsPerMesurement);

        HTML subTitle = new HTML("<h3>Time Resolution= " + round3(timeResolution) + " s; Resolution BW = "
                + freqResolution + " Hz; Measurements = " + measurementCount + "; Max Occupancy = "
                + maxOccupancy + "%; Median Occupancy = " + medianOccupancy + "%; Mean Occupancy = "
                + meanOccupancy + "%; Min Occupancy = " + minOccupancy + "%</h3>");
        vpanel.add(subTitle);

        help = new Label("Single click for detail. Double click to zoom");
        vpanel.add(help);

        spectrogramVerticalPanel = new VerticalPanel();

        hpanel = new HorizontalPanel();

        commands = new Grid(1, 7);
        commands.setStyleName("selectionGrid");

        for (int i = 0; i < commands.getRowCount(); i++) {
            for (int j = 0; j < commands.getColumnCount(); j++) {
                commands.getCellFormatter().setHorizontalAlignment(i, j, HasHorizontalAlignment.ALIGN_CENTER);
                commands.getCellFormatter().setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE);
            }
        }

        hpanel.setSpacing(10);
        hpanel.setStyleName("spectrogram");
        xaxisPanel = new HorizontalPanel();
        xaxisPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        HorizontalPanel xaxis = new HorizontalPanel();
        xaxis.setWidth(canvasPixelWidth + 30 + "px");
        xaxis.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        NumberFormat numberFormat = NumberFormat.getFormat("00.00");
        xaxis.add(new Label(numberFormat.format(minTime)));
        xaxis.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        xaxis.add(new Label("Time (sec)"));
        xaxis.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        xaxis.add(new Label(numberFormat.format(minTime + timeDelta)));
        xaxisPanel.add(xaxis);

        // Attach the previous reading button.

        if (prevAcquisitionTime != mSelectionTime) {

            final Button prevDayButton = new Button();
            prevDayButton.setEnabled(true);
            prevDayButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    mSelectionTime = prevAcquisitionTime;
                    prevDayButton.setEnabled(false);
                    acquisitionDuration = 0;
                    leftBound = 0;
                    rightBound = 0;
                    window = measurementsPerAcquisition;
                    help.setText(COMPUTING_PLEASE_WAIT);
                    mSpectrumBrowser.showWaitImage();
                    mSpectrumBrowser.getSpectrumBrowserService()
                            .generateSingleAcquisitionSpectrogramAndOccupancy(mSensorId, prevAcquisitionTime,
                                    mSys2detect, mMinFreq, mMaxFreq, cutoff,
                                    FftPowerOneAcquisitionSpectrogramChart.this);

                }
            });

            prevDayButton.setText("<< Prev. Acquisition");
            commands.setWidget(0, 0, prevDayButton);

        }

        // Attach button for panning within the acquisition

        if (leftBound > 0) {
            Button panLeftButton = new Button();
            panLeftButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    if (leftBound - window >= 0) {
                        leftBound = (int) (leftBound - window);
                        rightBound = rightBound + window;
                    } else {
                        rightBound = rightBound + leftBound;
                        leftBound = 0;
                    }
                    help.setText(COMPUTING_PLEASE_WAIT);
                    mSpectrumBrowser.getSpectrumBrowserService()
                            .generateSingleAcquisitionSpectrogramAndOccupancy(mSensorId, mSelectionTime,
                                    mSys2detect, mMinFreq, mMaxFreq, (int) leftBound, (int) rightBound, cutoff,
                                    FftPowerOneAcquisitionSpectrogramChart.this);
                }
            });
            panLeftButton.setText("< Pan Left");
            panLeftButton.setTitle("Click to pan left");
            commands.setWidget(0, 1, panLeftButton);
        }

        // Attach the labels for the spectrogram power
        VerticalPanel powerLevelPanel = new VerticalPanel();
        powerLevelPanel.setWidth(100 + "px");
        this.maxPowerLabel = new Label();
        this.minPowerLabel = new Label();
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
        powerLevelPanel.add(maxPowerLabel);
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        powerLevelPanel.add(new Label("Power (dBm) "));
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
        powerLevelPanel.add(minPowerLabel);
        // Attach labels for the frequency.
        freqPanel = new VerticalPanel();
        freqPanel.setWidth(100 + "px");
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
        freqPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
        freqPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        freqPanel.add(new Label(Double.toString(maxFreqMhz)));
        freqPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        freqPanel.add(new Label("Frequency (MHz)"));
        freqPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
        freqPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        freqPanel.add(new Label(Double.toString(minFreqMhz)));
        powerMapPanel = new HorizontalPanel();
        powerMapPanel.setWidth(30 + "px");
        hpanel.add(freqPanel);
        spectrogramPanel = new VerticalPanel();

        HorizontalPanel spectrogramAndPowerMapPanel = new HorizontalPanel();
        spectrogramAndPowerMapPanel.add(spectrogramPanel);
        spectrogramAndPowerMapPanel.add(powerMapPanel);
        hpanel.add(spectrogramAndPowerMapPanel);
        currentValue = new Label("Click for power spectrum and power at selected time. Double click to zoom.");
        spectrogramVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        spectrogramVerticalPanel.add(commands);
        if (maxTime - minTime < acquisitionDuration) {
            Button unzoom = new Button("Zoom Out");

            unzoom.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    zoomOut();
                }
            });
            commands.setWidget(0, 2, unzoom);
        }
        spectrogramVerticalPanel.add(currentValue);
        spectrogramVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        spectrogramVerticalPanel.add(hpanel);
        String helpString = "Single click for power spectrum. Double click to zoom.";

        // Add the slider bar for min occupancy selection.
        occupancyMinPowerVpanel = new VerticalPanel();
        occupancyMinPowerVpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        occupancyMinPowerVpanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

        occupancyMinPowerSliderBar = new SliderBarSimpleVertical(100, canvasPixelHeight + "px", true);
        occupancyMinPowerVpanel.add(occupancyMinPowerSliderBar);
        occupancyMinPowerSliderBar.setMaxValue(100);

        this.occupancyMinPowerLabel = new Label();
        occupancyMinPowerVpanel.add(occupancyMinPowerLabel);

        final Button clearTabsButton = new Button("Close Tabs");
        commands.setWidget(0, 3, clearTabsButton);
        clearTabsButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                tabPanel.clear();
                tabPanel.add(spectrogramVerticalPanel, "[Spectrogram]");
                tabPanel.add(occupancyPanel, "[Occupancy]");
                tabPanel.selectTab(0);
            }
        });

        final Button cutoffAndRedrawButton = new Button("Cutoff and Redraw");
        commands.setWidget(0, 4, cutoffAndRedrawButton);
        cutoffAndRedrawButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                mSpectrumBrowser.showWaitImage();
                cutoffAndRedrawButton.setEnabled(false);
                help.setText(COMPUTING_PLEASE_WAIT);
                mSpectrumBrowser.getSpectrumBrowserService().generateSingleAcquisitionSpectrogramAndOccupancy(
                        mSensorId, mSelectionTime, mSys2detect, mMinFreq, mMaxFreq, leftBound, rightBound,
                        cutoffPower, FftPowerOneAcquisitionSpectrogramChart.this);

            }
        });
        occupancyMinPowerSliderBar
                .addBarValueChangedHandler(new OccupancyMinPowerSliderHandler(occupancyMinPowerLabel));
        int initialValue = (int) ((double) (maxPower - cutoff) / (double) (maxPower - minPower) * 100);
        occupancyMinPowerSliderBar.setValue(initialValue);

        hpanel.add(occupancyMinPowerVpanel);

        spectrogramPanel.setTitle(helpString);
        spectrumAndOccupancyPanel = new VerticalPanel();
        spectrumAndOccupancyPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        spectrogramVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        spectrogramVerticalPanel.add(spectrumAndOccupancyPanel);

        occupancyPanel = new VerticalPanel();
        occupancyPanel.setWidth(canvasPixelWidth + "px");
        occupancyPanel.setHeight(canvasPixelHeight + "px");
        occupancyPanel.setPixelSize(canvasPixelWidth, canvasPixelHeight);
        // Fine pan to the right.
        if (rightBound > 0) {
            Button rightPanButton = new Button();
            rightPanButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    logger.finest("rightBound = " + rightBound + " leftBound = " + leftBound + " window =  "
                            + window + " aquisitionDuration = " + measurementsPerAcquisition);
                    if (rightBound - window > 0) {
                        rightBound = rightBound - window;
                        leftBound = leftBound + window;
                    } else {
                        leftBound = leftBound + rightBound;
                        rightBound = 0;
                    }
                    help.setText(COMPUTING_PLEASE_WAIT);
                    mSpectrumBrowser.showWaitImage();
                    mSpectrumBrowser.getSpectrumBrowserService()
                            .generateSingleAcquisitionSpectrogramAndOccupancy(mSensorId, mSelectionTime,
                                    mSys2detect, mMinFreq, mMaxFreq, (int) leftBound, (int) rightBound, cutoff,
                                    FftPowerOneAcquisitionSpectrogramChart.this);
                }
            });
            commands.setWidget(0, 5, rightPanButton);
            rightPanButton.setTitle("Click to pan right");
            rightPanButton.setText("Pan Right >");
        }

        // Attach the next spectrogram panel.

        if (nextAcquisitionTime != mSelectionTime) {
            final Button nextAquisitionButton = new Button();
            nextAquisitionButton.setEnabled(true);
            nextAquisitionButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    logger.finer("getting next spectrogram");
                    try {
                        mSelectionTime = nextAcquisitionTime;
                        nextAquisitionButton.setEnabled(false);
                        acquisitionDuration = 0;
                        leftBound = 0;
                        rightBound = 0;
                        window = measurementsPerAcquisition;
                        mSpectrumBrowser.showWaitImage();
                        help.setText(COMPUTING_PLEASE_WAIT);

                        mSpectrumBrowser.getSpectrumBrowserService()
                                .generateSingleAcquisitionSpectrogramAndOccupancy(mSensorId,
                                        nextAcquisitionTime, mSys2detect, mMinFreq, mMaxFreq, cutoff,
                                        FftPowerOneAcquisitionSpectrogramChart.this);
                    } catch (Throwable th) {
                        logger.log(Level.SEVERE, "Error calling spectrum browser service", th);
                    }

                }
            });
            nextAquisitionButton.setText("Next Acquisition >>");
            // .setHTML("<img border='0' src='myicons/right-arrow.png' />");
            commands.setWidget(0, 6, nextAquisitionButton);
        }
        setSpectrogramImage();
        drawOccupancyChart();
        tabPanel = new TabPanel();
        tabPanel.add(spectrogramVerticalPanel, "[Spectrogram]");
        tabPanel.add(occupancyPanel, "[Occupancy]");
        tabPanel.selectTab(0);
        vpanel.add(tabPanel);
        tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {

            @Override
            public void onSelection(SelectionEvent<Integer> event) {
                int item = event.getSelectedItem();
                if (item == 0) {
                    help.setText("Single click for detail. Double click to zoom");
                } else if (item == 1) {
                    help.setText("Single click for spectrum");
                } else {
                    help.setText("");
                }
            }
        });

    } catch (Throwable ex) {
        logger.log(Level.SEVERE, "Problem drawing specgtrogram", ex);
    }
}

From source file:gov.nist.spectrumbrowser.client.FftPowerOneDayOccupancyChart.java

License:Open Source License

public void draw() {
    ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);

    chartLoader.loadApi(new Runnable() {

        @Override//from www.ja  v a2 s. co  m
        public void run() {
            mVerticalPanel.clear();
            horizontalPanel = new HorizontalPanel();
            horizontalPanel.setWidth(SpectrumBrowser.SPEC_WIDTH + "px");
            horizontalPanel.setHeight(SpectrumBrowser.SPEC_HEIGHT + "px");

            lineChart = new LineChart();
            horizontalPanel.add(lineChart);
            drawNavigation();
            String dateString = jsonValue.isObject().get("formattedDate").isString().stringValue();
            HTML heading = new HTML("<h2>" + END_LABEL + "</h2>");
            mVerticalPanel.add(heading);
            int minFreq = (int) ((mMinFreq + 500000) / 1E6);
            int maxFreq = (int) ((mMaxFreq + 500000) / 1E6);
            int nChannels = (int) jsonValue.isObject().get(Defines.CHANNEL_COUNT).isNumber().doubleValue();
            int acquisitionCount = (int) jsonValue.isObject().get(Defines.ACQUISITION_COUNT).isNumber()
                    .doubleValue();
            int measurementsPerAcquisition = (int) jsonValue.isObject().get("measurementsPerAcquisition")
                    .isNumber().doubleValue();
            int cutoff = (int) jsonValue.isObject().get("cutoff").isNumber().doubleValue();
            HTML infoTitle = new HTML("<h3> Start Time = " + dateString + ";Detected System = " + sys2detect
                    + "; minFreq = " + minFreq + " MHz; maxFreq = " + maxFreq + " MHz" + "; nChannels = "
                    + nChannels + "; Occupancy cutoff = " + cutoff + " dBm </h3>");
            mVerticalPanel.add(infoTitle);
            HTML infoTitle1 = new HTML("<h3>Measurements Per Acquisition = " + measurementsPerAcquisition
                    + "; Acquisition Count = " + acquisitionCount + "</h3>");
            mVerticalPanel.add(infoTitle1);
            prevNextButtons = new Grid(1, 2);

            Label helpText = new Label("Click on data point to see detail.");

            mVerticalPanel.add(helpText);

            mVerticalPanel.add(prevNextButtons);

            mVerticalPanel.add(horizontalPanel);

            final long currentStartTime = (long) jsonValue.isObject().get("currentIntervalStart").isNumber()
                    .doubleValue();
            final long prevStartTime = (long) jsonValue.isObject().get("prevIntervalStart").isNumber()
                    .doubleValue();
            final long nextStartTime = (long) jsonValue.isObject().get("nextIntervalStart").isNumber()
                    .doubleValue();
            int count = 0;
            if (prevStartTime < currentStartTime) {
                Button prevIntervalButton = new Button("<< Previous Day");
                prevIntervalButton.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent event) {
                        mSpectrumBrowser.showWaitImage();
                        mSpectrumBrowser.getSpectrumBrowserService().getOneDayStats(mSensorId, lat, lon, alt,
                                prevStartTime, sys2detect, mMinFreq, mMaxFreq,
                                FftPowerOneDayOccupancyChart.this);
                    }
                });
                prevNextButtons.setWidget(0, 0, prevIntervalButton);
                count++;
            }

            if (nextStartTime > currentStartTime) {
                Button nextIntervalButton = new Button("Next Day >>");
                nextIntervalButton.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent event) {
                        mSpectrumBrowser.showWaitImage();
                        mSpectrumBrowser.getSpectrumBrowserService().getOneDayStats(mSensorId, lat, lon, alt,
                                nextStartTime, sys2detect, mMinFreq, mMaxFreq,
                                FftPowerOneDayOccupancyChart.this);

                    }
                });
                prevNextButtons.setWidget(0, 1, nextIntervalButton);
                count++;
            }

            if (count != 0) {
                prevNextButtons.setStyleName("selectionGrid");

            }
            for (int i = 0; i < prevNextButtons.getRowCount(); i++) {
                for (int j = 0; j < prevNextButtons.getColumnCount(); j++) {
                    prevNextButtons.getCellFormatter().setHorizontalAlignment(i, j,
                            HasHorizontalAlignment.ALIGN_CENTER);
                    prevNextButtons.getCellFormatter().setVerticalAlignment(i, j,
                            HasVerticalAlignment.ALIGN_MIDDLE);
                }
            }

            DataTable dataTable = DataTable.create();
            dataTable.addColumn(ColumnType.NUMBER, " Hours since start of day.");
            dataTable.addColumn(ColumnType.NUMBER, " Max");
            dataTable.addColumn(ColumnType.NUMBER, " Min");
            dataTable.addColumn(ColumnType.NUMBER, " Median");
            dataTable.addColumn(ColumnType.NUMBER, " Mean");

            JSONObject jsonObject = jsonValue.isObject().get("values").isObject();
            int rowCount = jsonObject.size();
            logger.finer("rowCount " + rowCount);
            dataTable.addRows(rowCount);
            try {
                int rowIndex = 0;
                for (String secondString : jsonObject.keySet()) {
                    JSONObject statsObject = jsonObject.get(secondString).isObject();
                    int second = Integer.parseInt(secondString);
                    long time = (long) statsObject.get("t").isNumber().doubleValue();
                    double mean = statsObject.get("meanOccupancy").isNumber().doubleValue() * 100;
                    double max = statsObject.get("maxOccupancy").isNumber().doubleValue() * 100;
                    double min = statsObject.get("minOccupancy").isNumber().doubleValue() * 100;
                    double median = statsObject.get("medianOccupancy").isNumber().doubleValue() * 100;
                    float hours = round3((double) second / (double) 3600);
                    int hourDelta = (int) hours;
                    int minutes = (int) ((((hours - hourDelta) * 60.0) / 60.0) * 60);
                    int seconds = (int) (((float) (second - hourDelta * 60 * 60 - minutes * 60) / 60.0) * 60);
                    NumberFormat nf = NumberFormat.getFormat("00");
                    dataTable.setCell(rowIndex, 0, hours,
                            nf.format(hourDelta) + ":" + nf.format(minutes) + ":" + nf.format(seconds));
                    dataTable.setCell(rowIndex, 1, round2(max), round2(max) + "%");
                    dataTable.setCell(rowIndex, 2, round2(min), round2(min) + "%");
                    dataTable.setCell(rowIndex, 3, round2(median), round2(median) + "%");
                    dataTable.setCell(rowIndex, 4, round2(mean), round2(mean) + "%");
                    selectionProperties.put(rowIndex, new SelectionProperty(time));
                    rowIndex++;
                }

                lineChart.addSelectHandler(new SelectHandler() {

                    @Override
                    public void onSelect(SelectEvent event) {
                        JsArray<Selection> selections = lineChart.getSelection();
                        int length = selections.length();
                        for (int i = 0; i < length; i++) {
                            int row = selections.get(i).getRow();
                            SelectionProperty property = selectionProperties.get(row);

                            new FftPowerOneAcquisitionSpectrogramChart(mSensorId, property.selectionTime,
                                    sys2detect, mMinFreq, mMaxFreq, mVerticalPanel, mSpectrumBrowser,
                                    navigation);
                        }
                    }
                });
                LineChartOptions options = LineChartOptions.create();
                options.setBackgroundColor("#f0f0f0");
                options.setPointSize(5);
                lineChart.setHeight(SpectrumBrowser.SPEC_HEIGHT + "px");
                lineChart.setWidth(SpectrumBrowser.SPEC_WIDTH + "px");
                HAxis haxis = HAxis.create("Hours since start of day.");
                haxis.setMinValue(0);
                haxis.setMaxValue(24);
                options.setHAxis(haxis);
                options.setVAxis(VAxis.create("Occupancy %"));
                lineChart.setStyleName("lineChart");
                lineChart.draw(dataTable, options);
                lineChart.setVisible(true);

                horizontalPanel.add(lineChart);
                mSpectrumBrowser.hideWaitImage();
            } catch (Throwable throwable) {
                logger.log(Level.SEVERE, "Problem parsing json ", throwable);
            }
        }
    });

}

From source file:gov.nist.spectrumbrowser.client.SpectrumBrowserShowDatasets.java

License:Open Source License

public void draw() {
    try {//from w  w w  . j  ava 2  s . c o m
        spectrumBrowser.showWaitImage();
        Window.setTitle("MSOD:Home");
        SpectrumBrowser.clearSensorInformation();
        sensorMarkers.clear();
        SensorGroupMarker.clear();
        verticalPanel.clear();
        navigationBar = new MenuBar();
        navigationBar.clearItems();

        verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        verticalPanel.add(navigationBar);

        HorizontalPanel mapAndSensorInfoPanel = new HorizontalPanel();
        mapAndSensorInfoPanel.setStyleName("mapAndSensorInfoPanel");

        HTML html = new HTML("<h2>" + END_LABEL + "</h2> ", true);

        verticalPanel.add(html);
        String help = "Click on a sensor marker to select it. "
                + "Then select start date and and duration of interest.";
        helpLabel = new Label();
        helpLabel.setText(help);
        verticalPanel.add(helpLabel);

        ScrollPanel scrollPanel = new ScrollPanel();
        scrollPanel.setHeight(SpectrumBrowser.MAP_WIDTH + "px");
        scrollPanel.setStyleName("sensorInformationScrollPanel");

        sensorInfoPanel = new VerticalPanel();
        sensorInfoPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        scrollPanel.add(sensorInfoPanel);
        sensorInfoPanel.setStyleName("sensorInfoPanel");

        mapAndSensorInfoPanel.add(scrollPanel);

        selectionGrid = new Grid(1, 10);
        selectionGrid.setStyleName("selectionGrid");
        selectionGrid.setVisible(false);

        for (int i = 0; i < selectionGrid.getRowCount(); i++) {
            for (int j = 0; j < selectionGrid.getColumnCount(); j++) {
                selectionGrid.getCellFormatter().setHorizontalAlignment(i, j,
                        HasHorizontalAlignment.ALIGN_CENTER);
                selectionGrid.getCellFormatter().setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE);
            }
        }

        verticalPanel.add(selectionGrid);

        sensorInfoPanel.clear();
        //sensorInfoPanel.setTitle("Click on marker to select sensors.");
        Label selectedMarkersLabel = new Label();
        selectedMarkersLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        selectedMarkersLabel.setText("Sensor Information Display");
        selectedMarkersLabel.getElement().getStyle().setCursor(Cursor.TEXT);
        selectedMarkersLabel.setStyleName("selectedMarkersLabel");
        sensorInfoPanel.add(selectedMarkersLabel);

        if (map == null) {
            MapOptions mapOptions = MapOptions.newInstance(true);
            mapOptions.setMaxZoom(15);
            mapOptions.setMinZoom(3);
            mapOptions.setStreetViewControl(false);
            map = new MapWidget(mapOptions);
            //map.setTitle("Click on a marker to display information about a sensor.");
            map.setSize(SpectrumBrowser.MAP_WIDTH + "px", SpectrumBrowser.MAP_HEIGHT + "px");
        } else if (map.getParent() != null) {
            map.removeFromParent();
        }
        mapAndSensorInfoPanel.add(map);
        verticalPanel.add(mapAndSensorInfoPanel);
        logger.finer("getLocationInfo");

        spectrumBrowser.getSpectrumBrowserService().getLocationInfo(SpectrumBrowser.getSessionToken(),
                new SpectrumBrowserCallback<String>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        logger.log(Level.SEVERE, "Error in processing request", caught);
                        verticalPanel.clear();

                        if (spectrumBrowser.isUserLoggedIn()) {
                            Window.alert("The system is down for maintenance. Please try again later.\n"
                                    + caught.getMessage());
                            spectrumBrowser.logoff();
                        } else {
                            HTML error = new HTML(
                                    "<h1>The System is down for maintenance. Please try later.</h1>");
                            verticalPanel.add(error);
                            HTML errorMsg = new HTML("<h2>" + caught.getMessage() + "</h2>");
                            verticalPanel.add(errorMsg);
                        }
                    }

                    @Override
                    public void onSuccess(String jsonString) {

                        try {
                            logger.finer(jsonString);
                            JSONObject jsonObj = (JSONObject) JSONParser.parseLenient(jsonString);

                            String baseUrl = SpectrumBrowser.getBaseUrlAuthority();
                            addSensor(jsonObj, baseUrl);

                            logger.finer("Added returned sensors. Dealing with peers");
                            // Now deal with the peers.
                            final JSONObject peers = jsonObj.get("peers").isObject();
                            // By definition, peers do not need login but we need a session
                            // Key to talk to the peer so go get one.
                            for (String url : peers.keySet()) {
                                logger.finer("Showing sensors for Peer " + url);
                                final String peerUrl = url;
                                spectrumBrowser.getSpectrumBrowserService().isAuthenticationRequired(url,
                                        new SpectrumBrowserCallback<String>() {

                                            @Override
                                            public void onSuccess(String result) {
                                                JSONObject jobj = JSONParser.parseLenient(result).isObject();
                                                boolean authRequired = jobj.get("AuthenticationRequired")
                                                        .isBoolean().booleanValue();
                                                if (!authRequired) {
                                                    String sessionToken = jobj.get("SessionToken").isString()
                                                            .stringValue();
                                                    SpectrumBrowser.setSessionToken(peerUrl, sessionToken);
                                                    JSONObject peerObj = peers.get(peerUrl).isObject();
                                                    addSensor(peerObj, peerUrl);
                                                }
                                            }

                                            @Override
                                            public void onFailure(Throwable throwable) {
                                                logger.log(Level.SEVERE, "Could not contact peer at " + peerUrl,
                                                        throwable);
                                            }
                                        });
                            }
                            final Timer timer = new Timer() {
                                @Override
                                public void run() {
                                    if (getMap().isAttached()) {
                                        spectrumBrowser.hideWaitImage();
                                        showMarkers();
                                        cancel();
                                    }
                                }
                            };
                            timer.scheduleRepeating(500);
                            populateMenuItems();

                            map.addZoomChangeHandler(new ZoomChangeMapHandler() {

                                @Override
                                public void onEvent(ZoomChangeMapEvent event) {
                                    SensorGroupMarker.showMarkers();
                                }
                            });

                        } catch (Exception ex) {
                            logger.log(Level.SEVERE, "Error ", ex);
                            spectrumBrowser.displayError("Error parsing json response");

                        }

                    }
                }

        );

    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Error in displaying data sets", ex);
    }
}

From source file:gov.nist.spectrumbrowser.client.SweptFrequencyOneDaySpectrogramChart.java

License:Open Source License

public void draw() {
    try {//from  w  w w .  jav  a2  s . c o  m
        vpanel.clear();
        drawNavigation();
        HTML pageTitle = new HTML("<h2>" + END_LABEL + "</h2>");
        vpanel.add(pageTitle);
        HTML title = new HTML("<H3>Detected System = " + mSys2detect + "; Start Time = "
                + localDateOfAcquisition + "; Occupancy Threshold = " + cutoff + " dBm; minPower = " + minPower
                + " dBm; maxPower = " + maxPower + " dBm</H3>");

        vpanel.add(title);
        HTML title1 = new HTML("<h3>Aquisition Count = " + acquisitionCount + "; max occupancy = "
                + maxOccupancy + "%; min occupancy = " + minOccupancy + "%; mean occupancy = " + meanOccupancy
                + "%; median occupancy = " + medianOccupancy + "%</h3>");
        vpanel.add(title1);
        HTML title3 = new HTML("<h3> Equiv. Noise BW = " + enbw + " Hz; Resolution BW = " + rbw + " Hz. </h3>");
        vpanel.add(title3);
        HTML help = new HTML("<p>Click on spectrogram or occupancy plot for detail. "
                + "Move slider and and click on redraw button to change threshold and redraw.</p>");
        vpanel.add(help);

        grid = new Grid(1, 4);

        vpanel.add(grid);
        grid.setStyleName("selectionGrid");

        for (int i = 0; i < grid.getRowCount(); i++) {
            for (int j = 0; j < grid.getColumnCount(); j++) {
                grid.getCellFormatter().setHorizontalAlignment(i, j, HasHorizontalAlignment.ALIGN_CENTER);
                grid.getCellFormatter().setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE);
            }
        }

        spectrogramVerticalPanel = new VerticalPanel();

        hpanel = new HorizontalPanel();

        hpanel.setSpacing(10);
        hpanel.setStyleName("spectrogram");
        xaxisPanel = new HorizontalPanel();
        xaxisPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        HorizontalPanel xaxis = new HorizontalPanel();
        xaxis.setWidth(canvasPixelWidth + 30 + "px");
        xaxis.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        xaxis.add(new Label("0"));
        xaxis.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        xaxis.add(new Label("Time (hours) since start of day"));
        xaxis.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        xaxis.add(new Label(Double.toString(timeDelta)));
        xaxisPanel.add(xaxis);

        // Attach the previous reading button.

        if (prevAcquisitionTime != tStartTimeUtc) {

            final Button prevDayButton = new Button();
            prevDayButton.setEnabled(true);
            prevDayButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    mSelectionTime = prevAcquisitionTime;
                    mSpectrumBrowser.showWaitImage();
                    infoLabel.setText(COMPUTING_PLEASE_WAIT);
                    mSpectrumBrowser.getSpectrumBrowserService().generateSingleDaySpectrogramAndOccupancy(
                            mSensorId, mLat, mLon, mAlt, prevAcquisitionTime, mSys2detect, mMinFreq, mMaxFreq,
                            mSubBandMinFreq, mSubBandMaxFreq, cutoff,
                            SweptFrequencyOneDaySpectrogramChart.this);

                }
            });

            prevDayButton.setText("< Previous Day");

            grid.setWidget(0, 0, prevDayButton);
        }

        // Attach the labels for the spectrogram power
        VerticalPanel powerLevelPanel = new VerticalPanel();
        powerLevelPanel.setWidth(100 + "px");
        this.maxPowerLabel = new Label();
        this.minPowerLabel = new Label();
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
        powerLevelPanel.add(maxPowerLabel);
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        powerLevelPanel.add(new Label("Power (dBm) "));
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
        powerLevelPanel.add(minPowerLabel);
        // Attach labels for the frequency.
        freqPanel = new VerticalPanel();
        freqPanel.setWidth(100 + "px");
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
        freqPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
        freqPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        freqPanel.add(new Label(Double.toString(maxFreqMhz)));

        freqPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        freqPanel.add(new Label("Frequency (MHz)"));
        freqPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
        freqPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        freqPanel.add(new Label(Double.toString(minFreqMhz)));
        logger.finest("minFreq = " + minFreqMhz);
        powerMapPanel = new HorizontalPanel();
        powerMapPanel.setWidth(30 + "px");
        hpanel.add(freqPanel);
        spectrogramPanel = new VerticalPanel();

        HorizontalPanel spectrogramAndPowerMapPanel = new HorizontalPanel();
        spectrogramAndPowerMapPanel.add(spectrogramPanel);
        spectrogramAndPowerMapPanel.add(powerMapPanel);
        hpanel.add(spectrogramAndPowerMapPanel);
        infoLabel = new Label("Click on spectrogram for power spectrum at selected time.");
        spectrogramVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        spectrogramVerticalPanel.add(infoLabel);
        spectrogramVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        spectrogramVerticalPanel.add(hpanel);
        String helpString = "Single click for power spectrum.";
        String powerString = "Single click for power occupancy.";

        // Add the slider bar for min occupancy selection.
        occupancyMinPowerVpanel = new VerticalPanel();
        occupancyMinPowerVpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        occupancyMinPowerVpanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

        occupancyMinPowerSliderBar = new SliderBarSimpleVertical(100, canvasPixelHeight + "px", true);
        occupancyMinPowerVpanel.add(occupancyMinPowerSliderBar);

        occupancyMinPowerSliderBar.setMaxValue(100);

        this.occupancyMinPowerLabel = new Label();
        occupancyMinPowerVpanel.add(occupancyMinPowerLabel);
        final Button generateSpectrogramButton = new Button("Cutoff and Redraw");
        grid.setWidget(0, 1, generateSpectrogramButton);
        generateSpectrogramButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                generateSpectrogramButton.setEnabled(false);
                mSpectrumBrowser.showWaitImage();
                mSpectrumBrowser.getSpectrumBrowserService().generateSingleDaySpectrogramAndOccupancy(mSensorId,
                        mLat, mLon, mAlt, mSelectionTime, mSys2detect, mMinFreq, mMaxFreq, mSubBandMinFreq,
                        mSubBandMaxFreq, occupancyMinPower, SweptFrequencyOneDaySpectrogramChart.this);

            }
        });

        // Close all the tabs.
        final Button closeTabsButton = new Button("Close Tabs");
        closeTabsButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                tabPanel.clear();
                tabPanel.add(spectrogramVerticalPanel, "[Spectrogram]");
                tabPanel.add(occupancyPanel, "[Occupancy]");
                tabPanel.selectTab(0);
            }
        });
        grid.setWidget(0, 2, closeTabsButton);

        occupancyMinPowerSliderBar
                .addBarValueChangedHandler(new OccupancyMinPowerSliderHandler(occupancyMinPowerLabel, cutoff));
        int initialValue = (int) ((double) (maxPower - cutoff) / (double) (maxPower - minPower) * 100 + 0.5);
        occupancyMinPowerSliderBar.setValue(initialValue);
        hpanel.add(occupancyMinPowerVpanel);

        spectrogramPanel.setTitle(helpString);
        //powerMapPanel.setTitle(helpString);
        spectrumAndOccupancyPanel = new VerticalPanel();
        spectrumAndOccupancyPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        spectrogramVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        spectrogramVerticalPanel.add(spectrumAndOccupancyPanel);

        occupancyPanel = new VerticalPanel();
        occupancyPanel.setWidth(canvasPixelWidth + "px");
        occupancyPanel.setHeight(canvasPixelHeight + "px");
        occupancyPanel.setPixelSize(canvasPixelWidth, canvasPixelHeight);
        occupancyPanel.setTitle(powerString);

        // Attach the next spectrogram panel.
        if (nextAcquisitionTime != tStartTimeUtc) {
            final Button nextDayButton = new Button();
            nextDayButton.setEnabled(true);
            nextDayButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    logger.finer("getting next spectrogram");
                    try {
                        mSelectionTime = nextAcquisitionTime;
                        nextDayButton.setEnabled(false);
                        mSpectrumBrowser.showWaitImage();
                        infoLabel.setText(COMPUTING_PLEASE_WAIT);
                        mSpectrumBrowser.getSpectrumBrowserService().generateSingleDaySpectrogramAndOccupancy(
                                mSensorId, mLat, mLon, mAlt, nextAcquisitionTime, mSys2detect, mMinFreq,
                                mMaxFreq, mSubBandMinFreq, mSubBandMaxFreq, cutoff,
                                SweptFrequencyOneDaySpectrogramChart.this);
                    } catch (Throwable th) {
                        logger.log(Level.SEVERE, "Error calling spectrum browser service", th);
                    }

                }
            });
            nextDayButton.setText("Next Day >");
            grid.setWidget(0, 3, nextDayButton);

        }
        setSpectrogramImage();
        drawOccupancyChart();
        tabPanel = new TabPanel();
        tabPanel.add(spectrogramVerticalPanel, "[Spectrogram]");
        tabPanel.add(occupancyPanel, "[Occupancy]");
        tabPanel.selectTab(0);
        vpanel.add(tabPanel);

    } catch (Throwable ex) {
        logger.log(Level.SEVERE, "Problem drawing specgtrogram", ex);
    }
}

From source file:gov.nist.spectrumbrowser.client.TextInputBox.java

License:Open Source License

public TextInputBox(String label, String initialText) {
    horizontalPanel = new HorizontalPanel();
    horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    initWidget(horizontalPanel);/*from  w  ww. j a  va2 s. com*/
    this.label = new Label();
    textBox = new TextBox();
    textBox.setWidth("30px");
    this.label.setText(label);
    horizontalPanel.add(this.label);
    horizontalPanel.add(textBox);
    textBox.setText(initialText);
    textBox.setAlignment(TextAlignment.CENTER);
}

From source file:it.pianetatecno.gwt.utility.client.suggest.MySuggestBox.java

License:Apache License

public MySuggestBox(SuggestOracle oracle) {
    HorizontalPanel panel = new HorizontalPanel();
    immagine = new Image(images.iconCloseSmall());
    immagine.setStyleName(CSS_PREFIX + "pointer");

    suggestBox = new SuggestBox(oracle);
    panel.add(suggestBox);//www  .  jav  a  2s .  c o m

    panel.add(immagine);
    panel.setCellVerticalAlignment(immagine, HasVerticalAlignment.ALIGN_MIDDLE);

    addHandler();

    initWidget(panel);
}

From source file:kurosawa.dictionary.main.client.Main.java

License:Open Source License

public void onModuleLoad() {
    RootPanel rootPanel = RootPanel.get();
    rootPanel.setStyleName("rootPanel");

    VerticalPanel verticalPanel = new VerticalPanel();
    rootPanel.add(verticalPanel, 5, 5);//from  www  . j  av a 2s .c  o m
    verticalPanel.setSize("244px", "162px");

    horizontalPanel = new HorizontalPanel();
    horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    verticalPanel.add(horizontalPanel);
    horizontalPanel.setWidth("100%");

    HTML htmlNewHtml = new HTML("<h3></h3>", true);
    htmlNewHtml.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    horizontalPanel.add(htmlNewHtml);
    htmlNewHtml.setWidth("59px");

    Label lblNewLabel = new Label("20120814Dictionary");
    lblNewLabel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    horizontalPanel.add(lblNewLabel);

    HorizontalPanel horizontalPanel_1 = new HorizontalPanel();
    horizontalPanel_1.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    verticalPanel.add(horizontalPanel_1);

    Label lblNewLabel_1 = new Label("");
    horizontalPanel_1.add(lblNewLabel_1);
    lblNewLabel_1.setSize("48px", "");

    txbEnglish = new TextBox();
    horizontalPanel_1.add(txbEnglish);

    HorizontalPanel horizontalPanel_2 = new HorizontalPanel();
    horizontalPanel_2.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    verticalPanel.add(horizontalPanel_2);

    Label lblNewLabel_2 = new Label("");
    horizontalPanel_2.add(lblNewLabel_2);
    lblNewLabel_2.setSize("48px", "");

    txbJapanese = new TextBox();
    horizontalPanel_2.add(txbJapanese);

    HorizontalPanel horizontalPanel_3 = new HorizontalPanel();
    verticalPanel.add(horizontalPanel_3);

    btnSearch = new Button();
    btnSearch.setHTML("");
    horizontalPanel_3.add(btnSearch);
    btnSearch.setText("");

    btnAdd = new Button("");
    btnAdd.setText("");
    horizontalPanel_3.add(btnAdd);

    btnDelete = new Button("");
    horizontalPanel_3.add(btnDelete);

    btnSearch.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            txbJapanese.setText("");
            lblMessage.setText("");
            dictionaryService.search(txbEnglish.getText(), new AsyncCallback<DictionaryServiceResponse>() {

                public void onFailure(Throwable caught) {
                    Window.alert(":" + caught.getMessage());
                }

                public void onSuccess(DictionaryServiceResponse response) {
                    txbJapanese.setText(response.getJapanese());
                    lblMessage.setText(response.getMessage());
                }

            });

        }
    });

    btnAdd.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            lblMessage.setText("");
            dictionaryService.add(txbEnglish.getText(), txbJapanese.getText(),
                    new AsyncCallback<DictionaryServiceResponse>() {

                        public void onFailure(Throwable caught) {
                            Window.alert(":" + caught.getMessage());
                        }

                        public void onSuccess(DictionaryServiceResponse response) {
                            lblMessage.setText(response.getMessage());
                        }

                    });

        }
    });

    btnDelete.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            txbJapanese.setText("");
            lblMessage.setText("");
            dictionaryService.delete(txbEnglish.getText(), new AsyncCallback<DictionaryServiceResponse>() {

                public void onFailure(Throwable caught) {
                    Window.alert(":" + caught.getMessage());
                }

                public void onSuccess(DictionaryServiceResponse response) {
                    txbJapanese.setText(response.getJapanese());
                    lblMessage.setText(response.getMessage());
                }

            });

        }
    });

    HorizontalPanel horizontalPanel_4 = new HorizontalPanel();
    verticalPanel.add(horizontalPanel_4);

    lblMessage = new Label("");
    horizontalPanel_4.add(lblMessage);
}