blob: 2a3c0e2a6e190daef04a7164fe80dcbf1f41cf66 [file] [log] [blame]
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Converting Existing Ascape Models</title>
<link href="book.css" rel="stylesheet" type="text/css">
<meta content="DocBook XSL Stylesheets V1.75.1" name="generator">
<link rel="home" href="index.html" title="Agent Modeling Guide">
<link rel="up" href="Programer_Guide.html" title="Programer Guide">
<link rel="prev" href="Integrating_Java_and_AMF_Models.html" title="Integrating Java and AMF Models">
<link rel="next" href="Installation_Guide.html" title="Installation Guide">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<h1 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">Converting Existing Ascape Models</h1>
<div class="section" title="Converting Existing Ascape Models">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="Converting_Existing_Ascape_Models"></a>Converting Existing Ascape Models</h2>
</div>
</div>
</div>
<p>There are only a few changes should have to make to existing Ascape models or to use existing Ascape documentation to develop Escape models.</p>
<div class="section" title="Model">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Model"></a>Model</h3>
</div>
</div>
</div>
<p>The core model is completely API compatible. No changes!</p>
</div>
<div class="section" title="View">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="View"></a>View</h3>
</div>
</div>
</div>
<p>Because Escape uses SWT and Ascape uses Swing, there are a few unavoidable incompatibilities. Most of these we avoid by using higher level APIs but here are the key changes that you're likely to have to make:</p>
<div class="section" title="Convert the low-level imports from AWT and Swing to SWT">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Convert_the_low-level_imports_from_AWT_and_Swing_to_SWT"></a>Convert the low-level imports from AWT and Swing to SWT</h4>
</div>
</div>
</div>
<p>The simplest way to accomplish this is to remove all of the imports and then organize imports. For example:</p>
<div class="literallayout">
<p>java.awt.Color&nbsp;=&gt;&nbsp;org.eclipse.swt.graphics.Color<br>
java.awt.Graphics&nbsp;=&gt;&nbsp;org.eclipse.draw2d.Graphics<br>
</p>
</div>
<p>Then just do a global find for all of the imports and replace them with nothing. This is a great place for a regexp. Try:</p>
<div class="literallayout">
<p>find:&nbsp;import&nbsp;java\.awt\.(.*);<br>
replace:&nbsp;[nothing]<br>
</p>
</div>
<p>You don't have to replace these with the SWT equivalents, just click on the project, right-click and choose "Source:Organize Imports.."
By the way, a great way to avoid having to select the right entries in optimize imports and to alert you when you have missed anything is to prevent the awt and swing classes from being used at all. Right-click on project, choose "Build Path:Configure Build Path", go to Libraries tab, open JRE System Library, choose "Access Rules", edit, and then add entries for java/awt/** and javax/swing/**. The code will regenerate and you'll have error markers for all of the stuff that won't work with Escape and Eclipse.</p>
</div>
<div class="section" title="Convert color features">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Convert_color_features"></a>Convert color features</h4>
</div>
</div>
</div>
<p>You can't use AWT colors either so you'll need to replace any colors. AMP provides a convenience classes for Colors called ColorFeature and ColorFeatureConcrete. You can use these or any of the other ways to define SWT colors. For example:</p>
<div class="literallayout">
<p>Color.lightGray&nbsp;=&gt;&nbsp;ColorFeature.LIGHT_GRAY<br>
new&nbsp;Color(Math.min(1.0f,&nbsp;(float)&nbsp;(redEnergy&nbsp;+&nbsp;orangeEnergy)),&nbsp;(float)&nbsp;orangeEnergy&nbsp;*&nbsp;.8f,&nbsp;(float)&nbsp;blueEnergy)&nbsp;=&gt;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;ColorFeatureConcrete.create(Math.min(1.0f,&nbsp;(float)&nbsp;(redEnergy&nbsp;+&nbsp;orangeEnergy)),&nbsp;(float)&nbsp;orangeEnergy&nbsp;*&nbsp;.8f,&nbsp;(float)&nbsp;blueEnergy)<br>
</p>
</div>
</div>
<div class="section" title="Change agent color getters">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Change_agent_color_getters"></a>Change agent color getters</h4>
</div>
</div>
</div>
<p>If you've defined colors through overriding Agents as in most models, you'll need to change the method signature. You could just do a global replace for this one.</p>
<div class="literallayout">
<p>public&nbsp;Color&nbsp;getColor(&nbsp;=&gt;&nbsp;public&nbsp;Object&nbsp;getPlatformColor(<br>
</p>
</div>
</div>
<div class="section" title="Get rid of image features">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Get_rid_of_image_features"></a>Get rid of image features</h4>
</div>
</div>
</div>
<p>Escape doesn't support them. In practice they haven't been used a lot. At some point perhaps we'll have nice sprite support instead. :)</p>
<div class="literallayout">
<p>public&nbsp;Image&nbsp;getImage()&nbsp;{**}&nbsp;=&gt;&nbsp;""<br>
</p>
</div>
</div>
<div class="section" title="Modify usages of DrawFeatures">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Modify_usages_of_DrawFeatures"></a>Modify usages of DrawFeatures</h4>
</div>
</div>
</div>
<p>If you've created any of your own draw features, you'll need to change them slightly to accommodate the differences between the AWT and SWT / Draw2D APIs. This should be pretty straightforwrd. For example:</p>
<div class="literallayout">
<p>g.setColor(...<br>
g.fillOval(..<br>
becomes:<br>
g.setBackgroundColor(<br>
g.fillOval(..<br>
</p>
</div>
<p>That's about it, though it's probable that we've missed something. Please post a message on the amp newsgroup if you run into any other conversion issues.</p>
</div>
<div class="section" title="Configuration">
<div class="titlepage">
<div>
<div>
<h4 class="title">
<a name="Configuration"></a>Configuration</h4>
</div>
</div>
</div>
<p>Instead of using Ant, Escape has really nice support for parameterizing and testing models. See
<a class="ulink" href="/wiki/Experimenting_and_Testing" target="_new">Experimenting and Testing</a> (todo). If you do want to work with ant you will need to install the plugins from the Sourceforge download site. (These have dependencies that I didn't want to bother with going through the Eclipse IP process to get in. If for some reason you think these should be part of core Escape let Miles know and I'll take care of it.) Ant has not been tested for Escape so it's not even clear it will work.
</p>
</div>
</div>
</div>
</body>
</html>