Exemple #1
0
  /**
   * Get the appropriate editor for the given property.
   *
   * @param prop Property to get editor for.
   * @return Editor to use, or null if none found.
   */
  private PropertyEditor getEditorForProperty(PropertyDescriptor prop) {
    PropertyEditor retval = null;
    Class type = prop.getPropertyEditorClass();
    if (type != null) {
      try {
        retval = (PropertyEditor) type.newInstance();
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
    // Handle case where there is no special editor
    // associated with the property. In that case we ask the
    // PropertyEditor manager for the editor registered for the
    // given property type.
    if (retval == null) {
      Class t = prop.getPropertyType();
      if (t != null) {
        retval = PropertyEditorManager.findEditor(t);
      }
    }

    // In the worse case we resort to the generic editor for Object types.
    if (retval == null) {
      retval = PropertyEditorManager.findEditor(Object.class);
    }

    return retval;
  }
Exemple #2
0
  /**
   * Set the object to be edited.
   *
   * @param value The object to be edited.
   */
  public void setObject(Object value) {
    if (!(_type.isInstance(value))) {
      throw new IllegalArgumentException(value.getClass() + " is not of type " + _type);
    }
    _value = value;

    // Disable event generation.
    _squelchChangeEvents = true;

    // Iterate over each property, doing a lookup on the associated editor
    // and setting the editor's value to the value of the property.
    Iterator it = _prop2Editor.keySet().iterator();
    while (it.hasNext()) {
      PropertyDescriptor desc = (PropertyDescriptor) it.next();
      PropertyEditor editor = (PropertyEditor) _prop2Editor.get(desc);
      Method reader = desc.getReadMethod();
      if (reader != null) {
        try {
          Object val = reader.invoke(_value, null);
          editor.setValue(val);
        } catch (IllegalAccessException ex) {
          ex.printStackTrace();
        } catch (InvocationTargetException ex) {
          ex.getTargetException().printStackTrace();
        }
      }
    }

    // Enable event generation.
    _squelchChangeEvents = false;
  }
Exemple #3
0
    public void propertyChange(PropertyChangeEvent e) {
      if (_squelchChangeEvents) return;

      PropertyEditor editor = (PropertyEditor) e.getSource();
      PropertyDescriptor prop = (PropertyDescriptor) _editor2Prop.get(editor);
      Method writer = prop.getWriteMethod();
      if (writer != null) {
        try {
          Object[] params = {editor.getValue()};
          writer.invoke(_value, params);
          setObject(_value);
          firePropertyChange(_value, prop.getName(), null, editor.getValue());
        } catch (IllegalAccessException ex) {
          ex.printStackTrace();
        } catch (InvocationTargetException ex) {
          ex.getTargetException().printStackTrace();
        }
      }
    }
Exemple #4
0
    public int compare(Object o1, Object o2) {
      PropertyDescriptor p1 = (PropertyDescriptor) o1;
      PropertyDescriptor p2 = (PropertyDescriptor) o2;

      Integer i1 = (Integer) p1.getValue(SORT_ORDER);
      Integer i2 = (Integer) p2.getValue(SORT_ORDER);

      if (i1 == null && i2 == null) {
        return p1.getName().compareTo(p2.getName());
      } else if (i1 != null) {
        return i1.compareTo(i2);
      } else {
        return i2.compareTo(i1) * -1;
      }
    }
  // For Make Multi_SpotTrade Order/Assign Order
  public static PropertyDescriptor[] getPropertyDescriptors(
      boolean isAllowEditIsBuy, int dQMaxMove, int stepSize) {
    PropertyDescriptor[] propertyDescriptors =
        new PropertyDescriptor[dQMaxMove > 0 && dQMaxMove > stepSize ? 4 : 3];
    int i = -1;

    PropertyDescriptor propertyDescriptor =
        PropertyDescriptor.create(
            MakeOrderAccount.class,
            MakeOrderAccountGridColKey.Code,
            true,
            null,
            MakeOrderAccountGridLanguage.Code,
            40,
            SwingConstants.LEFT,
            null,
            null);
    propertyDescriptors[++i] = propertyDescriptor;

    propertyDescriptor =
        PropertyDescriptor.create(
            MakeOrderAccount.class,
            MakeOrderAccountGridColKey.IsBuyForCombo,
            !isAllowEditIsBuy,
            null,
            MakeOrderAccountGridLanguage.IsBuyForCombo,
            15,
            SwingConstants.CENTER,
            null,
            null);
    propertyDescriptors[++i] = propertyDescriptor;

    /*propertyDescriptor = PropertyDescriptor.create(MakeOrderAccount.class, MakeOrderAccountGridColKey.SetPriceString, true, null,
    	MakeOrderAccountGridLanguage.SetPriceString, 40, SwingConstants.RIGHT, null, null);
    propertyDescriptors[++i] = propertyDescriptor;*/

    propertyDescriptor =
        PropertyDescriptor.create(
            MakeOrderAccount.class,
            MakeOrderAccountGridColKey.LotString,
            false,
            null,
            MakeOrderAccountGridLanguage.LotString,
            25,
            SwingConstants.CENTER,
            null,
            null,
            new StringCellEditor(),
            null);
    propertyDescriptors[++i] = propertyDescriptor;

    if (dQMaxMove > 0 && dQMaxMove > stepSize) {
      SpinnerCellEditor spinnerCellEditor = new SpinnerCellEditor();
      JDQMoveSpinnerHelper.applyMaxDQMove(spinnerCellEditor.getSpinner(), dQMaxMove, stepSize);

      propertyDescriptor =
          PropertyDescriptor.create(
              MakeOrderAccount.class,
              MakeOrderAccountGridColKey.DQMaxMove,
              false,
              null,
              MakeOrderAccountGridLanguage.DQMaxMove,
              (dQMaxMove > 0) ? 50 : 0,
              SwingConstants.CENTER,
              null,
              null,
              spinnerCellEditor,
              null);
      propertyDescriptors[++i] = propertyDescriptor;
    }
    return propertyDescriptors;
  }
    /**
     * Create a new ProjectionClass from the class
     *
     * @param pc projection class
     * @throws ClassNotFoundException couldn't find the class
     * @throws IntrospectionException problem with introspection
     */
    ProjectionClass(Class pc) throws ClassNotFoundException, IntrospectionException {
      projClass = pc;

      // eliminate common properties with "stop class" for getBeanInfo()
      Class stopClass;
      try {
        stopClass = Misc.findClass("ucar.unidata.geoloc.ProjectionImpl");
      } catch (Exception ee) {
        System.err.println("constructParamInput failed ");
        stopClass = null;
      }

      // analyze current projection class as a bean; may throw IntrospectionException
      BeanInfo info = java.beans.Introspector.getBeanInfo(projClass, stopClass);

      // find read/write methods
      PropertyDescriptor[] props = info.getPropertyDescriptors();
      if (debugBeans) {
        System.out.print("Bean Properties for class " + projClass);
        if ((props == null) || (props.length == 0)) {
          System.out.println("none");
          return;
        }
        System.out.println("");
      }
      for (int i = 0; i < props.length; i++) {
        PropertyDescriptor pd = props[i];
        Method reader = pd.getReadMethod();
        Method writer = pd.getWriteMethod();
        // only interesetd in read/write properties
        if ((reader == null) || (writer == null)) {
          continue;
        }
        // A hack to exclude some attributes
        if (pd.getName().equals("name") || pd.getName().equals("defaultMapArea")) {
          continue;
        }
        ProjectionParam p = new ProjectionParam(pd.getName(), reader, writer, pd.getPropertyType());
        paramList.add(p);

        if (debugBeans) {
          System.out.println("  -->" + p);
        }
      }

      // get an instance of this class so we can call toClassName()
      Projection project;
      if (null == (project = makeDefaultProjection())) {
        name = "none";
        return;
      }

      // invoke the toClassName method
      try {
        Method m = projClass.getMethod("getProjectionTypeLabel", VOIDCLASSARG);
        name = (String) m.invoke(project, VOIDOBJECTARG);
      } catch (NoSuchMethodException ee) {
        System.err.println(
            "ProjectionManager: class "
                + projClass
                + " does not have method getProjectionTypeLabel()");
        throw new ClassNotFoundException();
      } catch (SecurityException ee) {
        System.err.println(
            "ProjectionManager: class "
                + projClass
                + " got SecurityException on getProjectionTypeLabel()"
                + ee);
        throw new ClassNotFoundException();
      } catch (Exception ee) {
        System.err.println(
            "ProjectionManager: class "
                + projClass
                + " Exception when invoking getProjectionTypeLabel()"
                + ee);
        throw new ClassNotFoundException();
      }
    }
  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;
  }