Regarding custom events

I got some difficulties using custom event listeners.
What I would like to achieve is pretty simple. With a bunch
of movable fruits, when dragging one of them(this becomes the
'active' object) to collide with others(these are the 'inactive
objects'), I need Flash to tell me who is colliding whom.
So I setup the Fruit Class, with the ability to dispatch and
listen the custom event: "EXECUTE_HITTEST". For me the code looks
good, but there's must be something wrong...
The full .fla & .as files can be downloaded
here, and you can
preview
the
snapshot here.
Thanks in advance.
It's in the .zip file as well but for your convenience I just
put the Fruit Class here:
================================================================

your event (and everything else in your class) is specific to
class instances. no two instances can communicate with each other
directly.
you can create another class that contains references to them
all, but that won't get you any further than using each instance to
get to the root timeline which then allows access to the others.
there are several strategies for increasing efficiency of
hitTests. i like to use a grid.
imagine the stage divided into a grid. if your objects are
not changing position with time t, you have an easy task. if they
change position with time, you'll have more work to do.
but for each time t, each grid contains a list of objects
within it. for each time t, each object has a property referencing
the grid within which it's contained.
when you want to perform a hittest for a particular object,
check its grid. then execute a hittest against all objects in that
grid and the eight (assuming rectangular shaped) surrounding grids.
there are several strategies for picking a grid size. but, in
general, you don't want grids to be so small that when you check
for collisions, you have to check beyond the surrounding 8 plus the
center grid.

Similar Messages

  • Query regarding creating a Custom Event and Firing.

    I have created a custom event,a custom listener and a custom button.
    But when I click on custom button,my event is not being fired.
    When and how do I need to invoke the fireEvent() ?
    Please can any body tell me if I have overlooked any thing ?
    Thanks,
    // 1 Custom Event
    import java.util.EventObject;
    public class MyActionEvent extends EventObject{
            public MyActionEvent(Object arg0) {
         super(arg0);
    // 2 Custom Listener
    import java.util.EventListener;
    public interface MyActionListener extends EventListener {
          public void myActionPerformed(MyActionEvent myEvent);
    // 3 Custom Button
    public class MyButton extends JButton {
        // Create the listener list
        protected javax.swing.event.EventListenerList listenerList = new javax.swing.event.EventListenerList();
          public MyButton(String str){
         super(str);
         public void addMyActionEventListener(MyActionListener listener) {
             listenerList.add(MyActionListener.class, listener);
        protected void fireMyActionEvent() {
            MyActionEvent evt = new MyActionEvent(this);
            Object[] listeners = listenerList.getListenerList();
           for (int i = 0; i < listeners.length; i = i+2) {
                 if (listeners[i] == MyActionListener.class) {
                      ((MyActionListener) listeners[i+1]).myActionPerformed(evt);
    } // end of class MyButton.
    // 4 Test my Custom Event,Listener and Button
    public class MyButtonDemo extends JPanel {
        protected MyButton b1;
        public MyButtonDemo() {
            b1 = new MyButton("Disable Button");
            b1.setToolTipText("Click this button to disable the middle button.");
            b1.addMyActionEventListener(new MyActionListener() {
         @Override
         public void myActionPerformed(MyActionEvent myEvent) {
         System.out.println("My ActionEvent....");
            add(b1);
        private static void createAndShowGUI() {
            JFrame frame = new JFrame("ButtonDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            MyButtonDemo newContentPane = new MyButtonDemo();
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    Hi Stan,
    I would like to use my custom action listener rather that using the the normal actionPerformed(ActionEvent e)
    But some how this event is not being fired.
    Any suggestions to fire this?
    b1.addMyActionEventListener(new MyActionListener() {
             @Override
             public void myActionPerformed(MyActionEvent myEvent) {
         System.out.println("My ActionEvent triggered....");
    });

  • Custom Events and Scheduling more than once

    Hi,
    in BO 4.1, I successfully triggered WebI Report instance generation by a "Custom Event" through scheduling.
    Now, we have the requirement that the report should not be triggered only once but always when the event is triggered.
    At first glance, this looks tricky bc. in order that the report "reacts" to the event, the report itself must be scheduled with the event (it gets an instance "pending" that "wait + reacts" to the event). So it looks like we need schedule the report always manually with "event" before it is ready to react to the event specified in the scheduling.
    Is there any user-friendly trick to make the report react upon every fired event without having to "schedule" the report manually with the event?
    (Similar to schedule daily, just that the event is the trigger, note a daytime...)
    Best Regards

    Hi Florian,
    What is the frequency set under Recurrence option for the report instance?
    Can you give an idea like after how much time the event can be triggered?
    For example, if you are expecting the event to change in an hour, you can schedule the recurrence as hourly or you can specify something like 0 hours and 15 minutes or something like that.
    In that case, once the event is fired, your report instance will be ready to trigger after 15 minutes for the next run.
    Would suggest you to sync with the BO administrator as concurrent triggering of large number of instances can give load on Job Servers.
    Hope it will help in some way.
    Regards,
    Yuvraj

  • Issue in using custom event from outreach

    Hi
    I have created a custom event and executed a scenario successfully for this custom event from ACC. But when I try to configure the same event from Outreach(BCC), I am able to see this custom event in the list of available events, but after selecting this event there is no option to configure attributes for this event, but I can configure attributes in ACC. My BCC version is 10.1.1
    Edited by: 1002715 on Apr 26, 2013 3:06 AM

    Dear Ankit,
    Once the pricing procedure is downloaded, please maintain the document pricing procedure at service contract header level, and maintain the customer pricing procedure at business partner sales area billing data.
    In spro, maintain the pricing procedure for the combination of sales area, document pricing procedure, customer pricing procedure.
    Please crosscheck whether the condition table is active or not.
    Regards,
    Maddy

  • I am trying to trigger a custom event using a program but does not work ..

    HI ....i am trying to trigger a custom event of a custom object type using a program but does not work. If trigger the same event using SWUE it works.
    below is the code...
    {Key = '0010001115'. "Sales Order Number (hard-coded)
    CALL FUNCTION 'SWE_EVENT_CREATE'
      EXPORTING
        objtype                       = 'ZXXXXXXXF'
        objkey                        = KEY
        event                         = 'ZEVENT'
      CREATOR                       = ' '
      TAKE_WORKITEM_REQUESTER       = ' '
      START_WITH_DELAY              = ' '
      START_RECFB_SYNCHRON          = ' '
      NO_COMMIT_FOR_QUEUE           = ' '
      DEBUG_FLAG                    = ' '
      NO_LOGGING                    = ' '
      IDENT                         =
    IMPORTING
      EVENT_ID                      =
      RECEIVER_COUNT                =
    TABLES
      EVENT_CONTAINER               =
    EXCEPTIONS
      OBJTYPE_NOT_FOUND             = 1
      OTHERS                        = 2}
    Please guide me if i am missing something.

    Hi Sunny,
    I think you should try creating the event using FM SAP_WAPI_CREATE_EVENT.
    CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
      EXPORTING
        OBJECT_TYPE             =  'ZXXXXXXXF'
        OBJECT_KEY              = key
        EVENT                   = 'ZEVENT'
    *   COMMIT_WORK             = 'X'
    *   EVENT_LANGUAGE          = SY-LANGU
    *   LANGUAGE                = SY-LANGU
    *   USER                    = SY-UNAME
    *   IFS_XML_CONTAINER       =
    IMPORTING
       RETURN_CODE             = rcode
       EVENT_ID                = event_id
    * TABLES
    *   INPUT_CONTAINER         =
    *   MESSAGE_LINES           =
    *   MESSAGE_STRUCT          =
    Regards,
    Saumya

  • Custom Event generation and Handling

    HI all,
    I am new to java. I have a dataset which changes dynamically and this dataset is responsible for some other dataset(s). So whenever the original dataset is modified, the other datasets based on this dataset should be updated automatically so as to preserve the consistency.
    What I want to do is to write a custom event which is to be fired whenever the original dataset is modified and notify it to other datasets so as to ensure the consistency.
    Any help in this regard is extremely appreciated.

    HI Duffymo,
    Here is my problem for better understanding:
    I have a vector data in a NodePanel (this vector data originates from some other datastructure...but that is immaterial as we know that this data is an instance of that datastructure). This vectordata in NodePanel is responsible for another vectordata in SchedulePanel. The NodePanel and SchedulePanel are tabbedPanels in a tabbedframe. Whenever I update the vector data in NodePanel, the vector data in SchedulePanel needs to be updated.
    The solution you gave me, taught me an insight of the event handling in Java.
    I am quoting my source for your reference as I am unable to incorporate your idea into my project.
    Event class:
    import java.util.*;
    public class VectorUpdateEvent extends EventObject
         public VectorUpdateEvent(Object source)
              super(source);
    Interface to EventListener
    public interface VectorUpdateListener
         public void eventVectorUpdated(VectorUpdateEvent event);
    class EventGenerator
    import java.util.*;
    public class VectorUpdateEventIssuer
         implements EventListener
         public VectorUpdateEventIssuer()
              listListeners = new ArrayList();
         public synchronized void addVectorUpdateEventListener(VectorUpdateEvent l)
              listListeners.add(l);
         protected synchronized void removeVectorUpdateEventListener(VectorUpdateEvent l)
              listListeners.remove(listListeners.indexOf(l));
         protected void notifyVectorUpdateEvent(Object source)
              VectorUpdateEvent evt = new VectorUpdateEvent(source);
              Iterator itr = listListeners.iterator();
              while (itr.hasNext())
                   ((VectorUpdateListener)itr.next()).eventVectorUpdated(evt);
         private ArrayList listListeners;
    class where the event originates
    class NodePanel
         extends JPanel
         implements ActionListener, ListSelectionListener
         /////////////Constructors/////////////////////////
         public NodePanel()
              addNodeButton = new JButton("Add Node");
              delNodeButton = new JButton("Delete Node");
              dumpNodeButton = new JButton("Dump Node");
              reloadNodeButton = new JButton("Reload Node");
              browseButton = new JButton("Browse Node");
              exitButton = new JButton("Exit");
              add(addNodeButton);
              add(delNodeButton);
              add(dumpNodeButton);
              add(reloadNodeButton);
              add(browseButton);
              add(exitButton);
              setButtonsEnabled(false);
              addNodeButton.addActionListener(this);
              delNodeButton.addActionListener(this);
              dumpNodeButton.addActionListener(this);
              reloadNodeButton.addActionListener(this);
              browseButton.addActionListener(this);
              exitButton.addActionListener(this);
              nodesVector = new Vector();
              nodesList = new JList(nodesVector);
              this.vectorNodeAttributes = new Vector();
              JScrollPane scrollPane = new JScrollPane(nodesList);
              add(scrollPane,BorderLayout.CENTER);
              nodesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              nodesList.addListSelectionListener(this);
         ////////////////Methods///////////////////////////
         /////////////Event valueChanged///////////////////
         public void valueChanged(ListSelectionEvent evt)
              JList source = (JList) evt.getSource();
              setButtonsEnabled(true);
              desiredNode = (String) source.getSelectedValue();
              if (desiredNode == null)
                   setButtonsEnabled(false);
         //////////////Event actionPerformed////////////
         public void actionPerformed(ActionEvent evt)
              Object source = evt.getSource();
              if (source == addNodeButton)
                   addNodeButtonClicked();
              else if (source == delNodeButton && desiredNode != null)
                   deleteNodeButtonClicked();
              else if (source == dumpNodeButton && desiredNode != null)
                   JFileChooser d = new JFileChooser();
                   //d.setCurrentDirectory("");
                   d.setFileFilter(new XMLFilter());
                   int result = d.showSaveDialog(this);
              else if (source == reloadNodeButton && desiredNode != null)
                   JFileChooser d1 = new JFileChooser();
                   //d.setCurrentDirectory("");
                   d1.setFileFilter(new XMLFilter());
                   int result = d1.showOpenDialog(this);
                   //String filename=d1.getSelectedFile().getName();
              if (source == browseButton && desiredNode != null)
                   browseButtonClicked();
              else if (source == exitButton)
                   System.exit(0);
         //////////Enables or Diables the Buttons////////
         private void setButtonsEnabled(boolean enable)
              delNodeButton.setEnabled(enable);
              dumpNodeButton.setEnabled(enable);
              reloadNodeButton.setEnabled(enable);
              browseButton.setEnabled(enable);
              private void deleteNodeButtonClicked()
              if (noFieldDlg != null)
                   noFieldDlg.dispose();
              noFieldDlg = new NoFieldDialog("Delete the Node?");
              noFieldDlg.show();
              if (noFieldDlg.getDialogResult() == DialogResult.OK)
                   int nodeToRemove=0;
                   for (int i=0; i< vectorNodeAttributes.size(); i++)
                        if(((NodeAttributes)(vectorNodeAttributes.get(i))).getNodeName().compareTo(nodesList.getSelectedValue()) == 0)
                             nodeToRemove = i;
                   vectorNodeAttributes.remove(nodeToRemove);
                   nodesVector.removeElement(nodesList.getSelectedValue());
                   this.nodesList.setListData(nodesVector);
                   NodePanel.nodesPresent = nodesVector;
                   updateStaticNodeList();
    /*************** as soon as the NodePanel.nodesPresent is updated, the changes are to be reflected in the Schedule Panel ******************/
                   VectorUpdateEvent e = new VectorUpdateEvent(this);
                   VectorUpdateEventIssuer v = new VectorUpdateEventIssuer();
                   v.addVectorUpdateEventListener(e);
                   v.notifyVectorUpdateEvent(this);
         ///////////////Data Members////////////////////
         private JButton addNodeButton;
         private JButton delNodeButton;
         private JButton dumpNodeButton;
         private JButton reloadNodeButton;
         private JButton browseButton;
         private JButton exitButton;
         private String desiredNode;
         private OneFieldDialog oneFieldDlg = null;
         private NoFieldDialog noFieldDlg = null;
         private JList nodesList;
         private Vector nodesVector;
         private Vector vectorNodeAttributes;
         private static Vector nodesPresent = null;
    } // end class NodePanel
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    ////////////////Class SchedulePanel////////////////
    class SchedulePanel extends JPanel
    implements ActionListener, ListSelectionListener, VectorUpdateListener
         ////////////////Constructors//////////////////
         public SchedulePanel()
              addScheduleButton = new JButton("Add Schedule");
              delScheduleButton = new JButton("Delete Schedule");
              dumpScheduleButton = new JButton("Dump Schedule");
              reloadScheduleButton = new JButton("Reload Schedule");
              browseScheduleButton = new JButton("Browse Schedule");
              exitButton = new JButton("Exit");
              add(addScheduleButton);
              add(delScheduleButton);
              add(dumpScheduleButton);
              add(reloadScheduleButton);
              add(browseScheduleButton);
              add(exitButton);
              setButtonsEnabled(false);
              addScheduleButton.addActionListener(this);
              delScheduleButton.addActionListener(this);
              dumpScheduleButton.addActionListener(this);
              reloadScheduleButton.addActionListener(this);
              browseScheduleButton.addActionListener(this);
              exitButton.addActionListener(this);
              scheduleVector = new Vector();
              scheduleList = new JList(scheduleVector);
              this.vectorScheduleOperations = new Vector();
              JScrollPane scrollPane = new JScrollPane(scheduleList);
              add(scrollPane);
              scheduleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              scheduleList.addListSelectionListener(this);
              //updateEventListener = new VectorUpdateEventIssuer();
              //updateEventListener.addVectorUpdateEventListener(this);
         /////////////Methods///////////////////////
         ////////////Event valueChanged/////////////
         public void valueChanged(ListSelectionEvent evt)
              JList source = (JList)evt.getSource();
              setButtonsEnabled(true);
              desiredSchedule = (String)source.getSelectedValue();
              if (desiredSchedule == null)
                   setButtonsEnabled(false);
         ////////////Event actionPerformed////////
         public void actionPerformed(ActionEvent evt)
              Object source = evt.getSource();
              if (source == addScheduleButton )
                   addScheduleButtonClicked();
              else if (source==delScheduleButton && desiredSchedule!=null)
                   deleteScheduleButtonClicked();
              else if (source == dumpScheduleButton && desiredSchedule!=null)
                   JFileChooser d = new JFileChooser();
                   d.setFileFilter(new XMLFilter());
                   int result = d.showSaveDialog(this);
              else if (source == reloadScheduleButton && desiredSchedule!=null)
                   JFileChooser d1 = new JFileChooser();
                   d1.setFileFilter(new XMLFilter());
                   int result = d1.showOpenDialog(this);
              else if (source == browseScheduleButton && desiredSchedule!=null)
                   browseScheduleButtonClicked();
              else if (source == exitButton)
                   System.exit(0);
         public void eventVectorUpdated(VectorUpdateEvent event)
              System.out.println("Hello! EventRaised");
         ///////////Data Members//////////////////
         private JButton addScheduleButton;
         private JButton delScheduleButton;
         private JButton dumpScheduleButton;
         private JButton reloadScheduleButton;
         private JButton browseScheduleButton;
         private JButton exitButton;
         private String desiredSchedule;
         private OneFieldDialog oneFieldDlg = null;
         private NoFieldDialog noFieldDlg = null;
         private JList scheduleList;
         private Vector scheduleVector;
         private Vector vectorScheduleOperations;
         private VectorUpdateEventIssuer updateEventListener;
    } // end class SchedulePanel
    I hope you understood my problem now. The NodeAttributes is a datastructure containing the node name and an associated table for that. THe ScheduleOperations is similar to the NodeAttributes but it contains a DefaultTableModel which inturn consists of a column which is filled with the list of current nodes available + their schedules.
    I am sorry for my long posting.
    Thanks once again in anticipation.

  • Custom Event for Purchase Requisition Create, Change & Delete

    Hello Experts,
    I want to create a custom event which triggers on Purchase Requisition Create, SAP provide's standard event's for purchase requisition release but not for create.
    What are all the steps and how to create a new event.
    Thanks in Adavance,
    Sandhya.

    Hi Sandhya,
    may i know the reason why you are trying to create custom methods.
    You have business object BUS2009(for PR line item wise release) and BUS2105(for PR overall release).
    Both those business object have events RELEASESTEPCREATED (for PR creation) and SIGNIFICANTLYCHANGED(For PR change).
    Even then if you want to create custom events, create a subtype of the standard business object, then click on events, and then select create. Now create your Z-events, say ZCREATED (For creation), ZCHANGED (for changed) and ZDELETED (for deleted). Now select each event, click on edit -> Change release status -> object type component -> to be implemented. Follow the same for all the events. Then select each event, click on edit -> Change release status -> object type component -> to be released.
    Now click on your custom object, click on edit -> Change release status -> object type component -> to be implemented.Then click on your custom object, click on edit -> Change release status -> object type component -> to be released.
    After this in SWEC tcode, click on new entries. Select change document object as BANF, business object as say ZBUS2105 and event as ZCREATED. make sure radio button on create is checked.
    Similary create entries for ZCHANGED event and ZDELETED.
    Select on change and on delete radio button for event ZCHANGED and ZDELETED event respectively.
    let me know if you have any queries.
    Regards,
    Raj

  • How does custom event listener work.

    Hi,
    With reference to Custom Event Listener, I wanted to know the behaviour of Custom Listener whether they are sync or async.
    For Example :
    Suppose i have a method1() which has the listener1() get invoked at some operation at line #1 of method();
    The task of listener1() takes 2 minutes aprox.
    Then my question is does method1() waits until listener1() finishes its task(2 Minutes) ?
    What is he default behavior of listner1()
    Can we change the default behavior of custom listners ?
    Thanks & Regards,

    jwenting wrote:
    rephrase your question in gramatically (and preferably syntactically) correct English so people can actually understand what you're asking.You took the words straight out of my mouth
    Mel

  • Custom Event and Custom Expression Deletion in PCW

    Hi Sap Gurus,
    How can i delete the custom event and custom expression created by me in process controlled workflow... I have observed the deletion button grayed out... Is there any other option to delete the custom event and expression.
    Thanks in advance

    Hello Sanjay,
    check below thread:
    BRF - Can not delete expression
    Regards.
    Laurent.

  • Creating a Custom Event Log View Shortcut on a server desktop for an admin

    Good morning,
    We have a new admin starting and I would like to create custom event log view shortcut on there desktop for each server they need to check. Is there a way to do this in Server 2012 and Server 2008?
     I have figured out how to create a shortcut of the Application and System log, but not Custom Views. Thanks.

    Hi,
    Based on my research, you can create a custom view like
    this.However, I tried miltiple ways to create a shortcut of the custom view of the event viewer and no result. I can only create a shortcut of the event viewer. You may need a script can achieve that.
    Best regards,
    Susie

  • Custom event - adding Document in message data

    Hi,
    I'm trying (without success) to add a document variable into the message data of a custom event.
    I have tryed to define in schema an element having no type, and then to put directly the document using the data mapping.
    All the process is working except the fact that the passed content (a form) cannot be  readen as passed.
    Do somebody have an advice to achieve that?
    Thanks for your help
    Denis

    Hi Bin Dong,
    here are some hints in addition to the info from Steffen:
    How to find the version of SAP MDM components related to your question:
    SAP MDM Data Manager -> click on About
    SAP MDM Console -> Help -> select About SAP MDM Console
    SAP MDM Server -> on installation machine, go to folder .../Server , and in e.g. Windows, select the file mds.exe and the properties of the file will show its  version.
    Please use the installation files you got from the same SP/patch/hotfix.
    MDM 5.5 SP4 is in monitored shipment, therefore if you work at a customer, you can ask your customer to upgrade to the latest available SP4 patch1 5.5.33.13.
    What I could find about the RC code 82030100 is nothing more than you mentioned "Unhandled Exception" ...
    Regards.
    Laszlo.

  • Custom Event In DMS

    Hi,
    I have a requirement where in a document need to be digitally signed/approved - parallelly ( say by 3 people - par for each).
    The object is DRAW and the method is EDIT. The terminating event for this step is event CHANGED.
    Now the problem is: when ever the first person signs the document this step gets completed with out others being able to sign.
    How can this problem be solved - should i create a custom event? Please explain in detail. Points Guaranteed !!!
    Regards,
    Venkat.

    Hi Venkat,
    <b>Workflow triggers here and routes it to 3 approvers.</b>
    From this i understand that you have three activity steps in parallel using a fork. Right? Or do u mean to say the same workitem has three agents and is delivered to three peoples inbox. If you are delivering the same work item to three inboxes there is no way that you can have it in other agents inboxes after being processed by one agent. In fact immediately after the first agent opens the workitem for processing it will disappear from the inbox of other agents.
    But <b>if you are using three steps in parallel under a fork.</b> Yes you can achieve this.
    <u><b>Section 1:</b></u>
    You have already created a ZEDIT method and made the method as synchronous. Hence you must have made the task also as synchronous (checkbox "Synchronous object method" checked). Now goto the "Terminating Events" tab of the task. If you still have the terminating event here just delete it. You will not need this as your workitem will get automatically completed when the BO method is executed once.
    Now assign this task to the three activities (for three agents) under the fork step. Now when a workitem is created for this task you will get the workitems in all three inboxes (These will be three individual workitems belonging to each activity inside the fork). Now each of these workitems are independent of each other and will not affect other workitems based on its own processing status.
    <u><b>
    Section 2:</b></u>
    If you have reached till above your approvers will be able to process the workitem independent of each other. Now again you will have a problem here. Once you have made your task as synchronous it just waits for the execution of the BO method and it does not know whether you have achieved the purpose of the method. In your case your objective is to edit the document. But if your approver executes the workitem once it will bring him to CV02N. Now assume he wants to edit the document later and he presses the "BACK" button. Your objective is not completed but still your BO method will get completed and hence terminate the workitem of that approver. To avoid this you need to get back the sy-ucomm value for BACK into your BO  method and write a few lines of code such that your workitem will not get terminated when BACK is pressed. This can be done using some BADI's available for this transaction.
    Thanks,
    Prasath N

  • Hiding a custom event in portal eventing

    Hi,
    Can anyone tell me how to hide the custom event in portal eventing?
    Regards
    MQ

    I too use the PopUpManager, but to load Modules and had
    similar event/data and data binding issues. I ran across this post
    and have been integrating it's methods into my original code.
    Perhaps a read might help you as well.
    http://clockobj.co.uk/2007/10/17/simplified-cairngorm-easy-mvc-for-adobe-flex/

  • Trying to make up a Modal Dialog with customized event dispatcher

    Hello everyone.
    I try to make up a ModalDialog class with customized event dispatcher in order to wait an invoker.
    But it fails :-(
    import javafx.event.ActionEvent;
    import javafx.event.Event;
    import javafx.event.EventDispatchChain;
    import javafx.event.EventHandler;
    import javafx.event.EventTarget;
    import javafx.event.EventType;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.HBox;
    import javafx.stage.Modality;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    import javafx.stage.Window;
    import javafx.stage.WindowEvent;
    import com.sun.javafx.stage.WindowEventDispatcher;
    import java.util.ArrayList;
    public class ModalDialog extends Stage {
      ArrayList<Button> buttons;
      int rc;
      Stage stage;
      Event event;
      EventDispatchChain tail;
      public ModalDialog( Window owner, String title ){
        initModality( Modality.APPLICATION_MODAL );
        initOwner( owner );
        initStyle( StageStyle.UTILITY );
        setTitle( title );
        stage = this;
      public void setContents( Group group, ArrayList<Button> buttons ){
        BorderPane root = new BorderPane();
        Scene scene = new Scene(root);
        setScene(scene);
        root.setCenter( group );
        this.buttons = buttons;
        HBox buttonPane = new HBox();
        buttonPane.setSpacing(10);
        for( int i=0 ; i<buttons.size() ; i++ ){
          buttons.get(i).setOnAction( actionHandler );
        buttonPane.getChildren().setAll( buttons );
        root.setBottom( buttonPane );
      public int show( double screenX, double screenY ){
        setX( screenX ); setY( screenY );
        show();
        MyWindowEventDispatcher dispatcher =  new MyWindowEventDispatcher( stage );
        setEventDispatcher( dispatcher );
        while(true){
          event = dispatcher.dispatchEvent( event, tail );
          EventType<? extends Event> type = event.getEventType();
          if( type==WindowEvent.WINDOW_HIDDEN ){
            break;
        return( rc );
      EventHandler<ActionEvent> actionHandler = new EventHandler<ActionEvent>() {
        public void handle( ActionEvent e ){
          EventTarget src = e.getTarget();
          rc = buttons.indexOf( src );
          stage.hide();
      class MyWindowEventDispatcher extends WindowEventDispatcher {
        public MyWindowEventDispatcher( Window window ){
          super( window );
        public Event dispatchEvent( Event event, EventDispatchChain tail) {
          ModalDialog.this.event = dispatchCapturingEvent( event );
          ModalDialog.this.tail = tail;
          return( event );
    }A sample code to invoke ModalDialog
    import java.util.ArrayList;
    import javax.swing.JOptionPane;
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.stage.Stage;
    import javafx.stage.WindowEvent;
    public class WindowEvent06 extends Application {
      Stage mainStage;
      public void start(Stage stage) throws Exception {
        Group root = new Group();
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("WindowEvent06");
        mainStage = stage;
        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
          public void handle(WindowEvent e){
            ModalDialog dialog = new ModalDialog( mainStage, "Question" );
            Button yes = new Button( "Yes" );
            Button no  = new Button( "No" );
            ArrayList<Button> buttons = new ArrayList<>();
            buttons.add(yes); buttons.add(no);
            Label msg = new Label( "Really Exit ?" );
            Group groupInDialog = new Group();
            groupInDialog.getChildren().add( msg );
            dialog.setContents( groupInDialog, buttons );
            int ans = dialog.show( 300, 300 );
            System.out.println("returned from a modal dialog");
            if( ans == 1 ){
              e.consume(); // this blocks window closing
        stage.show();
      public static void main(String[] args) {
        launch(args);
    }

    Hi,
    The logic what you follows is some what in the right direction but need to have some changes.
    What I would say is, first consume the windowClose event. Then open the dialog box and close the parent accordingly.
    So after refactoring your code.
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.HBox;
    import javafx.stage.Modality;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    public class ModalDialog extends Stage {
         Stage owner;
         Stage stage;
         BorderPane root;
      public ModalDialog( Stage owner, String title){
        root = new BorderPane();
        stage = this;
        this.owner = owner;
        initModality( Modality.APPLICATION_MODAL );
        initOwner( owner );
        initStyle( StageStyle.UTILITY );
        setTitle( title );
        setContents();
      public void setContents(){
        Scene scene = new Scene(root,150,150);
        setScene(scene);
        Group groupInDialog = new Group();
        groupInDialog.getChildren().add( new Label("Really Exit ?") );
        root.setCenter( groupInDialog );
        Button yes = new Button( "Yes" );
        yes.setOnAction(new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent paramT) {
                   stage.close(); // Closing the pop up.
                   owner.close(); // Closing the parent stage also.
        Button no  = new Button( "No" );
        no.setOnAction(new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent paramT) {
                   stage.close(); // Closing the pop up only
        HBox buttonPane = new HBox();
        buttonPane.setSpacing(10);
        buttonPane.getChildren().addAll(yes,no);
        root.setBottom(buttonPane);
        stage.show();
    }And the main class to check this implementation is
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.stage.Stage;
    import javafx.stage.WindowEvent;
    public class WindowEvent06 extends Application {
      public void start(final Stage stage) throws Exception {
        Group root = new Group();
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("WindowEvent06");
        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
          public void handle(final WindowEvent e){
             e.consume(); // Consuming the event by default.
             new ModalDialog( stage, "Question");
        stage.show();
      public static void main(String[] args) {
        launch(args);
    }I hope the above code will give you some idea what i mean. :)
    Happy Coding !!
    Regards,
    Sai Pradeep Dandem.
    Edited by: Sai Pradeep Dandem on Jan 20, 2012 4:03 AM

  • Custom event not traced in the SWEL transaction

    Hi Experts,
                In my development server I have created a custom BOR ZBUS2078 with few custom events and delegate it to the standard BOR BUS2078.
    I have moved the same to quality. But i could not find the trace for the custom events of ZBUS2078 unlike the standard events of BUS2078 in the SWEL transaction .
    However those custom events are getting triggered in my development server.
    I have checked the delegation and the custom BOR in the quality and they are same as in development server
    Object type : BUS2078
    Delegation type : ZBUS2078
    What could be the problem  and how to resolve it?
    Please provide your valuable solution and suggestions.
    Thanks in Advance.
    Regards
    K Arasu

    Issue resolved. I have maintained those custom events in SWEC in quality server.

Maybe you are looking for

  • Organizer keeps will not open?

    I have had PSE for  6 months and used it lots but a few weeks ago the organizer just stopped opening, i have to go in to Edit to open organizer and my photo thumbnails are not shown, just timmers, i have changed the name of the online services file i

  • To Define Business group in HRMS

    Hi, I am new to HRMS module. I like to know how to create a Business group If any one could share the "Oracle HRMS-The fundamantals" guide that would help me a lot Regards Ramesh Kumar S

  • Different Screens in ADOBE

    Dear all, I have a PDF file, in this PDF i have different screens in each page. Can we assign each screen as one view. Regards, Maruti

  • Safari crashing when I open tab?

    Everytime I try to open a tab in Safari, the browser begins to open up the normal "top sites" page it always does when you open up a new tab, but then the whole brower crashes about a second later.  I'm really annoyed because I like Safari much bette

  • Dump:Function module "/GRCPI/GRIA_SPM_SYNC" not found

    Hello Experts, When executing EAM Master Data Synch from GRC system, a short dump results with the description "/GRCPI/GRIA_SPM_SYNC" in Plugin system ( Basis 640 ).Plugin system is at latest patch level ( GRCPINW SP12 ).we found that no function mod