コード例 #1
0
  /**
   * Highlight concepts that have already been resolved, but do not run solver. Otherwise, do
   * nothing.
   *
   * @param objects The set of objects to highlight.
   * @exception IllegalActionException Thrown if there is an error getting the colors for the
   *     resolved concept values.
   */
  public void highlightConcepts(Set<Object> objects) throws IllegalActionException {
    if (objects != null) {
      // Get the PropertySolver.
      OntologySolver solver = (OntologySolver) getContainer();

      for (Object object : objects) {
        if (object instanceof NamedObj) {
          Concept concept = solver.getConcept(object);
          if (concept != null) {
            ColorAttribute conceptColor = concept.getColor();
            if (conceptColor != null) {
              String request =
                  "<property name=\"_highlightColor\" "
                      + "class=\"ptolemy.actor.gui.ColorAttribute\" value=\""
                      + conceptColor.getExpression()
                      + "\"/>";
              MoMLChangeRequest change =
                  new MoMLChangeRequest(this, (NamedObj) object, request, false);
              ((NamedObj) object).requestChange(change);
            }
          }
        }
      }
      // Force a single repaint after all the above requests have been processed.
      solver.requestChange(new MoMLChangeRequest(this, solver, "<group/>"));
    }
  }
コード例 #2
0
ファイル: Line3D.java プロジェクト: blickly/ptii
  public void fire() throws IllegalActionException {
    if (_debugging) {
      _debug("Called fire()");
    }

    ArrayToken lineStartToken = ((ArrayToken) lineStart.getToken());
    ArrayToken lineEndToken = ((ArrayToken) lineEnd.getToken());
    ArrayToken rgbColorValue = ((ArrayToken) rgbColor.getToken());
    DoubleToken widthValue = (DoubleToken) width.getToken();

    GL gl = ((GRODirector) getDirector()).getGL();

    gl.glLineWidth((float) widthValue.doubleValue());
    gl.glBegin(GL.GL_LINES);

    gl.glColor3d(
        ((DoubleToken) rgbColorValue.getElement(0)).doubleValue(),
        ((DoubleToken) rgbColorValue.getElement(1)).doubleValue(),
        ((DoubleToken) rgbColorValue.getElement(2)).doubleValue());

    // origin of the line
    gl.glVertex3d(
        ((DoubleToken) lineStartToken.getElement(0)).doubleValue(),
        ((DoubleToken) lineStartToken.getElement(1)).doubleValue(),
        ((DoubleToken) lineStartToken.getElement(2)).doubleValue());

    // ending point of the line
    gl.glVertex3d(
        ((DoubleToken) lineEndToken.getElement(0)).doubleValue(),
        ((DoubleToken) lineEndToken.getElement(1)).doubleValue(),
        ((DoubleToken) lineEndToken.getElement(2)).doubleValue());

    gl.glEnd();
  }
