You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/02/24 12:30:14 UTC

svn commit: r1825230 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action: OpenMode.java PDActionEmbeddedGoTo.java

Author: tilman
Date: Sat Feb 24 12:30:14 2018
New Revision: 1825230

URL: http://svn.apache.org/viewvc?rev=1825230&view=rev
Log:
PDFBOX-4117: use new enum type for NewWindow

Added:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/OpenMode.java   (with props)
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java

Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/OpenMode.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/OpenMode.java?rev=1825230&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/OpenMode.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/OpenMode.java Sat Feb 24 12:30:14 2018
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2018 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.pdmodel.interactive.action;
+
+/**
+ * This will specify whether to open the destination document in a new window.
+ *
+ * @author Tilman Hausherr
+ */
+public enum OpenMode
+{
+    /**
+     * The viewer application should behave in accordance with the current user preference.
+     */
+    USER_PREFERENCE,
+
+    /**
+     * Destination document will replace the current document in the same window.
+     */
+    SAME_WINDOW,
+
+    /**
+     * Open the destination document in a new window.
+     */
+    NEW_WINDOW
+}

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/OpenMode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java?rev=1825230&r1=1825229&r2=1825230&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionEmbeddedGoTo.java Sat Feb 24 12:30:14 2018
@@ -120,40 +120,47 @@ public class PDActionEmbeddedGoTo extend
     }
 
     /**
-     * This will specify whether to open the destination document in a new window. If this flag is
-     * false, the destination document will replace the current document in the same window. If this
-     * entry is absent, the viewer application should behave in accordance with the current user
-     * preference.
+     * This will specify whether to open the destination document in a new window, in the same
+     * window, or behave in accordance with the current user preference.
      *
-     * @return A flag specifying whether to open the destination document in a new window, or null
-     * if the entry is absent.
+     * @return A flag specifying how to open the destination document.
      */
-    public Boolean shouldOpenInNewWindow()
+    public OpenMode getOpenInNewWindow()
     {
         if (getCOSObject().getDictionaryObject(COSName.NEW_WINDOW) instanceof COSBoolean)
         {
-            return getCOSObject().getBoolean(COSName.NEW_WINDOW, true);
+            COSBoolean b = (COSBoolean) getCOSObject().getDictionaryObject(COSName.NEW_WINDOW);
+            return b.getValue() ? OpenMode.NEW_WINDOW : OpenMode.SAME_WINDOW;
         }
-        return null;
+        return OpenMode.USER_PREFERENCE;
     }
 
     /**
-     * This will specify whether to open the destination document in a new window. If this flag is
-     * false, the destination document will replace the current document in the same window. If this
-     * entry is absent, the viewer application should behave in accordance with the current user
-     * preference.
+     * This will specify whether to open the destination document in a new window.
      *
-     * @param value The flag value or null if the entry should be removed.
+     * @param value The flag value.
      */
-    public void setOpenInNewWindow(Boolean value)
+    public void setOpenInNewWindow(OpenMode value)
     {
-        if (value == null)
+        if (null == value)
         {
             getCOSObject().removeItem(COSName.NEW_WINDOW);
+            return;
         }
-        else
+        switch (value)
         {
-            getCOSObject().setBoolean(COSName.NEW_WINDOW, value);
+            case USER_PREFERENCE:
+                getCOSObject().removeItem(COSName.NEW_WINDOW);
+                break;
+            case SAME_WINDOW:
+                getCOSObject().setBoolean(COSName.NEW_WINDOW, false);
+                break;
+            case NEW_WINDOW:
+                getCOSObject().setBoolean(COSName.NEW_WINDOW, true);
+                break;
+            default:
+                // shouldn't happen unless the enum type is changed
+                break;
         }
     }