Examples of OdfOfficeAutomaticStyles


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

    if (styleName == null || (styleName.equals(""))) {
      createNew = true;
      // get from default style element
      defaultStyleElement = mDocument.getDocumentStyles().getDefaultStyle(mOdfElement.getStyleFamily());
    } else {
      OdfOfficeAutomaticStyles styles = mOdfElement.getAutomaticStyles();
      styleElement = styles.getStyle(styleName, mOdfElement.getStyleFamily());

      // If not default cell style definition,
      // Try to find if the style is defined in document styles
      if (styleElement == null && defaultStyleElement == null) {
        styleElement = mDocument.getDocumentStyles().getStyle(styleName, mOdfElement.getStyleFamily());
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

          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());
      }
    } 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

      Assert.assertFalse(style.hasProperty(StyleTextPropertiesElement.FontNameAsian));

      Assert.assertNull(styles.getStyle("foobar", OdfStyleFamily.Chart));

      // test styles.xml:automatic-styles
      OdfOfficeAutomaticStyles autostyles = stylesDom.getAutomaticStyles();
      Assert.assertNotNull(autostyles);

      OdfStylePageLayout pageLayout = autostyles.getPageLayout("pm1");
      Assert.assertNotNull(pageLayout);
      Assert.assertEquals(pageLayout.getProperty(StylePageLayoutPropertiesElement.PageWidth), "8.5in");
      Assert.assertEquals(pageLayout.getProperty(StylePageLayoutPropertiesElement.PageHeight), "11in");

      Assert.assertNull(autostyles.getStyle("foobar", OdfStyleFamily.Chart));

    } catch (Exception e) {
      LOG.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
View Full Code Here

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

      Document odfdoc = Document.loadDocument(ResourceUtilities.getAbsolutePath(TEST_FILE));

      OdfContentDom contentDom = odfdoc.getContentDom();

      // test content.xml:automatic-styles
      OdfOfficeAutomaticStyles autoStyles = contentDom.getAutomaticStyles();
      Assert.assertNotNull(autoStyles);

      OdfStyle style = autoStyles.getStyle("P1", OdfStyleFamily.Paragraph);
      Assert.assertNotNull(style);
      Assert.assertEquals(style.getStyleNameAttribute(), "P1");
      Assert.assertEquals(style.getStyleParentStyleNameAttribute(), "Text_20_body");
      Assert.assertEquals(style.getStyleListStyleNameAttribute(), "L1");

      style = autoStyles.getStyle("T1", OdfStyleFamily.Text);
      Assert.assertNotNull(style);
      Assert.assertEquals(style.getStyleNameAttribute(), "T1");

      for (OdfStyle testStyle : autoStyles.getStylesForFamily(OdfStyleFamily.Paragraph)) {
        testStyle(testStyle);
      }

      for (OdfStyle testStyle : autoStyles.getStylesForFamily(OdfStyleFamily.Text)) {
        testStyle(testStyle);
      }

    } catch (Exception e) {
      LOG.log(Level.SEVERE, e.getMessage(), e);
View Full Code Here

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

    }
  }

  private void testStyle(OdfStyle testStyle) throws Exception {
    OdfFileDom fileDom = (OdfFileDom) testStyle.getOwnerDocument();
    OdfOfficeAutomaticStyles autoStyles = null;
    if (testStyle.getStyleParentStyleNameAttribute() != null) {
      if (fileDom instanceof OdfContentDom) {
        autoStyles = ((OdfContentDom) fileDom).getAutomaticStyles();
      } else if (fileDom instanceof OdfStylesDom) {
        autoStyles = ((OdfStylesDom) fileDom).getAutomaticStyles();
      }
      OdfStyle parentStyle = autoStyles.getStyle(testStyle.getStyleParentStyleNameAttribute(), testStyle.getFamily());
      if (parentStyle == null) {
        parentStyle = ((Document) fileDom.getDocument()).getDocumentStyles().getStyle(testStyle.getStyleParentStyleNameAttribute(), testStyle.getFamily());
      }

      Assert.assertNotNull(parentStyle);
    }
    if (testStyle.hasOdfAttribute(OdfName.newName(OdfDocumentNamespace.STYLE, "list-style-name"))) {
      if (testStyle.getStyleListStyleNameAttribute() != null) {
        OdfTextListStyle listStyle = autoStyles.getListStyle(testStyle.getStyleListStyleNameAttribute());
        if (listStyle == null) {
          listStyle = ((Document) fileDom.getDocument()).getDocumentStyles().getListStyle(testStyle.getStyleListStyleNameAttribute());
        }

        Assert.assertNotNull(listStyle);
View Full Code Here

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

 
  private void validPageBreakExist(TextDocument newDoc, Paragraph paragraph) throws Exception {
    Node paragraphNode = paragraph.getOdfElement().getNextSibling();
    Assert.assertTrue(paragraphNode instanceof TextPElement);
    OdfContentDom contentDocument = newDoc.getContentDom();
    OdfOfficeAutomaticStyles styles = contentDocument.getAutomaticStyles();
    OdfStyle style = styles.getStyle(((TextPElement) paragraphNode).getStyleName(), OdfStyleFamily.Paragraph);
    Assert.assertNotNull(style);
    Node paragraphPropertiesNode = style.getFirstChild();
    Assert.assertNotNull(paragraphPropertiesNode instanceof StyleParagraphPropertiesElement);
    Assert.assertEquals(((StyleParagraphPropertiesElement) paragraphPropertiesNode).getFoBreakBeforeAttribute(),
        "page");
View Full Code Here

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

  @Test
  public void testSetDefaultCellStyle() {
    SpreadsheetDocument outputDocument;
    OdfContentDom contentDom; // the document object model for content.xml
    // the office:automatic-styles element in content.xml
    OdfOfficeAutomaticStyles contentAutoStyles;
    OdfStyle style;
    String noaaDateStyleName;
    String noaaTempStyleName;

    try {
      outputDocument = SpreadsheetDocument.newSpreadsheetDocument();
      contentDom = outputDocument.getContentDom();
      contentAutoStyles = contentDom.getOrCreateAutomaticStyles();

      OdfNumberDateStyle dateStyle = new OdfNumberDateStyle(contentDom, "yyyy-MM-dd", "numberDateStyle", null);
      OdfNumberStyle numberStyle = new OdfNumberStyle(contentDom, "#0.00", "numberTemperatureStyle");

      contentAutoStyles.appendChild(dateStyle);
      contentAutoStyles.appendChild(numberStyle);

      style = contentAutoStyles.newStyle(OdfStyleFamily.TableCell);
      noaaDateStyleName = style.getStyleNameAttribute();
      style.setStyleDataStyleNameAttribute("numberDateStyle");

      // and for time cells
      style = contentAutoStyles.newStyle(OdfStyleFamily.TableCell);
      noaaTempStyleName = style.getStyleNameAttribute();
      style.setStyleDataStyleNameAttribute("numberTemperatureStyle");
      style.setProperty(StyleParagraphPropertiesElement.TextAlign, "end");

      Table table = Table.newTable(outputDocument);
      List<Column> columns = table.insertColumnsBefore(0, 3);
      Column column = columns.get(0);
      column.setDefaultCellStyle(contentAutoStyles.getStyle(noaaDateStyleName, OdfStyleFamily.TableCell));
      Cell aCell = column.getCellByIndex(0);
      aCell.setValueType("date");
      String format = aCell.getFormatString();
      Assert.assertEquals("yyyy-MM-dd", format);

      List<Row> rows = table.insertRowsBefore(0, 1);
      Row row = rows.get(0);
      row.setDefaultCellStyle(contentAutoStyles.getStyle(noaaTempStyleName, OdfStyleFamily.TableCell));
      Cell bCell = row.getCellByIndex(0);
      bCell.setValueType("float");
      String bformat = bCell.getFormatString();
      Assert.assertEquals("#0.00", bformat);
      Assert.assertEquals("end", bCell.getHorizontalAlignment());
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.