コード例 #3
0
ファイル: TableIcon.java プロジェクト: Elblonko/kepler
  /**
   * Create a new background figure. This overrides the base class to draw a box around the value
   * display, where the width of the box depends on the value.
   *
   * @return A new figure.
   */
  public Figure createBackgroundFigure() {
    NamedObj container = getContainer();
    CompositeFigure result = new CompositeFigure();
    if (container != null) {
      try {
        ArrayToken fieldsValue = (ArrayToken) fields.getToken();
        Attribute associatedAttribute = container.getAttribute(variableName.getExpression());
        if (associatedAttribute instanceof Variable) {
          Token value = ((Variable) associatedAttribute).getToken();
          if (value instanceof ArrayToken) {
            // Find the number of rows and columns.
            int numRows = ((ArrayToken) value).length();
            int numColumns = fieldsValue.length();
            if (numColumns == 0) {
              // All columns should be included.
              // Make a pass to figure out how many that is.
              for (int i = 0; i < numRows; i++) {
                Token row = ((ArrayToken) value).getElement(i);
                if (row instanceof RecordToken) {
                  int rowWidth = ((RecordToken) row).labelSet().size();
                  if (rowWidth > numColumns) {
                    numColumns = rowWidth;
                  }
                }
              }
            }

            // Find the width of each column and the height of each row.
            // All rows are the same height, but column widths can vary.
            double rowHeight = 0.0;
            double columnWidth[] = new double[numColumns];
            for (int i = 1; i < numColumns; i++) {
              columnWidth[i] = 0.0;
            }
            LabelFigure tableElement[][] = new LabelFigure[numRows][numColumns];
            // Iterate over rows.
            for (int i = 0; i < numRows; i++) {
              Token row = ((ArrayToken) value).getElement(i);
              if (row instanceof RecordToken) {
                if (fieldsValue.length() == 0) {
                  // Display all fields.
                  Iterator labelSet = ((RecordToken) row).labelSet().iterator();
                  int j = 0;
                  while (labelSet.hasNext()) {
                    String column = (String) labelSet.next();
                    tableElement[i][j] = _labelFigure((RecordToken) row, column);
                    Rectangle2D bounds = tableElement[i][j].getBounds();
                    double width = bounds.getWidth();
                    if (width > columnWidth[j]) {
                      columnWidth[j] = width;
                    }
                    double height = bounds.getHeight();
                    if (height > rowHeight) {
                      rowHeight = height;
                    }
                    j++;
                  }
                } else {
                  // Display specified fields.
                  for (int j = 0; j < fieldsValue.length(); j++) {
                    if (j >= numColumns) {
                      break;
                    }
                    String column = ((StringToken) fieldsValue.getElement(j)).stringValue();
                    tableElement[i][j] = _labelFigure((RecordToken) row, column);
                    Rectangle2D bounds = tableElement[i][j].getBounds();
                    double width = bounds.getWidth();
                    if (width > columnWidth[j]) {
                      columnWidth[j] = width;
                    }
                    double height = bounds.getHeight();
                    if (height > rowHeight) {
                      rowHeight = height;
                    }
                  }
                }
              }
            }

            // Now make a pass to position and add all the figures.
            double rowPosition = _VERTICAL_PADDING;
            // Iterate over rows.
            for (int i = 0; i < numRows; i++) {
              Token row = ((ArrayToken) value).getElement(i);
              if (row instanceof RecordToken) {
                if (fieldsValue.length() == 0) {
                  // Display all fields.
                  Iterator labelSet = ((RecordToken) row).labelSet().iterator();
                  int j = 0;
                  double columnPosition = _HORIZONTAL_PADDING;
                  while (labelSet.hasNext()) {
                    /*String column = (String) */ labelSet.next();
                    tableElement[i][j].translateTo(columnPosition, rowPosition);
                    result.add(tableElement[i][j]);
                    columnPosition += columnWidth[j] + _HORIZONTAL_PADDING;
                    j++;
                  }
                } else {
                  // Display specified fields.
                  double columnPosition = _HORIZONTAL_PADDING;
                  for (int j = 0; j < fieldsValue.length(); j++) {
                    // String column = ((StringToken)fieldsValue.getElement(j)).stringValue();
                    tableElement[i][j].translateTo(columnPosition, rowPosition);
                    result.add(tableElement[i][j]);
                    columnPosition += columnWidth[j] + _HORIZONTAL_PADDING;
                  }
                }
              }
              rowPosition += rowHeight + _VERTICAL_PADDING;
            }
          }
        }
      } catch (IllegalActionException e) {
        // Stick the error message in the icon.
        result.add(new LabelFigure(e.getMessage()));
      }
    }
    // Now put a box around it all.
    Rectangle2D bounds = result.getBounds();
    // Double the padding below to allow for both sides.
    double width = Math.floor(bounds.getWidth()) + _HORIZONTAL_PADDING * 2;
    double height = Math.floor(bounds.getHeight()) + _VERTICAL_PADDING * 2;
    Figure rectangle = new BasicRectangle(0, 0, width, height, boxColor.asColor(), 1);
    CompositeFigure finalResult = new CompositeFigure(rectangle);
    finalResult.add(result);
    return finalResult;
  }