diff options
Diffstat (limited to 'odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java')
-rw-r--r-- | odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java b/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java index 3a90b2d63313..d895be7df98f 100644 --- a/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java +++ b/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java @@ -72,32 +72,32 @@ import com.sun.star.awt.XWindow; public class SelectionChangeListener implements XSelectionChangeListener { public static void main( String args[] ) { SelectionChangeListener aMySelf = new SelectionChangeListener( args ); - + aMySelf.run(); } - + public SelectionChangeListener( String args[] ) { Helper aHelper = new Helper( args ); - + maContext = aHelper.getComponentContext(); - + CalcHelper aCalcHelper = new CalcHelper( aHelper.createSpreadsheetDocument() ); - + // insert a cell range with 4 columns and 12 rows filled with random numbers XCellRange aRange = aCalcHelper.insertRandomRange( 4, 12 ); CellRangeAddress aRangeAddress = ((XCellRangeAddressable) UnoRuntime.queryInterface( XCellRangeAddressable.class, aRange)).getRangeAddress(); - + // change view to sheet containing the chart aCalcHelper.raiseChartSheet(); - + // the unit for measures is 1/100th of a millimeter // position at (1cm, 1cm) Point aPos = new Point( 1000, 1000 ); - + // size of the chart is 15cm x 9.271cm Size aExtent = new Size( 15000, 9271 ); - + // insert a new chart into the "Chart" sheet of the // spreadsheet document maChartDocument = aCalcHelper.insertChart( @@ -107,12 +107,12 @@ public class SelectionChangeListener implements XSelectionChangeListener { aExtent, "com.sun.star.chart.XYDiagram" ); } - + // ____________________ - + public void run() { boolean bTrying = true; - + while( bTrying ) { // start listening for selection changes XSelectionSupplier aSelSupp = (XSelectionSupplier) UnoRuntime.queryInterface( @@ -124,67 +124,67 @@ public class SelectionChangeListener implements XSelectionChangeListener { System.out.println( "Successfully attached as selection change listener" ); bTrying = false; } - + // start listening for death of Controller XComponent aComp = (XComponent) UnoRuntime.queryInterface( XComponent.class, aSelSupp ); if( aComp != null ) { aComp.addEventListener( this ); System.out.println( "Successfully attached as dispose listener" ); } - + try { Thread.currentThread().sleep( 500 ); } catch( InterruptedException ex ) { } } } - + // ____________________ - + // XEventListener (base of XSelectionChangeListener) public void disposing( EventObject aSourceObj ) { System.out.println( "disposing called. detaching as listener" ); - + // stop listening for selection changes XSelectionSupplier aCtrl = (XSelectionSupplier) UnoRuntime.queryInterface( XSelectionSupplier.class, aSourceObj ); if( aCtrl != null ) aCtrl.removeSelectionChangeListener( this ); - + // remove as dispose listener XComponent aComp = (XComponent) UnoRuntime.queryInterface( XComponent.class, aSourceObj ); if( aComp != null ) aComp.removeEventListener( this ); - + // bail out System.exit( 0 ); } - + // ____________________ - + // XSelectionChangeListener public void selectionChanged( EventObject aEvent ) { XController aCtrl = (XController) UnoRuntime.queryInterface( XController.class, aEvent.Source ); if( aCtrl != null ) { XMultiComponentFactory mMCF = maContext.getServiceManager(); - + MyMessageBox aMsgBox = new MyMessageBox(mMCF); - + aMsgBox.start(); - + System.out.println("Listener finished"); } } - + // __________ private __________ - + private class MyMessageBox extends Thread{ private XMultiComponentFactory mMCF; - + public MyMessageBox(XMultiComponentFactory xMCF){ mMCF = xMCF; } - + public void run() { XDesktop aDesktop = null; XInterface aToolKit = null; @@ -196,16 +196,16 @@ public class SelectionChangeListener implements XSelectionChangeListener { try { Object oDesktop = mMCF.createInstanceWithContext("com.sun.star.frame.Desktop", maContext); Object oToolKit = mMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", maContext); - + aDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, oDesktop); aToolKit = (XInterface) UnoRuntime.queryInterface(XInterface.class, oToolKit); } catch (Exception ex) { ex.printStackTrace(); } - + XWindow xWin = aDesktop.getCurrentFrame().getContainerWindow(); XWindowPeer aWinPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xWin); - + Rectangle aRect = new Rectangle(); int button = com.sun.star.awt.MessageBoxButtons.BUTTONS_OK; XMessageBoxFactory aMBF = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, aToolKit); @@ -213,7 +213,7 @@ public class SelectionChangeListener implements XSelectionChangeListener { xMB.execute(); } } - + private XChartDocument maChartDocument; private XComponentContext maContext; } |