Arc Dockable Window
This practical we'll get our crime analysis toolbar to output its results to a dockable window.
First of all, open up last practical's project in Eclipse. We'll start by adding in a dockable window, and testing that.
Go to the config.xml form, and add a Dockable Window addin. Set it up as below. (Note that we haven't set the neighbor - this doesn't especially seem to help, and you can't get rid of it once you've set it to something).
Then generate the class. Set the package to uk.ac.leeds.geog.pgiaas
as above.
Next we'll set up our DockableWindow so it shows something.
First, make a class-level instance variable JTextArea textArea = new JTextArea();
(you'll need to import javax.swing.*
).
Next add the following code to the createUI()
method (you'll need to import java.awt.*
):
JPanel jPanel = new JPanel();
(Remove the
jPanel.setLayout(new BorderLayout());
jPanel.add(textArea, BorderLayout.NORTH);
textArea.setText("Hello World");
return jPanel;
return null
)
This createUI()
method needs to
return a GUI container that will be shown in the DockableWindow (here we're returning a JPanel). One thing to get your
head round slightly at this stage is that the class we're writing isn't actually the
DockableWindow, but a class that Arc wraps a proper DockableWindow around, and is used for setting the proper DockableWindow up. This doesn't usually matter
(we'll see an example in a bit where it does), however, this will hopefully explain why
we don't actually set up the GUI for
In addition, add the following method which we'll use later to change the textArea text:
public void setText(String text) {
textArea.setText(text);
}
The next thing we have to do is get our button to show the DockableWindow.
First, open up your RiskButton
code, and make the following class-level instance
variable:
private IDockableWindow docWin = null;
Then alter the RiskButton
init
method so it looks like the code below.
This gets hold of the DockableWindow that Arc generates from the class above and attaches the instance
variable label docWin
to it.
public void init (IApplication app) { this.app = app; try{ IDockableWindowManager dwm = new IDockableWindowManagerProxy(app); UID uid = new UID(); uid.setValue("uk.ac.leeds.geog.pgiaas.RiskOutput"); docWin = dwm.getDockableWindow(uid); docWin.show(false); } catch (Exception e){ JOptionPane.showMessageDialog(null, "ex3: " + e.getMessage()); } }
Play close attention to this and think about what it is doing. We'll come back to it.
Finally, at the end of your button's onClick
method, add the following
as the last thing it does:
if (docWin != null) {
docWin.show(true);
}
We should now be able to export the addin, as we did last practical, but see a new dockable window appear when we run it.
When you've got that working, go on to Part Two where we'll try and dump our results onto this new dockable window.