Difference: DpHipeTools (69 vs. 70)

Revision 702011-06-03 - JaimeSaiz

Line: 1 to 1
 
META TOPICPARENT name="WritingTasks"

Adding Tools to HIPE

Line: 438 to 438
 
Changed:
<
<

Simple sample

>
>

Example

 This simple reproducible example wraps up the just explained steps altogether.
It is just a button whose label is changed by the tool when the user clicks on it:
Line: 447 to 447
 
public class SimpleButtonTool extends AbstractTool {

Changed:
<
<
private ArrayData _data;
>
>
private ArrayData _data = null;
  private boolean _flag = true;

public SimpleButtonTool() {

Line: 459 to 459
  }

void updateLabel(JButton button) {

Added:
>
>
boolean hasData = _data = null; button.setEnabled(hasData); if (hasData) {
  int size = _data.getSize(); int rank = _data.getRank(); button.setText("Data has " + (_flag? "size " + size : "rank " + rank)); _flag = _flag;
Added:
>
>
} else { button.setText("No data selected"); }
  } }
Line: 477 to 483
  private static int _counter = 1; private SimpleButtonTool _tool;
Changed:
<
<
public SimpleButtonToolComponent() { super(new BorderLayout()); }

protected Class getSelectionType() {

>
>
protected Class<ToolSelection> getSelectionType() {
  return ToolSelection.class; }

protected boolean makeEditorContent() { final JButton button = new JButton(); setName("Button Tool " + _counter++);

Changed:
<
<
_tool = (SimpleButtonTool)getSelection().getTool(); _tool.setData((ArrayData)getSelection().getSelection().getValue());
>
>
ToolSelection toolSelection = getSelection(); _tool = (SimpleButtonTool)toolSelection.getTool(); Selection selection = toolSelection.getSelection(); if (selection = null) { _tool.setData((ArrayData)selection.getValue()); }
  _tool.updateLabel(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
 
This site is powered by the TWiki collaboration platform Powered by Perl