Examples of OdfOfficeAutomaticStyles


Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

    return unique_name;
  }

  private String getUniquePercentageStyleName() {
    String unique_name;
    OdfOfficeAutomaticStyles styles = mCellElement.getAutomaticStyles();
    do {
      unique_name = String.format("p%06x", (int) (Math.random() * 0xffffff));
    } while (styles.getPercentageStyle(unique_name) != null);
    return unique_name;
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

  // } while (styles.getStyle(unique_name, OdfStyleFamily.TableCell) != null);
  // return unique_name;
  // }
  private String getUniqueCurrencyStyleName() {
    String unique_name;
    OdfOfficeAutomaticStyles styles = mCellElement.getAutomaticStyles();
    do {
      unique_name = String.format("c%06x", (int) (Math.random() * 0xffffff));
    } while (styles.getCurrencyStyle(unique_name) != null);
    return unique_name;
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

        || headerColumnNumber > numCols) {
      throw new IllegalArgumentException("Can not create table with the given parameters:\n" + "Rows " + numRows
          + ", Columns " + numCols + ", HeaderRows " + headerRowNumber + ", HeaderColumns "
          + headerColumnNumber);
    }
    OdfOfficeAutomaticStyles styles = null;
    if (dom instanceof OdfContentDom) {
      styles = ((OdfContentDom) dom).getAutomaticStyles();
    } else if (dom instanceof OdfStylesDom) {
      styles = ((OdfStylesDom) dom).getAutomaticStyles();
    }
    // 1. create table element
    TableTableElement newTEle = (TableTableElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(
        OdfDocumentNamespace.TABLE, "table"));
    String tablename = getUniqueTableName(container);
    newTEle.setTableNameAttribute(tablename);
    // create style
    OdfStyle tableStyle = styles.newStyle(OdfStyleFamily.Table);
    String stylename = tableStyle.getStyleNameAttribute();
    tableStyle.setProperty(StyleTablePropertiesElement.Width, tableWidth + "in");
    tableStyle.setProperty(StyleTablePropertiesElement.Align, DEFAULT_TABLE_ALIGN);
    if (marginLeft != 0) {
      tableStyle.setProperty(StyleTablePropertiesElement.MarginLeft, (new DecimalFormat("#0.##")
          .format(marginLeft) + Unit.CENTIMETER.abbr()).replace(",", "."));
    }
    if (marginRight != 0) {
      tableStyle.setProperty(StyleTablePropertiesElement.MarginRight, (new DecimalFormat("#0.##")
          .format(marginRight) + Unit.CENTIMETER.abbr()).replace(",", "."));
    }
    newTEle.setStyleName(stylename);

    // 2. create column elements
    // 2.0 create column style
    OdfStyle columnStyle = styles.newStyle(OdfStyleFamily.TableColumn);
    String columnStylename = columnStyle.getStyleNameAttribute();
    // for spreadsheet document, no need compute column width.
    if (isTextDocument) {
      columnStyle.setProperty(StyleTableColumnPropertiesElement.ColumnWidth, IN_FORMAT.format(tableWidth
          / numCols)
          + "in");
      columnStyle.setProperty(StyleTableColumnPropertiesElement.RelColumnWidth, Math
          .round(DEFAULT_REL_TABLE_WIDTH / numCols)
          + "*");
    }
    // 2.1 create header column elements
    if (headerColumnNumber > 0) {
      TableTableHeaderColumnsElement headercolumns = (TableTableHeaderColumnsElement) OdfXMLFactory
          .newOdfElement(dom, OdfName.newName(OdfDocumentNamespace.TABLE, "table-header-columns"));
      TableTableColumnElement headercolumn = (TableTableColumnElement) OdfXMLFactory.newOdfElement(dom, OdfName
          .newName(OdfDocumentNamespace.TABLE, "table-column"));
      if (headerColumnNumber > 1) {
        headercolumn.setTableNumberColumnsRepeatedAttribute(headerColumnNumber);
      } else {
        headercolumn.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "number-columns-repeated");
      }
      headercolumns.appendChild(headercolumn);
      newTEle.appendChild(headercolumns);
      headercolumn.setStyleName(columnStylename);
    }
    // 2.2 create common column elements
    TableTableColumnElement columns = (TableTableColumnElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(
        OdfDocumentNamespace.TABLE, "table-column"));
    int tableNumberColumnsRepeatedValue = numCols - headerColumnNumber;
    if (tableNumberColumnsRepeatedValue > 1) {
      columns.setTableNumberColumnsRepeatedAttribute(tableNumberColumnsRepeatedValue);
    }
    columns.setStyleName(columnStylename);
    newTEle.appendChild(columns);

    // 3. create row elements
    // 3.0 create 4 kinds of styles
    OdfStyle lefttopStyle = null, leftbottomStyle = null, righttopStyle = null, rightbottomStyle = null;

    if (isTextDocument) {
      lefttopStyle = styles.newStyle(OdfStyleFamily.TableCell);
      setLeftTopBorderStyleProperties(lefttopStyle);

      leftbottomStyle = styles.newStyle(OdfStyleFamily.TableCell);
      setLeftBottomBorderStylesProperties(leftbottomStyle);

      righttopStyle = styles.newStyle(OdfStyleFamily.TableCell);
      setRightTopBorderStyleProperties(righttopStyle);

      rightbottomStyle = styles.newStyle(OdfStyleFamily.TableCell);
      setRightBottomBorderStylesProperties(rightbottomStyle);
    }

    // 3.1 create header row elements
    if (headerRowNumber > 0) {
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

    if (template == null)
      throw new IllegalArgumentException(
          "The template cannot null to be applied to a table.");

    Document doc = this.getOwnerDocument();
    OdfOfficeAutomaticStyles styles = doc.getContentDom()
        .getAutomaticStyles();

    // decide row style or column style
    boolean isEqualTableStyle = true;
    boolean isEqualParaStyle = true;
    OdfStyle evenRowsTableStyle = styles.getStyle(template
        .getTableEvenRowsTableStyle(), OdfStyleFamily.TableCell);
    OdfStyle oddRowsTableStyle = styles.getStyle(template
        .getTableOddRowsTableStyle(), OdfStyleFamily.TableCell);
    OdfStyle evenRowsParagraphStyle = styles.getStyle(template
        .getTableEvenRowsParagraphStyle(), OdfStyleFamily.Paragraph);
    OdfStyle oddRowsParagraphStyle = styles.getStyle(template
        .getTableOddRowsParagraphStyle(), OdfStyleFamily.Paragraph);
    if (evenRowsTableStyle != null || oddRowsTableStyle != null)
      isEqualTableStyle = evenRowsTableStyle.compareTo(oddRowsTableStyle) == 0;
    if (evenRowsParagraphStyle != null || oddRowsParagraphStyle != null)
      isEqualParaStyle = evenRowsParagraphStyle
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

          OdfDocumentNamespace.TABLE, "table-cell"));
      if (columnCount > 1) {
        aCell.setTableNumberColumnsRepeatedAttribute(columnCount);
      }
      if (!mIsSpreadsheet) {
        OdfOfficeAutomaticStyles automaticStyles = mTableElement.getAutomaticStyles();
        OdfStyle borderStyle = automaticStyles.newStyle(OdfStyleFamily.TableCell);
        setRightTopBorderStyleProperties(borderStyle);
        aCell.setStyleName(borderStyle.getStyleNameAttribute());
      }
      aRow.appendChild(aCell);
    } else {
      OdfStyle lefttopStyle = null, righttopStyle = null;
      // create 2 kinds of styles
      if (!mIsSpreadsheet) {
        OdfOfficeAutomaticStyles automaticStyles = mTableElement.getAutomaticStyles();
        lefttopStyle = automaticStyles.newStyle(OdfStyleFamily.TableCell);
        setLeftTopBorderStyleProperties(lefttopStyle);
        righttopStyle = automaticStyles.newStyle(OdfStyleFamily.TableCell);
        setRightTopBorderStyleProperties(righttopStyle);
      }
      for (int j = 0; j < columnCount; j++) {
        TableTableCellElement aCell = (TableTableCellElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(
            OdfDocumentNamespace.TABLE, "table-cell"));
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

   */
  private static double getTableWidth(TableContainer container, double marginLeft, double marginRight) {
    String pageWidthStr = null;
    double pageWidth = 0;
    double tableWidth = DEFAULT_TABLE_WIDTH;
    OdfOfficeAutomaticStyles automaticStyles = null;
    try {
      automaticStyles = getOwnerDocument(container).getStylesDom().getAutomaticStyles();
    } catch (Exception e) {
      Logger.getLogger(Table.class.getName()).log(Level.SEVERE,  e.getMessage(), e);
    }
    OdfStylePageLayout pageLayout = automaticStyles.getPageLayout("pm1");
    if (pageLayout == null) {
      pageLayout = automaticStyles.getPageLayout("Mpm1");
    }
    if (pageLayout != null) {
      pageWidthStr = pageLayout.getProperty(StylePageLayoutPropertiesElement.PageWidth);
      if (pageWidthStr != null) {
        pageWidth = Length.parseDouble(pageWidthStr, Unit.CENTIMETER);
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

   *           
   * @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(",", "."));
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

   */
  @Test
  public void testApplyStyle() {
    search = null;
    search = new TextNavigation("delete", doc);
    OdfOfficeAutomaticStyles autoStyles = null;
    try {
      autoStyles = doc.getContentDom().getAutomaticStyles();
    } catch (Exception e1) {
      Assert.fail("Failed with " + e1.getClass().getName() + ": '" + e1.getMessage() + "'");
    }
    // T4 is the bold style for text
    OdfStyleBase style = autoStyles.getStyle("T4", OdfStyleFamily.Text);
    Assert.assertNotNull(style);

    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      try {
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

  }

  private void checkLoadTemplateResults(TableTemplate template, String name) {
    OdfStyle style = null;
    try {
      OdfOfficeAutomaticStyles styles = doc.getContentDom()
          .getAutomaticStyles();
      style = styles.getStyle(name + ".A1", OdfStyleFamily.TableCell);
      Assert.assertNotNull(style);

      style = styles.getStyle(name + ".B1", OdfStyleFamily.TableCell);
      Assert.assertNotNull(style);

      style = styles.getStyle(name + ".E1", OdfStyleFamily.TableCell);
      Assert.assertNotNull(style);

      style = styles.getStyle(name + ".A2", OdfStyleFamily.TableCell);
      Assert.assertNotNull(style);

      style = styles.getStyle(name + ".B2", OdfStyleFamily.TableCell);
      Assert.assertNotNull(style);

      style = styles.getStyle(name + ".E2", OdfStyleFamily.TableCell);
      Assert.assertNotNull(style);

      if (name.contains("Column")) {
        style = styles.getStyle(name + ".C2", OdfStyleFamily.TableCell);
        Assert.assertNotNull(style);
      } else {
        style = styles.getStyle(name + ".B3", OdfStyleFamily.TableCell);
        Assert.assertNotNull(style);
      }
      style = styles.getStyle(name + ".A5", OdfStyleFamily.TableCell);
      Assert.assertNotNull(style);

      style = styles.getStyle(name + ".B5", OdfStyleFamily.TableCell);
      Assert.assertNotNull(style);

      style = styles.getStyle(name + ".E5", OdfStyleFamily.TableCell);
      Assert.assertNotNull(style);

      style = styles.getStyle("P1", OdfStyleFamily.Paragraph);
      Assert.assertNotNull(style);

      style = styles.getStyle("P2", OdfStyleFamily.Paragraph);
      Assert.assertNotNull(style);

      style = styles.getStyle("P4", OdfStyleFamily.Paragraph);
      Assert.assertNotNull(style);

      style = styles.getStyle("P5", OdfStyleFamily.Paragraph);
      Assert.assertNotNull(style);

      style = styles.getStyle("P3", OdfStyleFamily.Paragraph);
      Assert.assertNotNull(style);

    } catch (Exception e) {
      Logger.getLogger(TableTemplateTest.class.getName()).log(
          Level.SEVERE, null, e);
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

   */
  @Test
  public void testApplyStyle() {
    search = null;
    search = new TextNavigation("delete", doc);
    OdfOfficeAutomaticStyles autoStyles = null;
    try {
      autoStyles = doc.getContentDom().getAutomaticStyles();
    } catch (Exception e1) {
      Assert.fail("Failed with " + e1.getClass().getName() + ": '" + e1.getMessage() + "'");
    }
    // T4 is the bold style for text
    OdfStyleBase style = autoStyles.getStyle("T4", OdfStyleFamily.Text);
    Assert.assertNotNull(style);

    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      try {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.