/**
   * do a dilation operation
   *
   * @param original Original region
   * @param r Radius of a circle used for dilation operation
   * @param search HashSet of search area
   * @return Dilated region
   */
  public static Region doDilationOperation(Region original, int r, HashSet<Integer> search) {
    Region region = new Region();

    /*
     * Create a relative distance list of a radius 'r' circle
     */
    ArrayList<Point> rdlist = new ArrayList<Point>();
    for (int x = -r; x <= r; x++) {
      for (int y = -r; y <= r; y++) {
        if (x * x + y * y <= r * r) {
          rdlist.add(new Point(x, y));
        }
      }
    }

    /*
     * Set search area if 'search' is empty
     */
    if (search == null || search.isEmpty()) {
      search = new HashSet<Integer>();

      int x_from = Math.max(original.left - r, 0);
      int x_to = Math.min(original.right + r, canvas_width - 1);
      int y_from = Math.max(original.top - r, 0);
      int y_to = Math.min(original.bottom + r, canvas_height - 1);
      for (int x = x_from; x <= x_to; x++) {
        for (int y = y_from; y <= y_to; y++) {
          search.add(ID(x, y));
        }
      }
    }

    /*
     * Dilation operation
     */
    for (int id : search) {
      Point pos = XY(id);
      boolean flag = false;

      // check if there is a region pixel around (x, y)
      for (Point p : rdlist) {
        if (original.contains(pos.x + p.x, pos.y + p.y)) {
          flag = true;
          break;
        }
      }

      // point (x, y) is added by dilation operation
      if (flag) {
        region.addPixel(pos.x, pos.y);
      }
    }

    return region;
  }
Esempio n. 2
0
  public TrapezoidList tesselateStroke(
      Shape s,
      BasicStroke bs,
      boolean thin,
      boolean adjust,
      boolean antialias,
      AffineTransform at,
      Region clip) {

    float lw;
    if (thin) {
      if (antialias) {
        lw = 0.5f;
      } else {
        lw = 1.0f;
      }
    } else {
      lw = bs.getLineWidth();
    }

    convertPathData(s, at);

    double[] dashArray = floatToDoubleArray(bs.getDashArray());
    xTrapArray[0] = 0;

    xTrapArray =
        tesselateStrokeNative(
            points.getArray(),
            ops.getArray(),
            points.getSize(),
            ops.getSize(),
            xTrapArray,
            xTrapArray.length,
            lw,
            bs.getEndCap(),
            bs.getLineJoin(),
            bs.getMiterLimit(),
            dashArray,
            dashArray.length,
            bs.getDashPhase(),
            1,
            0,
            0,
            0,
            1,
            0,
            clip.getLoX(),
            clip.getLoY(),
            clip.getHiX(),
            clip.getHiY());

    return new TrapezoidList(xTrapArray);
  }
Esempio n. 3
0
  public TrapezoidList tesselateFill(Shape s, AffineTransform at, Region clip) {
    int windingRule = convertPathData(s, at);
    xTrapArray[0] = 0;

    xTrapArray =
        tesselateFillNative(
            points.getArray(),
            ops.getArray(),
            points.getSize(),
            ops.getSize(),
            xTrapArray,
            xTrapArray.length,
            getCairoWindingRule(windingRule),
            clip.getLoX(),
            clip.getLoY(),
            clip.getHiX(),
            clip.getHiY());

    return new TrapezoidList(xTrapArray);
  }
Esempio n. 4
0
  @Override
  public Color getColor(SynthContext context, ColorType type) {
    JComponent c = context.getComponent();
    Region id = context.getRegion();
    int state = context.getComponentState();

    if (c.getName() == "Table.cellRenderer") {
      if (type == ColorType.BACKGROUND) {
        return c.getBackground();
      }
      if (type == ColorType.FOREGROUND) {
        return c.getForeground();
      }
    }

    if (id == Region.LABEL && type == ColorType.TEXT_FOREGROUND) {
      type = ColorType.FOREGROUND;
    }

    // For the enabled state, prefer the widget's colors
    if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) {
      if (type == ColorType.BACKGROUND) {
        return c.getBackground();
      } else if (type == ColorType.FOREGROUND) {
        return c.getForeground();
      } else if (type == ColorType.TEXT_FOREGROUND) {
        // If getForeground returns a non-UIResource it means the
        // developer has explicitly set the foreground, use it over
        // that of TEXT_FOREGROUND as that is typically the expected
        // behavior.
        Color color = c.getForeground();
        if (color != null && !(color instanceof UIResource)) {
          return color;
        }
      }
    }
    return getColorForState(context, type);
  }
Esempio n. 5
0
  /**
   * Returns the color for the specified state.
   *
   * @param context SynthContext identifying requestor
   * @param state to get the color for
   * @param type of the color
   * @return Color to render with
   */
  Color getGTKColor(SynthContext context, int state, ColorType type) {
    if (context != null) {
      JComponent c = context.getComponent();
      Region id = context.getRegion();

      state = GTKLookAndFeel.synthStateToGTKState(id, state);
      if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) {
        if (type == ColorType.BACKGROUND || type == ColorType.TEXT_BACKGROUND) {
          Color bg = c.getBackground();
          if (!(bg instanceof UIResource)) {
            return bg;
          }
        } else if (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND) {
          Color fg = c.getForeground();
          if (!(fg instanceof UIResource)) {
            return fg;
          }
        }
      }
    }

    return getStyleSpecificColor(context, state, type);
  }
Esempio n. 6
0
  /**
   * Returns the Insets. If <code>insets</code> is non-null the resulting insets will be placed in
   * it, otherwise a new Insets object will be created and returned.
   *
   * @param context SynthContext identifying requestor
   * @param insets Where to place Insets
   * @return Insets.
   */
  @Override
  public Insets getInsets(SynthContext state, Insets insets) {
    Region id = state.getRegion();
    JComponent component = state.getComponent();
    String name = (id.isSubregion()) ? null : component.getName();

    if (insets == null) {
      insets = new Insets(0, 0, 0, 0);
    } else {
      insets.top = insets.bottom = insets.left = insets.right = 0;
    }

    if (id == Region.ARROW_BUTTON || id == Region.BUTTON || id == Region.TOGGLE_BUTTON) {
      if ("Spinner.previousButton" == name || "Spinner.nextButton" == name) {
        return getSimpleInsets(state, insets, 1);
      } else {
        return getButtonInsets(state, insets);
      }
    } else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) {
      return getRadioInsets(state, insets);
    } else if (id == Region.MENU_BAR) {
      return getMenuBarInsets(state, insets);
    } else if (id == Region.MENU
        || id == Region.MENU_ITEM
        || id == Region.CHECK_BOX_MENU_ITEM
        || id == Region.RADIO_BUTTON_MENU_ITEM) {
      return getMenuItemInsets(state, insets);
    } else if (id == Region.FORMATTED_TEXT_FIELD) {
      return getTextFieldInsets(state, insets);
    } else if (id == Region.INTERNAL_FRAME) {
      insets = Metacity.INSTANCE.getBorderInsets(state, insets);
    } else if (id == Region.LABEL) {
      if ("TableHeader.renderer" == name) {
        return getButtonInsets(state, insets);
      } else if (component instanceof ListCellRenderer) {
        return getTextFieldInsets(state, insets);
      } else if ("Tree.cellRenderer" == name) {
        return getSimpleInsets(state, insets, 1);
      }
    } else if (id == Region.OPTION_PANE) {
      return getSimpleInsets(state, insets, 6);
    } else if (id == Region.POPUP_MENU) {
      return getSimpleInsets(state, insets, 2);
    } else if (id == Region.PROGRESS_BAR
        || id == Region.SLIDER
        || id == Region.TABBED_PANE
        || id == Region.TABBED_PANE_CONTENT
        || id == Region.TOOL_BAR
        || id == Region.TOOL_BAR_DRAG_WINDOW
        || id == Region.TOOL_TIP) {
      return getThicknessInsets(state, insets);
    } else if (id == Region.SCROLL_BAR) {
      return getScrollBarInsets(state, insets);
    } else if (id == Region.SLIDER_TRACK) {
      return getSliderTrackInsets(state, insets);
    } else if (id == Region.TABBED_PANE_TAB) {
      return getTabbedPaneTabInsets(state, insets);
    } else if (id == Region.TEXT_FIELD || id == Region.PASSWORD_FIELD) {
      if (name == "Tree.cellEditor") {
        return getSimpleInsets(state, insets, 1);
      }
      return getTextFieldInsets(state, insets);
    } else if (id == Region.SEPARATOR
        || id == Region.POPUP_MENU_SEPARATOR
        || id == Region.TOOL_BAR_SEPARATOR) {
      return getSeparatorInsets(state, insets);
    } else if (id == GTKEngine.CustomRegion.TITLED_BORDER) {
      return getThicknessInsets(state, insets);
    }
    return insets;
  }