123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- /* ====================================================================
- 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.cf;
-
- import org.apache.poi.util.BitField;
- import org.apache.poi.util.BitFieldFactory;
- import org.apache.poi.util.LittleEndian;
- import org.apache.poi.util.LittleEndianInput;
- import org.apache.poi.util.LittleEndianOutput;
-
- /**
- * Border Formatting Block of the Conditional Formatting Rule Record.
- */
- public final class BorderFormatting {
- /** No border */
- public final static short BORDER_NONE = 0x0;
- /** Thin border */
- public final static short BORDER_THIN = 0x1;
- /** Medium border */
- public final static short BORDER_MEDIUM = 0x2;
- /** dash border */
- public final static short BORDER_DASHED = 0x3;
- /** dot border */
- public final static short BORDER_HAIR = 0x4;
- /** Thick border */
- public final static short BORDER_THICK = 0x5;
- /** double-line border */
- public final static short BORDER_DOUBLE = 0x6;
- /** hair-line border */
- public final static short BORDER_DOTTED = 0x7;
- /** Medium dashed border */
- public final static short BORDER_MEDIUM_DASHED = 0x8;
- /** dash-dot border */
- public final static short BORDER_DASH_DOT = 0x9;
- /** medium dash-dot border */
- public final static short BORDER_MEDIUM_DASH_DOT = 0xA;
- /** dash-dot-dot border */
- public final static short BORDER_DASH_DOT_DOT = 0xB;
- /** medium dash-dot-dot border */
- public final static short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
- /** slanted dash-dot border */
- public final static short BORDER_SLANTED_DASH_DOT = 0xD;
-
- // BORDER FORMATTING BLOCK
- // For Border Line Style codes see HSSFCellStyle.BORDER_XXXXXX
- private int field_13_border_styles1;
- private static final BitField bordLeftLineStyle = BitFieldFactory.getInstance(0x0000000F);
- private static final BitField bordRightLineStyle = BitFieldFactory.getInstance(0x000000F0);
- private static final BitField bordTopLineStyle = BitFieldFactory.getInstance(0x00000F00);
- private static final BitField bordBottomLineStyle= BitFieldFactory.getInstance(0x0000F000);
- private static final BitField bordLeftLineColor = BitFieldFactory.getInstance(0x007F0000);
- private static final BitField bordRightLineColor = BitFieldFactory.getInstance(0x3F800000);
- private static final BitField bordTlBrLineOnOff = BitFieldFactory.getInstance(0x40000000);
- private static final BitField bordBlTrtLineOnOff = BitFieldFactory.getInstance(0x80000000);
-
- private int field_14_border_styles2;
- private static final BitField bordTopLineColor = BitFieldFactory.getInstance(0x0000007F);
- private static final BitField bordBottomLineColor= BitFieldFactory.getInstance(0x00003f80);
- private static final BitField bordDiagLineColor = BitFieldFactory.getInstance(0x001FC000);
- private static final BitField bordDiagLineStyle = BitFieldFactory.getInstance(0x01E00000);
-
-
- public BorderFormatting() {
- field_13_border_styles1 = 0;
- field_14_border_styles2 = 0;
- }
-
- /** Creates new FontFormatting */
- public BorderFormatting(LittleEndianInput in) {
- field_13_border_styles1 = in.readInt();
- field_14_border_styles2 = in.readInt();
- }
-
- public int getDataLength() {
- return 8;
- }
-
- /**
- * set the type of border to use for the left border of the cell
- * @param border type
- * @see #BORDER_NONE
- * @see #BORDER_THIN
- * @see #BORDER_MEDIUM
- * @see #BORDER_DASHED
- * @see #BORDER_DOTTED
- * @see #BORDER_THICK
- * @see #BORDER_DOUBLE
- * @see #BORDER_HAIR
- * @see #BORDER_MEDIUM_DASHED
- * @see #BORDER_DASH_DOT
- * @see #BORDER_MEDIUM_DASH_DOT
- * @see #BORDER_DASH_DOT_DOT
- * @see #BORDER_MEDIUM_DASH_DOT_DOT
- * @see #BORDER_SLANTED_DASH_DOT
- */
- public void setBorderLeft(int border) {
- field_13_border_styles1 = bordLeftLineStyle.setValue(field_13_border_styles1, border);
- }
-
- /**
- * get the type of border to use for the left border of the cell
- * @return border type
- * @see #BORDER_NONE
- * @see #BORDER_THIN
- * @see #BORDER_MEDIUM
- * @see #BORDER_DASHED
- * @see #BORDER_DOTTED
- * @see #BORDER_THICK
- * @see #BORDER_DOUBLE
- * @see #BORDER_HAIR
- * @see #BORDER_MEDIUM_DASHED
- * @see #BORDER_DASH_DOT
- * @see #BORDER_MEDIUM_DASH_DOT
- * @see #BORDER_DASH_DOT_DOT
- * @see #BORDER_MEDIUM_DASH_DOT_DOT
- * @see #BORDER_SLANTED_DASH_DOT
- */
- public int getBorderLeft() {
- return bordLeftLineStyle.getValue(field_13_border_styles1);
- }
-
- /**
- * set the type of border to use for the right border of the cell
- * @param border type
- * @see #BORDER_NONE
- * @see #BORDER_THIN
- * @see #BORDER_MEDIUM
- * @see #BORDER_DASHED
- * @see #BORDER_DOTTED
- * @see #BORDER_THICK
- * @see #BORDER_DOUBLE
- * @see #BORDER_HAIR
- * @see #BORDER_MEDIUM_DASHED
- * @see #BORDER_DASH_DOT
- * @see #BORDER_MEDIUM_DASH_DOT
- * @see #BORDER_DASH_DOT_DOT
- * @see #BORDER_MEDIUM_DASH_DOT_DOT
- * @see #BORDER_SLANTED_DASH_DOT
- */
- public void setBorderRight(int border) {
- field_13_border_styles1 = bordRightLineStyle.setValue(field_13_border_styles1, border);
- }
-
- /**
- * get the type of border to use for the right border of the cell
- * @return border type
- * @see #BORDER_NONE
- * @see #BORDER_THIN
- * @see #BORDER_MEDIUM
- * @see #BORDER_DASHED
- * @see #BORDER_DOTTED
- * @see #BORDER_THICK
- * @see #BORDER_DOUBLE
- * @see #BORDER_HAIR
- * @see #BORDER_MEDIUM_DASHED
- * @see #BORDER_DASH_DOT
- * @see #BORDER_MEDIUM_DASH_DOT
- * @see #BORDER_DASH_DOT_DOT
- * @see #BORDER_MEDIUM_DASH_DOT_DOT
- * @see #BORDER_SLANTED_DASH_DOT
- */
- public int getBorderRight() {
- return bordRightLineStyle.getValue(field_13_border_styles1);
- }
-
- /**
- * set the type of border to use for the top border of the cell
- * @param border type
- * @see #BORDER_NONE
- * @see #BORDER_THIN
- * @see #BORDER_MEDIUM
- * @see #BORDER_DASHED
- * @see #BORDER_DOTTED
- * @see #BORDER_THICK
- * @see #BORDER_DOUBLE
- * @see #BORDER_HAIR
- * @see #BORDER_MEDIUM_DASHED
- * @see #BORDER_DASH_DOT
- * @see #BORDER_MEDIUM_DASH_DOT
- * @see #BORDER_DASH_DOT_DOT
- * @see #BORDER_MEDIUM_DASH_DOT_DOT
- * @see #BORDER_SLANTED_DASH_DOT
- */
- public void setBorderTop(int border) {
- field_13_border_styles1 = bordTopLineStyle.setValue(field_13_border_styles1, border);
- }
-
- /**
- * get the type of border to use for the top border of the cell
- * @return border type
- * @see #BORDER_NONE
- * @see #BORDER_THIN
- * @see #BORDER_MEDIUM
- * @see #BORDER_DASHED
- * @see #BORDER_DOTTED
- * @see #BORDER_THICK
- * @see #BORDER_DOUBLE
- * @see #BORDER_HAIR
- * @see #BORDER_MEDIUM_DASHED
- * @see #BORDER_DASH_DOT
- * @see #BORDER_MEDIUM_DASH_DOT
- * @see #BORDER_DASH_DOT_DOT
- * @see #BORDER_MEDIUM_DASH_DOT_DOT
- * @see #BORDER_SLANTED_DASH_DOT
- */
- public int getBorderTop() {
- return bordTopLineStyle.getValue(field_13_border_styles1);
- }
-
- /**
- * set the type of border to use for the bottom border of the cell
- * @param border type
- * @see #BORDER_NONE
- * @see #BORDER_THIN
- * @see #BORDER_MEDIUM
- * @see #BORDER_DASHED
- * @see #BORDER_DOTTED
- * @see #BORDER_THICK
- * @see #BORDER_DOUBLE
- * @see #BORDER_HAIR
- * @see #BORDER_MEDIUM_DASHED
- * @see #BORDER_DASH_DOT
- * @see #BORDER_MEDIUM_DASH_DOT
- * @see #BORDER_DASH_DOT_DOT
- * @see #BORDER_MEDIUM_DASH_DOT_DOT
- * @see #BORDER_SLANTED_DASH_DOT
- */
- public void setBorderBottom(int border) {
- field_13_border_styles1 = bordBottomLineStyle.setValue(field_13_border_styles1, border);
- }
-
- /**
- * get the type of border to use for the bottom border of the cell
- * @return border type
- * @see #BORDER_NONE
- * @see #BORDER_THIN
- * @see #BORDER_MEDIUM
- * @see #BORDER_DASHED
- * @see #BORDER_DOTTED
- * @see #BORDER_THICK
- * @see #BORDER_DOUBLE
- * @see #BORDER_HAIR
- * @see #BORDER_MEDIUM_DASHED
- * @see #BORDER_DASH_DOT
- * @see #BORDER_MEDIUM_DASH_DOT
- * @see #BORDER_DASH_DOT_DOT
- * @see #BORDER_MEDIUM_DASH_DOT_DOT
- * @see #BORDER_SLANTED_DASH_DOT
- */
- public int getBorderBottom() {
- return bordBottomLineStyle.getValue(field_13_border_styles1);
- }
-
- /**
- * set the type of border to use for the diagonal border of the cell
- * @param border type
- * @see #BORDER_NONE
- * @see #BORDER_THIN
- * @see #BORDER_MEDIUM
- * @see #BORDER_DASHED
- * @see #BORDER_DOTTED
- * @see #BORDER_THICK
- * @see #BORDER_DOUBLE
- * @see #BORDER_HAIR
- * @see #BORDER_MEDIUM_DASHED
- * @see #BORDER_DASH_DOT
- * @see #BORDER_MEDIUM_DASH_DOT
- * @see #BORDER_DASH_DOT_DOT
- * @see #BORDER_MEDIUM_DASH_DOT_DOT
- * @see #BORDER_SLANTED_DASH_DOT
- */
- public void setBorderDiagonal(int border) {
- field_14_border_styles2 = bordDiagLineStyle.setValue(field_14_border_styles2, border);
- }
-
- /**
- * get the type of border to use for the diagonal border of the cell
- * @return border type
- * @see #BORDER_NONE
- * @see #BORDER_THIN
- * @see #BORDER_MEDIUM
- * @see #BORDER_DASHED
- * @see #BORDER_DOTTED
- * @see #BORDER_THICK
- * @see #BORDER_DOUBLE
- * @see #BORDER_HAIR
- * @see #BORDER_MEDIUM_DASHED
- * @see #BORDER_DASH_DOT
- * @see #BORDER_MEDIUM_DASH_DOT
- * @see #BORDER_DASH_DOT_DOT
- * @see #BORDER_MEDIUM_DASH_DOT_DOT
- * @see #BORDER_SLANTED_DASH_DOT
- */
- public int getBorderDiagonal() {
- return bordDiagLineStyle.getValue(field_14_border_styles2);
- }
-
- /**
- * set the color to use for the left border
- * @param color The index of the color definition
- */
- public void setLeftBorderColor(int color) {
- field_13_border_styles1 = bordLeftLineColor.setValue(field_13_border_styles1, color);
- }
-
- /**
- * get the color to use for the left border
- * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
- * @return The index of the color definition
- */
- public int getLeftBorderColor() {
- return bordLeftLineColor.getValue(field_13_border_styles1);
- }
-
- /**
- * set the color to use for the right border
- * @param color The index of the color definition
- */
- public void setRightBorderColor(int color) {
- field_13_border_styles1 = bordRightLineColor.setValue(field_13_border_styles1, color);
- }
-
- /**
- * get the color to use for the right border
- * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
- * @return The index of the color definition
- */
- public int getRightBorderColor() {
- return bordRightLineColor.getValue(field_13_border_styles1);
- }
-
- /**
- * set the color to use for the top border
- * @param color The index of the color definition
- */
- public void setTopBorderColor(int color) {
- field_14_border_styles2 = bordTopLineColor.setValue(field_14_border_styles2, color);
- }
-
- /**
- * get the color to use for the top border
- * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
- * @return The index of the color definition
- */
- public int getTopBorderColor() {
- return bordTopLineColor.getValue(field_14_border_styles2);
- }
-
- /**
- * set the color to use for the bottom border
- * @param color The index of the color definition
- */
- public void setBottomBorderColor(int color)
- {
- field_14_border_styles2 = bordBottomLineColor.setValue(field_14_border_styles2, color);
- }
-
- /**
- * get the color to use for the bottom border
- * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
- * @return The index of the color definition
- */
- public int getBottomBorderColor() {
- return bordBottomLineColor.getValue(field_14_border_styles2);
- }
-
- /**
- * set the color to use for the diagonal borders
- * @param color The index of the color definition
- */
- public void setDiagonalBorderColor(int color) {
- field_14_border_styles2 = bordDiagLineColor.setValue(field_14_border_styles2, color);
- }
-
- /**
- * get the color to use for the diagonal border
- * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
- * @return The index of the color definition
- */
- public int getDiagonalBorderColor() {
- return bordDiagLineColor.getValue(field_14_border_styles2);
- }
-
- /**
- * Of/off bottom left to top right line
- *
- * @param on - if <code>true</code> - on, otherwise off
- */
- public void setForwardDiagonalOn(boolean on) {
- field_13_border_styles1 = bordBlTrtLineOnOff.setBoolean(field_13_border_styles1, on);
- }
-
- /**
- * Of/off top left to bottom right line
- *
- * @param on - if <code>true</code> - on, otherwise off
- */
- public void setBackwardDiagonalOn(boolean on) {
- field_13_border_styles1 = bordTlBrLineOnOff.setBoolean(field_13_border_styles1, on);
- }
-
- /**
- * @return <code>true</code> if forward diagonal is on
- */
- public boolean isForwardDiagonalOn() {
- return bordBlTrtLineOnOff.isSet(field_13_border_styles1);
- }
-
- /**
- * @return <code>true</code> if backward diagonal is on
- */
- public boolean isBackwardDiagonalOn() {
- return bordTlBrLineOnOff.isSet(field_13_border_styles1);
- }
-
-
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append(" [Border Formatting]\n");
- buffer.append(" .lftln = ").append(Integer.toHexString(getBorderLeft())).append("\n");
- buffer.append(" .rgtln = ").append(Integer.toHexString(getBorderRight())).append("\n");
- buffer.append(" .topln = ").append(Integer.toHexString(getBorderTop())).append("\n");
- buffer.append(" .btmln = ").append(Integer.toHexString(getBorderBottom())).append("\n");
- buffer.append(" .leftborder= ").append(Integer.toHexString(getLeftBorderColor())).append("\n");
- buffer.append(" .rghtborder= ").append(Integer.toHexString(getRightBorderColor())).append("\n");
- buffer.append(" .topborder= ").append(Integer.toHexString(getTopBorderColor())).append("\n");
- buffer.append(" .bottomborder= ").append(Integer.toHexString(getBottomBorderColor())).append("\n");
- buffer.append(" .fwdiag= ").append(isForwardDiagonalOn()).append("\n");
- buffer.append(" .bwdiag= ").append(isBackwardDiagonalOn()).append("\n");
- buffer.append(" [/Border Formatting]\n");
- return buffer.toString();
- }
-
- public Object clone() {
- BorderFormatting rec = new BorderFormatting();
- rec.field_13_border_styles1 = field_13_border_styles1;
- rec.field_14_border_styles2 = field_14_border_styles2;
- return rec;
- }
-
- public int serialize(int offset, byte [] data) {
- LittleEndian.putInt(data, offset+0, field_13_border_styles1);
- LittleEndian.putInt(data, offset+4, field_14_border_styles2);
- return 8;
- }
- public void serialize(LittleEndianOutput out) {
- out.writeInt(field_13_border_styles1);
- out.writeInt(field_14_border_styles2);
- }
- }
|