|
Projects
At heart, a project is a collection of source files and resource files that together form a functional unit. Each project in TJI has an associated project description file. These have the extension .proj and are stored in directory <homepath>/projects (this is created automatically when the IDE is first run). These files are updated by the IDE and need not be modified directly. <homepath> is the location of ide.jar and is the default, single-user <userhome>. When an alternative 'user home path' is set or changed to, via the 'User' menu, the project descriptor files will be stored elsewhere - in:
TJI employs a straightforward '1 to 1' mapping of package to project so that when you develop a number of packages (or subpackages), each will be it's own project. Hence, what you think of as a 'project' may comprise of one or more TJI projects. That is, your project (or program) may be composed of more than one TJI project, which you can think of as your 'sub-projects'. Hence, it is possible to open more than one TJI project at the same time and work on them simultaneously. For example, let's say that you wish to develop a chess program (your 'super-project'). Because you may later develop some other similar games, and also because you know that software is easier to develop and maintain when divided into parts, you decide to make your chess program from three packages. One will be the chess program itself and the other two packages will be for generic, reusable functionality; the first for game playing user interaction and display, and the second for the 'logic' - calculations to determine the 'score' that would result from a possible move by the computer player. It is possible that more than one package be unique to the program itself, rather than generic. It all depends on your goal and how good is your design. Once you have decided the packages you will need, you can begin to think about the classes (objects) you will need in each package. For example, you may decide to create an abstract class called 'PlayingPiece' and sub-classes for 'King' etc. Each package will be a separate TJI project composed of the classes and interfaces in that package. In practice, one will be see opportunities to further divide and thereby simplify a software design as the implementation progresses. These may include: creating a new package or class by taking some functionality out of an existing one, dividing a package or class into two or more, etc. When done well, there are pay-offs for program stability, development speed, maintainability and reusability. A little work (and thought) now can save a lot of work later.
New Project - And Framework Templates To create a new project, first select 'New Project' from the 'Project' menu. There is no need to give the .proj extention when asked for the project name. Any extention or path you give will be removed; project files always have the extention .proj and are stored in the '<homepath>projects' directory. If there is already a project with the entered name, you will be prompted to enter an alternative name, or cancel the operation. You can choose to create a new 'empty' project, to which you can either add existing source files, or begin creating source files from scratch. However, when starting a new project you can often save time by opting to create a project with an automatically generated framework; this can be done for GUI applications, console applications, applets, servlets and tag handlers. The applet framework can be based on class Applet or JApplet. Because applets are generally intended for deployment on the Web - and hence running by people who may have only limited Java support in their browsers - you may prefer to use the older Applet (AWT based) option. However, it is possible for the HTML page holding an applet to initiate the installation to the client browser of the Java Plugin (see http://java.sun.com for more information on this); although it takes some time to download, this is a one-off operation and once a user has it, they always have it. It is quite easy to change an Applet to one based on JApplet - simply change Applet to JApplet, import the required swing packages/classes and remember to use method getContentPane() to begin building your GUI (just as with JFrame). Swing requires that you build your gui on the ContentPane of a top level applet, frame or dialog. With Swing, you add to the ContentPane of the top-level container rather than the container itself (see the Java Guide for more information on this topic). When an application framework is created, the default package name
is suggested which will place the source files generated in a new directory whose path is
or:
if the user home has been changed. You can change the default base directory and default package settings suggested for new projects - see the 'Set Defaults' sub-menu of the 'Options' menu. To add existing Java source files, HTML files (as required for applets), image files etc to a project, choose from the 'Add File(s) to Project' options within the 'Project' menu. Opening a file ('File' menu) has the same effect as adding a file to the current project, but in addition opens it in an editor.
Modifying the framework template files The skeleton framework source files will be found in subdirectories of directory <homepath>/templates. For example, the files to create a skeleton Swing Applet will be found in
You may modify these files if you wish. The skeleton framework source files can even be replaced by one's of the developer's choice, not only modified. All the files found within the appropriate sub-directory of directory templates will be used for the skeleton project. Java files are named according to the main class name as defined in the source text. HTML files (for applets and servlets) are named <projectname>_run.html. Within the Java source files, package # is replaced by 'package' followed by the specified package, or removed completely if no package is specified. Also, package# (no space) is replaced completely by just the package name. $name$ is replaced throughout the source file by the project name. See the default template files as a guide. To restore the default skeleton files for any sub-directory (i.e. project type), simply remove all the existing files from that sub-directory and the defaults will be restored when the IDE is next started.
Open Project Select 'Open Project' from the 'Project' menu. Browse the project tree and select a project; then click on 'Ok' or press the 'Enter' key. You can also simply double-click on a project name to open it. The contents of a project are checked when it is opened, so any files which no longer exist (have been externally moved or deleted), will be removed.
Automatic Re-Opening of Last Opened Projects TJI will automatically load the project(s) last open when the IDE is restarted (if those projects were open at the time of quitting the IDE). Further, any files open at the time of quiting the IDE will be automatically reopened.
Save Project Any open project is automatically saved whenever it is changed or closed, and when one quits the IDE; so there is no option to explicitly save a project - it is entirely automatic. Project description files (with the file extension .proj) detail the base directory and all the files that are part of the project. They may also contain other information including which source file is the 'main' file, the project type and the package name (if any). Project description files are always stored in the directory
Close Project You will be prompted whether to first save any source files which have been altered before each editor closes down. The project information files are saved automatically.
Remove Project When you remove a project, it will no longer appear in the project list. Note that TJI will not delete any file from your hard disk (or remove any directory) - with the exception of the project description file. Hence, when you remove a project, only the project description file is deleted, not any of the source or resource files.
Rename Project This option gives a new name to the project description file and the project name as it appears in the project tree and on the project tab. It does not alter the package name or directory names of the source files. The project will continue to function exactly as before.
Adding to and Removing Files from a Project To add existing Java source files, HTML files (as required for applets), image files etc to a project, choose from the 'Add ... to project' options within the 'Project' menu. One reason you might want to add an image file to your project is so that it will be available to the Panel Builder. Opening a file ('File' menu) has the same effect but in addition opens an editor for the selected file. A new file is added to the project when it is named. To remove a file from a project, the project must be open. Select the 'Files' tab, then the file or files to remove (hold down the Ctrl key to make multiple selections); then click on the 'Remove' button below the list. Note that TJI does not delete the files from your hard disk - only the inclusion of the file in the project description is removed. When you opt to add files to the current project, you may make multiple selections in the File Browser by using the Ctrl key - keep the Ctrl key pressed while selecting multiple files with the mouse. It is also possible to 'Add Directory Contents to Project', which will add all the files within the selected directory to the current project.
Project Import This option allows the importation of a complete project. TJI's format for project export and import is a single standard zip file containing the java source files, resources such as gif files and HTML files, and the .proj project description file (which details the project type, 'main' file and package). There are many example projects available for download from the 'Resources' page of our web site. Project export and import is a simple way to share a project with colleagues or friends. Because it is packaged as a single file, it is easy to attach an exported project to an email, for example. To import a project, choose 'Import Project' from the 'Project' menu. Then select the project zip file and it will be installed automatically. Now simply click on 'Run' to build and run the project.
Project Export This option allows the creation of a single zip file containing all the Java source files, resource files and the project description file (the .proj file). This provides a convenient way to share projects with friends and colleagues, and to store project backups at regular intervals.
Jar Project This option allows you to create a jar file for deployment purposes. The jar file produced will contain the project's compiled class files, including inner classes, and any project resources such as GIF image files. If no package is involved, the following applet tag is an example of how to include an applet in an HTML web page:
The 'archive' attribute specifies that the classes are to be found within an archive (i.e. a jar or zip file). If the applet's code sets its size (perhaps a default size), then the size need not be specified in the HTML applet tag. Also, note that with most browsers, the '.class' is not required. So the applet tag could be as simple as:
In the case of an applet involving a package - for example, projects.myapplet - specify the fully qualified class name in the 'code' attribute of the applet tag. For example:
Our tests show that this does not not work in all browsers, but the following does, so is used by TJI when creating HTML pages:
If you simply provide classes on your website that are not contained within a jar, the archive attribute should be omitted. So the applet tag for an applet with no package would be:
For an applet with a package, the applet tag would be written this way:
When classes are not within a jar, they must be placed in a subdirectory structure (relative to the HTML file) to match the package. In the case of the classes being within a jar file, the jar file would normally be placed in the same directory as the HTML file. A 'codebase' attribute can be included to tell the browser that the archive (or class files) are to be found at a base directory (minus the package defined sub-directories) that is different from the location of the HTML file. However, in most cases this is not required.
Setting the 'Main' File Setting the 'main' file for a project is not essential. However, it allows the project to be compiled or run without you needing to switch to or open the main file first. By 'main file' is meant the file containing a class which has a public static void main(String[] args) method (in the case of applications) or the class which has the init() method (in the case of applets) used to start the program. For JSP projects, you can select one of the JSP files to be the 'main' file - in this case it simply means that when the project is run within TJI, that TJI's Web Browser will start by loading that JSP file.
Setting the 'HTML' File This specifies an HTML file as the starting file for running the project. For example, in an applet type project, you can specify the HTML file that refers to the applet. In a servlet type project, you can specify the HTML page that should appear first in the web browser; perhaps this HTML file has a link calling your servlet(s).
Setting the Project Type Setting whether the project type is 'Applet', 'Console' or 'GUI application', 'JSP', 'JSP Tag Handlers' or 'Servlet' allows the IDE to build and run or use the project appropriately.
Setting the Package Name Setting the package name (if one is used) allows the IDE to correctly compile and run the project. You can choose 'Set Package Name' at any time. If you set the 'Refactor Project' checkbox to true, not only is the package set in the project description, but the package statements in all Java source files will also be updated - and so will the directory location of those source files (if necessary), to match the new package name. Package names are used to uniquely identify classes and a convention is to base package names on the reverse of the web address of the authors - for example, com.kinabaloo.utilities. The standard Java classes, because they are standard classes, just start with java or javax, with the secondary names defining their functional role in the tree-structured class hierarchy. So classes String and Character, for example, are in package java.lang and their fully qualified names are hence java.lang.String and java.lang.Character. Classes LineBorder and EmptyBorder, meanwhile, are in package javax.swing.border When you create a project in TJI, the following package name is usually suggested
The main purpose of this is to maintain a relationship between package name and file location such that project files are stored in their own subdirectory and have a common base directory; in other words, the primary purpose is to keep your project files well organised. You can of course choose different package names for the purposes of developing a class library or for making your classes public (giving to others). You can store your source files in sub-directories without setting a package. In this case, the base directory path will include those sub-directories and TJI will still compile and run your project without you needing to specify a classpath. You will need to add to the classpath only if your project uses classes that are not part of the standard Java class libraries. In this case you will also need appropriate import statements in your source code. Note that you can specify a different base directory and a different package to use as default suggestions for the creation of new projects. To do this, go to the 'Set Defaults' sub-menu of the 'Options' menu.
Browse / Rename / Delete Project By choosing this option from the 'Projects' menu, you can rename or delete a project (see notes above). You can also browse the files it contains, and the date and time each was created or last modified. The 'Rename' option gives a new name to the project description file and the project name as it appears in the project tree and on the project tab. It does not alter the package name or directory names of the source files. The project will continue to function exactly as before. The 'Delete' option allows you to remove a project from TJI so that it will no longer appear in the project list. Note that TJI will not delete any file from your hard disk (or remove any directory) - with the exception of the project description file. Hence, when you delete a project, only the project description file is deleted, not any source or resource files.
Set Project Classpath This option in the 'Project' menu allows you to specify the location of classes used by your project that are not part of the standard Java packages. Theses additional classes may be either your own classes or 'third party' ones acquired from elsewhere. The location of these additional classes is added to the project class path so that these classes can be found by both the java compiler 'javac' and the java interpreter 'java'. For example, if your project wishes to use a printing package called org.javaprint that comes as a jar file called jp.jar and you have stored this in directory c:/java then you need to add c:/java/jp.jar to the classpath. If you don't have a jar file but separate class files (perhaps you unpacked the jar file or have created them yourself in a different TJI project), then add the base directory to these classes (i.e. minus the package part of the directory path). So, if you have unpacked the class files from jp.jar and correctly asked to preserve the directory structure, then class org.jp.JP will be stored in c:/java/org/jp and the base directory to add to the classpath will be simply c:/java. Don't forget that to use classes that are not part of the current TJI project, or within the standard Java class libraries, you will need to add import statements within your source code as well as adding their location to the classpath. For example, in the case of the hypothetical printing package, the import statement might be:
In summary, for classes within a jar or zip file provide the location of that file, including the archive name. For separate class files, provide the base directory.
Opening files not part of the current project It is possible to open and edit files that are not part of the current project - this can be useful for simply browsing other source code and for copying text to and from. These files are indicated as separate from the current project (the background color of the editor is darker) and will not appear in the current project's file list. To do this, use 'Open Non-Project File' available from the 'Edit' menu. If you open a file as external to the current project then decide that you would like it to be part of the current project, use the 'Add Current Editor File to Project' option available from the 'File' menu.
|