/** * 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; } }
/** * Gets an instance of a CircleAnnotation that has valid Object Reference. * * @param library document library * @param rect bounding rectangle in user space * @return new CircleAnnotation Instance. */ public static CircleAnnotation getInstance(Library library, Rectangle rect) { // state manager StateManager stateManager = library.getStateManager(); // create a new entries to hold the annotation properties HashMap<Name, Object> entries = new HashMap<Name, Object>(); // set default link annotation values. entries.put(Dictionary.TYPE_KEY, Annotation.TYPE_VALUE); entries.put(Dictionary.SUBTYPE_KEY, Annotation.SUBTYPE_CIRCLE); // coordinates if (rect != null) { entries.put(Annotation.RECTANGLE_KEY, PRectangle.getPRectangleVector(rect)); } else { entries.put(Annotation.RECTANGLE_KEY, new Rectangle(10, 10, 50, 100)); } // create the new instance CircleAnnotation circleAnnotation = new CircleAnnotation(library, entries); circleAnnotation.init(); circleAnnotation.setPObjectReference(stateManager.getNewReferencNumber()); circleAnnotation.setNew(true); // set default flags. circleAnnotation.setFlag(Annotation.FLAG_READ_ONLY, false); circleAnnotation.setFlag(Annotation.FLAG_NO_ROTATE, false); circleAnnotation.setFlag(Annotation.FLAG_NO_ZOOM, false); circleAnnotation.setFlag(Annotation.FLAG_PRINT, true); return circleAnnotation; }