示例#1
0
  /**
   * Handle a refresh of the style panel after the fig has moved.
   *
   * <p><em>Warning</em>. There is a circular trap here. Editing the boundary box will also trigger
   * a refresh, and so we reset the boundary box, which causes funny behaviour (the cursor keeps
   * jumping to the end of the text).
   *
   * <p>The solution is to not reset the boundary box field if the boundaries have not changed.
   *
   * <p>
   */
  public void refresh() {
    Fig target = getPanelTarget();
    if (target instanceof FigEdgeModelElement) {
      hasEditableBoundingBox(false);
    } else {
      hasEditableBoundingBox(true);
    }
    if (target == null) return;

    // The boundary box as held in the target fig, and as listed in
    // the
    // boundary box style field (null if we don't have anything
    // valid)

    Rectangle figBounds = target.getBounds();
    Rectangle styleBounds = parseBBox();

    // Only reset the text if the two are not the same (i.e the fig
    // has
    // moved, rather than we've just edited the text, when
    // setTargetBBox()
    // will have made them the same). Note that styleBounds could
    // be null,
    // so we do the test this way round.

    if (!(figBounds.equals(styleBounds))) {
      bboxField.setText(
          figBounds.x + "," + figBounds.y + "," + figBounds.width + "," + figBounds.height);
    }

    // Change the fill colour

    if (target.getFilled()) {
      Color c = target.getFillColor();
      fillField.setSelectedItem(c);
      if (c != null && !fillField.getSelectedItem().equals(c)) {
        fillField.insertItemAt(c, fillField.getItemCount() - 1);
        fillField.setSelectedItem(c);
      }
    } else {
      fillField.setSelectedIndex(0);
    }

    // Change the line colour

    if (target.getLineWidth() > 0) {
      Color c = target.getLineColor();
      lineField.setSelectedItem(c);
      if (c != null && !lineField.getSelectedItem().equals(c)) {
        lineField.insertItemAt(c, lineField.getItemCount() - 1);
        lineField.setSelectedItem(c);
      }
    } else {
      lineField.setSelectedIndex(0);
    }
  }