Zoom & Pan Support problem

From: Rajesh G S <gsronline@yahoo.com>
Date: Mon Mar 04 2002 - 05:34:45 EST

Hi,

I have created a ToolBar class for my application to use in conjunction with
the map. But the map isnt responding to the button clicks. I am enclosing
the brief class structure:

Thanks in Advance

Rajesh

//MapHome.class
public class MapHome extends JFrame {
        //Declarations
        private MapBean _mapBean = null;
        private Layer _layers[] = null;
        private LegendPanel _legend = null;
        private LayerHandler _layerHandler = null;
        private MapToolBar _toolBar = null;
        private JMenuBar _menuBar = null;
        private MouseHandler _mouseDelegator = null; //Implementation of the
mouseDelegator class. it houses multiple modes.
                                                     //I dont know if there
exists an easier way

        private InformationDelegator _statusBar = null;

        //Constructor class
        public Kochi() {
                //Init MapBean
                _mapBean = new MapBean();
                _mapBean.setCenter(new LatLonPoint(-3.0f, 3.0f));
                _mapBean.setScale(2000000f);

                //Call the UInterface
                UInterface();
        }

        //loads the User interface
        private void UInterface() {
                //Mouse Delegator
                _mouseDelegator = new MouseHandler(_mapBean,
MouseHandler.naviMode);

                //Load Tool Bar
                _toolBar = new MapToolBar();
                _toolBar.addMouseHandler(_mouseDelegator);
                _toolBar.addTools();

                //Load Menu Bar

                //Load layers
                _layers = new Layer[5];
                _layers[0] = loadLayer("City Area","map/city");
                _layers[1] = loadLayer("Water bodies","map/wbody");
                _layers[2] = loadLayer("Railway line","map/railway");
                _layers[3] = loadLayer("Locations","map/places");
                _layers[4] = loadLayer("Locations","map/roads");
                _layerHandler = new LayerHandler(_layers);

                //Add Legend
                _legend = new LegendPanel(_layerHandler);
                _legend.setLayers(_layers);

                //Status Bar
                        ..

                //Layout Controls
                        ...
        }

        //Loads the layer on to the map.
        private EsriLayer loadLayer(String name, String filename) {
                //Load the ESRI layer
                File dbf = new File(filename + ".dbf");
                File shp = new File(filename + ".shp");
                File shx = new File(filename + ".shx");
                EsriLayer layer=null;
                try {
                        layer = new EsriLayer(name, dbf.toURL(),
shp.toURL(), shx.toURL());
                } catch (Exception exception) {
                            System.out.println("Couldnt Load:"+filename);
                }
                return (layer);
        }

        //Main function
        public static void main(String args[]) {
                MapHome _mapHome= new MapHome();
                _mapHome.setVisible(true);
        }
}
//:End

//MapToolBar.class
public class MapToolBar extends JToolBar {
      //Declarations
        private JButton
PointerButton,PanCenter,ZoomInButton,ZoomOutButton,FindButton,InfoButton,
                MeasureButton,HelpButton,PropButton,QuitButton;

        private CenterSupport centerDelegate;
        private PanSupport panDelegate;
        private ZoomSupport zoomDelegate;
        private MouseDelegator mouseDelegator = null;

        public MapToolBar() {
                centerDelegate = new CenterSupport(this);
                panDelegate = new PanSupport(this);
                zoomDelegate = new ZoomSupport(this);

                this.setBorder(BorderFactory.createEtchedBorder());
                this.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
        }

        public void addTools() {
                PointerButton = new JButton(ptrgif);
                PointerButton.setToolTipText("Map Pointer");
                PointerButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                float lat;
                                float lon;
                                lat =
Environment.getFloat(Environment.Latitude, 0f);
                                lon =
Environment.getFloat(Environment.Longitude, 0f);
                                System.out.println(Environment.Latitude);
                                fireCenterEvent(lat,lon);
                        }
                });

                //this.add(PointerButton);
                //this.addSeparator();
                //=====================================================
                PanCenter = new JButton(pangif);
                PanCenter.setToolTipText("Reset Map to Center");
                PanCenter.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                panDelegate.firePan(0f, 2f);
                        }
                });

                this.add(PanCenter);
                //this.addSeparator();
                //=====================================================
                //Zoom In button
                ZoomInButton = new JButton(zingif);
                ZoomInButton.setToolTipText("Zoom In");
                ZoomInButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                zoomDelegate.fireZoom(ZoomEvent.RELATIVE,
.5f);
                        }
                });

                //Zoom Out Button
                ZoomOutButton = new JButton(outgif);
                ZoomOutButton.setToolTipText("Zoom Out");
                ZoomOutButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                zoomDelegate.fireZoom(ZoomEvent.RELATIVE,
1.5f);
                        }
                });
                this.add(ZoomInButton);
                this.add(ZoomOutButton);

                this.addSeparator();

//==========================================================================
=======================
                FindButton = new JButton(fndgif);
                FindButton.setToolTipText("Find..");

                InfoButton = new JButton(nfogif);
                InfoButton.setToolTipText("More Information");
                InfoButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                if (mouseDelegator == null)
System.out.println("This is null");

mouseDelegator.setActiveMouseModeWithID(MouseHandler.seleMode);
                        }
                });
                MeasureButton = new JButton(msrgif);
                MeasureButton.setToolTipText("Measure");
                MeasureButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {

mouseDelegator.setActiveMouseModeWithID(MouseHandler.distMode);
                        }
                });
                this.add(FindButton);
                this.add(InfoButton);
                this.add(MeasureButton);

                this.addSeparator();

//==========================================================================
=======================
                PropButton = new JButton(prpgif);
                this.add(PropButton);
                PropButton.setToolTipText("Settings..");
                HelpButton = new JButton(abtgif);
                HelpButton.setToolTipText("About..");
                this.add(HelpButton);

                this.addSeparator();

//==========================================================================
=======================

                QuitButton = new JButton(xitgif);
                QuitButton.setToolTipText("close Application");
                QuitButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                System.exit(0);
                        }
                });
                this.add(QuitButton);
        }

        private void fireCenterEvent(float lat, float lon) {
                centerDelegate.fireCenter(lat,lon);
        }

        public void addMouseHandler(MouseHandler md) {
                MapBean objMap = md.getMapBean();

                panDelegate.addPanListener((PanListener)objMap);
                centerDelegate.addCenterListener((CenterListener)objMap);
                zoomDelegate.addZoomListener((ZoomListener)objMap);
                mouseDelegator = md;
        }
}

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Mon Mar 4 05:35:49 2002

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:32 EDT