Package org.odftoolkit.odfdom.incubator.doc.office

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


  private void updateTableToNone(Table table) {
    OdfFileDom dom = (OdfFileDom) getTableContainerElement().getOwnerDocument();
    TableTableElement tableEle = table.getOdfElement();
    String stylename = tableEle.getStyleName();
    OdfOfficeAutomaticStyles styles = null;
    if (dom instanceof OdfContentDom) {
      styles = ((OdfContentDom) dom).getAutomaticStyles();
    } else if (dom instanceof OdfStylesDom) {
      styles = ((OdfStylesDom) dom).getAutomaticStyles();
    }
    OdfStyle tableStyle = styles.getStyle(stylename, OdfStyleFamily.Table);
    tableStyle.setProperty(StyleTablePropertiesElement.Shadow, "none");
    NodeList cells = tableEle.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table-cell");
    if (cells != null && cells.getLength() > 0) {
      OdfStyle cellStyleWithoutBorder = styles.newStyle(OdfStyleFamily.TableCell);
      cellStyleWithoutBorder.setProperty(StyleTableCellPropertiesElement.Border, "none");
      cellStyleWithoutBorder.removeProperty(StyleTableCellPropertiesElement.Padding);
      String cellStyleName = cellStyleWithoutBorder.getStyleNameAttribute();
      for (int i = 0; i < cells.getLength(); i++) {
        TableTableCellElement cell = (TableTableCellElement) cells.item(i);
View Full Code Here


    TextSectionElement newSectionEle = null;
    try {
      Document doc = (Document) ((OdfFileDom) headerEle
          .getOwnerDocument()).getDocument();
      OdfContentDom contentDocument = doc.getContentDom();
      OdfOfficeAutomaticStyles styles = contentDocument
          .getAutomaticStyles();
      OdfStyle style = styles.newStyle(OdfStyleFamily.Section);
      StyleSectionPropertiesElement sProperties = style
          .newStyleSectionPropertiesElement();
      sProperties.setTextDontBalanceTextColumnsAttribute(false);
      sProperties.setStyleEditableAttribute(false);
      StyleColumnsElement columnEle = sProperties
View Full Code Here

      return getStyleByName(parentName);
  }

  private OdfStyle getStyleByName(String name) {
    OdfStyle styleElement = null;
    OdfOfficeAutomaticStyles styles = mCellElement.getAutomaticStyles();
    styleElement = styles.getStyle(name, OdfStyleFamily.TableCell);

    if (styleElement == null) {
      styleElement = mDocument.getDocumentStyles().getStyle(name, OdfStyleFamily.TableCell);
    }
View Full Code Here

    try {
      Date simpleDate = simpleFormat.parse(sValue);
      SimpleDateFormat newFormat = new SimpleDateFormat(formatString);
      dateElement.setTextContent(newFormat.format(simpleDate));
      OdfFileDom dom = (OdfFileDom) dateElement.getOwnerDocument();
      OdfOfficeAutomaticStyles styles = null;
      if (dom instanceof OdfContentDom) {
        styles = ((OdfContentDom) dom).getAutomaticStyles();
      } else if (dom instanceof OdfStylesDom) {
        styles = ((OdfStylesDom) dom).getAutomaticStyles();
      }
      OdfNumberDateStyle dataStyle = styles.getDateStyle(dateElement.getStyleDataStyleNameAttribute());
      dataStyle.buildFromFormat(formatString);
    } catch (ParseException e) {
      Logger.getLogger(DateField.class.getName()).log(Level.SEVERE, e.getMessage(), e);
    }
  }
View Full Code Here

  }

  // Create an <code>OdfNumberDateStyle</code> element
  private OdfNumberDateStyle newDateStyle() {
    OdfFileDom dom = (OdfFileDom) dateElement.getOwnerDocument();
    OdfOfficeAutomaticStyles styles = null;
    if (dom instanceof OdfContentDom) {
      styles = ((OdfContentDom) dom).getAutomaticStyles();
    } else if (dom instanceof OdfStylesDom) {
      styles = ((OdfStylesDom) dom).getAutomaticStyles();
    }
    OdfNumberDateStyle newStyle = dom.newOdfElement(OdfNumberDateStyle.class);
    newStyle.setStyleNameAttribute(newUniqueStyleName(styles));
    styles.appendChild(newStyle);
    return newStyle;
  }
View Full Code Here

    }
  }

  private String getUniqueTimeStyleName() {
    String unique_name;
    OdfOfficeAutomaticStyles styles = getDrawControl()
        .getOdfElement().getAutomaticStyles();
    do {
      unique_name = String.format("t%06x",
          (int) (Math.random() * 0xffffff));
    } while (styles.getDateStyle(unique_name) != null);
    return unique_name;
  }
View Full Code Here

   *         yet exists, a new one is inserted into the dom and returned.
   *
   */
  public OdfOfficeAutomaticStyles getOrCreateAutomaticStyles() {

    OdfOfficeAutomaticStyles automaticStyles = getAutomaticStyles();
    if (automaticStyles == null) {
      automaticStyles = newOdfElement(OdfOfficeAutomaticStyles.class);

      Node parent = getFirstChild();

View Full Code Here

   *         yet exists, a new one is inserted into the dom and returned.
   *
   */
  public OdfOfficeAutomaticStyles getOrCreateAutomaticStyles() {

    OdfOfficeAutomaticStyles automaticStyles = getAutomaticStyles();
    if (automaticStyles == null) {
      automaticStyles = newOdfElement(OdfOfficeAutomaticStyles.class);

      Node parent = getFirstChild();

View Full Code Here

        || headerColumnNumber > numCols) {
      throw new IllegalArgumentException("Can not create table with the given parameters:\n"
          + "Rows " + numRows + ", Columns " + numCols + ", HeaderRows " + headerRowNumber + ", HeaderColumns " + headerColumnNumber);
    }
    OdfFileDom dom = (OdfFileDom) parent.getOwnerDocument();
    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(parent);
    newTEle.setTableNameAttribute(tablename);
    //create style
    OdfStyle tableStyle = styles.newStyle(OdfStyleFamily.Table);
    String stylename = tableStyle.getStyleNameAttribute();
    tableStyle.setProperty(StyleTablePropertiesElement.Width, DEFAULT_TABLE_WIDTH + "in");
    tableStyle.setProperty(StyleTablePropertiesElement.Align, DEFAULT_TABLE_ALIGN);
    newTEle.setStyleName(stylename);

    // 2. create column elements
    // 2.0 create column style
    OdfStyle columnStyle = styles.newStyle(OdfStyleFamily.TableColumn);
    String columnStylename = columnStyle.getStyleNameAttribute();
    columnStyle.setProperty(StyleTableColumnPropertiesElement.ColumnWidth,
        new DecimalFormat("000.0000").format(DEFAULT_TABLE_WIDTH / 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"));
      headercolumn.setTableNumberColumnsRepeatedAttribute(headerColumnNumber);
      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"));
    columns.setTableNumberColumnsRepeatedAttribute(numCols - headerColumnNumber);
    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;

    OdfPackageDocument document = dom.getDocument();
    if (!document.getMediaTypeString().equals(OdfMediaType.SPREADSHEET.getMediaTypeString())) {
      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

        || 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

TOP

Related Classes of org.odftoolkit.odfdom.incubator.doc.office.OdfOfficeAutomaticStyles

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.