Java Reference
In-Depth Information
That's where you're headed, but there are a few bridges to be crossed on the way. For starters, if the con-
text menu is to be really useful, users need to know which element is under the cursor before they pop up the
context menu; otherwise they can't be sure to which element the pop-up menu operations apply, particularly
when elements overlap on the screen. Deleting the wrong element could be irritating, to say the least.
What you need is some visual feedback to show when an element is under the cursor — highlighting the
element under the cursor by changing its color, for example.
Highlighting an Element
You could draw an element in magenta rather than its normal color to highlight that it's the one under the
mouse cursor. Every element needs a boolean field to indicate whether it is highlighted or not, so the object
knows which color to use in the draw() method when drawing the element. You can add this variable as a
field in the Element class:
protected boolean highlighted = false;
// Highlight flag
You can add this line immediately following the statement for the other data members in the Element
class definition. The highlighted field is inherited by all of the subclasses of Element .
You need a method to set the highlighted flag in the Element class:
// Set or reset highlight color
public void setHighlighted(boolean highlighted) {
this.highlighted = highlighted;
}
Directory "Sketcher 6 highlighting elements"
This method is also inherited by all of the subclasses of Element .
You can define the color to be used for highlighting in the SketcherConstants class as:
Search WWH ::




Custom Search