2 * Licensed to the Apache Software Foundation (ASF) under one or more
\r
3 * contributor license agreements. See the NOTICE file distributed with
\r
4 * this work for additional information regarding copyright ownership.
\r
5 * The ASF licenses this file to You under the Apache License, Version 2.0
\r
6 * (the "License"); you may not use this file except in compliance with
\r
7 * the License. You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
17 package org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure;
\r
19 import org.apache.pdfbox.cos.COSBase;
\r
20 import org.apache.pdfbox.cos.COSDictionary;
\r
21 import org.apache.pdfbox.cos.COSName;
\r
22 import org.apache.pdfbox.pdmodel.common.PDDictionaryWrapper;
\r
27 * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>
\r
28 * @version $Revision: $
\r
30 public class PDUserProperty extends PDDictionaryWrapper
\r
33 private final PDUserAttributeObject userAttributeObject;
\r
36 * Creates a new user property.
\r
38 * @param the user attribute object
\r
40 public PDUserProperty(PDUserAttributeObject userAttributeObject)
\r
42 this.userAttributeObject = userAttributeObject;
\r
46 * Creates a user property with a given dictionary.
\r
48 * @param dictionary the dictionary
\r
49 * @param the user attribute object
\r
51 public PDUserProperty(COSDictionary dictionary,
\r
52 PDUserAttributeObject userAttributeObject)
\r
55 this.userAttributeObject = userAttributeObject;
\r
60 * Returns the property name.
\r
62 * @return the property name
\r
64 public String getName()
\r
66 return this.getCOSDictionary().getNameAsString(COSName.N);
\r
70 * Sets the property name.
\r
72 * @param name the property name
\r
74 public void setName(String name)
\r
76 this.potentiallyNotifyChanged(this.getName(), name);
\r
77 this.getCOSDictionary().setName(COSName.N, name);
\r
81 * Returns the property value.
\r
83 * @return the property value
\r
85 public COSBase getValue()
\r
87 return this.getCOSDictionary().getDictionaryObject(COSName.V);
\r
91 * Sets the property value.
\r
93 * @param value the property value
\r
95 public void setValue(COSBase value)
\r
97 this.potentiallyNotifyChanged(this.getValue(), value);
\r
98 this.getCOSDictionary().setItem(COSName.V, value);
\r
102 * Returns the string for the property value.
\r
104 * @return the string for the property value
\r
106 public String getFormattedValue()
\r
108 return this.getCOSDictionary().getString(COSName.F);
\r
112 * Sets the string for the property value.
\r
114 * @param formattedValue the string for the property value
\r
116 public void setFormattedValue(String formattedValue)
\r
118 this.potentiallyNotifyChanged(this.getFormattedValue(), formattedValue);
\r
119 this.getCOSDictionary().setString(COSName.F, formattedValue);
\r
123 * Shall the property be hidden?
\r
125 * @return <code>true</code> if the property shall be hidden,
\r
126 * <code>false</code> otherwise
\r
128 public boolean isHidden()
\r
130 return this.getCOSDictionary().getBoolean(COSName.H, false);
\r
134 * Specifies whether the property shall be hidden.
\r
136 * @param hidden <code>true</code> if the property shall be hidden,
\r
137 * <code>false</code> otherwise
\r
139 public void setHidden(boolean hidden)
\r
141 this.potentiallyNotifyChanged(this.isHidden(), hidden);
\r
142 this.getCOSDictionary().setBoolean(COSName.H, hidden);
\r
147 public String toString()
\r
149 return new StringBuilder("Name=").append(this.getName())
\r
150 .append(", Value=").append(this.getValue())
\r
151 .append(", FormattedValue=").append(this.getFormattedValue())
\r
152 .append(", Hidden=").append(this.isHidden()).toString();
\r
157 * Notifies the user attribute object if the user property is changed.
\r
159 * @param oldEntry old entry
\r
160 * @param newEntry new entry
\r
162 private void potentiallyNotifyChanged(Object oldEntry, Object newEntry)
\r
164 if (this.isEntryChanged(oldEntry, newEntry))
\r
166 this.userAttributeObject.userPropertyChanged(this);
\r
171 * Is the value changed?
\r
173 * @param oldEntry old entry
\r
174 * @param newEntry new entry
\r
175 * @return <code>true</code> if the entry is changed, <code>false</code>
\r
178 private boolean isEntryChanged(Object oldEntry, Object newEntry)
\r
180 if (oldEntry == null)
\r
182 if (newEntry == null)
\r
188 return !oldEntry.equals(newEntry);
\r