<?php header("Content-Type: text/html; charset=iso-8859-1") ?>
<?php include("course_info.php") ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
 <link rel="stylesheet" href="classweb.css" type="text/css" />
 <title><?=$course_number?> <?=$quarter?> <?=$year?>: Lab 9 Instructions</title>
</head>

<body>

<h2><?=$course_number?>, <?=$quarter?> <?=$year?></h2>
<h1><?=$course_title?></h1>

<h2>Lab 9 Instructions</h2>

<hr />

<h3>Code generation in Eclipse</h3>

<p>
In addition to handy features like automatic code formatting,
Eclipse can generate code for you.
In this lab we'll explore how to configure and use its code-generation features.
</p>

<h4>Create a new Class.</h4>

<p>
The following steps will lead you through the steps of
automatically generating a class in your ircclient package
that implements the interface <code>IRCMessageListener</code>. 
</p>

<ol>
 <li>
  In the Package Explorer, expand <code>src</code>
  and select the <code>edu.ucsd.cse70.ircclient</code> package.
 </li>
 <li>
  From the menu bar, select <code>File-&gt;New-&gt;Class</code>.
  In the "New Java Class" dialog,
  make sure the package is set to <code>edu.ucsd.cse70.ircclient</code>,
  and give the class any name you like. (You won't commit it to the repository.)
  Don't close the dialog just yet!
 </li>
 <li>
  In the "New Java Class" dialog,
  click the <code>Add...</code> button,
  and in the text field, begin typing
  the name of the interface you're implemeting (see above).
  Then select it and press "OK".
 </li>
 <li>
  In the "New Java Class" dialog again,
  press "Finish".
  Notice Eclipse adds methods from the interface, but without implementation.
 </li>
</ol>

<h4>Add some functionality to the class.</h4>

<ol>
 <li>
  Create 3 variables:
  <code>message</code>, <code>connection</code>, and <code>user</code>.
  Give each variable a type that seems appropriate.
  In keeping with good encapsulation, make them <code>private</code>.
  So that other classes can read and modify the values of these variables,
  we'll generate accessor methods.
 </li>
 <li>
  From the menu bar, select
  <code>Source-&gt;Generate Getters and Setters....</code>.
  In the resulting dialog, check all 3 variables
  and check the "Generate method comments" option
  before pressing "OK".
 </li>
 <li>
  Suppose we want a constructor that takes values for these variables.
  See if you can have Eclipse generate this for you.
 </li>
</ol>

<h4>Customize template settings.</h4>

<p>
Notice the <code>TODO</code> comment in the <code>notify</code> method?
Find it painfully obvious? Let's tell Eclipse to stop generating those.
</p>

<ol>
 <li>
  From the menu bar, select
  <code>Window-&gt;Preferences-&gt;Java-&gt;Code&nbsp;Style-&gt;Code Templates</code>.
 </li>
 <li>
  There are 2 categories of templates: comments and code.
  Each template has a pattern (although some are empty) for what to generate.
  See if you can find the pattern that generated the <code>TODO</code> comment
  and remove it.
  Then try generating another class (hint: or at least another method)
  to verify it works.
 </li>
 <li>
  Now setup your templates so that when you create a new Java class,
  the comments at the top look like:
<pre>
package edu.ucsd.cse70.ircclient;

/**
 * @author Tess
 * @version .1 10/20/2008
 */
public class MYCLASS implements IRCMessageListener
</pre>
 </li>
 <li>
  Try out different settings. See what you and your teammates like!
 </li>
</ol>

<hr />

<p>
 <a href="http://validator.w3.org/check?uri=referer"><img
    style="border:0;width:88px;height:31px"
    src="http://www.w3.org/Icons/valid-xhtml10"
    alt="Valid XHTML 1.0 Strict" height="31" width="88" />
 </a>
 <a href="http://jigsaw.w3.org/css-validator/check/referer">
  <img style="border:0;width:88px;height:31px"
       src="http://jigsaw.w3.org/css-validator/images/vcss" 
       alt="Valid CSS!" />
 </a>
</p>

</body>

</html>
