Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

More Java Pitfalls Share Reactor - Daconta M,C.

Daconta M,C. More Java Pitfalls Share Reactor - Wiley publishing, 2003. - 476 p.
ISBN: 0-471-23751-5
Download (direct link): morejavapitfallssharereactor2003.pdf
Previous << 1 .. 30 31 32 33 34 35 < 36 > 37 38 39 40 41 42 .. 166 >> Next

>>>java GoodRightMouseButton (on MacOSX with a single mouse button)
In mousePressed(), isPopupTrigger? false In mouseReleased(), isPopupTrigger? false Button 1 clicked.
isControlDown? false isMetaDown? false isAltDown? false isShiftDown? false isAltGraphDown? false
In mouseClicked(), isPopupTrigger? false Left button? true Middle button? false Right button? false
In mousePressed(), isPopupTrigger? true In mouseReleased(), isPopupTrigger? false Button 2 clicked.
isControlDown? true isMetaDown? false isAltDown? true isShiftDown? false isAltGraphDown? false
In mouseClicked(), isPopupTrigger? false Left button? false Middle button? true Right button? false
In mousePressed(), isPopupTrigger? false In mouseReleased(), isPopupTrigger? false
88 Item 11
Button 3 clicked.
isControlDown? false isMetaDown? true isAltDown? false isShiftDown? false isAltGraphDown? false
In mouseClicked(), isPopupTrigger? false Left button? false Middle button? false Right button? true
The new results show that we can determine which mouse button (left, right, or middle) was clicked and whether that click is the popup trigger event. The solution has two parts: first, the SwingUtilities class contains a set of methods that allow you to test a mouse event to determine which side of the mouse was clicked. It is slightly nonintuitive to have these separated from the other test methods in InputEvent or MouseEvent; however, that could change in a future release. Second, you should notice how you have to test for the popupTrigger in the mousePressed() and mouseReleased() to accurately determine the trigger event. It is interesting to note that the Ctrl-mouse combination on the Macintosh is considered the middle mouse button and not the right mouse button. It would be better if the popup trigger was consistent on Windows and the Mac (both being considered a "right click").
In conclusion, using the SwingUtilities class and understanding when to call isPopupTrigger() allows us to better process mouse events in cross-platform applications.
Item 11: Apache Ant and Lifecycle Management
The software lifecycle process describes the life of a software product from its conception to its implementation and deployment. An important aspect of this process is the need to impose consistency and structure on all lifecycle activities that can guide actions through development to deployment. This practice is often compared to a cookbook, where knowledge is captured and then transferred to others so that they can emulate similar actions. Unfortunately, most projects incorporate inconsistent practices where developers create and deploy on disparate platforms and apply their individual techniques for building and testing code, which becomes problematic during integration when disparities between scripts make them difficult to understand and implement.
An important solution to this problem is a utility available through the Apache Software Foundation called Ant ("Another Neat Tool"). Ant's main purpose is to facilitate application builds and deployments. This is achieved by combining Java programming language applications and XML build files, which can be run on multiple platforms and offer open-architecture flexibility. By maintaining applications and program builds with Ant, consistency levels can be achieved by disparate groups of developers, and the best practices can be propagated throughout a project.
With Ant, targets are generated in project files for compilation, testing, and deployment tasks. The aim of the Ant build file which follows is to highlight some useful
Apache Ant and Lifecycle Management 89
target generation tasks that can facilitate software lifecycle activities so that manual development processes can be automated, which will free up developers' time for greater creativity in their own applications rather than being tied down with mundane build and deployment activities.
Most Ant scripts start with the initialization of application properties demonstrated in lines 11 to 23. These same properties could also be established from the command line and delivered to the Ant build script in the same manner as Java programs with the -D parameter during the Ant build invocation. One important thing to consider about properties that are set in an Ant script is that these are immutable constants that cannot be changed once declared. Line 31 shows the depends tag that signals that the target "compile" depends on the "init" target being run prior to its execution. Most scripts will use the depends tag to execute sequential build processes.
001 <?xml version="1.0"?>
002 <project name="lifecycle management">
003
004 <!--
005 *******************************************************
006 ** Initialize global properties.
007 ****************************************************-- >
008 <target name="init" description="initialize lifecycle properties.">
009
010 <tstamp/>
011 <property name="testdir" value="." />
012 <property name="rootdir" value="."/>
Previous << 1 .. 30 31 32 33 34 35 < 36 > 37 38 39 40 41 42 .. 166 >> Next