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

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


   * Get the style name of this cell.
   *
   * @return the name of the style
   */
  public String getStyleName() {
    OdfStyle style = getCellStyleElement();
    if (style == null) {
      return "";
    }
    return style.getStyleNameAttribute();
  }
View Full Code Here


    }
    if (styleName == null || (styleName.equals(""))) {
      return null;
    }

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

    if (styleElement == null) {
      styleElement = mDocument.getDocumentStyles().getStyle(styleName,
          OdfStyleFamily.TableCell);
    }

    if (styleElement == null) {
      styleElement = mCellElement.getDocumentStyle();
    }

    if (styleElement == null) {
      OdfStyle newStyle = mCellElement.getAutomaticStyles().newStyle(
          OdfStyleFamily.TableCell);
      String newname = newStyle.getStyleNameAttribute();
      mCellElement.setStyleName(newname);
      newStyle.addStyleUser(mCellElement);
      return newStyle;
    }

    return styleElement;
  }
View Full Code Here

    if (styleName == null || (styleName.equals(""))) {
      return null;
    }

    OdfOfficeAutomaticStyles styles = mCellElement.getAutomaticStyles();
    OdfStyle styleElement = styles.getStyle(styleName, mCellElement.getStyleFamily());

    if (styleElement == null) {
      styleElement = mDocument.getDocumentStyles().getStyle(styleName, OdfStyleFamily.TableCell);
    }

    if (styleElement == null) {
      styleElement = mCellElement.getDocumentStyle();
    }

    if (styleElement.getStyleUserCount() > 1 || copy) //if this style are used by many users,
    //should create a new one.
    {
      OdfStyle newStyle = mCellElement.getAutomaticStyles().newStyle(OdfStyleFamily.TableCell);
      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
      //mCellElement.getAutomaticStyles().appendChild(newStyle);
      String newname = newStyle.getStyleNameAttribute();
      mCellElement.setStyleName(newname);
      return newStyle;
    }
    return styleElement;
  }
View Full Code Here

  private void applyTextStyleProperties(Map<OdfStyleProperty, String> styleMap,
      OdfStylableElement toElement) {
    if (styleMap != null) {
      //preserve the style property of toElement if it is also exist in styleMap
      OdfStyle resultStyleElement = toElement.getAutomaticStyles().newStyle(
          OdfStyleFamily.Text);

      for (Map.Entry<OdfStyleProperty, String> entry : styleMap.entrySet()) {
        if (toElement.hasProperty(entry.getKey())) {
          resultStyleElement.setProperty(entry.getKey(), toElement.getProperty(entry.getKey()));
        } else {
          resultStyleElement.setProperty(entry.getKey(), entry.getValue());
        }
      }
      toElement.setStyleName(resultStyleElement.getStyleNameAttribute());
    }
  }
View Full Code Here

     * @param name  The style name
     * @param family The style family
     * @return  The <code>OdfStyle</code> element
     */
    public OdfStyle newStyle(String name, OdfStyleFamily family) {
        OdfStyle newStyle = ((OdfFileDom) this.ownerDocument).newOdfElement(OdfStyle.class);
        newStyle.setStyleNameAttribute(name);
        newStyle.setStyleFamilyAttribute(family.getName());
        this.appendChild(newStyle);
        return newStyle;
    }
View Full Code Here

    return ListType.IMAGE;
  }

  private OdfStyle getOrCreateStyleByName(OdfOfficeStyles documentStyles, OdfOfficeAutomaticStyles styles,
      String styleName, OdfStyleFamily styleFamily) {
    OdfStyle odfStyle = documentStyles.getStyle(styleName, styleFamily);
    if (odfStyle == null) {
      styles.getStyle(styleName, styleFamily);
    }
    if (odfStyle == null) {
      odfStyle = styles.newStyle(styleFamily);
      odfStyle.setStyleNameAttribute(styleName);
      odfStyle.setStyleDisplayNameAttribute(styleName);
    }
    return odfStyle;
  }
View Full Code Here

   * @param styleFamily  The <code>OdfStyleFamily</code> element
   * @return an <code>OdfStyle</code> element
   */
  public OdfStyle newStyle(OdfStyleFamily styleFamily) {
    OdfFileDom dom = (OdfFileDom) this.ownerDocument;
    OdfStyle newStyle = dom.newOdfElement(OdfStyle.class);
    newStyle.setStyleFamilyAttribute(styleFamily.getName());

    newStyle.setStyleNameAttribute(newUniqueStyleName(styleFamily));

    this.appendChild(newStyle);

    return newStyle;
  }
