Package org.odftoolkit.odfdom.incubator.doc.style

Examples of org.odftoolkit.odfdom.incubator.doc.style.OdfStyle


      return null;
    }

    if (mWritableTextProperties != null)
      return mWritableTextProperties;
    OdfStyle style = getStyleElementForWrite();
    mWritableTextProperties = TextProperties.getOrCreateTextProperties(style);
    return mWritableTextProperties;
  }
View Full Code Here


      return null;
    }

    if (mWritableTableCellProperties != null)
      return mWritableTableCellProperties;
    OdfStyle style = getStyleElementForWrite();
    mWritableTableCellProperties = TableCellProperties.getOrCreateTableCellProperties(style);
    return mWritableTableCellProperties;
  }
View Full Code Here

      return null;
    }

    if (mWritableParagraphProperties != null)
      return mWritableParagraphProperties;
    OdfStyle style = getStyleElementForWrite();
    mWritableParagraphProperties = ParagraphProperties.getOrCreateParagraphProperties(style);
    return mWritableParagraphProperties;
  }
View Full Code Here

      return null;
    }

    if (mWritableGraphicProperties != null)
      return mWritableGraphicProperties;
    OdfStyle style = getStyleElementForWrite();
    mWritableGraphicProperties = GraphicProperties.getOrCreateGraphicProperties(style);
    return mWritableGraphicProperties;
  }
View Full Code Here

      defaultStyleElement = mDocument.getDocumentStyles().getDefaultStyle(mOdfElement.getStyleFamily());
      isUseDefaultStyle = true;
      return defaultStyleElement;
    }

    OdfStyle styleElement = mOdfElement.getAutomaticStyles().getStyle(styleName, mOdfElement.getStyleFamily());

    if (styleElement == null) {
      styleElement = mDocument.getDocumentStyles().getStyle(styleName, mOdfElement.getStyleFamily());
    }
View Full Code Here

   *            - the style name
   * @return a writable style element
   */
  protected OdfStyle getWritableStyleElementByName(String styleName, boolean isShared) {
    boolean createNew = isShared;
    OdfStyle styleElement = null;
    OdfDefaultStyle defaultStyleElement = null;
    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());
      }

      if (styleElement == null && defaultStyleElement == null) {
        styleElement = mOdfElement.getDocumentStyle();
      }
      if (styleElement == null || styleElement.getStyleUserCount() > 1) {
        createNew = true;
      }
    }
    // if style name is null or this style are used by many users,
    // should create a new one.
    if (createNew) {
      OdfStyle newStyle = mOdfElement.getAutomaticStyles().newStyle(mOdfElement.getStyleFamily());
      if (styleElement != null) {
        newStyle.setProperties(styleElement.getStylePropertiesDeep());
        // copy attributes
        NamedNodeMap attributes = styleElement.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
          Node attr = attributes.item(i);
          if (!attr.getNodeName().equals("style:name")) {
            newStyle.setAttributeNS(attr.getNamespaceURI(), attr.getNodeName(), attr.getNodeValue());
          }
        }// end of copying attributes
      } else if (defaultStyleElement != null) {
        newStyle.setProperties(defaultStyleElement.getStylePropertiesDeep());
        // copy attributes
        NamedNodeMap attributes = defaultStyleElement.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
          Node attr = attributes.item(i);
          if (!attr.getNodeName().equals("style:name")) {
            newStyle.setAttributeNS(attr.getNamespaceURI(), attr.getNodeName(), attr.getNodeValue());
          }
        }// end of copying attributes
        isUseDefaultStyle = true;
      }
      // mCellElement.getAutomaticStyles().appendChild(newStyle);
      String newname = newStyle.getStyleNameAttribute();
      mOdfElement.setStyleName(newname);
      return newStyle;
    }
    return styleElement;
  }
