/** * Displays the applications window and starts service tracking; everything is done on the Swing * event thread to avoid synchronization and repainting issues. * * @param context The context of the bundle. */ public void start(final BundleContext context) { javax.swing.SwingUtilities.invokeLater( new Runnable() { // This creates of the application window. public void run() { m_frame = new DrawingFrame(); m_frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); m_frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent evt) { try { context.getBundle(0).stop(); } catch (BundleException ex) { ex.printStackTrace(); } } }); m_frame.setVisible(true); m_shapetracker = new ShapeTracker(context, m_frame); m_shapetracker.open(); } }); }
/** * Stops service tracking and disposes of the application window. * * @param context The context of the bundle. */ public void stop(BundleContext context) { Runnable runner = new Runnable() { // This disposes of the application window. public void run() { m_shapetracker.close(); m_frame.setVisible(false); m_frame.dispose(); } }; if (SwingUtilities.isEventDispatchThread()) { runner.run(); } else { try { javax.swing.SwingUtilities.invokeAndWait(runner); } catch (Exception ex) { ex.printStackTrace(); } } }