|
|||||||||
| PREV NEXT | FRAMES NO FRAMES | ||||||||
See:
Description
Welcome to TangoATK.
This document does assumes some prior knowledge:
Attributes and commands need to be stored somewhere, and for that we
have supplied the AttributeList and
the CommandList. These objects take the name of a
command or attribute, fetch them and store them.
setModel method on a view with the model you want to
connect to it as argument:
INumberScalar model;
SimpleScalarViewer viewer;
AttributeList list;
list = new AttributeList();
// initialize the model and the viewer, more on that later...
model = (INumberScalar)list.add("my/device/name/numberscalar");
// connect them
viewer.setModel(model);
Normally the setModel method in a viewer takes care of
adding the viewer to the list of listeners of the model.
$ export CLASSPATH=$TANGO/lib/java/TangORB.jar:$TANGO/lib/java/ATKCore.jar:$TANGO/lib/java/ATKWidget.jarIt is also worth noting that TangoATK is for the moment made with and for jdk1.4, but we invite you to use jdk1.5 today because future releases of ATK will be built with jdk1.5 and might be incompatible with jdk1.4. So you better fetch that from http://java.sun.com/ while you're at it.
import fr.esrf.TangoATK.Core.*;
public class FirstExample {
public static void main (String[] args) {
AttributeList list = new AttributeList();
IAttribute attribute;
// add an attribute to the list
// AttributeList returs the last attribute added as an
// IEntity, so we need to cast it to an IAttribute.
// The AttributeList can throw a ConnectionException if
// it is not treated nicely, so you need to catch that.
try {
attribute = (IAttribute)list.add("eas/test-api/1/Short_attr");
System.out.println("Attribute " + attribute + " added OK");
} catch (ConnectionException connEx) {
System.out.println("Failed to add attributes");
} // end of try-catch
} // end of main ()
}
AttributeList and CommandList also accept wildcard-entries and
String-arrays as arguments to their add methods.
import fr.esrf.TangoATK.Core.AttributeList;
import fr.esrf.TangoATK.Core.INumberScalar;
import fr.esrf.TangoATK.Core.ConnectionException;
import fr.esrf.TangoATK.Widget.attribute.SimpleScalarViewer;
import javax.swing.JFrame;
public class SecondExample {
public static void main (String[] args) {
AttributeList list = new AttributeList();
SimpleScalarViewer viewer = new SimpleScalarViewer();
INumberScalar attribute ;
try {
// This time we need to know what kind of attribute AttributeList
// returns. By prior knowledge, I know that the attribute
// I'm adding is some sort of a numeric scalar, and therefore
// I treat it as a INumberScalar, since all numeric scalars are
// INumberScalars.
attribute = (INumberScalar)list.add("eas/test-api/1/Att_sinus");
// This is the fun part. Here my viewer is informed of who
// its model is. The viewer then connects itself to the model,
// and things start to happen.
viewer.setModel(attribute);
// Another fun part of the AttributeList is that it has a
// refreshing mechanism, which automagically refreshes any
// attributes in the list and makes them send out events.
list.startRefresher();
// Boring old swing stuff, add the viewer to a frames content-
// pane and have the frame show itself.
javax.swing.JFrame frame = new javax.swing.JFrame();
frame.getContentPane().add(viewer);
frame.pack();
frame.show();
} catch (ConnectionException e) {
System.out.println("Couldn't add attribute: " + e);
} // end of try-catch
}
}
|
|||||||||
| PREV NEXT | FRAMES NO FRAMES | ||||||||