Belongs to following categories: Extension, ULC5.2, ULC6.1, ULC6.2,
Project Home
Downloads
LinkSupport
Implements widgets that provide the look & feel of HTML links. Is
useful when your ULC application needs to conform to a HTML style
guide.Two widgets are implemented:
- Link label
- Link table: supports renderes that return link labels as
renderer components
Other widgets can be implemented in a similar way, e.g. link list, link
table tree. The sample application shows the possibilities for rendering
lanels as links and also serves as an example of how to use the API of
this extension.
Below is a screenshot of the sample application. The
LinkSupport Label section shows a ULC Label that is rendered as
link. A mouse click will trigger a server-side event.
The same behaviour is implemented for the labels in the first
column of the table.
Resources
How to use link labels
Create the link label and add an action listener.
ULCLinkLabel linkLabel = new ULCLinkLabel("test");
linkLabel.addActionListener(new IActionListener() { public void actionPerformed(ActionEvent event) {
String message = "Label clicked.";
ULCAlert alert = new ULCAlert("Action", message, "OK");
alert.setMessageType(ULCAlert.INFORMATION_MESSAGE);
alert.show();
}});
How to use link tables
Create the link table, set a renderer that returns link labels as
renderer components and add an action listener.
final ULCLinkTable linkTable = new ULCLinkTable(new SampleTableModel());
linkTable.getColumnModel().getColumn(0).setCellRenderer(new LinkCellRenderer());linkTable.addActionListener(new IActionListener() {
public void actionPerformed(ActionEvent event) {
String message = "Table row " + linkTable.getSelectedRow() + " clicked.";
ULCAlert alert = new ULCAlert("Action", message, "OK");
alert.setMessageType(ULCAlert.INFORMATION_MESSAGE);
alert.show();
}});
How it is implemented
The solution chosen adds a mouse listener to the client-side widget that
sends an action event to the server-side when a mouse button is pressed.
Moreover, a mouse motion listener is added to display a hand cursor when
the mouse pointer is over a link widget.
Add the listeners client-side
We add the listener to the basic component in the restoreState() method.
The restoreState() method is invoked by the ULC framework for each
created client-side proxy. The getBasicComponent() returns the Swing
component the proxy stands for, i.e. a JLabel / JTable in our case.
public void restoreState(Anything args) {
super.restoreState(args); getBasicComponent().addMouseListener(new ActionHandler());
getBasicComponent().addMouseMotionListener(new ActionHandler());}
Send the action event to the server-side
An action event is sent to the server-side only when the user presses a
mouse button over the link.
private class ActionHandler extends MouseAdapter implements MouseMotionListener { … public void mousePressed(MouseEvent event) { if (isOverLink(event.getPoint())) {
sendOptionalEventULC(IUlcEventConstants.ACTION_EVENT, IUlcEventConstants.ACTION_PERFORMED);
}
} private boolean isOverLink(Point point) {
Dimension preferredSize = getBasicComponent().getPreferredSize();
return point.x < preferredSize.width && point.y < preferredSize.height;
}}
Change the cursor to give feedback
The cursor is changed to the hand cursor whenever the mouse pointer is
over a link.
private class ActionHandler extends MouseAdapter implements MouseMotionListener {
public void mouseMoved(MouseEvent event) { if (isOverLink(event.getPoint())) {
getBasicComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
} else {
getBasicComponent().setCursor(null);
}
} ...}
Compatibility
- ULC 5.2: JDK 1.4.2, JDK 1.5
- ULC 6.1: JDK 1.4.2, JDK 1.5
- ULC 6.2: JDK 1.4.2, JDK 1.5, JDK 1.6, Windows XP, Windows
Vista, Linux, Mac OSX Tiger
Change Log
- 1.0: First version compatible with ULC 5.2
- 2.0: Second version compatible with ULC 6.1.1