Guess I was feeling lazy when I wrote menuRemoveItem...it's an easy fix.
The array.splice(indexToStart, numberOfElements) function is perfect for
it. Now fixed; see the new method below.

menuRemoveItem: function(menu, index) {
if(index >= 0 && index < menu.items.length)
menu.items.splice(index, 1);
}

I see what you mean about the action listener, Bob. Shouldn't be too tough
to make that happen. Thanks for the debugCode tip; should be easier to get
a handle on that now as well. Finally, feel free to copy over any or all of
my code to the "official" JSmol code (probably don't have to tell you
that... :D).

Cheers, Mike

---
Michael Evans
Organic Chemistry Graduate Student, Moore Group
University of Illinois, Urbana-Champaign


On Wed, Dec 19, 2012 at 3:05 PM, Robert Hanson <[email protected]> wrote:

> Wow, this is great! Almost there, I think.
>
>
> On Wed, Dec 19, 2012 at 12:48 PM, Michael Evans <[email protected]>wrote:
>
>> Bob et al.,
>> Progress has been made on a popup menu for JSmol. I've implemented
>> PopupMenu, MenuItem, CheckboxMenuItem, and RadioButtonMenuItem, among other
>> things. Check it out:
>>
>> http://www.metallacycle.com/play/netmol/tests/popupMenu/jmolPopupMenu.js
>>
>>
> OK! You are way ahead of me!
>
>
>
>> The demo is still functional as well:
>>
>> http://www.metallacycle.com/play/netmol/tests/popupMenu/popupMenu.html
>>
>> Two things I'm struggling with:
>> 1) What's the difference between a ButtonGroup and a set of
>> RadioButtonMenuItems?
>>
>
> I think it's the same. I think really in JavaScript it's just a set of
> radio buttons with the same name. Be sure to use
>
> applet._id
>
> as a prefix to every name or id so that multiple applets on a page do not
> have the same name or id for anything.
>
>
>
>> 2) Event handling in general. For example, a checkbox menu item doesn't
>> "know" its parent, so when it's clicked, it can't run commands on its
>> parent applet without bubbling an event up to its parent jmol object. I
>> will continue to work on this, but event handling in JS is not one of my
>> specialties. I'll look into custom events mediated by jQuery, but in the
>> meantime, if there are any JS event experts out there, help would be
>> appreciated! :-)
>>
>
> Actually, it does. What you are missing is that when a checkbox is
> created, the following command sequence is run:
>
>     /**
>      * @j2sNative
>      *
>      *      if (isRadio) {
>      *        item = new Jmol.Menu.RadioButtonMenuItem(entry);
>      *        item.setArmed(state);
>      *      } else {
>      *        item = new Jmol.Menu.CheckBoxMenuItem(entry);
>      *        item.setState(state);
>      *      }
>      *      item.setSelected(state);
>      *      item.addItemListener(this);
>      *
>      */
>
> So that "addItemListener" is giving the checkbox a reference to the
> instance of org.jmol.awt2d.JSPopup that created it. Store that as jmolPopup
> in the item. Then:
>
>  xxxx.jmolPopup.checkBoxStateChanged(xxxx);
>
> Similarly, all normal menu items have:
>
>     /**
>      * @j2sNative
>      *
>      *      item = new Jmol.Menu.MenuItem(entry);
>      *      item.addActionListener(this);
>      *
>      */
>
> (notice "Action" here, not "Item")
> This is going to respond to clicks:
>
> xxxx.jmolPopup.checkMenuClick(xxxx, xxxx.getActionCommand());
>
>
> where getActionCommand() returns "background yellow"  should take care of
> it.
>
> Finally, there are a few items that are special and start with "Focus".
> These also get a mouse listener so that we can track when they are entered
> and exited:
>
>        /**
>         * @j2sNative
>         *    if (id != null && id.startsWith("Focus")) {
>         *      item.addMouseListener(this);
>         *      id = menu.getName() + "." + id;
>         *    }
>         *    item.setName(id == null ? menu.getName() + "." : id);
>         */
>
> Then that needs to be set up so that we can run:
>
>    item.jmolPopup.checkMenuFocus(item.getName(), item.getActionCommand(),
> true);
>    item.jmolPopup.checkMenuFocus(item.getName(), item.getActionCommand(),
> false);
>
> And we should be done!
>
>
> By the way, your comment there that it should be OK to use a null instead
> of removing an item is not right. This could happen extensively, and we
> need to actually remove that array element.
>
> Bob
>
>
> --
> Robert M. Hanson
> Larson-Anderson Professor of Chemistry
> Chair, Chemistry Department
> St. Olaf College
> Northfield, MN
> http://www.stolaf.edu/people/hansonr
>
>
> If nature does not answer first what we want,
> it is better to take what answer we get.
>
> -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
>
>
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> Jmol-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>
>
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to