1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.pdfbox.pdmodel.interactive.action; 18 19 import org.apache.pdfbox.cos.COSBase; 20 import org.apache.pdfbox.cos.COSDictionary; 21 22 import org.apache.pdfbox.pdmodel.common.COSObjectable; 23 import org.apache.pdfbox.pdmodel.interactive.action.type.PDAction; 24 25 /** 26 * This class represents an annotation's dictionary of actions 27 * that occur due to events. 28 * 29 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 30 * @author Panagiotis Toumasis (ptoumasis@mail.gr) 31 * @version $Revision: 1.2 $ 32 */ 33 public class PDAnnotationAdditionalActions implements COSObjectable 34 { 35 private COSDictionary actions; 36 37 /** 38 * Default constructor. 39 */ 40 public PDAnnotationAdditionalActions() 41 { 42 actions = new COSDictionary(); 43 } 44 45 /** 46 * Constructor. 47 * 48 * @param a The action dictionary. 49 */ 50 public PDAnnotationAdditionalActions( COSDictionary a ) 51 { 52 actions = a; 53 } 54 55 /** 56 * Convert this standard java object to a COS object. 57 * 58 * @return The cos object that matches this Java object. 59 */ 60 public COSBase getCOSObject() 61 { 62 return actions; 63 } 64 65 /** 66 * Convert this standard java object to a COS object. 67 * 68 * @return The cos object that matches this Java object. 69 */ 70 public COSDictionary getCOSDictionary() 71 { 72 return actions; 73 } 74 75 /** 76 * This will get an action to be performed when the cursor 77 * enters the annotation's active area. 78 * 79 * @return The E entry of annotation's additional actions dictionary. 80 */ 81 public PDAction getE() 82 { 83 COSDictionary e = (COSDictionary)actions.getDictionaryObject( "E" ); 84 PDAction retval = null; 85 if( e != null ) 86 { 87 retval = PDActionFactory.createAction( e ); 88 } 89 return retval; 90 } 91 92 /** 93 * This will set an action to be performed when the cursor 94 * enters the annotation's active area. 95 * 96 * @param e The action to be performed. 97 */ 98 public void setE( PDAction e ) 99 { 100 actions.setItem( "E", e ); 101 } 102 103 /** 104 * This will get an action to be performed when the cursor 105 * exits the annotation's active area. 106 * 107 * @return The X entry of annotation's additional actions dictionary. 108 */ 109 public PDAction getX() 110 { 111 COSDictionary x = (COSDictionary)actions.getDictionaryObject( "X" ); 112 PDAction retval = null; 113 if( x != null ) 114 { 115 retval = PDActionFactory.createAction( x ); 116 } 117 return retval; 118 } 119 120 /** 121 * This will set an action to be performed when the cursor 122 * exits the annotation's active area. 123 * 124 * @param x The action to be performed. 125 */ 126 public void setX( PDAction x ) 127 { 128 actions.setItem( "X", x ); 129 } 130 131 /** 132 * This will get an action to be performed when the mouse button 133 * is pressed inside the annotation's active area. 134 * The name D stands for "down". 135 * 136 * @return The d entry of annotation's additional actions dictionary. 137 */ 138 public PDAction getD() 139 { 140 COSDictionary d = (COSDictionary)actions.getDictionaryObject( "D" ); 141 PDAction retval = null; 142 if( d != null ) 143 { 144 retval = PDActionFactory.createAction( d ); 145 } 146 return retval; 147 } 148 149 /** 150 * This will set an action to be performed when the mouse button 151 * is pressed inside the annotation's active area. 152 * The name D stands for "down". 153 * 154 * @param d The action to be performed. 155 */ 156 public void setD( PDAction d ) 157 { 158 actions.setItem( "D", d ); 159 } 160 161 /** 162 * This will get an action to be performed when the mouse button 163 * is released inside the annotation's active area. 164 * The name U stands for "up". 165 * 166 * @return The U entry of annotation's additional actions dictionary. 167 */ 168 public PDAction getU() 169 { 170 COSDictionary u = (COSDictionary)actions.getDictionaryObject( "U" ); 171 PDAction retval = null; 172 if( u != null ) 173 { 174 retval = PDActionFactory.createAction( u ); 175 } 176 return retval; 177 } 178 179 /** 180 * This will set an action to be performed when the mouse button 181 * is released inside the annotation's active area. 182 * The name U stands for "up". 183 * 184 * @param u The action to be performed. 185 */ 186 public void setU( PDAction u ) 187 { 188 actions.setItem( "U", u ); 189 } 190 191 /** 192 * This will get an action to be performed when the annotation 193 * receives the input focus. 194 * 195 * @return The Fo entry of annotation's additional actions dictionary. 196 */ 197 public PDAction getFo() 198 { 199 COSDictionary fo = (COSDictionary)actions.getDictionaryObject( "Fo" ); 200 PDAction retval = null; 201 if( fo != null ) 202 { 203 retval = PDActionFactory.createAction( fo ); 204 } 205 return retval; 206 } 207 208 /** 209 * This will set an action to be performed when the annotation 210 * receives the input focus. 211 * 212 * @param fo The action to be performed. 213 */ 214 public void setFo( PDAction fo ) 215 { 216 actions.setItem( "Fo", fo ); 217 } 218 219 /** 220 * This will get an action to be performed when the annotation 221 * loses the input focus. 222 * The name Bl stands for "blurred". 223 * 224 * @return The Bl entry of annotation's additional actions dictionary. 225 */ 226 public PDAction getBl() 227 { 228 COSDictionary bl = (COSDictionary)actions.getDictionaryObject( "Bl" ); 229 PDAction retval = null; 230 if( bl != null ) 231 { 232 retval = PDActionFactory.createAction( bl ); 233 } 234 return retval; 235 } 236 237 /** 238 * This will set an action to be performed when the annotation 239 * loses the input focus. 240 * The name Bl stands for "blurred". 241 * 242 * @param bl The action to be performed. 243 */ 244 public void setBl( PDAction bl ) 245 { 246 actions.setItem( "Bl", bl ); 247 } 248 249 /** 250 * This will get an action to be performed when the page containing 251 * the annotation is opened. The action is executed after the O action 252 * in the page's additional actions dictionary and the OpenAction entry 253 * in the document catalog, if such actions are present. 254 * 255 * @return The PO entry of annotation's additional actions dictionary. 256 */ 257 public PDAction getPO() 258 { 259 COSDictionary po = (COSDictionary)actions.getDictionaryObject( "PO" ); 260 PDAction retval = null; 261 if( po != null ) 262 { 263 retval = PDActionFactory.createAction( po ); 264 } 265 return retval; 266 } 267 268 /** 269 * This will set an action to be performed when the page containing 270 * the annotation is opened. The action is executed after the O action 271 * in the page's additional actions dictionary and the OpenAction entry 272 * in the document catalog, if such actions are present. 273 * 274 * @param po The action to be performed. 275 */ 276 public void setPO( PDAction po ) 277 { 278 actions.setItem( "PO", po ); 279 } 280 281 /** 282 * This will get an action to be performed when the page containing 283 * the annotation is closed. The action is executed before the C action 284 * in the page's additional actions dictionary, if present. 285 * 286 * @return The PC entry of annotation's additional actions dictionary. 287 */ 288 public PDAction getPC() 289 { 290 COSDictionary pc = (COSDictionary)actions.getDictionaryObject( "PC" ); 291 PDAction retval = null; 292 if( pc != null ) 293 { 294 retval = PDActionFactory.createAction( pc ); 295 } 296 return retval; 297 } 298 299 /** 300 * This will set an action to be performed when the page containing 301 * the annotation is closed. The action is executed before the C action 302 * in the page's additional actions dictionary, if present. 303 * 304 * @param pc The action to be performed. 305 */ 306 public void setPC( PDAction pc ) 307 { 308 actions.setItem( "PC", pc ); 309 } 310 311 /** 312 * This will get an action to be performed when the page containing 313 * the annotation becomes visible in the viewer application's user interface. 314 * 315 * @return The PV entry of annotation's additional actions dictionary. 316 */ 317 public PDAction getPV() 318 { 319 COSDictionary pv = (COSDictionary)actions.getDictionaryObject( "PV" ); 320 PDAction retval = null; 321 if( pv != null ) 322 { 323 retval = PDActionFactory.createAction( pv ); 324 } 325 return retval; 326 } 327 328 /** 329 * This will set an action to be performed when the page containing 330 * the annotation becomes visible in the viewer application's user interface. 331 * 332 * @param pv The action to be performed. 333 */ 334 public void setPV( PDAction pv ) 335 { 336 actions.setItem( "PV", pv ); 337 } 338 339 /** 340 * This will get an action to be performed when the page containing the annotation 341 * is no longer visible in the viewer application's user interface. 342 * 343 * @return The PI entry of annotation's additional actions dictionary. 344 */ 345 public PDAction getPI() 346 { 347 COSDictionary pi = (COSDictionary)actions.getDictionaryObject( "PI" ); 348 PDAction retval = null; 349 if( pi != null ) 350 { 351 retval = PDActionFactory.createAction( pi ); 352 } 353 return retval; 354 } 355 356 /** 357 * This will set an action to be performed when the page containing the annotation 358 * is no longer visible in the viewer application's user interface. 359 * 360 * @param pi The action to be performed. 361 */ 362 public void setPI( PDAction pi ) 363 { 364 actions.setItem( "PI", pi ); 365 } 366 }