Java Reference
In-Depth Information
context
g2D.setXORMode(getBackground()); // Set XOR mode
}
}
Directory "Sketcher 5 displaying a font dialog"
You obtain a reference to the JPopupMenu object from the application window object, which you access
via the application object reference that is stored in the view. You then call the show() method for the
pop-up menu object, passing a reference to the source of the event as the parent.
This is one of the rare occasions when you want to reference the outer class object from an inner class.
As you know, you use the keyword this to refer to the current class object, so here this references the
MouseHandler object. To reference the outer class object from an inner class object you qualify this
with the class name, so here you use SketcherView.this .
The cursor position is the point stored in start . You reset start and buttonState here because you
cannot be certain they will be reset in event handlers that are called subsequently. Button 2 down is the
pop-up trigger, and the code in the mouseDragged() and mouseReleased() methods are executed only
when button 1 is down.
Here's how the mouseReleased() method can be implemented:
public void mouseReleased(MouseEvent e) {
if(e.isPopupTrigger()) {
if(last != null) {
// If mouse was dragged
start = last;
// show popup at last
cursor position
}
theApp.getWindow().getPopup().show(SketcherView.this,
start.x, start.y);
start = last = null;
buttonState = MouseEvent.NOBUTTON;
return;
}
if(theApp.getWindow().getElementType() == TEXT) {
if(last != null) {
start = last = null;
}
return;
}
if(e.getButton() == MouseEvent.BUTTON1) {
buttonState = MouseEvent.NOBUTTON; // Reset the
button state
if(tempElement != null) { // If there is an
element...
Search WWH ::




Custom Search