Ejemplo n.º 1
0
 /** @overrides WorkspaceWidget.blockDropped() */
 @Override
 public void blockDropped(RenderableBlock block) {
   // add to view at the correct location
   Component oldParent = block.getParent();
   block.setLocation(
       SwingUtilities.convertPoint(oldParent, block.getLocation(), this.pageJComponent));
   addBlock(block);
   this.pageJComponent.setComponentZOrder(block, 0);
   this.pageJComponent.revalidate();
 }
Ejemplo n.º 2
0
 @Override
 public int compare(RenderableBlock rb1, RenderableBlock rb2) {
   if (rb1 == rb2) {
     return 0;
   } else {
     // translate points to a common reference: the parent of rb1
     Point pt1 = rb1.getLocation();
     Point pt2 =
         SwingUtilities.convertPoint(
             rb2.getParentWidget().getJComponent(),
             rb2.getLocation(),
             rb1.getParentWidget().getJComponent());
     if (pt1.getY() < pt2.getY()) {
       return -1;
     } else {
       return 1;
     }
   }
 }
Ejemplo n.º 3
0
  /**
   * @param block - the new block being added whose position must be revalidated
   * @requires block != null
   * @modifies block.location or this page's abstract width
   * @effects shifts this block into the page or increases the width of this page to fit the new
   *     block. It must then notify listeners that the page's size may have changed
   */
  public void reformBlockPosition(RenderableBlock block) {
    // move blocks in
    Point p =
        SwingUtilities.convertPoint(block.getParent(), block.getLocation(), this.pageJComponent);
    if (p.x < block.getHighlightStrokeWidth() / 2 + 1) {
      block.setLocation(block.getHighlightStrokeWidth() / 2 + 1, p.y);
      block.moveConnectedBlocks();
      // the block has moved, so update p
      p = SwingUtilities.convertPoint(block.getParent(), block.getLocation(), this.pageJComponent);
    } else if (p.x + block.getWidth() + block.getHighlightStrokeWidth() / 2 + 1
        > this.pageJComponent.getWidth()) {
      this.setPixelWidth(p.x + block.getWidth() + block.getHighlightStrokeWidth() / 2 + 1);
    }

    if (p.y < block.getHighlightStrokeWidth() / 2 + 1) {
      block.setLocation(p.x, block.getHighlightStrokeWidth() / 2 + 1);
      block.moveConnectedBlocks();
    } else if (p.y + block.getStackBounds().height + block.getHighlightStrokeWidth() / 2 + 1
        > this.pageJComponent.getHeight()) {
      block.setLocation(
          p.x,
          this.pageJComponent.getHeight()
              - block.getStackBounds().height
              - block.getHighlightStrokeWidth() / 2
              + 1);
      block.moveConnectedBlocks();
    }

    if (block.hasComment()) {
      // p = SwingUtilities.convertPoint(block.getComment().getParent(),
      // block.getComment().getLocation(), this.pageJComponent);
      p = block.getComment().getLocation();
      if (p.x + block.getComment().getWidth() + 1 > this.pageJComponent.getWidth()) {
        this.setPixelWidth(p.x + block.getComment().getWidth() + 1);
      }
    }

    // repaint all pages
    PageChangeEventManager.notifyListeners();
  }
Ejemplo n.º 4
0
  private void pasteStack(BlockNode node) {
    //		====================>>>>>>>>>>>>>>>>>>>>>>>>>
    //		====================focus coming in>>>>>>>>>> TODO
    //		====================>>>>>>>>>>>>>>>>>>>>>>>>>
    if (node == null) {
      return;
    }
    WorkspaceWidget widget = null;
    Iterable<WorkspaceWidget> widgets = null;
    Point spot = null;
    if (invalidBlockID(focusManager.getFocusBlockID())) {
      // canvas has focus
      Point location =
          SwingUtilities.convertPoint(
              this.blockCanvas.getCanvas(), this.focusManager.getCanvasPoint(), workspace);
      widget = workspace.getWidgetAt(location);
      spot =
          SwingUtilities.convertPoint(
              this.blockCanvas.getCanvas(),
              this.focusManager.getCanvasPoint(),
              widget.getJComponent());
    } else {
      RenderableBlock focusRenderable =
          workspace.getEnv().getRenderableBlock(focusManager.getFocusBlockID());
      widget = focusRenderable.getParentWidget();
      spot = focusRenderable.getLocation();
    }

    if (widget == null) {
      // TODO: To be examined and fixed, occurs on macs
      JOptionPane.showMessageDialog(
          frame, "Please click somewhere on the canvas first.", "Error", JOptionPane.PLAIN_MESSAGE);
      // throw new RuntimeException("Why are we adding a block to a null widget?");
    } else {
      // checks to see if the copied block still exists
      if (BlockUtilities.blockExists(workspace, node)) {
        // create mirror block and mirror childrens
        spot.translate(10, 10);
        RenderableBlock mirror = BlockUtilities.makeRenderable(workspace, node, widget);
        mirror.setLocation(spot);
        mirror.moveConnectedBlocks(); // make sure the childrens are placed correctly
      } else {
        // TODO: future version, allow them to paste
        JOptionPane.showMessageDialog(
            frame,
            "You cannot paste blocks that are currently NOT on the canvas."
                + "\nThis function will be available in a future version.\n",
            "Error",
            JOptionPane.PLAIN_MESSAGE);
      }
    }
  }