publicclass ChartDocumentTest implements DocumentTest
{ public ChartDocumentTest( final XMultiServiceFactory i_orb ) throws com.sun.star.uno.Exception
{
m_textDocument = OfficeDocument.blankDocument( i_orb, DocumentType.WRITER );
// create an OLE shape in the document final XMultiServiceFactory factory = UnoRuntime.queryInterface( XMultiServiceFactory.class, m_textDocument.getDocument() ); final String shapeServiceName = "com.sun.star.text.TextEmbeddedObject"; final XPropertySet shapeProps = UnoRuntime.queryInterface( XPropertySet.class, factory.createInstance( shapeServiceName ) );
shapeProps.setPropertyValue("CLSID", "12dcae26-281f-416f-a234-c3086127382e");
final XShape shape = UnoRuntime.queryInterface( XShape.class, shapeProps );
shape.setSize( new Size( 16000, 9000 ) );
final XTextContent chartTextContent = UnoRuntime.queryInterface( XTextContent.class, shapeProps );
final XSelectionSupplier selSupplier = UnoRuntime.queryInterface( XSelectionSupplier.class,
m_textDocument.getCurrentView().getController() ); final Object selection = selSupplier.getSelection(); final XTextRange textRange = getAssociatedTextRange( selection ); if ( textRange == null ) thrownew RuntimeException( "can't locate a text range" );
// insert the chart
textRange.getText().insertTextContent(textRange, chartTextContent, false);
// retrieve the chart model
XChartDocument chartDoc = UnoRuntime.queryInterface( XChartDocument.class, shapeProps.getPropertyValue( "Model" ) ); // insert default chart for the test to use.
com.sun.star.chart2.XChartDocument xCD2 =
UnoRuntime.queryInterface(com.sun.star.chart2.XChartDocument.class, chartDoc);
xCD2.createDefaultChart();
m_chartDocument = new OfficeDocument( i_orb, chartDoc );
// actually activate the object final XEmbeddedObject embeddedChart = UnoRuntime.queryInterface( XEmbeddedObject.class,
shapeProps.getPropertyValue( "EmbeddedObject" ) );
embeddedChart.doVerb( EmbedVerbs.MS_OLEVERB_SHOW );
finalint state = embeddedChart.getCurrentState(); if ( state != EmbedStates.UI_ACTIVE )
fail( "unable to activate the embedded chart" );
}
public String getDocumentDescription()
{ return"chart document";
}
private XPropertySet impl_getWallProperties()
{ final XChartDocument chartDoc = UnoRuntime.queryInterface( XChartDocument.class, m_chartDocument.getDocument() ); final XDiagram diagram = chartDoc.getFirstDiagram(); final XPropertySet wallProperties = diagram.getWall(); return wallProperties;
}
private XPropertySet impl_getYAxisProperties() throws IndexOutOfBoundsException
{
XPropertySet axisProperties = null; final XChartDocument chartDoc = UnoRuntime.queryInterface( XChartDocument.class, m_chartDocument.getDocument() ); final XDiagram diagram = chartDoc.getFirstDiagram(); final XCoordinateSystemContainer coordContainer = UnoRuntime.queryInterface( XCoordinateSystemContainer.class, diagram ); final XCoordinateSystem[] coordSystems = coordContainer.getCoordinateSystems(); final XCoordinateSystem coordSystem = coordSystems[0]; final XAxis primaryYAxis = coordSystem.getAxisByDimension( 1, 0 );
axisProperties = UnoRuntime.queryInterface( XPropertySet.class, primaryYAxis ); return axisProperties;
}
private XUndoManager impl_getUndoManager()
{ final XUndoManagerSupplier undoManagerSupp = UnoRuntime.queryInterface( XUndoManagerSupplier.class, m_chartDocument.getDocument() ); final XUndoManager undoManager = undoManagerSupp.getUndoManager(); return undoManager;
}
publicvoid doSingleModification() throws com.sun.star.uno.Exception
{ final XPropertySet wallProperties = impl_getWallProperties();
// simulate an Undo action, as long as the chart implementation doesn't add Undo actions itself final XUndoManager undoManager = impl_getUndoManager();
undoManager.addUndoAction( new PropertyUndoAction( wallProperties, "FillColor", 0xCCFF44 ) ); // (the UndoAction will actually set the property value)
}
publicint doMultipleModifications() throws com.sun.star.uno.Exception
{ final XPropertySet axisProperties = impl_getYAxisProperties();
final XUndoManager undoManager = impl_getUndoManager();
undoManager.addUndoAction( new PropertyUndoAction( axisProperties, "LineWidth", 300 ) );
undoManager.addUndoAction( new PropertyUndoAction( axisProperties, "LineColor", 0x000000 ) );
return2;
}
public OfficeDocument getDocument()
{ return m_chartDocument;
}
private XTextRange getAssociatedTextRange( final Object i_object ) throws WrappedTargetException, IndexOutOfBoundsException
{ // possible cases: // 1. a container of other objects - e.g. selection of 0 to n text portions, or 1 to n drawing objects final XIndexAccess indexer = UnoRuntime.queryInterface( XIndexAccess.class, i_object ); if ((indexer != null) && indexer.getCount() > 0) { finalint count = indexer.getCount(); for (int i = 0; i < count; ++i) { final XTextRange range = getAssociatedTextRange( indexer.getByIndex(i) ); if (range != null) { return range;
}
}
} // 2. another TextContent, having an anchor we can use final XTextContent textContent = UnoRuntime.queryInterface(XTextContent.class, i_object); if (textContent != null) { final XTextRange range = textContent.getAnchor(); if (range != null) { return range;
}
}
// an object which supports XTextRange directly final XTextRange range = UnoRuntime.queryInterface(XTextRange.class, i_object); if (range != null) { return range;
}
returnnull;
}
privatestaticclass PropertyUndoAction implements XUndoAction
{
PropertyUndoAction( final XPropertySet i_component, final String i_propertyName, final Object i_newValue ) throws com.sun.star.uno.Exception
{
m_component = i_component;
m_propertyName = i_propertyName;
m_newValue = i_newValue;
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.