@Override protected void updateComponents() { if (!isInitialized || !isVisible()) { return; } super.updateComponents(); chart.setTitle( getRaster() != null ? CHART_TITLE + " for " + getRaster().getName() : CHART_TITLE); updateXAxis(); if (xAxisRangeControl.isAutoMinMax()) { xAxisRangeControl .getBindingContext() .getPropertySet() .getDescriptor("min") .setDefaultValue(HISTO_MIN_DEFAULT); xAxisRangeControl .getBindingContext() .getPropertySet() .getDescriptor("max") .setDefaultValue(HISTO_MAX_DEFAULT); } dataset = null; handleStxChange(); updateRefreshButton(); }
private void initParameters() { final PropertyChangeListener recomputeListener = evt -> computeChartDataIfPossible(); bindingContext.addPropertyChangeListener( RoiMaskSelector.PROPERTY_NAME_USE_ROI_MASK, recomputeListener); bindingContext.addPropertyChangeListener( RoiMaskSelector.PROPERTY_NAME_ROI_MASK, recomputeListener); bindingContext.addPropertyChangeListener(PROPERTY_NAME_BOX_SIZE, recomputeListener); bindingContext.addPropertyChangeListener(PROPERTY_NAME_DATA_FIELD, recomputeListener); final PropertyChangeListener computeLineDataListener = evt -> computeRegressionAndAcceptableDeviationData(); bindingContext.addPropertyChangeListener( PROPERTY_NAME_SHOW_ACCEPTABLE_DEVIATION, computeLineDataListener); bindingContext.addPropertyChangeListener( PROPERTY_NAME_ACCEPTABLE_DEVIATION, computeLineDataListener); bindingContext.addPropertyChangeListener( PROPERTY_NAME_SHOW_REGRESSION_LINE, computeLineDataListener); final PropertyChangeListener rangeLabelUpdateListener = evt -> { final VectorDataNode pointDataSource = scatterPlotModel.pointDataSource; final AttributeDescriptor dataField = scatterPlotModel.dataField; if (dataField != null && pointDataSource != null) { final String dataFieldName = dataField.getLocalName(); getPlot().getDomainAxis().setLabel(dataFieldName); xAxisRangeControl.setTitleSuffix(dataFieldName); } else { getPlot().getDomainAxis().setLabel(""); xAxisRangeControl.setTitleSuffix(""); } }; bindingContext.addPropertyChangeListener(PROPERTY_NAME_DATA_FIELD, rangeLabelUpdateListener); bindingContext.addPropertyChangeListener( PROPERTY_NAME_POINT_DATA_SOURCE, rangeLabelUpdateListener); bindingContext.addPropertyChangeListener( PROPERTY_NAME_X_AXIS_LOG_SCALED, evt -> updateScalingOfXAxis()); bindingContext.addPropertyChangeListener( PROPERTY_NAME_Y_AXIS_LOG_SCALED, evt -> updateScalingOfYAxis()); xAxisRangeControl .getBindingContext() .addPropertyChangeListener( evt -> handleAxisRangeControlChanges( evt, xAxisRangeControl, getPlot().getDomainAxis(), xAutoRangeAxisRange)); yAxisRangeControl .getBindingContext() .addPropertyChangeListener( evt -> handleAxisRangeControlChanges( evt, yAxisRangeControl, getPlot().getRangeAxis(), yAutoRangeAxisRange)); }
private void updateChartData(boolean recompute) { final boolean autoMinMaxEnabled = getAutoMinMaxEnabled(); final Double min; final Double max; if (autoMinMaxEnabled) { min = null; max = null; } else { min = (Double) xAxisRangeControl.getBindingContext().getBinding("min").getPropertyValue(); max = (Double) xAxisRangeControl.getBindingContext().getBinding("max").getPropertyValue(); } new StxWorker(min, max, autoMinMaxEnabled, recompute).execute(); }
private void createUI() { dataset = new XIntervalSeriesCollection(); chart = ChartFactory.createHistogram( CHART_TITLE, "Values", "Frequency in #pixels", dataset, PlotOrientation.VERTICAL, false, // Legend? true, // tooltips false // url ); final XYPlot xyPlot = chart.getXYPlot(); xyPlot.setDomainZeroBaselineStroke(new BasicStroke(0.2f)); final XYBarRenderer renderer = (XYBarRenderer) xyPlot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setShadowVisible(false); renderer.setShadowYOffset(-4.0); renderer.setBaseToolTipGenerator(new XYPlotToolTipGenerator()); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setSeriesPaint(0, new Color(0, 0, 200)); createUI(createChartPanel(chart), createOptionsPanel(), bindingContext); isInitialized = true; final Binding minBinding = xAxisRangeControl.getBindingContext().getBinding("min"); final double min = (Double) minBinding.getPropertyValue(); final Binding maxBinding = xAxisRangeControl.getBindingContext().getBinding("max"); final double max = (Double) maxBinding.getPropertyValue(); if (!histogramComputing && min > max) { minBinding.setPropertyValue(max); maxBinding.setPropertyValue(min); } updateXAxis(); }
private void updateLogXAxisCheckBox() { HistogramPanelModel.HistogramConfig config = createHistogramConfig(); final boolean enabled = dataset != null && model.hasStx(config) && model.getStx(config).getMinimum() > 0 && !model.getStx(config).isLogHistogram(); Binding binding = xAxisRangeControl.getBindingContext().getBinding(PROPERTY_NAME_LOG_SCALED); if (!enabled) { binding.setPropertyValue(false); } log10AxisEnablement.apply(); binding.adjustComponents(); }
private JPanel createOptionsPanel() { final JLabel numBinsLabel = new JLabel("#Bins:"); JTextField numBinsField = new JTextField(Integer.toString(NUM_BINS_DEFAULT)); numBinsField.setPreferredSize(new Dimension(50, numBinsField.getPreferredSize().height)); final JCheckBox histoLogCheck = new JCheckBox("Log10 scaled bins"); histoLogCheck.addActionListener(configChangeListener); bindingContext .getPropertySet() .getDescriptor(PROPERTY_NAME_NUM_BINS) .setDescription("Set the number of bins in the histogram"); bindingContext .getPropertySet() .getDescriptor(PROPERTY_NAME_NUM_BINS) .setValueRange(new ValueRange(2.0, 2048.0)); bindingContext .getPropertySet() .getDescriptor(PROPERTY_NAME_NUM_BINS) .setDefaultValue(NUM_BINS_DEFAULT); bindingContext.bind(PROPERTY_NAME_NUM_BINS, numBinsField); bindingContext .getPropertySet() .getDescriptor(PROPERTY_NAME_LOGARITHMIC_HISTOGRAM) .setDescription("Use log-10 scaled values for computation of histogram"); bindingContext .getPropertySet() .getDescriptor(PROPERTY_NAME_LOGARITHMIC_HISTOGRAM) .setDefaultValue(false); bindingContext.bind(PROPERTY_NAME_LOGARITHMIC_HISTOGRAM, histoLogCheck); log10HistEnablement = bindingContext.bindEnabledState( PROPERTY_NAME_LOGARITHMIC_HISTOGRAM, true, new Enablement.Condition() { @Override public boolean evaluate(BindingContext bindingContext) { return getRaster() != null && getRaster().getStx().getMaximum() > 0; } }); PropertyChangeListener logChangeListener = new AxisControlChangeListener(); xAxisRangeControl.getBindingContext().addPropertyChangeListener(logChangeListener); xAxisRangeControl .getBindingContext() .getPropertySet() .addProperty( bindingContext.getPropertySet().getProperty(PROPERTY_NAME_LOGARITHMIC_HISTOGRAM)); xAxisRangeControl .getBindingContext() .getPropertySet() .addProperty(bindingContext.getPropertySet().getProperty(PROPERTY_NAME_LOG_SCALED)); xAxisRangeControl .getBindingContext() .getPropertySet() .getDescriptor(PROPERTY_NAME_LOG_SCALED) .setDescription("Toggle whether to use a logarithmic x-axis"); log10AxisEnablement = xAxisRangeControl .getBindingContext() .bindEnabledState( PROPERTY_NAME_LOG_SCALED, true, new Enablement.Condition() { @Override public boolean evaluate(BindingContext bindingContext) { HistogramPanelModel.HistogramConfig currentConfig = createHistogramConfig(); boolean hasStx = model.hasStx(currentConfig); // log10 xAxis is enabled when current histogram exists and is NOT log10 scaled return dataset != null && hasStx && !model.getStx(currentConfig).isLogHistogram(); } }); JPanel dataSourceOptionsPanel = GridBagUtils.createPanel(); GridBagConstraints dataSourceOptionsConstraints = GridBagUtils.createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2"); GridBagUtils.addToPanel( dataSourceOptionsPanel, new JLabel(" "), dataSourceOptionsConstraints, "gridwidth=2,gridy=0,gridx=0,weightx=0"); GridBagUtils.addToPanel( dataSourceOptionsPanel, numBinsLabel, dataSourceOptionsConstraints, "insets.top=2,insets.left=4,gridwidth=1,gridy=1,gridx=0,weightx=1"); GridBagUtils.addToPanel( dataSourceOptionsPanel, numBinsField, dataSourceOptionsConstraints, "insets.top=0,insets.left=0,insets.right=2,gridwidth=1,gridy=1,gridx=1"); GridBagUtils.addToPanel( dataSourceOptionsPanel, histoLogCheck, dataSourceOptionsConstraints, "insets.right=0,gridwidth=2,gridy=2,gridx=0"); xAxisRangeControl .getBindingContext() .bind(PROPERTY_NAME_LOG_SCALED, new JCheckBox("Log10 scaled")); xAxisRangeControl .getBindingContext() .addPropertyChangeListener( PROPERTY_NAME_LOG_SCALED, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { ValueAxis oldAxis = chart.getXYPlot().getDomainAxis(); ValueAxis newAxis = StatisticChartStyling.updateScalingOfAxis( (Boolean) evt.getNewValue(), oldAxis, true); chart.getXYPlot().setDomainAxis(newAxis); } }); JPanel displayOptionsPanel = GridBagUtils.createPanel(); GridBagConstraints displayOptionsConstraints = GridBagUtils.createConstraints("anchor=SOUTH,fill=HORIZONTAL,weightx=1"); GridBagUtils.addToPanel( displayOptionsPanel, xAxisRangeControl.getPanel(), displayOptionsConstraints, "gridy=2"); JPanel optionsPanel = GridBagUtils.createPanel(); GridBagConstraints gbc = GridBagUtils.createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1"); GridBagUtils.addToPanel(optionsPanel, dataSourceOptionsPanel, gbc, "gridy=0"); GridBagUtils.addToPanel(optionsPanel, new JPanel(), gbc, "gridy=1,fill=VERTICAL,weighty=1"); GridBagUtils.addToPanel( optionsPanel, displayOptionsPanel, gbc, "gridy=2,fill=HORIZONTAL,weighty=0"); GridBagUtils.addToPanel(optionsPanel, new JPanel(), gbc, "gridy=3,fill=VERTICAL,weighty=1"); GridBagUtils.addToPanel( optionsPanel, xAxisRangeControl .getBindingContext() .getBinding(PROPERTY_NAME_LOG_SCALED) .getComponents()[0], gbc, "gridy=4"); return optionsPanel; }