ALOV logo

DOCUMENTATION

As mentioned above you may define the applet appearance via layout file. Moreover you may create and add your own components and controls to the applet. It allows you to customize the applet behaviour as you please.

There are four interfaces that allows your class to handle applet and map events. All of them are in package org.alov.map.

CarteHostListener.java This interface has two methods which are being invoked on starting and stopping of applet.

public void setParameters(CarteHost host, XmlElement layout) This method is being called when applet loads the layout file. Straight after the creation of instance of your class.

For example, you declare your class in the layout file:

<object class="MyControl" colour_for_small_fonts="255:0:0" some_other_property="bla bla" is_active="yes" image_icon="myicon.gif"/>

In this method you are able to read the values of attributes you described for this object.

public void setParameters(CarteHost host, XmlElement layout){ Color selectionColor = XmlUtils.getColor("colour_for_small_fonts", layout, Color.blue); my_property = XmlUtils.getString("some_other_property", layout,"default bla bla"); isActive = XmlUtils.getBoolean("isactive", layout, true); myimage = host.getImage(XmlUtils.getString("image_icon",layout,null)); //adds this class to list of StatusListener and CarteListener implemetations Carte map = host.getMapByName(layout); map.mapListeners.addElement(this); map.statusListeners.addElement(this); }

Note: if your class is descendant of AWT visual component (label, panel, button etc) you may skip reading the following properties that defines its appearance:

name, caption, bounds, backcolor, forecolor, align, font.

These values are loaded and assigned by default.

If your class is the implementation of interfaces StatusListener or CarteListener you have to add it to the lists of implementation explicitly.

Carte map = host.getMapByName(layout); map.mapListeners.addElement(this); map.statusListeners.addElement(this);

public void stop() This method is being invoked on applet's stop. Use this method to free your resources and perform some finalization operations.

CarteAttribute.java This interface has the only method

public void showAttributes(LayerVector lyr, Vector records); It is being called to show the attribute data, after searching or for selected objects.

StatusListener.java use this interface to handle map events such as changing of map extent or thematic map, start and stop the networking. There are two methods for this interface

public void afterProjectLoaded(boolean bSuccess); This method is being called straight after map loading and parsing of the project file. Utilize this method to initialize the instance of your class and assign the action handlers for its child controls.

For example your component is a descendant of panel (java.awt.Panel). It has a button with name "Hide_cities".

<object class="org.alov.addon.MyCustomPanel"/> <object name="hide_cities" type="button" bounds="5,2,60,23"/> </object>

If you wish to set its caption according to the title of layer "Cities" and assign Action Listener.

public void afterProjectLoaded( boolean bSuccess ) { if ( bSuccess ) { //find button with name Hide_cities Button btn = (Button)MapUtils.findComp( (Container)this, "hide cities"); //it is assumed that you have a variable map that you get in //setParameters method map =host.getMapByName(layout); //find layer by unique name Layer layer = map.getProject().getLayerById("Cities"); //assign title of layer to caption of button btn.setLabel(layer.getName()); //set action listeners MapUtils.addActionListener( this, this, "hide cities"); } }

public void notifyStatus(int code, Object obj); It is invoked when internal map event occurs. It may be: the changing of active layer, thematic map, setting the domain extent, selection of objects on map, start and stop of data downloading. The parameter code is an identifier of map event. The parameter obj depends on event. Please refer to API documentation for detail description of events identifiers.

CarteListener.java. This interface has three method that allows you to handle map mouse events

public void mouseMapPressed(MouseEvent e);
public void mouseMapReleased(FloatRectangle selRect, MouseEvent e);
public void mouseMapMoved(MouseEvent e);

Besides, there is method which is being called after map repaint. This is the place where you can write your code to modify final map image.

public void afterMapDraw(Graphics g);


To declare your component in the layout file, set the value of the attribute "class". Class name is the name of Java class. For example

<object class="MyPanel" .... >

or if class MyPanel in the package

<object class="com.xyz.mycontrols.MyPanel" .... >

In the same XML element you may declare the attributes. If you class is the implementation of CarteHostListener interface, their values may be read in setParameter method. In layout file:

<object class="MyPanel" myproperty="bla bla" ... >

In setParameters

my_property = XmlUtils.getString("myproperty",layout,"default bla") ;

You may define more complex XML structure for your class.

<object class="MyPanel" .. > <image name="select" url="select.gif"/> <image name="alarm" url="alarm.gif"/> <image name="warning" url="warning.gif"/> </object>

in setParameters

Vector nodes = layout.getElementsByTagName("image"); int count = nodes.size(); for(int i=0; i<count; i++) { XmlElement el = (XmlElement)nodes.elementAt(i); String sName = XmlUtils.getString("name",el,null); String sFile = XmlUtils.getString("url",el,null); if((sFile!=null)&&(sName)) { Image img = host.getImage(sFile); if(img!=null){ myimages.put(sName, img); } } }

If your class is descendant of java.awt.Container, you may define other controls that will be placed on your component.

<object class="MyAtttributeDataDialogue"> <object type="panel" bounds="0,0,180,30" align="top"> <object type="panel" bounds="0,0,380,30" align="client"> <object name="lbl_recno" type="label" bounds="2,5,50,23" align="left"/> <object name="btn_onmap" type="button" caption="On Map" bounds="52,2,60,23" align="left"/> <object name="btn_weblink" type="button" caption="Link" bounds="115,2,60,23" align="left"/> <object name="lbl_weblink" type="label" bounds="175,5,550,23" align="left"/> </object> </object> <object class="org.alov.viewer.LightGrid" bounds="0,30,180,30" align="client"/> </object>

If you develop a class which is the descendant of java.awt.Frame, try our FrameAlign class. This class has a alignment feature that utilizes the values of attribute "align" declared in the layout file. Of course you are free to use standard Java layout classes.


After compilation of your class you have to copy Java class file into applet codebase or include it into alov_applet.jar.

Download FrameSearch.java. It defines custom search dialogue. You may utilize as a start point for your own development.

previous  top


© ALOV 2002-2005 contact6 at alov.org