tag:blogger.com,1999:blog-41724312235349188432024-03-13T06:05:45.374+02:00С Миру по БитуAnonymoushttp://www.blogger.com/profile/03043645254806539347noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-4172431223534918843.post-83497513739980393462010-08-27T03:46:00.000+03:002015-04-13T20:08:03.056+03:00ListView Multiple Selection 2After reading the post about <a href="http://fxexperience.com/2010/07/listview-multiple-selection/comment-page-1/#comment-9065">ListView Multiple Selection</a> I started integrating a new ListView it into my project, but in few minutes I figured out that there were no normal <q>key multiple selection</q> support. So, I decided to fix this problem.<br />
<h2>The problem</h2>At first I was thinking about overriding <strong>callActionForEvent(e:KeyEvent):Void</strong> method in <strong>com.sun.javafx.scene.control.behavior.ListViewBehavior</strong>, but I've found out that it's not so simple. After applying a new behavior for a <strong>ListView</strong> in <strong>ListViewSkin</strong> like this:<br />
<pre class="brush:jfx;">class ListSkin extends ListViewSkin {
override var behavior = ListBehavior{}
...
}
</pre>The ListView stops scrolling up/down if I use keys for navigation. I was thinking about putting some parameters in ListBehavior, but still no luck.<br />
<br />
<h2>Workaround</h2>As for workaround you'll need to put some extra code in <strong>MultiSelectListView</strong> class<br />
<pre class="brush:jfx;">override var onKeyPressed = function(e:KeyEvent):Void {
if ((e.code == KeyCode.VK_UP) or (e.code == KeyCode.VK_DOWN)
or (e.code == KeyCode.VK_PAGE_DOWN) or (e.code == KeyCode.VK_PAGE_UP)
or (e.code == KeyCode.VK_HOME) or (e.code == KeyCode.VK_END)) {
if (not e.controlDown and not e.shiftDown) {
delete selectedIndexes;
}
}
if (e.controlDown and e.code == KeyCode.VK_SPACE) {
def index:Integer = (e.node as List).focusedIndex;
if (-1 == Sequences.indexOf(selectedIndexes, index)) {
insert index into selectedIndexes;
} else {
delete index from selectedIndexes;
if (index == selectedIndex) select(selectedIndexes[0]);
}
}
}
</pre><br />
<h2>As a result</h2><ul><li>So, now you are able to use Ctrl+Space to add new selected items or remove old items from selection.</li>
<li>If you use keys such as: HOME, END, PAGE_UP, PAGE_DOWN, UP or DOWN without holding a Ctrl button multiple selection will be lost(I think it's user expected behavior :) )</li>
<li>I didn't do anything with <q>Shift</q> key. So, it does nothing.</li>
</ul><br />
<h2>Small fix</h2>The <a href="http://fxexperience.com/2010/07/listview-multiple-selection/comment-page-1/#comment-9065">ListView</a> by Jonathan Giles has a small bug, it's also about using keys for selecting items. In <strong>MultiSelectListCellBehavior</strong> class, he has a case for deselecting all previously selected items.<br />
<pre class="brush:jfx;">public class MultiSelectListCellBehavior extends ListCellBehavior {
...
override function mouseReleased(e) {
...
} else {
delete listView.selectedIndexes;
insert row into listView.selectedIndexes;
listView.focus(row);
}
}
}
</pre>As you can see in the end he used <strong>listView.focus(row);</strong> for selecting an item, but this stuff wont wok correctly. If you made some selection with the help of keys you'll get at least two selected items. So, I think it's better to use <strong>listView.select(row);</strong> instead.<br />
<br />
Have a nice code :)Anonymoushttp://www.blogger.com/profile/03043645254806539347noreply@blogger.com0tag:blogger.com,1999:blog-4172431223534918843.post-34905436835170048582010-08-23T15:09:00.000+03:002015-04-13T20:08:03.046+03:00Creating Pseudo-class in JavaFx (TabPanel control)Before reading this article I suggest to read <a href="http://pleasingsoftware.blogspot.com/2010/04/advanced-javafx-control-styling.html">Advanced JavaFX Control Styling</a> by Dean Iverson.<br />
After JavaFx 1.3 has been published we've got a new bunch of controls and a new way to produce our own ones and, of course, don't forget about new CSS support in this release. So, today I'm going to show you how to create your own JavaFx controls with CSS support.<br />
<br />
<h2>Specification</h2>Currently there are no tabs in JavaFx, and that's a good reason to start having them :). At the end I expect to get such a result:<br />
<img src="http://lh6.ggpht.com/_JbWSRLNTur0/THJP8838-SI/AAAAAAAAA6Q/gE7ZRiOEULA/TabPanel.png" /><br />
<h3>Specification itself:</h3><ul><li>TabPanel has TabButtons</li>
<li>You are able to select only one TabButton in TabPanel</li>
<li>You are able to set styles for TabButtons and TabPanel</li>
<li>TabButtons can be aligned inside TabPanel</li>
<li>TabButtons can fit TabPanel by width, height or both</li>
<li>TabPanel can set common width or height for TabButtons</li>
</ul><br />
<h2>Implementation</h2>I'm not going to explain all the code, but I'll stop in most interesting parts:<br />
<h3>Creating your own pseudo-class</h3>Each TabButton should have a status <b>selected</b> in order to display the button as selected and not to perform a click action on it.<br />
<pre class="brush:jfx; highlight: [4, 14]">public class TabButton extends ButtonBase, Labeled {
override var skin = SkinAdapter {
rootRegion:ButtonSkin{}
}
public var selected:Boolean = false on replace {
impl_pseudoClassStateChanged("selected");
}
override function impl_getPseudoClassState():String[] {
return [
if (selected) "selected" else null,
super.impl_getPseudoClassState()
]
}
}
</pre>This is just a piece of the TabButton class. As you can see, I use two functions <b>impl_pseudoClassStateChanged</b> and <b>impl_getPseudoClassState</b> that will help me to organize my pseudo-class &quote;selected&quote; for this control.<br />
Now let's take a look at the CSS file:<br />
<pre class="brush:css;">.tab-button {
-fx-padding: 3 10 2 10;
-fx-background-color: -fx-shadow-highlight-color, -fx-outer-border, -fx-inner-border, -fx-body-color;
-fx-background-radius: 10 10 0 0;
-fx-background-insets: 0 0 -1 0, 0, 1, 2;
-fx-border-radius: 10 10 0 0;
-fx-border-color: -fx-outer-border, -fx-inner-border;
-fx-border-style: solid;
-fx-text-fill: -fx-text-base-color;
-fx-vpos: CENTER;
-fx-graphic-vpos: CENTER;
}
.tab-button:hover {
-fx-color: -fx-hover-base;
}
.tab-button:selected {
-fx-color: -fx-pressed-base;
}
</pre>Please pay attention, that now I can use keyword <b>selected</b> as a name of the new pseudo-class for my control. Also I can use standard pseudo-classes of Button and Labeled controls cause I invoke a <b>super.impl_getPseudoClassState()</b> highlighted on line 14.<br />
Now look at line 4, in order not to write my own Skin class, for this control, I'm using an existing one.<br />
<br />
<h3>Source</h3>To download a full source code press <a href="https://docs.google.com/uc?id=0B-o587Z3NxZ9NDZjNmUzMDEtOTY1OS00ZjNmLTg2ZWEtM2RmMWI4NDUwZWQ5&export=download&hl=en">here</a><br />
<br />
Have a nice code :)Anonymoushttp://www.blogger.com/profile/03043645254806539347noreply@blogger.com4tag:blogger.com,1999:blog-4172431223534918843.post-88823940903901862822010-06-24T01:59:00.000+03:002015-04-13T20:08:03.059+03:00Binding Java model in JavaFx<p>All this time I was looking for a good solution of binding java model class to javafx UI. There are some articles about that and the most interesting, on my mind, is on <a href="http://blog.netopyr.com/2008/12/19/binding-java-objects-in-javafx-script/" target="_blank">Mike's Blog</a>, but it's seams like a lot of code to write and some of the examples are not working at all. There are also some frameworks for binding through aspects, but still it wasn't the way I want it to be.<br />
So, I think I found a nice solution, that is really easy to implement and to use.<br />
</p><br />
<h2>Making interfaces</h2><p>Let's make an interface for our future model. No rocket-science just getters and setters.</p><pre class="brush:java;">public interface TextModel {
public void setText(String text);
public String getText();
}
</pre><h2>Creating a JavaFx model</h2><p>There are some restrictions for using binding in javafx. One of them is that you can't pass a method in bind. for example:</p><pre class="brush:jfx;">Label {
text:bind model.getText() // wont work
}
</pre><p>For this reason we are going to create a javafx class, that implements our new interface and has a public field. It will helps us to use all the good binding stuff of javafx. After all we going to have a class that has a javafx property, that can be changed directly form java</p><pre class="brush:jfx;">public class JFxTextModel extends TextModel {
public var text:String;
public void setText(String text) {
this.text = text;
}
public String getText() {
return this.text;
}
}
</pre><p><i>For newbies in JavaFx, there is no <strong>implements</strong> option for implementing interfaces, we use <strong>extends</strong></i></p><p>Now we can move all our business login on Java side and leave only views and model as a bridge on JavaFx side</p><pre class="brush:jfx;">def model:JFxTextModel = JFxTextModel{};
Label {
text:bind model.text
}
</pre><h2>P.S.</h2>It's really useful to have getters in interfaces, cause you can retrieve data on Java side, leaving javafx only for displaying and effect.<br />
<br />
Have a nice code :)Anonymoushttp://www.blogger.com/profile/03043645254806539347noreply@blogger.com0tag:blogger.com,1999:blog-4172431223534918843.post-44193966862813845952010-02-22T02:08:00.000+02:002015-04-13T20:08:03.049+03:00Simple-XML with OSGi<p>For me these weekends was almost a final step of our project transformations with OSGi and of cause there were a lot of problems. One of these problems was that there are libraries that don't have bundle representation for OSGi systems. Thanks God, for me it was only the one library: <a href="http://simple.sourceforge.net/" target="_blank">Simple-XML</a>. So I had to recompile it using <a href="http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html" target="_blank">maven-bundle-plugin</a> from Apache.<br />
</p><br />
<h3>Steps to do it yourself:</h3><ol><li>Download sources from <a href="http://simple.sourceforge.net/download.php" target="_blank">here</a></li>
<li>Write a new pom.xml and package a new bundle</li>
</ol><br />
<p>Here is my pom.xml for this library:</p><pre class="brush:xml;"><project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.3</version>
<packaging>bundle</packaging>
<name>Simple XML</name>
<url>http://simple.sourceforge.net</url>
<description>Simple is a high performance XML serialization and configuration framework for Java</description>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<build>
<sourceDirectory>src/</sourceDirectory>
<finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.simpleframework.xml.*</Export-Package>
<Private-Package>org.simpleframework.xml.*</Private-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>stax</groupId>
<artifactId>stax</artifactId>
<version>1.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_core</artifactId>
<version>1.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_compendium</artifactId>
<version>1.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>
</project>
</pre><p>As you can see I've removed all the tests from my pom.xml. If you want to add tests to this project it's <strong>important</strong> to edit a <strong>testSourceDirectory</strong> in the same way as I did it with <strong>sourceDirectory</strong> cause by default maven search for src/main/java and sources for this project is just in src<br />
</p><br />
<h3>Downloads</h3><p>For those who don't want to mess with all this recompilation stuff here are links to download this bundle from my google-docs</p><ul><li><a href="http://docs.google.com/leaf?id=0B-o587Z3NxZ9NGNlNTZjZTItNGQxNy00NTZkLWIzYzItOTQ4OTYzY2MwYWIx&hl=en" target="_blank">org.simpleframework.simple-xml.2.3.jar</a></li>
<li><a href="http://docs.google.com/leaf?id=0B-o587Z3NxZ9YWI0MTFhMzQtZmM5NS00M2M4LWE4YTktNDVhZTczNDYyZjk3&hl=en" target="_blank">org.simpleframework.simple-xml-2.3.pom</a></li>
</ul><br />
<h3>Installation</h3><p>After you download it or do it yourself you'll need to install it in your local or companies repository. To do so simply invoke this line of code in your shell<br />
<code>mvn install:install-file -DgroupId=org.simpleframework -DartifactId=org.simpleframework.simple-xml -Dversion=2.3 -Dpackaging=jar -Dfile=org.simpleframework.simple-xml.2.3.jar<br />
</code><br />
</p><br />
<h3>Usage</h3><p>In your maven project you'll need to add these lines:<br />
</p><pre class="brush:xml;"><dependency>
<groupId>org.simpleframework</groupId>
<artifactId>org.simpleframework.simple-xml</artifactId>
<version>2.3</version>
</dependency>
</pre><br />
<h3>P.S.</h3><p>During all the time I was transfering my project to OSGi world I used <a href="http://www.springsource.com/repository/app/bundle" traget="_blank">THE GREATEST MAVEN BUNDLE REPOSITORY</a><br />
</p>Have a nice code :)Anonymoushttp://www.blogger.com/profile/03043645254806539347noreply@blogger.com4tag:blogger.com,1999:blog-4172431223534918843.post-74411601214027495142009-11-19T02:00:00.000+02:002015-04-13T20:08:03.051+03:00Flash Builder on LinuxGreat news for people who develop in Flex on Linux.<br />
A great person <a href="http://forums.adobe.com/people/feiy">feiy</a> made a breakthrough. After half a year of discussion on <a href="http://bugs.adobe.com/jira/browse/FB-19053">Abode Jira</a> <strong>THE feiy</strong> made a post:<br />
<q><i><br />
hi,don't waiting....<br />
this is a port version for linux:<br />
a project to port the Adobe Flash Builder to Linux<br />
<a href="http://code.google.com/p/fb4linux/">http://code.google.com/p/fb4linux/</a></i></q><br />
<p>So I took a try and here are the results:</p><br />
<h2>Installation</h2><ol><li>Download tar archive from <a href="http://218.65.19.25/wp-content/uploads/Adobe_Flash_Builder_Beta_2_For_Linux_Alpha1.tar.gz">here</a></li>
<li>Try to extract. <q style="color:#003366">So, I couldn't do it properly, so simply rename archive file to Adobe_Flash_Builder_Beta_2_For_Linux_Alpha1.tar, just remove .gz and then try <strong>tar -xvf [archive_name]</strong></q></li>
<li>After extraction you get a folder <strong>Adobe Flash Builder Beta 2 Linux Alpha1</strong> with <strong>eclipse</strong> folder inside</li>
<li>Copy all the files from this new <strong>eclipse</strong> folder to your eclipse folder</li>
</ol><br />
<p>Actually this is it for installation. Now everything should work.<br />
<br />
<a target="_blank" href="http://lh3.ggpht.com/_JbWSRLNTur0/SwSGpA9qqgI/AAAAAAAAAjw/SjY5MR9-gF8/s800/fb4linux.png"><img src="http://lh3.ggpht.com/_JbWSRLNTur0/SwSGpA9qqgI/AAAAAAAAAjw/SjY5MR9-gF8/s128/fb4linux.png" /></a></p><br />
<h2>Testing Flash Builder 4 under Linux</h2><p>During testing I had some problems:</p><h3>First problem with Flash Player and Flex 4</h3><p>So I installed flex 4 sdk, made a test project and tried to run it. I got an error about different version of Flash Player, so I have to set in properties of the project to use Falsh Player 10.0.0. To do so go to: <strong>Project Properties/Flex Compiler/Adobe Flash Player</strong> options, check <strong>Use specific version</strong>. After that you can compile and get to debug mode.</p><h3>Second problem with Flash Player</h3><p>I didn't solve it yet but I'm in the process. Each time when I'm try to start the project or get into debug it gives me an Alert window<br />
<br />
<img src="http://lh4.ggpht.com/_JbWSRLNTur0/SwSGpBpbDzI/AAAAAAAAAj0/Z-ZoZj9NA98/fpwarn.png" /></p><br />
<h2>General Impressions</h2><p>Sometimes eclipse gets stuck and I have to reload it. It happens on different operations, but I think it's just because it's beta version.<br />
<br />
Also the most important was the improvement in installation process. I think right now it's the correct one, so I don't need to run wizards to setup plugin for eclipse as it was with Flex Builder 3 alpha for Linux and as it is right now on Windows. I can install it once and then give it to someone else, this is a basic idea of eclipse (I think so).<br />
<br />
Anyway it's incredible to have flash builder 4 on linux, thanks a lot to <strong>feiy</strong>. I'll continue testing this version of builder and updating this post.</p><br />
<p>Have a nice code :)</p><br />
<h2>Update:</h2>November 21, 2009 - <a href="http://218.65.19.25/wp-content/uploads/FB4Linux_A2.tar.gz">Flash Builder Alpha 2</a><br />
<br />
<a href="http://code.google.com/p/fb4linux/wiki/WhatIsNewAlpha2">New features in Alpha 2</a>Anonymoushttp://www.blogger.com/profile/03043645254806539347noreply@blogger.com4tag:blogger.com,1999:blog-4172431223534918843.post-82581827889214075942009-09-07T16:52:00.000+03:002015-04-13T20:08:03.053+03:00Highlighting your code on Blogger.com<p>I don't know why but there is no plugin for highlighting code in blogger.com.<br />
Maybe I was searching in the wrong place but steel I've faced this problem and I'd like to share my solution.<br />
</p><br />
<p>First let's find a free, nice highlighter online. I'd like to say that this one <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter">http://alexgorbatchev.com/wiki/SyntaxHighlighter</a> is the most interesting I could found in Internet.<br />
</p><p>Then configure the layout of your page. Go to: Layout -> Edit HTML. In this section you'll have ability to change your html-template manually. All you need is to add some javascript and css files in the header. You can use my configuration.<br />
</p><pre class="brush:html"><script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushBash.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushPlain.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushXml.js' type='text/javascript'/>
<link href='http://alexgorbatchev.com/pub/sh/2.0.278/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/2.0.278/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script type='text/javascript'>
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.0.278/scripts/clipboard.swf&#39;;
SyntaxHighlighter.all();
</script>
<style type='text/css'>
.syntaxhighlighter div.line {
margin:0px;
}
</style>
</pre><br />
<p>This is for configuration.<br />
Now, how you should write your article?<br />
Where ever you'd like to insert a piece of code you need to use this element:</p><pre class="brush:html"><pre class="brush:html">
&lt;h2&gt;Hello world!&lt;/h2&gt;
</pre>
</pre><br />
The result is:<br />
<pre class="brush:html"><h2>Hello world!</h2>
</pre><br />
<p>If you need another language to use you need to change a attribute class. For example for <strong>java</strong> you need to set it in <strong><code>class="brush:java"</code></strong>.</p><br />
<p>Another cool feature is a string-highlighting. To do so you need to add string in class attribute of <strong>pre</strong> element. For example I need to highlight a 2-nd line of code, just type <strong><code>highlight: [2]</code></strong>. To highlight more then 1 line of code just use comma to separate the lines numbers <strong><code>highlight: [10, 11, 12, 13, 14]</code></strong></p><br />
<p>An example with highlighting of lines 9 and 11</p><pre class="brush:java;highlight: [9,11];">package ua.ekta.observer.bean.basis;
import java.util.List;
import ua.ekta.observer.bean.IBean;
import ua.ekta.observer.persistence.system.IDomain;
public interface IBasisManager extends IBean {
IDomain detectDomain(String url);
List<IDomain> loadBases();
void clearBases();
}
</pre><br />
Have a nice code :)Anonymoushttp://www.blogger.com/profile/03043645254806539347noreply@blogger.com0tag:blogger.com,1999:blog-4172431223534918843.post-17034085960833272262009-07-21T13:26:00.001+03:002015-04-13T20:08:03.043+03:00Compiling Flex with Maven 2 (Flexmojos)Over several months I've been compiling my flex applications using Ant and Adobe Flex-Tasks, but here comes a day when our company decides to use Maven. So here is my advice for those who happened to find themselves in the same situation.<br />
<span style="font-size: 100%;"><br />
For now</span><span style="font-size: 100%;"> flex is not very popular in maven</span><span style="font-weight: bold;"> </span>community and there are not so many repositories for flex libraries and plugins as well. So I'd like to recommend a great plugin for maven to compile flex applications - <a href="http://flexmojos.sonatype.org/">Flexmojos</a> from <a href="http://www.sonatype.com/">Sonatype</a>. It's well documented, supporting flex 2-4 versions, rsl, modules, localization and has it's own repositories.<br />
<br />
For those who haven't work with maven at all, I strongly recommend to read <a href="http://www.sonatype.com/maven/documentation/download-book?file=books/maven-definitive-guide.pdf">this book</a> at least first two chapters to understand the philosophy of maven. For those who think that he or she is a God of maven then I recommend to read the same book from chapter 17.<br />
<br />
As for me I like to use maven as much as possible. So first I'll create a folder structure for our flex project. For this action maven has a great plugin <span style="font-style: italic;">archetype</span> that will create a folder structure and necessary <span style="font-style: italic;">pom.xml</span> files for you.<br />
<br />
Flexmojos has its own archetypes for flex application, so here they are:<br />
<br />
<span style="font-weight: bold;">Create library:</span><br />
<span style="font-style: italic;">mvn archetype:generate -DarchetypeRepository=http://repository.sonatype.org/content/groups/public -DarchetypeGroupId=org.sonatype.flexmojos -DarchetypeArtifactId=flexmojos-archetypes-library -DarchetypeVersion=3.2.0</span><br />
<br />
<span style="font-weight: bold;">Create application:</span><br />
<span style="font-style: italic;">mvn archetype:generate -DarchetypeRepository=http://repository.sonatype.com/content/groups/public -DarchetypeGroupId=org.sonatype.flexmojos -DarchetypeArtifactId=flexmojos-archetypes-application -DarchetypeVersion=3.2.0</span><br />
<br />
<span style="font-weight: bold;">Create modular application:</span><br />
<span style="font-style: italic;">mvn archetype:generate -DarchetypeRepository=http://repository.sonatype.org/content/groups/public -DarchetypeGroupId=org.sonatype.flexmojos -DarchetypeArtifactId=flexmojos-archetypes-modular-webapp -DarchetypeVersion=3.2.0</span><br />
<br />
We will use the second one <span style="font-style: italic;">flexmojos-archetype-application</span> to create a simple flex application. To run this archetype simply copy it from post and past into a shell. You'll need to answer some questions before the plugin will create you a folder structure. If everything was good you'll be able to have such a screen.<br />
<br />
<a href="http://3.bp.blogspot.com/_JbWSRLNTur0/Spg1gG4IDSI/AAAAAAAAAf0/Qyas2pAmOmc/s1600-h/maven-archetype.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5375104980984794402" src="http://3.bp.blogspot.com/_JbWSRLNTur0/Spg1gG4IDSI/AAAAAAAAAf0/Qyas2pAmOmc/s320/maven-archetype.png" style="cursor: pointer; display: block; height: 207px; margin: 0px auto 10px; text-align: center; width: 320px;" /></a>If you haven't installed Flexmojos yet, maven will do it automatically.<br />
Now let's take a look at the folder structure that maven has created for us.<br />
<a href="http://1.bp.blogspot.com/_JbWSRLNTur0/Spg5alUYsiI/AAAAAAAAAf8/-6oRtnp2Vqs/s1600-h/flexmojos-folder-structure.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5375109284123685410" src="http://1.bp.blogspot.com/_JbWSRLNTur0/Spg5alUYsiI/AAAAAAAAAf8/-6oRtnp2Vqs/s320/flexmojos-folder-structure.png" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 305px;" /></a>So, all your code goes to src/main/flex folder. In this folder you should create your packages and write your code. As you see Flexmojos already has created the main application file Main.mxml. Also there is a test folder for all your tests: src/test/flex/{groupId}, so you can write tests for your application.<br />
But the most interesting part is <span style="font-style: italic;">pom.xml</span>. Let's take a look.<br />
<pre class="brush:xml;"><project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ua.com.xoas</groupId>
<artifactId>testapp</artifactId>
<version>1.0</version>
<packaging>swf</packaging>
<name>testapp Flex</name>
<build>
<sourceDirectory>src/main/flex</sourceDirectory>
<testSourceDirectory>src/test/flex</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.2.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>3.2.0.3958</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-unittest-support</artifactId>
<version>3.2.0</version>
<type>swc</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
</pre><br />
If you need to configure your build simply add a configuration element inside of the build element, like this:<br />
<br />
<pre class="brush:xml;highlight: [10, 11, 12, 13, 14];"><build>
<sourceDirectory>src/main/flex</sourceDirectory>
<testSourceDirectory>src/test/flex</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.2.0</version>
<extensions>true</extensions>
<configuration>
<!-- put your configuration options here -->
<debug>true</debug>
<allowSourcePathOverlap>true</allowSourcePathOverlap>
</configuration>
</plugin>
</plugins>
</build>
</pre><br />
I've added two more options to build:<br />
<span style="font-style: italic;">debug</span> - Turn on generation of debuggable SWFs.<br />
<span style="font-style: italic;">allowSourcePathOverlap</span> - Allow the source-path to have path-elements which contain other path-elements.<br />
Use this <a href="http://sites.sonatype.org/flexmojos/flexmojos-maven-plugin/compile-swf-mojo.html">link</a> to get a list of available configuration options.<br />
<br />
To compile this application you'll need to run: <span style="font-style: italic;">mvn install -DflashPlayer.command=</span>{path to flexplayer} (path to flashplayer is required otherwise you'll get an error during test phase) If you want to skip test phase run this: <span style="font-style: italic;">mvn install -Dmaven.test.skip=true</span><br />
<br />
The last thing I'd like to pay your attention to is <span style="font-style: italic;">dependencies</span> element. One of the pros of the Flexmojos is that you don't have to install flex-sdk - it will be downloaded automatically and all you need is to add a dependency, in "<span style="font-weight: bold;">maven style</span>", to flex-sdk.<br />
<pre class="brush:xml;"><dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>3.2.0.3958</version>
<type>pom</type>
</dependency>
</pre><span style="font-size: 130%;"><span style="font-weight: bold;">P.S.</span></span><br />
Great documentation, great support makes Flexmojos the best plugin for maven to compile flex application.<br />
<br />
Almost forgot: use <span style="font-style: italic;">flexmojos:flexbuilder</span> goal to configure environment files for flexbuilder.<br />
<br />
Have a nice code :)Anonymoushttp://www.blogger.com/profile/03043645254806539347noreply@blogger.com15