RE: [OpenMap Users] custom button actions / tooltip text on point data

From: Chris Hopkins <>
Date: Wed, 7 Jul 2004 15:59:51 -0400

Hi Ben -

> Question 1:
> What class should I look at to get an idea of how to create
> my own custom buttons with actions to do things? Basically what I want to

> do is extremely simple, just have a bunch of GIS icons like rivers,
> railroads, ... and allow the user to toggle them on or off by clicking
(instead of
> using the "Layers" menu).

I actually did this with my last project. The class that does this is
riddled with project specific stuff (I didn't do a good job generalizing
it). But, here is the approach I took (modified slightly so that it should
work a little better with OM4.6).

NOTE: If you want this to show up somewhere if you don't implement Tool,
you'll need to extend something like BasicMapPanel and deal with it in

1. Extend OMComponent and implement LayerListener, Tool
        - although implementing Tool may not be necessary with what you want
to do. If you want it to appear in the OMToolSet then implement Tool
2. Add a JToolbar member variable (e.g. private JToolbar toolBar)
3. if implementing Tool, getFace() of Tool returns the JToolbar (e.g. return
4. override findAndInit(Object ob)
        - if the ob passed instanceof LayerHandler, add this as a layer
5. in the setLayers method (from LayerListener)
        - if the getType() == LayerListener.ADD, add a new ToggleButton
instance (see below) to the JToolbar
        - you'll need to figure out a good way to associate the icon image
with the button
6. Add your component to the file

I haven't tested this approach under 4.6 but I think the idea is sound
according to the API. If I'm way off, I'm sure Don (or someone) will correct
me. ;)

  - Chris

This ToggleButton class will react to the layer being show/hidden through
other means as well and will turn on/off the layer when toggled.

  private class ToggleButton extends JToggleButton
      implements ComponentListener
    private Layer layer = null;
    ToggleButton(Layer layer)
      this.layer = layer;





    // ComponentListener methods

     * We don't care about resizing or moving
    public void componentResized(ComponentEvent e)

    public void componentMoved(ComponentEvent e)

     * This button listens to the status of its layer. If the
     * layer becomes visible, it makes the button toggled on
    public void componentShown(ComponentEvent e)
      if(e.getComponent() == layer && !isSelected())

     * This button listens to the status of its layer. If the
     * layer becomes invisible, it makes the button toggled off
    public void componentHidden(ComponentEvent e)
      if(e.getComponent() == layer && isSelected())

     * Triggered by the toggle button being clicked
     * _at_param e ActionEvent fired by the button.
    public void actionPerformed(ActionEvent e)
        System.err.println("Incorrect source");

      layerHandler.turnLayerOn(isSelected(), layer);

[To unsubscribe to this list send an email to ""
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Wed Jul 07 2004 - 16:00:48 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:05 EDT