Annotation.java

1
/*
2
 * $Id: Annotation.java 3373 2008-05-12 16:21:24Z xlv $
3
 *
4
 * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * (the "License"); you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the License.
13
 *
14
 * The Original Code is 'iText, a free JAVA-PDF library'.
15
 *
16
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
17
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
18
 * All Rights Reserved.
19
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
20
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
21
 *
22
 * Contributor(s): all the names of the contributors are added in the source code
23
 * where applicable.
24
 *
25
 * Alternatively, the contents of this file may be used under the terms of the
26
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
27
 * provisions of LGPL are applicable instead of those above.  If you wish to
28
 * allow use of your version of this file only under the terms of the LGPL
29
 * License and not to allow others to use your version of this file under
30
 * the MPL, indicate your decision by deleting the provisions above and
31
 * replace them with the notice and other provisions required by the LGPL.
32
 * If you do not delete the provisions above, a recipient may use your version
33
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
34
 *
35
 * This library is free software; you can redistribute it and/or modify it
36
 * under the terms of the MPL as stated above or under the terms of the GNU
37
 * Library General Public License as published by the Free Software Foundation;
38
 * either version 2 of the License, or any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful, but WITHOUT
41
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
42
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
43
 * details.
44
 *
45
 * If you didn't download this code from the following link, you should check if
46
 * you aren't using an obsolete version:
47
 * http://www.lowagie.com/iText/
48
 */
49
50
package com.lowagie.text;
51
52
import java.net.URL;
53
import java.util.ArrayList;
54
import java.util.HashMap;
55
import java.util.Map;
56
57
/**
58
 * An <CODE>Annotation</CODE> is a little note that can be added to a page on
59
 * a document.
60
 * 
61
 * @see Element
62
 * @see Anchor
63
 */
64
65
public class Annotation implements Element {
66
67
    // membervariables
68
69
    /** This is a possible annotation type. */
70
    public static final int TEXT = 0;
71
72
    /** This is a possible annotation type. */
73
    public static final int URL_NET = 1;
74
75
    /** This is a possible annotation type. */
76
    public static final int URL_AS_STRING = 2;
77
78
    /** This is a possible annotation type. */
79
    public static final int FILE_DEST = 3;
80
81
    /** This is a possible annotation type. */
82
    public static final int FILE_PAGE = 4;
83
84
    /** This is a possible annotation type. */
85
    public static final int NAMED_DEST = 5;
86
87
    /** This is a possible annotation type. */
88
    public static final int LAUNCH = 6;
89
90
    /** This is a possible annotation type. */
91
    public static final int SCREEN = 7;
92
93
    /** This is a possible attribute. */
94
    public static final String TITLE = "title";
95
96
    /** This is a possible attribute. */
97
    public static final String CONTENT = "content";
98
99
    /** This is a possible attribute. */
100
    public static final String URL = "url";
101
102
    /** This is a possible attribute. */
103
    public static final String FILE = "file";
104
105
    /** This is a possible attribute. */
106
    public static final String DESTINATION = "destination";
107
108
    /** This is a possible attribute. */
109
    public static final String PAGE = "page";
110
111
    /** This is a possible attribute. */
112
    public static final String NAMED = "named";
113
114
    /** This is a possible attribute. */
115
    public static final String APPLICATION = "application";
116
117
    /** This is a possible attribute. */
118
    public static final String PARAMETERS = "parameters";
119
120
    /** This is a possible attribute. */
121
    public static final String OPERATION = "operation";
122
123
    /** This is a possible attribute. */
124
    public static final String DEFAULTDIR = "defaultdir";
125
126
    /** This is a possible attribute. */
127
    public static final String LLX = "llx";
128
129
    /** This is a possible attribute. */
130
    public static final String LLY = "lly";
131
132
    /** This is a possible attribute. */
133
    public static final String URX = "urx";
134
135
    /** This is a possible attribute. */
136
    public static final String URY = "ury";
137
138
    /** This is a possible attribute. */
139
    public static final String MIMETYPE = "mime";
140
141
    /** This is the type of annotation. */
142
    protected int annotationtype;
143
144
    /** This is the title of the <CODE>Annotation</CODE>. */
145
    protected Map<String, Object> annotationAttributes = new HashMap<>();
146
147
    /** This is the lower left x-value */
148
    protected float llx = Float.NaN;
149
150
    /** This is the lower left y-value */
151
    protected float lly = Float.NaN;
152
153
    /** This is the upper right x-value */
154
    protected float urx = Float.NaN;
155
156
    /** This is the upper right y-value */
157
    protected float ury = Float.NaN;
158
159
    // constructors
160
161
    /**
162
     * Constructs an <CODE>Annotation</CODE> with a certain title and some
163
     * text.
164
     * 
165
     * @param llx
166
     *            lower left x coordinate
167
     * @param lly
168
     *            lower left y coordinate
169
     * @param urx
170
     *            upper right x coordinate
171
     * @param ury
172
     *            upper right y coordinate
173
     */
174
    private Annotation(float llx, float lly, float urx, float ury) {
175
        this.llx = llx;
176
        this.lly = lly;
177
        this.urx = urx;
178
        this.ury = ury;
179
    }
180
181
    /**
182
     * Copy constructor.
183
     */
184
    public Annotation(Annotation an) {
185
        annotationtype = an.annotationtype;
186
        annotationAttributes = an.annotationAttributes;
187
        llx = an.llx;
188
        lly = an.lly;
189
        urx = an.urx;
190
        ury = an.ury;
191
    }
192
    
193
    /**
194
     * Constructs an <CODE>Annotation</CODE> with a certain title and some
195
     * text.
196
     * 
197
     * @param title
198
     *            the title of the annotation
199
     * @param text
200
     *            the content of the annotation
201
     */
202
    public Annotation(String title, String text) {
203
        annotationtype = TEXT;
204
        annotationAttributes.put(TITLE, title);
205
        annotationAttributes.put(CONTENT, text);
206
    }
207
208
    /**
209
     * Constructs an <CODE>Annotation</CODE> with a certain title and some
210
     * text.
211
     * 
212
     * @param title
213
     *            the title of the annotation
214
     * @param text
215
     *            the content of the annotation
216
     * @param llx
217
     *            the lower left x-value
218
     * @param lly
219
     *            the lower left y-value
220
     * @param urx
221
     *            the upper right x-value
222
     * @param ury
223
     *            the upper right y-value
224
     */
225
    public Annotation(String title, String text, float llx, float lly,
226
            float urx, float ury) {
227
        this(llx, lly, urx, ury);
228
        annotationtype = TEXT;
229
        annotationAttributes.put(TITLE, title);
230
        annotationAttributes.put(CONTENT, text);
231
    }
232
233
    /**
234
     * Constructs an <CODE>Annotation</CODE>.
235
     * 
236
     * @param llx
237
     *            the lower left x-value
238
     * @param lly
239
     *            the lower left y-value
240
     * @param urx
241
     *            the upper right x-value
242
     * @param ury
243
     *            the upper right y-value
244
     * @param url
245
     *            the external reference
246
     */
247
    public Annotation(float llx, float lly, float urx, float ury, URL url) {
248
        this(llx, lly, urx, ury);
249
        annotationtype = URL_NET;
250
        annotationAttributes.put(URL, url);
251
    }
252
253
    /**
254
     * Constructs an <CODE>Annotation</CODE>.
255
     * 
256
     * @param llx
257
     *            the lower left x-value
258
     * @param lly
259
     *            the lower left y-value
260
     * @param urx
261
     *            the upper right x-value
262
     * @param ury
263
     *            the upper right y-value
264
     * @param url
265
     *            the external reference
266
     */
267
    public Annotation(float llx, float lly, float urx, float ury, String url) {
268
        this(llx, lly, urx, ury);
269
        annotationtype = URL_AS_STRING;
270
        annotationAttributes.put(FILE, url);
271
    }
272
273
    /**
274
     * Constructs an <CODE>Annotation</CODE>.
275
     * 
276
     * @param llx
277
     *            the lower left x-value
278
     * @param lly
279
     *            the lower left y-value
280
     * @param urx
281
     *            the upper right x-value
282
     * @param ury
283
     *            the upper right y-value
284
     * @param file
285
     *            an external PDF file
286
     * @param dest
287
     *            the destination in this file
288
     */
289
    public Annotation(float llx, float lly, float urx, float ury, String file,
290
            String dest) {
291
        this(llx, lly, urx, ury);
292
        annotationtype = FILE_DEST;
293
        annotationAttributes.put(FILE, file);
294
        annotationAttributes.put(DESTINATION, dest);
295
    }
296
297
    /**
298
     * Creates a Screen annotation to embed media clips
299
     * 
300
     * @param llx
301
     * @param lly
302
     * @param urx
303
     * @param ury
304
     * @param moviePath
305
     *            path to the media clip file
306
     * @param mimeType
307
     *            mime type of the media
308
     * @param showOnDisplay
309
     *            if true play on display of the page
310
     */
311
    public Annotation(float llx, float lly, float urx, float ury,
312
            String moviePath, String mimeType, boolean showOnDisplay) {
313
        this(llx, lly, urx, ury);
314
        annotationtype = SCREEN;
315
        annotationAttributes.put(FILE, moviePath);
316
        annotationAttributes.put(MIMETYPE, mimeType);
317
        annotationAttributes.put(PARAMETERS, new boolean[] {
318
                false /* embedded */, showOnDisplay });
319
    }
320
321
    /**
322
     * Constructs an <CODE>Annotation</CODE>.
323
     * 
324
     * @param llx
325
     *            the lower left x-value
326
     * @param lly
327
     *            the lower left y-value
328
     * @param urx
329
     *            the upper right x-value
330
     * @param ury
331
     *            the upper right y-value
332
     * @param file
333
     *            an external PDF file
334
     * @param page
335
     *            a page number in this file
336
     */
337
    public Annotation(float llx, float lly, float urx, float ury, String file,
338
            int page) {
339
        this(llx, lly, urx, ury);
340
        annotationtype = FILE_PAGE;
341
        annotationAttributes.put(FILE, file);
342
        annotationAttributes.put(PAGE, page);
343
    }
344
345
    /**
346
     * Constructs an <CODE>Annotation</CODE>.
347
     * 
348
     * @param llx
349
     *            the lower left x-value
350
     * @param lly
351
     *            the lower left y-value
352
     * @param urx
353
     *            the upper right x-value
354
     * @param ury
355
     *            the upper right y-value
356
     * @param named
357
     *            a named destination in this file
358
     */
359
    public Annotation(float llx, float lly, float urx, float ury, int named) {
360
        this(llx, lly, urx, ury);
361
        annotationtype = NAMED_DEST;
362
        annotationAttributes.put(NAMED, named);
363
    }
364
365
    /**
366
     * Constructs an <CODE>Annotation</CODE>.
367
     * 
368
     * @param llx
369
     *            the lower left x-value
370
     * @param lly
371
     *            the lower left y-value
372
     * @param urx
373
     *            the upper right x-value
374
     * @param ury
375
     *            the upper right y-value
376
     * @param application
377
     *            an external application
378
     * @param parameters
379
     *            parameters to pass to this application
380
     * @param operation
381
     *            the operation to pass to this application
382
     * @param defaultdir
383
     *            the default directory to run this application in
384
     */
385
    public Annotation(float llx, float lly, float urx, float ury,
386
            String application, String parameters, String operation,
387
            String defaultdir) {
388
        this(llx, lly, urx, ury);
389
        annotationtype = LAUNCH;
390
        annotationAttributes.put(APPLICATION, application);
391
        annotationAttributes.put(PARAMETERS, parameters);
392
        annotationAttributes.put(OPERATION, operation);
393
        annotationAttributes.put(DEFAULTDIR, defaultdir);
394
    }
395
396
    // implementation of the Element-methods
397
398
    /**
399
     * Gets the type of the text element.
400
     * 
401
     * @return a type
402
     */
403
    public int type() {
404
        return Element.ANNOTATION;
405
    }
406
407
    /**
408
     * Processes the element by adding it (or the different parts) to an <CODE>
409
     * ElementListener</CODE>.
410
     * 
411
     * @param listener
412
     *            an <CODE>ElementListener</CODE>
413
     * @return <CODE>true</CODE> if the element was processed successfully
414
     */
415
    public boolean process(ElementListener listener) {
416
        try {
417 1 1. process : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return listener.add(this);
418
        } catch (DocumentException de) {
419 1 1. process : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return false;
420
        }
421
    }
422
423
    /**
424
     * Gets all the chunks in this element.
425
     * 
426
     * @return an <CODE>ArrayList</CODE>
427
     */
428
429
    public ArrayList getChunks() {
430 1 1. getChunks : mutated return of Object value for com/lowagie/text/Annotation::getChunks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return new ArrayList();
431
    }
432
433
    // methods
434
435
    /**
436
     * Sets the dimensions of this annotation.
437
     * 
438
     * @param llx
439
     *            the lower left x-value
440
     * @param lly
441
     *            the lower left y-value
442
     * @param urx
443
     *            the upper right x-value
444
     * @param ury
445
     *            the upper right y-value
446
     */
447
    public void setDimensions(float llx, float lly, float urx, float ury) {
448
        this.llx = llx;
449
        this.lly = lly;
450
        this.urx = urx;
451
        this.ury = ury;
452
    }
453
454
    // methods to retrieve information
455
456
    /**
457
     * Returns the lower left x-value.
458
     * 
459
     * @return a value
460
     */
461
    public float llx() {
462
        return llx;
463
    }
464
465
    /**
466
     * Returns the lower left y-value.
467
     * 
468
     * @return a value
469
     */
470
    public float lly() {
471
        return lly;
472
    }
473
474
    /**
475
     * Returns the upper right x-value.
476
     * 
477
     * @return a value
478
     */
479
    public float urx() {
480
        return urx;
481
    }
482
483
    /**
484
     * Returns the upper right y-value.
485
     * 
486
     * @return a value
487
     */
488
    public float ury() {
489
        return ury;
490
    }
491
492
    /**
493
     * Returns the lower left x-value.
494
     * 
495
     * @param def
496
     *            the default value
497
     * @return a value
498
     */
499
    public float llx(float def) {
500 1 1. llx : negated conditional → NO_COVERAGE
        if (Float.isNaN(llx))
501 1 1. llx : replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::llx → NO_COVERAGE
            return def;
502 1 1. llx : replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::llx → NO_COVERAGE
        return llx;
503
    }
504
505
    /**
506
     * Returns the lower left y-value.
507
     * 
508
     * @param def
509
     *            the default value
510
     * @return a value
511
     */
512
    public float lly(float def) {
513 1 1. lly : negated conditional → NO_COVERAGE
        if (Float.isNaN(lly))
514 1 1. lly : replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::lly → NO_COVERAGE
            return def;
515 1 1. lly : replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::lly → NO_COVERAGE
        return lly;
516
    }
517
518
    /**
519
     * Returns the upper right x-value.
520
     * 
521
     * @param def
522
     *            the default value
523
     * @return a value
524
     */
525
    public float urx(float def) {
526 1 1. urx : negated conditional → NO_COVERAGE
        if (Float.isNaN(urx))
527 1 1. urx : replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::urx → NO_COVERAGE
            return def;
528 1 1. urx : replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::urx → NO_COVERAGE
        return urx;
529
    }
530
531
    /**
532
     * Returns the upper right y-value.
533
     * 
534
     * @param def
535
     *            the default value
536
     * @return a value
537
     */
538
    public float ury(float def) {
539 1 1. ury : negated conditional → NO_COVERAGE
        if (Float.isNaN(ury))
540 1 1. ury : replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::ury → NO_COVERAGE
            return def;
541 1 1. ury : replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::ury → NO_COVERAGE
        return ury;
542
    }
543
544
    /**
545
     * Returns the type of this <CODE>Annotation</CODE>.
546
     * 
547
     * @return a type
548
     */
549
    public int annotationType() {
550
        return annotationtype;
551
    }
552
553
    /**
554
     * Returns the title of this <CODE>Annotation</CODE>.
555
     * 
556
     * @return a name
557
     */
558
    public String title() {
559
        String s = (String) annotationAttributes.get(TITLE);
560 1 1. title : negated conditional → NO_COVERAGE
        if (s == null)
561
            s = "";
562 1 1. title : mutated return of Object value for com/lowagie/text/Annotation::title to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return s;
563
    }
564
565
    /**
566
     * Gets the content of this <CODE>Annotation</CODE>.
567
     * 
568
     * @return a reference
569
     */
570
    public String content() {
571
        String s = (String) annotationAttributes.get(CONTENT);
572 1 1. content : negated conditional → NO_COVERAGE
        if (s == null)
573
            s = "";
574 1 1. content : mutated return of Object value for com/lowagie/text/Annotation::content to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return s;
575
    }
576
577
    /**
578
     * Gets the content of this <CODE>Annotation</CODE>.
579
     * 
580
     * @return a reference
581
     */
582
    public Map<String, Object> attributes() {
583
        return annotationAttributes;
584
    }
585
    
586
    /**
587
     * @see com.lowagie.text.Element#isContent()
588
     * @since    iText 2.0.8
589
     */
590
    public boolean isContent() {
591
        return true;
592
    }
593
594
    /**
595
     * @see com.lowagie.text.Element#isNestable()
596
     * @since    iText 2.0.8
597
     */
598
    public boolean isNestable() {
599
        return true;
600
    }
601
602
}