View Full Code Here

   */
  public void optimize() {
    Iterator<OdfStyle> iter = mStylesBaseImpl.getAllOdfStyles().iterator();
    SortedSet<OdfStyle> stylesSet = new TreeSet<OdfStyle>();
    while (iter.hasNext()) {
      OdfStyle cur = iter.next();

      // skip styles which are not in use:
      if (cur.getStyleUserCount() < 1) {
        continue;
      }

      SortedSet<OdfStyle> tail = stylesSet.tailSet(cur);
      OdfStyle found = tail.size() > 0 ? tail.first() : null;
      if (found != null && found.equals(cur)) {
        // cur already in set. Replace all usages of cur by found:
        Iterator<OdfStylableElement> styleUsersIter = cur.getStyleUsers().iterator();
        ArrayList<OdfStylableElement> styleUsers = new ArrayList<OdfStylableElement>();
        while (styleUsersIter.hasNext()) {
          styleUsers.add(styleUsersIter.next());
        }
        styleUsersIter = styleUsers.iterator();
        while (styleUsersIter.hasNext()) {
          OdfStylableElement elem = styleUsersIter.next();
          OdfStyle autoStyle = elem.getAutomaticStyle();
          if (autoStyle != null) {
            elem.setStyleName(found.getStyleNameAttribute());
          }
        }
      } else {
        stylesSet.add(cur);
      }
    }

    OdfStyle style = OdfElement.findFirstChildNode(OdfStyle.class, this);
    while (style != null) {
      OdfStyle nextStyle = OdfElement.findNextChildNode(OdfStyle.class, style);
      if (style.getStyleUserCount() < 1) {
        this.removeChild(style);
      }

      style = nextStyle;
View Full Code Here

   *
   * @param referenceStyle The reference <code>OdfStyle</code> element
   * @return an <code>OdfStyle</code> element
   */
  public OdfStyle makeStyleUnique(OdfStyle referenceStyle) {
    OdfStyle newStyle = null;

    if (referenceStyle.getOwnerDocument() != this.getOwnerDocument()) {
      // import style from a different dom
      newStyle = (OdfStyle) this.getOwnerDocument().importNode(referenceStyle, true);
    } else {
      // just clone
      newStyle = (OdfStyle) referenceStyle.cloneNode(true);
    }

    newStyle.setStyleNameAttribute(newUniqueStyleName(newStyle.getFamily()));
    appendChild(newStyle);

    return newStyle;
  }
View Full Code Here

        defaultStyles.put(defStyle.getFamilyName(), defStyle);
      }

      NodeList styleList = mTextDocument.getDocumentStyles().getElementsByTagName("style:style");
      for (int i = 0; i < styleList.getLength(); i++) {
        OdfStyle sStyle = (OdfStyle) styleList.item(i);
        //get default properties and style properties
        Map<OdfStyleProperty, String> map = sStyle.getStylePropertiesDeep();
        //check if properties include all search properties and value equal
        Iterator<OdfStyleProperty> pIter = mProps.keySet().iterator();
        boolean isStyle = false;
        while (pIter.hasNext()) {
          isStyle = false;
          OdfStyleProperty p = pIter.next();
          if (map.containsKey(p)) {
            if (map.get(p).equals(mProps.get(p))) {
              isStyle = true;
            } else {
              break;
            }
          } else {
            break;
          }
        }
        //put all match style names
        if (isStyle) {
          sname = sStyle.getStyleNameAttribute();
          //if(sname.contains("default"))sname="defaultstyle";
          styleNames.add(sname);
        }
      }
      //get all automatic styles
      Iterator<OdfStyle> cStyles = mTextDocument.getContentDom().getAutomaticStyles().getAllStyles().iterator();
      while (cStyles.hasNext()) {
        OdfStyle cStyle = cStyles.next();
        //get default properties and style properties
        Map<OdfStyleProperty, String> map = cStyle.getStylePropertiesDeep();

        if (cStyle.getParentStyle() == null) {
          if (cStyle.getFamilyName().equals("text")) {
            if (defaultStyles.containsKey("text")) {
              getTextDefaultProperties("text", defaultStyles, map);
            } else {
              getTextDefaultProperties("paragraph", defaultStyles, map);
            }
          }
        }

        //check if the search properties is in properties
        Iterator<OdfStyleProperty> pIter = mProps.keySet().iterator();
        boolean isStyle = false;
        while (pIter.hasNext()) {
          isStyle = false;
          OdfStyleProperty p = pIter.next();
          if (map.containsKey(p)) {
            if (map.get(p).equals(mProps.get(p))) {
              isStyle = true;
            } else {
              break;
            }
          } else {
            break;
          }
        }
        //put all match style names
        if (isStyle) {
          styleNames.add(cStyle.getStyleNameAttribute());
        }
      }

    } catch (Exception e1) {
      Logger.getLogger(TextStyleNavigation.class.getName()).log(Level.SEVERE, e1.getMessage(), e1);
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.