Re: [OpenMap Users] add JButton in a layer

From: Mike Lackey <mr.blutarski_at_gmail.com>
Date: Thu, 25 Sep 2008 09:15:51 -0500

Hello Ruben,

Here is ome sample code for creating an icon image to be drawn on the
map. A bitmap image might be similar.

Mike

/**
 * a base class for all icon-type images
 */
public class IconObject extends GraphicObject
{
     // the icon for this object
    protected OMScalingIcon omIcon = null;

    /**
     * create an image icon
     */
    protected void init (float lat, float lon, String fileName) throws
GraphicException
    {
        if (fileName == null)
        {
            throw new GraphicException ("PointObject: null filename");
        }
        ImageIcon imageIcon = new ImageIcon(fileName);
        if (imageIcon == null)
        {
            throw new GraphicException ("PointObject: null ImageIcon");
        }
        omIcon = new OMScalingIcon(lat, lon, imageIcon);
        if (omIcon == null)
        {
            throw new GraphicException ("PointObject: null OMScalingIcon");
        }

        ConfigApi cfgApi = new ConfigApi(App.getInstance().getConfigData());
        omIcon.setMinScale(cfgApi.getIconMinScale()); //icon will
be scaled (smaller) until map scale <= this value
        omIcon.setMaxScale(cfgApi.getIconMaxScale()); //icon will
be scaled (larger) until map scale >= value
        omIcon.setBaseScale(cfgApi.getIconBaseScale()); //at map
scale of 1:500,000 the icon will appear full size

        omIcon.setSelectPaint(Color.red);
    }

    <snip>
}



On Thu, Sep 25, 2008 at 8:32 AM, Ruben DF <rdocasalf_at_yahoo.es> wrote:
> Thanks Don and Chris by your answers.
>
> Don, You mentioned that it could extend from RenderPolicy, it is an
> interface...you mean that i have to create a class that implements that
> interface? (like standardRenderPolicy). I've seen at DemoLayer class the
> following code:
>
> public void paint(java.awt.Graphics g) {
> // Super calls the RenderPolicy that makes decisions on how to
> // paint the OMGraphicList. The only reason we have this
> // method overridden is to paint the legend if it exists.
> super.paint(g);
> if (legend != null) {
> legend.paint(g);
> }
> }
> I've seen that legend (JPanel component) is always null, if I initialize and
> adding a Swing component (Example, legend.add(new JButton("hello")); and
> execute legend.paint(g) this is not shown in the layer...
>
> How can I paint the Swing components?. If I put layer.getGUI.paints(g) it
> does not appear anything about the Swing components. And there is not a
> setGUI...so...how can I add swing components to the layer in order to paint
> it after of that?
>
> I also modified the code of paint at StandardRenderPolicy adding this:
> layer.getGUI().paintAll(g) but there was not success... :(
>
> Chris, How can I put a image like a OMGraphics? I was trying with OMBitmap,
> but it is not refered to a window bitmap...Thanks a lot
>
> I don't know what i'm doing wrong... I'd appreciate an example of code of
> this please. It's very important for me. Thank you very much
>
> Best regards
>
>
>
>
> --- El mié, 24/9/08, Don Dietrick <dietrick_at_bbn.com> escribió:
>
> De: Don Dietrick <dietrick_at_bbn.com>
> Asunto: Re: [OpenMap Users] add JButton in a layer
> Para: "Ruben DF" <rdocasalf_at_yahoo.es>, "Christopher Franklin"
> <christopher.franklin_at_lmco.com>
> CC: "OpenMapUsers questions" <openmap-users_at_bbn.com>
> Fecha: miércoles, 24 septiembre, 2008 8:20
>
> The thing that makes this not-so-obvious is that OpenMap layers
> override the paint() method so that the
> com.bbn.openmap.layer.policy.RenderPolicy object handles the rendering
> of the OMGraphicList, instead of using the paint(...) method hierarchy
> of the Swing ancestry.
>
> The easiest thing to do is extend a RenderPolicy class and set that on
> your layer. You'll probably want the
> RenderPolicy object to call
> paintAll(java.awt.Graphics) on the layer. In addition to painting the
> OMGraphicList.
>
> RenderPolicy object can be set in the layer's constructor, or you can
> set it in the properties, too.
>
> Hope this helps,
>
> Don
>
> On Sep 24, 2008, at 1:03 PM, Christopher Franklin wrote:
>
>> Ruben,
>>
>> Someone can correct me if I am wrong but I don't think it is
>> possible to embed Swing objects inside the Openmap bean. I do know
>> for a fact that you can embed the openmap bean into a Swing
>> container along with your button and link the functionality but it
>> sounds like you really want the button as part of the map itself. If
>> this is the case the only way I can think of to do this is to create
>> an image to represent your button and to place this image into a
>> layer as an OMGraphic. You can then hook in a mouse listener to the
>
>> OMGraphic and interpret the clicks as you see fit. I hope one of
>> these two solutions will work for you!
>>
>> Chris
>>
>> Ruben DF wrote:
>>>
>>> Hi,
>>>
>>> How can I add a Jbutton in the layer? I tried with this
>>> unsuccessfully (JButton does not appear in the layer)
>>>
>>> JButton jb = new JButton("hello");
>>> jb.setLocation(100,100);
>>> myLayer.add(jb);
>>>
>>> I also tried passing the Jbutton in OMGraphicList.add(JButton) but
>>> it is not correct because add is expecting a OMGraphic...
>>>
>>> Is there any way to convert JButton to OMGraphic?
>>>
>>> Thanks in advance
>>> Best regards
>>>
>>>
>>
>
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Don Dietrick, dietrick_at_bbn.com
> BBN Technologies, Cambridge
> MA
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
>
>
> --
> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]
>
>

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu Sep 25 2008 - 10:16:09 EDT

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