japi-cvs Mailing List for JAPI (Page 29)
Status: Beta
Brought to you by:
christianhujer
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
(115) |
May
(11) |
Jun
(5) |
Jul
(2) |
Aug
(10) |
Sep
(35) |
Oct
(14) |
Nov
(49) |
Dec
(27) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(57) |
Feb
(1) |
Mar
|
Apr
(2) |
May
(25) |
Jun
(134) |
Jul
(76) |
Aug
(34) |
Sep
(27) |
Oct
(5) |
Nov
|
Dec
(1) |
| 2008 |
Jan
(3) |
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(63) |
Nov
(30) |
Dec
(43) |
| 2009 |
Jan
(10) |
Feb
(420) |
Mar
(67) |
Apr
(3) |
May
(61) |
Jun
(21) |
Jul
(19) |
Aug
|
Sep
(6) |
Oct
(16) |
Nov
(1) |
Dec
|
| 2010 |
Jan
(1) |
Feb
|
Mar
|
Apr
(7) |
May
(3) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
|
From: <chr...@us...> - 2008-11-30 16:21:40
|
Revision: 710
http://japi.svn.sourceforge.net/japi/?rev=710&view=rev
Author: christianhujer
Date: 2008-11-30 16:21:35 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Updated JWGet.
Modified Paths:
--------------
tools/jwget/trunk/src/prj/net/sf/japi/jwget/JWGet.java
Added Paths:
-----------
tools/jwget/trunk/build.xml
Added: tools/jwget/trunk/build.xml
===================================================================
--- tools/jwget/trunk/build.xml (rev 0)
+++ tools/jwget/trunk/build.xml 2008-11-30 16:21:35 UTC (rev 710)
@@ -0,0 +1,226 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ DirCount is a program for converting Strings into byte arrays.
+ ~ Copyright (C) 2007 Christian Hujer
+ ~
+ ~ This program is free software; you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation; either version 2 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License along
+ ~ with this program; if not, write to the Free Software Foundation, Inc.,
+ ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ -->
+
+<project name="dircount" default="compile">
+
+ <property name="module.version" value="0.1" />
+ <property name="module.name" value="dircount" />
+ <property name="module.shortname" value="dircount" />
+ <property name="module.title" value="DirCount" />
+ <property name="main.class" value="net.sf.japi.dircount.DirCount" />
+
+ <taskdef name="pack200" classpath="common/antlib/Pack200Task.jar" classname="com.sun.tools.apache.ant.pack200.Pack200Task" />
+
+ <target
+ name = "clean"
+ description = "Cleans Sandbox"
+ >
+ <delete dir="classes" />
+ <delete dir="docs" />
+ </target>
+
+ <target
+ name = "compile"
+ description = "Compiles production classes"
+ >
+ <mkdir dir="classes/production/${module.shortname}" />
+ <mkdir dir="classes/test/${module.shortname}" />
+ <javac
+ srcdir="src/prj"
+ destdir="classes/production/${module.shortname}"
+ encoding="utf-8"
+ source="1.5"
+ target="1.5"
+ >
+ <classpath>
+ <fileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <fileset dir="common/lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ </classpath>
+ <exclude name="test/**/*.java" />
+ </javac>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="src/prj" includes="**/*.properties" excludes="test/**/*.properties" />
+ <fileset dir="src/prj" includes="META-INF/services/**" />
+ </copy>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="lib" includes="LICENSE-*" />
+ <fileset dir="." includes="COPYING" />
+ </copy>
+ </target>
+
+ <target
+ name = "dist"
+ description = "Packs distribution archives."
+ depends = "clean, compile"
+ >
+ <!--depends = "clean, compile, doc"
+ -->
+ <delete dir="dist" />
+ <mkdir dir="dist" />
+ <property name="distName" value="dist/${module.name}-${module.version}" />
+ <parallel>
+ <tar tarfile="${distName}.src.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.src.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.src.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </jar>
+ <jar destfile="${distName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" />
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ <tar tarfile="${distName}.doc.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.doc.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.doc.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ </zipfileset>
+ </jar>
+ </parallel>
+ <parallel>
+ <gzip src="${distName}.src.tar" destfile="${distName}.src.tar.gz" />
+ <bzip2 src="${distName}.src.tar" destfile="${distName}.src.tar.bz2" />
+ <gzip src="${distName}.doc.tar" destfile="${distName}.doc.tar.gz" />
+ <bzip2 src="${distName}.doc.tar" destfile="${distName}.doc.tar.bz2" />
+ <pack200
+ src="${distName}.jar"
+ destfile="${distName}.pack.gz"
+ gzipoutput="true"
+ stripdebug="true"
+ effort="9"
+ keepfileorder="false"
+ modificationtime="latest"
+ deflatehint="false"
+ />
+ </parallel>
+ <delete file="${distName}.src.tar" />
+ <delete file="${distName}.doc.tar" />
+ </target>
+
+ <target
+ name = "doc"
+ description = "Creates public javadoc documentation."
+ >
+ <mkdir dir="docs/api" />
+ <!--copy todir="docs/api" file="src/doc/api/public/copyright.html" />
+ <copy todir="docs/api" file="src/doc/api/public/.htaccess" /-->
+ <javadoc
+ destdir = "docs/api"
+ access = "protected"
+ author = "yes"
+ version = "yes"
+ locale = "en_US"
+ use = "yes"
+ splitindex = "yes"
+ windowtitle = "JAPI Library ${module.title} ${module.version} API documentation"
+ doctitle = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ header = "JAPI Library ${module.title} ${module.version}<br />API Documentation"
+ footer = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ bottom = "<div style=" text-align:center;">© 2005-2006 Christian Hujer. All rights reserved. See <a href="{@docRoot}/copyright.html">copyright</a></div>"
+ serialwarn = "yes"
+ charset = "utf-8"
+ docencoding = "utf-8"
+ encoding = "utf-8"
+ source = "1.5"
+ linksource = "yes"
+ link = "${user.javadoc.link}"
+ >
+ <!--
+ overview = "src/overview.html"
+ -->
+ <classpath>
+ <fileset dir="lib" includes="annotations.jar" />
+ </classpath>
+ <sourcepath>
+ <pathelement path="${user.javadoc.javasrc}" />
+ <pathelement path="src/prj" />
+ </sourcepath>
+ <packageset
+ dir="src/prj"
+ defaultexcludes="yes"
+ >
+ <include name="net/**" />
+ </packageset>
+ <tag enabled="true" name="retval" description="Return Values:" scope="methods" />
+ <tag enabled="true" name="pre" description="Preconditions:" scope="methods,constructors" />
+ <tag enabled="true" name="post" description="Postconditions:" scope="methods" />
+ <tag enabled="true" name="invariant" description="Invariant:" scope="methods,fields" />
+ <tag enabled="true" name="note" description="Notes:" />
+ <tag enabled="true" name="warning" description="Warnings:" />
+ <!--tag enabled="true" name="todo" description="Todo:" /-->
+ <taglet name="com.sun.tools.doclets.ToDoTaglet" path="" />
+ <tag enabled="true" name="fixme" description="Fixme:" />
+ <tag enabled="true" name="xxx" description="XXX:" />
+ </javadoc>
+ </target>
+
+ <target
+ name = "buildapp"
+ description = "Creates executable jar"
+ >
+ <property name="appName" value="${module.name}-${module.version}-app" />
+ <jar destfile="${appName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <zipgroupfileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <!--attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" /-->
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ </target>
+
+</project>
Property changes on: tools/jwget/trunk/build.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Modified: tools/jwget/trunk/src/prj/net/sf/japi/jwget/JWGet.java
===================================================================
--- tools/jwget/trunk/src/prj/net/sf/japi/jwget/JWGet.java 2008-11-30 16:19:15 UTC (rev 709)
+++ tools/jwget/trunk/src/prj/net/sf/japi/jwget/JWGet.java 2008-11-30 16:21:35 UTC (rev 710)
@@ -32,8 +32,7 @@
import net.sf.japi.io.args.LogCommand;
import org.jetbrains.annotations.NotNull;
-/**
- * WGet implementation in Java.
+/** WGet implementation in Java.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
public class JWGet extends LogCommand {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-11-30 16:19:17
|
Revision: 709
http://japi.svn.sourceforge.net/japi/?rev=709&view=rev
Author: christianhujer
Date: 2008-11-30 16:19:15 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Added tool mail.
Added Paths:
-----------
tools/mail/
tools/mail/branches/
tools/mail/tags/
tools/mail/trunk/
tools/mail/trunk/build.xml
tools/mail/trunk/lib/
tools/mail/trunk/lib/annotations.jar
tools/mail/trunk/lib/japi-lib-argparser-trunk.jar
tools/mail/trunk/mail.iml
tools/mail/trunk/src/
tools/mail/trunk/src/doc/
tools/mail/trunk/src/prj/
tools/mail/trunk/src/prj/net/
tools/mail/trunk/src/prj/net/sf/
tools/mail/trunk/src/prj/net/sf/japi/
tools/mail/trunk/src/prj/net/sf/japi/tools/
tools/mail/trunk/src/prj/net/sf/japi/tools/mail/
tools/mail/trunk/src/prj/net/sf/japi/tools/mail/Mail.java
tools/mail/trunk/src/prj/net/sf/japi/tools/mail/Mail.properties
tools/mail/trunk/src/prj/net/sf/japi/tools/mail/PingPongSession.java
tools/mail/trunk/src/tst/
Added: tools/mail/trunk/build.xml
===================================================================
--- tools/mail/trunk/build.xml (rev 0)
+++ tools/mail/trunk/build.xml 2008-11-30 16:19:15 UTC (rev 709)
@@ -0,0 +1,228 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Replacer is a program for performing an in-place search and replace
+ ~ based on regular expressions.
+ ~ Copyright (C) 2007 Christian Hujer
+ ~
+ ~ This program is free software; you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation; either version 2 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License along
+ ~ with this program; if not, write to the Free Software Foundation, Inc.,
+ ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ -->
+
+<project name="ArchStat" default="compile">
+
+ <property name="module.version" value="0.1" />
+ <property name="module.name" value="JapiMail" />
+ <property name="module.shortname" value="JapiMail" />
+ <property name="module.title" value="JapiMail" />
+ <property name="main.class" value="net.sf.japi.tools.mail.Mail" />
+
+ <taskdef name="pack200" classpath="common/antlib/Pack200Task.jar" classname="com.sun.tools.apache.ant.pack200.Pack200Task" />
+
+ <target
+ name = "clean"
+ description = "Cleans Sandbox"
+ >
+ <delete dir="classes" />
+ <delete dir="docs" />
+ </target>
+
+ <target
+ name = "compile"
+ description = "Compiles production classes"
+ >
+ <mkdir dir="classes/production/${module.shortname}" />
+ <mkdir dir="classes/test/${module.shortname}" />
+ <javac
+ srcdir="src/prj"
+ destdir="classes/production/${module.shortname}"
+ encoding="utf-8"
+ source="1.5"
+ target="1.5"
+ >
+ <classpath>
+ <fileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <fileset dir="common/lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ </classpath>
+ <exclude name="test/**/*.java" />
+ </javac>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="src/prj" includes="**/*.properties" excludes="test/**/*.properties" />
+ <fileset dir="src/prj" includes="**/*.xml" excludes="test/**/*.xml" />
+ <fileset dir="src/prj" includes="META-INF/services/**" />
+ </copy>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="lib" includes="LICENSE-*" />
+ <fileset dir="." includes="COPYING" />
+ </copy>
+ </target>
+
+ <target
+ name = "dist"
+ description = "Packs distribution archives."
+ depends = "clean, compile"
+ >
+ <!--depends = "clean, compile, doc"
+ -->
+ <delete dir="dist" />
+ <mkdir dir="dist" />
+ <property name="distName" value="dist/${module.name}-${module.version}" />
+ <parallel>
+ <tar tarfile="${distName}.src.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.src.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.src.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </jar>
+ <jar destfile="${distName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" />
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ <tar tarfile="${distName}.doc.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.doc.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.doc.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ </zipfileset>
+ </jar>
+ </parallel>
+ <parallel>
+ <gzip src="${distName}.src.tar" destfile="${distName}.src.tar.gz" />
+ <bzip2 src="${distName}.src.tar" destfile="${distName}.src.tar.bz2" />
+ <gzip src="${distName}.doc.tar" destfile="${distName}.doc.tar.gz" />
+ <bzip2 src="${distName}.doc.tar" destfile="${distName}.doc.tar.bz2" />
+ <pack200
+ src="${distName}.jar"
+ destfile="${distName}.pack.gz"
+ gzipoutput="true"
+ stripdebug="true"
+ effort="9"
+ keepfileorder="false"
+ modificationtime="latest"
+ deflatehint="false"
+ />
+ </parallel>
+ <delete file="${distName}.src.tar" />
+ <delete file="${distName}.doc.tar" />
+ </target>
+
+ <target
+ name = "doc"
+ description = "Creates public javadoc documentation."
+ >
+ <mkdir dir="docs/api" />
+ <!--copy todir="docs/api" file="src/doc/api/public/copyright.html" />
+ <copy todir="docs/api" file="src/doc/api/public/.htaccess" /-->
+ <javadoc
+ destdir = "docs/api"
+ access = "protected"
+ author = "yes"
+ version = "yes"
+ locale = "en_US"
+ use = "yes"
+ splitindex = "yes"
+ windowtitle = "JAPI Library ${module.title} ${module.version} API documentation"
+ doctitle = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ header = "JAPI Library ${module.title} ${module.version}<br />API Documentation"
+ footer = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ bottom = "<div style=" text-align:center;">© 2005-2006 Christian Hujer. All rights reserved. See <a href="{@docRoot}/copyright.html">copyright</a></div>"
+ serialwarn = "yes"
+ charset = "utf-8"
+ docencoding = "utf-8"
+ encoding = "utf-8"
+ source = "1.5"
+ linksource = "yes"
+ link = "${user.javadoc.link}"
+ >
+ <!--
+ overview = "src/overview.html"
+ -->
+ <classpath>
+ <fileset dir="lib" includes="annotations.jar" />
+ </classpath>
+ <sourcepath>
+ <pathelement path="${user.javadoc.javasrc}" />
+ <pathelement path="src/prj" />
+ </sourcepath>
+ <packageset
+ dir="src/prj"
+ defaultexcludes="yes"
+ >
+ <include name="net/**" />
+ </packageset>
+ <tag enabled="true" name="retval" description="Return Values:" scope="methods" />
+ <tag enabled="true" name="pre" description="Preconditions:" scope="methods,constructors" />
+ <tag enabled="true" name="post" description="Postconditions:" scope="methods" />
+ <tag enabled="true" name="invariant" description="Invariant:" scope="methods,fields" />
+ <tag enabled="true" name="note" description="Notes:" />
+ <tag enabled="true" name="warning" description="Warnings:" />
+ <!--tag enabled="true" name="todo" description="Todo:" /-->
+ <taglet name="com.sun.tools.doclets.ToDoTaglet" path="" />
+ <tag enabled="true" name="fixme" description="Fixme:" />
+ <tag enabled="true" name="xxx" description="XXX:" />
+ </javadoc>
+ </target>
+
+ <target
+ name = "buildapp"
+ description = "Creates executable jar"
+ >
+ <property name="appName" value="${module.name}-${module.version}-app" />
+ <jar destfile="${appName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <zipgroupfileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <!--attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" /-->
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ </target>
+
+</project>
Property changes on: tools/mail/trunk/build.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: tools/mail/trunk/lib/annotations.jar
===================================================================
(Binary files differ)
Property changes on: tools/mail/trunk/lib/annotations.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: tools/mail/trunk/lib/japi-lib-argparser-trunk.jar
===================================================================
(Binary files differ)
Property changes on: tools/mail/trunk/lib/japi-lib-argparser-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: tools/mail/trunk/mail.iml
===================================================================
--- tools/mail/trunk/mail.iml (rev 0)
+++ tools/mail/trunk/mail.iml 2008-11-30 16:19:15 UTC (rev 709)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/doc" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/prj" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/tst" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module" module-name="libs-argparser" />
+ <orderEntry type="library" name="annotations" level="project" />
+ <orderEntryProperties />
+ </component>
+</module>
+
Property changes on: tools/mail/trunk/mail.iml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: tools/mail/trunk/src/prj/net/sf/japi/tools/mail/Mail.java
===================================================================
--- tools/mail/trunk/src/prj/net/sf/japi/tools/mail/Mail.java (rev 0)
+++ tools/mail/trunk/src/prj/net/sf/japi/tools/mail/Mail.java 2008-11-30 16:19:15 UTC (rev 709)
@@ -0,0 +1,146 @@
+package net.sf.japi.tools.mail;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.Socket;
+import java.util.Arrays;
+import java.util.List;
+import net.sf.japi.io.args.ArgParser;
+import net.sf.japi.io.args.BasicCommand;
+import net.sf.japi.io.args.Option;
+import net.sf.japi.io.args.OptionType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** A very simple and primitive mail command.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class Mail extends BasicCommand {
+
+ /** The default welcome name. */
+ private static final String DEFAULT_HELO_NAME = "JapiMail";
+
+ /** The default port. */
+ private static final int DEFAULT_PORT = 25;
+
+ /** The sender. */
+ private String from;
+
+ /** The welcome name. */
+ private String heloName = DEFAULT_HELO_NAME;
+
+ /** The smtp server to communicate with. */
+ private String server;
+
+ /** The port. */
+ private int port = DEFAULT_PORT;
+
+ /** Whether or not to print debug messages. */
+ private boolean debug;
+
+ /** Whether or not to use simple smtp instead of enhanced smtp. */
+ private boolean simple;
+
+ /** The msg to send.
+ * Maybe <code>null</code> which means the message will be read from stdin.
+ */
+ @Nullable private String msg;
+
+ /** Main program.
+ * @param args Command line arguments (try --help)
+ */
+ public static void main(final String... args) {
+ ArgParser.simpleParseAndRun(new Mail(), args);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings({"InstanceMethodNamingConvention"})
+ public int run(@NotNull final List<String> args) throws IOException {
+ final PingPongSession session = new PingPongSession(new Socket(server, port));
+ session.setDebug(debug);
+ try {
+ session.waitFor("220");
+ session.sendAndWait((simple ? "HELO" : "EHLO") + " " + heloName, "250");
+ session.sendAndWait("MAIL from: " + from, "250");
+ for (final String arg : args) {
+ session.sendAndWait("RCPT to: " + arg, "250");
+ }
+ session.sendAndWait("DATA", "354");
+ if (msg == null) {
+ final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ for (String line; (line = in.readLine()) != null && !".".equals(line);) {
+ session.send(line);
+ }
+ } else {
+ session.send(msg);
+ }
+ session.sendAndWait(".", "250");
+ session.sendAndWait("QUIT", "221");
+ } finally {
+ session.close();
+ }
+ return 0;
+ }
+
+
+ /** Sets the server.
+ * @param server Server.
+ */
+ @Option(type = OptionType.REQUIRED, value = {"s", "server"})
+ public void setServer(@NotNull final String server) {
+ this.server = server;
+ }
+
+ /** Sets the port.
+ * @param port Port.
+ */
+ @Option({"p", "port"})
+ public void setPort(@Nullable final Integer port) {
+ this.port = port != null ? port : DEFAULT_PORT;
+ }
+
+ /** Sets the sender.
+ * @param from The sender.
+ */
+ @Option(type = OptionType.REQUIRED, value = {"f", "from"})
+ public void setFrom(@NotNull final String from) {
+ this.from = from;
+ }
+
+ /** Turns on debugging. */
+ @Option({"d", "debug"})
+ public void setDebug() {
+ debug = true;
+ }
+
+ /** Turns off enhanced smtp. */
+ @Option({"simple"})
+ public void setSimple() {
+ simple = true;
+ }
+
+ /** Sets the message to send.
+ * @param msg Message to send (without trailing "." line).
+ */
+ public void setMsg(@Nullable final String msg) {
+ this.msg = msg;
+ }
+
+ /** Send mail.
+ * @param server Server address.
+ * @param port Server port.
+ * @param from Sender address.
+ * @param msg Message to send (without trailing "." line).
+ * @param rcpts Recipient addresses.
+ * @throws IOException in case of I/O problems.
+ */
+ public static void sendMail(@NotNull final String server, final int port, @NotNull final String from, @NotNull final String msg, @NotNull final String... rcpts) throws IOException {
+ final Mail mail = new Mail();
+ mail.setServer(server);
+ mail.setPort(port);
+ mail.setFrom(from);
+ mail.setMsg(msg);
+ mail.run(Arrays.asList(rcpts));
+ }
+}
Property changes on: tools/mail/trunk/src/prj/net/sf/japi/tools/mail/Mail.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/mail/trunk/src/prj/net/sf/japi/tools/mail/Mail.properties
===================================================================
--- tools/mail/trunk/src/prj/net/sf/japi/tools/mail/Mail.properties (rev 0)
+++ tools/mail/trunk/src/prj/net/sf/japi/tools/mail/Mail.properties 2008-11-30 16:19:15 UTC (rev 709)
@@ -0,0 +1,9 @@
+setFrom=Sender address, e.g. you...@yo....
+setServer=SMTP server, e.g. mail.yourcompany.com.
+setPort=SMTP server port, defaults to 25.
+setDebug=Enables debug log (prints each line send and received).
+setSimple=Switches from enhanced smtp to simple smtp (only changes EHLO to HELO, nothing else yet).
+helpHeader=JapiMail [OPTION...] [RECEIVER...]\nSends email.\nVery primitive. Does not support anything more than sending plain mail. No encoding, no attachment, no nothing.
+helpFooter=Example: JapiMail -f ern...@yo... -s mail.yourcompany.com ti...@yo... sa...@yo... <mail.txt\n\
+ Do not forget to specify a subject. The first line of your mail should be:\n\
+ Subject: The subject
Property changes on: tools/mail/trunk/src/prj/net/sf/japi/tools/mail/Mail.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/mail/trunk/src/prj/net/sf/japi/tools/mail/PingPongSession.java
===================================================================
--- tools/mail/trunk/src/prj/net/sf/japi/tools/mail/PingPongSession.java (rev 0)
+++ tools/mail/trunk/src/prj/net/sf/japi/tools/mail/PingPongSession.java 2008-11-30 16:19:15 UTC (rev 709)
@@ -0,0 +1,166 @@
+package net.sf.japi.tools.mail;
+
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.Socket;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** A PingPongSession is a session for simple ping pong protocols like SMTP.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class PingPongSession implements Closeable {
+
+ /** The Socket to communicate with. */
+ private final Socket socket;
+
+ /** The Reader to read from. */
+ private final BufferedReader sin;
+
+ /** The Writer to write to. */
+ private final PrintWriter sout;
+
+ /** Whether or not to print debug messages. */
+ private boolean debug;
+
+ /** The debug stream. */
+ private PrintStream err = System.err;
+
+ /** Establishes a PingPong session.
+ * @param socket Socket for which to establish a PingPong session.
+ * @throws IOException in case of I/O problems when connecting the streams of the socket.
+ */
+ public PingPongSession(@NotNull final Socket socket) throws IOException {
+ this(socket.getInputStream(), socket.getOutputStream(), socket);
+ }
+
+ /** Establishes a PingPong session.
+ * @param in InputStream to communicate with.
+ * @param out OutputStream to communicate with.
+ * @throws IOException in case of I/O problems when connecting the streams of the socket.
+ */
+ public PingPongSession(@NotNull final InputStream in, @NotNull final OutputStream out) throws IOException {
+ this(in, out, null);
+ }
+
+ /** Establishes a PingPong session.
+ * @param in InputStream to communicate with.
+ * @param out OutputStream to communicate with.
+ */
+ public PingPongSession(@NotNull final Reader in, @NotNull final Writer out) {
+ this(in, out, null);
+ }
+
+ /** Establishes a PingPong session.
+ * @param in InputStream to communicate with.
+ * @param out OutputStream to communicate with.
+ * @param socket Socket to communicate with.
+ * @throws IOException in case of I/O problems when connecting the streams of the socket.
+ */
+ public PingPongSession(@NotNull final InputStream in, @NotNull final OutputStream out, @Nullable final Socket socket) throws IOException {
+ this(new InputStreamReader(in, "ASCII"), new OutputStreamWriter(out, "ASCII"), socket);
+ }
+
+ /** Establishes a PingPong session.
+ * @param in Reader to communicate with.
+ * @param out Writer to communicate with.
+ * @param socket Socket to communicate with.
+ */
+ public PingPongSession(@NotNull final Reader in, @NotNull final Writer out, @Nullable final Socket socket) {
+ sin = in instanceof BufferedReader ? (BufferedReader) in : new BufferedReader(in);
+ sout = new PrintWriter(out, true);
+ this.socket = socket;
+ }
+
+ /** Sets whether or not to print debug messages.
+ * @param debug <code>true</code> if debug messages are desired, otherwise <code>false</code>.
+ */
+ public void setDebug(final boolean debug) {
+ this.debug = debug;
+ }
+
+ /** Returns whether or not debug messages are printed.
+ * @return <code>true</code> if debug messages are printed, otherwise <code>false</code>.
+ */
+ public boolean isDebug() {
+ return debug;
+ }
+
+ /** Sets the Stream to which debug messages are printed.
+ * @param err Stream to which debug messages are printed.
+ */
+ public void setErr(@NotNull final PrintStream err) {
+ this.err = err;
+ }
+
+ /** Returns the Stream to which debug messages are printed.
+ * @return Stream to which debug messages are printed.
+ */
+ public PrintStream getErr() {
+ return err;
+ }
+
+ /** Sends a line of text to the SMTP server, expecting an answer with a specific SMTP return code.
+ * @param line Line to send.
+ * @param returnCode Return code to wait for after sending the line.
+ * @throws IOException in case of I/O problems or the expected return code was not received.
+ */
+ public void sendAndWait(@NotNull final String line, @NotNull final String returnCode) throws IOException {
+ send(line);
+ waitFor(returnCode);
+ }
+
+ /** Waits for a specific SMTP return code.
+ * @param returnCode Return code to wait for.
+ * @throws IOException in case the expected return code was not received.
+ */
+ public void waitFor(@NotNull final String returnCode) throws IOException {
+ String line;
+ do {
+ line = sin.readLine();
+ if (debug && line != null) {
+ err.println("< " + line);
+ }
+ } while ((line != null) && (line.startsWith(returnCode + "-")));
+ if (line == null) {
+ if (debug) {
+ err.println("< <EOF>");
+ }
+ throw new EOFException();
+ }
+ if (!line.startsWith(returnCode + " ")) {
+ throw new IOException("Unexpected response from SMTP server.\nExpected: " + returnCode + "\nReceived: " + line);
+ }
+ }
+
+ /** Sends a line of text to the SMTP server.
+ * @param line Line to send.
+ * @throws IOException in case of I/O problems.
+ */
+ public void send(@NotNull final String line) throws IOException {
+ sout.println(line);
+ if (debug) {
+ err.println("> " + line);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void close() throws IOException {
+ if (socket != null) {
+ socket.close();
+ } else {
+ sout.close();
+ sin.close();
+ }
+ }
+}
Property changes on: tools/mail/trunk/src/prj/net/sf/japi/tools/mail/PingPongSession.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-11-30 16:11:04
|
Revision: 708
http://japi.svn.sourceforge.net/japi/?rev=708&view=rev
Author: christianhujer
Date: 2008-11-30 16:10:59 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Added tool archStat.
Added Paths:
-----------
tools/archStat/
tools/archStat/branches/
tools/archStat/tags/
tools/archStat/trunk/
tools/archStat/trunk/archStat.iml
tools/archStat/trunk/build.xml
tools/archStat/trunk/lib/
tools/archStat/trunk/lib/annotations.jar
tools/archStat/trunk/lib/japi-lib-argparser-trunk.jar
tools/archStat/trunk/src/
tools/archStat/trunk/src/doc/
tools/archStat/trunk/src/prj/
tools/archStat/trunk/src/prj/net/
tools/archStat/trunk/src/prj/net/sf/
tools/archStat/trunk/src/prj/net/sf/japi/
tools/archStat/trunk/src/prj/net/sf/japi/archstat/
tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.java
tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.properties
tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat_de.properties
tools/archStat/trunk/src/prj/net/sf/japi/archstat/Checker.xml
tools/archStat/trunk/src/prj/net/sf/japi/archstat/FileStat.java
tools/archStat/trunk/src/prj/net/sf/japi/archstat/LineCheck.java
tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogEntry.java
tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java
tools/archStat/trunk/src/prj/net/sf/japi/archstat/Logger.java
tools/archStat/trunk/src/prj/net/sf/japi/archstat/MessageType.java
tools/archStat/trunk/src/prj/net/sf/japi/archstat/StreamLogger.java
tools/archStat/trunk/src/tst/
Property changes on: tools/archStat/trunk
___________________________________________________________________
Added: svn:externals
+ common https://japi.svn.sourceforge.net/svnroot/japi/common/trunk
Added: tools/archStat/trunk/archStat.iml
===================================================================
--- tools/archStat/trunk/archStat.iml (rev 0)
+++ tools/archStat/trunk/archStat.iml 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/doc" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/prj" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/tst" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="annotations" level="project" />
+ <orderEntry type="library" name="junit" level="project" />
+ <orderEntry type="module" module-name="libs-argparser" />
+ <orderEntryProperties />
+ </component>
+</module>
+
Property changes on: tools/archStat/trunk/archStat.iml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/build.xml
===================================================================
--- tools/archStat/trunk/build.xml (rev 0)
+++ tools/archStat/trunk/build.xml 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,228 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Replacer is a program for performing an in-place search and replace
+ ~ based on regular expressions.
+ ~ Copyright (C) 2007 Christian Hujer
+ ~
+ ~ This program is free software; you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation; either version 2 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License along
+ ~ with this program; if not, write to the Free Software Foundation, Inc.,
+ ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ -->
+
+<project name="ArchStat" default="compile">
+
+ <property name="module.version" value="0.1" />
+ <property name="module.name" value="ArchStat" />
+ <property name="module.shortname" value="ArchStat" />
+ <property name="module.title" value="ArchStat" />
+ <property name="main.class" value="net.sf.japi.archstat.ArchStat" />
+
+ <taskdef name="pack200" classpath="common/antlib/Pack200Task.jar" classname="com.sun.tools.apache.ant.pack200.Pack200Task" />
+
+ <target
+ name = "clean"
+ description = "Cleans Sandbox"
+ >
+ <delete dir="classes" />
+ <delete dir="docs" />
+ </target>
+
+ <target
+ name = "compile"
+ description = "Compiles production classes"
+ >
+ <mkdir dir="classes/production/${module.shortname}" />
+ <mkdir dir="classes/test/${module.shortname}" />
+ <javac
+ srcdir="src/prj"
+ destdir="classes/production/${module.shortname}"
+ encoding="utf-8"
+ source="1.5"
+ target="1.5"
+ >
+ <classpath>
+ <fileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <fileset dir="common/lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ </classpath>
+ <exclude name="test/**/*.java" />
+ </javac>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="src/prj" includes="**/*.properties" excludes="test/**/*.properties" />
+ <fileset dir="src/prj" includes="**/*.xml" excludes="test/**/*.xml" />
+ <fileset dir="src/prj" includes="META-INF/services/**" />
+ </copy>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="lib" includes="LICENSE-*" />
+ <fileset dir="." includes="COPYING" />
+ </copy>
+ </target>
+
+ <target
+ name = "dist"
+ description = "Packs distribution archives."
+ depends = "clean, compile"
+ >
+ <!--depends = "clean, compile, doc"
+ -->
+ <delete dir="dist" />
+ <mkdir dir="dist" />
+ <property name="distName" value="dist/${module.name}-${module.version}" />
+ <parallel>
+ <tar tarfile="${distName}.src.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.src.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.src.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </jar>
+ <jar destfile="${distName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" />
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ <tar tarfile="${distName}.doc.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.doc.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.doc.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ </zipfileset>
+ </jar>
+ </parallel>
+ <parallel>
+ <gzip src="${distName}.src.tar" destfile="${distName}.src.tar.gz" />
+ <bzip2 src="${distName}.src.tar" destfile="${distName}.src.tar.bz2" />
+ <gzip src="${distName}.doc.tar" destfile="${distName}.doc.tar.gz" />
+ <bzip2 src="${distName}.doc.tar" destfile="${distName}.doc.tar.bz2" />
+ <pack200
+ src="${distName}.jar"
+ destfile="${distName}.pack.gz"
+ gzipoutput="true"
+ stripdebug="true"
+ effort="9"
+ keepfileorder="false"
+ modificationtime="latest"
+ deflatehint="false"
+ />
+ </parallel>
+ <delete file="${distName}.src.tar" />
+ <delete file="${distName}.doc.tar" />
+ </target>
+
+ <target
+ name = "doc"
+ description = "Creates public javadoc documentation."
+ >
+ <mkdir dir="docs/api" />
+ <!--copy todir="docs/api" file="src/doc/api/public/copyright.html" />
+ <copy todir="docs/api" file="src/doc/api/public/.htaccess" /-->
+ <javadoc
+ destdir = "docs/api"
+ access = "protected"
+ author = "yes"
+ version = "yes"
+ locale = "en_US"
+ use = "yes"
+ splitindex = "yes"
+ windowtitle = "JAPI Library ${module.title} ${module.version} API documentation"
+ doctitle = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ header = "JAPI Library ${module.title} ${module.version}<br />API Documentation"
+ footer = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ bottom = "<div style=" text-align:center;">© 2005-2006 Christian Hujer. All rights reserved. See <a href="{@docRoot}/copyright.html">copyright</a></div>"
+ serialwarn = "yes"
+ charset = "utf-8"
+ docencoding = "utf-8"
+ encoding = "utf-8"
+ source = "1.5"
+ linksource = "yes"
+ link = "${user.javadoc.link}"
+ >
+ <!--
+ overview = "src/overview.html"
+ -->
+ <classpath>
+ <fileset dir="lib" includes="annotations.jar" />
+ </classpath>
+ <sourcepath>
+ <pathelement path="${user.javadoc.javasrc}" />
+ <pathelement path="src/prj" />
+ </sourcepath>
+ <packageset
+ dir="src/prj"
+ defaultexcludes="yes"
+ >
+ <include name="net/**" />
+ </packageset>
+ <tag enabled="true" name="retval" description="Return Values:" scope="methods" />
+ <tag enabled="true" name="pre" description="Preconditions:" scope="methods,constructors" />
+ <tag enabled="true" name="post" description="Postconditions:" scope="methods" />
+ <tag enabled="true" name="invariant" description="Invariant:" scope="methods,fields" />
+ <tag enabled="true" name="note" description="Notes:" />
+ <tag enabled="true" name="warning" description="Warnings:" />
+ <!--tag enabled="true" name="todo" description="Todo:" /-->
+ <taglet name="com.sun.tools.doclets.ToDoTaglet" path="" />
+ <tag enabled="true" name="fixme" description="Fixme:" />
+ <tag enabled="true" name="xxx" description="XXX:" />
+ </javadoc>
+ </target>
+
+ <target
+ name = "buildapp"
+ description = "Creates executable jar"
+ >
+ <property name="appName" value="${module.name}-${module.version}-app" />
+ <jar destfile="${appName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <zipgroupfileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <!--attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" /-->
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ </target>
+
+</project>
Property changes on: tools/archStat/trunk/build.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/lib/annotations.jar
===================================================================
(Binary files differ)
Property changes on: tools/archStat/trunk/lib/annotations.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: tools/archStat/trunk/lib/japi-lib-argparser-trunk.jar
===================================================================
(Binary files differ)
Property changes on: tools/archStat/trunk/lib/japi-lib-argparser-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.java
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.java (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.java 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,208 @@
+package net.sf.japi.archstat;
+
+// Recursive code statistics.
+// © Copyright 2008 Christian Hujer. All rights reserved.
+// License: GPL (Gnu General Public License) v2 or newer
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.jetbrains.annotations.NotNull;
+import org.xml.sax.SAXException;
+import net.sf.japi.io.args.BasicCommand;
+import net.sf.japi.io.args.ArgParser;
+import net.sf.japi.io.args.Option;
+
+/** A Command for performing recursive source code file statistics.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class ArchStat extends BasicCommand {
+
+ /** Default buffer size. */
+ private static final int BUF_SIZE = 8192;
+
+ /** Main program.
+ * @param args Command line arguments (try --help).
+ */
+ public static void main(final String... args) {
+ ArgParser.simpleParseAndRun(new ArchStat(), args);
+ }
+
+ /** The DocumentBuilder for parsing XML documents. */
+ @NotNull private DocumentBuilder db;
+
+ /** Whether or not to output memory statistics. */
+ private boolean memoryStatistics;
+
+ /** {@inheritDoc} */
+ @SuppressWarnings({"InstanceMethodNamingConvention"})
+ public int run(@NotNull final List<String> args) throws Exception {
+ if (args.size() == 0) {
+ System.err.println("Error: No arguments given.");
+ return 1;
+ }
+ if (memoryStatistics) {
+ System.err.println("Memory free (start): " + Runtime.getRuntime().freeMemory());
+ }
+ final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ db = dbf.newDocumentBuilder();
+ readDefaultCheckers();
+ final FileStat fileStat = new FileStat(checkers);
+ for (final String arg : args) {
+ fileStat.addChild(arg);
+ }
+ fileStat.printStatistic(System.out, depth);
+ if (memoryStatistics) {
+ System.err.println("Memory free (end, before GC): " + Runtime.getRuntime().freeMemory());
+ System.gc();
+ System.err.println("Memory free (end, after GC): " + Runtime.getRuntime().freeMemory());
+ }
+ return fileStat.warnings > 0 ? 1 : 0;
+ }
+
+ /** The default depth. */
+ private static final int DEFAULT_DEPTH = Integer.MAX_VALUE;
+
+ /** The depth up to which statistics are printed.
+ */
+ private int depth = DEFAULT_DEPTH;
+
+ /** Sets whether or not to output memory statistics.
+ * @param memoryStatistics Whether or not to output memory statistics.
+ */
+ @Option({"memory"})
+ public void setMemoryStatistics(@NotNull final Boolean memoryStatistics) {
+ this.memoryStatistics = memoryStatistics;
+ }
+
+ /** Sets the depth up to which statistics are printed.
+ * @param depth Depth up to which statistics are printed.
+ */
+ @Option({"d", "depth"})
+ public void setDepth(@NotNull final Integer depth) {
+ this.depth = depth;
+ }
+
+ /** Returns the depth up to which statistics are printed.
+ * @return The depth up to which statistics are printed.
+ */
+ public int getDepth() {
+ return depth;
+ }
+
+ /** The checks that should be performed. */
+ private final List<LineCheck> checkers = new ArrayList<LineCheck>();
+
+ /** Reads a file.
+ * @param file File to read.
+ * @return Contents of that file as String.
+ * @throws IOException In case of I/O problems.
+ */
+ public static CharSequence readFile(final File file) throws IOException {
+ assert file.isFile();
+ final BufferedReader in = new BufferedReader(new FileReader(file));
+ final StringBuilder sb = new StringBuilder((int) file.length());
+ final char[] buf = new char[BUF_SIZE];
+ try {
+ for (int charsRead; (charsRead = in.read(buf)) != -1; ) {
+ sb.append(buf, 0, charsRead);
+ }
+ } finally {
+ in.close();
+ }
+ return sb.toString();
+ }
+
+ /** The Pattern for splitting lines. */
+ // TODO: This is somehow bogus. Replace this by something else.
+ private static final Pattern lineSplitPattern = Pattern.compile("(?<=\\r\\n|\\r|\\n)");
+
+ /** The Pattern for counting lines. */
+ private static final Pattern lineCountPattern = Pattern.compile("$", Pattern.MULTILINE);
+
+ /** Returns the number of lines in the specified string.
+ * @param string String of which to count lines.
+ * @return The number of lines in <var>string</var>
+ */
+ static int countLines(final CharSequence string) {
+ return count(lineCountPattern, string) - 1;
+ }
+
+ /** Returns a split array of lines for the specified string.
+ * @param string String to split.
+ * @return Array with lines.
+ */
+ static String[] getLines(final CharSequence string) {
+ return lineSplitPattern.split(string);
+ }
+
+ private static final Pattern commentPattern = Pattern.compile("/(/.*?$|\\*.*?\\*/(\\s*?\\n)?)", Pattern.MULTILINE | Pattern.DOTALL);
+ static CharSequence removeCComments(final CharSequence string) {
+ return commentPattern.matcher(string).replaceAll("");
+ }
+
+ private static final Pattern sourceLinePattern = Pattern.compile("^.*\\S.*\\S.*\\S.*$", Pattern.MULTILINE);
+ static int countSourceLines(final CharSequence string) {
+ return count(sourceLinePattern, string);
+ }
+
+ private static int count(final Pattern pattern, final CharSequence string) {
+ int count = 0;
+ final Matcher m = pattern.matcher(string);
+ while (m.find()) {
+ count++;
+ }
+ return count;
+ }
+
+ private void readDefaultCheckers() throws SAXException, IOException {
+ final Enumeration<URL> checkers = ArchStat.class.getClassLoader().getResources("net/sf/japi/archstat/Checker.xml");
+ while (checkers.hasMoreElements()) {
+ final URL url = checkers.nextElement();
+ readCheckers(url);
+ }
+ }
+ private void readCheckers(final Document doc) {
+ final NodeList nl = doc.getElementsByTagName("pattern");
+ for (int i = 0; i < nl.getLength(); i++) {
+ final LineCheck check = new LineCheck((Element) nl.item(i));
+ if (checkers.contains(check)) {
+ // TODO improve
+ throw new RuntimeException("Duplicate Checker " + check.getName());
+ }
+ checkers.add(new LineCheck((Element) nl.item(i)));
+ }
+ }
+
+ /** Reads additional configuration from the specified file.
+ * @param file File from which to read the config.
+ * @throws IOException in case of I/O problems.
+ * @throws SAXException in case of XML parsing errors.
+ */
+ @Option({"c", "config"})
+ public void readCheckers(@NotNull final File file) throws SAXException, IOException {
+ readCheckers(db.parse(file));
+ }
+
+ /** Reads additional configuration from the specified resource.
+ * @param url Resource to read.
+ * @throws IOException in case of I/O problems.
+ * @throws SAXException in case of XML parsing errors.
+ */
+ private void readCheckers(final URL url) throws SAXException, IOException {
+ readCheckers(db.parse(url.openStream()));
+ }
+
+}
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.properties
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.properties (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.properties 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,2 @@
+readCheckers=Specify an additional configuration file. Can be specified more than once.
+setDepth=Set the maximum output depth. Default: No limit.
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat_de.properties
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat_de.properties (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat_de.properties 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,2 @@
+readCheckers=Eine zus\xE4tzliche Konfiguration lesen. Kann mehrmals angegeben werden.
+setDepth=Maximale Ausgabetiefe festlegen. Voreinstellung: unbegrenzt.
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat_de.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/Checker.xml
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/Checker.xml (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/Checker.xml 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,72 @@
+<config>
+ <filetypes>
+ <filetype id="CSource" match="^.+\.(c)$" description="C Source Code" />
+ <filetype id="CHeader" match="^.+\.(h)$" description="C Header"/>
+ <filetype id="C" groups="CSource CHeader" description="C Language (Source and Header)"/>
+ <filetype id="AsmSource" match="^.+\.(s|src|asm|i|inc)$" description="Assembly Source Code"/>
+ <filetype id="AsmHeader" match="^.+\.(i|inc)$" description="Assembly Header"/>
+ <filetype id="Asm" groups="AsmSource AsmHeader" description="Assembly Language (Source and Header)"/>
+ <filetype id="Java" match="^.+\.(java)$" description="Java Source"/>
+ <filetype id="Jpp" match="^.+\.(jpp)$" description="Jpp Source"/>
+ <filetype id="Curly" groups="C Asm Java Jpp" description="Java and Jpp Source"/>
+ <filetype id="Makefile" match="^(Makefile|.+\.mak)$" description="Makefile" />
+ </filetypes>
+ <patterns>
+ <pattern
+ match="line"
+ type="WARNING"
+ name="bogusLintSuppression"
+ regex="/[/*] lint"
+ message="Bogus lint suppression."
+ />
+ <pattern
+ match="line"
+ type="WARNING"
+ name="trailingWhitespace"
+ regex="[\p{javaWhitespace}&&[^\p{Zl}]]+?(\r\n|\r|\n)$"
+ message="Trailing whitespace."
+ />
+ <pattern
+ match="line"
+ type="WARNING"
+ name="unixLine"
+ regex="[^\r]\n$"
+ message="Unix line."
+ />
+ <pattern
+ match="line"
+ type="WARNING"
+ name="oldIntegerType"
+ regex="\b[US](08|16|32)_(EXACT|FAST)\b"
+ message="Old integer type."
+ />
+ <pattern
+ match="line"
+ type="WARNING"
+ name="oldBooleanType"
+ regex="\bBOOL(_FAST)?\b"
+ message="Old boolean type."
+ />
+ <pattern
+ match="line"
+ type="WARNING"
+ name="tab"
+ regex="\t"
+ message="Tab character."
+ />
+ <pattern
+ match="line"
+ type="WARNING"
+ name="commentStart"
+ regex="/\*\*\s*?[\r\n]"
+ message="Documentation comment text doesn't start in first line of documentation comment."
+ />
+ <pattern
+ match="line"
+ type="WARNING"
+ name="oldStyleComment"
+ regex="(\*{3,}|/{3,})"
+ message="Old style comment."
+ />
+ </patterns>
+</config>
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/Checker.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/FileStat.java
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/FileStat.java (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/FileStat.java 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,173 @@
+package net.sf.japi.archstat;
+
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.TreeSet;
+import java.io.File;
+import java.io.IOException;
+import org.jetbrains.annotations.NotNull;
+
+/** Per-File statistics.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class FileStat {
+
+ /** The checks that should be performed. */
+ private final List<LineCheck> checkers;
+
+ /** The warnings that occurred in that individual check. */
+ private final Map<LineCheck, Integer> checkWarnings = new HashMap<LineCheck, Integer>();
+
+ /** The children of this statistic. */
+ private final Map<File, FileStat> children = new HashMap<File, FileStat>();
+
+ /** The list of errors that occurred. */
+ private final List<Throwable> errors = new ArrayList<Throwable>();
+
+ /** The title of this statistic. */
+ private final String title;
+
+ /** The file (regular file or directory) of this statistic. */
+ private final File file;
+
+ private int linesRaw;
+
+ private int linesNoComment;
+
+ private int sourceLines;
+
+ private int commentLines;
+
+ private CharSequence fileText;
+
+ int warnings;
+
+ @SuppressWarnings({"AssignmentToCollectionOrArrayFieldFromParameter"})
+ FileStat(final List<LineCheck> checkers) {
+ this.checkers = checkers;
+ title = "<SUM>";
+ file = null;
+ }
+
+ @SuppressWarnings({"AssignmentToCollectionOrArrayFieldFromParameter"})
+ FileStat(final List<LineCheck> checkers, @NotNull final File file) {
+ this.checkers = checkers;
+ this.file = file;
+ title = file.toString();
+ if (file.isFile()) {
+ CharSequence fileText;
+ try {
+ fileText = ArchStat.readFile(file);
+ } catch (final IOException e) {
+ System.err.println(e);
+ fileText = "";
+ errors.add(e);
+ }
+ this.fileText = fileText;
+ linesRaw = ArchStat.countLines(fileText);
+ final CharSequence noComments = ArchStat.removeCComments(fileText);
+ linesNoComment = ArchStat.countLines(noComments);
+ sourceLines = ArchStat.countSourceLines(noComments);
+ commentLines = linesRaw - linesNoComment;
+ final String[] lines = ArchStat.getLines(fileText);
+ for (int i = 0; i < lines.length; i++) {
+ checkLine(lines[i], i + 1);
+ }
+ }
+ if (file.isDirectory()) {
+ for (final File member : file.listFiles()) {
+ addChild(member);
+ }
+ }
+ treeWarnings();
+ }
+ void treeWarnings() {
+ for (final LineCheck lineCheck : checkers) {
+ final Integer i = checkWarnings.get(lineCheck);
+ if (i != null && i > 0) {
+ System.err.println(file + ": " + lineCheck.getType() + ": " + i + " " + lineCheck.getPlural());
+ }
+ }
+ if (warnings > 0) {
+ System.err.println(file + ": " + "warning: " + warnings + " warnings.");
+ }
+ }
+ void checkLine(final String line, final int lineNumber) {
+ for (final LineCheck lineCheck : checkers) {
+ if (lineCheck.hasProblem(file, line, lineNumber)) {
+ incWarning(lineCheck);
+ }
+ }
+ }
+ public void incWarning(final LineCheck lineCheck) {
+ warnings++;
+ final Integer i = checkWarnings.get(lineCheck);
+ checkWarnings.put(lineCheck, i != null ? i + 1 : 1);
+ }
+
+ /** Adds a child with the specified filename.
+ * @param filename Filename of the child to add.
+ */
+ public void addChild(final String filename) {
+ addChild(new File(filename));
+ }
+
+ /** Adds a child with the specified file.
+ * @param file File of the child to add.
+ */
+ public void addChild(final File file) {
+ addChild(new FileStat(checkers, file));
+ }
+
+ /** Adds a child with the specified statistics.
+ * @param child Child to add.
+ */
+ public void addChild(final FileStat child) {
+ children.put(child.file, child);
+ linesRaw += child.linesRaw;
+ linesNoComment += child.linesNoComment;
+ sourceLines += child.sourceLines;
+ commentLines += child.commentLines;
+ warnings += child.warnings;
+ for (final LineCheck lineCheck : checkers) {
+ final Integer childI = child.checkWarnings.get(lineCheck);
+ if (childI != null) {
+ final Integer i = checkWarnings.get(lineCheck);
+ checkWarnings.put(lineCheck, i != null ? i + childI : childI);
+ }
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return title + ";" + errors.size() + ";" + linesRaw + ";" + linesNoComment + ";" + commentLines + ";" + sourceLines;
+ }
+
+ /** Prints recursive statistics including table header to the specified appendable.
+ * @param out Appendable to print to.
+ * @param level Nesting level for which to print statistics.
+ * @throws IOException In case of I/O problems.
+ */
+ public void printStatistic(@NotNull final Appendable out, final int level) throws IOException {
+ out.append("Title;Errors;Raw lines;Lines w/o comments;Comment lines;Sloc\n");
+ print(out, level);
+ }
+
+ /** Prints recursive statistics to the specified appendable.
+ * @param out Appendable to print to.
+ * @param level Nesting level for which to print statistics.
+ * @throws IOException In case of I/O problems.
+ */
+ public void print(final Appendable out, final int level) throws IOException {
+ out.append(toString());
+ out.append("\n");
+ if (level > 0) {
+ for (final File file : new TreeSet<File>(children.keySet())) {
+ children.get(file).print(out, level - 1);
+ }
+ }
+ }
+}
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/FileStat.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/LineCheck.java
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/LineCheck.java (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/LineCheck.java 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,99 @@
+package net.sf.japi.archstat;
+
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import java.io.File;
+import org.w3c.dom.Element;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** A Line-based Check.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class LineCheck {
+
+ /** The message type to emit if this check found something. */
+ @NotNull private MessageType type;
+
+ /** The name of this check. */
+ @NotNull private final String name;
+
+ /** The regular expression for this check.
+ * If it matches, the check found something to report.
+ */
+ @NotNull private final Pattern regex;
+
+ /** The message to emit if this check found something. */
+ @NotNull private final String message;
+
+ /** Create a line check.
+ * @param elem XML Element with the check information.
+ */
+ public LineCheck(@NotNull final Element elem) {
+ this(Enum.valueOf(MessageType.class, elem.getAttribute("type")), elem.getAttribute("name"), Pattern.compile(elem.getAttribute("regex")), elem.getAttribute("message"));
+ }
+
+ /** Create a line check.
+ * @param type The message type to emit if this check found something.
+ * @param name The name of this check.
+ * @param regex The regular expression for this check.
+ * @param message The message to emit if this check found something.
+ */
+ public LineCheck(@NotNull final MessageType type, @NotNull final String name, @NotNull final Pattern regex, @NotNull final String message) {
+ this.type = type;
+ this.name = name;
+ this.regex = regex;
+ this.message = message;
+ }
+
+ /** Returns whether or not this line check finds something.
+ * @param file File to check (informational purpose only, e.g. for error message).
+ * @param line Line to check.
+ * @param lineNumber Line number of the line that's checked.
+ * @return true if this check found a problem, otherwise false.
+ */
+ boolean hasProblem(@NotNull final File file, @NotNull final String line, final int lineNumber) {
+ boolean ret = false;
+ final Matcher m = regex.matcher(line);
+ if (m.find()) {
+ final int column = m.start();
+ ret = true;
+ LogSystem.log(new LogEntry(file, line, lineNumber, column + 1, type, name, message));
+ }
+ return ret;
+ }
+
+ /** Returns the name of this check.
+ * @return The name of this check.
+ */
+ @NotNull public String getName() {
+ return name;
+ }
+
+ /** Returns the type of this check.
+ * @return The type of this check.
+ */
+ @NotNull public MessageType getType() {
+ return type;
+ }
+
+ /** returns the plural name of this check.
+ * @return The plural name of this check.
+ */
+ @NotNull public String getPlural() {
+ return name; // TODO
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean equals(@Nullable final Object o) {
+ return o != null && o instanceof LineCheck && ((LineCheck) o).name.equals(name);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+}
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/LineCheck.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogEntry.java
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogEntry.java (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogEntry.java 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,118 @@
+package net.sf.japi.archstat;
+
+import java.io.File;
+import java.util.Formatter;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** A LogEntry represents an atomic ArchStat information.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class LogEntry {
+
+ /** The File for which this LogEntry is being logged. */
+ private final File file;
+
+ /** The line in {@link #file} for which this LogEntry is being logged.
+ * Maybe <code>null</code> if the LogEntry does not apply to a particular line.
+ */
+ @Nullable private final String line;
+
+ /** The lineNumber in {@link #file} for which this LogEntry is being logged.
+ * Maybe <code>null</code> if the LogEntry does not apply to a particular lineNumber.
+ * The line number is the user line, the first line is 1.
+ */
+ @Nullable private final Integer lineNumber;
+
+ /** The column in {@link #file} {@link #lineNumber} for which this LogEntry is being logged.
+ * Maybe <code>null</code> if the LogEntry does not apply to a particular column.
+ * The column is the user column, the first column is 1.
+ */
+ @Nullable private final Integer column;
+
+ /** The MessageType for this LogEntry. */
+ @NotNull private final MessageType messageType;
+
+ /** The message ID of this type of log entry. */
+ @NotNull private final String messageId;
+
+ /** The message of this log entry. */
+ @NotNull private final String message;
+
+ /** Creates a LogEntry.
+ * @param file File for which this LogEntry is being logged.
+ * @param line Line in <var>file</var> or <code>null</code>.
+ * @param lineNumber Line number in <var>file</var> or <code>null</code> (user line, first line is 1).
+ * @param column Column in <var>lineNumber</var> or <code>null</code> (user column, first column is 1).
+ * @param messageType Message Type.
+ * @param messageId Message ID.
+ * @param message The message.
+ */
+ public LogEntry(final File file, @Nullable final String line, @Nullable final Integer lineNumber, @Nullable final Integer column, @NotNull final MessageType messageType, @NotNull final String messageId, @NotNull final String message) {
+ this.file = file;
+ this.line = line;
+ this.lineNumber = lineNumber;
+ this.column = column;
+ this.messageType = messageType;
+ this.messageId = messageId;
+ this.message = message;
+ }
+
+ /** Creates a LogEntry.
+ * @param file File for which this LogEntry is being logged.
+ * @param messageType Message Type.
+ * @param messageId Message ID.
+ * @param message The message.
+ */
+ public LogEntry(final File file, @NotNull final MessageType messageType, @NotNull final String messageId, @NotNull final String message) {
+ this(file, null, null, null, messageType, messageId, message);
+ }
+
+ /** Returns the file for which this LogEntry was created.
+ * @return The file for which this LogEntry was created.
+ */
+ public File getFile() {
+ return file;
+ }
+
+ /** Returns the lineNumber for which this LogEntry was created.
+ * @return The lineNumber number or <code>null</code> in case it's not applicable.
+ */
+ @Nullable public Integer getLineNumber() {
+ return lineNumber;
+ }
+
+ /** Returns the column for which this LogEntry was created.
+ * @return The column number or <code>null</code> in case it's not applicable.
+ */
+ @Nullable public Integer getColumn() {
+ return column;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return toString(new Formatter()).toString();
+ }
+
+ /** Formats this LogEntry to the specified formatter.
+ * @param out Formatter to log to.
+ * @return <var>out</var> for convenience.
+ */
+ public Formatter toString(@NotNull final Formatter out) {
+ if (lineNumber != null && column != null) {
+ out.format("%s:%s:%s: %s: (%s): %s", file, lineNumber, column, messageType, messageId, message);
+ if (line != null) {
+ out.format("%n%s%n", line);
+ for (int i = 1; i < column; i++) {
+ out.format("-");
+ }
+ out.format("^%n");
+ }
+ } else if (lineNumber != null) {
+ out.format("%s:%s: %s: (%s): %s", file, lineNumber, messageType, messageId, message);
+ } else {
+ out.format("%s: %s: (%s): %s", file, messageType, messageId, message);
+ }
+ return out;
+ }
+}
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogEntry.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,21 @@
+package net.sf.japi.archstat;
+
+import org.jetbrains.annotations.NotNull;
+
+/** Static access to logging.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class LogSystem {
+
+ /** The loggers. */
+ private static final Logger[] loggers = { new StreamLogger(System.err) };
+
+ /** Logs a single log entry.
+ * @param logEntry LogEntry to log.
+ */
+ public static void log(@NotNull final LogEntry logEntry) {
+ for (final Logger logger : loggers) {
+ logger.log(logEntry);
+ }
+ }
+}
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/Logger.java
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/Logger.java (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/Logger.java 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,14 @@
+package net.sf.japi.archstat;
+
+import org.jetbrains.annotations.NotNull;
+
+/** Loggers log LogEntries.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public interface Logger {
+
+ /** Logs a LogEntry.
+ * @param logEntry LogEntry to log.
+ */
+ void log(@NotNull LogEntry logEntry);
+}
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/Logger.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/MessageType.java
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/MessageType.java (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/MessageType.java 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,37 @@
+package net.sf.japi.archstat;
+
+import org.jetbrains.annotations.NotNull;
+
+/** A MessageType.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public enum MessageType {
+
+ /** An error. */
+ ERROR("error"),
+
+ /** A warning. */
+ WARNING("warning"),
+
+ /** An informational message. */
+ INFO("info"),
+
+ /** Statistical information. */
+ STAT("stat");
+
+ /** The name of this message type. */
+ @NotNull private final String name;
+
+ /** Create a MessageType.
+ * @param name Name of this message type.
+ */
+ MessageType(@NotNull final String name) {
+ this.name = name;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return name;
+ }
+}
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/MessageType.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/archStat/trunk/src/prj/net/sf/japi/archstat/StreamLogger.java
===================================================================
--- tools/archStat/trunk/src/prj/net/sf/japi/archstat/StreamLogger.java (rev 0)
+++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/StreamLogger.java 2008-11-30 16:10:59 UTC (rev 708)
@@ -0,0 +1,26 @@
+package net.sf.japi.archstat;
+
+import java.util.Formatter;
+import org.jetbrains.annotations.NotNull;
+
+/** The StreamLogger is a Logger for LogEntries that logs to the specified Stream.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class StreamLogger implements Logger {
+
+ /** The Stream for logging. */
+ @NotNull
+ private final Formatter out;
+
+ /** Creates a StreamLogger.
+ * @param out Stream for logging.
+ */
+ public StreamLogger(@NotNull final Appendable out) {
+ this.out = new Formatter(out);
+ }
+
+ /** {@inheritDoc} */
+ public void log(@NotNull final LogEntry logEntry) {
+ out.format("%s%n", logEntry);
+ }
+}
Property changes on: tools/archStat/trunk/src/prj/net/sf/japi/archstat/StreamLogger.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-11-30 15:57:20
|
Revision: 707
http://japi.svn.sourceforge.net/japi/?rev=707&view=rev
Author: christianhujer
Date: 2008-11-30 15:57:11 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Improved font browser.
Modified Paths:
--------------
tools/fontbrowser/trunk/src/prj/net/sf/japi/tools/fontbrowser/FontBrowser.java
tools/fontbrowser/trunk/src/prj/net/sf/japi/tools/fontbrowser/action.properties
Added Paths:
-----------
tools/fontbrowser/trunk/build.xml
Added: tools/fontbrowser/trunk/build.xml
===================================================================
--- tools/fontbrowser/trunk/build.xml (rev 0)
+++ tools/fontbrowser/trunk/build.xml 2008-11-30 15:57:11 UTC (rev 707)
@@ -0,0 +1,226 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ DirCount is a program for converting Strings into byte arrays.
+ ~ Copyright (C) 2007 Christian Hujer
+ ~
+ ~ This program is free software; you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation; either version 2 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License along
+ ~ with this program; if not, write to the Free Software Foundation, Inc.,
+ ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ -->
+
+<project name="dircount" default="compile">
+
+ <property name="module.version" value="0.1" />
+ <property name="module.name" value="dircount" />
+ <property name="module.shortname" value="dircount" />
+ <property name="module.title" value="DirCount" />
+ <property name="main.class" value="net.sf.japi.dircount.DirCount" />
+
+ <taskdef name="pack200" classpath="common/antlib/Pack200Task.jar" classname="com.sun.tools.apache.ant.pack200.Pack200Task" />
+
+ <target
+ name = "clean"
+ description = "Cleans Sandbox"
+ >
+ <delete dir="classes" />
+ <delete dir="docs" />
+ </target>
+
+ <target
+ name = "compile"
+ description = "Compiles production classes"
+ >
+ <mkdir dir="classes/production/${module.shortname}" />
+ <mkdir dir="classes/test/${module.shortname}" />
+ <javac
+ srcdir="src/prj"
+ destdir="classes/production/${module.shortname}"
+ encoding="utf-8"
+ source="1.5"
+ target="1.5"
+ >
+ <classpath>
+ <fileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <fileset dir="common/lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ </classpath>
+ <exclude name="test/**/*.java" />
+ </javac>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="src/prj" includes="**/*.properties" excludes="test/**/*.properties" />
+ <fileset dir="src/prj" includes="META-INF/services/**" />
+ </copy>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="lib" includes="LICENSE-*" />
+ <fileset dir="." includes="COPYING" />
+ </copy>
+ </target>
+
+ <target
+ name = "dist"
+ description = "Packs distribution archives."
+ depends = "clean, compile"
+ >
+ <!--depends = "clean, compile, doc"
+ -->
+ <delete dir="dist" />
+ <mkdir dir="dist" />
+ <property name="distName" value="dist/${module.name}-${module.version}" />
+ <parallel>
+ <tar tarfile="${distName}.src.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.src.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.src.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </jar>
+ <jar destfile="${distName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" />
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ <tar tarfile="${distName}.doc.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.doc.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.doc.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ </zipfileset>
+ </jar>
+ </parallel>
+ <parallel>
+ <gzip src="${distName}.src.tar" destfile="${distName}.src.tar.gz" />
+ <bzip2 src="${distName}.src.tar" destfile="${distName}.src.tar.bz2" />
+ <gzip src="${distName}.doc.tar" destfile="${distName}.doc.tar.gz" />
+ <bzip2 src="${distName}.doc.tar" destfile="${distName}.doc.tar.bz2" />
+ <pack200
+ src="${distName}.jar"
+ destfile="${distName}.pack.gz"
+ gzipoutput="true"
+ stripdebug="true"
+ effort="9"
+ keepfileorder="false"
+ modificationtime="latest"
+ deflatehint="false"
+ />
+ </parallel>
+ <delete file="${distName}.src.tar" />
+ <delete file="${distName}.doc.tar" />
+ </target>
+
+ <target
+ name = "doc"
+ description = "Creates public javadoc documentation."
+ >
+ <mkdir dir="docs/api" />
+ <!--copy todir="docs/api" file="src/doc/api/public/copyright.html" />
+ <copy todir="docs/api" file="src/doc/api/public/.htaccess" /-->
+ <javadoc
+ destdir = "docs/api"
+ access = "protected"
+ author = "yes"
+ version = "yes"
+ locale = "en_US"
+ use = "yes"
+ splitindex = "yes"
+ windowtitle = "JAPI Library ${module.title} ${module.version} API documentation"
+ doctitle = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ header = "JAPI Library ${module.title} ${module.version}<br />API Documentation"
+ footer = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ bottom = "<div style=" text-align:center;">© 2005-2006 Christian Hujer. All rights reserved. See <a href="{@docRoot}/copyright.html">copyright</a></div>"
+ serialwarn = "yes"
+ charset = "utf-8"
+ docencoding = "utf-8"
+ encoding = "utf-8"
+ source = "1.5"
+ linksource = "yes"
+ link = "${user.javadoc.link}"
+ >
+ <!--
+ overview = "src/overview.html"
+ -->
+ <classpath>
+ <fileset dir="lib" includes="annotations.jar" />
+ </classpath>
+ <sourcepath>
+ <pathelement path="${user.javadoc.javasrc}" />
+ <pathelement path="src/prj" />
+ </sourcepath>
+ <packageset
+ dir="src/prj"
+ defaultexcludes="yes"
+ >
+ <include name="net/**" />
+ </packageset>
+ <tag enabled="true" name="retval" description="Return Values:" scope="methods" />
+ <tag enabled="true" name="pre" description="Preconditions:" scope="methods,constructors" />
+ <tag enabled="true" name="post" description="Postconditions:" scope="methods" />
+ <tag enabled="true" name="invariant" description="Invariant:" scope="methods,fields" />
+ <tag enabled="true" name="note" description="Notes:" />
+ <tag enabled="true" name="warning" description="Warnings:" />
+ <!--tag enabled="true" name="todo" description="Todo:" /-->
+ <taglet name="com.sun.tools.doclets.ToDoTaglet" path="" />
+ <tag enabled="true" name="fixme" description="Fixme:" />
+ <tag enabled="true" name="xxx" description="XXX:" />
+ </javadoc>
+ </target>
+
+ <target
+ name = "buildapp"
+ description = "Creates executable jar"
+ >
+ <property name="appName" value="${module.name}-${module.version}-app" />
+ <jar destfile="${appName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <zipgroupfileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <!--attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" /-->
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ </target>
+
+</project>
Property changes on: tools/fontbrowser/trunk/build.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Modified: tools/fontbrowser/trunk/src/prj/net/sf/japi/tools/fontbrowser/FontBrowser.java
===================================================================
--- tools/fontbrowser/trunk/src/prj/net/sf/japi/tools/fontbrowser/FontBrowser.java 2008-11-30 15:55:51 UTC (rev 706)
+++ tools/fontbrowser/trunk/src/prj/net/sf/japi/tools/fontbrowser/FontBrowser.java 2008-11-30 15:57:11 UTC (rev 707)
@@ -25,6 +25,7 @@
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Toolkit;
+import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
@@ -46,18 +47,24 @@
/** Action Builder. */
@NotNull private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.japi.tools.fontbrowser");
+ /** Number of rows for the sample text. */
+ private static final int SAMPLETEXT_ROWS = 16;
+
+ /** Number of columns for the sample text. */
+ private static final int SAMPLETEXT_COLUMNS = 64;
+
+ private static final int DEFAULT_FONT_SIZE = 14;
+
+ /** No instantiation needed. */
+ private FontBrowser() {
+ }
+
/** Main program.
* @param args command line arguments
*/
public static void main(@NotNull final String... args) {
- //noinspection ResultOfObjectAllocationIgnored
- new FontBrowser();
- }
-
- /** Create a font browser. */
- public FontBrowser() {
final JFrame frame = new JFrame(ACTION_BUILDER.getString("frame.title"));
- final JTabbedPane tabs = new JTabbedPane();
+ final Container tabs = new JTabbedPane();
frame.add(tabs);
tabs.add(ACTION_BUILDER.getString("names.title"), createNamesTab());
tabs.add(ACTION_BUILDER.getString("fonts.title"), createFontsTab());
@@ -75,15 +82,15 @@
*/
@NotNull private static Component createNamesTab() {
final JList fontNameList = new JList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
- final JTextArea fontExample = new JTextArea(64, 16);
+ final JTextArea fontExample = new JTextArea(SAMPLETEXT_ROWS, SAMPLETEXT_COLUMNS);
fontNameList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(final ListSelectionEvent e) {
final String value = (String) fontNameList.getSelectedValue();
- fontExample.setFont(new Font(value, Font.PLAIN, 14));
+ fontExample.setFont(new Font(value, Font.PLAIN, DEFAULT_FONT_SIZE));
System.err.println(value);
}
});
- fontExample.setText("Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.");
+ fontExample.setText(ACTION_BUILDER.getString("font.example.text"));
return new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, new JScrollPane(fontNameList), new JScrollPane(fontExample));
}
Modified: tools/fontbrowser/trunk/src/prj/net/sf/japi/tools/fontbrowser/action.properties
===================================================================
--- tools/fontbrowser/trunk/src/prj/net/sf/japi/tools/fontbrowser/action.properties 2008-11-30 15:55:51 UTC (rev 706)
+++ tools/fontbrowser/trunk/src/prj/net/sf/japi/tools/fontbrowser/action.properties 2008-11-30 15:57:11 UTC (rev 707)
@@ -20,3 +20,4 @@
frame.title=Font Browser
names.title=Font Names
fonts.title=Fonts
+font.example.text=Falsches \xDCben von Xylophonmusik qu\xE4lt jeden gr\xF6\xDFeren Zwerg.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-11-30 15:55:56
|
Revision: 706
http://japi.svn.sourceforge.net/japi/?rev=706&view=rev
Author: christianhujer
Date: 2008-11-30 15:55:51 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Minor improvements to dircount.
Modified Paths:
--------------
tools/dircount/trunk/build.xml
tools/dircount/trunk/dircount.iml
tools/dircount/trunk/lib/japi-lib-argparser-trunk.jar
tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.java
Added Paths:
-----------
tools/dircount/trunk/src/doc/
Modified: tools/dircount/trunk/build.xml
===================================================================
--- tools/dircount/trunk/build.xml 2008-11-30 15:54:49 UTC (rev 705)
+++ tools/dircount/trunk/build.xml 2008-11-30 15:55:51 UTC (rev 706)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- ~ DirCount is a program for converting Strings into byte arrays.
+ ~ DirCount is a program for counting directories.
~ Copyright (C) 2007 Christian Hujer
~
~ This program is free software; you can redistribute it and/or modify
@@ -206,6 +206,7 @@
<target
name = "buildapp"
+ description = "Creates executable jar"
>
<property name="appName" value="${module.name}-${module.version}-app" />
<jar destfile="${appName}.jar">
Modified: tools/dircount/trunk/dircount.iml
===================================================================
--- tools/dircount/trunk/dircount.iml 2008-11-30 15:54:49 UTC (rev 705)
+++ tools/dircount/trunk/dircount.iml 2008-11-30 15:55:51 UTC (rev 706)
@@ -3,6 +3,7 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/doc" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/prj" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/tst" isTestSource="true" />
</content>
Modified: tools/dircount/trunk/lib/japi-lib-argparser-trunk.jar
===================================================================
(Binary files differ)
Modified: tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.java
===================================================================
--- tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.java 2008-11-30 15:54:49 UTC (rev 705)
+++ tools/dircount/trunk/src/prj/net/sf/japi/dircount/DirCount.java 2008-11-30 15:55:51 UTC (rev 706)
@@ -8,8 +8,7 @@
import net.sf.japi.io.args.Option;
import org.jetbrains.annotations.NotNull;
-/**
- * A command that counts subdirectories and files.
+/** A command that counts subdirectories and files.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
public class DirCount extends LogCommand {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-11-30 15:54:53
|
Revision: 705
http://japi.svn.sourceforge.net/japi/?rev=705&view=rev
Author: christianhujer
Date: 2008-11-30 15:54:49 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Added tool GdbControl.
Added Paths:
-----------
tools/gdbControl/
tools/gdbControl/branches/
tools/gdbControl/tags/
tools/gdbControl/trunk/
tools/gdbControl/trunk/build.xml
tools/gdbControl/trunk/gdbControl.iml
tools/gdbControl/trunk/lib/
tools/gdbControl/trunk/lib/annotations.jar
tools/gdbControl/trunk/lib/japi-lib-argparser-trunk.jar
tools/gdbControl/trunk/module.properties
tools/gdbControl/trunk/src/
tools/gdbControl/trunk/src/doc/
tools/gdbControl/trunk/src/prj/
tools/gdbControl/trunk/src/prj/net/
tools/gdbControl/trunk/src/prj/net/sf/
tools/gdbControl/trunk/src/prj/net/sf/japi/
tools/gdbControl/trunk/src/prj/net/sf/japi/tools/
tools/gdbControl/trunk/src/prj/net/sf/japi/tools/gdbcontrol/
tools/gdbControl/trunk/src/prj/net/sf/japi/tools/gdbcontrol/ComWithGdb.java
tools/gdbControl/trunk/src/tst/
Property changes on: tools/gdbControl/trunk
___________________________________________________________________
Added: svn:externals
+ common https://japi.svn.sourceforge.net/svnroot/japi/common/trunk
Added: tools/gdbControl/trunk/build.xml
===================================================================
--- tools/gdbControl/trunk/build.xml (rev 0)
+++ tools/gdbControl/trunk/build.xml 2008-11-30 15:54:49 UTC (rev 705)
@@ -0,0 +1,238 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Replacer is a program for performing an in-place search and replace
+ ~ based on regular expressions.
+ ~ Copyright (C) 2007 Christian Hujer
+ ~
+ ~ This program is free software; you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation; either version 2 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License along
+ ~ with this program; if not, write to the Free Software Foundation, Inc.,
+ ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ -->
+
+<project name="GdbControl" default="buildapp">
+
+ <property file="module.properties" />
+
+ <!-- Sets module.version to something very reasonable, depending on whether we're in trunk, tags, branches or somewhere else. -->
+ <basename property="dir.version" file="${user.dir}" />
+ <dirname property="parent" file="${user.dir}" />
+ <basename property="parentRegion" file="${parent}" />
+ <exec outputproperty="svnversion" executable="svnversion">
+ <env key="LC_ALL" value="C" />
+ </exec>
+ <condition property="module.version" value="trunk-${svnversion}">
+ <equals arg1="trunk" arg2="${dir.version}" />
+ </condition>
+ <condition property="module.version" value="branch-${dir.version}-${svnversion}">
+ <equals arg1="branches" arg2="${parentRegion}" />
+ </condition>
+ <condition property="module.version" value="${dir.version}">
+ <equals arg1="tags" arg2="${parentRegion}" />
+ </condition>
+ <property name="module.version" value="${parentRegion}-${dir.version}-${svnversion}" />
+
+ <taskdef name="pack200" classpath="common/antlib/Pack200Task.jar" classname="com.sun.tools.apache.ant.pack200.Pack200Task" />
+
+ <target
+ name = "clean"
+ description = "Cleans Sandbox"
+ >
+ <delete dir="classes" />
+ <delete dir="docs" />
+ </target>
+
+ <target
+ name = "compile"
+ description = "Compiles production classes"
+ >
+ <mkdir dir="classes/production/${module.shortname}" />
+ <javac
+ srcdir="src/prj"
+ destdir="classes/production/${module.shortname}"
+ encoding="utf-8"
+ source="1.5"
+ target="1.5"
+ >
+ <classpath>
+ <fileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <fileset dir="common/lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ </classpath>
+ </javac>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="src/prj" includes="**/*.properties" excludes="test/**/*.properties" />
+ <fileset dir="src/prj" includes="META-INF/services/**" />
+ </copy>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="lib" includes="LICENSE-*" />
+ <fileset dir="." includes="COPYING" />
+ </copy>
+ </target>
+
+ <target
+ name = "dist"
+ description = "Packs distribution archives."
+ depends = "clean, compile"
+ >
+ <delete dir="dist" />
+ <mkdir dir="dist" />
+ <property name="distName" value="dist/${module.name}-${module.version}" />
+ <parallel>
+ <tar tarfile="${distName}.src.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.src.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.src.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </jar>
+ <jar destfile="${distName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" />
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ <tar tarfile="${distName}.doc.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.doc.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.doc.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ </zipfileset>
+ </jar>
+ </parallel>
+ <parallel>
+ <gzip src="${distName}.src.tar" destfile="${distName}.src.tar.gz" />
+ <bzip2 src="${distName}.src.tar" destfile="${distName}.src.tar.bz2" />
+ <gzip src="${distName}.doc.tar" destfile="${distName}.doc.tar.gz" />
+ <bzip2 src="${distName}.doc.tar" destfile="${distName}.doc.tar.bz2" />
+ <pack200
+ src="${distName}.jar"
+ destfile="${distName}.pack.gz"
+ gzipoutput="true"
+ stripdebug="true"
+ effort="9"
+ keepfileorder="false"
+ modificationtime="latest"
+ deflatehint="false"
+ />
+ </parallel>
+ <delete file="${distName}.src.tar" />
+ <delete file="${distName}.doc.tar" />
+ </target>
+
+ <target
+ name = "doc"
+ description = "Creates public javadoc documentation."
+ >
+ <mkdir dir="docs/api" />
+ <!--copy todir="docs/api" file="src/doc/api/public/copyright.html" />
+ <copy todir="docs/api" file="src/doc/api/public/.htaccess" /-->
+ <javadoc
+ destdir = "docs/api"
+ access = "protected"
+ author = "yes"
+ version = "yes"
+ locale = "en_US"
+ use = "yes"
+ splitindex = "yes"
+ windowtitle = "JAPI Library ${module.title} ${module.version} API documentation"
+ doctitle = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ header = "JAPI Library ${module.title} ${module.version}<br />API Documentation"
+ footer = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ bottom = "<div style=" text-align:center;">© 2005-2006 Christian Hujer. All rights reserved. See <a href="{@docRoot}/copyright.html">copyright</a></div>"
+ serialwarn = "yes"
+ charset = "utf-8"
+ docencoding = "utf-8"
+ encoding = "utf-8"
+ source = "1.5"
+ linksource = "yes"
+ link = "${user.javadoc.link}"
+ >
+ <!--
+ overview = "src/overview.html"
+ -->
+ <classpath>
+ <fileset dir="lib" includes="annotations.jar" />
+ </classpath>
+ <sourcepath>
+ <pathelement path="${user.javadoc.javasrc}" />
+ <pathelement path="src/prj" />
+ </sourcepath>
+ <packageset
+ dir="src/prj"
+ defaultexcludes="yes"
+ >
+ <include name="net/**" />
+ </packageset>
+ <taglet name="net.sf.japi.taglets.FixmeTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.HistoryTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.InvariantTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.NoteTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.PostconditionTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.PreconditionTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.ReturnValueTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.TodoTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.WarningTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.XxxTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ </javadoc>
+ </target>
+
+ <target
+ name = "buildapp"
+ description = "Creates executable jar"
+ depends = "compile"
+ >
+ <property name="appName" value="${module.name}-${module.version}-app" />
+ <jar destfile="${appName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <zipgroupfileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <!--attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" /-->
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ </target>
+
+</project>
Property changes on: tools/gdbControl/trunk/build.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: tools/gdbControl/trunk/gdbControl.iml
===================================================================
--- tools/gdbControl/trunk/gdbControl.iml (rev 0)
+++ tools/gdbControl/trunk/gdbControl.iml 2008-11-30 15:54:49 UTC (rev 705)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/doc" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/prj" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/tst" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="annotations" level="project" />
+ <orderEntry type="library" name="junit" level="project" />
+ <orderEntryProperties />
+ </component>
+</module>
+
Property changes on: tools/gdbControl/trunk/gdbControl.iml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: tools/gdbControl/trunk/lib/annotations.jar
===================================================================
(Binary files differ)
Property changes on: tools/gdbControl/trunk/lib/annotations.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: tools/gdbControl/trunk/lib/japi-lib-argparser-trunk.jar
===================================================================
(Binary files differ)
Property changes on: tools/gdbControl/trunk/lib/japi-lib-argparser-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: tools/gdbControl/trunk/module.properties
===================================================================
--- tools/gdbControl/trunk/module.properties (rev 0)
+++ tools/gdbControl/trunk/module.properties 2008-11-30 15:54:49 UTC (rev 705)
@@ -0,0 +1,24 @@
+#
+# GdbControl is a program / library / frontend from Java to gdb.
+# Copyright (C) 2008 Christian Hujer.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+update.focus=none
+module.name=GdbCobtrol
+module.shortname=GdbCobtrol
+module.title=GdbCobtrol
+main.class=net.sf.japi.tools.gdbcontrol.ComWithGdb
Property changes on: tools/gdbControl/trunk/module.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/gdbControl/trunk/src/prj/net/sf/japi/tools/gdbcontrol/ComWithGdb.java
===================================================================
--- tools/gdbControl/trunk/src/prj/net/sf/japi/tools/gdbcontrol/ComWithGdb.java (rev 0)
+++ tools/gdbControl/trunk/src/prj/net/sf/japi/tools/gdbcontrol/ComWithGdb.java 2008-11-30 15:54:49 UTC (rev 705)
@@ -0,0 +1,180 @@
+package net.sf.japi.tools.gdbcontrol;
+
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import org.jetbrains.annotations.NotNull;
+
+/** A Java wrapper for communication with gdb.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ * <!-- Copyright 2008 Christian Hujer. -->
+ */
+public final class ComWithGdb {
+
+ /** The prompt String. */
+ private final CharSequence prompt = "(gdb) ";
+
+ /** The process of gdb. */
+ private Process gdbProcess;
+
+ /** InputStream to read data from gdb's stdout. */
+ private InputStream gdbIn;
+
+ /** OutputStream to write data to gdb's stdin. */
+ private OutputStream gdbOut;
+
+ /** OutputStream to read data from gdb's stderr. */
+ private InputStream gdbErr;
+
+ /** Own InputStream to read data from usually stdin. */
+ private InputStream stdIn;
+
+ /** Own OutputStream to write data to usually stdout. */
+ private OutputStream stdOut;
+
+ /** Own OutputStream to write data to usually stderr. */
+ private OutputStream stdErr;
+
+ /** The encoding to use. */
+ private String encoding = "US-ASCII";
+
+ /** Collector for read operations. */
+ private final ByteArrayOutputStream collector = new ByteArrayOutputStream();
+
+ /** Creates a ComWithGdb.
+ * @param name Name of the program to debug.
+ * @throws IOException in case of I/O problems.
+ */
+ public ComWithGdb(final String name) throws IOException {
+ gdbProcess = Runtime.getRuntime().exec("gdb " + name);
+ gdbIn = gdbProcess.getInputStream();
+ gdbOut = gdbProcess.getOutputStream();
+ gdbErr = gdbProcess.getErrorStream();
+ stdIn = System.in;
+ stdOut = System.out;
+ stdErr = System.err;
+ readUntilPrompt();
+ }
+
+ /** Starts a debug session.
+ * @throws IOException in case of I/O problems.
+ */
+ public void start() throws IOException {
+ execute("start");
+ }
+
+ /** Reads from gdb until gdb sends a prompt.
+ * @return The text until and including the prompt.
+ * @throws IOException in case of I/O problems.
+ */
+ public String readUntilPrompt() throws IOException {
+ return readUntil(prompt);
+ }
+
+ /** Reads until a specific String is found.
+ * @warning This implementation will only work correctly if the text does not contain duplicate characters.
+ * It works fine for Strings like "(gdb) ".
+ * It will not work reliably for Strings like "A_AB" because this will not find "A_AB" in "A_A_AB".
+ * @param text The text to search, usually a prompt.
+ * @return The data that was read until the text was found, including that text itself.
+ * @throws IOException in case of I/O problems.
+ */
+ public synchronized String readUntil(@NotNull final CharSequence text) throws IOException {
+ try {
+ int match = 0;
+ for (int c; (c = gdbIn.read()) != -1;) {
+ stdOut.write(c);
+ collector.write(c);
+ if ((c == text.charAt(match)) || (c == text.charAt(match = 0))) {
+ match++;
+ if (match == text.length()) {
+ return collector.toString(encoding);
+ }
+ }
+ }
+ throw new EOFException("Unexpected end of data from gdb.");
+ } finally {
+ stdOut.flush();
+ }
+ }
+
+ /** Sends a Command to gdb and waits for the next prompt.
+ * @param command Command to send.
+ * @return What gdb responded to that command (including the prompt).
+ * @throws IOException in case of I/O problems.
+ */
+ public String execute(@NotNull final String command) throws IOException {
+ send(command);
+ return readUntilPrompt();
+ }
+
+ /** Sends a Command to gdb.
+ * @param command Command to send.
+ * @throws IOException in case of I/O problems.
+ */
+ public void send(@NotNull final String command) throws IOException {
+ final byte[] data = command.getBytes(encoding);
+ stdOut.write(ANSI.l_blue);
+ gdbOut.write(data);
+ stdOut.write(data);
+ gdbOut.write('\n');
+ stdOut.write('\n');
+ gdbOut.flush();
+ stdOut.write(ANSI.normal);
+ stdOut.flush();
+ }
+
+ /** Quits the gdb.
+ * @return exit value of the gdb process.
+ * @throws IOException in case of I/O problems.
+ * @throws InterruptedException in case the calling thread was interrupted while waiting for gdb's termination.
+ */
+ public int quit() throws IOException, InterruptedException {
+ send("quit");
+ gdbProcess.waitFor();
+ final int retVal = gdbProcess.exitValue();
+ gdbProcess.destroy();
+ gdbProcess = null;
+ return retVal;
+ }
+
+ /** Main program.
+ * @param args Command line arguments - name of the executable to debug.
+ * @throws IOException in case of I/O problems.
+ * @throws InterruptedException in case the calling thread was interrupted while waiting for gdb's termination.
+ */
+ public static void main(final String... args) throws IOException, InterruptedException {
+ final ComWithGdb gdb = new ComWithGdb(args[0]);
+ gdb.execute("start");
+ gdb.quit();
+ }
+
+ /** ANSI color escape sequences. */
+ @SuppressWarnings({"MagicNumber", "ClassNamingConvention"})
+ static class ANSI {
+ static byte[] d_black = { 0x1B, 0x5B, 0x30, 0x30, 0x3B, 0x33, 0x30, 0x6D };
+ static byte[] d_red = { 0x1B, 0x5B, 0x30, 0x30, 0x3B, 0x33, 0x31, 0x6D };
+ static byte[] d_green = { 0x1B, 0x5B, 0x30, 0x30, 0x3B, 0x33, 0x32, 0x6D };
+ static byte[] d_yellow = { 0x1B, 0x5B, 0x30, 0x30, 0x3B, 0x33, 0x33, 0x6D };
+ static byte[] d_blue = { 0x1B, 0x5B, 0x30, 0x30, 0x3B, 0x33, 0x34, 0x6D };
+ static byte[] d_magenta = { 0x1B, 0x5B, 0x30, 0x30, 0x3B, 0x33, 0x35, 0x6D };
+ static byte[] d_cyan = { 0x1B, 0x5B, 0x30, 0x30, 0x3B, 0x33, 0x36, 0x6D };
+ static byte[] d_white = { 0x1B, 0x5B, 0x30, 0x30, 0x3B, 0x33, 0x37, 0x6D };
+
+ static byte[] l_black = { 0x1B, 0x5B, 0x30, 0x31, 0x3B, 0x33, 0x30, 0x6D };
+ static byte[] l_red = { 0x1B, 0x5B, 0x30, 0x31, 0x3B, 0x33, 0x31, 0x6D };
+ static byte[] l_green = { 0x1B, 0x5B, 0x30, 0x31, 0x3B, 0x33, 0x32, 0x6D };
+ static byte[] l_yellow = { 0x1B, 0x5B, 0x30, 0x31, 0x3B, 0x33, 0x33, 0x6D };
+ static byte[] l_blue = { 0x1B, 0x5B, 0x30, 0x31, 0x3B, 0x33, 0x34, 0x6D };
+ static byte[] l_magenta = { 0x1B, 0x5B, 0x30, 0x31, 0x3B, 0x33, 0x35, 0x6D };
+ static byte[] l_cyan = { 0x1B, 0x5B, 0x30, 0x31, 0x3B, 0x33, 0x36, 0x6D };
+ static byte[] l_white = { 0x1B, 0x5B, 0x30, 0x31, 0x3B, 0x33, 0x37, 0x6D };
+
+ static byte[] normal = { 0x1B, 0x5B, 0x30, 0x30, 0x6D };
+
+ private ANSI() {
+ }
+ }
+}
Property changes on: tools/gdbControl/trunk/src/prj/net/sf/japi/tools/gdbcontrol/ComWithGdb.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-11-30 15:27:15
|
Revision: 704
http://japi.svn.sourceforge.net/japi/?rev=704&view=rev
Author: christianhujer
Date: 2008-11-30 15:27:12 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Added Tool MidiDeviceLister.
Added Paths:
-----------
tools/midiDeviceLister/
tools/midiDeviceLister/branches/
tools/midiDeviceLister/tags/
tools/midiDeviceLister/trunk/
tools/midiDeviceLister/trunk/midiDeviceLister.iml
tools/midiDeviceLister/trunk/src/
tools/midiDeviceLister/trunk/src/doc/
tools/midiDeviceLister/trunk/src/prj/
tools/midiDeviceLister/trunk/src/prj/net/
tools/midiDeviceLister/trunk/src/prj/net/sf/
tools/midiDeviceLister/trunk/src/prj/net/sf/japi/
tools/midiDeviceLister/trunk/src/prj/net/sf/japi/tools/
tools/midiDeviceLister/trunk/src/prj/net/sf/japi/tools/midiDeviceLister/
tools/midiDeviceLister/trunk/src/prj/net/sf/japi/tools/midiDeviceLister/MidiDeviceLister.java
tools/midiDeviceLister/trunk/src/tst/
Added: tools/midiDeviceLister/trunk/midiDeviceLister.iml
===================================================================
--- tools/midiDeviceLister/trunk/midiDeviceLister.iml (rev 0)
+++ tools/midiDeviceLister/trunk/midiDeviceLister.iml 2008-11-30 15:27:12 UTC (rev 704)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/doc" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/prj" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/tst" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module" module-name="libs-argparser" />
+ <orderEntry type="library" name="annotations" level="project" />
+ <orderEntry type="library" name="junit" level="project" />
+ <orderEntryProperties />
+ </component>
+</module>
+
Property changes on: tools/midiDeviceLister/trunk/midiDeviceLister.iml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: tools/midiDeviceLister/trunk/src/prj/net/sf/japi/tools/midiDeviceLister/MidiDeviceLister.java
===================================================================
--- tools/midiDeviceLister/trunk/src/prj/net/sf/japi/tools/midiDeviceLister/MidiDeviceLister.java (rev 0)
+++ tools/midiDeviceLister/trunk/src/prj/net/sf/japi/tools/midiDeviceLister/MidiDeviceLister.java 2008-11-30 15:27:12 UTC (rev 704)
@@ -0,0 +1,56 @@
+package net.sf.japi.tools.midiDeviceLister;
+
+import java.util.List;
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequencer;
+import javax.sound.midi.Synthesizer;
+import net.sf.japi.io.args.ArgParser;
+import net.sf.japi.io.args.BasicCommand;
+import org.jetbrains.annotations.NotNull;
+
+/** A small command line program that lists Midi Devices.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class MidiDeviceLister extends BasicCommand {
+
+ /** Main program.
+ * @param args Command line arguments (ignored).
+ */
+ public static void main(final String... args){
+ ArgParser.simpleParseAndRun(new MidiDeviceLister(), args);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings({"InstanceMethodNamingConvention"})
+ public int run(@NotNull final List<String> args) throws Exception {
+ for (final MidiDevice.Info deviceInfo : MidiSystem.getMidiDeviceInfo()) {
+ System.out.println("Name: " + deviceInfo.getName());
+ System.out.println("Version: " + deviceInfo.getVendor());
+ System.out.println("Vendor: " + deviceInfo.getVersion());
+ System.out.println("Description: " + deviceInfo.getDescription());
+ final MidiDevice device = MidiSystem.getMidiDevice(deviceInfo);
+ System.out.println("Maximum transmitters: " + getMaxInfo(device.getMaxTransmitters()));
+ System.out.println("Maximum receivers: " + getMaxInfo(device.getMaxReceivers()));
+ System.out.println("Sequencer: " + (device instanceof Sequencer));
+ System.out.println("Synthesizer: " + (device instanceof Synthesizer));
+ System.out.println();
+ }
+ return 0;
+ }
+
+ /** Returns a String representing a transmitter or receiver maximum count information.
+ * @param count Count to represent as String.
+ * @return String representing that count.
+ */
+ private static String getMaxInfo(final int count) {
+ switch (count) {
+ case -1:
+ return "-1 (Unlimited)";
+ case 0:
+ return "0 (Unsupported)";
+ default:
+ return Integer.toString(count);
+ }
+ }
+}
Property changes on: tools/midiDeviceLister/trunk/src/prj/net/sf/japi/tools/midiDeviceLister/MidiDeviceLister.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-11-30 15:25:32
|
Revision: 703
http://japi.svn.sourceforge.net/japi/?rev=703&view=rev
Author: christianhujer
Date: 2008-11-30 15:25:28 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Added TodoScanner tool.
Added Paths:
-----------
tools/todoScanner/
tools/todoScanner/branches/
tools/todoScanner/tags/
tools/todoScanner/trunk/
tools/todoScanner/trunk/build.xml
tools/todoScanner/trunk/lib/
tools/todoScanner/trunk/module.properties
tools/todoScanner/trunk/src/
tools/todoScanner/trunk/src/doc/
tools/todoScanner/trunk/src/prj/
tools/todoScanner/trunk/src/prj/net/
tools/todoScanner/trunk/src/prj/net/sf/
tools/todoScanner/trunk/src/prj/net/sf/japi/
tools/todoScanner/trunk/src/prj/net/sf/japi/tools/
tools/todoScanner/trunk/src/prj/net/sf/japi/tools/todoScanner/
tools/todoScanner/trunk/src/prj/net/sf/japi/tools/todoScanner/TodoScanner.java
tools/todoScanner/trunk/src/tst/
tools/todoScanner/trunk/todoScanner.iml
Property changes on: tools/todoScanner/trunk
___________________________________________________________________
Added: svn:externals
+ common https://japi.svn.sourceforge.net/svnroot/japi/common/trunk
Added: tools/todoScanner/trunk/build.xml
===================================================================
--- tools/todoScanner/trunk/build.xml (rev 0)
+++ tools/todoScanner/trunk/build.xml 2008-11-30 15:25:28 UTC (rev 703)
@@ -0,0 +1,239 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ TodoScanner is a program for finding TODO comments.
+ ~ Copyright (C) 2008 Christian Hujer
+ ~
+ ~ This program is free software; you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation; either version 2 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License along
+ ~ with this program; if not, write to the Free Software Foundation, Inc.,
+ ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ -->
+
+<project name="Replacer" default="buildapp">
+
+ <property file="module.properties" />
+
+ <!-- Sets module.version to something very reasonable, depending on whether we're in trunk, tags, branches or somewhere else. -->
+ <basename property="dir.version" file="${user.dir}" />
+ <dirname property="parent" file="${user.dir}" />
+ <basename property="parentRegion" file="${parent}" />
+ <exec outputproperty="svnversion" executable="svnversion">
+ <env key="LC_ALL" value="C" />
+ </exec>
+ <condition property="module.version" value="trunk-${svnversion}">
+ <equals arg1="trunk" arg2="${dir.version}" />
+ </condition>
+ <condition property="module.version" value="branch-${dir.version}-${svnversion}">
+ <equals arg1="branches" arg2="${parentRegion}" />
+ </condition>
+ <condition property="module.version" value="${dir.version}">
+ <equals arg1="tags" arg2="${parentRegion}" />
+ </condition>
+ <property name="module.version" value="${parentRegion}-${dir.version}-${svnversion}" />
+
+ <property name="main.class" value="net.sf.japi.tools.replacer.Replacer" />
+
+ <taskdef name="pack200" classpath="common/antlib/Pack200Task.jar" classname="com.sun.tools.apache.ant.pack200.Pack200Task" />
+
+ <target
+ name = "clean"
+ description = "Cleans Sandbox"
+ >
+ <delete dir="classes" />
+ <delete dir="docs" />
+ </target>
+
+ <target
+ name = "compile"
+ description = "Compiles production classes"
+ >
+ <mkdir dir="classes/production/${module.shortname}" />
+ <javac
+ srcdir="src/prj"
+ destdir="classes/production/${module.shortname}"
+ encoding="utf-8"
+ source="1.5"
+ target="1.5"
+ >
+ <classpath>
+ <fileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <fileset dir="common/lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ </classpath>
+ </javac>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="src/prj" includes="**/*.properties" excludes="test/**/*.properties" />
+ <fileset dir="src/prj" includes="META-INF/services/**" />
+ </copy>
+ <copy
+ todir="classes/production/${module.shortname}"
+ >
+ <fileset dir="lib" includes="LICENSE-*" />
+ <fileset dir="." includes="COPYING" />
+ </copy>
+ </target>
+
+ <target
+ name = "dist"
+ description = "Packs distribution archives."
+ depends = "clean, compile"
+ >
+ <delete dir="dist" />
+ <mkdir dir="dist" />
+ <property name="distName" value="dist/${module.name}-${module.version}" />
+ <parallel>
+ <tar tarfile="${distName}.src.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.src.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.src.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="src/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </jar>
+ <jar destfile="${distName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" />
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ <tar tarfile="${distName}.doc.tar">
+ <tarfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </tarfileset>
+ </tar>
+ <zip destfile="${distName}.doc.zip">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ <include name="build.xml" />
+ </zipfileset>
+ </zip>
+ <jar destfile="${distName}.doc.jar">
+ <zipfileset dir="." prefix="${module.name}-${module.version}">
+ <include name="docs/**" />
+ </zipfileset>
+ </jar>
+ </parallel>
+ <parallel>
+ <gzip src="${distName}.src.tar" destfile="${distName}.src.tar.gz" />
+ <bzip2 src="${distName}.src.tar" destfile="${distName}.src.tar.bz2" />
+ <gzip src="${distName}.doc.tar" destfile="${distName}.doc.tar.gz" />
+ <bzip2 src="${distName}.doc.tar" destfile="${distName}.doc.tar.bz2" />
+ <pack200
+ src="${distName}.jar"
+ destfile="${distName}.pack.gz"
+ gzipoutput="true"
+ stripdebug="true"
+ effort="9"
+ keepfileorder="false"
+ modificationtime="latest"
+ deflatehint="false"
+ />
+ </parallel>
+ <delete file="${distName}.src.tar" />
+ <delete file="${distName}.doc.tar" />
+ </target>
+
+ <target
+ name = "doc"
+ description = "Creates public javadoc documentation."
+ >
+ <mkdir dir="docs/api" />
+ <!--copy todir="docs/api" file="src/doc/api/public/copyright.html" />
+ <copy todir="docs/api" file="src/doc/api/public/.htaccess" /-->
+ <javadoc
+ destdir = "docs/api"
+ access = "protected"
+ author = "yes"
+ version = "yes"
+ locale = "en_US"
+ use = "yes"
+ splitindex = "yes"
+ windowtitle = "JAPI Library ${module.title} ${module.version} API documentation"
+ doctitle = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ header = "JAPI Library ${module.title} ${module.version}<br />API Documentation"
+ footer = "JAPI<br />Yet another Java API<br />Library ${module.title} ${module.version} API documentation"
+ bottom = "<div style=" text-align:center;">© 2005-2006 Christian Hujer. All rights reserved. See <a href="{@docRoot}/copyright.html">copyright</a></div>"
+ serialwarn = "yes"
+ charset = "utf-8"
+ docencoding = "utf-8"
+ encoding = "utf-8"
+ source = "1.5"
+ linksource = "yes"
+ link = "${user.javadoc.link}"
+ >
+ <!--
+ overview = "src/overview.html"
+ -->
+ <classpath>
+ <fileset dir="lib" includes="annotations.jar" />
+ </classpath>
+ <sourcepath>
+ <pathelement path="${user.javadoc.javasrc}" />
+ <pathelement path="src/prj" />
+ </sourcepath>
+ <packageset
+ dir="src/prj"
+ defaultexcludes="yes"
+ >
+ <include name="net/**" />
+ </packageset>
+ <taglet name="net.sf.japi.taglets.FixmeTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.HistoryTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.InvariantTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.NoteTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.PostconditionTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.PreconditionTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.ReturnValueTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.TodoTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.WarningTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.XxxTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ </javadoc>
+ </target>
+
+ <target
+ name = "buildapp"
+ description = "Creates executable jar"
+ depends = "compile"
+ >
+ <property name="appName" value="${module.name}-${module.version}-app" />
+ <jar destfile="${appName}.jar">
+ <zipfileset dir="classes/production/${module.shortname}"/>
+ <zipgroupfileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
+ <manifest>
+ <attribute name="Main-Class" value="${main.class}" />
+ <!--attribute name="Class-Path" value="lib/annotations.jar lib/japi-lib-lang-0.1.jar lib/japi-lib-swing-about-0.1.jar lib/japi-lib-swing-action-0.1.jar" /-->
+ <attribute name="Implementation-Title" value="${module.name}" />
+ <attribute name="Implementation-Vendor" value="Christian Hujer + the JAPI Developers" />
+ <attribute name="Implementation-Version" value="${module.version}" />
+ <attribute name="Implementation-URL" value="http://sourceforge.net/projects/japi/" />
+ </manifest>
+ </jar>
+ </target>
+
+</project>
Property changes on: tools/todoScanner/trunk/build.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: tools/todoScanner/trunk/module.properties
===================================================================
--- tools/todoScanner/trunk/module.properties (rev 0)
+++ tools/todoScanner/trunk/module.properties 2008-11-30 15:25:28 UTC (rev 703)
@@ -0,0 +1,23 @@
+#
+# Replacer is a command for performing regular expression substitutions.
+# Copyright (C) 2008 Christian Hujer.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+update.focus=none
+module.name=TodoScanner
+module.shortname=TodoScanner
+module.title=TodoScanner
Property changes on: tools/todoScanner/trunk/module.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/todoScanner/trunk/src/prj/net/sf/japi/tools/todoScanner/TodoScanner.java
===================================================================
--- tools/todoScanner/trunk/src/prj/net/sf/japi/tools/todoScanner/TodoScanner.java (rev 0)
+++ tools/todoScanner/trunk/src/prj/net/sf/japi/tools/todoScanner/TodoScanner.java 2008-11-30 15:25:28 UTC (rev 703)
@@ -0,0 +1,78 @@
+package net.sf.japi.tools.todoScanner;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.Charset;
+import java.util.List;
+import net.sf.japi.io.args.ArgParser;
+import net.sf.japi.io.args.BasicCommand;
+import org.jetbrains.annotations.NotNull;
+
+/** Scanner for comments of specific formats like to do comments.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class TodoScanner extends BasicCommand {
+
+ /** The file encoding that is used for reading and writing files as weil es parsing substitutions from {@link System#in}. */
+ private Charset encoding = Charset.defaultCharset();
+
+ /** Main program.
+ * @param args Command line arguments (try --help).
+ */
+ public static void main(@NotNull final String... args) {
+ ArgParser.simpleParseAndRun(new TodoScanner(), args);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings({"InstanceMethodNamingConvention"})
+ public int run(@NotNull final List<String> args) throws Exception {
+ if (args.size() == 0) {
+ scanForTodos(System.in);
+ } else {
+ for (final String filename : args) {
+ scanForTodos(new File(filename));
+ }
+ }
+ return 0;
+ }
+
+ /** Scans for todos in the specified file.
+ * @param file File to scan for todos.
+ * @throws IOException In case of I/O problems.
+ */
+ public void scanForTodos(@NotNull final File file) throws IOException {
+ final InputStream in = new FileInputStream(file);
+ try {
+ scanForTodos(in);
+ } finally {
+ in.close();
+ }
+ }
+
+ /** Scans for todos in the specified stream.
+ * @param in Stream to scan for todos.
+ * @throws IOException In case of I/O problems.
+ */
+ public void scanForTodos(@NotNull final InputStream in) throws IOException {
+ scanForTodos(new InputStreamReader(in, encoding));
+ }
+
+ /** Scans for todos in the specified stream.
+ * @param cin Stream to scan for todos.
+ * @throws IOException In case of I/O problems.
+ */
+ public void scanForTodos(@NotNull final Reader cin) throws IOException {
+ final BufferedReader in = cin instanceof BufferedReader ? (BufferedReader) cin : new BufferedReader(cin);
+ int lineNumber = 0;
+ for (String line; (line = in.readLine()) != null; lineNumber++) {
+ if (line.matches("TODO")) {
+ System.out.println(lineNumber + ": " + line);
+ }
+ }
+ }
+}
Property changes on: tools/todoScanner/trunk/src/prj/net/sf/japi/tools/todoScanner/TodoScanner.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/todoScanner/trunk/todoScanner.iml
===================================================================
--- tools/todoScanner/trunk/todoScanner.iml (rev 0)
+++ tools/todoScanner/trunk/todoScanner.iml 2008-11-30 15:25:28 UTC (rev 703)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/doc" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/prj" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/tst" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module" module-name="libs-argparser" />
+ <orderEntry type="library" name="annotations" level="project" />
+ <orderEntry type="library" name="junit" level="project" />
+ <orderEntryProperties />
+ </component>
+</module>
+
Property changes on: tools/todoScanner/trunk/todoScanner.iml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-11-30 11:00:57
|
Revision: 702
http://japi.svn.sourceforge.net/japi/?rev=702&view=rev
Author: christianhujer
Date: 2008-11-30 11:00:50 +0000 (Sun, 30 Nov 2008)
Log Message:
-----------
Updated replacer. More tests, better build.
Modified Paths:
--------------
tools/replacer/trunk/build.xml
tools/replacer/trunk/lib/japi-lib-argparser-trunk.jar
tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.java
tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.properties
tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Substitution.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/ReplacerTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/SubstitutionTest.java
Added Paths:
-----------
tools/replacer/trunk/module.properties
tools/replacer/trunk/replacer.iml
tools/replacer/trunk/src/doc/
tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterable.java
tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterator.java
tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/SplitIterator.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationTestCase.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableDefaultTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableLineIteratorTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterablePatternListTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableSplitIteratorTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIteratorTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithSplitIteratorTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithStringSplitTest.java
Property Changed:
----------------
tools/replacer/trunk/
Property changes on: tools/replacer/trunk
___________________________________________________________________
Added: svn:externals
+ common https://japi.svn.sourceforge.net/svnroot/japi/common/trunk
Modified: tools/replacer/trunk/build.xml
===================================================================
--- tools/replacer/trunk/build.xml 2008-11-03 22:59:37 UTC (rev 701)
+++ tools/replacer/trunk/build.xml 2008-11-30 11:00:50 UTC (rev 702)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- ~ DirCount is a program for converting Strings into byte arrays.
+ ~ Replacer is a program for performing an in-place search and replace
+ ~ based on regular expressions.
~ Copyright (C) 2007 Christian Hujer
~
~ This program is free software; you can redistribute it and/or modify
@@ -18,12 +19,28 @@
~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-->
-<project name="Replacer" default="compile">
+<project name="Replacer" default="buildapp">
- <property name="module.version" value="0.1" />
- <property name="module.name" value="Replacer" />
- <property name="module.shortname" value="Replacer" />
- <property name="module.title" value="Replacer" />
+ <property file="module.properties" />
+
+ <!-- Sets module.version to something very reasonable, depending on whether we're in trunk, tags, branches or somewhere else. -->
+ <basename property="dir.version" file="${user.dir}" />
+ <dirname property="parent" file="${user.dir}" />
+ <basename property="parentRegion" file="${parent}" />
+ <exec outputproperty="svnversion" executable="svnversion">
+ <env key="LC_ALL" value="C" />
+ </exec>
+ <condition property="module.version" value="trunk-${svnversion}">
+ <equals arg1="trunk" arg2="${dir.version}" />
+ </condition>
+ <condition property="module.version" value="branch-${dir.version}-${svnversion}">
+ <equals arg1="branches" arg2="${parentRegion}" />
+ </condition>
+ <condition property="module.version" value="${dir.version}">
+ <equals arg1="tags" arg2="${parentRegion}" />
+ </condition>
+ <property name="module.version" value="${parentRegion}-${dir.version}-${svnversion}" />
+
<property name="main.class" value="net.sf.japi.tools.replacer.Replacer" />
<taskdef name="pack200" classpath="common/antlib/Pack200Task.jar" classname="com.sun.tools.apache.ant.pack200.Pack200Task" />
@@ -41,7 +58,6 @@
description = "Compiles production classes"
>
<mkdir dir="classes/production/${module.shortname}" />
- <mkdir dir="classes/test/${module.shortname}" />
<javac
srcdir="src/prj"
destdir="classes/production/${module.shortname}"
@@ -53,7 +69,6 @@
<fileset dir="lib" includes="*.jar" excludes="LICENSE-*.jar" />
<fileset dir="common/lib" includes="*.jar" excludes="LICENSE-*.jar" />
</classpath>
- <exclude name="test/**/*.java" />
</javac>
<copy
todir="classes/production/${module.shortname}"
@@ -74,8 +89,6 @@
description = "Packs distribution archives."
depends = "clean, compile"
>
- <!--depends = "clean, compile, doc"
- -->
<delete dir="dist" />
<mkdir dir="dist" />
<property name="distName" value="dist/${module.name}-${module.version}" />
@@ -191,22 +204,23 @@
>
<include name="net/**" />
</packageset>
- <tag enabled="true" name="retval" description="Return Values:" scope="methods" />
- <tag enabled="true" name="pre" description="Preconditions:" scope="methods,constructors" />
- <tag enabled="true" name="post" description="Postconditions:" scope="methods" />
- <tag enabled="true" name="invariant" description="Invariant:" scope="methods,fields" />
- <tag enabled="true" name="note" description="Notes:" />
- <tag enabled="true" name="warning" description="Warnings:" />
- <!--tag enabled="true" name="todo" description="Todo:" /-->
- <taglet name="com.sun.tools.doclets.ToDoTaglet" path="" />
- <tag enabled="true" name="fixme" description="Fixme:" />
- <tag enabled="true" name="xxx" description="XXX:" />
+ <taglet name="net.sf.japi.taglets.FixmeTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.HistoryTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.InvariantTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.NoteTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.PostconditionTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.PreconditionTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.ReturnValueTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.TodoTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.WarningTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
+ <taglet name="net.sf.japi.taglets.XxxTaglet" path="${commonPath}/antlib/japi-lib-taglets-trunk.jar" />
</javadoc>
</target>
<target
name = "buildapp"
description = "Creates executable jar"
+ depends = "compile"
>
<property name="appName" value="${module.name}-${module.version}-app" />
<jar destfile="${appName}.jar">
Modified: tools/replacer/trunk/lib/japi-lib-argparser-trunk.jar
===================================================================
(Binary files differ)
Added: tools/replacer/trunk/module.properties
===================================================================
--- tools/replacer/trunk/module.properties (rev 0)
+++ tools/replacer/trunk/module.properties 2008-11-30 11:00:50 UTC (rev 702)
@@ -0,0 +1,23 @@
+#
+# Replacer is a command for performing regular expression substitutions.
+# Copyright (C) 2008 Christian Hujer.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+update.focus=none
+module.name=Replacer
+module.shortname=Replacer
+module.title=Replacer
Property changes on: tools/replacer/trunk/module.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/replacer/trunk/replacer.iml
===================================================================
--- tools/replacer/trunk/replacer.iml (rev 0)
+++ tools/replacer/trunk/replacer.iml 2008-11-30 11:00:50 UTC (rev 702)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/doc" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/prj" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/tst" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="annotations" level="project" />
+ <orderEntry type="library" name="junit" level="project" />
+ <orderEntry type="module" module-name="libs-argparser" />
+ <orderEntryProperties />
+ </component>
+</module>
+
Property changes on: tools/replacer/trunk/replacer.iml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterable.java
===================================================================
--- tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterable.java (rev 0)
+++ tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterable.java 2008-11-30 11:00:50 UTC (rev 702)
@@ -0,0 +1,77 @@
+package net.sf.japi.tools.replacer;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.regex.Pattern;
+import org.jetbrains.annotations.NotNull;
+
+/** Iterable for iterating lines.
+ *
+ * @warning The returned Iterator may show unexpected behaviour when the underlying CharSequence is concurrently modified.
+ *
+ * @see LineIterator for more details.
+ *
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class LineIterable implements Iterable<CharSequence> {
+
+ /** The pattern for splitting lines. */
+ private static final Pattern LINE_SPLIT_PATTERN = Pattern.compile("(?<=\\n|\u0085|\u2028|\u2029|\\r(?!\\n))");
+
+ /** The implementation for creating the iterator. */
+ public enum IteratorImplementation {
+
+ /** Create the iterator from a list from a pattern split. */
+ PATTERN_LIST,
+
+ /** Use the {@link LineIterator} class. */
+ LINE_ITERATOR,
+
+ /** Use the {@link SplitIterator} class. */
+ SPLIT_ITERATOR
+ }
+
+ /** Compile time-switch whether to use regex or LineIterator. */
+ public static final IteratorImplementation DEFAULT_MODE = IteratorImplementation.SPLIT_ITERATOR;
+
+ /** The text that should be iterated. */
+ @NotNull private final CharSequence text;
+
+ /** The implementation to use. */
+ @NotNull private final IteratorImplementation mode;
+
+ /** Create an Iterable for iterating lines.
+ * Uses the default mode for creating the iterator.
+ * @param text CharSequence that for iterating line-wise.
+ */
+ public LineIterable(final CharSequence text) {
+ this(text, DEFAULT_MODE);
+ }
+
+ /** Create an Iterable for iterating lines.
+ * Uses the default mode for creating the iterator.
+ * @param text CharSequence that for iterating line-wise.
+ * @param mode Implemenation to use.
+ */
+ public LineIterable(final CharSequence text, @NotNull final IteratorImplementation mode) {
+ this.text = text;
+ this.mode = mode;
+ }
+
+ /** {@inheritDoc} */
+ public Iterator<CharSequence> iterator() {
+ switch (mode) {
+ case PATTERN_LIST:
+ if (text.length() == 0) {
+ return Collections.<CharSequence>emptySet().iterator();
+ }
+ return Arrays.<CharSequence>asList(LINE_SPLIT_PATTERN.split(text)).iterator();
+ case LINE_ITERATOR:
+ return new LineIterator(text);
+ case SPLIT_ITERATOR:
+ return new SplitIterator(text, LINE_SPLIT_PATTERN);
+ }
+ throw new Error("Compile time error. IteratorImplementation missing.");
+ }
+}
Property changes on: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterable.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterator.java
===================================================================
--- tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterator.java (rev 0)
+++ tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterator.java 2008-11-30 11:00:50 UTC (rev 702)
@@ -0,0 +1,115 @@
+package net.sf.japi.tools.replacer;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import org.jetbrains.annotations.NotNull;
+
+/** Iterator for lines.
+ *
+ * <h4>Line terminators</h4>
+ * A <dfn>line terminator</dfn> is a one- or two-character sequence that marks the end of a line of the input character sequence.
+ * The following are recognized as line terminators:
+ * <ul>
+ * <li>A newline (line feed) character (<code>'\n'</code>),</li>
+ * <li>a carriage-return character followed immediately by a newline character (<code>"\r\n"</code>),</li>
+ * <li>a standalone carriage-return character (<code>'\r'</code>),</li>
+ * <li>a next-line character (<code>'\u0085'</code>),</li>
+ * <li>a line-separator character (<code>'\u2028'</code>), or</li>
+ * <li>a paragraph-separator character (<code>'\u2029</code>).</li>
+ * </ul>
+ *
+ * The line terminator is included in the returned line.
+ *
+ * This Iterator does not support {@link Iterator#remove()}.
+ *
+ * @warning The Iterator may show unexpected behaviour when the underlying CharSequence is concurrently modified.
+ *
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class LineIterator implements Iterator<CharSequence> {
+
+ /** Unicode character "NEW LINE" / "LINE FEED". */
+ private static final char LINE_FEED = '\n';
+
+ /** Unicode character "CARRIAGE RETURN". */
+ private static final char CARRIAGE_RETURN = '\r';
+
+ /** Unicode character "NEXT LINE". */
+ private static final char NEXT_LINE = '\u0085';
+
+ /** Unicode character "LINE SEPARATOR". */
+ private static final char LINE_SEPARATOR = '\u2028';
+
+ /** Unicode character "PARAGRAPH SEPARATOR". */
+ private static final char PARAGRAPH_SEPARATOR = '\u2029';
+
+ /** The text that contains the lines over which to iterate. */
+ @NotNull private final CharSequence text;
+
+ /** The end index of the previous line (exclusive),
+ * at the same time the start index of the next line (inclusive).
+ */
+ // Do not rename end - matches CharSequence#subSequence(int, int).
+ private int end = 0;
+
+ /** Create a line iterator.
+ * @param text Text to iterator line-wise.
+ */
+ public LineIterator(@NotNull final CharSequence text) {
+ this.text = text;
+ }
+
+ /** {@inheritDoc} */
+ public boolean hasNext() {
+ return end < text.length();
+ }
+
+ /** {@inheritDoc} */
+ public CharSequence next() {
+ // 1. Check if there is a next line.
+ // If not, the iterator was used wrongly, so throw an exception.
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ // 2. Determine start of line.
+ // The previous end (exclusive) is the next start (inclusive).
+ // Do not rename start - matches CharSequence#subSequence(int, int).
+ final int start = end;
+
+ // 3. Determine end of line.
+ // The end of line is after the next line terminator.
+ while (++end < text.length()) {
+ if (isCharBeforeEndALineTerminator()) {
+ break;
+ }
+ }
+
+ // 4. Return the text's subsequence that is that line.
+ return text.subSequence(start, end);
+ }
+
+ /** Returns whether or not the character before the current {@link #end} terminates a line.
+ * @return Whether or not the character before the current {@link #end} terminates a line.
+ * @retval <code>true</code> if the character before the current {@link #end} terminates a line.
+ * @retval <code>false</code> otherwise (no line termination).
+ */
+ private boolean isCharBeforeEndALineTerminator() {
+ final char c = text.charAt(end - 1);
+ return
+ c == LINE_FEED ||
+ // CARRIAGE_RETURN only already terminates a line if it is standalone.
+ // If it is immediately followed by a LINE_FEED, that line feed will terminate the line in the next invocation.
+ (c == CARRIAGE_RETURN && (end == text.length() || text.charAt(end) != LINE_FEED)) ||
+ c == NEXT_LINE ||
+ c == LINE_SEPARATOR ||
+ c == PARAGRAPH_SEPARATOR;
+ }
+
+ /** {@inheritDoc}
+ * @throws UnsupportedOperationException The remove operation is not supported by this iterator.
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Modified: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.java
===================================================================
--- tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.java 2008-11-03 22:59:37 UTC (rev 701)
+++ tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.java 2008-11-30 11:00:50 UTC (rev 702)
@@ -1,10 +1,5 @@
package net.sf.japi.tools.replacer;
-import net.sf.japi.io.args.ArgParser;
-import net.sf.japi.io.args.BasicCommand;
-import net.sf.japi.io.args.Option;
-import org.jetbrains.annotations.NotNull;
-
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
@@ -18,23 +13,45 @@
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
+import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Formatter;
import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import net.sf.japi.io.args.ArgParser;
+import net.sf.japi.io.args.BasicCommand;
+import net.sf.japi.io.args.CharsetDisplaynameComparator;
+import net.sf.japi.io.args.Option;
+import net.sf.japi.io.args.OptionType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
/** Performs one or more regular expression based substitutions on one or more files.
* Files will only be written if at least one of the substitution steps caused a change.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
+// TODO Add interactive mode.
+// The interactive mode for each match should show the context of the substitution.
+// It should replace only after user confirmation.
+// TODO Add ranges mode.
+// The ranges mode specifies a range before an s command.
+// The default range is % - all lines of the file.
+// Ranges could also be 3,5 - lines 3 to 5 in the file.
+// TODO Add option for user-definable command, e.g. for checking out files from a VCS.
+// TODO Add pretend option to just pretend changing files but do not actually change them.
+// TODO Support comment lines, e.g. with #
public class Replacer extends BasicCommand {
/** The default file ending for backup files. */
@NotNull
public static final String DEFAULT_BACKUP_EXTENSION = ".bak";
- /** Buffer size for read buffer. */
+ /** Buffer size for buffers, e.g. read or copy buffer. */
private static final int BUF_SIZE = 4096;
/** Main program.
@@ -50,25 +67,31 @@
/** Unmodifiable view to the list of substitutions that shall be performed. */
@NotNull private final Collection<Substitution> unmodifiableSubstitutions = Collections.unmodifiableCollection(substitutions);
- /** Whether to force overwriting files or not.
+ /** Whether or not to force overwriting files or not.
* If <code>true</code>, files will be made writable if possible.
* If <code>false</code> (default), files can only be written if they were writable before.
*/
private boolean force;
- /** Whether to recurse into subdirectories or not.
+ /** Whether or not to recurse into subdirectories or not.
* If <code>true</code>, directories will be opened recursively and substitution performed on all files found.
* If <code>false</code> (default), directories will simply be ignored.
*/
private boolean recursive;
- /** Whether to create backups of modified files.
+ /** Whether or not to create backups of modified files.
* If <code>true</code>, backups with the original file content will be made if a file has changed.
* If <code>false</code> (default), no backups will be made.
* Intermediate backups will always be created to make writing pseudo-atomic.
*/
private boolean backup;
+ /** Whether or not to be verbose.
+ * If <code>true</code>, verbose output like the changed file will be printed to stderr.
+ * If <code>false</code> (default), the program behaves silently.
+ */
+ private boolean verbose;
+
/** The number of errors that occurred.
* Errors are only cases where actual exceptions were thrown, i.e. {@link FileNotFoundException} or {@link IOException}.
* If 0 (zero) no errors occurred.
@@ -80,9 +103,13 @@
@NotNull private String backupExtension = DEFAULT_BACKUP_EXTENSION;
/** The file encoding that is used for reading and writing files as weil es parsing substitutions from {@link System#in}. */
- private String encoding = Charset.defaultCharset().name();
+ private Charset encoding = Charset.defaultCharset();
+ /** The command to make the file writable. */
+ @Nullable private String makeWritableCommand = null;
+
/** {@inheritDoc} */
+ @SuppressWarnings({"InstanceMethodNamingConvention"})
public int run(@NotNull final List<String> args) throws Exception {
if (args.size() == 0) {
final CharSequence content = read(System.in);
@@ -114,16 +141,20 @@
replace(f);
}
}
- if (file.isFile()) {
+ // Checking for non-existant files is intentional.
+ // Opening the non-existant file will lead to the exception and thus the error message to inform the user.
+ if (file.isFile() || !file.exists()) {
try {
final CharSequence content = readFile(file);
final CharSequence newContent = replaceAll(content);
if (!equals(content, newContent)) {
- final File tmpFile = new File(file.getParentFile(), file.getName() + backupExtension);
- file.renameTo(tmpFile);
- writeFile(file, newContent);
- if (!backup) {
+ if (backup) {
+ final File tmpFile = new File(file.getParentFile(), file.getName() + backupExtension);
+ copyFile(file, tmpFile);
+ writeFile(file, newContent);
tmpFile.deleteOnExit();
+ } else {
+ writeFile(file, newContent);
}
}
} catch (final IOException e) {
@@ -133,7 +164,7 @@
}
}
- /** Returns whether two Objects are equal regarding their String representation.
+ /** Returns whether or not two Objects are equal regarding their String representation.
* This method is particularly useful for CharSequences because CharSequence does not define a general contract about <code>equals()</code> and <code>hashCode()</code>.
* Therefore it is inappropriate to compare CharSequences using <code>equals()</code>.
* @param s1 First Object to compare.
@@ -148,10 +179,10 @@
* @param orig Original char sequence to perform substitution on.
* @return New CharSequence with all substitutions performed.
*/
- public CharSequence replaceAll(@NotNull final CharSequence orig) {
+ @NotNull public CharSequence replaceAll(@NotNull final CharSequence orig) {
CharSequence temp = orig;
for (final Substitution substitution : substitutions) {
- temp = substitution.replaceAll(temp);
+ temp = substitution.replace(temp);
}
return temp;
}
@@ -161,7 +192,7 @@
* @return Contents of the InputStream.
* @throws IOException In case of I/O problems.
*/
- public CharSequence read(@NotNull final InputStream stream) throws IOException {
+ @NotNull public CharSequence read(@NotNull final InputStream stream) throws IOException {
final StringBuilder sb = new StringBuilder();
final Reader in = new InputStreamReader(stream instanceof BufferedInputStream ? stream : new BufferedInputStream(stream), encoding);
final char[] buf = new char[BUF_SIZE];
@@ -178,7 +209,7 @@
* @return Contents of the file.
* @throws IOException In case of I/O problems.
*/
- public CharSequence readFile(@NotNull final File file) throws IOException {
+ @NotNull public CharSequence readFile(@NotNull final File file) throws IOException {
final InputStream in = new FileInputStream(file);
try {
return read(in);
@@ -189,22 +220,97 @@
/** Writes a CharSequence into a (text) file.
* @param file File to write.
- * @param string CharSequence to write.
+ * @param text CharSequence to write.
* @throws IOException In case of I/O problems.
*/
- public void writeFile(@NotNull final File file, @NotNull final CharSequence string) throws IOException {
+ public void writeFile(@NotNull final File file, @NotNull final CharSequence text) throws IOException {
+ if (verbose) {
+ System.err.print("File : " + file);
+ System.err.flush();
+ }
if (force && !file.canWrite()) {
- file.setWritable(true);
+ makeWritable(file);
}
final Writer out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), encoding);
try {
- out.append(string);
+ out.append(text);
out.flush();
+ if (verbose) {
+ System.err.println("\rChanged file: " + file);
+ }
} finally {
out.close();
}
}
+ /** Copies a file into another.
+ * @param src File from which to copy.
+ * @param dest File to copy to.
+ * @throws IOException in case of I/O problems.
+ */
+ private static void copyFile(@NotNull final File src, @NotNull final File dest) throws IOException {
+ final InputStream in = new FileInputStream(src);
+ try {
+ final OutputStream out = new FileOutputStream(dest);
+ try {
+ copy(in, out);
+ } finally {
+ out.close();
+ }
+ } finally {
+ in.close();
+ }
+ }
+
+ /** Copies a stream to another.
+ * @param in Stream from which to copy.
+ * @param out Stream to copy to.
+ * @throws IOException in case of I/O problems.
+ */
+ private static void copy(@NotNull final InputStream in, @NotNull final OutputStream out) throws IOException {
+ final byte[] buf = new byte[BUF_SIZE];
+ for (int bytesRead; (bytesRead = in.read(buf, 0, BUF_SIZE)) != -1;) {
+ out.write(buf, 0, bytesRead);
+ }
+ out.flush();
+ }
+
+ /** Makes a file writable.
+ * If no command is defined, this is simply done by trying to change the file's access permissions.
+ * If a command is defined, the command will be executed.
+ * @param file File to make writable.
+ * @throws IOException In case of I/O problems when trying to make the file writable.
+ */
+ private void makeWritable(@NotNull final File file) throws IOException {
+ final String makeWritableCommand = this.makeWritableCommand;
+ if (makeWritableCommand != null) {
+ final String cmd = makeWritableCommand.replaceAll("(?<!%)%f", file.toString());
+ if (verbose) {
+ System.err.println("\rExecuting \"" + cmd + "\" to make " + file + " writable.");
+ }
+ final Process p = Runtime.getRuntime().exec(cmd);
+ copy(p.getInputStream(), System.err);
+ copy(p.getErrorStream(), System.err);
+ System.err.flush();
+ try {
+ p.waitFor();
+ } catch (final InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.err.println(p.exitValue());
+ } else {
+ file.setWritable(true);
+ }
+ }
+
+ /** Sets the command to make a file writable.
+ * @param makeWritableCommand Command to make a file writable.
+ */
+ @Option({"writeCmd"})
+ public void setMakeWritableCommand(@NotNull final String makeWritableCommand) {
+ this.makeWritableCommand = makeWritableCommand;
+ }
+
/** Sets or unsets the force option.
* @param force Value of the force option.
*/
@@ -213,13 +319,28 @@
this.force = force;
}
- /** Returns whether the force option is set.
+ /** Returns whether or not the force option is set.
* @return <code>true</code> if the force option is set, otherwise <code>false</code>.
*/
public boolean isForce() {
return force;
}
+ /** Sets or unsets the verbose option.
+ * @param verbose Value of the verbose option.
+ */
+ @Option({"v", "verbose"})
+ public void setVerbose(@NotNull final Boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ /** Returns whether or not the verbose option is set.
+ * @return <code>true</code> if the verbose option is set, otherwise <code>false</code>.
+ */
+ public boolean isVerbose() {
+ return verbose;
+ }
+
/** Sets or unsets the recurse option.
* @param recursive Value of the recurse option.
*/
@@ -228,7 +349,7 @@
this.recursive = recursive;
}
- /** Returns whether the recurse option is set.
+ /** Returns whether or not the recurse option is set.
* @return <code>true</code> if the recurse option is set, otherwise <code>false</code>.
*/
public boolean isRecursive() {
@@ -243,7 +364,7 @@
this.backup = backup;
}
- /** Returns whether the backup option is set.
+ /** Returns whether or not the backup option is set.
* @return <code>true</code> if the backup option is set, otherwise <code>false</code>.
*/
public boolean isBackup() {
@@ -298,4 +419,55 @@
}
}
+ /** Sets the encoding to use for reading and writing files.
+ * @param charsetName Name of the charset to use as encoding for reading and writing files.
+ */
+ @Option({"e", "encoding"})
+ public void setEncoding(@NotNull final String charsetName) {
+ encoding = Charset.forName(charsetName);
+ }
+
+ /** Returns the currently set encoding for reading and writing files.
+ * @return The currently set encoding for reading and writing files.
+ */
+ @NotNull public String getEncoding() {
+ return encoding.name();
+ }
+
+ /** Lists available encodings for reading and writing files. */
+ @Option(type = OptionType.TERMINAL, value = {"listEncodings"})
+ public void listEncodings() {
+ final Formatter format = new Formatter(System.err);
+ final Map<String, Charset> availableCharsets = Charset.availableCharsets();
+ //SortedSet because it is important that they are sorted.
+ //noinspection TypeMayBeWeakened
+ final SortedSet<Charset> charsetsByDisplayname = new TreeSet<Charset>(new CharsetDisplaynameComparator());
+ charsetsByDisplayname.addAll(availableCharsets.values());
+ for (final Charset charset : charsetsByDisplayname) {
+ format.format("%s (Aliases:", charset.name());
+ for (final String alias : charset.aliases()) {
+ format.format(" %s", alias);
+ }
+ format.format(")%n");
+ }
+ format.flush();
+ }
+
+ /** Prints help about the supported flags. */
+ @Option(type = OptionType.TERMINAL, value = {"helpFlags"})
+ public void helpFlags() {
+ final Formatter format = new Formatter(System.err);
+ for (final Character c : new TreeSet<Character>(Substitution.getFlagMap().keySet())) {
+ format.format("%s %s%n", c, getString("flag." + c));
+ }
+ format.flush();
+ }
+
+ /** Prints some more examples. */
+ @Option(type = OptionType.TERMINAL, value = {"helpExamples"})
+ public void helpExamples() {
+ final Formatter format = new Formatter(System.err);
+ format.format(getString("examples"));
+ format.flush();
+ }
}
Modified: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.properties
===================================================================
--- tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.properties 2008-11-03 22:59:37 UTC (rev 701)
+++ tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.properties 2008-11-30 11:00:50 UTC (rev 702)
@@ -2,6 +2,60 @@
setRecursive=Descend into subdirectories recursively.
setBackup=Create backup files.
setBackupExtension=File extension for backup files (default: .bak).
+setEncoding=Encoding to use for reading and writing files.
+setMakeWritableCommand=The command for making a file writable. E.g. 'cleartool checkout -nc "%f"' (UNTESTED!)
+listEncodings=List available encodings for reading and writing files.
addSubstitution=Adds a substitution to the list of substitutions that will be performed.
addSubstitutionsFromFile=Specify a text file with substitutions.
-helpFooter=If multiple substitutions or files are specified, they will be merged. If there are conflicting patterns, the first pattern takes precedence.
+helpHeader=Syntax: Replacer [OPTION...] [FILE...]\n\
+ Performs the regular expression substitutions specified by the options on the specified files.\n\
+ If no file is specified, the substitution is perfromed from stdin to stdout.
+helpFooter=The syntax for substitutions is similar to that of perl, sed or vim:\n\
+ s/regex/subst/flags\n\
+ The description of the regex syntax can be found at http://java.sun.com/docs/jdk6/api/java/util/regex/Pattern.html\n\
+ For a list of supported regex flags, use --helpFlags.\n\
+ If multiple substitutions or files are specified, they will be executed in the same order in which they were specified.\n\
+ \n\
+ Examples:\n\
+ Replacer -s 's/\\bfoo\\b/bar/g' myFile.txt\n \
+ Replaces each occurrence of "foo" as a single word with "bar" in the file myFile.txt.\n\
+ Replacer -r true -v true -s 's/\\bchar\\b/uint8_t/g' src/ inc/\n \
+ Recursively replaces all "char" with "uint8_t" in the directories src/ and inc/.\n \
+ Also prints a list of files that were changed.\n\
+ \n\
+ Memory considerations: Replacer replaces files in-memory.\n\
+ To be safe, assume you need 4 * max file size free heap space.\n\
+ Max file size is the size of the largest file on which you want Replacer to operate.
+helpFlags=Print a help on the flags.
+helpExamples=Print some more examples.
+setVerbose=Verbose mode - report each file that was changed.
+flag.d=UNIX_LINES - ^ and $ matches \\n only. Otherwise they match \\n, \\r\\n, \\r, \\u0085, \\u2028 or \\u2029.
+flag.i=CASE_INSENSITIVE - ignore case for ASCII.
+flag.x=COMMENTS - Permits whitespace and comments in pattern.
+flag.m=MULTILINE - If on, ^ and $ match on lines, if off ^ and $ match on the file. Usually only makes sense together with f.
+flag.l=LITERAL - The pattern is taken literally, not as regular expression. All special characters loose their meanings.
+flag.s=DOTALL - Make . match line terminators as well. By default, . matches any character except the line terminator.
+flag.u=UNICODE_CASE - ignore case for Unicode instead of ASCII if CASE_INSENSITIVE is specified.
+flag.c=CANON_EQ - Enables canonical equivalence for Unicode, e.g. \\u030A matches \\u00E5.\n Beware, vi users: /c is NOT "confirm".
+flag.g=If specified, replace all occurrences, otherwise only the first.\n If FILE is set, this is the first in the file, otherwise this is the first in each line.
+flag.f=If on, substitution is performed per-file. If off, substitution is performed line-per-line.
+examples=Replacer Examples\n\n\
+ Example: Insert text 'foo' at each start of line\n \
+ Replacer -s 's/^/foo/' someFile.txt\n\
+ \n\
+ Example: Insert text '//' at each start of line\n \
+ Replacer -s 's/^/\\/\\//' someFile.txt\n\
+ \n\
+ Example: Insert text 'foo' at each end of line\n \
+ Replacer -s 's/$/foo/' someFile.txt\n\
+ \n\
+ Example: Remove trailing whitespace\n \
+ Replacer -s 's/[ \\t]+$//' someFile.txt\n\
+ Note: 's/\\s+$//' as you know it from vim wouldn't work as expected.\n\
+ \n\
+ Example: Change from Allman to 1TBS, taking care of comments as well\n \
+ Replacer -s 's/\\s*?( ?(?:\\/\\/.*|\\/\\*.*\\*\\/))$\\s+\\{/ {$1/mfg' -r true src/\n\
+ \n\
+ Note on all examples: The syntax specified is for bash and similar shells.\n\
+ When running Replacer on another OS, a different command line syntax may be required.\n
+
Added: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/SplitIterator.java
===================================================================
--- tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/SplitIterator.java (rev 0)
+++ tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/SplitIterator.java 2008-11-30 11:00:50 UTC (rev 702)
@@ -0,0 +1,89 @@
+package net.sf.japi.tools.replacer;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.jetbrains.annotations.NotNull;
+
+/** An iterator that iterates over a regular expression split.
+ *
+ * @note Splitting the empty String will lead to zero CharSequences returned by this Iterator.
+ *
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class SplitIterator implements Iterator<CharSequence> {
+
+ /** The CharSequence to split. */
+ @NotNull private final CharSequence text;
+
+ /** The Matcher used. */
+ @NotNull private final Matcher matcher;
+
+ /** The start of the next part.
+ * By initializing it with zero, {@link #hasNext()} will return false for an empty String.
+ */
+ private int nextStart = 0;
+
+ /** Creates a SplitIterator.
+ * @param text Text to split.
+ * @param pattern Pattern to use for splitting.
+ */
+ public SplitIterator(@NotNull final CharSequence text, @NotNull final Pattern pattern) {
+ this.text = text;
+ matcher = pattern.matcher(text);
+ }
+
+ /** Creates a SplitIterator.
+ * @param text Text to split.
+ * @param pattern Patten to use for splitting.
+ */
+ public SplitIterator(@NotNull final CharSequence text, @NotNull final String pattern) {
+ this.text = text;
+ matcher = Pattern.compile(pattern).matcher(text);
+ }
+
+ /** {@inheritDoc} */
+ public boolean hasNext() {
+ return nextStart < text.length();
+ }
+
+ /** {@inheritDoc} */
+ public CharSequence next() {
+ // 1. Throw an exception if there are no remaining elements.
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ // 2. Determine the start of the element.
+ // The start was the initial value or set by the previous invocation of next().
+ // Do not rename start - matches CharSequence#subSequence(int, int).
+ final int start = nextStart;
+
+ // 3. Determine the end (exclusive) of the element and the start of the next element.
+ final int end;
+ if (matcher.find()) {
+ // If the matcher found something, there either are remaining elements or it matched the end of the text.
+ // In both situations, this element ends before the start of the match.
+ end = matcher.start();
+ // If there are remaining elements, nextStart points to the next element.
+ // If not, nextStart points beyond the end of the text, which correctly prevents further iteration.
+ nextStart = matcher.end();
+ } else {
+ // If there are no remaining parts, the end of the part is the end of the text().
+ // Setting nextStart beyond the end of the text will prevent further iterations.
+ end = text.length();
+ nextStart = text.length();
+ }
+
+ // 4. Return the subsequence that is that part.
+ return text.subSequence(start, end);
+ }
+
+ /** {@inheritDoc}
+ * @throws UnsupportedOperationException The remove operation is not supported by this iterator.
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/SplitIterator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Modified: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Substitution.java
===================================================================
--- tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Substitution.java 2008-11-03 22:59:37 UTC (rev 701)
+++ tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Substitution.java 2008-11-30 11:00:50 UTC (rev 702)
@@ -9,19 +9,21 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-/** Substitution is a small wrapper class for performing repeated substitutions.
+/** Substitution is a small wrapper class for performing repeated regular expression substitutions.
+ * Its main purpose is to provide a sed / perl / vi-like interface to regular expression substitutions.
+ *
* <h4 id="substitutionSyntax">Syntax of the substitution command</h4>
* <p>
- * Whne specifying a substitution with the constructor {@link #Substitution(CharSequence)}, the parameter specifies the substitution.
- * That parameter MUST follow the syntax described here.
+ * When specifying a substitution with the constructor {@link #Substitution(CharSequence)}, the parameter specifies the substitution.
+ * That parameter MUST follow the syntax described here, which is resembled after the syntax found in sed / perl / vi and similar tools.
* </p>
* <p>
- * Syntax: <code>s/<var>substitution</var>/<var>replacement</var>/<var>flags</var></code>
+ * Syntax: <code>s/<var>pattern</var>/<var>replacement</var>/<var>flags</var></code>
* </p>
* <dl>
- * <dt><code><var>substitution</var></code></dt>
+ * <dt><code><var>pattern</var></code></dt>
* <dd>
- * Specifies the substitution regular expression.
+ * Specifies the regular expression for the substitution.
* </dd>
* <dt><code><var>replacement</var></code></dt>
* <dd>
@@ -30,15 +32,56 @@
* <dt><code><var>flags</var></code></dt>
* <dd>
* Specifies the flags.
- * Currently the flags are ignored.
* </dd>
* </dl>
+ *
+ * <h4>Supported substitution flags</h4>
+ * <p>
+ * The substitution flags are specified as a sequence of characters, each of which activates a certain behaviour.
+ * The flags may be specified in any order and combination.
+ * The following flags are supported:
+ * </p>
+ * <ul>
+ * <li><code>d</code> activates {@link Pattern#UNIX_LINES}</li>
+ * <li><code>i</code> activates {@link Pattern#CASE_INSENSITIVE}</li>
+ * <li><code>x</code> activates {@link Pattern#COMMENTS}</li>
+ * <li><code>m</code> activates {@link Pattern#MULTILINE}</li>
+ * <li><code>l</code> activates {@link Pattern#LITERAL}</li>
+ * <li><code>s</code> activates {@link Pattern#DOTALL}</li>
+ * <li><code>u</code> activates {@link Pattern#UNICODE_CASE}</li>
+ * <li><code>c</code> activates {@link Pattern#CANON_EQ}</li>
+ * <li><code>g</code> activates global mode (replace all instead of replace first - replace first is default if <code>g</code> is not set)</li>
+ * <li><code>f</code> activates file mode (match pattern against the whole file instead of individual llines - default is line mode)</li>
+ * </ul>
+ *
+ * <h4>Replacement syntax extension</h4>
+ * In addition to group reference with \ and $, the replacement part may contain the following escape sequences:
+ * <ul>
+ * <li><code>\/</code> A literal '/' (otherwise '/' would terminate the substitution)</li>
+ * <li><code>\\</code> A literel '\'</li>
+ * <li><code>\n</code> The newline character (line feed)</li>
+ * <li><code>\r</code> The carriage return character</li>
+ * <li><code>\t</code> The tab character</li>
+ * <li><code>\f</code> The form feed character</li>
+ * <li><code>\a</code> The bell character</li>
+ * <li><code>\e</code> The escape character</li>
+ * <li><code>\$</code> The dollar character (otherwise would start a backreference)</li>
+ * </ul>
+ * @note The replacement syntax extension is subject of change.
+ * There are plans to support \l, \L, \u, \U, \E etc. in the replacement syntax.
+ *
+ * @see Pattern for a detailled description of the supported regular expression syntax.
+ *
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
+// TODO: Add support for /e and a way for specifying the expression language (e.g. Java, ECMAScript, Groovy) for /e.
public class Substitution {
- /** The regular expression used to parse an sed / perl / vim like substitution command. */
- private static final Pattern rePattern = Pattern.compile("^s/((?:\\\\/|[^/])*+)/((?:\\\\/|[^/])*+)/(.*+)$");
+ /** The regular expression used to parse an sed / perl / vi like substitution command.
+ * The syntax is "s/pattern/replacement/flags".
+ * If "/" appears in the pattern or the replacement, it needs to be escaped.
+ */
+ private static final Pattern rePattern = Pattern.compile("^s/((?:\\\\/|[^/])*+)/((?:\\\\|\\\\/|[^/])*+)/(.*+)$");
/** The unmodifiable map with the flags.
* Key: Flag character.
@@ -52,9 +95,23 @@
/** The replacement specifier for a substitution. */
private final String replacement;
- /** The flags used for substitution. */
+ /** The flags used for substitution.
+ * Only those flags supported by {@link Pattern} are stored in this variable.
+ */
private final int flags;
+ /** The global flag.
+ * If true, replaces all occurrences.
+ * If false, replaces the first occurrency only.
+ */
+ private final boolean global;
+
+ /** The file flag.
+ * If true, replace file wise.
+ * If false, replace line wise.
+ */
+ private final boolean file;
+
/** The matcher for performing the substitution. */
private final Matcher matcher;
@@ -62,6 +119,7 @@
* @param params Parameters in the order <var>pattern</var>, <var>replacement</var>, <var>flags</var>.
* @pre params.length == 3
*/
+ @SuppressWarnings({"OverloadedVarargsMethod"}) // Not public anyway.
private Substitution(@NotNull final String... params) {
this(params[0], params[1], params[2]);
assert params.length == 3 : "Expected length: 3, got length: " + params.length;
@@ -79,7 +137,7 @@
* @param patternString Regular expression matcher pattern.
* @param replacement Replacement.
*/
- public Substitution(@NotNull final String patternString, @NotNull final String replacement) {
+ public Substitution(@NotNull final String patternString, @NotNull final CharSequence replacement) {
this(patternString, replacement, null);
}
@@ -87,21 +145,69 @@
* @param patternString Regular expression matcher pattern.
* @param replacement Replacement.
* @param flags Substitution Flags (currently ignored).
+ * @param global <code>true</code> to replace all, <code>false<code> to replace first only.
+ * @param file <code>true</code> to match file, <code>false<code> to match lines.
*/
- public Substitution(@NotNull final String patternString, @NotNull final String replacement, final int flags) {
+ public Substitution(@NotNull final String patternString, @NotNull final CharSequence replacement, final int flags, final boolean global, final boolean file) {
this.patternString = patternString;
- this.replacement = replacement;
+ this.replacement = unescapeReplacement(replacement);
this.flags = flags;
+ this.global = global;
+ this.file = file;
matcher = Pattern.compile(patternString, flags).matcher("");
}
+ /** Takes a String (usually the replacement part of a substitution) and replaces escape sequences.
+ * @param replacement String to unescape.
+ * @return Unescaped String.
+ */
+ private static String unescapeReplacement(final CharSequence replacement) {
+ boolean escape = false;
+ final StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < replacement.length(); i++) {
+ final char c = replacement.charAt(i);
+ if (escape) {
+ escape = false;
+ switch (c) {
+ // Supporting \t to \e brings at least a subset of the escape sequences supported in patters into the substitution part.
+ case 't': sb.append('\t'); break;
+ case 'n': sb.append('\n'); break;
+ case 'r': sb.append('\r'); break;
+ case 'f': sb.append('\f'); break;
+ case 'a': sb.append('\u0007'); break;
+ case 'e': sb.append('\u001b'); break;
+ case '$': sb.append("\\$"); break;
+ case '\\': sb.append("\\\\"); break;
+ default:
+ if (c >= '0' && c <= '9') {
+ sb.append('\\').append(c);
+ } else {
+ throw new IllegalArgumentException("Unsupported escape sequence in replacement part.");
+ }
+ }
+ } else {
+ switch (c) {
+ case '\\':
+ escape = true;
+ break;
+ default:
+ sb.append(c);
+ }
+ }
+ }
+ if (escape) {
+ throw new IllegalArgumentException("Incomplete escape sequence in replacement part.");
+ }
+ return sb.toString();
+ }
+
/** Creates a Substitution based on the specified pattern and replacement.
* @param patternString Regular expression matcher pattern.
* @param replacement Replacement.
* @param flags Substitution Flags (currently ignored).
*/
- public Substitution(@NotNull final String patternString, @NotNull final String replacement, @Nullable final String flags) {
- this(patternString, replacement, parseFlags(flags));
+ public Substitution(@NotNull final String patternString, @NotNull final CharSequence replacement, @Nullable final String flags) {
+ this(patternString, replacement, parseFlags(flags), isGlobal(flags), isFile(flags));
}
/** Creates an unmodifiable map with the flags.
@@ -113,31 +219,35 @@
flagMap.put('i', Pattern.CASE_INSENSITIVE);
flagMap.put('x', Pattern.COMMENTS);
flagMap.put('m', Pattern.MULTILINE);
- flagMap.put('l', Pattern.LITERAL); // TODO check char
+ flagMap.put('l', Pattern.LITERAL);
flagMap.put('s', Pattern.DOTALL);
flagMap.put('u', Pattern.UNICODE_CASE);
- flagMap.put('c', Pattern.CANON_EQ); // TODO check char
+ flagMap.put('c', Pattern.CANON_EQ);
+ flagMap.put('g', null); // g is supported by Substitution but not by Pattern / Matcher, we handle it ourselves.
+ flagMap.put('f', null); // f is supported by Substitution but not by Pattern / Matcher, we handle it ourselves.
return Collections.unmodifiableMap(flagMap);
}
/** Converts a flag string into a flag value.
* @param flagString String that specifies substitution flags.
* @return Integer value with the flags.
- * @throws IllegalArgumentException in case an invalid flag was specified.
+ * @throws IllegalArgumentException in case an unsupported flag was specified.
*/
public static int parseFlags(@Nullable final String flagString) {
int flags = 0;
if (flagString != null) {
StringBuilder bogusFlags = null;
for (final char c : flagString.toCharArray()) {
- final Integer flag = flagMap.get(c);
- if (flag == null) {
+ if (flagMap.containsKey(c)) {
+ final Integer flag = flagMap.get(c);
+ if (flag != null) {
+ flags |= flag;
+ }
+ } else {
if (bogusFlags == null) {
bogusFlags = new StringBuilder();
}
bogusFlags.append(c);
- } else {
- flags |= flag;
}
}
if (bogusFlags != null) {
@@ -147,16 +257,32 @@
return flags;
}
+ /** Returns whether the flags have the global flag set.
+ * @param flagString String that specifies substitution flags.
+ * @return <code>true</code> if the flagString has the g flag set, otherwise <code>false</code>
+ */
+ public static boolean isGlobal(@Nullable final String flagString) {
+ return flagString != null && flagString.contains("g");
+ }
+
+ /** Returns whether the flags have the file flag set.
+ * @param flagString String that specifies substitution flags.
+ * @return <code>true</code> if the flagString has the f flag set, otherwise <code>false</code>
+ */
+ public static boolean isFile(@Nullable final String flagString) {
+ return flagString != null && flagString.contains("f");
+ }
+
/** Splits a substitution String into its subcomponents.
* @param regex Substitution String to split.
* @return The three subcomponents pattern, replacement and flags.
*/
public static String[] parseRegex(@NotNull final CharSequence regex) {
- final String[] parsed = new String[3];
final Matcher matcher = rePattern.matcher(regex);
if (!matcher.matches()) {
throw new IllegalArgumentException("Malformed substitution command.");
}
+ final String[] parsed = new String[3];
parsed[0] = matcher.group(1);
parsed[1] = matcher.group(2);
parsed[2] = matcher.group(3);
@@ -167,9 +293,20 @@
* @param s CharSequence in which to perform the substitution.
* @return a String which represents <var>s</var> after performing all substitutions.
*/
- public String replaceAll(final CharSequence s) {
- matcher.reset(s);
- return matcher.replaceAll(replacement);
+ public String replace(final CharSequence s) {
+ if (file) {
+ matcher.reset(s);
+ return global ? matcher.replaceAll(replacement) : matcher.replaceFirst(replacement);
+ } else {
+ final StringBuilder sb = new StringBuilder();
+ final Pattern linePattern = Pattern.compile((flags & Pattern.UNIX_LINES) == Pattern.UNIX_LINES ? "(?<=\\n)" : "(?<=\\n|\u0085|\u2028|\u2029|\\r(?!\\n))");
+ for (final CharSequence line : linePattern.split(s)) {
+ //for (final CharSequence line : new LineIterable(s)) {
+ matcher.reset(line);
+ sb.append(global ? matcher.replaceAll(replacement) : matcher.replaceFirst(replacement));
+ }
+ return sb.toString();
+ }
}
/** Returns the regular expression pattern that is used to perform this Substitution.
@@ -187,10 +324,35 @@
}
/** Returns the flags that are used to perform this Substitution.
+ * @note This method returns only those flags known to {@link Pattern}.
* @return The flags that are used to perform this Substitution.
+ * @see #isFile() For the global flag.
+ * @see #isGlobal() For the file flag.
*/
public int getFlags() {
return flags;
}
+ /** Returns whether or not the file flag is set.
+ * @return <code>true</code> if the file flag is set, otherwise <code>false</code>.
+ */
+ public boolean isFile() {
+ return file;
+ }
+
+ /** Returns whether or not the global flag is set.
+ * @return <code>true</code> if the global flag is set, otherwise <code>false</code>.
+ */
+ public boolean isGlobal() {
+ return global;
+ }
+
+ /** Returns the flag map.
+ * @return The flag map.
+ */
+ public static Map<Character, Integer> getFlagMap() {
+ //The collection already is unmodifiable.
+ //noinspection ReturnOfCollectionOrArrayField
+ return flagMap;
+ }
}
Added: tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationTestCase.java
===================================================================
--- tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationTestCase.java (rev 0)
+++ tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationTestCase.java 2008-11-30 11:00:50 UTC (rev 702)
@@ -0,0 +1,129 @@
+package test.net.sf.japi.tools.replacer;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import net.sf.japi.tools.replacer.LineIterable;
+import org.jetbrains.annotations.NotNull;
+import org.junit.Assert;
+import org.junit.Test;
+
+/** Unit Test for {@link LineIterable}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+pu...
[truncated message content] |
|
From: <chr...@us...> - 2008-11-03 22:59:39
|
Revision: 701
http://japi.svn.sourceforge.net/japi/?rev=701&view=rev
Author: christianhujer
Date: 2008-11-03 22:59:37 +0000 (Mon, 03 Nov 2008)
Log Message:
-----------
Updated site README.
Modified Paths:
--------------
site/trunk/README
Modified: site/trunk/README
===================================================================
--- site/trunk/README 2008-10-07 23:34:08 UTC (rev 700)
+++ site/trunk/README 2008-11-03 22:59:37 UTC (rev 701)
@@ -1,8 +1,10 @@
-JAPI COMMON README
-==================
+JAPI SITE README
+================
-This file contains some important information about Japi Common. You should
-read it first.
+This is the source code of the project website.
+It also is under version control to be able to track changes to the website.
+Another goodie is that it enables all JAPI admins to update the website any
+time.
TABLE OF CONTENTS
@@ -43,61 +45,6 @@
Previous versions of Ant might work but are not tested.
-FILE STRUCTURE
---------------
-build.xml
- The build file to build the project with Ant.
-
-COPYING
- Japi Common license conditions. Note: applies to Japi Common only, not
- third party libraries.
-
-CREDITS
- List of project contributors. See also MAINTAINERS.
-
-INSTALL
- Description of how to build and install Japi Common.
-
-lib/
- Directory containing third party libraries used to build Japi Common.
- Please note that these thrid party libraries have their own license
- conditions. The licenses of the third party libraries are included in the
- lib/ directory.
-
-LICENSE
- File with license information.
-
-MAINTAINERS
- List of current project maintainers. See also CREDITS.
-
-NEWS
- Project News.
-
-project.properties
- File with automatically changed settings for Ant.
-
-README
- This file.
-
-src/
- Source files.
-
-
-BUILD / INSTALLATION
---------------------
-See the file INSTALL.
-
-
-MAINTAINERS / CREDITS
----------------------
-See the file CREDITS.
-
-
-PROJECT NEWS
-------------
-See the file NEWS.
-
-
MAILING LISTS
-------------
Japi mailing lists are the usual sourceforge hosted sourceforge project
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 23:34:14
|
Revision: 700
http://japi.svn.sourceforge.net/japi/?rev=700&view=rev
Author: christianhujer
Date: 2008-10-07 23:34:08 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Minor improvements.
Modified Paths:
--------------
libs/swing-list/trunk/src/prj/net/sf/japi/swing/list/ArrayListModel.java
libs/swing-list/trunk/src/prj/net/sf/japi/swing/list/MutableListModel.java
Modified: libs/swing-list/trunk/src/prj/net/sf/japi/swing/list/ArrayListModel.java
===================================================================
--- libs/swing-list/trunk/src/prj/net/sf/japi/swing/list/ArrayListModel.java 2008-10-07 23:33:55 UTC (rev 699)
+++ libs/swing-list/trunk/src/prj/net/sf/japi/swing/list/ArrayListModel.java 2008-10-07 23:34:08 UTC (rev 700)
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** ArrayList-backed implementation of {@link MutableListModel}.
@@ -66,7 +67,7 @@
}
/** {@inheritDoc} */
- public boolean remove(final E e) {
+ public boolean remove(final Object e) {
if (!list.contains(e)) {
throw new IllegalArgumentException("Element " + e + " not part of " + this);
}
@@ -171,7 +172,45 @@
/** {@inheritDoc} */
public Iterator<E> iterator() {
- return list.iterator();
+ return new IteratorWrapper(list.iterator());
}
+ /** Iterator wrapper.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+ private class IteratorWrapper implements Iterator<E> {
+
+ /** Iterator that's wrapped. */
+ private Iterator<E> iterator;
+
+ /** The current element, needed in {@link #remove()}. */
+ private E currentElement = null;
+
+ /** Create an IteratorWrapper.
+ * @param iterator Iterator to wrap.
+ */
+ IteratorWrapper(@NotNull final Iterator<E> iterator) {
+ this.iterator = iterator;
+ }
+
+ /** {@inheritDoc} */
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ /** {@inheritDoc} */
+ public E next() {
+ currentElement = iterator.next();
+ return currentElement;
+ }
+
+ /** {@inheritDoc} */
+ public void remove() {
+ synchronized (list) {
+ final int index = list.indexOf(currentElement);
+ iterator.remove();
+ fireIntervalRemoved(this, index, index);
+ }
+ }
+ }
} // class ArrayListModel
Modified: libs/swing-list/trunk/src/prj/net/sf/japi/swing/list/MutableListModel.java
===================================================================
--- libs/swing-list/trunk/src/prj/net/sf/japi/swing/list/MutableListModel.java 2008-10-07 23:33:55 UTC (rev 699)
+++ libs/swing-list/trunk/src/prj/net/sf/japi/swing/list/MutableListModel.java 2008-10-07 23:34:08 UTC (rev 700)
@@ -40,7 +40,7 @@
* @param e Element to remove.
* @return <code>true</code> if the element was successfully removed, otherwise <code>false</code>.
*/
- boolean remove(E e);
+ boolean remove(Object e);
/** Moves the specified element to top.
* @param e Element to move to top.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 23:34:04
|
Revision: 699
http://japi.svn.sourceforge.net/japi/?rev=699&view=rev
Author: christianhujer
Date: 2008-10-07 23:33:55 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Made compilable with ant.
Modified Paths:
--------------
libs/swing-list/trunk/lib/japi-lib-swing-action-trunk.jar
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 23:30:42
|
Revision: 698
http://japi.svn.sourceforge.net/japi/?rev=698&view=rev
Author: christianhujer
Date: 2008-10-07 23:30:37 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Made compilable with ant.
Added Paths:
-----------
libs/swing-font/trunk/lib/
libs/swing-font/trunk/lib/japi-lib-swing-action-trunk.jar
Property changes on: libs/swing-font/trunk/lib/japi-lib-swing-action-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 23:28:41
|
Revision: 697
http://japi.svn.sourceforge.net/japi/?rev=697&view=rev
Author: christianhujer
Date: 2008-10-07 23:28:33 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Fixed code conventions issues.
Made compilable with ant.
Modified Paths:
--------------
libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/BookmarkManager.java
libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/BookmarkTransferHandler.java
libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/Bookmarkable.java
Added Paths:
-----------
libs/swing-bookmarks/trunk/lib/
libs/swing-bookmarks/trunk/lib/japi-lib-swing-action-trunk.jar
libs/swing-bookmarks/trunk/lib/japi-lib-swing-app-trunk.jar
libs/swing-bookmarks/trunk/lib/japi-lib-util-trunk.jar
Property changes on: libs/swing-bookmarks/trunk/lib/japi-lib-swing-action-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Property changes on: libs/swing-bookmarks/trunk/lib/japi-lib-swing-app-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Property changes on: libs/swing-bookmarks/trunk/lib/japi-lib-util-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/BookmarkManager.java
===================================================================
--- libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/BookmarkManager.java 2008-10-07 23:24:28 UTC (rev 696)
+++ libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/BookmarkManager.java 2008-10-07 23:28:33 UTC (rev 697)
@@ -91,11 +91,18 @@
this.bookmarkable = bookmarkable;
try {
load();
- save();
- } catch (final Exception e) {
+ } catch (final IOException e) {
e.printStackTrace();
- // TODO: improve dialog
+ // TODO:christianhujer:improve dialog
showMessageDialog(bookmarkable.getBookmarkBlocker(), ACTION_BUILDER.getString("bookmarksCreated.message"));
+ } catch (final ParserConfigurationException e) {
+ e.printStackTrace();
+ // TODO:christianhujer:improve dialog
+ showMessageDialog(bookmarkable.getBookmarkBlocker(), ACTION_BUILDER.getString("bookmarksCreated.message"));
+ } catch (final SAXException e) {
+ e.printStackTrace();
+ // TODO:christianhujer:improve dialog
+ showMessageDialog(bookmarkable.getBookmarkBlocker(), ACTION_BUILDER.getString("bookmarksCreated.message"));
}
}
@@ -276,6 +283,7 @@
* </ul>
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
+ @SuppressWarnings({"ClassReferencesSubclass"})
public abstract static class Bookmark extends AbstractAction implements MutableTreeNode {
/** Title for Bookmark.
@@ -545,7 +553,7 @@
* This should only be used for the basic BookmarkFolder containing all other BookmarkItems and BookmarkFolders.
*/
public BookmarkFolder() {
- super(ACTION_BUILDER.getString("bookmark_text"));
+ super(ACTION_BUILDER.getString("bookmark.text"));
}
/** Create a BookmarkFolder.
Modified: libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/BookmarkTransferHandler.java
===================================================================
--- libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/BookmarkTransferHandler.java 2008-10-07 23:24:28 UTC (rev 696)
+++ libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/BookmarkTransferHandler.java 2008-10-07 23:28:33 UTC (rev 697)
@@ -45,7 +45,7 @@
*/
@Override
public boolean canImport(final JComponent comp, final DataFlavor[] transferFlavors) {
- // TODO
+ // TODO:christianhujer:Proper implementation.
return true;
}
Modified: libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/Bookmarkable.java
===================================================================
--- libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/Bookmarkable.java 2008-10-07 23:24:28 UTC (rev 696)
+++ libs/swing-bookmarks/trunk/src/prj/net/sf/japi/swing/bookmarks/Bookmarkable.java 2008-10-07 23:28:33 UTC (rev 697)
@@ -21,18 +21,20 @@
import java.awt.Component;
import net.sf.japi.swing.app.CanLoad;
+import net.sf.japi.swing.app.Document;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** Interface for classes that want to interact with the BookmarkManager.
* Implement this interface if your class provides information for creating bookmarks.
* See the class {@link BookmarkManager} for more information on Bookmarks.
+ * @param <D> The document type that can be loaded.
* @see BookmarkManager
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public interface Bookmarkable extends CanLoad {
+public interface Bookmarkable<D> extends CanLoad<D> {
- /** Get wether it currently is possible to create a bookmark.
+ /** Get whether it currently is possible to create a bookmark.
* @return <code>true</code> if it is possible to create a bookmark, e.g. {@link #getBookmarkTitle()} and {@link #getBookmarkURL()} will return
* meaningful values, otherwise <code>false</code>
*/
@@ -53,9 +55,10 @@
/** {@inheritDoc}
* Invoked when the user requests to load a Bookmark.
* The implementor of this method is itself responsible of handling errors and displaying eventual error messages to the user
- * @param url URL from bookmark
+ * @param uri URL from bookmark
*/
- boolean load(@NotNull String url);
+ @NotNull
+ Document<D> load(@NotNull String uri);
/** Get the component which to block for modal dialogs.
* It is safe to return <code>null</code>.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 23:24:35
|
Revision: 696
http://japi.svn.sourceforge.net/japi/?rev=696&view=rev
Author: christianhujer
Date: 2008-10-07 23:24:28 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Fixed code conventions issues.
Added new tests.
Modified Paths:
--------------
libs/util/trunk/src/prj/net/sf/japi/util/Arrays2.java
libs/util/trunk/src/prj/net/sf/japi/util/filter/file/AbstractFileFilter.java
libs/util/trunk/src/prj/net/sf/japi/util/filter/file/EndingFileFilter.java
libs/util/trunk/src/prj/net/sf/japi/util/filter/file/Factory.java
libs/util/trunk/src/prj/net/sf/japi/util/filter/file/FilenameFileFilter.java
libs/util/trunk/src/tst/test/net/sf/japi/util/Arrays2Test.java
Added Paths:
-----------
libs/util/trunk/src/tst/test/net/sf/japi/util/EnumerationIteratorTest.java
Modified: libs/util/trunk/src/prj/net/sf/japi/util/Arrays2.java
===================================================================
--- libs/util/trunk/src/prj/net/sf/japi/util/Arrays2.java 2008-10-07 23:20:54 UTC (rev 695)
+++ libs/util/trunk/src/prj/net/sf/japi/util/Arrays2.java 2008-10-07 23:24:28 UTC (rev 696)
@@ -278,8 +278,8 @@
return n;
} // eventually add filters for primitive types and provide corresponding methods
- /** Searches the specified array of ints for the specified value using the binary search algorithm.
- * The array <strong>must</strong> be sorted (as by the <tt>sort</tt> method, above) prior to making this call.
+ /** Searches the specified array region of ints for the specified value using the binary search algorithm.
+ * The array region <strong>must</strong> be sorted (as by the <tt>sort</tt> method, above) prior to making this call.
* If it is not sorted, the results are undefined (even a runtime exception might occur).
* If the array contains multiple elements with the specified value, there is no guarantee which one will be found.
* @param a the array to be searched.
Modified: libs/util/trunk/src/prj/net/sf/japi/util/filter/file/AbstractFileFilter.java
===================================================================
--- libs/util/trunk/src/prj/net/sf/japi/util/filter/file/AbstractFileFilter.java 2008-10-07 23:20:54 UTC (rev 695)
+++ libs/util/trunk/src/prj/net/sf/japi/util/filter/file/AbstractFileFilter.java 2008-10-07 23:24:28 UTC (rev 696)
@@ -19,7 +19,7 @@
package net.sf.japi.util.filter.file;
-/** A FileFilter that combines several File filtering classes and interfaces.
+/** The AbstractFileFilter is a combination of a normal {@link java.io.FileFilter}, {@link javax.swing.filechooser.FileFilter} and {@link net.sf.japi.util.filter.file.FileFilter}.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
@SuppressWarnings({"EmptyClass"})
Modified: libs/util/trunk/src/prj/net/sf/japi/util/filter/file/EndingFileFilter.java
===================================================================
--- libs/util/trunk/src/prj/net/sf/japi/util/filter/file/EndingFileFilter.java 2008-10-07 23:20:54 UTC (rev 695)
+++ libs/util/trunk/src/prj/net/sf/japi/util/filter/file/EndingFileFilter.java 2008-10-07 23:24:28 UTC (rev 696)
@@ -28,10 +28,10 @@
*/
public class EndingFileFilter extends AbstractFileFilter {
- /** Wether to accept directories. */
+ /** Whether to accept directories. */
private final boolean acceptDirectories;
- /** Wether to negate the endings. */
+ /** Whether to negate the endings. */
private final boolean negate;
/** The description text. */
Modified: libs/util/trunk/src/prj/net/sf/japi/util/filter/file/Factory.java
===================================================================
--- libs/util/trunk/src/prj/net/sf/japi/util/filter/file/Factory.java 2008-10-07 23:20:54 UTC (rev 695)
+++ libs/util/trunk/src/prj/net/sf/japi/util/filter/file/Factory.java 2008-10-07 23:24:28 UTC (rev 696)
@@ -57,7 +57,7 @@
/** {@inheritDoc} */
@Override public boolean accept(final File pathname) {
- // XXX workaround bug in IntelliJ IDEA
+ // XXX:christianhujer:workaround bug in IntelliJ IDEA
//noinspection RedundantCast
return !((java.io.FileFilter) filter).accept(pathname);
}
@@ -68,7 +68,7 @@
+ (filter instanceof javax.swing.filechooser.FileFilter
? ((javax.swing.filechooser.FileFilter) filter).getDescription()
: filter.toString())
- + ')'; // TODO: I18N/L10N
+ + ')'; // TODO:christianhujer:I18N/L10N
}
} // class NotFileFilter
Modified: libs/util/trunk/src/prj/net/sf/japi/util/filter/file/FilenameFileFilter.java
===================================================================
--- libs/util/trunk/src/prj/net/sf/japi/util/filter/file/FilenameFileFilter.java 2008-10-07 23:20:54 UTC (rev 695)
+++ libs/util/trunk/src/prj/net/sf/japi/util/filter/file/FilenameFileFilter.java 2008-10-07 23:24:28 UTC (rev 696)
@@ -27,10 +27,10 @@
*/
public final class FilenameFileFilter extends AbstractFileFilter {
- /** Wether to accept directories. */
+ /** Whether to accept directories. */
private final boolean acceptDirectories;
- /** Wether to negate the names. */
+ /** Whether to negate the names. */
private final boolean negate;
/** The description text. */
Modified: libs/util/trunk/src/tst/test/net/sf/japi/util/Arrays2Test.java
===================================================================
--- libs/util/trunk/src/tst/test/net/sf/japi/util/Arrays2Test.java 2008-10-07 23:20:54 UTC (rev 695)
+++ libs/util/trunk/src/tst/test/net/sf/japi/util/Arrays2Test.java 2008-10-07 23:24:28 UTC (rev 696)
@@ -23,6 +23,7 @@
import java.util.Arrays;
import junit.framework.TestCase;
import net.sf.japi.util.Arrays2;
+import net.sf.japi.util.filter.Filter;
import org.junit.Test;
/** Test for {@link Arrays2}.
@@ -30,9 +31,9 @@
*/
public class Arrays2Test extends TestCase {
- /** Test case for Arrays2#concat(double[]...). */
+ /** Test case for {@link Arrays2#concat(byte[]...)}. */
@Test
- public void testConcat() {
+ public void testConcatByte() {
final byte[] data1Orig = {1, 2, 3};
final byte[] data2Orig = {4, 5, 6, 7};
final byte[] data1Copy = data1Orig.clone();
@@ -44,4 +45,160 @@
assertTrue("Concatenation must correctly concatenate", Arrays.equals(concatExpected, concatResult));
}
+ /** Test case for {@link Arrays2#concat(short[]...)}. */
+ @Test
+ public void testConcatShort() {
+ final short[] data1Orig = {1, 2, 3};
+ final short[] data2Orig = {4, 5, 6, 7};
+ final short[] data1Copy = data1Orig.clone();
+ final short[] data2Copy = data2Orig.clone();
+ final short[] concatExpected = {1, 2, 3, 4, 5, 6, 7};
+ final short[] concatResult = Arrays2.concat(data1Copy, data2Copy);
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data1Orig, data1Copy));
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data2Orig, data2Copy));
+ assertTrue("Concatenation must correctly concatenate", Arrays.equals(concatExpected, concatResult));
+ }
+
+ /** Test case for {@link Arrays2#concat(int[]...)}. */
+ @Test
+ public void testConcatInt() {
+ final int[] data1Orig = {1, 2, 3};
+ final int[] data2Orig = {4, 5, 6, 7};
+ final int[] data1Copy = data1Orig.clone();
+ final int[] data2Copy = data2Orig.clone();
+ final int[] concatExpected = {1, 2, 3, 4, 5, 6, 7};
+ final int[] concatResult = Arrays2.concat(data1Copy, data2Copy);
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data1Orig, data1Copy));
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data2Orig, data2Copy));
+ assertTrue("Concatenation must correctly concatenate", Arrays.equals(concatExpected, concatResult));
+ }
+
+ /** Test case for {@link Arrays2#concat(long[]...)}. */
+ @Test
+ public void testConcatLong() {
+ final long[] data1Orig = {1, 2, 3};
+ final long[] data2Orig = {4, 5, 6, 7};
+ final long[] data1Copy = data1Orig.clone();
+ final long[] data2Copy = data2Orig.clone();
+ final long[] concatExpected = {1, 2, 3, 4, 5, 6, 7};
+ final long[] concatResult = Arrays2.concat(data1Copy, data2Copy);
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data1Orig, data1Copy));
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data2Orig, data2Copy));
+ assertTrue("Concatenation must correctly concatenate", Arrays.equals(concatExpected, concatResult));
+ }
+
+ /** Test case for {@link Arrays2#concat(float[]...)}. */
+ @Test
+ public void testConcatFloat() {
+ final float[] data1Orig = {1, 2, 3};
+ final float[] data2Orig = {4, 5, 6, 7};
+ final float[] data1Copy = data1Orig.clone();
+ final float[] data2Copy = data2Orig.clone();
+ final float[] concatExpected = {1, 2, 3, 4, 5, 6, 7};
+ final float[] concatResult = Arrays2.concat(data1Copy, data2Copy);
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data1Orig, data1Copy));
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data2Orig, data2Copy));
+ assertTrue("Concatenation must correctly concatenate", Arrays.equals(concatExpected, concatResult));
+ }
+
+ /** Test case for {@link Arrays2#concat(double[]...)}. */
+ @Test
+ public void testConcatDouble() {
+ final double[] data1Orig = {1, 2, 3};
+ final double[] data2Orig = {4, 5, 6, 7};
+ final double[] data1Copy = data1Orig.clone();
+ final double[] data2Copy = data2Orig.clone();
+ final double[] concatExpected = {1, 2, 3, 4, 5, 6, 7};
+ final double[] concatResult = Arrays2.concat(data1Copy, data2Copy);
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data1Orig, data1Copy));
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data2Orig, data2Copy));
+ assertTrue("Concatenation must correctly concatenate", Arrays.equals(concatExpected, concatResult));
+ }
+
+ /** Test case for {@link Arrays2#concat(char[]...)}. */
+ @Test
+ public void testConcatChar() {
+ final char[] data1Orig = {1, 2, 3};
+ final char[] data2Orig = {4, 5, 6, 7};
+ final char[] data1Copy = data1Orig.clone();
+ final char[] data2Copy = data2Orig.clone();
+ final char[] concatExpected = {1, 2, 3, 4, 5, 6, 7};
+ final char[] concatResult = Arrays2.concat(data1Copy, data2Copy);
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data1Orig, data1Copy));
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data2Orig, data2Copy));
+ assertTrue("Concatenation must correctly concatenate", Arrays.equals(concatExpected, concatResult));
+ }
+
+ /** Test case for {@link Arrays2#concat(boolean[]...)}. */
+ @Test
+ public void testConcatBoolean() {
+ final boolean[] data1Orig = {true, false, true};
+ final boolean[] data2Orig = {false, true, false, false};
+ final boolean[] data1Copy = data1Orig.clone();
+ final boolean[] data2Copy = data2Orig.clone();
+ final boolean[] concatExpected = {true, false, true, false, true, false, false};
+ final boolean[] concatResult = Arrays2.concat(data1Copy, data2Copy);
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data1Orig, data1Copy));
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data2Orig, data2Copy));
+ assertTrue("Concatenation must correctly concatenate", Arrays.equals(concatExpected, concatResult));
+ }
+
+ /** Test case for {@link Arrays2#concat(Object[][])}. */
+ @Test
+ public void testConcatObject() {
+ final String[] data1Orig = {"1", "2", "3"};
+ final String[] data2Orig = {"4", "5", "6", "7"};
+ final String[] data1Copy = data1Orig.clone();
+ final String[] data2Copy = data2Orig.clone();
+ final String[] concatExpected = {"1", "2", "3", "4", "5", "6", "7"};
+ final String[] concatResult = Arrays2.concat(data1Copy, data2Copy);
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data1Orig, data1Copy));
+ assertTrue("Original arrays must be unmodified", Arrays.equals(data2Orig, data2Copy));
+ assertTrue("Concatenation must correctly concatenate", Arrays.equals(concatExpected, concatResult));
+ }
+
+ /** Test case for {@link Arrays2#filter(Filter, Object[])}. */
+ @Test
+ public void testFilter() {
+ final String[] dataOrig = {"foo1", "foo2", "bar1", "foo3", "bar2", "bar3", "bar4"};
+ final String[] dataCopy = dataOrig.clone();
+ final Filter<String> filter = new Filter<String>() {
+ public boolean accept(final String o) {
+ return o.startsWith("foo");
+ }
+ };
+ final String[] expected = {"foo1", "foo2", "foo3"};
+ final String[] actual = Arrays2.filter(filter, dataCopy);
+ assertTrue("Original array must be unmodified", Arrays.equals(dataOrig, dataCopy));
+ assertTrue("Filter must filter correctly.", Arrays.equals(expected, actual));
+ }
+
+ /** Test case for {@link Arrays2#count(Filter, Object[])}. */
+ @Test
+ public void testCount() {
+ final String[] dataOrig = {"foo1", "foo2", "bar1", "foo3", "bar2", "bar3", "bar4"};
+ final String[] dataCopy = dataOrig.clone();
+ final Filter<String> filter = new Filter<String>() {
+ public boolean accept(final String o) {
+ return o.startsWith("foo");
+ }
+ };
+ final int expected = 3;
+ final int actual = Arrays2.count(filter, dataCopy);
+ assertTrue("Original array must be unmodified", Arrays.equals(dataOrig, dataCopy));
+ assertEquals("Count must count correctly.", expected, actual);
+ }
+
+ /** Test case for {@link Arrays2#linearSearch(int, int[])}. */
+ @Test
+ public void testLinearSearch() {
+ final int[] data = { 0, 1, 2, 3 };
+ assertEquals(-1, Arrays2.linearSearch(-1, data));
+ assertEquals(0, Arrays2.linearSearch(0, data));
+ assertEquals(1, Arrays2.linearSearch(1, data));
+ assertEquals(2, Arrays2.linearSearch(2, data));
+ assertEquals(3, Arrays2.linearSearch(3, data));
+ assertEquals(-1, Arrays2.linearSearch(4, data));
+ }
+
} // class Arrays2Test
Copied: libs/util/trunk/src/tst/test/net/sf/japi/util/EnumerationIteratorTest.java (from rev 635, historic/trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java)
===================================================================
--- libs/util/trunk/src/tst/test/net/sf/japi/util/EnumerationIteratorTest.java (rev 0)
+++ libs/util/trunk/src/tst/test/net/sf/japi/util/EnumerationIteratorTest.java 2008-10-07 23:24:28 UTC (rev 696)
@@ -0,0 +1,92 @@
+/*
+ * JAPI - (Yet another (hopefully) useful) Java API
+ *
+ * Copyright (C) 2006 Christian Hujer
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+package test.net.sf.japi.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.NoSuchElementException;
+import net.sf.japi.util.EnumerationIterator;
+import org.junit.Assert;
+import org.junit.Test;
+
+/** Test class for {@link EnumerationIterator}.
+ * @author <a href="mailto:ch...@it...">Christian Hujer</a>
+ */
+public class EnumerationIteratorTest {
+
+ /** Test case for {@link EnumerationIterator#iterator()}. */
+ @Test
+ public void testIterator() throws Exception {
+ EnumerationIterator<?> oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
+ Assert.assertNotNull("Even empty enumerations must generate an iterator instance.", oUT.iterator());
+ oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
+ Assert.assertNotNull("Even empty enumerations must generate an iterator instance.", oUT.iterator());
+ }
+
+ /** Test case for {@link EnumerationIterator#hasNext()}. */
+ @Test public void testHasNext() throws Exception {
+ EnumerationIterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
+ Assert.assertFalse("hasNext() on empty enumeration must instantly return false.", oUT.hasNext());
+ oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
+ Assert.assertTrue("hasNext() on nonempty enumeration must first return true.", oUT.hasNext());
+ }
+
+ /** Test case for {@link EnumerationIterator#next()}. */
+ @Test public void testNext() throws Exception {
+ EnumerationIterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
+ try {
+ oUT.next();
+ Assert.fail("next() on empty enumeration must instantly throw NoSuchElementException.");
+ } catch (final NoSuchElementException e) {
+ /* Expected exception. */
+ }
+ oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
+ oUT.next();
+ oUT.next();
+ try {
+ oUT.next();
+ Assert.fail("next() on two elements enumeration must throw NoSuchElementException on third invocation.");
+ } catch (final NoSuchElementException e) {
+ /* Expected exception. */
+ }
+ }
+
+ /** Test case for {@link EnumerationIterator#remove()}. */
+ @Test public void testRemove() throws Exception {
+ EnumerationIterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
+ try {
+ oUT.remove();
+ Assert.fail("remove() on empty enumeration must instantly throw UnsupportedOperationException.");
+ } catch (final UnsupportedOperationException e) {
+ /* Expected exception. */
+ }
+ oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
+ try {
+ oUT.next();
+ oUT.remove();
+ Assert.fail("remove() must throw UnsupportedOperationException.");
+ } catch (final UnsupportedOperationException e) {
+ /* Expected exception. */
+ }
+ }
+
+} // class EnumerationIteratorTest
Property changes on: libs/util/trunk/src/tst/test/net/sf/japi/util/EnumerationIteratorTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 23:21:00
|
Revision: 695
http://japi.svn.sourceforge.net/japi/?rev=695&view=rev
Author: christianhujer
Date: 2008-10-07 23:20:54 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Saved current status. Warning: swing-app is very experimental right now!
Modified Paths:
--------------
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/CanLoad.java
Added Paths:
-----------
libs/swing-app/trunk/lib/
libs/swing-app/trunk/lib/japi-lib-argparser-trunk.jar
libs/swing-app/trunk/lib/japi-lib-swing-about-trunk.jar
libs/swing-app/trunk/lib/japi-lib-swing-action-trunk.jar
libs/swing-app/trunk/lib/japi-lib-swing-extlib-trunk.jar
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/AppLaunchCommand.java
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/Application.java
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/ApplicationQuitter.java
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/Document.java
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentEvent.java
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentEventType.java
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentFrame.java
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentListener.java
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/action.properties
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/requirements.txt
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/Application.java
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/TryApplication.java
libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/package-info.java
Property changes on: libs/swing-app/trunk/lib/japi-lib-argparser-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Property changes on: libs/swing-app/trunk/lib/japi-lib-swing-about-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Property changes on: libs/swing-app/trunk/lib/japi-lib-swing-action-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Property changes on: libs/swing-app/trunk/lib/japi-lib-swing-extlib-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/AppLaunchCommand.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/AppLaunchCommand.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/AppLaunchCommand.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,50 @@
+package net.sf.japi.swing.app;
+
+import java.util.List;
+import net.sf.japi.io.args.CommandWithHelp;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** Command for launching a GUI application.
+ * If the application does not need additional command line parameters, this class is sufficient and needn't be subclassed.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class AppLaunchCommand extends CommandWithHelp {
+
+ /** The Application Class. */
+ @Nullable private final Class<? extends Application<?>> appClass;
+
+ /** The Application. */
+ @Nullable private Application<?> application;
+
+ /** Creates an AppLaunchCommand.
+ * @param appClass Application Class to launch.
+ */
+ public AppLaunchCommand(@NotNull final Class<? extends Application<?>> appClass) {
+ this.appClass = appClass;
+ application = null;
+ }
+
+ /** Creates an AppLaunchCommand.
+ * @param application Application to launch.
+ */
+ public AppLaunchCommand(@NotNull final Application<?> application) {
+ appClass = null;
+ this.application = application;
+ }
+
+ @SuppressWarnings({"InstanceMethodNamingConvention"})
+ public int run(@NotNull final List<String> args) throws Exception {
+ Application<?> application = this.application;
+ assert !(application == null && appClass == null);
+ if (application == null) {
+ application = appClass.newInstance();
+ }
+
+ for (final String arg : args) {
+ application.load(arg);
+ }
+ application.show();
+ return 0;
+ }
+}
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/AppLaunchCommand.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/Application.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/Application.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/Application.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,503 @@
+package net.sf.japi.swing.app;
+
+import java.awt.Container;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import javax.swing.Action;
+import javax.swing.JDesktopPane;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.WindowConstants;
+import javax.swing.event.InternalFrameEvent;
+import javax.swing.event.InternalFrameListener;
+import net.sf.japi.swing.ActionBuilder;
+import net.sf.japi.swing.ActionBuilderFactory;
+import net.sf.japi.swing.ActionMethod;
+import net.sf.japi.swing.ToolBarLayout;
+import net.sf.japi.swing.about.AboutDialog;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** Base class for applications.
+ * @param <D> The document type that is managed by this application.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class Application<D> implements CanLoad<D>, InternalFrameListener, DocumentListener<D> {
+
+ /** The application frame. */
+ @NotNull private JFrame appFrame;
+
+ /** The ActionBuilder. */
+ @NotNull private final ActionBuilder actionBuilder;
+
+ /** Whether or not to ask the user before quitting. */
+ private boolean askForQuit = true;
+
+ /** The About Dialog. */
+ private AboutDialog aboutDialog = null; // lazy
+
+ /** The file chooser for loading and saving. */
+ private JFileChooser fileChooser;
+
+ /** The MDI handler. */
+ private JDesktopPane desktop;
+
+ /** The current document frame. */
+ @Nullable private DocumentFrame<D> currentDocumentFrame = null;
+
+ /** The current document. */
+ @Nullable private Document<D> currentDocument = null;
+
+ /** The opened documents. */
+ @NotNull private final Collection<Document<D>> documents = new ArrayList<Document<D>>();
+
+ /** Maps Window Actions to JMenuItems for later removal. */
+ private final Map<Action, JMenuItem> windowActionMap = new HashMap<Action, JMenuItem>();
+
+ /** Creates an Application. */
+ protected Application() {
+ final ActionBuilderFactory actionBuilderFactory = ActionBuilderFactory.getInstance();
+ actionBuilder = actionBuilderFactory.getActionBuilder(getClass());
+ actionBuilder.addParent(actionBuilderFactory.getActionBuilder("net.sf.japi.swing.app"));
+ appFrame = new JFrame(actionBuilder.getString("application.title"));
+ final Container cont = appFrame.getContentPane();
+ cont.setLayout(new ToolBarLayout());
+ appFrame.setJMenuBar(actionBuilder.createMenuBar(true, "application", this));
+ fileChooser = new JFileChooser();
+ desktop = new JDesktopPane();
+ cont.add(desktop);
+ updateActionStates();
+ }
+
+ /** Invoke this as soon as the application is ready to display. */
+ protected void show() {
+ if (!appFrame.isVisible()) {
+ appFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ appFrame.addWindowListener(new ApplicationQuitter<D>(this));
+ appFrame.pack();
+ appFrame.setVisible(true);
+ }
+ }
+
+ /** Returns the application frame.
+ * @return The application frame.
+ */
+ @NotNull protected JFrame getAppFrame() {
+ return appFrame;
+ }
+
+ /** Returns the ActionBuilder.
+ * @return The Actionbuilder.
+ */
+ @NotNull protected ActionBuilder getActionBuilder() {
+ return actionBuilder;
+ }
+
+ /** Action New. */
+ @ActionMethod
+ public void fileNew() {
+ addDocument(createNew());
+ }
+
+ /** Action Open.
+ * @throws Exception in case of I/O problems.
+ */
+ @ActionMethod
+ public void fileOpen() throws Exception {
+ fileChooser.setMultiSelectionEnabled(true);
+ if (fileChooser.showOpenDialog(appFrame) == JFileChooser.APPROVE_OPTION) {
+ final File[] files = fileChooser.getSelectedFiles();
+ fileLoop:
+ for (final File file : files) {
+ final String uri = file.toURI().toString();
+ for (final Document<D> doc : documents) {
+ if (uri.equals(doc.getUri())) {
+ doc.getFirstFrame().setSelected(true);
+ continue fileLoop;
+ }
+ }
+ addDocument(load(uri));
+ }
+ }
+ }
+
+ /** Adds the specified document.
+ * @param doc Document to add.
+ */
+ public void addDocument(@NotNull final Document<D> doc) {
+ documents.add(doc);
+ doc.addDocumentListener(this);
+ // TODO:christianhujer:handle frames with a menu.
+ final DocumentFrame<D> docFrame = doc.createDocumentFrame();
+ docFrame.addInternalFrameListener(this);
+ desktop.add(docFrame);
+ docFrame.pack();
+ docFrame.setVisible(true);
+ }
+
+ /** Action Save.
+ * @throws Exception in case of I/O problems while saving.
+ */
+ @ActionMethod
+ public void fileSave() throws Exception {
+ final Document<D> docToSave = currentDocument;
+ if (docToSave != null) {
+ final String uri = docToSave.getUri();
+ if (uri != null) {
+ save(docToSave, uri);
+ docToSave.setChanged(false);
+ updateActionStates();
+ } else {
+ fileSaveAs();
+ }
+ }
+ }
+
+ /** Action Save As.
+ * @throws Exception in case of I/O problems while saving.
+ */
+ @ActionMethod
+ public void fileSaveAs() throws Exception {
+ saveAs(currentDocument);
+ updateActionStates();
+ }
+
+ /** Saves a document with a new location.
+ * @param docToSaveAs Doc to save with a new location.
+ * @throws Exception in case of I/O problems while saving.
+ */
+ public void saveAs(final Document<D> docToSaveAs) throws Exception {
+ if (docToSaveAs != null) {
+ fileChooser.setMultiSelectionEnabled(false);
+ final String currentUri = docToSaveAs.getUri();
+ if (currentUri != null) {
+ fileChooser.setSelectedFile(new File(new URI(currentUri)));
+ } else {
+ fileChooser.setSelectedFile(new File("Unnamed")); // TODO:christianhujer:I18N/L10N of file name
+ }
+ if (fileChooser.showSaveDialog(appFrame) == JFileChooser.APPROVE_OPTION) {
+ final File file = fileChooser.getSelectedFile();
+ final String uri = file.toURI().toString();
+ save(docToSaveAs, uri);
+ docToSaveAs.setChanged(false);
+ docToSaveAs.setUri(uri);
+ updateActionStates();
+ }
+ }
+ }
+
+ /** Action Save All.
+ * @throws Exception in case of I/O problems during saving.
+ */
+ @ActionMethod
+ public void fileSaveAll() throws Exception {
+ for (final Document<D> docToSave : documents) {
+ final String uri = docToSave.getUri();
+ if (uri != null) {
+ save(docToSave, uri);
+ docToSave.setChanged(false);
+ } else {
+ saveAs(docToSave);
+ }
+ }
+ updateActionStates();
+ }
+
+ /** Action Close. */
+ @ActionMethod
+ public void fileClose() {
+ final Document<D> currentDocument = this.currentDocument;
+ if (currentDocument != null) {
+ if (close(currentDocument)) {
+ // TODO:christianhujer:Finish implementation
+ documents.remove(currentDocument);
+ }
+ }
+ updateActionStates();
+ }
+
+ /** Action New Window. */
+ @ActionMethod
+ public void winNew() {
+ final Document<D> doc = currentDocument;
+ if (doc == null) {
+ return;
+ }
+ final DocumentFrame<D> docFrame = doc.createDocumentFrame();
+ docFrame.addInternalFrameListener(this);
+ desktop.add(docFrame);
+ docFrame.pack();
+ docFrame.setVisible(true);
+ updateActionStates();
+ }
+
+ /** Action Close Window. */
+ @ActionMethod
+ public void winClose() {
+ final DocumentFrame<D> frameToClose = currentDocumentFrame;
+ if (frameToClose == null) {
+ return;
+ }
+ close(frameToClose);
+ updateActionStates();
+ }
+
+ /** Closes the specified frame.
+ * The frame is not definitely closed.
+ * The user might be asked and prevent the frame from being closed.
+ * @param frameToClose The frame to close.
+ * @return <code>true</code> if the frame was closed, otherwise <code>false</code>.
+ */
+ private boolean close(@NotNull final DocumentFrame<D> frameToClose) {
+ final Document<D> doc = frameToClose.getDocument();
+ if (doc.getFrameCount() > 1) {
+ doc.removeDocumentFrame(frameToClose);
+ desktop.remove(frameToClose);
+ desktop.selectFrame(true);
+ return true;
+ } else {
+ close(doc);
+ documents.remove(doc);
+ return false;
+ }
+ }
+
+ /** Closes the specified document.
+ * The document is not yet removed from the list of opened documents.
+ * That must be done by the caller.
+ * @param doc Document to close.
+ * @return <code>true</code> if <var>doc</var> was closed, otherwise <code>false</code>.
+ */
+ private boolean close(@NotNull final Document<D> doc) {
+ if (doc.hasChanged()) {
+ // TODO:christianhujer:Finish implementation
+ final int result = actionBuilder.showConfirmDialog(desktop.getSelectedFrame(), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "documentNotSaved", doc.getTitle());
+ switch (result) {
+ case JOptionPane.YES_OPTION:
+ // TODO:christianhujer:try saving. If that fails, cancel.
+ break;
+ case JOptionPane.NO_OPTION:
+ // TODO:christianhujer:force closing.
+ break;
+ case JOptionPane.CANCEL_OPTION:
+ return false;
+ default:
+ assert false : "Switch that misses cases.";
+ }
+ } else {
+ while (doc.getFrameCount() > 0) {
+ final DocumentFrame<D> frameToClose = doc.getFirstFrame();
+ doc.removeDocumentFrame(frameToClose);
+ desktop.remove(frameToClose);
+ }
+ desktop.selectFrame(true);
+ return true;
+ }
+ return false;
+ }
+
+ /** Action Close All. */
+ @ActionMethod
+ public void fileCloseAll() {
+ final Iterator<Document<D>> iterator = documents.iterator();
+ while (iterator.hasNext()) {
+ final Document<D> doc = iterator.next();
+ if (close(doc)) {
+ // TODO:christianhujer:Finish implementation
+ iterator.remove();
+ }
+ }
+ updateActionStates();
+ }
+ /** Action Quit. */
+ @ActionMethod
+ public void fileQuit() {
+ // TODO:christianhujer:This should ask about each document with unsaved changes.
+ if (!isUserPermissionForQuitRequired() || isQuitAllowedByUser()) {
+ appFrame.dispose();
+ }
+ }
+
+ /** Action About. */
+ @ActionMethod
+ public void about() {
+ synchronized (this) {
+ if (aboutDialog == null) {
+ aboutDialog = new AboutDialog(actionBuilder);
+ }
+ }
+ aboutDialog.showAboutDialog(appFrame);
+ }
+
+ /** Returns whether or not asking the user before quitting is requried.
+ * Asking the user may be required if the user configured to be always asked, or if there are unsaved changes.
+ * @return <code>true</code> if asking the user is required.
+ */
+ public boolean isUserPermissionForQuitRequired() {
+ return askForQuit || hasUnsavedChanges();
+ }
+
+ /** Returns whether or not the user allowed quitting.
+ * @return <code>true</code> if the user allowed quitting, otherwise <code>false</code>
+ */
+ public boolean isQuitAllowedByUser() {
+ return actionBuilder.showQuestionDialog(appFrame, "reallyQuit");
+ }
+
+ /** Returns whether or not one or more documents have unsaved changes.
+ * @return <code>true</code> if one or more documents have unsaved changes, <code>false</code> if all changes are saved.
+ */
+ public boolean hasUnsavedChanges() {
+ // TODO:christianhujer:Finish implementation.
+ return true;
+ }
+
+ public void internalFrameOpened(final InternalFrameEvent e) {
+ final JMenu windows = (JMenu) actionBuilder.find(appFrame.getJMenuBar(), "window");
+ assert windows != null;
+ final DocumentFrame<D> docFrame = (DocumentFrame<D>) e.getInternalFrame();
+ final Action winAction = docFrame.getWindowAction();
+ windowActionMap.put(winAction, windows.add(winAction));
+ }
+
+ public void internalFrameClosing(final InternalFrameEvent e) {
+ close((DocumentFrame<D>) e.getInternalFrame());
+ }
+
+ public void internalFrameClosed(final InternalFrameEvent e) {
+ final JMenu windows = (JMenu) actionBuilder.find(appFrame.getJMenuBar(), "window");
+ assert windows != null;
+ final DocumentFrame<D> docFrame = (DocumentFrame<D>) e.getInternalFrame();
+ final Action winAction = docFrame.getWindowAction();
+ windows.remove(windowActionMap.get(winAction));
+ }
+
+ public void internalFrameIconified(final InternalFrameEvent e) {
+ //ignore
+ }
+
+ public void internalFrameDeiconified(final InternalFrameEvent e) {
+ //ignore
+ }
+
+ public void internalFrameActivated(final InternalFrameEvent e) {
+ setActiveDocumentImpl(((DocumentFrame<D>) e.getInternalFrame()));
+ }
+
+ public void internalFrameDeactivated(final InternalFrameEvent e) {
+ //ignore
+ }
+
+ /** Updates the states of the actions.
+ * @param docFrame Update the application to match this document frame and its document.
+ */
+ private void setActiveDocumentImpl(@Nullable final DocumentFrame<D> docFrame) {
+ currentDocumentFrame = docFrame;
+ if (docFrame != null) {
+ currentDocument = docFrame.getDocument();
+ } else {
+ currentDocument = null;
+ }
+ updateActionStates();
+ }
+
+ /** Updates the states of all actions. */
+ private synchronized void updateActionStates() {
+ final Document<D> currentDocument = this.currentDocument;
+ final boolean hasCurrentDocumentFrame = currentDocumentFrame != null;
+ final boolean hasCurrentDocument = currentDocument != null;
+ final boolean hasDocumentsWithUnsavedChanges = hasDocumentsWithUnsavedChanges();
+ actionBuilder.setActionEnabled("fileSave", hasCurrentDocument && currentDocument.hasChanged());
+ actionBuilder.setActionEnabled("fileSaveAs", hasCurrentDocument);
+ actionBuilder.setActionEnabled("fileSaveAll", hasDocumentsWithUnsavedChanges);
+ actionBuilder.setActionEnabled("fileClose", hasCurrentDocument);
+ actionBuilder.setActionEnabled("fileCloseAll", documents.size() > 0);
+ actionBuilder.setActionEnabled("winNew", hasCurrentDocument);
+ actionBuilder.setActionEnabled("winClose", hasCurrentDocumentFrame);
+ }
+
+ private boolean hasDocumentsWithUnsavedChanges() {
+ for (final Document<D> doc : documents) {
+ if (doc.hasChanged()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @NotNull public abstract Document<D> load(@NotNull final String uri) throws Exception;
+
+ /** Saves the specified document at the specified uri.
+ * @param doc Document to save.
+ * @param uri Uri at which to save the document.
+ * @throws Exception in case of problems while saving.
+ */
+ public abstract void save(@NotNull final Document<D> doc, @NotNull final String uri) throws Exception;
+
+ /** Creates a new empty document.
+ * @return A new empty document.
+ */
+ public abstract Document<D> createNew();
+
+ /** Opens the specified uri for writing.
+ * @param uri URI to open
+ * @return OutputStream for writing to that uri.
+ * @throws IOException in case the uri couldn't be opened for writing.
+ * @throws URISyntaxException in case the syntax of the uri was not correct.
+ */
+ public static OutputStream openUriForwriting(@NotNull final String uri) throws IOException, URISyntaxException {
+ final URI theUri = new URI(uri);
+ final String scheme = theUri.getScheme();
+ if (scheme == null || "file".equals(scheme)) {
+ return new FileOutputStream(new File(theUri));
+ }
+ final URL url = theUri.toURL();
+ final URLConnection con = url.openConnection();
+ con.setDoInput(true);
+ con.setDoOutput(true);
+ return con.getOutputStream();
+ }
+
+ /** Opens the specified uri for reading.
+ * @param uri URI to open
+ * @return InputStream for reading from that uri.
+ * @throws IOException in case the uri couldn't be opened for reading.
+ * @throws URISyntaxException in case the syntax of the uri was not correct.
+ */
+ public static InputStream openUriForReading(@NotNull final String uri) throws IOException, URISyntaxException {
+ final URI theUri = new URI(uri);
+ final URL url = theUri.toURL();
+ return url.openStream();
+ }
+
+ public void documentUriChanged(@NotNull final DocumentEvent<D> e) {
+ // Nothing to do
+ }
+
+ public void documentTitleChanged(@NotNull final DocumentEvent<D> e) {
+ // Nothing to do
+ }
+
+ public void documentContentChanged(@NotNull final DocumentEvent<D> e) {
+ if (e.getSource() == currentDocument) {
+ updateActionStates();
+ }
+ }
+
+}
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/Application.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/ApplicationQuitter.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/ApplicationQuitter.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/ApplicationQuitter.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,27 @@
+package net.sf.japi.swing.app;
+
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import org.jetbrains.annotations.NotNull;
+
+/** Quits an application when its window is closing.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ * @param <D> The document type that is managed by the application.
+ */
+class ApplicationQuitter<D> extends WindowAdapter {
+
+ /** Application to quit. */
+ @NotNull private Application<D> application;
+
+ /** Creates an ApplicationQuitter.
+ * @param application Application to quit when its window is closing.
+ */
+ ApplicationQuitter(@NotNull final Application<D> application) {
+ this.application = application;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void windowClosing(final WindowEvent e) {
+ application.fileQuit();
+ }
+}
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/ApplicationQuitter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Modified: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/CanLoad.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/CanLoad.java 2008-10-07 23:03:58 UTC (rev 694)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/CanLoad.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -22,16 +22,17 @@
import org.jetbrains.annotations.NotNull;
/** Interface to be implemented by classes that are able to load a URL.
+ * @param <D> The document type that can be loaded.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public interface CanLoad {
+public interface CanLoad<D> {
/** Load a document.
- * This method does not declare any exceptions.
- * The implementor of this method is responsible for handling any exceptional conditions which might occur during the load operation.
- * @param url URL to load
- * @return <code>true</code> if and only if loading the file was successful
+ * The returned document will have its URI set.
+ * @param uri URL to load.
+ * @return The document that was just loaded.
+ * @throws Exception in case of problems when loading.
*/
- boolean load(@NotNull String url);
+ @NotNull Document<D> load(@NotNull String uri) throws Exception;
} // interface CanLoad
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/Document.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/Document.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/Document.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,239 @@
+package net.sf.japi.swing.app;
+
+import java.awt.Component;
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.event.EventListenerList;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** A document represents an entity of work in an application that can be loaded and saved.
+ * In a text editor, a document would represent the text file that is being edited.
+ * In a word processor, it would be the document edited in the word processor.
+ * In a spread sheet, it would be the spread sheet file.
+ * @param <D> The document type that is managed by the application.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class Document<D> {
+
+ /** The frames of this document. */
+ private final List<DocumentFrame<D>> frames = new ArrayList<DocumentFrame<D>>();
+
+ /** The Event Listeners. */
+ private final EventListenerList listenerList = new EventListenerList();
+
+ /** The data of this Document. */
+ @NotNull private D data;
+
+ /** The URI of this document. */
+ @Nullable private String uri;
+
+ /** The title of this document. */
+ // TODO:christianhujer:@Nullable or @NotNull
+ private String title;
+
+ /** The changed state of this document. */
+ private boolean changed = false;
+
+ /** Creates a Document.
+ * @param uri URI.
+ * @param title Title.
+ * @param data Data for this document.
+ */
+ public Document(@Nullable final String uri, final String title, @NotNull final D data) {
+ this.uri = uri;
+ this.title = title;
+ this.data = data;
+ }
+
+ /** Adds a {@link DocumentListener} to this Document.
+ * @param l the listener to be added.
+ */
+ public void addDocumentListener(final DocumentListener<D> l) {
+ listenerList.add(DocumentListener.class, l);
+ }
+
+ /** Removes a {@link DocumentListener} from this Document.
+ * @param l the listener to be removed.
+ */
+ public void removeDocumentListener(final DocumentListener<D> l) {
+ listenerList.add(DocumentListener.class, l);
+ }
+
+ /** Forward the notification that the document title has changed
+ * to all {@link DocumentListener}s that registered themselves
+ * as listeners for this Document.
+ */
+ private void fireDocumentTitleChanged() {
+ final Object[] listeners = listenerList.getListenerList();
+ DocumentEvent<D> e = null;
+ for (int i = listeners.length - 2; i >= 0; i -= 2) {
+ if (listeners[i] == DocumentListener.class) {
+ if (e == null) {
+ e = new DocumentEvent<D>(this, DocumentEventType.DOCUMENT_TITLE_CHANGED);
+ }
+ //noinspection unchecked
+ ((DocumentListener<D>) listeners[i + 1]).documentTitleChanged(e);
+ }
+ }
+ }
+
+ /** Forward the notification that the document uri has changed
+ * to all {@link DocumentListener}s that registered themselves
+ * as listeners for this Document.
+ */
+ private void fireDocumentUriChanged() {
+ final Object[] listeners = listenerList.getListenerList();
+ DocumentEvent<D> e = null;
+ for (int i = listeners.length - 2; i >= 0; i -= 2) {
+ if (listeners[i] == DocumentListener.class) {
+ if (e == null) {
+ e = new DocumentEvent<D>(this, DocumentEventType.DOCUMENT_URI_CHANGED);
+ }
+ //noinspection unchecked
+ ((DocumentListener<D>) listeners[i + 1]).documentUriChanged(e);
+ }
+ }
+ }
+
+ /** Forward the notification that the document content has changed
+ * to all {@link DocumentListener}s that registered themselves
+ * as listeners for this Document.
+ */
+ private void fireDocumentContentChanged() {
+ final Object[] listeners = listenerList.getListenerList();
+ DocumentEvent<D> e = null;
+ for (int i = listeners.length - 2; i >= 0; i -= 2) {
+ if (listeners[i] == DocumentListener.class) {
+ if (e == null) {
+ e = new DocumentEvent<D>(this, DocumentEventType.DOCUMENT_CONTENT_CHANGED);
+ }
+ //noinspection unchecked
+ ((DocumentListener<D>) listeners[i + 1]).documentContentChanged(e);
+ }
+ }
+ }
+
+ /** Creates a DocumentFrame for this Document.
+ * @return DocumentFrame for this Document.
+ */
+ DocumentFrame<D> createDocumentFrame() {
+ final DocumentFrame<D> frame = new DocumentFrame<D>(this);
+ frame.add(createDocumentComponent());
+ frames.add(frame);
+ updateFrameTitles();
+ return frame;
+ }
+
+ /** Removes a DocumentFrame for this Document.
+ * @param docFrame DocumentFrame for this Document to remove.
+ */
+ @SuppressWarnings({"TypeMayBeWeakened"})
+ void removeDocumentFrame(@NotNull final DocumentFrame<D> docFrame) {
+ assert frames.contains(docFrame);
+ docFrame.setVisible(false);
+ docFrame.dispose();
+ frames.remove(docFrame);
+ updateFrameTitles();
+ }
+
+ /** Returns the number of frames this document has.
+ * @return The number of frames this document has.
+ */
+ int getFrameCount() {
+ return frames.size();
+ }
+
+ /** Returns the data of this document.
+ * @return The data of this document.
+ */
+ @NotNull public D getData() {
+ return data;
+ }
+
+ /** Returns the first frame of this document.
+ * @return the first frame of this document.
+ */
+ public DocumentFrame<D> getFirstFrame() {
+ return frames.get(0);
+ }
+
+ /** Creates a Component for the document.
+ * @return Component for displaying the specified document.
+ */
+ protected abstract Component createDocumentComponent();
+
+ /** Returns whether this document has changed.
+ * A document is changed if it either was never saved or it was changed after saving.
+ * @return <code>true</code> if this document has changed, otherwise <code>false</code>.
+ */
+ public boolean hasChanged() {
+ return changed;
+ }
+
+ /** Returns the URI of this document.
+ * @return The URI of this document.
+ */
+ @Nullable String getUri() {
+ return uri;
+ }
+
+ /** Sets the URI of this document.
+ * @param uri URI of thsi document.
+ */
+ void setUri(@Nullable final String uri) {
+ this.uri = uri;
+ fireDocumentUriChanged();
+ }
+
+ /** Sets the title of this document.
+ * @param title New title of this document.
+ */
+ protected final synchronized void setTitle(@Nullable final String title) {
+ this.title = title;
+ updateFrameTitles();
+ fireDocumentTitleChanged();
+ }
+
+ /** Updates the titles of all frames. */
+ private synchronized void updateFrameTitles() {
+ for (final DocumentFrame<D> frame : frames) {
+ frame.updateFrameTitle();
+ }
+ }
+
+ /** Returns the title of this document.
+ * @return The title of this document.
+ */
+ @Nullable public final String getTitle() {
+ return title;
+ }
+
+ /** Returns whether or not this Document has more than one frame.
+ * @return <code>true</code> if this Document has more than one frame, otherwise <code>false</code>.
+ */
+ public boolean hasMoreThanOneFrame() {
+ return frames.size() > 1;
+ }
+
+ /** Returns the number of a frame.
+ * @param frame Frame for which to return the number.
+ * @return The number of that frame.
+ */
+ @SuppressWarnings({"TypeMayBeWeakened"})
+ int getFrameNumber(@NotNull final DocumentFrame<D> frame) {
+ return frames.indexOf(frame);
+ }
+
+ /** Sets the changed state of this document.
+ * @param changed New changed state of this document.
+ */
+ protected void setChanged(final boolean changed) {
+ if (!this.changed && changed) {
+ this.changed = changed;
+ fireDocumentContentChanged();
+ }
+ this.changed = changed;
+ }
+
+}
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/Document.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentEvent.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentEvent.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentEvent.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,42 @@
+package net.sf.japi.swing.app;
+
+import java.util.EventObject;
+import org.jetbrains.annotations.NotNull;
+
+/** A DocumentEvent describes notable changes to a {@link Document}.
+ * @param <D> The document type that is managed by the application.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class DocumentEvent<D> extends EventObject {
+
+ /** The type of this event. */
+ @NotNull private final DocumentEventType type;
+
+ /** The source of this event. */
+ private Document<D> source;
+
+ /** Constructs a DocumentEvent.
+ * @param source The Document on which the Event initially occurred.
+ * @param type The type of this event.
+ * @throws IllegalArgumentException if source is null.
+ */
+ public DocumentEvent(@NotNull final Document<D> source, @NotNull final DocumentEventType type) {
+ super(source);
+ this.source = source;
+ this.type = type;
+ }
+
+ /** {@inheritDoc}
+ * The source is the document on which this event occurred.
+ */
+ @Override public Document<D> getSource() {
+ return source;
+ }
+
+ /** Returns the type of this event.
+ * @return The type of this event.
+ */
+ @NotNull public DocumentEventType getType() {
+ return type;
+ }
+}
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentEvent.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentEventType.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentEventType.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentEventType.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,16 @@
+package net.sf.japi.swing.app;
+
+/** Type for {@link DocumentEvent}s.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public enum DocumentEventType {
+
+ /** A DocumentEvent that describes that the document's uri has changed. */
+ DOCUMENT_URI_CHANGED,
+
+ /** A DocumentEvent that describes that the document's title has changed. */
+ DOCUMENT_TITLE_CHANGED,
+
+ /** A DocumentEvent that describes that the document's content has changed. */
+ DOCUMENT_CONTENT_CHANGED,
+}
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentEventType.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentFrame.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentFrame.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentFrame.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,64 @@
+package net.sf.japi.swing.app;
+
+import java.awt.event.ActionEvent;
+import java.beans.PropertyVetoException;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JInternalFrame;
+import javax.swing.WindowConstants;
+import org.jetbrains.annotations.NotNull;
+
+/** Internal Frame for a document.
+ * @param <D> The document type that is managed by the application.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+class DocumentFrame<D> extends JInternalFrame {
+
+ /** The document of this DocumentFrame. */
+ @NotNull private Document<D> document;
+
+ /** The Action for activating this frame. */
+ private final Action windowAction = new AbstractAction() {
+
+ public void actionPerformed(final ActionEvent e) {
+ try {
+ setSelected(true);
+ } catch (final PropertyVetoException e1) {
+ /* simply ignore this. */
+ }
+ }
+ };
+
+ /** Creates a DocumentFrame.
+ * @param document Document for which to create a JInternalFrame.
+ */
+ DocumentFrame(@NotNull final Document<D> document) {
+ super("TODO", true, true, true, true);
+ setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ this.document = document;
+ }
+
+ /** Returns the document of this DocumentFrame.
+ * @return The document of this DocumentFrame.
+ */
+ @NotNull Document<D> getDocument() {
+ return document;
+ }
+
+ /** Updates the title of this frame. */
+ void updateFrameTitle() {
+ final StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(document.getTitle());
+ if (document.hasMoreThanOneFrame()) {
+ stringBuilder.append(":");
+ stringBuilder.append(document.getFrameNumber(this) + 1);
+ }
+ final String frameTitle = stringBuilder.toString();
+ setTitle(frameTitle);
+ windowAction.putValue(Action.NAME, frameTitle);
+ }
+
+ public Action getWindowAction() {
+ return windowAction;
+ }
+}
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentFrame.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentListener.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentListener.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentListener.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,33 @@
+package net.sf.japi.swing.app;
+
+import java.util.EventListener;
+import org.jetbrains.annotations.NotNull;
+
+/** The listener interface for receiving {@link DocumentEvent}s.
+ *
+ * Document events are provided for notification purposes ONLY.
+ * JAPI will automatically handle documentation uri and title changes
+ * so that these aspects work properly regardless of whether or not
+ * a program registers a {@link DocumentListener}.
+ * @param <D> The document type that is managed by the application.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public interface DocumentListener<D> extends EventListener {
+
+ /** Notifies this DocumentListener that a document's uri has changed.
+ * @param e DocumentEvent describing the uri change.
+ */
+ void documentUriChanged(@NotNull DocumentEvent<D> e);
+
+ /** Notifies this DocumentListener that a document's title has changed.
+ * @param e DocumentEvent describing the title change.
+ */
+ void documentTitleChanged(@NotNull DocumentEvent<D> e);
+
+ /** Notifies this DocumentListener that a document's content has changed.
+ * Only the first change is reported.
+ * Saving a document resets the state to unchanged.
+ * @param e DocumentEvent describing the content change.
+ */
+ void documentContentChanged(@NotNull DocumentEvent<D> e);
+}
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/DocumentListener.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/action.properties
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/action.properties (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/action.properties 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,84 @@
+application.title=Missing Resource: application.title
+
+application.menubar=file window help
+
+file.menu=fileNew fileOpen - fileSave fileSaveAs fileSaveAll - fileClose fileCloseAll - fileQuit
+
+file.text=File
+file.mnemonic=F
+
+fileNew.text=New
+fileNew.mnemonic=N
+fileNew.accel=ctrl pressed N
+fileNew.icon=general/New16
+fileNew.shortdescription=Creates a new document.
+
+fileOpen.text=Open...
+fileOpen.mnemonic=O
+fileOpen.accel=ctrl pressed O
+fileOpen.icon=general/Open16
+fileOpen.shortdescription=Opens an existing document.
+fileOpen.exception.java.io.IOException.title=Error while opening
+fileOpen.exception.java.io.IOException.message=Couldn''t open file.\nReason: {0}
+fileOpen.exception.java.io.IOException.messageType=ERROR_MESSAGE
+
+fileSave.text=Save
+fileSave.mnemonic=S
+fileSave.accel=ctrl pressed S
+fileSave.icon=general/Save16
+fileSave.shortdescription=Saves the current document.
+
+fileSaveAs.text=Save As...
+fileSaveAs.mnemonic=A
+fileSaveAs.icon=general/SaveAs16
+fileSaveAs.shortdescriptino=Saves the current document at a different location.
+
+fileSaveAll.text=Save all
+fileSaveAll.mnemonic=L
+fileSaveAll.icon=general/SaveAs16
+fileSaveAll.shortdescription=Saves all documents with unsaved changes.
+
+fileClose.text=Close
+fileClose.mnemonic=C
+fileClose.shortdescription=Closes the current document.
+
+fileCloseAll.text=Close all
+fileCloseAll.mnemonic=L
+fileCloseAll.shortdescription=Closes all documents.
+
+fileQuit.text=Quit
+fileQuit.mnemonic=Q
+fileQuit.accel=ctrl pressed Q
+fileQuit.shortdescription=Quits the program.
+
+reallyQuit.title=Really Quit?
+reallyQuit.message=Do you really want to quit?
+
+window.menu=winNew winClose -
+
+window.text=Window
+window.mnemonic=W
+
+winNew.text=New window
+winNew.mnemonic=N
+winNew.shortdescription=Opens a new window for this document.
+
+winClose.text=Close window
+winClose.mnemonic=C
+winClose.accel=ctrl pressed W
+winClose.shortdescription=Closes this document window.
+
+help.menu=about
+
+help.text=Help
+help.mnemonic=H
+
+about.text=About
+about.mnemonic=A
+about.icon=general/About16
+about.shortdescription=Shows some information about this application.
+
+about=MISSING
+
+documentNotSaved.message={0} contains unsaved changes.\nSave before closing?
+documentNotSaved.title=Not saved.
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/action.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/requirements.txt
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/Application.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/Application.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/Application.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,56 @@
+package net.sf.japi.swing.app.script;
+
+import java.util.List;
+
+/** The Application from a script's view.
+ * @param <D> The document type that is managed by the application.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class Application<D> {
+
+ /** Loads a document.
+ * @param uri URI from which to load the document.
+ */
+ public abstract Document<D> load(String uri);
+
+ /** Quits this application. */
+ public abstract void quit();
+
+ /** Returns the documents open in this application.
+ * @return The documents open in this application.
+ */
+ public abstract List<Document<D>> getDocuments();
+
+ /** A document within this application.
+ * @param <D> The document type that is managed by the application.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+ public abstract class Document<D> {
+
+ /** Saves this document. */
+ public abstract void save();
+
+ /** Saves this document at a different URI.
+ * The supplied URI is then the default URI for future saves with {@link save()}.
+ * @param uri URI at which to save this document.
+ */
+ public abstract void saveAs(String uri);
+
+ /** Closes this document. */
+ public abstract void close();
+
+ /** Returns the views on this document.
+ * @return The views on this document.
+ */
+ public abstract List<View<D>> getViews();
+
+ /** A view on a document.
+ * @param <D> The document type that is managed by the application.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+ public abstract class View<D> {
+ /** Closes this view. */
+ public abstract void close();
+ }
+ }
+}
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/Application.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/TryApplication.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/TryApplication.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/TryApplication.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,49 @@
+package net.sf.japi.swing.app.script;
+
+import java.util.List;
+
+/**
+ * TODO
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class TryApplication extends Application {
+
+ /** {@inheritDoc} */
+ public Document load(final String uri) {
+ return new Document();
+ }
+
+ /** {@inheritDoc} */
+ public void quit() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ /** {@inheritDoc} */
+ public List getDocuments() {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ /** {@inheritDoc} */
+ public class Document extends Application.Document {
+
+ /** {@inheritDoc} */
+ public void save() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ /** {@inheritDoc} */
+ public void saveAs(final String uri) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ /** {@inheritDoc} */
+ public void close() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ /** {@inheritDoc} */
+ public List getViews() {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+ }
+}
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/TryApplication.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/package-info.java
===================================================================
--- libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/package-info.java (rev 0)
+++ libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/package-info.java 2008-10-07 23:20:54 UTC (rev 695)
@@ -0,0 +1,4 @@
+/** This package contains the fundamental bindings for scripting applications.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+package net.sf.japi.swing.app.script;
Property changes on: libs/swing-app/trunk/src/prj/net/sf/japi/swing/app/script/package-info.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 23:04:02
|
Revision: 694
http://japi.svn.sourceforge.net/japi/?rev=694&view=rev
Author: christianhujer
Date: 2008-10-07 23:03:58 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Made compilable with ant.
Added Paths:
-----------
libs/swing-about/trunk/lib/japi-lib-swing-action-trunk.jar
Property changes on: libs/swing-about/trunk/lib/japi-lib-swing-action-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 23:00:38
|
Revision: 693
http://japi.svn.sourceforge.net/japi/?rev=693&view=rev
Author: christianhujer
Date: 2008-10-07 23:00:28 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Made compilable with ant.
Added Paths:
-----------
libs/net/trunk/lib/
libs/net/trunk/lib/japi-lib-io-trunk.jar
Property changes on: libs/net/trunk/lib/japi-lib-io-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 22:56:51
|
Revision: 692
http://japi.svn.sourceforge.net/japi/?rev=692&view=rev
Author: christianhujer
Date: 2008-10-07 22:56:47 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Made compilable with ant.
Added Paths:
-----------
libs/midi/trunk/build.xml
libs/midi/trunk/lib/
libs/midi/trunk/lib/japi-lib-swing-action-trunk.jar
libs/midi/trunk/module.properties
Property Changed:
----------------
libs/midi/trunk/
Property changes on: libs/midi/trunk
___________________________________________________________________
Added: svn:externals
+ common https://japi.svn.sourceforge.net/svnroot/japi/common/trunk
Added: libs/midi/trunk/build.xml
===================================================================
--- libs/midi/trunk/build.xml (rev 0)
+++ libs/midi/trunk/build.xml 2008-10-07 22:56:47 UTC (rev 692)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ JAPI libs-midi is a library for midi access.
+ ~ Copyright (C) 2008 Christian Hujer.
+ ~
+ ~ This library is free software; you can redistribute it and/or
+ ~ modify it under the terms of the GNU Lesser General Public
+ ~ License as published by the Free Software Foundation; either
+ ~ version 2.1 of the License, or (at your option) any later version.
+ ~
+ ~ This library is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ~ Lesser General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public
+ ~ License along with this library; if not, write to the Free Software
+ ~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE project [
+ <!ENTITY commonBuild SYSTEM "common/commonBuild.xml">
+]>
+<project name="japi lib midi" default="all">
+
+ &commonBuild;
+
+</project>
Property changes on: libs/midi/trunk/build.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Property changes on: libs/midi/trunk/lib/japi-lib-swing-action-trunk.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: libs/midi/trunk/module.properties
===================================================================
--- libs/midi/trunk/module.properties (rev 0)
+++ libs/midi/trunk/module.properties 2008-10-07 22:56:47 UTC (rev 692)
@@ -0,0 +1,26 @@
+#
+# JAPI libs-midi is a library for midi access.
+# Copyright (C) 2008 Christian Hujer.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+update.focus=none
+module.version=trunk
+module.name=japi-lib-midi
+module.shortname=midi
+module.title=Midi
+module.package=net.sf.japi.midi
+module.package.path=net/sf/japi/midi/
Property changes on: libs/midi/trunk/module.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 22:55:49
|
Revision: 691
http://japi.svn.sourceforge.net/japi/?rev=691&view=rev
Author: christianhujer
Date: 2008-10-07 22:55:45 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Fixed code convention issues.
Modified Paths:
--------------
libs/midi/trunk/src/prj/net/sf/japi/midi/DeviceComparator.java
libs/midi/trunk/src/prj/net/sf/japi/midi/MidiUtils.java
libs/midi/trunk/src/prj/net/sf/japi/midi/gui/OutputConfigurator.java
Modified: libs/midi/trunk/src/prj/net/sf/japi/midi/DeviceComparator.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/DeviceComparator.java 2008-10-07 21:15:19 UTC (rev 690)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/DeviceComparator.java 2008-10-07 22:55:45 UTC (rev 691)
@@ -8,6 +8,7 @@
*/
public class DeviceComparator implements Comparator<MidiDevice> {
+ /** The convenient default instance. */
private static Comparator<? super MidiDevice> instance = new DeviceComparator();
/** {@inheritDoc} */
Modified: libs/midi/trunk/src/prj/net/sf/japi/midi/MidiUtils.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/MidiUtils.java 2008-10-07 21:15:19 UTC (rev 690)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/MidiUtils.java 2008-10-07 22:55:45 UTC (rev 691)
@@ -15,7 +15,7 @@
/** Utility functions for working with MIDI.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public class MidiUtils {
+public final class MidiUtils {
/** Utility class - do not instanciate. */
private MidiUtils() {
Modified: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/OutputConfigurator.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/gui/OutputConfigurator.java 2008-10-07 21:15:19 UTC (rev 690)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/gui/OutputConfigurator.java 2008-10-07 22:55:45 UTC (rev 691)
@@ -26,6 +26,7 @@
*/
public class OutputConfigurator extends JComponent {
+ /** ActionBuilder. */
private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(OutputConfigurator.class);
/** The List of Devices from which to choose. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 21:15:23
|
Revision: 690
http://japi.svn.sourceforge.net/japi/?rev=690&view=rev
Author: christianhujer
Date: 2008-10-07 21:15:19 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Changed TODO comments to match code convention.
Modified Paths:
--------------
libs/logging/trunk/src/prj/net/sf/japi/log/StandardLogger.java
Modified: libs/logging/trunk/src/prj/net/sf/japi/log/StandardLogger.java
===================================================================
--- libs/logging/trunk/src/prj/net/sf/japi/log/StandardLogger.java 2008-10-07 20:56:33 UTC (rev 689)
+++ libs/logging/trunk/src/prj/net/sf/japi/log/StandardLogger.java 2008-10-07 21:15:19 UTC (rev 690)
@@ -29,7 +29,7 @@
public final class StandardLogger<Level extends Enum<Level>> implements Logger<Level> {
/** The minimum enabled level. */
- private Level enabledLevel; // TODO: init with reasonable value
+ private Level enabledLevel; // TODO:christianhujer:init with reasonable value
/** The ResourceBundle to get messages from. */
private final ResourceBundle bundle;
@@ -50,7 +50,7 @@
public void log(final Level level, final String key, final Object... params) {
if (level.ordinal() >= enabledLevel.ordinal()) {
- // TODO: alternatively use MessageFormat
+ // TODO:christianhujer:alternatively use MessageFormat
logImpl(level, null, String.format(bundle.getString(key), params));
}
}
@@ -63,7 +63,7 @@
public void log(final Level level, final Throwable t, final String key, final Object... params) {
if (level.ordinal() >= enabledLevel.ordinal()) {
- // TODO: alternatively use MessageFormat
+ // TODO:christianhujer:alternatively use MessageFormat
logImpl(level, t, String.format(bundle.getString(key), params));
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 20:56:36
|
Revision: 689
http://japi.svn.sourceforge.net/japi/?rev=689&view=rev
Author: christianhujer
Date: 2008-10-07 20:56:33 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Updated TODO comments to match code conventions.
Modified Paths:
--------------
libs/lang/trunk/src/prj/net/sf/japi/lang/PropertyComparator.java
Modified: libs/lang/trunk/src/prj/net/sf/japi/lang/PropertyComparator.java
===================================================================
--- libs/lang/trunk/src/prj/net/sf/japi/lang/PropertyComparator.java 2008-10-07 20:55:01 UTC (rev 688)
+++ libs/lang/trunk/src/prj/net/sf/japi/lang/PropertyComparator.java 2008-10-07 20:56:33 UTC (rev 689)
@@ -74,7 +74,7 @@
} catch (final IllegalAccessException e) {
throw new IllegalAccessError(e.getMessage());
} catch (final InvocationTargetException e) {
- throw new RuntimeException(e); // TODO use something better than RuntimeException
+ throw new RuntimeException(e); // TODO:christianhujer:use something better than RuntimeException
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 20:55:17
|
Revision: 688
http://japi.svn.sourceforge.net/japi/?rev=688&view=rev
Author: christianhujer
Date: 2008-10-07 20:55:01 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Fixed code style issue: IOUtils should be final and now is.
Modified Paths:
--------------
libs/io/trunk/src/prj/net/sf/japi/io/IOUtils.java
Modified: libs/io/trunk/src/prj/net/sf/japi/io/IOUtils.java
===================================================================
--- libs/io/trunk/src/prj/net/sf/japi/io/IOUtils.java 2008-10-07 20:37:03 UTC (rev 687)
+++ libs/io/trunk/src/prj/net/sf/japi/io/IOUtils.java 2008-10-07 20:55:01 UTC (rev 688)
@@ -9,7 +9,7 @@
/** Utility class for I/O.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public class IOUtils {
+public final class IOUtils {
/** Default size of buffers for copying and similar operations. */
private static final int DEFAULT_BUF_SIZE = 4096;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 20:37:06
|
Revision: 687
http://japi.svn.sourceforge.net/japi/?rev=687&view=rev
Author: christianhujer
Date: 2008-10-07 20:37:03 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Updated TODO comments to match code conventions.
Modified Paths:
--------------
libs/swing-action/trunk/src/prj/net/sf/japi/swing/DefaultActionBuilder.java
libs/swing-action/trunk/src/prj/net/sf/japi/swing/ReflectionAction.java
libs/swing-action/trunk/src/prj/net/sf/japi/swing/ToggleAction.java
Modified: libs/swing-action/trunk/src/prj/net/sf/japi/swing/DefaultActionBuilder.java
===================================================================
--- libs/swing-action/trunk/src/prj/net/sf/japi/swing/DefaultActionBuilder.java 2008-10-07 20:31:57 UTC (rev 686)
+++ libs/swing-action/trunk/src/prj/net/sf/japi/swing/DefaultActionBuilder.java 2008-10-07 20:37:03 UTC (rev 687)
@@ -853,7 +853,7 @@
return JOptionPane.PLAIN_MESSAGE;
}
if (!typeText.endsWith("_MESSAGE")) {
- System.err.println("Warning: Illegal type value " + typeText + " for dialog " + dialogKey); // TODO: I18N/L10N
+ System.err.println("Warning: Illegal type value " + typeText + " for dialog " + dialogKey); // TODO:christianhujer:I18N/L10N
return JOptionPane.PLAIN_MESSAGE;
}
if ("PLAIN_MESSAGE".equals(typeText)) {
@@ -874,11 +874,11 @@
return f.getInt(null);
}
} catch (final NoSuchFieldException e) {
- System.err.println("Warning: Field " + typeText + " not found in JOptionPane (dialog: " + dialogKey + ")."); // TODO: I18N/L10N
- e.printStackTrace(); //TODO
+ System.err.println("Warning: Field " + typeText + " not found in JOptionPane (dialog: " + dialogKey + ")."); // TODO:christianhujer:I18N/L10N
+ e.printStackTrace(); //TODO:christianhujer:Replace with proper logging.
} catch (final IllegalAccessException e) {
- System.err.println("Warning: Field " + typeText + " not accessible in JOptionPane (dialog: " + dialogKey + ")."); // TODO: I18N/L10N
- e.printStackTrace(); //TODO
+ System.err.println("Warning: Field " + typeText + " not accessible in JOptionPane (dialog: " + dialogKey + ")."); // TODO:christianhujer:I18N/L10N
+ e.printStackTrace(); //TODO:christianhujer:Replace with proper logging.
}
return JOptionPane.PLAIN_MESSAGE;
}
Modified: libs/swing-action/trunk/src/prj/net/sf/japi/swing/ReflectionAction.java
===================================================================
--- libs/swing-action/trunk/src/prj/net/sf/japi/swing/ReflectionAction.java 2008-10-07 20:31:57 UTC (rev 686)
+++ libs/swing-action/trunk/src/prj/net/sf/japi/swing/ReflectionAction.java 2008-10-07 20:37:03 UTC (rev 687)
@@ -167,13 +167,13 @@
if (!isEnabled()) { return; }
final Object instance = getValue(REFLECTION_TARGET);
try {
- // TODO: Special value for REFLECTION_ARGUMENTS which determines whether to use ActionEvent.
+ // TODO:christianhujer:Special value for REFLECTION_ARGUMENTS which determines whether to use ActionEvent.
final Method method = getMethod(instance);
if (method != null) {
final Object[] arguments = getArguments(method, e);
method.invoke(instance, arguments);
} else {
- // TODO: Improve logging / debugging
+ // TODO:christianhujer:Improve logging / debugging
System.err.println("Missing implementation for action " + getValue(ACTION_ID));
}
} catch (final IllegalAccessException ex) {
@@ -188,7 +188,7 @@
if (title != null) {
// source cannot be null because the ActionEvent constructor will not allow a null source.
@NotNull final Object source = e.getSource();
- final Component parent = source instanceof Component ? (Component) source : null; // TODO: find better alternative to null
+ final Component parent = source instanceof Component ? (Component) source : null; // TODO:christianhujer:find better alternative to null
actionBuilder.showMessageDialog(parent, dialogKey, cause.getLocalizedMessage());
return;
}
Modified: libs/swing-action/trunk/src/prj/net/sf/japi/swing/ToggleAction.java
===================================================================
--- libs/swing-action/trunk/src/prj/net/sf/japi/swing/ToggleAction.java 2008-10-07 20:31:57 UTC (rev 686)
+++ libs/swing-action/trunk/src/prj/net/sf/japi/swing/ToggleAction.java 2008-10-07 20:37:03 UTC (rev 687)
@@ -88,7 +88,7 @@
} catch (final IllegalAccessException ex) {
assert false : ex;
} catch (final InvocationTargetException ex) {
- // XXX workaround bug in IntelliJ IDEA (ex is NOT ignored)
+ // XXX:christianhujer:workaround bug in IntelliJ IDEA (ex is NOT ignored)
//noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException
ex.printStackTrace();
throw new RuntimeException(ex.getCause());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <chr...@us...> - 2008-10-07 20:32:00
|
Revision: 686
http://japi.svn.sourceforge.net/japi/?rev=686&view=rev
Author: christianhujer
Date: 2008-10-07 20:31:57 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Added midi library.
Added Paths:
-----------
libs/midi/
libs/midi/branches/
libs/midi/tags/
libs/midi/trunk/
libs/midi/trunk/midi.iml
libs/midi/trunk/src/
libs/midi/trunk/src/doc/
libs/midi/trunk/src/prj/
libs/midi/trunk/src/prj/net/
libs/midi/trunk/src/prj/net/sf/
libs/midi/trunk/src/prj/net/sf/japi/
libs/midi/trunk/src/prj/net/sf/japi/midi/
libs/midi/trunk/src/prj/net/sf/japi/midi/DeviceComparator.java
libs/midi/trunk/src/prj/net/sf/japi/midi/Interval.java
libs/midi/trunk/src/prj/net/sf/japi/midi/Interval.properties
libs/midi/trunk/src/prj/net/sf/japi/midi/IntervalTrainer.java
libs/midi/trunk/src/prj/net/sf/japi/midi/Interval_de.properties
libs/midi/trunk/src/prj/net/sf/japi/midi/MidiUtils.java
libs/midi/trunk/src/prj/net/sf/japi/midi/MonitorReceiver.java
libs/midi/trunk/src/prj/net/sf/japi/midi/MultiReceiver.java
libs/midi/trunk/src/prj/net/sf/japi/midi/OutputConfiguration.java
libs/midi/trunk/src/prj/net/sf/japi/midi/gui/
libs/midi/trunk/src/prj/net/sf/japi/midi/gui/MidiDeviceListCellRenderer.java
libs/midi/trunk/src/prj/net/sf/japi/midi/gui/OutputConfigurator.java
libs/midi/trunk/src/prj/net/sf/japi/midi/gui/SpinnerChannelModel.java
libs/midi/trunk/src/prj/net/sf/japi/midi/gui/action.properties
libs/midi/trunk/src/tst/
Added: libs/midi/trunk/midi.iml
===================================================================
--- libs/midi/trunk/midi.iml (rev 0)
+++ libs/midi/trunk/midi.iml 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/doc" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/prj" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/tst" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="annotations" level="project" />
+ <orderEntry type="library" name="junit" level="project" />
+ <orderEntry type="module" module-name="libs-swing-action" />
+ <orderEntryProperties />
+ </component>
+</module>
+
Property changes on: libs/midi/trunk/midi.iml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/DeviceComparator.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/DeviceComparator.java (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/DeviceComparator.java 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,24 @@
+package net.sf.japi.midi;
+
+import java.util.Comparator;
+import javax.sound.midi.MidiDevice;
+
+/** Comparator for MidiDevices which compares them by name.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class DeviceComparator implements Comparator<MidiDevice> {
+
+ private static Comparator<? super MidiDevice> instance = new DeviceComparator();
+
+ /** {@inheritDoc} */
+ public int compare(final MidiDevice o1, final MidiDevice o2) {
+ return o1.getDeviceInfo().getName().compareTo(o2.getDeviceInfo().getName());
+ }
+
+ /** Returns a default instance.
+ * @return Default instance.
+ */
+ public static Comparator<? super MidiDevice> getInstance() {
+ return instance;
+ }
+}
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/DeviceComparator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/Interval.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/Interval.java (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/Interval.java 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,29 @@
+package net.sf.japi.midi;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+import org.jetbrains.annotations.NotNull;
+
+/** An Interval, used for the {@link IntervalTrainer}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class Interval {
+
+ /** The distance of this interval, e.g. 0 for prime, 12 for octave. */
+ private int distance;
+
+ /** Returns the names of this interval in the current locale.
+ * @return The names of this interval in the current locale.
+ */
+ public String[] getNames() {
+ return ResourceBundle.getBundle("Interval").getString("I_" + distance + ".names").split(",");
+ }
+
+ /** Returns the names of this interval in the specified locale.
+ * @param locale Locale in which to return the names.
+ * @return The names of this interval in the specified locale.
+ */
+ public String[] getNames(@NotNull final Locale locale) {
+ return ResourceBundle.getBundle("Interval", locale).getString("I_" + distance + ".names").split(",");
+ }
+}
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/Interval.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/Interval.properties
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/Interval.properties (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/Interval.properties 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,13 @@
+I_0.names=Prime
+I_1.names=Kleine Sekunde,\xDCberm\xE4\xDFige Prime
+I_2.names=Gro\xDFe Sekunde,Verminderte Terz
+I_3.names=Kleine Terz
+I_4.names=Gro\xDFe Terz
+I_5.names=Quarte,\xDCberm\xE4\xDFige Terz
+I_6.names=Tritonus,\xDCberm\xE4\xDFige Quarte,Verminderte Quinte
+I_7.names=Quinte,Verminderte Sexte
+I_8.names=Kleine Sexte,\xDCberm\xE4\xDFige Quinte
+I_9.names=Gro\xDFe Sexte,Verminderte Septime
+I_10.names=Kleine Septime,\xDCberm\xE4\xDFige Sexte
+I_11.names=Gro\xDFe Septime,Verminderte Oktave
+I_12.names=Oktave,\xDCberm\xE4\xDFige Septime
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/Interval.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/IntervalTrainer.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/IntervalTrainer.java (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/IntervalTrainer.java 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,10 @@
+package net.sf.japi.midi;
+
+/** Training program for intervals.
+ * Plays intervals and asks the user to tell the correct kind of interval.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class IntervalTrainer {
+
+}
+
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/IntervalTrainer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/Interval_de.properties
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/Interval_de.properties (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/Interval_de.properties 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,13 @@
+I_0.names=Prime
+I_1.names=Kleine Sekunde,\xDCberm\xE4\xDFige Prime
+I_2.names=Gro\xDFe Sekunde,Verminderte Terz
+I_3.names=Kleine Terz
+I_4.names=Gro\xDFe Terz
+I_5.names=Quarte,\xDCberm\xE4\xDFige Terz
+I_6.names=Tritonus,\xDCberm\xE4\xDFige Quarte,Verminderte Quinte
+I_7.names=Quinte,Verminderte Sexte
+I_8.names=Kleine Sexte,\xDCberm\xE4\xDFige Quinte
+I_9.names=Gro\xDFe Sexte,Verminderte Septime
+I_10.names=Kleine Septime,\xDCberm\xE4\xDFige Sexte
+I_11.names=Gro\xDFe Septime,Verminderte Oktave
+I_12.names=Oktave,\xDCberm\xE4\xDFige Septime
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/Interval_de.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/MidiUtils.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/MidiUtils.java (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/MidiUtils.java 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,136 @@
+package net.sf.japi.midi;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.Receiver;
+import javax.sound.midi.SysexMessage;
+import javax.sound.midi.Transmitter;
+import org.jetbrains.annotations.NotNull;
+
+/** Utility functions for working with MIDI.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class MidiUtils {
+
+ /** Utility class - do not instanciate. */
+ private MidiUtils() {
+ }
+
+ /** Returns all {@link MidiDevice}s which provide {@link Receiver}s.
+ * @return All {@link MidiDevice}s which provide {@link Receiver}s.
+ * @throws MidiUnavailableException if one of the requested devices is unavailable due to resource restrictions.
+ */
+ public static MidiDevice[] getAllReceivingDevices() throws MidiUnavailableException {
+ return getReceivingDevices(MidiSystem.getMidiDeviceInfo());
+ }
+
+ /** Returns all {@iink MidiDevice}s which provide {@link Transmitter}s.
+ * @return All {@link MidiDevice}s which provide {@link Transmitter}s.
+ * @throws MidiUnavailableException if one of the requested devices is unavailable due to resource restrictions.
+ */
+ public static MidiDevice[] getAllTransmittingDevices() throws MidiUnavailableException {
+ return getTransmittingDevices(MidiSystem.getMidiDeviceInfo());
+ }
+
+ /** Returns those {@link MidiDevice}s which provide {@link Receiver}s.
+ * @param infos Device informations of which to return devices.
+ * @return Those {@link MidiDevice}s from <var>infos</var> which provide {@link Receiver}s.
+ * @throws MidiUnavailableException if one of the requested devices is unavailable due to resource restrictions.
+ */
+ public static MidiDevice[] getReceivingDevices(final MidiDevice.Info... infos) throws MidiUnavailableException {
+ final List<MidiDevice> receivingDevices = new ArrayList<MidiDevice>();
+ for (final MidiDevice.Info deviceInfo : infos) {
+ final MidiDevice device = MidiSystem.getMidiDevice(deviceInfo);
+ if (device.getMaxReceivers() != 0) {
+ receivingDevices.add(device);
+ }
+ }
+ Collections.sort(receivingDevices, DeviceComparator.getInstance());
+ return receivingDevices.toArray(new MidiDevice[receivingDevices.size()]);
+ }
+
+ /** Returns those {@link MidiDevice}s which provide {@link Transmitter}s.
+ * @param infos Device informations of which to return devices.
+ * @return Those {@link MidiDevice}s from <var>infos</var> which provide {@link Transmitter}s.
+ * @throws MidiUnavailableException if one of the requested devices is unavailable due to resource restrictions.
+ */
+ public static MidiDevice[] getTransmittingDevices(final MidiDevice.Info... infos) throws MidiUnavailableException {
+ final List<MidiDevice> transmittingDevices = new ArrayList<MidiDevice>();
+ for (final MidiDevice.Info deviceInfo : infos) {
+ final MidiDevice device = MidiSystem.getMidiDevice(deviceInfo);
+ if (device.getMaxTransmitters() != 0) {
+ transmittingDevices.add(device);
+ }
+ }
+ Collections.sort(transmittingDevices, DeviceComparator.getInstance());
+ return transmittingDevices.toArray(new MidiDevice[transmittingDevices.size()]);
+ }
+
+ /** Creates a Sysex message from a String.
+ * @param data String from which to create the Sysex message.
+ * @return Sysex message created from <var>data</var>.
+ * @throws InvalidMidiDataException if <var>data</var> does not denote a valid Sysex message (the first byte must be 0xF0 or 0xF7).
+ */
+ public static SysexMessage createSysexMessage(@NotNull final String data) throws InvalidMidiDataException {
+ final SysexMessage message = new SysexMessage();
+ final byte[] realData = new byte[data.length() / 2];
+ for (int i = 0; i < realData.length; i++) {
+ realData[i] = (byte) Integer.parseInt(data.substring(i * 2, i * 2 + 2), 16);
+ }
+ System.out.format("%n");
+ message.setMessage(realData, realData.length);
+ return message;
+ }
+
+ /** Returns the first device found in the system with the specified name that provides Receivers.
+ * @param name Name of the receiving device to return.
+ * @return The requested device or <code>null</code> if the requested device was not found.
+ * @throws MidiUnavailableException if one of the requested devices is unavailable due to resource restrictions.
+ */
+ public static MidiDevice getReceivingDevice(@NotNull final String name) throws MidiUnavailableException {
+ for (final MidiDevice.Info deviceInfo : MidiSystem.getMidiDeviceInfo()) {
+ if (deviceInfo.getName().equals(name)) {
+ final MidiDevice device = MidiSystem.getMidiDevice(deviceInfo);
+ if (device.getMaxReceivers() != 0) {
+ return device;
+ }
+ }
+ }
+ return null;
+ }
+
+ /** Returns the first device found in the system with the specified name that provides Transmitters.
+ * @param name Name of the receiving device to return.
+ * @return The requested device or <code>null</code> if the requested device was not found.
+ * @throws MidiUnavailableException if one of the requested devices is unavailable due to resource restrictions.
+ */
+ public static MidiDevice getTransmittingDevice(@NotNull final String name) throws MidiUnavailableException {
+ for (final MidiDevice.Info deviceInfo : MidiSystem.getMidiDeviceInfo()) {
+ if (deviceInfo.getName().equals(name)) {
+ final MidiDevice device = MidiSystem.getMidiDevice(deviceInfo);
+ if (device.getMaxTransmitters() != 0) {
+ return device;
+ }
+ }
+ }
+ return null;
+ }
+
+ /** Returns a device by its name.
+ * @param name Name of the device to return.
+ * @return The first device found that matches <var>name</var> or <code>null</code> if the requested device was not found.
+ */
+ public static MidiDevice getDeviceByName(@NotNull final String name) throws MidiUnavailableException {
+ for (final MidiDevice.Info deviceInfo : MidiSystem.getMidiDeviceInfo()) {
+ if (deviceInfo.getName().equals(name)) {
+ return MidiSystem.getMidiDevice(deviceInfo);
+ }
+ }
+ return null;
+ }
+}
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/MidiUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/MonitorReceiver.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/MonitorReceiver.java (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/MonitorReceiver.java 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,76 @@
+package net.sf.japi.midi;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Formatter;
+import javax.sound.midi.MidiMessage;
+import javax.sound.midi.Receiver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/** A MonitorReceiver is a Receiver that prints messages to System.out.
+ * It optionally can delegate to another receiver.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class MonitorReceiver implements Receiver {
+
+ /** The Receiver to which to delegate. */
+ @Nullable private final Receiver receiver;
+
+ /** The prefix for messages printed by this MonitorReceiver. */
+ private final String prefix;
+
+ /** The Appendable to which messages are printed. */
+ private final Appendable out;
+
+ /** The Formatter that is used to format messages to {@link #out}. */
+ private final Formatter format;
+
+ /** Create a MonitorReceiver.
+ * @param prefix Prefix for messages printed by this MonitorReceiver.
+ */
+ public MonitorReceiver(@NotNull final String prefix) {
+ this(prefix, null);
+ }
+
+ /** Create a MonitorReceiver.
+ * @param prefix Prefix for messages printed by this MonitorReceiver.
+ * @param receiver Receiver to which messages shall be delegated.
+ */
+ public MonitorReceiver(@NotNull final String prefix, @Nullable final Receiver receiver) {
+ this.prefix = prefix;
+ out = System.out;
+ format = new Formatter(out);
+ this.receiver = receiver;
+ }
+
+ /** {@inheritDoc} */
+ public void send(final MidiMessage message, final long timeStamp) {
+ format.format("[%s] %08x ", prefix, timeStamp);
+ final byte[] msg = message.getMessage();
+ for (final byte b : msg) {
+ format.format("%02x", b);
+ }
+ format.format("%n");
+ format.flush();
+ if (receiver != null) {
+ receiver.send(message, timeStamp);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void close() {
+ if (receiver != null) {
+ receiver.close();
+ }
+ format.flush();
+ if (out instanceof Closeable) {
+ try {
+ ((Closeable) out).close();
+ } catch (final IOException e) {
+ // ignore
+ }
+ }
+ }
+
+}
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/MonitorReceiver.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/MultiReceiver.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/MultiReceiver.java (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/MultiReceiver.java 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,44 @@
+package net.sf.japi.midi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.sound.midi.MidiMessage;
+import javax.sound.midi.Receiver;
+import org.jetbrains.annotations.NotNull;
+
+/** A Midi Receiver which sends its received message to an arbitrary number of other receivers.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class MultiReceiver implements Receiver {
+
+ /** The Receivers. */
+ private final Collection<Receiver> receivers = new ArrayList<Receiver>();
+
+ /** Adds a Receiver.
+ * @param receiver Receiver to add.
+ */
+ public void addReceiver(@NotNull final Receiver receiver) {
+ receivers.add(receiver);
+ }
+
+ /** Removes a Receiver.
+ * @param receiver Receiver to remove.
+ */
+ public void removeReceiver(@NotNull final Receiver receiver) {
+ receivers.remove(receiver);
+ }
+
+ /** {@inheritDoc} */
+ public void send(final MidiMessage message, final long timeStamp) {
+ for (final Receiver receiver : receivers) {
+ receiver.send(message, timeStamp);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void close() {
+ for (final Receiver receiver : receivers) {
+ receiver.close();
+ }
+ }
+}
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/MultiReceiver.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/OutputConfiguration.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/OutputConfiguration.java (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/OutputConfiguration.java 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,44 @@
+package net.sf.japi.midi;
+
+import javax.sound.midi.MidiDevice;
+import org.jetbrains.annotations.NotNull;
+
+/** OutputConfiguration describes a MIDI target, which is the combination of device and channel.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class OutputConfiguration {
+
+ /** The device. */
+ @NotNull private final MidiDevice device;
+
+ /** The channel. */
+ private final int channel;
+
+ /** Creates an OutputConfiguration.
+ * @param device MidiDevice.
+ * @param channel Midi Channel.
+ */
+ public OutputConfiguration(@NotNull final MidiDevice device, final int channel) {
+ this.device = device;
+ this.channel = channel;
+ }
+
+ /** Returns the MidiDevice.
+ * @return The MidiDevice.
+ */
+ @NotNull public MidiDevice getDevice() {
+ return device;
+ }
+
+ /** Returns the Midi Channel.
+ * @return The Midi Channel.
+ */
+ public int getChannel() {
+ return channel;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return device.getDeviceInfo().getName() + ": " + channel;
+ }
+}
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/OutputConfiguration.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/MidiDeviceListCellRenderer.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/gui/MidiDeviceListCellRenderer.java (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/gui/MidiDeviceListCellRenderer.java 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,22 @@
+package net.sf.japi.midi.gui;
+
+import java.awt.Component;
+import javax.sound.midi.MidiDevice;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JList;
+
+/** ListCellRenderer for Midi Devices.
+ * Class Description.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class MidiDeviceListCellRenderer extends DefaultListCellRenderer {
+
+ /** {@inheritDoc} */
+ @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
+ final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+ if (value instanceof MidiDevice) {
+ setText(((MidiDevice) value).getDeviceInfo().getName());
+ }
+ return c;
+ }
+}
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/MidiDeviceListCellRenderer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/OutputConfigurator.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/gui/OutputConfigurator.java (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/gui/OutputConfigurator.java 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,95 @@
+package net.sf.japi.midi.gui;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.FlowLayout;
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiUnavailableException;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import net.sf.japi.midi.MidiUtils;
+import net.sf.japi.midi.OutputConfiguration;
+import net.sf.japi.swing.ActionBuilder;
+import net.sf.japi.swing.ActionBuilderFactory;
+import org.jetbrains.annotations.Nullable;
+
+/** UI component for configuring a midi output.
+ * The user can choose of one of the receiving devices and select a channel.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class OutputConfigurator extends JComponent {
+
+ private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(OutputConfigurator.class);
+
+ /** The List of Devices from which to choose. */
+ private final JList deviceList;
+
+ /** The Spinner for selecting the channel. */
+ private final JSpinner channelSpinner;
+
+ /** Creates an OutputConfigurator with no initial configuration.
+ * The first device and channel 0 will be selected as defaults.
+ * @throws MidiUnavailableException if one of the requested devices is unavailable due to resource restrictions.
+ */
+ public OutputConfigurator() throws MidiUnavailableException {
+ setLayout(new BorderLayout());
+ deviceList = new JList(MidiUtils.getAllReceivingDevices());
+ deviceList.setCellRenderer(new MidiDeviceListCellRenderer());
+ deviceList.setSelectedIndex(0);
+ channelSpinner = new JSpinner(new SpinnerNumberModel(0, 0x0, 0xF, 1));
+ //channelSpinner = new JSpinner(new SpinnerChannelModel());
+ add(new JScrollPane(deviceList));
+ final Container spinnerPanel = new JPanel();
+ spinnerPanel.setLayout(new FlowLayout());
+ spinnerPanel.add(new JLabel(ACTION_BUILDER.getString("Channel.label")));
+ spinnerPanel.add(channelSpinner);
+ add(spinnerPanel, BorderLayout.SOUTH);
+ }
+
+ /** Shows a dialog where the user can choose a receiving device and channel once.
+ * @param parent Parent component on which to show the dialog.
+ * @return OutputConfiguration or <code>null</code> if the user chose to abort the dialog.
+ * @throws MidiUnavailableException if one of the requested devices is unavailable due to resource restrictions.
+ */
+ @Nullable public static OutputConfiguration showDialog(@Nullable final Component parent) throws MidiUnavailableException {
+ final OutputConfigurator configurator = new OutputConfigurator();
+ final int result = JOptionPane.showConfirmDialog(parent, configurator, ACTION_BUILDER.getString("Dialog.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
+ return result == JOptionPane.OK_OPTION ? configurator.getConfiguration() : null;
+ }
+
+ /** Returns the selected configuration.
+ * @return The selected configuration.
+ */
+ public OutputConfiguration getConfiguration() {
+ return new OutputConfiguration(getSelectedDevice(), getSelectedChannel());
+ }
+
+ /** Returns the selected device.
+ * @return The selected device.
+ */
+ public MidiDevice getSelectedDevice() {
+ return (MidiDevice) deviceList.getSelectedValue();
+ }
+
+ /** Returns the selected channel.
+ * @return The selected channel.
+ */
+ public int getSelectedChannel() {
+ return (Integer) channelSpinner.getValue();
+ }
+
+ /** Main program of OutputConfigurator, used for trying the most common use cases.
+ * @param args Command line arguments (ignored).
+ * @throws MidiUnavailableException if one of the requested devices is unavailable due to resource restrictions.
+ */
+ public static void main(final String... args) throws MidiUnavailableException {
+ System.out.println(showDialog(null));
+ }
+}
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/OutputConfigurator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/SpinnerChannelModel.java
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/gui/SpinnerChannelModel.java (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/gui/SpinnerChannelModel.java 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,42 @@
+package net.sf.japi.midi.gui;
+
+import javax.swing.AbstractSpinnerModel;
+
+/** A SpinnerModel for MIDI Channels.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class SpinnerChannelModel extends AbstractSpinnerModel {
+
+ /** The current channel. */
+ private int value;
+
+ /** Creates a SpinnerChannelModel which initially selects channel 0. */
+ public SpinnerChannelModel() {
+ value = 0;
+ }
+
+ /** {@inheritDoc} */
+ public Object getValue() {
+ return value;
+ }
+
+ /** {@inheritDoc} */
+ public void setValue(final Object value) {
+ final int newValue = (Integer) value;
+ if (newValue < 0x0 || newValue > 0xF) {
+ throw new IllegalArgumentException("Not a valid MIDI channel.");
+ }
+ this.value = newValue;
+ fireStateChanged();
+ }
+
+ /** {@inheritDoc} */
+ public Object getNextValue() {
+ return value < 0xF ? value + 1 : null;
+ }
+
+ /** {@inheritDoc} */
+ public Object getPreviousValue() {
+ return value > 0x0 ? value - 1 : null;
+ }
+}
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/SpinnerChannelModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/action.properties
===================================================================
--- libs/midi/trunk/src/prj/net/sf/japi/midi/gui/action.properties (rev 0)
+++ libs/midi/trunk/src/prj/net/sf/japi/midi/gui/action.properties 2008-10-07 20:31:57 UTC (rev 686)
@@ -0,0 +1,2 @@
+Channel.label=Channel
+Dialog.title=Midi Output
Property changes on: libs/midi/trunk/src/prj/net/sf/japi/midi/gui/action.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|