Java Reference
In-Depth Information
if(buttonState == MouseEvent.BUTTON1) {
g2D = (Graphics2D)getGraphics(); // Get graphics context
g2D.setXORMode(getBackground()); // Set XOR mode
}
}
Directory "Sketcher 7 with element context menus"
This just adds an if statement that calls the showContextMenu() method as the condition. This method
displays the appropriate menu depending on whether there is a highlighted element, and returns true
when it displays a menu and false otherwise. You can add a definition for this to the MouseHandler
class:
private boolean showContextMenu(MouseEvent e) {
if(e.isPopupTrigger()){
if(last != null) {
// If mouse was dragged
start = last;
// show popup at last
cursor position
}
if(highlightElement == null) {
// If there is no
highlighted element
// Show the popup menu from the app window
theApp.getWindow().getPopup().show(SketcherView.this,
start.x, start.y);
} else { // Otherwise...
// Show the element operations context menu
elementPopup.show(SketcherView.this, start.x, start.y);
}
return true;
}
return false;
}
Directory "Sketcher 7 with element context menus"
The mouseReleased() method makes use of this method, too:
public void mouseReleased(MouseEvent e) {
if(showContextMenu(e)) {
start = last = null;
return;
}
Search WWH ::




Custom Search