📄 columninforecordsaggregate.java
字号:
/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with* this work for additional information regarding copyright ownership.* The ASF licenses this file to You 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.poi.hssf.record.aggregates;import org.apache.poi.hssf.record.ColumnInfoRecord;import org.apache.poi.hssf.record.Record;import org.apache.poi.hssf.record.RecordInputStream;import java.util.ArrayList;import java.util.Iterator;import java.util.List;/** * @author Glen Stampoultzis * @version $Id: ColumnInfoRecordsAggregate.java 496526 2007-01-15 22:46:35Z markt $ */public class ColumnInfoRecordsAggregate extends Record{// int size = 0; List records = null; public ColumnInfoRecordsAggregate() { records = new ArrayList(); } /** You never fill an aggregate */ protected void fillFields(RecordInputStream in) { } /** Not required by an aggregate */ protected void validateSid(short id) { } /** It's an aggregate... just made something up */ public short getSid() { return -1012; } public int getRecordSize() { int size = 0; for ( Iterator iterator = records.iterator(); iterator.hasNext(); ) size += ( (ColumnInfoRecord) iterator.next() ).getRecordSize(); return size; } public Iterator getIterator() { return records.iterator(); } /** * Performs a deep clone of the record */ public Object clone() { ColumnInfoRecordsAggregate rec = new ColumnInfoRecordsAggregate(); for (int k = 0; k < records.size(); k++) { ColumnInfoRecord ci = ( ColumnInfoRecord ) records.get(k); ci=(ColumnInfoRecord) ci.clone(); rec.insertColumn( ci ); } return rec; } /** * Inserts a column into the aggregate (at the end of the list). */ public void insertColumn( ColumnInfoRecord col ) { records.add( col ); } /** * Inserts a column into the aggregate (at the position specified * by <code>idx</code>. */ public void insertColumn( int idx, ColumnInfoRecord col ) { records.add( idx, col ); } public int getNumColumns( ) { return records.size(); } /** * called by the class that is responsible for writing this sucker. * Subclasses should implement this so that their data is passed back in a * byte array. * * @param offset offset to begin writing at * @param data byte array containing instance data * @return number of bytes written */ public int serialize(int offset, byte [] data) { Iterator itr = records.iterator(); int pos = offset; while (itr.hasNext()) { pos += (( Record ) itr.next()).serialize(pos, data); } return pos - offset; } public int findStartOfColumnOutlineGroup(int idx) { // Find the start of the group. ColumnInfoRecord columnInfo = (ColumnInfoRecord) records.get( idx ); int level = columnInfo.getOutlineLevel(); while (idx != 0) { ColumnInfoRecord prevColumnInfo = (ColumnInfoRecord) records.get( idx - 1 ); if (columnInfo.getFirstColumn() - 1 == prevColumnInfo.getLastColumn()) { if (prevColumnInfo.getOutlineLevel() < level) { break; } idx--; columnInfo = prevColumnInfo; } else { break; } } return idx; } public int findEndOfColumnOutlineGroup(int idx) { // Find the end of the group. ColumnInfoRecord columnInfo = (ColumnInfoRecord) records.get( idx ); int level = columnInfo.getOutlineLevel(); while (idx < records.size() - 1) { ColumnInfoRecord nextColumnInfo = (ColumnInfoRecord) records.get( idx + 1 ); if (columnInfo.getLastColumn() + 1 == nextColumnInfo.getFirstColumn()) { if (nextColumnInfo.getOutlineLevel() < level) { break; } idx++; columnInfo = nextColumnInfo; } else { break; } } return idx; } public ColumnInfoRecord getColInfo(int idx) { return (ColumnInfoRecord) records.get( idx ); } public ColumnInfoRecord writeHidden( ColumnInfoRecord columnInfo, int idx, boolean hidden ) { int level = columnInfo.getOutlineLevel(); while (idx < records.size()) { columnInfo.setHidden( hidden ); if (idx + 1 < records.size()) { ColumnInfoRecord nextColumnInfo = (ColumnInfoRecord) records.get( idx + 1 ); if (columnInfo.getLastColumn() + 1 == nextColumnInfo.getFirstColumn()) { if (nextColumnInfo.getOutlineLevel() < level) break; columnInfo = nextColumnInfo; } else { break; } } idx++; } return columnInfo; } public boolean isColumnGroupCollapsed( int idx ) { int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup( idx ); if (endOfOutlineGroupIdx >= records.size()) return false; if (getColInfo(endOfOutlineGroupIdx).getLastColumn() + 1 != getColInfo(endOfOutlineGroupIdx + 1).getFirstColumn()) return false; else return getColInfo(endOfOutlineGroupIdx+1).getCollapsed(); } public boolean isColumnGroupHiddenByParent( int idx ) { // Look out outline details of end int endLevel; boolean endHidden; int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup( idx ); if (endOfOutlineGroupIdx >= records.size()) { endLevel = 0; endHidden = false; } else if (getColInfo(endOfOutlineGroupIdx).getLastColumn() + 1 != getColInfo(endOfOutlineGroupIdx + 1).getFirstColumn()) { endLevel = 0; endHidden = false; } else { endLevel = getColInfo( endOfOutlineGroupIdx + 1).getOutlineLevel(); endHidden = getColInfo( endOfOutlineGroupIdx + 1).getHidden(); } // Look out outline details of start int startLevel; boolean startHidden; int startOfOutlineGroupIdx = findStartOfColumnOutlineGroup( idx ); if (startOfOutlineGroupIdx <= 0) { startLevel = 0; startHidden = false; } else if (getColInfo(startOfOutlineGroupIdx).getFirstColumn() - 1 != getColInfo(startOfOutlineGroupIdx - 1).getLastColumn()) { startLevel = 0; startHidden = false; } else { startLevel = getColInfo( startOfOutlineGroupIdx - 1).getOutlineLevel(); startHidden = getColInfo( startOfOutlineGroupIdx - 1 ).getHidden(); } if (endLevel > startLevel) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -