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:
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:
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".
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
or if class MyPanel in the package
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:
You may define more complex XML structure for your class.
in setParameters
Vector nodes = layout.getElementsByTagName("image");
int count = nodes.size();
for(int i=0; i
If your class is descendant of java.awt.Container, you may define other controls that will be placed on your component.
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.