Thread: [Japi-cvs] SF.net SVN: japi: [307] tools/string2bytes/trunk/src
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2007-01-18 16:44:09
|
Revision: 307 http://svn.sourceforge.net/japi/?rev=307&view=rev Author: christianhujer Date: 2007-01-18 08:44:00 -0800 (Thu, 18 Jan 2007) Log Message: ----------- Started implementation of configurable codec steps. Added Paths: ----------- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecSelectionPanel.java tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStep.java tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStepsListModel.java tools/string2bytes/trunk/src/test/ tools/string2bytes/trunk/src/test/net/ tools/string2bytes/trunk/src/test/net/sf/ tools/string2bytes/trunk/src/test/net/sf/japi/ tools/string2bytes/trunk/src/test/net/sf/japi/string2bytes/ tools/string2bytes/trunk/src/test/net/sf/japi/string2bytes/CodecStepTest.java Added: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecSelectionPanel.java =================================================================== --- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecSelectionPanel.java (rev 0) +++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecSelectionPanel.java 2007-01-18 16:44:00 UTC (rev 307) @@ -0,0 +1,53 @@ +/* + * String2Bytes 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. + */ + +package net.sf.japi.string2bytes; + +import javax.swing.JPanel; +import javax.swing.JList; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; + +/** + * The CodecSelectionPanel allows the selection and configuration of one or more CodecSteps. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class CodecSelectionPanel extends JPanel { + + /** The list with the available codecs. */ + private JList availableCodecsList = new JList(); + + /** The list with the configured codec steps. */ + private JList configuredCodecSteps = new JList(); + + /** + * Creates a CodecSelectionPanel. + */ + public CodecSelectionPanel() { + super(new GridBagLayout()); + final GridBagConstraints gbc = new GridBagConstraints(); + add(new JLabel("Available Codec"), gbc); + add(new JLabel("Selected Codecs"), gbc); + add(new JScrollPane(availableCodecsList), gbc); + add(new JScrollPane(configuredCodecSteps), gbc); + } + +} // class CodecSelectionPanel Property changes on: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecSelectionPanel.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStep.java =================================================================== --- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStep.java (rev 0) +++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStep.java 2007-01-18 16:44:00 UTC (rev 307) @@ -0,0 +1,78 @@ +/* + * String2Bytes 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. + */ + +package net.sf.japi.string2bytes; + +import org.jetbrains.annotations.NotNull; + +/** + * A CodecStep represents a single configurable step for running a Codec with a specified Charset. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class CodecStep { + + /** The Charset to use for this CodecStep. */ + @NotNull private String charset; + + /** The Codec to run. */ + @NotNull private StringCodec codec; + + /** + * Create a CodecStep. + * @param codec The Codec to run. + * @param charset The Charset to use. + */ + public CodecStep(@NotNull final StringCodec codec, @NotNull final String charset) { + this.codec = codec; + this.charset = charset; + } + + /** + * Returns the charset to use for coding. + * @return The charset to use for coding. + */ + @NotNull public String getCharset() { + return charset; + } + + /** + * Sets the charset to use for coding. + * @param charset Charset to use for coding. + */ + public void setCharset(@NotNull String charset) { + this.charset = charset; + } + + /** + * Returns the codec to use for coding. + * @return The codec to use for coding. + */ + @NotNull public StringCodec getCodec() { + return codec; + } + + /** + * Sets the codec to use for coding. + * @param codec Codec to use for coding. + */ + public void setCodec(@NotNull StringCodec codec) { + this.codec = codec; + } + +} // class CodecStep Property changes on: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStep.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStepsListModel.java =================================================================== --- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStepsListModel.java (rev 0) +++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStepsListModel.java 2007-01-18 16:44:00 UTC (rev 307) @@ -0,0 +1,31 @@ +/* + * String2Bytes 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. + */ + +package net.sf.japi.string2bytes; + +import javax.swing.ListModel; +import javax.swing.JList; +import javax.swing.DefaultListModel; + +/** + * The CodecStepsListModel is a {@link ListModel} for listing {@link CodecStep}s in a {@link JList}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class CodecStepsListModel extends DefaultListModel { +} // class CodecStepsListModel Property changes on: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStepsListModel.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: tools/string2bytes/trunk/src/test/net/sf/japi/string2bytes/CodecStepTest.java =================================================================== --- tools/string2bytes/trunk/src/test/net/sf/japi/string2bytes/CodecStepTest.java (rev 0) +++ tools/string2bytes/trunk/src/test/net/sf/japi/string2bytes/CodecStepTest.java 2007-01-18 16:44:00 UTC (rev 307) @@ -0,0 +1,113 @@ +/* + * String2Bytes 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. + */ + +package test.net.sf.japi.string2bytes; + +import net.sf.japi.string2bytes.CodecStep; +import net.sf.japi.string2bytes.StringCodec; +import net.sf.japi.string2bytes.IdentityCodec; +import net.sf.japi.string2bytes.EntityCodec; +import org.junit.Test; +import org.junit.Assert; +import org.junit.Before; +import org.junit.After; + +/** + * Test for {@link CodecStep}. + * + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class CodecStepTest { + + /** The CodecStep to test. */ + private CodecStep codecStep; + + /** The Codec to use for most tests. */ + private StringCodec codec; + + /** The Charset to use for most tests. */ + private String charset; + + /** + * Creates the test data and a testling. + * @throws Exception (unexpected) + */ + @Before public void setUp() throws Exception { + codec = new IdentityCodec(); + charset = "utf-8"; + codecStep = new CodecStep(codec, charset); + } + + /** + * Removes the test data and the testling. + * @throws Exception (unexpected) + */ + @After public void tearDown() throws Exception { + codec = null; + charset = null; + codecStep = null; + } + + /** + * Tests whether {@link CodecStep#CodecStep(StringCodec, String)} works. + * @throws Exception (unexpected) + */ + @Test public void testCodecStep() throws Exception { + testGetCharset(); + testGetCodec(); + } + + + /** + * Tests whether {@link CodecStep#getCharset()} works. + * @throws Exception (unexpected) + */ + @Test public void testGetCharset() throws Exception { + Assert.assertEquals("Charset must be stored by constructor.", charset, codecStep.getCharset()); + } + + /** + * Tests whether {@link CodecStep#setCharset(String)} works. + * @throws Exception (unexpected) + */ + @Test public void testSetCharset() throws Exception { + final String charset = "iso-8859-1"; + codecStep.setCharset(charset); + Assert.assertEquals("Charset must be stored by setter.", charset, codecStep.getCharset()); + } + + /** + * Tests whether {@link CodecStep#getCodec()} works. + * @throws Exception (unexpected) + */ + @Test public void testGetCodec() throws Exception { + Assert.assertSame("Codec must be stored by constructor.", codec, codecStep.getCodec()); + } + + /** + * Tests whether {@link CodecStep#setCodec(StringCodec)} works. + * @throws Exception (unexpected) + */ + @Test public void testSetCodec() throws Exception { + final StringCodec codec = new EntityCodec(); + codecStep.setCodec(codec); + Assert.assertSame("Codec must be stored by setter.", codec, codecStep.getCodec()); + } + +} // class CodecStepTest \ No newline at end of file Property changes on: tools/string2bytes/trunk/src/test/net/sf/japi/string2bytes/CodecStepTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |