예제 #1
0
 // todo consider composite cache.
 public static Composite getInstance(Name modeName, float alpha) {
   // check for -1, value not set and default should be used.
   if (alpha == -1) {
     alpha = 1;
   }
   if (modeName.equals(NORMAL_VALUE) || modeName.equals(COMPATIBLE_VALUE)) {
     return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
     //            return new BlendComposite(BlendingMode.NORMAL, alpha);
   } else if (modeName.equals(MULTIPLY_VALUE)) {
     return new BlendComposite(BlendingMode.MULTIPLY, alpha);
   } else if (modeName.equals(SCREEN_VALUE)) {
     return new BlendComposite(BlendingMode.SCREEN, alpha);
   } else if (modeName.equals(OVERLAY_VALUE)) {
     return new BlendComposite(BlendingMode.OVERLAY, alpha);
   } else if (modeName.equals(DARKEN_VALUE)) {
     return new BlendComposite(BlendingMode.DARKEN, alpha);
   } else if (modeName.equals(LIGHTEN_VALUE)) {
     return new BlendComposite(BlendingMode.LIGHTEN, alpha);
   } else if (modeName.equals(COLOR_DODGE_VALUE)) {
     return new BlendComposite(BlendingMode.SOFT_DODGE, alpha);
   } else if (modeName.equals(COLOR_BURN_VALUE)) {
     return new BlendComposite(BlendingMode.SOFT_BURN, alpha);
   } else if (modeName.equals(HARD_LIGHT_VALUE)) {
     return new BlendComposite(BlendingMode.HARD_LIGHT, alpha);
   } else if (modeName.equals(SOFT_LIGHT_VALUE)) {
     return new BlendComposite(BlendingMode.SOFT_LIGHT, alpha);
   } else if (modeName.equals(DIFFERENCE_VALUE)) {
     return new BlendComposite(BlendingMode.DIFFERENCE, alpha);
   } else if (modeName.equals(EXCLUSION_VALUE)) {
     return new BlendComposite(BlendingMode.EXCLUSION, alpha);
   }
   //        return new BlendComposite(BlendingMode.NORMAL, alpha);
   return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
 }
  public void createTextMarkupAnnotation(ArrayList<Shape> highlightBounds) {
    // mke sure we don't create a highlight annotation for every word in the
    // document when first selecting the tool for highlighted next. .
    if (documentViewModel.isSelectAll()) {
      documentViewController.clearSelectedText();
    }

    // get the geometric path of the selected text
    if (highlightBounds == null) {
      highlightBounds = getSelectedTextBounds();
    }
    // grab the selected text
    String contents = enableHighlightContents && highlightBounds != null ? getSelectedText() : "";

    // clear the selected text
    documentViewController.clearSelectedText();

    if (highlightBounds != null) {

      // bound of the selected text
      GeneralPath highlightPath = new GeneralPath();
      for (Shape bounds : highlightBounds) {
        highlightPath.append(bounds, false);
      }
      // get the bounds before convert to page space
      Rectangle bounds = highlightPath.getBounds();

      Rectangle tBbox = convertToPageSpace(highlightBounds, highlightPath);

      // create annotations types that that are rectangle based;
      // which is actually just link annotations
      TextMarkupAnnotation annotation =
          (TextMarkupAnnotation)
              AnnotationFactory.buildAnnotation(
                  documentViewModel.getDocument().getPageTree().getLibrary(), highLightType, tBbox);

      // pass outline shapes and bounds to create the highlight shapes
      if (TextMarkupAnnotation.SUBTYPE_HIGHLIGHT.equals(highLightType)) {
        annotation.setOpacity(TextMarkupAnnotation.HIGHLIGHT_ALPHA);
      }
      annotation.setContents(
          contents != null && enableHighlightContents ? contents : highLightType.toString());
      annotation.setColor(annotation.getTextMarkupColor());
      annotation.setCreationDate(PDate.formatDateTime(new Date()));
      annotation.setTitleText(System.getProperty("user.name"));
      annotation.setMarkupBounds(highlightBounds);
      annotation.setMarkupPath(highlightPath);
      annotation.setBBox(tBbox);
      // finalized the appearance properties.
      annotation.resetAppearanceStream(getPageTransform());

      // create new annotation given the general path
      AbstractAnnotationComponent comp =
          AnnotationComponentFactory.buildAnnotationComponent(
              annotation, documentViewController, pageViewComponent, documentViewModel);

      // convert to user rect to page space along with the bounds.
      comp.setBounds(bounds);
      comp.refreshAnnotationRect();

      // create component and add it to the page.
      // add them to the container, using absolute positioning.
      if (documentViewController.getAnnotationCallback() != null) {
        AnnotationCallback annotationCallback = documentViewController.getAnnotationCallback();
        annotationCallback.newAnnotation(pageViewComponent, comp);
      }
    }
    pageViewComponent.repaint();
  }
예제 #3
0
 /**
  * Creates a new Annotation object using properties from the annotationState paramater. If no
  * annotaitonState is provided a LinkAnnotation is returned with with a black border. The rect
  * specifies where the annotation should be located in user space.
  *
  * <p>This call adds the new Annotation object to the document library as well as the document
  * StateManager.
  *
  * @param library library to register annotation with
  * @param subType type of annotation to create
  * @param rect bounds of new annotation specified in user space.
  * @return new annotation object with the same properties as the one specified in annotaiton
  *     state.
  */
 public static Annotation buildAnnotation(Library library, final Name subType, Rectangle rect) {
   // build up a link annotation
   if (subType.equals(Annotation.SUBTYPE_LINK)) {
     return LinkAnnotation.getInstance(library, rect);
   }
   // highlight version of a TextMarkup annotation.
   else if (subType.equals(TextMarkupAnnotation.SUBTYPE_HIGHLIGHT)
       || subType.equals(TextMarkupAnnotation.SUBTYPE_STRIKE_OUT)
       || subType.equals(TextMarkupAnnotation.SUBTYPE_UNDERLINE)) {
     return TextMarkupAnnotation.getInstance(library, rect, subType);
   } else if (subType.equals(Annotation.SUBTYPE_LINE)) {
     return LineAnnotation.getInstance(library, rect);
   } else if (subType.equals(Annotation.SUBTYPE_SQUARE)) {
     return SquareAnnotation.getInstance(library, rect);
   } else if (subType.equals(Annotation.SUBTYPE_CIRCLE)) {
     return CircleAnnotation.getInstance(library, rect);
   } else if (subType.equals(Annotation.SUBTYPE_INK)) {
     return InkAnnotation.getInstance(library, rect);
   } else if (subType.equals(Annotation.SUBTYPE_FREE_TEXT)) {
     return FreeTextAnnotation.getInstance(library, rect);
   } else if (subType.equals(Annotation.SUBTYPE_TEXT)) {
     return TextAnnotation.getInstance(library, rect);
   } else if (subType.equals(Annotation.SUBTYPE_POPUP)) {
     return PopupAnnotation.getInstance(library, rect);
   } else {
     logger.warning("Unsupported Annotation type. ");
     return null;
   }
 }