/*
* [TagConfig.java]
*
* Summary: Configuration information about one tag how to handle newlines and indents.
*
* Copyright: (c) 2010-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
*
* Licence: This software may be copied and used freely for any purpose but military.
* http://mindprod.com/contact/nonmil.html
*
* Requires: JDK 1.8+
*
* Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
*
* Version History:
* 1.0 2010-01-17 initial release.
*/
package com.mindprod.htmlreflow;
/**
* Configuration information about one tag how to handle newlines and indents.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2010-01-17 initial release.
* @since 2010-01-17
*/
class TagConfig
{
/**
* Defining a layout version for a class.
* We use the Preferences mechanism, but this serves the same purpose as serialization.
*/
static final long serialVersionUID = 1L;
/**
* name of tag without < > or /
*/
private final String tagName;
/**
* true, it is ok to break lines inside this tag
*/
private final boolean wrap;
/**
* 0=following text is on same line, 1=following text is on next line, 2=following text is on line after blank line.
*/
private final int afterSlashTag;
/**
* 0=following text is on same line, 1=following text is on next line, 2=following text is on line after blank line.
*/
private final int afterTag;
/**
* goes on 0=same same, 1=new line, 2=with blank link before
*/
private final int beforeSlashTag;
/**
* goes on 0=same same, 1=new line, 2=with blank link before
*/
private final int beforeTag;
/**
* number of cols to indent following lines, relative to current indent. Does not affect this tagName.
*/
private final int nestedIndent;
/**
* number of cols to this tagName, relative to current indent.
*/
private final int tagIndent;
/**
* constructor
*
* @param tag name of tagName without < > or /
* @param byteValues byte[6] beforeTag, tagIndent, afterTag, beforeSlashTag, afterSlashTag, nestedIndent
*/
TagConfig( final String tag, byte[] byteValues )
{
this.tagName = tag;
assert byteValues.length == 7 : "TagConfig constructor must have 7 byte value";
this.beforeTag = byteValues[ 0 ];
this.tagIndent = byteValues[ 1 ];
this.afterTag = byteValues[ 2 ];
this.beforeSlashTag = byteValues[ 3 ];
this.afterSlashTag = byteValues[ 4 ];
this.nestedIndent = byteValues[ 5 ];
this.wrap = byteValues[ 6 ] > 0;
}
/**
* constructor
*
* @param tag name of tagName without < > or /
* @param beforeTag goes on 0=same same, 1=new line, 2=with blank link before
* @param tagIndent number of cols to this tagName, relative to current indent.
* @param afterTag 0=following text is on same line, 1=following text is on next line,
* 2=following text is on line after blank line.
* @param beforeSlashTag goes on 0=same same, 1=new line, 2=with blank link before
* @param afterSlashTag 0=following text is on same line, 1=following text is on next line,
* 2=following text is on line after blank line.
* @param nestedIndent number of cols to indent following lines, relative to current indent. Does not affect
* this tagName.
* @param wrap true if it is ok af text inside this tag pair is ok to wrap
*/
TagConfig( final String tag, final int beforeTag, final int tagIndent, final int afterTag,
final int beforeSlashTag, final int afterSlashTag, final int nestedIndent, final boolean wrap )
{
this.tagName = tag;
this.beforeTag = beforeTag;
this.tagIndent = tagIndent;
this.afterTag = afterTag;
this.beforeSlashTag = beforeSlashTag;
this.afterSlashTag = afterSlashTag;
this.nestedIndent = nestedIndent;
this.wrap = wrap;
}
/**
* how many NLs after
*
* @return 0=following text is on same line, 1=following text is on next line, 2=following text is on line after
* blank line.
*/
public int getAfterSlashTag()
{
return afterSlashTag;
}
/**
* how many NLs after
*
* @return 0=following text is on same line, 1=following text is on next line, 2=following text is on line after
* blank line.
*/
public int getAfterTag()
{
return afterTag;
}
/**
* how many NLs before
*
* @return goes on 0=same same, 1=new line, 2=with blank link before
*/
public int getBeforeSlashTag()
{
return beforeSlashTag;
}
/**
* how many nls go before the
*
* @return goes on 0=same same, 1=new line, 2=with blank link before
*/
public int getBeforeTag()
{
return beforeTag;
}
/**
* get the 7 numeric values as a byte array
*
* @return byte[7] beforeTag, tagIndent, afterTag, beforeSlashTag, afterSlashTag, nestedIndent
*/
public byte[] getByteValues()
{
return new byte[] {
( byte ) beforeTag,
( byte ) tagIndent,
( byte ) afterTag,
( byte ) beforeSlashTag,
( byte ) afterSlashTag,
( byte ) nestedIndent,
( byte ) ( wrap ? 1 : 0 ) };
}
/**
* indent of following nested lines.
*
* @return number of cols to indent following lines, relative to current indent. Does not affect this tagName.
*/
public int getNestedIndent()
{
return nestedIndent;
}
/**
* how much to indent and itself (not the body inside)
*
* @return number of cols to this tagName, relative to current indent.
*/
public int getTagIndent()
{
return tagIndent;
}
/**
* tagName name
*
* @return name of tagName without < > or /, lower case
*/
public String getTagName()
{
return tagName;
}
public boolean isWrap()
{
return wrap;
}
}