[Japi-cvs] SF.net SVN: japi:[1298] progs/batcher/trunk
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2009-05-21 12:49:07
|
Revision: 1298 http://japi.svn.sourceforge.net/japi/?rev=1298&view=rev Author: christianhujer Date: 2009-05-21 12:47:00 +0000 (Thu, 21 May 2009) Log Message: ----------- Update Batcher. Now has a simple example that works and much of the desired final structure. Still a long way to go, though. Modified Paths: -------------- progs/batcher/trunk/Batcher.iml progs/batcher/trunk/build.xml progs/batcher/trunk/module.properties progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Main.java Added Paths: ----------- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/AbstractChangeable.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Batch.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/BatchList.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/BatchRun.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Changeable.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/ChangeableList.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Job.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobList.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobRun.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobRunView.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobView.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Project.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/ShellPane.java progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/SimpleShell.java Modified: progs/batcher/trunk/Batcher.iml =================================================================== --- progs/batcher/trunk/Batcher.iml 2009-05-12 23:42:49 UTC (rev 1297) +++ progs/batcher/trunk/Batcher.iml 2009-05-21 12:47:00 UTC (rev 1298) @@ -21,23 +21,41 @@ <orderEntry type="module-library"> <library> <CLASSES> - <root url="jar://$MODULE_DIR$/common/lib/jlfgr-1_0.jar!/" /> + <root url="jar://$MODULE_DIR$/common/antlib.auto/junit.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> </orderEntry> + <orderEntry type="module" module-name="libs-swing-about" /> + <orderEntry type="module" module-name="libs-swing-action" /> <orderEntry type="module-library"> <library> <CLASSES> - <root url="jar://$MODULE_DIR$/common/antlib.auto/junit.jar!/" /> + <root url="jar://$MODULE_DIR$/lib/japi-lib-swing-action.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> </orderEntry> - <orderEntry type="module" module-name="libs-swing-about" /> - <orderEntry type="module" module-name="libs-swing-action" /> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MODULE_DIR$/lib/japi-lib-swing-misc.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MODULE_DIR$/lib/jlfgr-1_0.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> </component> </module> Modified: progs/batcher/trunk/build.xml =================================================================== --- progs/batcher/trunk/build.xml 2009-05-12 23:42:49 UTC (rev 1297) +++ progs/batcher/trunk/build.xml 2009-05-21 12:47:00 UTC (rev 1298) @@ -24,6 +24,8 @@ <target name="getlibs"> <get src="http://downloads.sourceforge.net/japi/japi-lib-swing-action-0.1.0.jar" dest="lib/japi-lib-swing-action.jar" /> + <get src="http://downloads.sourceforge.net/japi/japi-lib-swing-misc-0.1.0.jar" dest="lib/japi-lib-swing-misc.jar" /> + <get src="http://downloads.sourceforge.net/japi/jlfgr-1_0.jar" dest="lib/jlfgr-1_0.jar" /> </target> </project> Modified: progs/batcher/trunk/module.properties =================================================================== --- progs/batcher/trunk/module.properties 2009-05-12 23:42:49 UTC (rev 1297) +++ progs/batcher/trunk/module.properties 2009-05-21 12:47:00 UTC (rev 1298) @@ -20,5 +20,5 @@ shortname=Batcher title=Batcher package=net.sf.japi.batcher -package.path=net/sf/japi/batcher -main.class=net.sf.japi.batcher.Batcher +package.path=net/sf/japi/progs/batcher +main.class=net.sf.japi.progs.batcher.SimpleShell Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/AbstractChangeable.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/AbstractChangeable.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/AbstractChangeable.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +/** Abstract base implementation of {@link Changeable}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public abstract class AbstractChangeable implements Changeable { + + /** Change status. + * @serial include + */ + private boolean changed; + + /** {@inheritDoc} */ + public boolean hasChanged() { + return changed; + } + + /** {@inheritDoc} */ + public void setChanged(final boolean changed) { + this.changed = changed; + } + +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/AbstractChangeable.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Batch.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Batch.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Batch.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +/** A Batch. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class Batch extends AbstractChangeable { + + /** The title of this batch. + * @serial include + */ + private String title; + +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Batch.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/BatchList.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/BatchList.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/BatchList.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +/** A list of batches. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class BatchList extends ChangeableList<Batch> { +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/BatchList.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/BatchRun.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/BatchRun.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/BatchRun.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +/** A batch run. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class BatchRun { + + /** The batch that is run. */ + private Batch batch; + + /** Stops this job. */ + public void stop() { + } +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/BatchRun.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Changeable.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Changeable.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Changeable.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +import java.io.Serializable; + +/** Interface for application data elements which are queried for the changed state of a project or document. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public interface Changeable extends Serializable { + + /** Returns whether or not this Changeable has changed. + * A changeable has changed if itself or one of its components is changed. + * @return <code>true</code> if this changeable has changed, otherwise <code>false</code>. + */ + boolean hasChanged(); + + /** Sets whether or not this Changeable has changed. + * @param changed <code>true</code> if this changeable is changed, otherwise <code>false</code>. + * @note Setting changed to true is a shallow, setting changed to false is a deep operation. + */ + void setChanged(boolean changed); + +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Changeable.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/ChangeableList.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/ChangeableList.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/ChangeableList.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import javax.swing.AbstractListModel; +import org.jetbrains.annotations.NotNull; + +/** List of Changeables. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @param <C> Changeable type to list. + * @since 0.1 + */ +public class ChangeableList<C extends Changeable> extends AbstractListModel implements Changeable { + + /** Changeables in this ChangeableList. + * @serial include + */ + private List<C> elements = new ArrayList<C>(); + + /** Changed state. + * @serial include + */ + private boolean changed; + + /** Creates a ChangeableList. */ + public ChangeableList() { + } + + /** {@inheritDoc} */ + public boolean hasChanged() { + boolean changed = this.changed; + for (final Iterator<C> it = elements.iterator(); !changed && it.hasNext();) { + changed |= it.next().hasChanged(); + } + return changed; + } + + /** {@inheritDoc} */ + public void setChanged(final boolean changed) { + this.changed = changed; + if (!changed) { + for (final Iterator<C> it = elements.iterator(); it.hasNext();) { + it.next().setChanged(false); + } + } + } + + /** Adds an element to this ChangeableList. + * @param c Element to add. + */ + protected void add(final C c) { + int index = elements.size(); + elements.add(c); + setChanged(true); + fireIntervalAdded(this, index, index); + } + + /** Removes an element from this ChangeableList. + * @param c Element to remove. + */ + protected void remove(final C c) { + int index = elements.indexOf(c); + if (index == -1) { + assert false : "Trying to remove an element from a list which is not there."; + return; + } + elements.remove(c); + setChanged(true); + fireIntervalRemoved(this, index, index); + } + + /** {@inheritDoc} */ + public Object getElementAt(final int index) { + return elements.get(index); + } + + /** {@inheritDoc} */ + public int getSize() { + return elements.size(); + } + +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/ChangeableList.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Job.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Job.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Job.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Map; +import net.sf.japi.swing.misc.CollectionsListModel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** A Job. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class Job extends AbstractChangeable { + + /** The title. + * @serial include + */ + private String title; + + /** The environment. + * Inherited from parent if <code>null</code>. + * @serial include + */ + @Nullable private Map<String, String> env; + + /** The command line with its arguments. + * @serial include + */ + private CollectionsListModel<String> command = new CollectionsListModel<String>(new ArrayList<String>()); + + /** The process builder. + * @serial exclude + */ + private transient ProcessBuilder processBuilder; + + /** Creates a Job. + * @param title Title for this Job. + */ + public Job(@NotNull final String title) { + processBuilder = new ProcessBuilder(command); + processBuilder.redirectErrorStream(true); + env = processBuilder.environment(); + this.title = title; + } + + /** Returns the current working directory. + * @return The current working directory. + */ + @Nullable public File getCurrentWorkingDirectory() { + return processBuilder.directory(); + } + + /** Sets the current working directory. + * @param directory The new current working directory. + */ + public void setCurrentWorkingDirectory(@Nullable final File directory) { + processBuilder.directory(directory); + } + + /** Returns the arguments. + * @return Arguments + */ + @NotNull public CollectionsListModel<String> getCommand() { + return command; + } + + /** Starts a process. + * @return Process just started. + * @throws IOException in case the process could not be started. + */ + public Process start() throws IOException { + return processBuilder.start(); + } + +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Job.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobList.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobList.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobList.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +/** A list of jobs. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class JobList extends ChangeableList<Job> { +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobList.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobRun.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobRun.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobRun.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.IOException; +import java.util.List; +import javax.swing.SwingWorker; +import org.jetbrains.annotations.NotNull; + +/** A job run. + * + * A job run can be executed only once. + * If you want to execute the same job a second time, use a new JobRun instance. + * + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class JobRun extends SwingWorker<Object, String> { + + /** The view on which the job run shall be displayed. */ + private final JobRunView jobRunView; + + /** The job that is run. */ + private final Job job; + + /** The output of the job. */ + private String output; + + /** The return value of the job. */ + private int retVal; + + /** Creates a JobRun. + * @param jobRunView JobRunView for displaying the job run. + * @param job Job to run. + */ + public JobRun(@NotNull final JobRunView jobRunView, @NotNull final Job job) { + this.job = job; + this.jobRunView = jobRunView; + } + + /** {@inheritDoc} */ + @Override + public Object doInBackground() { + final StringBuilder sb = new StringBuilder(); + try { + final Process p = job.start(); + final Reader in = /*new BufferedReader*/(new InputStreamReader(p.getInputStream())); + final char[] buf = new char[4096]; + for (int charsRead; (charsRead = in.read(buf)) != -1;) { + publish(new String(buf, 0, charsRead)); + } + } catch (final Throwable e) { + publish(e.toString()); + } + return null; + } + + /** {@inheritDoc} */ + @Override + public void process(final List<String> chunks) { + for (final String s : chunks) { + jobRunView.append(s); + } + } + + /** Stops this JobRun. */ + public void stop() { + cancel(true); + } +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobRun.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobRunView.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobRunView.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobRunView.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +import java.awt.Color; +import java.awt.Font; +import java.awt.GridLayout; +import javax.swing.ScrollPaneConstants; +import javax.swing.JComponent; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +/** View to a Job Run. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class JobRunView extends JComponent { + + /** The textArea of this JobRunView. */ + private JTextArea textArea = new JTextArea(25, 80); + + /** Creates a JobRunView. */ + public JobRunView() { + setLayout(new GridLayout(1, 1)); + textArea.setForeground(Color.white); + textArea.setBackground(Color.black); + textArea.setEditable(false); + textArea.setFont(new Font(Font.MONOSPACED, textArea.getFont().getStyle(), textArea.getFont().getSize())); + add(new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED)); + } + + /** Appends a String to this JobRunView. + * @param s String to append. + */ + public void append(final String s) { + textArea.append(s); + } +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobRunView.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobView.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobView.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobView.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JTextField; +import javax.swing.JScrollPane; +import net.sf.japi.swing.misc.JFileField; +import org.jetbrains.annotations.NotNull; + +/** View for a Job. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class JobView extends JComponent implements ActionListener { + + /** The Job of this JobView. + * @serial include + */ + private Job job; + + /** The textfield for the title. + * @serial include + */ + private JTextField titleField; + + /** The filefield for the current working directory. + * @serial include + */ + private JFileField currentWorkingDirectoryField; + + /** The view of the current JobRun. */ + private JobRunView out; + + /** Creates a JobView. + * @param job Job to view. + */ + public JobView(@NotNull final Job job) { + this.job = job; + + //setLayout(new GridBagLayout()); + setLayout(new java.awt.FlowLayout()); + final GridBagConstraints gbc = new GridBagConstraints(); + + titleField = new JTextField(20); + currentWorkingDirectoryField = new JFileField("", "" + job.getCurrentWorkingDirectory(), JFileChooser.DIRECTORIES_ONLY); + + add(new JScrollPane(new JList(job.getCommand())), gbc); + + add(new JLabel("XXX title"), gbc); + add(titleField, gbc); + + add(new JLabel("XXX wd"), gbc); + add(currentWorkingDirectoryField, gbc); + + final JButton start = new JButton("run"); + start.addActionListener(this); + add(start, gbc); + + out = new JobRunView(); + add(out, gbc); + } + + public void actionPerformed(@NotNull final ActionEvent e) { + System.out.println("Run"); + new JobRun(out, job).execute(); + } +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/JobView.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Main.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Main.java 2009-05-12 23:42:49 UTC (rev 1297) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Main.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -17,18 +17,32 @@ package net.sf.japi.progs.batcher; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; import java.awt.Frame; import java.awt.Toolkit; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.beans.PropertyVetoException; +import java.util.Arrays; +import javax.swing.JButton; +import javax.swing.JDesktopPane; import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.ScrollPaneConstants; import javax.swing.WindowConstants; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; import net.sf.japi.swing.action.ActionMethod; import org.jetbrains.annotations.NotNull; -/** Main class of Batcher +/** Main class of Batcher. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @since 0.1 */ @@ -38,33 +52,88 @@ @NotNull private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(Main.class); - /** - * Main program. + /** Main program. * @param args Command line arguments (ignored). */ public static void main(final String... args) { - new Main(); + new Main(args); } /** The program frame. */ private final JFrame frame; - /** Creates Main. */ - public Main() { + /** Creates Main. + * @param args Command line arguments. + */ + public Main(final String... args) { frame = new JFrame(ACTION_BUILDER.getString("window.title")); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.setJMenuBar(ACTION_BUILDER.createMenuBar(true, "Main", this)); frame.setSize(Toolkit.getDefaultToolkit().getScreenSize()); frame.setExtendedState(Frame.MAXIMIZED_BOTH); frame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent e) { + @Override public void windowClosing(final WindowEvent e) { quit(); } }); - frame.setVisible(true); } +// /** Creates Main. +// * @param args Command line arguments +// */ +// public Main(final String... args) { +// frame = new JFrame(ACTION_BUILDER.getString("window.title")); +// frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); +// frame.setJMenuBar(ACTION_BUILDER.createMenuBar(true, "Main", this)); +// frame.setSize(Toolkit.getDefaultToolkit().getScreenSize()); +// frame.setExtendedState(Frame.MAXIMIZED_BOTH); +// frame.addWindowListener(new WindowAdapter() { +// @Override +// public void windowClosing(final WindowEvent e) { +// quit(); +// } +// }); +// final JDesktopPane desktop = new JDesktopPane(); +// frame.add(desktop, BorderLayout.CENTER); +// for (int i = 0; i < 5; i++) { +// final JInternalFrame iFrame = new JInternalFrame("app " + i, true, true, true, false); +// init(iFrame); +// desktop.add(iFrame); +// try { +// iFrame.setMaximum(true); +// } catch (final PropertyVetoException e) { +// System.err.println(e); +// } +// } +// frame.setVisible(true); +// } +// +// public void init(final JInternalFrame frame) { +// frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); +// //final Job job = new Job("foo"); +// //job.getCommand().addAll(Arrays.asList(args)); +// //frame.getContentPane().add(new JobView(job)); +// +// final JTabbedPane tabs = new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT); +// for (int i = 0; i < 40; i++) { +// final JTextArea textArea = new JTextArea(25, 80); +// textArea.setForeground(Color.white); +// textArea.setBackground(Color.black); +// textArea.setEditable(false); +// textArea.setFont(new Font(Font.MONOSPACED, textArea.getFont().getStyle(), textArea.getFont().getSize())); +// final Component c = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); +// tabs.add("Command " + i, c); +// } +// frame.getContentPane().add(tabs); +// +// final JPanel east = new JPanel(); +// east.add(new JButton("foo")); +// frame.getContentPane().add(east, BorderLayout.WEST); +// +// frame.pack(); +// frame.setVisible(true); +// } +// /** Quits the program. */ @ActionMethod public void quit() { Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Project.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Project.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Project.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +import org.jetbrains.annotations.NotNull; + +/** A project. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class Project implements Changeable { + + /** List with all jobs. + * @serial include + */ + private JobList jobList = new JobList(); + + /** List with all batches. + * @serial include + */ + private BatchList batchList = new BatchList(); + + /** The title of this project. + * @serial include + */ + private String title; + + /** Changed state. + * @serial include + */ + private boolean changed; + + /** Create an unnamed project. */ + public Project() { + this("unnamed project"); + } + + /** Create a project. + * @param title The title of this project. + */ + public Project(@NotNull final String title) { + this.title = title; + } + + /** Returns the job list of this project. + * @return The job list. + */ + public JobList getJobList() { + return jobList; + } + + /** Returns the batch list of this project. + * @return The batch list. + */ + public BatchList getBatchList() { + return batchList; + } + + /** Returns the title of this project. + * @return The title. + */ + public String getTitle() { + return title; + } + + /** Sets the title of this project. + * @param title New title of this project. + */ + public void setTitle(@NotNull final String title) { + this.title = title; + setChanged(true); + } + + /** {@inheritDoc} */ + public boolean hasChanged() { + return changed || jobList.hasChanged() || batchList.hasChanged(); + } + + /** {@inheritDoc} */ + public void setChanged(final boolean changed) { + this.changed = changed; + if (!changed) { + jobList.setChanged(changed); + batchList.setChanged(changed); + } + } + +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/Project.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/ShellPane.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/ShellPane.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/ShellPane.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JButton; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; +import javax.swing.SwingWorker; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; +import java.util.List; +import java.util.ArrayList; +import java.io.Reader; +import java.io.InputStreamReader; + +/** A Shell Pane. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class ShellPane extends JPanel implements ActionListener { + + /** The terminal screen. */ + private final JTextArea textArea = new JTextArea(25, 80); + + /** The textfield to enter commands. */ + private final JTextField command = new JTextField(); + + /** Button for clearing the terminal screen. */ + private final JButton clear = new JButton("clear"); + + /** Button for stopping the current process. */ + private final JButton stop = new JButton("stop"); + + /** ProcessBuilder for starting processes. */ + private final ProcessBuilder processBuilder = new ProcessBuilder().redirectErrorStream(true); + + /** Running shell process. */ + private ShellWorker worker; + + /** Create a ShellPane. */ + public ShellPane() { + setLayout(new BorderLayout()); + command.setForeground(Color.white); + command.setBackground(Color.black); + command.setFont(new Font(Font.MONOSPACED, textArea.getFont().getStyle(), textArea.getFont().getSize())); + textArea.setForeground(Color.white); + textArea.setBackground(Color.black); + textArea.setFont(new Font(Font.MONOSPACED, textArea.getFont().getStyle(), textArea.getFont().getSize())); + textArea.setEditable(false); + add(new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER); + add(command, BorderLayout.SOUTH); + add(clear, BorderLayout.NORTH); + add(stop, BorderLayout.EAST); + command.addActionListener(this); + clear.addActionListener(this); + stop.addActionListener(this); + } + + /** {@inheritDoc} */ + public void actionPerformed(final ActionEvent e) { + if (e.getSource() == command) { + processBuilder.command(parse(command.getText())); + worker = new ShellWorker(); + worker.execute(); + } + if (e.getSource() == clear) { + textArea.setText(""); + } + if (e.getSource() == stop) { + worker.stop(); + } + } + + /** Parses a command String into a list suitable for starting a process with arguments. + * @param text Command String to parse. + * @return List of command and arguments + */ + public List<String> parse(final String text) { + final List<String> strings = new ArrayList<String>(); + final StringBuilder sb = new StringBuilder(); + int state = 0; + for (final char c : text.toCharArray()) { + switch (state) { + case 0: + switch (c) { + case ' ': state = 0; break; + case '"': state = 2; break; + default: state = 1; sb.append(c); break; + } + break; + case 1: + switch (c) { + case ' ': state = 0; strings.add(sb.toString()); sb.setLength(0); break; + case '"': state = 2; break; + default: state = 1; sb.append(c); break; + } + break; + case 2: + switch (c) { + case '"': state = 1; break; + default: state = 2; sb.append(c); break; + } + break; + default: + assert false; + } + } + if (sb.length() != 0) { + strings.add(sb.toString()); + } + return strings; + } + + /** SwingWorker to run a process and read its output. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ + class ShellWorker extends SwingWorker<Object, String> { + + /** The process to run. */ + private Process p; + + /** {@inheritDoc} */ + @Override public Object doInBackground() { + final StringBuilder sb = new StringBuilder(); + try { + p = processBuilder.start(); + try { + final Reader in = new InputStreamReader(p.getInputStream()); + final char[] buf = new char[4096]; + for (int charsRead; !isCancelled() && (charsRead = in.read(buf)) != -1;) { + publish(new String(buf, 0, charsRead)); + } + } finally { + p.destroy(); + } + } catch (final Throwable e) { + publish(e.toString() + "\n"); + } + return null; + } + + /** {@inheritDoc} */ + @Override public void process(final List<String> chunks) { + for (final String s : chunks) { + textArea.append(s); + } + } + + /** Stop. */ + public void stop() { + if (p != null) { + p.destroy(); + } + cancel(true); + } + } +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/ShellPane.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/SimpleShell.java =================================================================== --- progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/SimpleShell.java (rev 0) +++ progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/SimpleShell.java 2009-05-21 12:47:00 UTC (rev 1298) @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2009 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +package net.sf.japi.progs.batcher; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JTabbedPane; + +/** SimpleShell example application. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @since 0.1 + */ +public class SimpleShell implements ActionListener { + + /** Main program of SimpleShell. + * @param args Command line arguments (ignored). + */ + public static void main(final String... args) { + new SimpleShell(); + } + + /** The tabs. */ + private final JTabbedPane tabs; + + /** Create a SimpleShell instance. */ + public SimpleShell() { + final JFrame frame = new JFrame("SimpleShell"); + tabs = new JTabbedPane(); + frame.getContentPane().add(tabs, BorderLayout.CENTER); + final JMenuBar menuBar = new JMenuBar(); + final JMenu file = new JMenu("File"); + menuBar.add(file); + final JMenuItem newFile = new JMenuItem("New"); + newFile.addActionListener(this); + file.add(newFile); + frame.setJMenuBar(menuBar); + frame.pack(); + frame.setVisible(true); + } + public void actionPerformed(final ActionEvent e) { + tabs.add(new ShellPane()); + } +} Property changes on: progs/batcher/trunk/src/prj/net/sf/japi/progs/batcher/SimpleShell.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. |