Mutations

417

1.1
Location : process
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

419

1.1
Location : process
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

430

1.1
Location : getChunks
Killed by : none
mutated return of Object value for com/lowagie/text/Annotation::getChunks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

500

1.1
Location : llx
Killed by : none
negated conditional → NO_COVERAGE

501

1.1
Location : llx
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::llx → NO_COVERAGE

502

1.1
Location : llx
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::llx → NO_COVERAGE

513

1.1
Location : lly
Killed by : none
negated conditional → NO_COVERAGE

514

1.1
Location : lly
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::lly → NO_COVERAGE

515

1.1
Location : lly
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::lly → NO_COVERAGE

526

1.1
Location : urx
Killed by : none
negated conditional → NO_COVERAGE

527

1.1
Location : urx
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::urx → NO_COVERAGE

528

1.1
Location : urx
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::urx → NO_COVERAGE

539

1.1
Location : ury
Killed by : none
negated conditional → NO_COVERAGE

540

1.1
Location : ury
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::ury → NO_COVERAGE

541

1.1
Location : ury
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Annotation::ury → NO_COVERAGE

560

1.1
Location : title
Killed by : none
negated conditional → NO_COVERAGE

562

1.1
Location : title
Killed by : none
mutated return of Object value for com/lowagie/text/Annotation::title to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

572

1.1
Location : content
Killed by : none
negated conditional → NO_COVERAGE

574

1.1
Location : content
Killed by : none
mutated return of Object value for com/lowagie/text/Annotation::content to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2