summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRüdiger Timm <rt@openoffice.org>2007-11-06 14:07:48 +0000
committerRüdiger Timm <rt@openoffice.org>2007-11-06 14:07:48 +0000
commit520374fa58bdf4c55e30dec69fac73a6b2e78739 (patch)
treeb96ea0adbbb94b0f5eef44bad549da45928bd4d6
parentb41b7e84f14070c2faeb6e1aed76461064d775c5 (diff)
INTEGRATION: CWS cn1 (1.3.312); FILE MERGED
2007/05/30 19:26:07 cn 1.3.312.1: #i77943# implement uno-awt messagebox into SelectionChangeListener
-rw-r--r--odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java124
1 files changed, 76 insertions, 48 deletions
diff --git a/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java b/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java
index cb14070216b0..e4ce27462dd4 100644
--- a/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java
+++ b/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java
@@ -2,9 +2,9 @@
*
* $RCSfile: SelectionChangeListener.java,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: hr $ $Date: 2003-06-30 15:10:57 $
+ * last change: $Author: rt $ $Date: 2007-11-06 15:07:48 $
*
* The Contents of this file are made available subject to the terms of
* the BSD license.
@@ -38,10 +38,9 @@
*
*************************************************************************/
-// __________ Imports __________
-
-// base classes
-import com.sun.star.uno.XInterface;
+import com.sun.star.awt.XMessageBox;
+import com.sun.star.awt.XWindowPeer;
+import com.sun.star.frame.XDesktop;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.lang.*;
import com.sun.star.frame.XModel;
@@ -49,6 +48,8 @@ import com.sun.star.frame.XController;
// application specific classes
import com.sun.star.chart.*;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.uno.XInterface;
import com.sun.star.view.XSelectionChangeListener;
import com.sun.star.view.XSelectionSupplier;
@@ -58,39 +59,34 @@ import com.sun.star.table.XCellRange;
import com.sun.star.sheet.XCellRangeAddressable;
import com.sun.star.awt.Point;
+import com.sun.star.awt.Rectangle;
import com.sun.star.awt.Size;
-
-// Exceptions
-import com.sun.star.uno.Exception;
-import com.sun.star.uno.RuntimeException;
-
-// for output messages
-import javax.swing.JOptionPane;
+import com.sun.star.awt.XMessageBoxFactory;
+import com.sun.star.awt.XWindow;
// __________ Implementation __________
/** Create a spreadsheet add some data.
- Create a presentation and add a chart.
- Connect the chart to a calc range via a listener
-
- Note: This example does not work in StarOffice 6.0. It will be available
- in the StarOffice Accessibility release.
-
- @author Bj&ouml;rn Milcke
+ * Create a presentation and add a chart.
+ * Connect the chart to a calc range via a listener
+ *
+ * Note: This example does not work in StarOffice 6.0. It will be available
+ * in the StarOffice Accessibility release.
+ *
+ * @author Bj&ouml;rn Milcke
*/
-public class SelectionChangeListener implements XSelectionChangeListener
-{
- public static void main( String args[] )
- {
+public class SelectionChangeListener implements XSelectionChangeListener {
+ public static void main( String args[] ) {
SelectionChangeListener aMySelf = new SelectionChangeListener( args );
aMySelf.run();
}
- public SelectionChangeListener( String args[] )
- {
+ 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
@@ -120,19 +116,16 @@ public class SelectionChangeListener implements XSelectionChangeListener
// ____________________
- public void run()
- {
+ public void run() {
boolean bTrying = true;
- while( bTrying )
- {
+ while( bTrying ) {
// start listening for selection changes
XSelectionSupplier aSelSupp = (XSelectionSupplier) UnoRuntime.queryInterface(
XSelectionSupplier.class,
(((XModel) UnoRuntime.queryInterface(
- XModel.class, maChartDocument )).getCurrentController()) );
- if( aSelSupp != null )
- {
+ XModel.class, maChartDocument )).getCurrentController()) );
+ if( aSelSupp != null ) {
aSelSupp.addSelectionChangeListener( this );
System.out.println( "Successfully attached as selection change listener" );
bTrying = false;
@@ -140,18 +133,14 @@ public class SelectionChangeListener implements XSelectionChangeListener
// start listening for death of Controller
XComponent aComp = (XComponent) UnoRuntime.queryInterface( XComponent.class, aSelSupp );
- if( aComp != null )
- {
+ if( aComp != null ) {
aComp.addEventListener( this );
System.out.println( "Successfully attached as dispose listener" );
}
- try
- {
+ try {
Thread.currentThread().sleep( 500 );
- }
- catch( InterruptedException ex )
- {
+ } catch( InterruptedException ex ) {
}
}
}
@@ -159,8 +148,7 @@ public class SelectionChangeListener implements XSelectionChangeListener
// ____________________
// XEventListener (base of XSelectionChangeListener)
- public void disposing( EventObject aSourceObj )
- {
+ public void disposing( EventObject aSourceObj ) {
System.out.println( "disposing called. detaching as listener" );
// stop listening for selection changes
@@ -181,17 +169,57 @@ public class SelectionChangeListener implements XSelectionChangeListener
// ____________________
// XSelectionChangeListener
- public void selectionChanged( EventObject aEvent )
- {
+ public void selectionChanged( EventObject aEvent ) {
XController aCtrl = (XController) UnoRuntime.queryInterface( XController.class, aEvent.Source );
- if( aCtrl != null )
- {
- JOptionPane.showMessageDialog( null, "Selection has changed", "Got new Event",
- JOptionPane.INFORMATION_MESSAGE );
+ 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;
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ 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);
+ XMessageBox xMB = aMBF.createMessageBox(aWinPeer, aRect, "infobox" , button, "Event-Notify", "Listener was called, selcetion has changed");
+ xMB.execute();
+ }
+ }
+
private XChartDocument maChartDocument;
+ private XComponentContext maContext;
}