コード例 #1
0
ファイル: MapXadlNoteLogic.java プロジェクト: zheng3/AS
  @Override
  protected PolygonAssembly addAssembly(
      IBNAModel model, ObjRef objRef, ObjRef[] relativeAncestorRefs) {

    PolygonAssembly assembly =
        new PolygonAssembly(
            model,
            parentThing,
            kind,
            new IPolygonGenerator() {

              public Point[] calculatePoints(Rectangle r) {
                int x1 = r.x;
                int y1 = r.y;
                int x2 = r.x + r.width;
                int y2 = r.y + r.height;

                int foldSize = 11;

                return new Point[] {
                  new Point(x1, y1),
                  new Point(x2, y1),
                  new Point(x2, y2 - foldSize),
                  new Point(x2 - foldSize, y2),
                  new Point(x2 - foldSize, y2 - foldSize),
                  new Point(x2, y2 - foldSize),
                  new Point(x2 - foldSize, y2),
                  new Point(x1, y2),
                  new Point(x1, y1)
                };
              }
            });
    assembly.getPolygonThing().setColor(new RGB(255, 255, 128));
    assembly.getPolygonBorderThing().setColor(new RGB(0, 0, 0));
    assembly
        .getPolygonGlassThing()
        .setBoundingBox(ArchipelagoUtils.findOpenSpotForNewThing(model, 200, 75));

    BoxedLabelThing boxedLabelThing = new BoxedLabelThing();
    model.addThing(boxedLabelThing, assembly.getPolygonThing());

    MirrorBoundingBoxLogic.mirrorBoundingBox(
        assembly.getPolygonGlassThing(), new Rectangle(5, 5, -10, -10), boxedLabelThing);

    UserEditableUtils.addEditableQuality(
        assembly.getPolygonGlassThing(),
        IHasMutableSelected.USER_MAY_SELECT,
        IHasMutableBoundingBox.USER_MAY_RESIZE,
        IRelativeMovable.USER_MAY_MOVE);
    UserEditableUtils.addEditableQuality(boxedLabelThing, IHasMutableText.USER_MAY_EDIT_TEXT);

    assembly.markPart("label", boxedLabelThing);

    return assembly;
  }
コード例 #2
0
 @Override
 protected void updateToTarget(
     IBNAModel sourceModel, IHasMutableBoundingBox targetThing, ThingEvent targetThingEvent) {
   IBNAModel targetModel = getBNAModel();
   if (sourceModel == null) {
     sourceModel = targetModel;
   }
   IThing gridMasterThing = sourceModel.getParentThing(targetThing);
   if (gridMasterThing instanceof IHasBoundingBox) {
     updateFromSource(sourceModel, (IHasBoundingBox) gridMasterThing, null);
   }
 }
コード例 #3
0
  @Override
  protected void updateFromSource(
      IBNAModel sourceModel, IHasBoundingBox sourceThing, ThingEvent sourceThingEvent) {
    IBNAModel targetModel = getBNAModel();
    Rectangle tableBB = sourceThing.getBoundingBox();
    GridMasterData gmd = sourceThing.getProperty(GRID_MASTER_DATA_PROPERTY_NAME);
    if (tableBB != null && gmd != null) {
      IThing[] childThings = sourceModel.getChildThings(sourceThing);

      int cols = gmd.numColumns;
      int rows = (childThings.length + gmd.numColumns - 1) / gmd.numColumns;

      SizeHint[] colSizeHints = new SizeHint[cols];
      SizeHint[] rowSizeHints = new SizeHint[rows];

      // calculate cumulative column and row size hints
      for (int i = 0; i < childThings.length; i++) {
        GridData gd = childThings[i].getProperty(GRID_DATA_PROPERTY_NAME);
        int row = i / cols;
        int col = i % cols;
        // System.err.println("row=" + row + " col=" + col + " hint=" + gd);
        if (gd != null) {

          SizeHint colHint = colSizeHints[col];
          if (colHint == null) {
            colSizeHints[col] = colHint = new SizeHint(0, 0);
          }
          SizeHint widthHint = gd.widthHint;
          if (widthHint != null) {
            if (colHint.minSize < widthHint.minSize) {
              colHint.minSize = widthHint.minSize;
            }
            if (colHint.minRatio < widthHint.minRatio) {
              colHint.minRatio = widthHint.minRatio;
            }
          }

          SizeHint rowHint = rowSizeHints[row];
          if (rowHint == null) {
            rowSizeHints[row] = rowHint = new SizeHint(0, 0);
          }
          SizeHint heightHint = gd.heightHint;
          if (heightHint != null) {
            if (rowHint.minSize < heightHint.minSize) {
              rowHint.minSize = heightHint.minSize;
            }
            if (rowHint.minRatio < heightHint.minRatio) {
              rowHint.minRatio = heightHint.minRatio;
            }
          }
        }
      }

      // distribute table size to rows and columns
      int[] widths = calculateSizes(tableBB.width, colSizeHints);
      int[] heights = calculateSizes(tableBB.height, rowSizeHints);
      int[] xs = calculateOffsets(tableBB.x, widths);
      int[] ys = calculateOffsets(tableBB.y, heights);

      // assign cell sizes to things
      for (int i = 0; i < childThings.length; i++) {
        int col = i % cols;
        int row = i / cols;

        childThings[i].setProperty(
            IHasBoundingBox.BOUNDING_BOX_PROPERTY_NAME,
            new Rectangle(xs[col], ys[row], widths[col], heights[row]));
      }
    }
  }