/** * Returns the Unit of the given length. * @param length the <code>Unit</code> should be obtained from * @return Returns a <code>Unit</code> object representing the specified Length unit. */ public static Unit parseUnit(String length) { Unit lengthUnit = null; if (length == null) { throw new NumberFormatException("The input length should not be null!"); } else { boolean identifiedInput = false; for (Unit unit : Unit.values()) { if (length.contains(unit.abbr())) { lengthUnit = unit; identifiedInput = true; break; } if (!identifiedInput) { throw new NumberFormatException("The input length " + length + " has no valid Unit!"); } } } return lengthUnit; }
/** * Returns the Unit of the given length. * @param length the <code>Unit</code> should be obtained from * @return Returns a <code>Unit</code> object representing the specified Length unit. */ public static Unit parseUnit(String length) { Unit lengthUnit = null; if (length == null) { throw new NumberFormatException("The input length should not be null!"); } else { boolean identifiedInput = false; for (Unit unit : Unit.values()) { if (length.contains(unit.abbr())) { lengthUnit = unit; identifiedInput = true; break; } } if (!identifiedInput) { throw new NumberFormatException("The input length " + length + " has no valid Unit!"); } } return lengthUnit; }
/** * Returns the Unit of the given length. * @param length the <code>Unit</code> should be obtained from * @return Returns a <code>Unit</code> object representing the specified Length unit. */ public static Unit parseUnit(String length) { Unit lengthUnit = null; if (length == null) { throw new NumberFormatException("The input length should not be null!"); } else { boolean identifiedInput = false; for (Unit unit : Unit.values()) { if (length.contains(unit.abbr())) { lengthUnit = unit; identifiedInput = true; break; } } if (!identifiedInput) { throw new NumberFormatException("The input length " + length + " has no valid Unit!"); } } return lengthUnit; }
/** * Set the width of the column (in Millimeter). * @param width * the width that will be set to the column (in Millimeter). */ public void setWidth(long width) { String sWidthMM = String.valueOf(width) + Unit.MILLIMETER.abbr(); String sWidthIN = PositiveLength.mapToUnit(sWidthMM, Unit.INCH); splitRepeatedColumns(); maColumnElement.setProperty(OdfTableColumnProperties.ColumnWidth, sWidthIN); //check if need set relative width int index = getColumnIndex(); if (index >= 1) { index = index - 1; } else { index = index + 1; } OdfTableColumn column = null; if (index < getTable().getColumnCount()) { column = getTable().getColumnByIndex(index); } if (column != null) { long prevColumnRelWidth = column.getRelativeWidth(); if (prevColumnRelWidth != 0) { long prevColumnWidth = column.getWidth(); setRelativeWidth(prevColumnRelWidth / prevColumnWidth * width); } } }
/** * Set the width of the column (in Millimeter). * @param width * the width that will be set to the column (in Millimeter). */ public void setWidth(long width) { String sWidthMM = String.valueOf(width) + Unit.MILLIMETER.abbr(); String sWidthIN = PositiveLength.mapToUnit(sWidthMM, Unit.INCH); splitRepeatedColumns(); maColumnElement.setProperty(OdfTableColumnProperties.ColumnWidth, sWidthIN); //check if need set relative width int index = getColumnIndex(); if (index >= 1) { index = index - 1; } else { index = index + 1; } OdfTableColumn column = null; if (index < getTable().getColumnCount()) { column = getTable().getColumnByIndex(index); } if (column != null) { long prevColumnRelWidth = column.getRelativeWidth(); if (prevColumnRelWidth != 0) { long prevColumnWidth = column.getWidth(); setRelativeWidth(prevColumnRelWidth / prevColumnWidth * width); } } }
/** * Set the width of the table (in Millimeter). * <p> * Throw an UnsupportedOperationException if the * table is part of a spreadsheet document that does not allow to change the table size, * because spreadsheet is not allow user to set the table size. * * @param width the width that need to set (in Millimeter). * <p> * An UnsupportedOperationException will be thrown if the table is in the spreadsheet document. */ public void setWidth(long width) { if (!mIsSpreadsheet) { String sWidthMM = String.valueOf(width) + Unit.MILLIMETER.abbr(); String sWidthIN = PositiveLength.mapToUnit(sWidthMM, Unit.INCH); mTableElement.setProperty(OdfTableProperties.Width, sWidthIN); //if the width is changed, we should also change the table:align properties if it is "margins" //otherwise the width seems not changed String alineStyle = mTableElement.getProperty(StyleTablePropertiesElement.Align); if (TableAlignAttribute.Value.MARGINS.toString().equals(alineStyle)) { mTableElement.setProperty(StyleTablePropertiesElement.Align, TableAlignAttribute.Value.LEFT.toString()); } } else { throw new UnsupportedOperationException(); } }
/** * Set the width of the table (in Millimeter). * <p> * Throw an UnsupportedOperationException if the * table is part of a spreadsheet document that does not allow to change the table size, * because spreadsheet is not allow user to set the table size. * * @param width the width that need to set (in Millimeter). * <p> * An UnsupportedOperationException will be thrown if the table is in the spreadsheet document. */ public void setWidth(long width) { if (!mIsSpreadsheet) { String sWidthMM = String.valueOf(width) + Unit.MILLIMETER.abbr(); String sWidthIN = PositiveLength.mapToUnit(sWidthMM, Unit.INCH); mTableElement.setProperty(OdfTableProperties.Width, sWidthIN); //if the width is changed, we should also change the table:align properties if it is "margins" //otherwise the width seems not changed String alineStyle = mTableElement.getProperty(StyleTablePropertiesElement.Align); if (TableAlignAttribute.Value.MARGINS.toString().equals(alineStyle)) { mTableElement.setProperty(StyleTablePropertiesElement.Align, TableAlignAttribute.Value.LEFT.toString()); } } else { throw new UnsupportedOperationException(); } }
/** * Modifies the margin above and below the table. * * @param spaceTop * space above the table in centimeter(cm), ex. 1.25 cm * @param spaceBottom * spacing below the table in centimeter(cm), ex. 0.7 cm * * @since 0.5.5 */ public void setVerticalMargin(double spaceTop, double spaceBottom) { String tableStyleName = mTableElement.getStyleName(); OdfOfficeAutomaticStyles automaticStyles = mTableElement.getAutomaticStyles(); OdfStyleBase tableStyle = automaticStyles.getStyle(tableStyleName, OdfStyleFamily.Table); if (tableStyle != null) { tableStyle.setProperty(StyleTablePropertiesElement.MarginTop, (new DecimalFormat("#0.##").format(spaceTop) + Unit.CENTIMETER.abbr()).replace(",", ".")); tableStyle.setProperty(StyleTablePropertiesElement.MarginBottom, (new DecimalFormat("#0.##") .format(spaceBottom) + Unit.CENTIMETER.abbr()).replace(",", ".")); } }
/** * Set the height/minimal height of the row (in Millimeter) according to the * second parameter. * * @param height * the height/minimal height that will be set to the row (in * Millimeter). * @param isMinHeight * if it is true, the row can fit the height to the text, vice * versa. */ public void setHeight(double height, boolean isMinHeight) { double roundingFactor = 10000.0; OdfStyleProperty rowHeightProp = isMinHeight ? OdfTableRowProperties.MinRowHeight : OdfTableRowProperties.RowHeight; // TODO:need refactor to PositiveLength. double inValue = Math.round(roundingFactor * height / Unit.INCH.unitInMillimiter()) / roundingFactor; String sHeightIN = String.valueOf(inValue) + Unit.INCH.abbr(); splitRepeatedRows(); maRowElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "style-name"); maRowElement.setProperty(rowHeightProp, sHeightIN); }
/** * Modifies the margin above and below the table. * * @param spaceTop * space above the table in centimeter(cm), ex. 1.25 cm * @param spaceBottom * spacing below the table in centimeter(cm), ex. 0.7 cm * * @since 0.5.5 */ public void setVerticalMargin(double spaceTop, double spaceBottom) { String tableStyleName = mTableElement.getStyleName(); OdfOfficeAutomaticStyles automaticStyles = mTableElement.getAutomaticStyles(); OdfStyleBase tableStyle = automaticStyles.getStyle(tableStyleName, OdfStyleFamily.Table); if (tableStyle != null) { tableStyle.setProperty(StyleTablePropertiesElement.MarginTop, (new DecimalFormat("#0.##").format(spaceTop) + Unit.CENTIMETER.abbr()).replace(",", ".")); tableStyle.setProperty(StyleTablePropertiesElement.MarginBottom, (new DecimalFormat("#0.##") .format(spaceBottom) + Unit.CENTIMETER.abbr()).replace(",", ".")); } }
/** * Set the height/minimal height of the row (in Millimeter) according to the * second parameter. * * @param height * the height/minimal height that will be set to the row (in * Millimeter). * @param isMinHeight * if it is true, the row can fit the height to the text, vice * versa. */ public void setHeight(double height, boolean isMinHeight) { double roundingFactor = 10000.0; OdfStyleProperty rowHeightProp = isMinHeight ? OdfTableRowProperties.MinRowHeight : OdfTableRowProperties.RowHeight; // TODO:need refactor to PositiveLength. double inValue = Math.round(roundingFactor * height / Unit.INCH.unitInMillimiter()) / roundingFactor; String sHeightIN = String.valueOf(inValue) + Unit.INCH.abbr(); splitRepeatedRows(); maRowElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "style-name"); maRowElement.setProperty(rowHeightProp, sHeightIN); }
/** * Set the height/minimal height of the row (in Millimeter) according to the * second parameter. * * @param height * the height/minimal height that will be set to the row (in * Millimeter). * @param isMinHeight * if it is true, the row can fit the height to the text, vice * versa. */ public void setHeight(double height, boolean isMinHeight) { double roundingFactor = 10000.0; OdfStyleProperty rowHeightProp = isMinHeight ? OdfTableRowProperties.MinRowHeight : OdfTableRowProperties.RowHeight; // TODO:need refactor to PositiveLength. double inValue = Math.round(roundingFactor * height / Unit.INCH.unitInMillimiter()) / roundingFactor; String sHeightIN = String.valueOf(inValue) + Unit.INCH.abbr(); splitRepeatedRows(); maRowElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "style-name"); maRowElement.setProperty(rowHeightProp, sHeightIN); }
/** * Modifies the margin above and below the table. * * @param spaceTop * space above the table in centimeter(cm), ex. 1.25 cm * @param spaceBottom * spacing below the table in centimeter(cm), ex. 0.7 cm * * @since 0.5.5 */ public void setVerticalMargin(double spaceTop, double spaceBottom) { String tableStyleName = mTableElement.getStyleName(); OdfOfficeAutomaticStyles automaticStyles = mTableElement.getAutomaticStyles(); OdfStyleBase tableStyle = automaticStyles.getStyle(tableStyleName, OdfStyleFamily.Table); if (tableStyle != null) { tableStyle.setProperty(StyleTablePropertiesElement.MarginTop, (new DecimalFormat("#0.##").format(spaceTop) + Unit.CENTIMETER.abbr()).replace(",", ".")); tableStyle.setProperty(StyleTablePropertiesElement.MarginBottom, (new DecimalFormat("#0.##") .format(spaceBottom) + Unit.CENTIMETER.abbr()).replace(",", ".")); } }
/** * Returns the provided Millimeter value as Inch value * * @param value * the value to set the attribute value to (in Millimeter) */ private static String getInchValue(double value) { // build the string for mm final String mmValueString = value + Unit.MILLIMETER.abbr(); // convert the length to inch final String inchValueString = Length.mapToUnit(mmValueString, Unit.INCH); // return the value return inchValueString; }
/** * Returns the provided Millimeter value as Inch value * * @param value * the value to set the attribute value to (in Millimeter) */ private static String getInchValue(double value) { // build the string for mm final String mmValueString = value + Unit.MILLIMETER.abbr(); // convert the length to inch final String inchValueString = Length.mapToUnit(mmValueString, Unit.INCH); // return the value return inchValueString; }
/** * Set the height/minimal height of the row (in Millimeter) according to the second parameter. * @param height * the height/minimal height that will be set to the row (in Millimeter). * @param isMinHeight * if it is true, the row can fit the height to the text, vice versa. */ public void setHeight(long height, boolean isMinHeight) { String sHeightMM = String.valueOf(height) + Unit.MILLIMETER.abbr(); String sHeightIN = PositiveLength.mapToUnit(sHeightMM, Unit.INCH); splitRepeatedRows(); maRowElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "style-name"); maRowElement.setProperty(OdfTableRowProperties.RowHeight, sHeightIN); }
/** * Set the height/minimal height of the row (in Millimeter) according to the second parameter. * @param height * the height/minimal height that will be set to the row (in Millimeter). * @param isMinHeight * if it is true, the row can fit the height to the text, vice versa. */ public void setHeight(long height, boolean isMinHeight) { String sHeightMM = String.valueOf(height) + Unit.MILLIMETER.abbr(); String sHeightIN = PositiveLength.mapToUnit(sHeightMM, Unit.INCH); splitRepeatedRows(); maRowElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "style-name"); maRowElement.setProperty(OdfTableRowProperties.RowHeight, sHeightIN); }
/** * Set the height/minimal height of the row (in Millimeter) according to the second parameter. * @param height * the height/minimal height that will be set to the row (in Millimeter). * @param isMinHeight * if it is true, the row can fit the height to the text, vice versa. */ public void setHeight(long height, boolean isMinHeight) { String sHeightMM = String.valueOf(height) + Unit.MILLIMETER.abbr(); String sHeightIN = PositiveLength.mapToUnit(sHeightMM, Unit.INCH); splitRepeatedRows(); maRowElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "style-name"); maRowElement.setProperty(OdfTableRowProperties.RowHeight, sHeightIN); }
/** * Returns the provided Millimeter value as Inch value * * @param value the value to set the attribute value to (in Millimeter) */ private static String getInchValue(double value) { // build the string for mm final String mmValueString = value + Unit.MILLIMETER.abbr(); // convert the length to inch final String inchValueString = Length.mapToUnit(mmValueString, Unit.INCH); // return the value return inchValueString; }
/** * Returns the provided Millimeter value as Inch value * * @param value the value to set the attribute value to (in Millimeter) */ private static String getInchValue(double value) { // build the string for mm final String mmValueString = value + Unit.MILLIMETER.abbr(); // convert the length to inch final String inchValueString = Length.mapToUnit(mmValueString, Unit.INCH); // return the value return inchValueString; }