Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 64 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
64
Dung lượng
8,71 MB
Nội dung
keeps a list of all the places you tell it that Javadoc documentation germane to your project may be found while gener- ating new Javadoc documentation. The Javadoc view (shown in Figure 3-8) maintains this search list and allows you to mount directories which contain Javadoc documentation the same way you mount source trees in the NetBeans Ex- plorer Filesystem view. Figure 3-8: The NetBeans Explorer Javadoc view. By default, each project starts out with two Javadoc trees mounted, the Javadocs for the Ant build system and the direc- tory in which NetBeans deposits all Javadocs which it generates on your behalf. You may at any time mount new direc- Chapter 3. Concepts and Paradigms 42 tories, archives or HTTP URL'S in the Javadoc view to be searched while generating Javadocs. Simply right-click on the Javadoc icon at the top of the Javadoc view and choose either Add Local Directory, Add Archive, or Add HTTP filesystem, at which point you will be presented with a dialog analogous to the one which appears for mounting filesys- tems in the Filesystem view. The Runtime View The NetBeans Explorer Runtime View really might be called alternatively the "What Happened? View". The Runtime View keeps track of various facilities available to your project and also operations which have been performed relative to your project. This is useful primarily when errors or problems occur; for example, if an RMI connection is being un- cooperative or if there are difficulties encountered during version control operations. Expanding the view of an individ- ual facility within the Runtime View yields a status view of that facility and a list of error messages from previous op- erations. The Runtime View is shown in Figure 3-9. Chapter 3. Concepts and Paradigms 43 Figure 3-9: The NetBeans Explorer Runtime view. Node Paradigms "Node Paradigms" is a fancy way of saying "How we operate on nodes represented by icons within the various Net- Beans windows such as the Explorer and the Tools Options windows". Chapter 3. Concepts and Paradigms 44 Explorer views of Java classes NetBeans Explorer displays its nodes as icons in an expandable tree hierarchy matching the package structure of your program. Most of the icons are fairly intuitive. Java classes look like building blocks; the composite representation of the class and its source looks like a piece of paper with building blocks drawn on it. Filesystem mounts look like com- puter hard disk drives. There is a complete glossary of Explorer icons and their meanings in the online help for Net- Beans. Do a search for "icon" and you will quickly find the relevant page. Badges NetBeans Explorer nodes are displayed as icons, but next to the icons are little "sub-icons" which in NetBeans parlance are called badges. Badges indicate something about the state of the object they sit next to in the Explorer view. There are badges to indicate such states as: • the associated node needs compilation • the associated node is under version control and has been modified • the associated node has a syntactic error in its source code (NetBeans "live parses" your source as you edit it so many errors can be caught by the IDE without even trying to compile the code.) There is a complete list of badges in the online help which comes with NetBeans. Do a search in the online help for "badges" and you will be shown pictures and explanations of the badges currently exhibited alongside to NetBeans ob- jects. Expanded view of Classes If you click the little horizontal lever to the left of one of Explorer's node icons which happens to represent Java source+class, the view will expand, as was illustrated above. When you start at the collapsed view of a Java class, you are seeing an object which, as has been noted, represents the class, its source, and pretty much everything about that class as one entity. The first click to expand this view shows you an object representation of the class itself (see Figure 3-10). Figure 3-10: Explorer view of a class object expanded one level. If you again expand the view by clicking the little lever to the left, you get a view of fields, constructors, methods and bean patterns, as shown in Figure 3-11. Chapter 3. Concepts and Paradigms 45 Figure 3-11: Explorer view of a class object expanded two levels. One more click on any of these entities opens up for you the individual fields, or methods, or constructors, etc. The re- sults of this additional click are detailed in Figure 3-12. Figure 3-12: Explorer view of a class object expanded three levels. Furthermore, each representation has a pop-up menu associated with it by a right mouse click that allow you to cus- tomize and perform other operations on each element of your Java class. Wander around with the mouse and explore the Explorer! Cut/copy/paste subnodes You can move portions of your project around the filesystem hierarchy using familiar GUI metaphors in the NetBeans Explorer. Just select a subnode (e.g., a folder), right-click and choose Cut, move to another position on the tree view and choose Paste and the subnode and its descendants are moved. Typically, if you "cut" a node it may not disappear until you try to "paste" it somewhere. And as regards a "copy" and "paste" operation, some objects, particularly nodes representing your Java classes, will offer the choice of a real copy operation or just inserting in the new location a link to the original object. Be careful with "cut"! So much of what happens in the NetBeans Explorer, e.g., mounting/unmounting a file system, is Chapter 3. Concepts and Paradigms 46 virtual, it's easy to forget that cutting a file from a package is real and the file is indeed removed from its original loca- tion. Tools actions One of the submenu choices on the right-click context menu available for all objects visible in the NetBeans Explorer is Tools. On this submenu will be found tool operations appropriate to the type of object which was selected at the time the menu was pulled down. For instance, if the object is a folder, the selections offered by the Tools submenu might in- clude Update Parser Database and Generate Javadoc, whereas if the object is a Java class, the selections would include operations like Add to Component Palette and Set as Main Class. Sometimes Explorer Gets Behind the Times As clever as it is, sometimes NetBeans Explorer gets a little confused. Explorer is not necessarily wrong. NetBeans is running in many threads, one of which is keeping an eye on your objects. Sometimes it can be a while until information about your project percolates through the system. NetBeans engineers sometimes view these delays as "bugs" and try to fix them. But the relative autonomy enjoyed by even the core modules of NetBeans insures that interactions between the modules are somewhat loosely linked. So here are comments on a few phenomena, mostly harmless but often confusing, phenomena which we have observed, along with tips how to shake the Explorer back to consciousness on those rare occasions when you suspect that Ex- plorer has other things on its mind than the current and correct state of your project. Does a file really need recompilation? The NetBeans Explorer, as we've seen, annotates program objects visually using "badges". Sometimes the "needs re- compilation" badge is erroneously displayed next to an object which was either recently revealed to view in Explorer (either because the project changed or because you just opened its package) or was recently changed and recompiled. You can wait, and after a few seconds, NetBeans will usually update its view. If it doesn't, try opening, saving and re- compiling the object. If that doesn't work, and the object is under version control, try doing a CVS refresh on the ob- ject. Right-click on a parent folder of the package you are interested in to bring up the context menu and choose CVS->Refresh Recursively and NetBeans Explorer will verify with the repository its view of the current state of all the objects and sub-packages in the package. Is a version really up-to-date? Is a file really local or is it already in the repository? When a mounted tree is under version control NetBeans Explorer indicates to the right of an object icon what the ver- sion level of an object is and whether it is up-to-date with respect to the repository. Explorer can sometimes end up mo- mentarily out of synch with the versioning repository, indicating that a file is up-to-date which has been changed, or that a file which has been imported with an entire package into the repository is still local. Again, the solution is to do a recursive refresh on that branch of the mounted tree, by right-clicking on the enclosing package and choosing CVS->Refresh Recursively. Summary Perhaps these Explorer phenomema we have mentioned above will be fixed in the version of NetBeans you are using. However, as they are artifacts of multithreading and the insoluble question of "how often should NetBeans burn CPU cycles and network bandwidth to cross-check its view of the project?" it's likely something of the sort will occasionally pop up. The point is that unexpected albeit innocuous surprises can occur in NetBeans that require you to jiggle things Chapter 3. Concepts and Paradigms 47 around some to make sure you yourself are clear on the state of your project. Filesystems and the CLASSPATH The relationship between NetBeans Explorer's concept of mounted filesystems and classpath used by Java when com- piling, debugging and running your code is intricate. Here we attempt to untangle some of the mysteries involved. How branches of the host file system manifest themselves in NetBeans Any branch of the host file system might appear no times, one time, or any number of times, in the same or in different projects. The view of any branch of the host file system is registered in the explorer view by the process of mounting, discussed below. How CLASSPATH is handled in the IDE You already know how to compile a Java program and run it outside of NetBeans. Outside of NetBeans, you append to the CLASSPATH (typically a shell environment variable) the directory names or jar file names in which reside the package trees of any necessary supporting Java code, including the directory containing the packages of source for the code of your project. Then you compile and run. The CLASSPATH shell environment variable Let's refresh our memory on how one normally sets the CLASSPATH shell environment variable in order to compile or run Java applications at the command line. • Under any Unix-like operating system, you set classpath in a shell command or a shell script with CLASSPATH=$CLASSPATH:/some/path:/some/jar.jar:/some/path • Under Windows you either use the MyComputer->Properties->Advanced->Environment or using the command shell enter SET CLASSPATH=%CLASSPATH%;\some\path;\some\jar.jar;\some\path and use that same shell for your subsequent Java commands. Having this experience, you would easily guess that setting your CLASSPATH before running NetBeans would govern the CLASSPATH used by NetBeans to operate on your project. But that guess is wrong! NetBeans ignores the CLASSPATH shell environment variable. NetBeans does this for two reasons: 1. because NetBeans wants to make sure that for its own operation its own classes appear in the right order; 2. because NetBeans allows the user to maintain multiple independent projects, each with its own CLASSPATH. Instead of using your preset classpath, NetBeans assigns a per-project CLASSPATH which consists of a few hidden el- ements plus the order of mounts within the Filesystems view of the NetBeans Explorer for the project in question. How to modify the IDE's CLASSPATH As noted above, the IDE's CLASSPATH can be different for each project you are developing in NetBeans. When we Chapter 3. Concepts and Paradigms 48 say here "the IDE's CLASSPATH" we mean the classpath which NetBeans uses when analyzing, compiling or running your project. We do not mean the classpath used when the IDE itself is launched: this latter issue is covered in the next section. As noted above, controlling the classpath used by the IDE with regard to your project is very simple: The classpath used by the IDE consists of a few hidden elements plus the order of mounts within the Filesystems view of the Net- Beans Explorer. If you have a filesystem or filesystems mounted in a project but for some reason do not wish them to be used in the classpath (e.g., you have two versions of the same .jar file with which you are experimenting), you can edit the capa- bilities of that filesystem. "Capabilities" is one of the tabs of the properties editor for a filesystem. Right-click on the icon for the filesystem whose capabilities you wish to edit and choose Properties->Capabilities. All of this is shown in Figure 3-13. Chapter 3. Concepts and Paradigms 49 Figure 3-13: Editing filesystem capabilities. You can include or exclude a filesystem from the path for • documentation • execution • compilation • debugging from the Capabilities tab of the Properties dialog. By default, filesystems mounted in the NetBeans Explorer appear in the CLASSPATH used by NetBeans to compile and run your code in the order in which they appear vertically in the NetBeans Explorer Filesystem view. To change the order of CLASSPATH evaluation change the vertical order in which they appear in the NetBeans Explorer. Top- most elements appear foremost in the classpath. In the NetBeans Explorer in the Filesystems view, right-click on Filesystems icon at the top and choose Filesystems->Customize. The Customizer Dialog appears. Right-click on the mount whose order you wish to change and choose "Move up" or Move down" (see Figure 3-14). Chapter 3. Concepts and Paradigms 50 Figure 3-14: Using the Customizer Dialog Appending and pre-pending CLASSPATH to the IDE's CLASSPATH You might be tempted to change the classpath which the IDE itself uses internally as it launches. Here's a hint: Don't. However, if you must, note that the IDE picks up its CLASSPATH from the script which launches it. If you're smart enough to know how to change the CLASSPATH of the IDE itself safely, you're smart enough to figure out everything you need to do from study of the launching script file. Other CLASSPATH tricks You can change the classpath associated with particular services such as compilation and execution. Choose Tools->Options->Building->Compiler Types->External Compilation. Then choose the Expert tab in the properties notebook, and you can change the classpath for external compilation in a number of different ways in the expert proper- ties. In a similar fashion you can change the external execution classpath by choosing Tools->Options->Debugging and Executing->Execution Types->External Execution. Chapter 3. Concepts and Paradigms 51 [...]... code in the editor window Opening the Source Editor There are two prinicipal ways to open a file in the NetBeans Source Editor 1 From the NetBeans Main Window, pull down File->Open and use the file dialog to browse to the file you wish to open 2 From within the NetBeans Explorer, find the node representing of your source, right-click on it and choose Edit if that action is available, or Open if there... folder 2 You can use the NetBeans Explorer to create the package Right-click on the package under which you wish the new package to reside to bring up the context menu and choose: New->Java Package and the new package will be created Versioning of the new package If the tree on which you are working is under version control, the new package still needs to be added to the repository Right-click on the. .. window • The next window to the right is titled "Members" and displays the data and method members of the class or interface selected in the Objects window • The Properties window displays the properties of the last entity you clicked in either of the three Object Browser window • You can right-click on entities in the three Object Browser windows to bring up menus of actions you can perform upon them... it, right-click on the class in the NetBeans Explorer and choose Properties Flip to the Execution tab and modify the Debugger property Workspaces Workspaces are how NetBeans groups the user' s work so that related tasks are associated with one another and disparate tasks can be hidden offscreen away from active tasks The NetBeans main window, shown in Figure 3-16, has several tabs on the bottom which... This menu has many of the selections which you would find when you right-click on the NetBeans Explorer node representation for the same entity These selections include CVS, Compile, Build, etc Additionally, there are options on the menu relevant to the task of editing, such as Cut, Copy and Paste Closing the Source Editor When you click the close widget on the Source Editor window, the window closes,... take a while! A message box will keep you posted on the progress of the operation as the update executes 72 Chapter 4 Working with the Source Editor Abbreviations You can assign abbreviations which the Source Editor expands Just type the first few letters of the abbreviation and hit the Spacebar, and the Source Editor will expand the abbreviation The Source Editor keeps separate sets of abbreviations... NetBeans refers to the cluster of functionality supporting the generation of object code from the sources of your project NetBeans can use various different Java compilers, and the settings are there for you to change if you wish Compiling your code 55 Chapter 3 Concepts and Paradigms • To compile a Java source file, open the file in the Source Editor or select it in the NetBeans Explorer and either press... selects text to the right, Shift+Control+Right Arrow selects text to the right a word at a time Et cetera… no surprises here The reason that the NetBeans Source Editor is indispensible to your NetBeans development workflow is the level of integration provided between objects in the NetBeans Explorer and Form Editor, code entities in your program, and your actions within the editor and the appearance... to modify, flip to the Execution tab and choose from the dropdown list for the Executor Note Several of these execution settings can also be manipulated by selecting the individual class and then pulling down the Buildmenu Debugging services Debugging services are how NetBeans refers to the facilities for debugging your program from within NetBeans More on Debugging Debugging your NetBeans project has... Edit action on the menu 68 Chapter 4 Working with the Source Editor “Open” vs “Edit” vs a good, hard double-click! Actually, with Java sources and many other NetBeans Explorer nodes, you can just double-click on the node to open it in the NetBeans Source Editor So why the rigamarole about Open and Edit? Recall from our discussion of the NetBeans Explorer that a double-click invokes the default action . in which they appear in the NetBeans Explorer. Top- most elements appear foremost in the classpath. In the NetBeans Explorer in the Filesystems view, right-click on Filesystems icon at the top. right-click on the class in the NetBeans Ex- plorer and choose Properties. Flip to the Execution tab and modify the Debugger property. Workspaces Workspaces are how NetBeans groups the user& apos;s. used by NetBeans to compile and run your code in the order in which they appear vertically in the NetBeans Explorer Filesystem view. To change the order of CLASSPATH evaluation change the vertical