publicclass StyleDemo
{ publicstaticvoid main( String args[] )
{
XComponent xComponent = null; try
{ // get the remote office context of a running office (a new office // instance is started if necessary)
com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
// suppress Presentation Autopilot when opening the document // properties are the same as described for // com.sun.star.document.MediaDescriptor
PropertyValue[] pPropValues = new PropertyValue[ 1 ];
pPropValues[ 0 ] = new PropertyValue();
pPropValues[ 0 ].Name = "Silent";
pPropValues[ 0 ].Value = Boolean.TRUE;
/* The first part of this demo will set each "CharColor" Property thatisavailablewithinthestylesofthedocumenttored.It
will also print each family and style name to the standard output */
XModel xModel =
UnoRuntime.queryInterface(
XModel.class, xComponent );
com.sun.star.style.XStyleFamiliesSupplier xSFS =
UnoRuntime.queryInterface(
com.sun.star.style.XStyleFamiliesSupplier.class, xModel );
// the element should now contain at least two Styles. The first is // "graphics" and the other one is the name of the Master page
String[] Families = xFamilies.getElementNames(); for ( int i = 0; i < Families.length; i++ )
{ // this is the family
System.out.println( "\n" + Families[ i ] );
// and now all available styles
Object aFamilyObj = xFamilies.getByName( Families[ i ] );
com.sun.star.container.XNameAccess xStyles =
UnoRuntime.queryInterface(
com.sun.star.container.XNameAccess.class, aFamilyObj );
String[] Styles = xStyles.getElementNames(); for( int j = 0; j < Styles.length; j++ )
{
System.out.println( " " + Styles[ j ] );
Object aStyleObj = xStyles.getByName( Styles[ j ] );
com.sun.star.style.XStyle xStyle = UnoRuntime.queryInterface(
com.sun.star.style.XStyle.class, aStyleObj ); // now we have the XStyle Interface and the CharColor for // all styles is exemplary be set to red.
XPropertySet xStylePropSet = UnoRuntime.queryInterface( XPropertySet.class, xStyle );
XPropertySetInfo xStylePropSetInfo =
xStylePropSet.getPropertySetInfo(); if ( xStylePropSetInfo.hasPropertyByName( "CharColor" ) )
{
xStylePropSet.setPropertyValue( "CharColor",
Integer.valueOf( 0xff0000 ) );
}
}
}
/* now create a rectangle and apply the "title1" style of
the "graphics" family */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.