Results 1 to 7 of 7
  1. #1
    Digital Larry is offline Member
    Join Date
    Mar 2013
    Posts
    49
    Rep Power
    0

    Default Keeping track of "child" dialogs.

    I've written a CAD program which has an internally defined concept of CAD "blocks" which are NOT Swing JComponents or anything else Swing like. When you right-click on a CAD Block, I pop up a block-type-specific control panel which IS a Swing JComponent. This has controls which let you set the parameters which are specific to that CAD Block.

    So each of these has two classes.
    #1 The CAD Block itself
    #2 the control panel which communicates with the CAD Block via setters and getters.

    All great so far.

    My issue is that the CAD Block doesn't keep track of the control panel. So it's possible to open multiple control panels rather than bringing the original one to the foreground if it is still open. Also, if you have a control panel open and delete the block, the control panel should also get deleted, but it doesn't.

    Any suggestions for how to manage this? Many thanks.

    DL

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default Re: Keeping track of "child" dialogs.

    Without seeing an SSCCE, it's pretty hard to give you any suggestions. What's stopping you from simply having the cad block keep track of the control panel?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Digital Larry is offline Member
    Join Date
    Mar 2013
    Posts
    49
    Rep Power
    0

    Default Re: Keeping track of "child" dialogs.

    Well, let's see. Maybe if I just talk it through the answer will leap out at me.

    Here's how I access the control panel from a right mouse click:

    else if (arg0.getButton() == 3) { // right button
    b.editBlock();
    }
    and then here's an example of the function call to create the control panel from within the CAD Block ("b" above):

    public void editBlock(){
    new BiQuadControlPanel(this);
    }
    so obviously at this point I'm not even trying to keep track of already having created one.

    Tell me if this makes sense.

    #1 I need to maintain a variable in the CAD block which is the "handle" of the control panel. This is initialized to null.
    #2 Upon right click on a given CAD block, I check to see if this handle is null.
    #3 If it's null, then create a new one. Otherwise, set focus to the existing one and put it on top. (I don't know the Swing calls to do this, but sure I can find them)...
    #4 Trap the exit handler for the control panel to call back to the CAD block to reset the handle to null.
    #5 As part of the CAD Block's delete method, be sure to delete the control panel if it exists.

    Sounds good to me. I will try it. Thanks! (sorry I don't get out much and some times it helps just to talk these things through)...

    [Edit:]
    Right now my Control Panels are just JFrames. Looks like I'll need to create a new class extending JFrame which includes a method to link back to a calling CAD block's "resetControlPanelHandle()" method.

    I'll give this a shot and if I paint myself into a corner will return for help.
    Last edited by Digital Larry; 08-08-2013 at 04:23 PM.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default Re: Keeping track of "child" dialogs.

    Makes sense to me. Sometimes all we need is a rubber duck: Coding Horror: Rubber Duck Problem Solving
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: Keeping track of "child" dialogs.

    Is your CADBlock your model?
    In other words, is it (essentially) unrelated to the GUI, and something you might choose to persist?

    If so, do not put the handle to the GUI part in there.
    Have the GUI (somewhere) maintain a Map of CADBlock to popup.
    When the editBlock occurs have it reference this Map and grab a popup if there is one alreay in existence for that CADBlock.
    If one does not exist then create it and add it to the Map.

    This is similar to your setup but removes the link inside your model to the GUI.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Digital Larry is offline Member
    Join Date
    Mar 2013
    Posts
    49
    Rep Power
    0

    Default Re: Keeping track of "child" dialogs.

    Hi Tolls, that's an interesting idea. You are correct, though the CAD Block is not the entire model, it's just part of it. Within a model there could be several of the same type of CAD Block. Does this matter, to your suggestion? I do also keep track of the block's sequence number internally, so this could be unambiguous. That is, until I sort the model...

    Also, when a given model is retrieved from a file, the Map should be emptied. So the state of any control panels is not important to persist.
    Last edited by Digital Larry; 08-08-2013 at 04:44 PM.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: Keeping track of "child" dialogs.

    OK, so then yes, I would go with some form of Map in the GUI, so that your model remains detached from it.

    The existence of lots of the same type of thing shouldn't matter, so long as there is a way for you to identify one from the other so you can Map a block to a panel.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  2. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  3. Replies: 1
    Last Post: 07-27-2012, 08:41 AM
  4. how to create a "child" frame.
    By Shellback3 in forum AWT / Swing
    Replies: 4
    Last Post: 02-02-2011, 04:48 AM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •