001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hslf.model.textproperties;
019:
020: /**
021: * Definition of a special kind of property of some text, or its
022: * paragraph. For these properties, a flag in the "contains" header
023: * field tells you the data property family will exist. The value
024: * of the property is itself a mask, encoding several different
025: * (but related) properties
026: */
027: public class BitMaskTextProp extends TextProp implements Cloneable {
028: private String[] subPropNames;
029: private int[] subPropMasks;
030: private boolean[] subPropMatches;
031:
032: /** Fetch the list of the names of the sub properties */
033: public String[] getSubPropNames() {
034: return subPropNames;
035: }
036:
037: /** Fetch the list of if the sub properties match or not */
038: public boolean[] getSubPropMatches() {
039: return subPropMatches;
040: }
041:
042: public BitMaskTextProp(int sizeOfDataBlock, int maskInHeader,
043: String overallName, String[] subPropNames) {
044: super (sizeOfDataBlock, maskInHeader, "bitmask");
045: this .subPropNames = subPropNames;
046: this .propName = overallName;
047: subPropMasks = new int[subPropNames.length];
048: subPropMatches = new boolean[subPropNames.length];
049:
050: // Initialise the masks list
051: for (int i = 0; i < subPropMasks.length; i++) {
052: subPropMasks[i] = (1 << i);
053: }
054: }
055:
056: /**
057: * As we're purely mask based, just set flags for stuff
058: * that is set
059: */
060: public int getWriteMask() {
061: return dataValue;
062: }
063:
064: /**
065: * Set the value of the text property, and recompute the sub
066: * properties based on it
067: */
068: public void setValue(int val) {
069: dataValue = val;
070:
071: // Figure out the values of the sub properties
072: for (int i = 0; i < subPropMatches.length; i++) {
073: subPropMatches[i] = false;
074: if ((dataValue & subPropMasks[i]) != 0) {
075: subPropMatches[i] = true;
076: }
077: }
078: }
079:
080: /**
081: * Fetch the true/false status of the subproperty with the given index
082: */
083: public boolean getSubValue(int idx) {
084: return subPropMatches[idx];
085: }
086:
087: /**
088: * Set the true/false status of the subproperty with the given index
089: */
090: public void setSubValue(boolean value, int idx) {
091: if (subPropMatches[idx] == value) {
092: return;
093: }
094: if (value) {
095: dataValue += subPropMasks[idx];
096: } else {
097: dataValue -= subPropMasks[idx];
098: }
099: subPropMatches[idx] = value;
100: }
101:
102: public Object clone() {
103: BitMaskTextProp newObj = (BitMaskTextProp) super .clone();
104:
105: // Don't carry over matches, but keep everything
106: // else as it was
107: newObj.subPropMatches = new boolean[subPropMatches.length];
108:
109: return newObj;
110: }
111: }
|