View Full Code Here

    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) {
      TableTableHeaderRowsElement headerrows = (TableTableHeaderRowsElement) OdfXMLFactory.newOdfElement(dom,
          OdfName.newName(OdfDocumentNamespace.TABLE, "table-header-rows"));
      for (int i = 0; i < headerRowNumber; i++) {
        TableTableRowElement aRow = (TableTableRowElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(
            OdfDocumentNamespace.TABLE, "table-row"));
        for (int j = 0; j < numCols; j++) {
          TableTableCellElement aCell = (TableTableCellElement) OdfXMLFactory.newOdfElement(dom, OdfName
              .newName(OdfDocumentNamespace.TABLE, "table-cell"));
          if (isTextDocument) {
            if ((j + 1 == numCols) && (i == 0)) {
              aCell.setStyleName(righttopStyle.getStyleNameAttribute());
            } else if (i == 0) {
              aCell.setStyleName(lefttopStyle.getStyleNameAttribute());
            } else if ((j + 1 == numCols) && (i > 0)) {
              aCell.setStyleName(rightbottomStyle.getStyleNameAttribute());
            } else {
              aCell.setStyleName(leftbottomStyle.getStyleNameAttribute());
            }
          }
          aRow.appendChild(aCell);
        }
        headerrows.appendChild(aRow);
      }
      newTEle.appendChild(headerrows);
    }

    // 3.2 create common row elements
    for (int i = headerRowNumber; i < numRows; i++) {
      TableTableRowElement aRow = (TableTableRowElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(
          OdfDocumentNamespace.TABLE, "table-row"));
      for (int j = 0; j < numCols; j++) {
        TableTableCellElement aCell = (TableTableCellElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(
            OdfDocumentNamespace.TABLE, "table-cell"));
        if (isTextDocument) {
          if ((j + 1 == numCols) && (i == 0)) {
            aCell.setStyleName(righttopStyle.getStyleNameAttribute());
          } else if (i == 0) {
            aCell.setStyleName(lefttopStyle.getStyleNameAttribute());
          } else if ((j + 1 == numCols) && (i > 0)) {
            aCell.setStyleName(rightbottomStyle.getStyleNameAttribute());
          } else {
            aCell.setStyleName(leftbottomStyle.getStyleNameAttribute());
          }
View Full Code Here

      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"));
        if (!mIsSpreadsheet) {
          if (j + 1 == columnCount) {
            aCell.setStyleName(righttopStyle.getStyleNameAttribute());
          } else {
            aCell.setStyleName(lefttopStyle.getStyleNameAttribute());
          }
        }
        aRow.appendChild(aCell);
      }
    }
View Full Code Here

    }

    // insert columns secondly
    if (columnList.size() == 0) // no column, create a new column
    {
      OdfStyle columnStyle = mTableElement.getAutomaticStyles().newStyle(OdfStyleFamily.TableColumn);
      String columnStylename = columnStyle.getStyleNameAttribute();
      columnStyle.setProperty(StyleTableColumnPropertiesElement.ColumnWidth, DEFAULT_TABLE_WIDTH + "in");
      columnStyle.setProperty(StyleTableColumnPropertiesElement.RelColumnWidth, DEFAULT_REL_TABLE_WIDTH + "*");

      newColumn = (TableTableColumnElement) OdfXMLFactory.newOdfElement((OdfFileDom) mTableElement
          .getOwnerDocument(), OdfName.newName(OdfDocumentNamespace.TABLE, "table-column"));
      newColumn.setStyleName(columnStylename);
      mTableElement.insertBefore(newColumn, positonElement);
View Full Code Here

      Cell cell = oldTopRow.getCellByIndex(i);
      if (cell.isCoveredElement()) {
        i = i + cell.getColumnsRepeatedNumber();
        continue;
      }
      OdfStyle styleEle = cell.getStyleHandler().getStyleElementForWrite();
      if (i < length - 1) {
        setLeftBottomBorderStylesProperties(styleEle);
      } else {
        setRightBottomBorderStylesProperties(styleEle);
      }
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.incubator.doc.style.OdfStyle

Copyright © 2018 www.massapicom. 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.