Package ca.nengo.config

Examples of ca.nengo.config.Property


  public void renameProperty(String oldName, String newName) {
    if (myPropertyNames.contains(oldName)) {
      int index = myPropertyNames.indexOf(oldName);
      myPropertyNames.remove(index);
      myPropertyNames.add(index, newName);
      Property p = myProperties.remove(oldName);
      p.setName(newName);
      myProperties.put(newName, p);
    } else {
      throw new IllegalArgumentException("There is no Property named " + oldName);
    }
  }
View Full Code Here


  }

  private void setResult() throws StructuralException {
    List<Object> args = new ArrayList<Object>(myConfiguration.getPropertyNames().size());
    for (String string : myConfiguration.getPropertyNames()) {
      Property p = myConfiguration.getProperty(string);
      if (p instanceof SingleValuedProperty) {
        args.add(((SingleValuedProperty) p).getValue());
      } else if (p instanceof ListProperty) {
        ListProperty lp = (ListProperty) p;
        Object array = Array.newInstance(p.getType(), lp.getNumValues());
        for (int i = 0; i < lp.getNumValues(); i++) {
          Array.set(array, i, lp.getValue(i));
        }
        args.add(array);
      }
View Full Code Here

   
    if (value instanceof Value && ((Value) value).getConfiguration() != null) {
      setText(((Value) value).getObject().getClass().getSimpleName());
      setToolTipText(((Value) value).getObject().getClass().getCanonicalName());
    } else if (value instanceof Property) {
      Property property = (Property) value;
     
      StringBuffer text = new StringBuffer(property.getName());
      text.append(" (");
      text.append(property.getType().getSimpleName());
      text.append(")");
      setText(text.toString());
     
      setToolTipText(null);
    } else if (value instanceof Value) { //with null getConfiguration (a leaf)
View Full Code Here

            }
          });
          popup.add(addValueItem);
        }
      } else if (path.getParentPath() != null && path.getParentPath().getLastPathComponent() instanceof Property) {
        final Property p = (Property) path.getParentPath().getLastPathComponent();
        if (p.isMutable() && !MainHandler.getInstance().canHandle(p.getType())) {
          final JMenuItem replaceValueItem = new JMenuItem("Replace");
          replaceValueItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              Class<?> currentType = ((Value) path.getLastPathComponent()).getObject().getClass();
              Object o = NewConfigurableDialog.showDialog(replaceValueItem, p.getType(), currentType);
              if (o != null) {
                try {
                  myModel.setValue(path, o);
                } catch (StructuralException ex) {
                  ConfigExceptionHandler.handle(ex, ex.getMessage(), event.getComponent());
                }
              }
            }
          });
          popup.add(replaceValueItem);                 
        }
       
        if (!p.isFixedCardinality()) {
          if (p instanceof ListProperty) {
            JMenuItem insertValueItem = new JMenuItem("Insert");
            insertValueItem.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                myModel.insertValue(path, getValue(p.getType()));
              }
            });
            popup.add(insertValueItem);           
          }
          JMenuItem removeValueItem = new JMenuItem("Remove");
          removeValueItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              myModel.removeValue(path);
            }
          });
          popup.add(removeValueItem);       
        }
       
      }
     
      JMenuItem refreshItem = new JMenuItem("Refresh");
      refreshItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          myModel.refresh(path);
        }
      });
      popup.add(refreshItem);
     
      //property help on either property or property value ...
      Property property = null;
      if (path.getParentPath() != null && path.getParentPath().getLastPathComponent() instanceof Property) {
        property = (Property) path.getParentPath().getLastPathComponent();
      } else if (path.getLastPathComponent() instanceof Property) {
        property = (Property) path.getLastPathComponent();
      }     
      if (property != null) {
        JMenuItem helpItem = new JMenuItem("Help");
        final Property p = property;
        helpItem.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String documentation = p.getDocumentation();
            if (documentation != null)
              ConfigUtil.showHelp(documentation);
          }       
        });
        popup.add(helpItem);
View Full Code Here

    int index = -1;

    try {
      if (child instanceof Property) {
        Configuration c = ((Value) parent).getConfiguration();
        Property p = (Property) child;
        List<String> propertyNames = c.getPropertyNames();
        Collections.sort(propertyNames);
        index = propertyNames.indexOf(p.getName());
      } else if (parent instanceof SingleValuedProperty) {
        SingleValuedProperty p = (SingleValuedProperty) parent;
        Value v = (Value) child;
        if (p.getValue() != null && p.getValue().equals(v.getObject())) {
          index = 0;
        }
      } else if (parent instanceof ListProperty) {
        ListProperty p = (ListProperty) parent;
        Value v = (Value) child;
        for (int i = 0; i < p.getNumValues() && index == -1; i++) {
          if (p.getValue(i) != null && p.getValue(i).equals(v.getObject())) {
                        index = i;
                    }
        }
      } else if (parent instanceof NamedValueProperty) {
        NamedValueProperty p = (NamedValueProperty) parent;
        String name = ((Value) child).getName();
        for (int i = 0; i < p.getValueNames().size() && index == -1; i++) {
          if (p.getValueNames().get(i).equals(name)) {
                        index = i;
                    }
        }
      }
    } catch (StructuralException e) {
View Full Code Here

  private void initConfiguration() {
    myConfiguration = ConfigUtil.defaultConfiguration(this);
    myConfiguration.removeProperty("dimensions");
    try {
      Property p = new SingleValuedPropertyImpl(myConfiguration, "dimensions", Integer.TYPE,
          this.getClass().getMethod("getDimensions", new Class[0]));
      myConfiguration.defineProperty(p);
    } catch (Exception e) {
      ourLogger.warn("Can't define property 'dimensions'", e);
    }
View Full Code Here

TOP

Related Classes of ca.nengo.config.Property

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.