@paramsFormComponentService theservicenameoftheformcomponenttocreate,e.g."TextField" @paramnXPos theabscissaofthepositionofthenewlyinsertedshape @paramnXPos theordinateofthepositionofthenewlyinsertedshape @paramnWidth thewidthofthenewlyinsertedshape @paramnHeight theheightofthenewlyinsertedshape @paramxParentForm theformtouseasparentforthenewlycreateformcomponent.Maybenull,inthiscase adefaultparentischosenbytheimplementation @return thepropertyaccesstothecontrol'smodel
*/ protected XPropertySet createControlAndShape( String sFormComponentService, int nXPos, int nYPos, int nWidth, int nHeight, XIndexContainer xParentForm ) throws java.lang.Exception
{ // let the document create a shape
XMultiServiceFactory xDocAsFactory = UnoRuntime.queryInterface(
XMultiServiceFactory.class, m_document.getDocument() );
XControlShape xShape = UnoRuntime.queryInterface( XControlShape.class,
xDocAsFactory.createInstance( "com.sun.star.drawing.ControlShape" ) );
// position and size of the shape
xShape.setSize( new Size( nWidth * 100, nHeight * 100 ) );
xShape.setPosition( new Point( nXPos * 100, nYPos * 100 ) );
// adjust the anchor so that the control is tied to the page
XPropertySet xShapeProps = UNO.queryPropertySet( xShape );
TextContentAnchorType eAnchorType = TextContentAnchorType.AT_PARAGRAPH;
xShapeProps.setPropertyValue( "AnchorType", eAnchorType );
// create the form component (the model of a form control)
String sQualifiedComponentName = "com.sun.star.form.component." + sFormComponentService;
XControlModel xModel = UnoRuntime.queryInterface( XControlModel.class,
m_document.getOrb().createInstance( sQualifiedComponentName ) );
// insert the model into the form component hierarchy, if the caller gave us a location if ( null != xParentForm )
{
xParentForm.insertByIndex( xParentForm.getCount(), xModel );
}
// knitt them
xShape.setControl( xModel );
// add the shape to the shapes collection of the document
XDrawPage pageWhereToInsert = ( m_insertPage != -1 ) ? m_document.getDrawPage( m_insertPage ) : m_document.getMainDrawPage();
@paramsFormComponentService theservicenameoftheformcomponenttocreate,e.g."TextField" @paramnXPos theabscissaofthepositionofthenewlyinsertedshape @paramnXPos theordinateofthepositionofthenewlyinsertedshape @paramnWidth thewidthofthenewlyinsertedshape @paramnHeight theheightofthenewlyinsertedshape @return thepropertyaccesstothecontrol'smodel
*/ protected XPropertySet createControlAndShape( String sFormComponentService, int nXPos, int nYPos, int nWidth, int nHeight ) throws java.lang.Exception
{ return createControlAndShape( sFormComponentService, nXPos, nYPos, nWidth, nHeight, null );
}
/* ------------------------------------------------------------------ */ /** creates a line of controls, consisting of a label and a field for data input.
// insert the text field control
XPropertySet xFieldModel = createControlAndShape( sControlType, nXPos + 26, nYPos, 40, nHeight );
xFieldModel.setPropertyValue( "DataField", sFieldName ); // knit it to its label component
xFieldModel.setPropertyValue( "LabelControl", xLabelModel );
// some names, so later on we can find them
xLabelModel.setPropertyValue( "Name", sFieldName + sControlNamePostfix + "_Label" );
xFieldModel.setPropertyValue( "Name", sFieldName + sControlNamePostfix );
return xFieldModel;
}
/* ------------------------------------------------------------------ */ /** creates a line of controls, consisting of a label and a field for data input.
/* ------------------------------------------------------------------ */ /** retrieves the radio button model with the given name and the given ref value *@paramform *theparentformoftheradiobuttonmodeltofind *@paramname *thenameoftheradiobutton *@paramrefValue *thereferencevalueoftheradiobutton
*/ public XPropertySet getRadioModelByRefValue( XPropertySet form, String name, String refValue ) throws com.sun.star.uno.Exception, java.lang.Exception
{
XIndexAccess indexAccess = UnoRuntime.queryInterface( XIndexAccess.class,
form );
for ( int i=0; i<indexAccess.getCount(); ++i )
{
XPropertySet control = UNO.queryPropertySet( indexAccess.getByIndex( i ) );
if ( ((String)control.getPropertyValue( "Name" )).equals( name ) ) if ( ((String)control.getPropertyValue( "RefValue" )).equals( refValue ) ) return control;
} returnnull;
}
/* ------------------------------------------------------------------ */ /** retrieves the radio button model with the given name and the given tag *@paramform *theparentformoftheradiobuttonmodeltofind *@paramname *thenameoftheradiobutton *@paramtag *thetagoftheradiobutton
*/ public XPropertySet getRadioModelByTag( XPropertySet form, String name, String tag ) throws com.sun.star.uno.Exception, java.lang.Exception
{
XIndexAccess indexAccess = UnoRuntime.queryInterface( XIndexAccess.class,
form );
for ( int i=0; i<indexAccess.getCount(); ++i )
{
XPropertySet control = UNO.queryPropertySet( indexAccess.getByIndex( i ) );
if ( ((String)control.getPropertyValue( "Name" )).equals( name ) ) if ( ((String)control.getPropertyValue( "Tag" )).equals( tag ) ) return control;
} returnnull;
}
}
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.