コード例 #1
0
  /** @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */
  public void actionPerformed(ActionEvent ae) {
    super.actionPerformed(ae);
    try {
      /*Here the actions to delete a region.
      We assume the only figs enclosed in a concurrent composite state
      are concurrent region figs*/
      Fig f = (Fig) TargetManager.getInstance().getFigTarget();
      Fig encloser = null;

      int height = 0;
      Rectangle encBound;
      Project p = ProjectManager.getManager().getCurrentProject();

      if (Model.getFacade().isAConcurrentRegion(f.getOwner())) encloser = f.getEnclosingFig();

      Vector nodesInside;
      nodesInside = ((Vector) encloser.getEnclosedFigs().clone());
      int index = nodesInside.indexOf(f);
      Rectangle r = f.getBounds();
      encBound = encloser.getBounds();
      if (Model.getFacade().isAConcurrentRegion(f.getOwner())) p.moveToTrash(f.getOwner());
      // It wasnt the last region
      if (index < nodesInside.size() - 1) {
        Rectangle rFig = ((Fig) nodesInside.elementAt(index + 1)).getBounds();
        height = rFig.y - r.y;
        for (int i = ++index; i < nodesInside.size(); i++)
          ((FigNodeModelElement) nodesInside.elementAt(i)).displace(0, -height);
      }
      // It was the last region
      else height = r.height + 4;

      /*When only one concurrent region remains it must be erased and the
      composite state sets non concurent*/
      if (((Vector) encloser.getEnclosedFigs()).size() == 1) {
        f = ((Fig) encloser.getEnclosedFigs().elementAt(0));
        nodesInside = ((Vector) f.getEnclosedFigs());
        Model.getStateMachinesHelper().setConcurrent(encloser.getOwner(), false);
        if (!nodesInside.isEmpty()) {
          for (int i = 0; i < nodesInside.size(); i++) {
            FigStateVertex curFig = (FigStateVertex) nodesInside.elementAt(i);
            curFig.setEnclosingFig(encloser);
          }
        }
        p.moveToTrash(f.getOwner());
      }

    } catch (Exception ex) {
      LOG.error(ex);
    }
  }
コード例 #2
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);
    }
  }
コード例 #3
0
  /**
   * Change the bounds of the target fig. Called whenever the bounds box is edited.
   *
   * <p>Format of the bounds is four integers representing x, y, width and height separated by
   * spaces or commas. An empty field is treated as no change and leading and trailing spaces are
   * ignored.
   *
   * <p><em>Note</em>. There is a note in the old code that more work might be needed, because this
   * could change the graph model. I don't see how that could ever be.
   */
  protected void setTargetBBox() {
    Fig target = getPanelTarget();
    // Can't do anything if we don't have a fig.
    if (target == null) {
      return;
    }
    // Parse the boundary box text. Null is
    // returned if it is empty or
    // invalid, which causes no change. Otherwise we tell
    // GEF we are making
    // a change, make the change and tell GEF we've
    // finished.
    Rectangle bounds = parseBBox();
    if (bounds == null) {
      return;
    }

    if (!target.getBounds().equals(bounds)) {
      target.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
      target.endTrans();
    }
  }
コード例 #4
0
 /**
  * Parse the boundary box string and return the rectangle it represents.
  *
  * <p>The syntax are four integers separated by spaces or commas. We ignore leading and trailing
  * blanks.
  *
  * <p>If we have the empty string we return <code>null</code>.
  *
  * <p>If we fail to parse, then we return <code>null</code> and print out a rude message.
  *
  * <p>
  *
  * @return The size of the box, or <code>null</code> if the bounds string is empty or invalid.
  */
 protected Rectangle parseBBox() {
   Fig target = getPanelTarget();
   // Get the text in the field, and don't do anything if the
   // field is
   // empty.
   String bboxStr = bboxField.getText().trim();
   if (bboxStr.length() == 0) {
     return null;
   } // Parse the string as if
   // possible
   Rectangle res = new Rectangle();
   java.util.StringTokenizer st = new java.util.StringTokenizer(bboxStr, ", ");
   try {
     boolean changed = false;
     if (!st.hasMoreTokens()) {
       return target.getBounds();
     }
     res.x = Integer.parseInt(st.nextToken());
     if (!st.hasMoreTokens()) {
       res.y = target.getBounds().y;
       res.width = target.getBounds().width;
       res.height = target.getBounds().height;
       return res;
     }
     res.y = Integer.parseInt(st.nextToken());
     if (!st.hasMoreTokens()) {
       res.width = target.getBounds().width;
       res.height = target.getBounds().height;
       return res;
     }
     res.width = Integer.parseInt(st.nextToken());
     if ((res.width + res.x) > 6000) {
       res.width = 6000 - res.x;
       changed = true;
     }
     if (!st.hasMoreTokens()) {
       res.width = target.getBounds().width;
       return res;
     }
     res.height = Integer.parseInt(st.nextToken());
     if ((res.height + res.y) > 6000) {
       res.height = 6000 - res.y;
       changed = true;
     }
     if (res.x < 0 || res.y < 0 || res.width < 0 || res.height < 0) {
       throw new IllegalArgumentException();
     }
     if (changed) {
       StringBuffer sb = new StringBuffer();
       sb.append(Integer.toString(res.x));
       sb.append(",");
       sb.append(Integer.toString(res.y));
       sb.append(",");
       sb.append(Integer.toString(res.width));
       sb.append(",");
       sb.append(Integer.toString(res.height));
       bboxField.setText(sb.toString());
     }
   } catch (NumberFormatException ex) {
     bboxField.setBackground(Color.RED);
     return null;
   } catch (IllegalArgumentException iae) {
     bboxField.setBackground(Color.RED);
     return null;
   }
   bboxField.setBackground(null);
   return res;
 }