Beispiel #1
0
    @Override
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

      // ### We should indicate the current thread independently of the
      // ### selection, e.g., with an icon, because the user may change
      // ### the selection graphically without affecting the current
      // ### thread.

      super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      if (value == null) {
        this.setText("<unavailable>");
      } else {
        StackFrame frame = (StackFrame) value;
        Location loc = frame.location();
        Method meth = loc.method();
        String methName = meth.declaringType().name() + '.' + meth.name();
        String position = "";
        if (meth.isNative()) {
          position = " (native method)";
        } else if (loc.lineNumber() != -1) {
          position = ":" + loc.lineNumber();
        } else {
          long pc = loc.codeIndex();
          if (pc != -1) {
            position = ", pc = " + pc;
          }
        }
        // Indices are presented to the user starting from 1, not 0.
        this.setText("[" + (index + 1) + "] " + methName + position);
      }
      return this;
    }
 public void itemStateChanged(ItemEvent event) {
   if (event.getStateChange() == ItemEvent.SELECTED) {
     int index = getSelectedIndex();
     int lower = _lower[index];
     int upper = _upper[index];
     MMultiplicity mult = null;
     if (lower >= 0) {
       mult = new MMultiplicity(lower, upper);
     }
     try {
       _setMethod.invoke(_container.getTarget(), new Object[] {mult});
     } catch (Exception e) {
       System.out.println(e.toString() + " in UMLMultiplicityComboBox.itemStateChanged()");
     }
   }
 }
  private void update() {
    int lower = -1;
    int upper = -1;

    try {
      Object obj = _getMethod.invoke(_container.getTarget(), _noArg);
      if (obj instanceof MMultiplicity) {
        MMultiplicity mult = (MMultiplicity) obj;
        lower = mult.getLower();
        upper = mult.getUpper();
      }
    } catch (Exception e) {
      System.out.println(e.toString() + " in UMLMultiplicityComboBox.update()");
    }
    boolean match = false;
    for (int i = 0; i < _mults.length; i++) {
      if (lower == _lower[i] && upper == _upper[i]) {
        setSelectedIndex(i);
        match = true;
        break;
      }
    }
    if (!match) {
      StringBuffer buf = new StringBuffer();
      if (lower <= 0) {
        buf.append("0..");
      } else {
        buf.append(Integer.toString(lower));
        buf.append("..");
      }
      if (upper < 0) {
        buf.append("*");
      } else {
        buf.append(Integer.toString(upper));
      }
      setSelectedItem(buf.toString());
    }
  }
    /**
     * 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();
      }
    }