@Test public void variablesProperty() { final JTable table = new JTable(); bindingContext.bind("conditions", new ConditionsTableAdapter(table)); assertTrue(table.getModel() instanceof DefaultTableModel); final DefaultTableModel tableModel = (DefaultTableModel) table.getModel(); tableModel.addRow((Object[]) null); tableModel.addRow((Object[]) null); assertEquals(2, table.getRowCount()); table.setValueAt("a", 0, 0); assertEquals("a", table.getValueAt(0, 0)); table.setValueAt("A", 0, 1); assertEquals("A", table.getValueAt(0, 1)); table.setValueAt(true, 0, 2); assertEquals(true, table.getValueAt(0, 2)); table.setValueAt("b", 1, 0); assertEquals("b", table.getValueAt(1, 0)); table.setValueAt("B", 1, 1); assertEquals("B", table.getValueAt(1, 1)); table.setValueAt(false, 1, 2); assertEquals(false, table.getValueAt(1, 2)); bindingContext .getPropertySet() .setValue("conditions", new MosaicOp.Condition[] {new MosaicOp.Condition("d", "D", true)}); assertEquals(1, table.getRowCount()); assertEquals("d", table.getValueAt(0, 0)); assertEquals("D", table.getValueAt(0, 1)); assertEquals(true, table.getValueAt(0, 2)); }
public void setComponentsEnabled(boolean enabled) { if (!enabled) { for (Property property : bindingContext.getPropertySet().getProperties()) { bindingContext.setComponentsEnabled(property.getName(), enabled); } } else { for (Property property : bindingContext.getPropertySet().getProperties()) { if (property.getName().equals("min") || property.getName().equals("max")) { bindingContext.setComponentsEnabled(property.getName(), !isAutoMinMax()); } else { bindingContext.setComponentsEnabled(property.getName(), enabled); } } } }
private JComponent[] createComponents( String propertyName, Class<? extends PropertyEditor> editorClass) { PropertyDescriptor descriptor = bindingContext.getPropertySet().getDescriptor(propertyName); PropertyEditor editor = PropertyEditorRegistry.getInstance().getPropertyEditor(editorClass.getName()); return editor.createComponents(descriptor, bindingContext); }
private void makeUI() { JComponent[] variableComponents = createComponents(PROPERTY_VARIABLE_NAME, TextFieldEditor.class); final TableLayout layout = new TableLayout(2); layout.setTablePadding(4, 3); layout.setCellWeightX(0, 1, 1.0); layout.setCellWeightX(1, 1, 1.0); layout.setCellWeightX(2, 0, 1.0); layout.setCellColspan(2, 0, 2); layout.setTableFill(TableLayout.Fill.HORIZONTAL); final JPanel panel = new JPanel(layout); panel.add(variableComponents[1]); panel.add(variableComponents[0]); JLabel expressionLabel = new JLabel("Variable expression:"); JTextArea expressionArea = new JTextArea(); expressionArea.setRows(3); TextComponentAdapter textComponentAdapter = new TextComponentAdapter(expressionArea); bindingContext.bind(PROPERTY_EXPRESSION, textComponentAdapter); panel.add(expressionLabel); panel.add(layout.createHorizontalSpacer()); panel.add(expressionArea); JButton editExpressionButton = new JButton("Edit Expression..."); editExpressionButton.setName("editExpressionButton"); editExpressionButton.addActionListener(createEditExpressionButtonListener()); panel.add(layout.createHorizontalSpacer()); panel.add(editExpressionButton); setContent(panel); }
@Override protected void initComponents() { SnapApp.getDefault() .getSelectionSupport(ProductNode.class) .addHandler( (oldValue, newValue) -> { if (newValue != null) { handleMasklessProduct(newValue.getProduct()); } }); SnapApp.getDefault() .getProductManager() .addListener( new ProductManager.Listener() { @Override public void productAdded(ProductManager.Event event) { // do nothing } @Override public void productRemoved(ProductManager.Event event) { model.removeStxFromProduct(event.getProduct()); } }); model = new HistogramPanelModel(); xAxisRangeControl = new AxisRangeControl("X-Axis"); histogramPlotConfig = new HistogramPlotConfig(); bindingContext = new BindingContext(PropertyContainer.createObjectBacked(histogramPlotConfig)); configChangeListener = new ConfigChangeListener(); bindingContext.addPropertyChangeListener(configChangeListener); createUI(); updateComponents(); }
private void handleMasklessProduct(Product product) { if (product != null && product.getMaskGroup().getNodeCount() == 0) { try { bindingContext.getPropertySet().getProperty("useRoiMask").setValue(Boolean.FALSE); } catch (ValidationException e) { throw new IllegalStateException("Cannot come here"); } } }
ScatterPlotPanel(TopComponent parentDialog, String helpId) { super(parentDialog, helpId, CHART_TITLE, false); userSettingsMap = new HashMap<>(); productRemovedListener = new ProductManager.Listener() { @Override public void productAdded(ProductManager.Event event) {} @Override public void productRemoved(ProductManager.Event event) { final UserSettings userSettings = userSettingsMap.remove(event.getProduct()); if (userSettings != null) { userSettings.dispose(); } } }; xAxisRangeControl = new AxisRangeControl("X-Axis"); yAxisRangeControl = new AxisRangeControl("Y-Axis"); scatterPlotModel = new ScatterPlotModel(); bindingContext = new BindingContext(PropertyContainer.createObjectBacked(scatterPlotModel)); scatterpointsDataset = new XYIntervalSeriesCollection(); acceptableDeviationDataset = new XYIntervalSeriesCollection(); regressionDataset = new XYIntervalSeriesCollection(); r2Annotation = new XYTitleAnnotation(0, 0, new TextTitle("")); chart = ChartFactory.createScatterPlot( CHART_TITLE, "", "", scatterpointsDataset, PlotOrientation.VERTICAL, true, true, false); chart.getXYPlot().setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); createDomainAxisChangeListener(); final PropertyChangeListener userSettingsUpdateListener = evt -> { if (getRaster() != null) { final VectorDataNode pointDataSourceValue = scatterPlotModel.pointDataSource; final AttributeDescriptor dataFieldValue = scatterPlotModel.dataField; final UserSettings userSettings = getUserSettings(getRaster().getProduct()); userSettings.set(getRaster().getName(), pointDataSourceValue, dataFieldValue); } }; bindingContext.addPropertyChangeListener(PROPERTY_NAME_DATA_FIELD, userSettingsUpdateListener); bindingContext.addPropertyChangeListener( PROPERTY_NAME_POINT_DATA_SOURCE, userSettingsUpdateListener); }
private void bindComponents() { final BindingContext bc = new BindingContext(model.getValueContainer()); bc.bind("productName", productNameTextField); bc.bind("productDir", productDirTextField); if (!alwaysWriteOutput) { bc.bind("saveToFileSelected", saveToFileCheckBox); bc.bind("openInAppSelected", openInAppCheckBox); bc.bind("formatName", formatNameComboBox); } model .getValueContainer() .addPropertyChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if (propertyName.equals(TargetProductSelectorModel.PROPERTY_PRODUCT_DIR)) { productDirTextField.setToolTipText(model.getProductDir().getPath()); } else { updateUIState(); } } }); }
private void bindComponents() { final BindingContext bc = new BindingContext(model.getValueContainer()); bc.bind("productName", productNameTextField); bc.bind("saveToFileSelected", saveToFileCheckBox); bc.bind("openInAppSelected", openInAppCheckBox); bc.bind("formatName", formatNameComboBox); bc.bind("productDir", productDirTextField); model .getValueContainer() .addPropertyChangeListener( "productDir", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { productDirTextField.setToolTipText(model.getProductDir().getPath()); } }); model .getValueContainer() .addPropertyChangeListener( "formatName", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { updateUIState(); } }); }
private void editSliderSample(MouseEvent evt, final int sliderIndex) { final PropertyContainer vc = new PropertyContainer(); vc.addProperty(Property.create("sample", getSliderSample(sliderIndex))); vc.getDescriptor("sample").setDisplayName("sample"); vc.getDescriptor("sample").setUnit(getModel().getParameterUnit()); final ValueRange valueRange; if (sliderIndex == 0) { valueRange = new ValueRange(Double.NEGATIVE_INFINITY, round(getMaxSliderSample(sliderIndex))); } else if (sliderIndex == getSliderCount() - 1) { valueRange = new ValueRange(round(getMinSliderSample(sliderIndex)), Double.POSITIVE_INFINITY); } else { valueRange = new ValueRange( round(getMinSliderSample(sliderIndex)), round(getMaxSliderSample(sliderIndex))); } vc.getDescriptor("sample").setValueRange(valueRange); final BindingContext ctx = new BindingContext(vc); final NumberFormatter formatter = new NumberFormatter(new DecimalFormat("#0.0#")); formatter.setValueClass(Double.class); // to ensure that double values are returned final JFormattedTextField field = new JFormattedTextField(formatter); field.setColumns(11); field.setHorizontalAlignment(JFormattedTextField.RIGHT); ctx.bind("sample", field); showPopup(evt, field); ctx.addPropertyChangeListener( "sample", pce -> { hidePopup(); setSliderSample(sliderIndex, (Double) ctx.getBinding("sample").getPropertyValue()); computeZoomInToSliderLimits(); applyChanges(); }); }
@Override protected void configure(BindingContext context) { Enablement enablementAvgGridSize = context.bindEnabledState( GraticuleLayerType.PROPERTY_NAME_RES_PIXELS, true, GraticuleLayerType.PROPERTY_NAME_RES_AUTO, true); Enablement enablementLatStep = context.bindEnabledState( GraticuleLayerType.PROPERTY_NAME_RES_LAT, true, GraticuleLayerType.PROPERTY_NAME_RES_AUTO, false); Enablement enablementLonStep = context.bindEnabledState( GraticuleLayerType.PROPERTY_NAME_RES_LON, true, GraticuleLayerType.PROPERTY_NAME_RES_AUTO, false); context .getPropertySet() .getProperty(GraticuleLayerType.PROPERTY_NAME_RES_AUTO) .addPropertyChangeListener( evt -> { enablementAvgGridSize.apply(); enablementLatStep.apply(); enablementLonStep.apply(); }); Enablement enablementTextBgTransparency = context.bindEnabledState( GraticuleLayerType.PROPERTY_NAME_TEXT_BG_TRANSPARENCY, true, GraticuleLayerType.PROPERTY_NAME_TEXT_ENABLED, true); context .getPropertySet() .getProperty(GraticuleLayerType.PROPERTY_NAME_TEXT_ENABLED) .addPropertyChangeListener( evt -> { enablementTextBgTransparency.apply(); for (JComponent component : textFgColorComponents) { component.setEnabled(((Boolean) evt.getNewValue())); } for (JComponent component : textBgColorComponents) { component.setEnabled(((Boolean) evt.getNewValue())); } }); for (JComponent component : textFgColorComponents) { component.setEnabled(true); } for (JComponent component : textBgColorComponents) { component.setEnabled(true); } }
protected JPanel createMiddlePanel(BindingContext bindingContext) { final JLabel boxSizeLabel = new JLabel("Box size: "); final JSpinner boxSizeSpinner = new JSpinner(); final JCheckBox computeInBetweenPoints = new JCheckBox("Compute in-between points"); final JCheckBox useCorrelativeData = new JCheckBox("Use correlative data"); correlativeFieldSelector = new CorrelativeFieldSelector(bindingContext); final PropertyDescriptor boxSizeDescriptor = bindingContext.getPropertySet().getProperty("boxSize").getDescriptor(); boxSizeDescriptor.setValueRange(new ValueRange(1, 101)); boxSizeDescriptor.setAttribute("stepSize", 2); boxSizeDescriptor.setValidator( new Validator() { @Override public void validateValue(Property property, Object value) throws ValidationException { if (((Number) value).intValue() % 2 == 0) { throw new ValidationException("Only odd values allowed as box size."); } } }); bindingContext.bind("boxSize", boxSizeSpinner); bindingContext.bind("computeInBetweenPoints", computeInBetweenPoints); bindingContext.bind("useCorrelativeData", useCorrelativeData); EnablePointDataCondition condition = new EnablePointDataCondition(); pointDataSourceEnablement = bindingContext.bindEnabledState("pointDataSource", true, condition); dataFieldEnablement = bindingContext.bindEnabledState("dataField", true, condition); bindingContext.addPropertyChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { updateDataSource(); updateDataSet(); updateUIState(); } }); JPanel dataSourceOptionsPanel = GridBagUtils.createPanel(); GridBagConstraints dataSourceOptionsConstraints = GridBagUtils.createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2"); GridBagUtils.addToPanel( dataSourceOptionsPanel, boxSizeLabel, dataSourceOptionsConstraints, "gridwidth=1,gridy=0,gridx=0,weightx=0,insets.left=4"); GridBagUtils.addToPanel( dataSourceOptionsPanel, boxSizeSpinner, dataSourceOptionsConstraints, "gridwidth=1,gridy=0,gridx=1,weightx=1,insets.left=0"); GridBagUtils.addToPanel( dataSourceOptionsPanel, computeInBetweenPoints, dataSourceOptionsConstraints, "gridwidth=2,gridy=1,gridx=0,weightx=2"); GridBagUtils.addToPanel( dataSourceOptionsPanel, useCorrelativeData, dataSourceOptionsConstraints, "gridy=2,insets.top=16"); GridBagUtils.addToPanel( dataSourceOptionsPanel, correlativeFieldSelector.pointDataSourceLabel, dataSourceOptionsConstraints, "gridy=3,insets.top=0,insets.left=4"); GridBagUtils.addToPanel( dataSourceOptionsPanel, correlativeFieldSelector.pointDataSourceList, dataSourceOptionsConstraints, "gridy=4,insets.left=4"); GridBagUtils.addToPanel( dataSourceOptionsPanel, correlativeFieldSelector.dataFieldLabel, dataSourceOptionsConstraints, "gridy=5,insets.left=4"); GridBagUtils.addToPanel( dataSourceOptionsPanel, correlativeFieldSelector.dataFieldList, dataSourceOptionsConstraints, "gridy=6,insets.left=4"); xAxisRangeControl .getBindingContext() .bind(PROPERTY_NAME_MARK_SEGMENTS, new JCheckBox("Mark segments")); yAxisRangeControl .getBindingContext() .bind(PROPERTY_NAME_LOG_SCALED, new JCheckBox("Log10 scaled")); JPanel displayOptionsPanel = GridBagUtils.createPanel(); GridBagConstraints displayOptionsConstraints = GridBagUtils.createConstraints("anchor=SOUTH,fill=HORIZONTAL,weightx=1"); GridBagUtils.addToPanel( displayOptionsPanel, xAxisRangeControl.getPanel(), displayOptionsConstraints, "gridy=0"); GridBagUtils.addToPanel( displayOptionsPanel, xAxisRangeControl .getBindingContext() .getBinding(PROPERTY_NAME_MARK_SEGMENTS) .getComponents()[0], displayOptionsConstraints, "gridy=1"); GridBagUtils.addToPanel( displayOptionsPanel, yAxisRangeControl.getPanel(), displayOptionsConstraints, "gridy=2"); GridBagUtils.addToPanel( displayOptionsPanel, yAxisRangeControl .getBindingContext() .getBinding(PROPERTY_NAME_LOG_SCALED) .getComponents()[0], displayOptionsConstraints, "gridy=3"); JPanel middlePanel = GridBagUtils.createPanel(); GridBagConstraints middlePanelConstraints = GridBagUtils.createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1"); GridBagUtils.addToPanel(middlePanel, dataSourceOptionsPanel, middlePanelConstraints, "gridy=0"); GridBagUtils.addToPanel( middlePanel, new JPanel(), middlePanelConstraints, "gridy=1,fill=VERTICAL,weighty=1"); GridBagUtils.addToPanel( middlePanel, displayOptionsPanel, middlePanelConstraints, "gridy=2,fill=HORIZONTAL,weighty=0"); return middlePanel; }
private JPanel createInputParameterPanel() { final PropertyDescriptor boxSizeDescriptor = bindingContext.getPropertySet().getDescriptor(PROPERTY_NAME_BOX_SIZE); boxSizeDescriptor.setValueRange(new ValueRange(1, 101)); boxSizeDescriptor.setAttribute("stepSize", 2); boxSizeDescriptor.setValidator( (property, value) -> { if (((Number) value).intValue() % 2 == 0) { throw new ValidationException("Only odd values allowed as box size."); } }); final JSpinner boxSizeSpinner = new JSpinner(); bindingContext.bind(PROPERTY_NAME_BOX_SIZE, boxSizeSpinner); final JPanel boxSizePanel = new JPanel(new BorderLayout(5, 3)); boxSizePanel.add(new JLabel("Box size:"), BorderLayout.WEST); boxSizePanel.add(boxSizeSpinner); correlativeFieldSelector = new CorrelativeFieldSelector(bindingContext); final JPanel pointDataSourcePanel = new JPanel(new BorderLayout(5, 3)); pointDataSourcePanel.add(correlativeFieldSelector.pointDataSourceLabel, BorderLayout.NORTH); pointDataSourcePanel.add(correlativeFieldSelector.pointDataSourceList); final JPanel pointDataFieldPanel = new JPanel(new BorderLayout(5, 3)); pointDataFieldPanel.add(correlativeFieldSelector.dataFieldLabel, BorderLayout.NORTH); pointDataFieldPanel.add(correlativeFieldSelector.dataFieldList); final JCheckBox xLogCheck = new JCheckBox("Log10 scaled"); bindingContext.bind(PROPERTY_NAME_X_AXIS_LOG_SCALED, xLogCheck); final JPanel xAxisOptionPanel = new JPanel(new BorderLayout()); xAxisOptionPanel.add(xAxisRangeControl.getPanel()); xAxisOptionPanel.add(xLogCheck, BorderLayout.SOUTH); final JCheckBox yLogCheck = new JCheckBox("Log10 scaled"); bindingContext.bind(PROPERTY_NAME_Y_AXIS_LOG_SCALED, yLogCheck); final JPanel yAxisOptionPanel = new JPanel(new BorderLayout()); yAxisOptionPanel.add(yAxisRangeControl.getPanel()); yAxisOptionPanel.add(yLogCheck, BorderLayout.SOUTH); final JCheckBox acceptableCheck = new JCheckBox("Show tolerance range"); JLabel fieldPrefix = new JLabel("+/-"); final JTextField acceptableField = new JTextField(); acceptableField.setPreferredSize(new Dimension(40, acceptableField.getPreferredSize().height)); acceptableField.setHorizontalAlignment(JTextField.RIGHT); final JLabel percentLabel = new JLabel(" %"); bindingContext.bind(PROPERTY_NAME_SHOW_ACCEPTABLE_DEVIATION, acceptableCheck); bindingContext.bind(PROPERTY_NAME_ACCEPTABLE_DEVIATION, acceptableField); bindingContext.getBinding(PROPERTY_NAME_ACCEPTABLE_DEVIATION).addComponent(percentLabel); bindingContext.getBinding(PROPERTY_NAME_ACCEPTABLE_DEVIATION).addComponent(fieldPrefix); bindingContext.bindEnabledState( PROPERTY_NAME_ACCEPTABLE_DEVIATION, true, PROPERTY_NAME_SHOW_ACCEPTABLE_DEVIATION, true); final JPanel confidencePanel = GridBagUtils.createPanel(); GridBagConstraints confidencePanelConstraints = GridBagUtils.createConstraints( "anchor=NORTHWEST,fill=HORIZONTAL,insets.top=5,weighty=0,weightx=1"); GridBagUtils.addToPanel( confidencePanel, acceptableCheck, confidencePanelConstraints, "gridy=0,gridwidth=3"); GridBagUtils.addToPanel( confidencePanel, fieldPrefix, confidencePanelConstraints, "weightx=0,insets.left=22,gridy=1,gridx=0,insets.top=4,gridwidth=1"); GridBagUtils.addToPanel( confidencePanel, acceptableField, confidencePanelConstraints, "weightx=1,gridx=1,insets.left=2,insets.top=2"); GridBagUtils.addToPanel( confidencePanel, percentLabel, confidencePanelConstraints, "weightx=0,gridx=2,insets.left=0,insets.top=4"); final JCheckBox regressionCheck = new JCheckBox("Show regression line"); bindingContext.bind(PROPERTY_NAME_SHOW_REGRESSION_LINE, regressionCheck); // UI arrangement JPanel middlePanel = GridBagUtils.createPanel(); GridBagConstraints middlePanelConstraints = GridBagUtils.createConstraints( "anchor=NORTHWEST,fill=HORIZONTAL,insets.top=6,weighty=0,weightx=1"); GridBagUtils.addToPanel( middlePanel, boxSizePanel, middlePanelConstraints, "gridy=0,insets.left=6"); GridBagUtils.addToPanel(middlePanel, pointDataSourcePanel, middlePanelConstraints, "gridy=1"); GridBagUtils.addToPanel(middlePanel, pointDataFieldPanel, middlePanelConstraints, "gridy=2"); GridBagUtils.addToPanel( middlePanel, xAxisOptionPanel, middlePanelConstraints, "gridy=3,insets.left=0"); GridBagUtils.addToPanel(middlePanel, yAxisOptionPanel, middlePanelConstraints, "gridy=4"); GridBagUtils.addToPanel( middlePanel, new JSeparator(), middlePanelConstraints, "gridy=5,insets.left=4"); GridBagUtils.addToPanel( middlePanel, confidencePanel, middlePanelConstraints, "gridy=6,fill=HORIZONTAL,insets.left=-4"); GridBagUtils.addToPanel( middlePanel, regressionCheck, middlePanelConstraints, "gridy=7,insets.left=-4,insets.top=8"); return middlePanel; }
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)); }
/** * Creates the UI component. The enable state of the UI is controlled via the parameter <code> * disableUIProperty</code>. If it matches the value of the property provided in the constructor, * the UI will be disabled. * * @param disableUIProperty Controls the enable state of the UI. * @return The UI component. */ public JPanel createBoundsInputPanel(boolean disableUIProperty) { final TableLayout layout = new TableLayout(9); layout.setTableAnchor(TableLayout.Anchor.WEST); layout.setTableFill(TableLayout.Fill.BOTH); layout.setTableWeightX(1.0); layout.setTableWeightY(1.0); layout.setTablePadding(3, 3); layout.setColumnWeightX(0, 0.0); layout.setColumnWeightX(1, 1.0); layout.setColumnWeightX(2, 0.0); layout.setColumnWeightX(3, 0.0); layout.setColumnWeightX(4, 1.0); layout.setColumnWeightX(5, 0.0); layout.setColumnWeightX(6, 0.0); layout.setColumnWeightX(7, 1.0); layout.setColumnWeightX(8, 0.0); layout.setColumnPadding(2, new Insets(3, 0, 3, 12)); layout.setColumnPadding(5, new Insets(3, 0, 3, 12)); final JPanel panel = new JPanel(layout); final DoubleFormatter doubleFormatter = new DoubleFormatter("###0.0##"); pixelXUnit = new JLabel(NonSI.DEGREE_ANGLE.toString()); pixelYUnit = new JLabel(NonSI.DEGREE_ANGLE.toString()); panel.add(new JLabel("West:")); final JFormattedTextField westLonField = new JFormattedTextField(doubleFormatter); westLonField.setHorizontalAlignment(JTextField.RIGHT); bindingContext.bind(PROPERTY_WEST_BOUND, westLonField); bindingContext.bindEnabledState( PROPERTY_WEST_BOUND, false, enablePropertyKey, disableUIProperty); panel.add(westLonField); panel.add(new JLabel(NonSI.DEGREE_ANGLE.toString())); panel.add(new JLabel("East:")); final JFormattedTextField eastLonField = new JFormattedTextField(doubleFormatter); eastLonField.setHorizontalAlignment(JTextField.RIGHT); bindingContext.bind(PROPERTY_EAST_BOUND, eastLonField); bindingContext.bindEnabledState( PROPERTY_EAST_BOUND, false, enablePropertyKey, disableUIProperty); panel.add(eastLonField); panel.add(new JLabel(NonSI.DEGREE_ANGLE.toString())); panel.add(new JLabel("Pixel size X:")); pixelSizeXField = new JFormattedTextField(doubleFormatter); pixelSizeXField.setHorizontalAlignment(JTextField.RIGHT); bindingContext.bind(PROPERTY_PIXEL_SIZE_X, pixelSizeXField); bindingContext.bindEnabledState( PROPERTY_PIXEL_SIZE_X, false, enablePropertyKey, disableUIProperty); panel.add(pixelSizeXField); panel.add(pixelXUnit); panel.add(new JLabel("North:")); final JFormattedTextField northLatField = new JFormattedTextField(doubleFormatter); northLatField.setHorizontalAlignment(JTextField.RIGHT); bindingContext.bind(PROPERTY_NORTH_BOUND, northLatField); bindingContext.bindEnabledState( PROPERTY_NORTH_BOUND, false, enablePropertyKey, disableUIProperty); panel.add(northLatField); panel.add(new JLabel(NonSI.DEGREE_ANGLE.toString())); panel.add(new JLabel("South:")); final JFormattedTextField southLatField = new JFormattedTextField(doubleFormatter); southLatField.setHorizontalAlignment(JTextField.RIGHT); bindingContext.bind(PROPERTY_SOUTH_BOUND, southLatField); bindingContext.bindEnabledState( PROPERTY_SOUTH_BOUND, false, enablePropertyKey, disableUIProperty); panel.add(southLatField); panel.add(new JLabel(NonSI.DEGREE_ANGLE.toString())); panel.add(new JLabel("Pixel size Y:")); pixelSizeYField = new JFormattedTextField(doubleFormatter); pixelSizeYField.setHorizontalAlignment(JTextField.RIGHT); bindingContext.bind(PROPERTY_PIXEL_SIZE_Y, pixelSizeYField); bindingContext.bindEnabledState( PROPERTY_PIXEL_SIZE_Y, false, enablePropertyKey, disableUIProperty); panel.add(pixelSizeYField); panel.add(pixelYUnit); bindingContext.addProblemListener( new BindingProblemListener() { @Override public void problemReported(BindingProblem problem, BindingProblem ignored) { final String propertyName = problem.getBinding().getPropertyName(); final boolean invalidBoundSet = propertyName.equals(PROPERTY_NORTH_BOUND) || propertyName.equals(PROPERTY_EAST_BOUND) || propertyName.equals(PROPERTY_SOUTH_BOUND) || propertyName.equals(PROPERTY_WEST_BOUND); if (invalidBoundSet) { resetTextField(problem); } } private void resetTextField(BindingProblem problem) { problem.getBinding().getComponentAdapter().adjustComponents(); } @Override public void problemCleared(BindingProblem ignored) { // do nothing } }); return panel; }
private JPanel createPanel() { final JCheckBox autoMinMaxBox = new JCheckBox("Auto min/max"); final JLabel minLabel = new JLabel("Min:"); final JLabel maxLabel = new JLabel("Max:"); final JTextField minTextField = new JTextField(); final JTextField maxTextField = new JTextField(); final JPanel panel = GridBagUtils.createPanel(); final GridBagConstraints gbc = GridBagUtils.createConstraints("anchor=WEST,fill=HORIZONTAL"); GridBagUtils.setAttributes(gbc, "gridwidth=2,insets.top=2,weightx=1"); titledSeparator = new TitledSeparator(axisName, SwingConstants.CENTER); GridBagUtils.addToPanel(panel, titledSeparator, gbc, "gridy=0,insets.right=-2"); GridBagUtils.addToPanel(panel, autoMinMaxBox, gbc, "gridy=1"); GridBagUtils.setAttributes(gbc, "gridwidth=1"); GridBagUtils.addToPanel(panel, minLabel, gbc, "insets.left=22,gridx=0,gridy=2,weightx=0"); GridBagUtils.addToPanel(panel, minTextField, gbc, "insets=2,gridx=1,gridy=2,weightx=1"); GridBagUtils.addToPanel(panel, maxLabel, gbc, "insets.left=22,gridx=0,gridy=3,weightx=0"); GridBagUtils.addToPanel(panel, maxTextField, gbc, "insets=2,gridx=1,gridy=3,weightx=1"); bindingContext.bind("autoMinMax", autoMinMaxBox); bindingContext.bind("min", minTextField); bindingContext.bind("max", maxTextField); bindingContext .getPropertySet() .getDescriptor("min") .setDescription("Minimum display value for " + axisName); bindingContext .getPropertySet() .getDescriptor("max") .setDescription("Maximum display value for " + axisName); bindingContext .getPropertySet() .getDescriptor("min") .setValidator( new Validator() { @Override public void validateValue(Property property, Object value) throws ValidationException { final Double max = bindingContext.getPropertySet().getValue("max"); if ((Double) value >= max) { throw new ValidationException("min value has to be less than " + max); } } }); bindingContext .getPropertySet() .getDescriptor("max") .setValidator( new Validator() { @Override public void validateValue(Property property, Object value) throws ValidationException { final Double min = bindingContext.getPropertySet().getValue("min"); if ((Double) value <= min) { throw new ValidationException("max value has to be greater than " + min); } } }); bindingContext.getBinding("min").addComponent(minLabel); bindingContext.getBinding("max").addComponent(maxLabel); bindingContext.bindEnabledState("min", true, "autoMinMax", false); bindingContext.bindEnabledState("max", true, "autoMinMax", false); return panel; }
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; }
@Override protected JPanel createPanel(BindingContext context) { TableLayout tableLayout = new TableLayout(2); tableLayout.setTableAnchor(TableLayout.Anchor.NORTHWEST); tableLayout.setTablePadding(new Insets(4, 10, 0, 0)); tableLayout.setTableFill(TableLayout.Fill.BOTH); tableLayout.setColumnWeightX(1, 1.0); tableLayout.setCellColspan(0, 0, 2); tableLayout.setCellColspan(1, 0, 2); tableLayout.setCellColspan(8, 0, 2); JPanel pageUI = new JPanel(tableLayout); PropertyEditorRegistry registry = PropertyEditorRegistry.getInstance(); Property computeLatLonSteps = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_RES_AUTO); Property avgGridSize = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_RES_PIXELS); Property latStep = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_RES_LAT); Property lonStep = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_RES_LON); Property lineColor = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_LINE_COLOR); Property lineWidth = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_LINE_WIDTH); Property lineTransparency = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_LINE_TRANSPARENCY); Property showTextLabels = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_TEXT_ENABLED); Property textFgColor = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_TEXT_FG_COLOR); Property textBgColor = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_TEXT_BG_COLOR); Property textBgTransparency = context.getPropertySet().getProperty(GraticuleLayerType.PROPERTY_NAME_TEXT_BG_TRANSPARENCY); JComponent[] computeLatLonStepsComponents = registry .findPropertyEditor(computeLatLonSteps.getDescriptor()) .createComponents(computeLatLonSteps.getDescriptor(), context); JComponent[] avgGridSizeComponents = registry .findPropertyEditor(avgGridSize.getDescriptor()) .createComponents(avgGridSize.getDescriptor(), context); JComponent[] latStepComponents = registry .findPropertyEditor(latStep.getDescriptor()) .createComponents(latStep.getDescriptor(), context); JComponent[] lonStepComponents = registry .findPropertyEditor(lonStep.getDescriptor()) .createComponents(lonStep.getDescriptor(), context); JComponent[] lineColorComponents = PreferenceUtils.createColorComponents(lineColor); JComponent[] lineWidthComponents = registry .findPropertyEditor(lineWidth.getDescriptor()) .createComponents(lineWidth.getDescriptor(), context); JComponent[] lineTransparencyComponents = registry .findPropertyEditor(lineTransparency.getDescriptor()) .createComponents(lineTransparency.getDescriptor(), context); JComponent[] showTextLabelsComponents = registry .findPropertyEditor(showTextLabels.getDescriptor()) .createComponents(showTextLabels.getDescriptor(), context); textFgColorComponents = PreferenceUtils.createColorComponents(textFgColor); textBgColorComponents = PreferenceUtils.createColorComponents(textBgColor); JComponent[] textBgTransparencyComponents = registry .findPropertyEditor(textBgTransparency.getDescriptor()) .createComponents(textBgTransparency.getDescriptor(), context); pageUI.add(computeLatLonStepsComponents[0]); addNote( pageUI, "<html>Note: Deselect this option only very carefully. The latitude and longitude<br>" + "steps you enter will be used for low and high resolution products.</html>"); pageUI.add(avgGridSizeComponents[1]); pageUI.add(avgGridSizeComponents[0]); pageUI.add(latStepComponents[1]); pageUI.add(latStepComponents[0]); pageUI.add(lonStepComponents[1]); pageUI.add(lonStepComponents[0]); pageUI.add(lineColorComponents[0]); pageUI.add(lineColorComponents[1]); pageUI.add(lineWidthComponents[1]); pageUI.add(lineWidthComponents[0]); pageUI.add(lineTransparencyComponents[1]); pageUI.add(lineTransparencyComponents[0]); pageUI.add(showTextLabelsComponents[0]); pageUI.add(textFgColorComponents[0]); pageUI.add(textFgColorComponents[1]); pageUI.add(textBgColorComponents[0]); pageUI.add(textBgColorComponents[1]); pageUI.add(textBgTransparencyComponents[1]); pageUI.add(textBgTransparencyComponents[0]); pageUI.add(tableLayout.createVerticalSpacer()); JPanel parent = new JPanel(new BorderLayout()); parent.add(pageUI, BorderLayout.CENTER); parent.add(Box.createHorizontalStrut(100), BorderLayout.EAST); return parent; }
private String getAxisLabel() { boolean logScaled = (Boolean) bindingContext.getBinding(PROPERTY_NAME_LOGARITHMIC_HISTOGRAM).getPropertyValue(); return StatisticChartStyling.getAxisLabel(getRaster(), "X", logScaled); }
public boolean isAutoMinMax() { return (Boolean) bindingContext.getBinding("autoMinMax").getPropertyValue(); }