[Japi-cvs] SF.net SVN: japi: [322] tools/string2bytes/trunk/src/net/sf/japi/ string2bytes
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2007-01-30 20:51:30
|
Revision: 322
http://svn.sourceforge.net/japi/?rev=322&view=rev
Author: christianhujer
Date: 2007-01-30 12:51:18 -0800 (Tue, 30 Jan 2007)
Log Message:
-----------
Commit for preliminary support of configurable codecs. (Unfinnished)
Modified 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/net/sf/japi/string2bytes/EntityCodec.java
tools/string2bytes/trunk/src/net/sf/japi/string2bytes/IdentityCodec.java
tools/string2bytes/trunk/src/net/sf/japi/string2bytes/JavaBytesCodec.java
tools/string2bytes/trunk/src/net/sf/japi/string2bytes/StringCodec.java
tools/string2bytes/trunk/src/net/sf/japi/string2bytes/URLEncodeCodec.java
tools/string2bytes/trunk/src/net/sf/japi/string2bytes/action.properties
Added Paths:
-----------
tools/string2bytes/trunk/src/net/sf/japi/string2bytes/AbstractStringCodec.java
tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecListModel.java
tools/string2bytes/trunk/src/net/sf/japi/string2bytes/DoubleListController.java
tools/string2bytes/trunk/src/net/sf/japi/string2bytes/ListOrderController.java
Added: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/AbstractStringCodec.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/AbstractStringCodec.java (rev 0)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/AbstractStringCodec.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -0,0 +1,40 @@
+/*
+ * 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.Nullable;
+
+/**
+ * Base implementation for StringCodecs.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class AbstractStringCodec implements StringCodec {
+
+ /** {@inheritDoc} */
+ @Nullable public String getDisplayName() {
+ return getClass().getName();
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return getDisplayName();
+ }
+
+} // class AbstractStringCodec
Property changes on: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/AbstractStringCodec.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Added: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecListModel.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecListModel.java (rev 0)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecListModel.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -0,0 +1,52 @@
+/*
+ * 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.event.ListDataListener;
+
+/**
+ * ListModel for codecs.
+ * Immutable, holds all available codecs.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class CodecListModel implements ListModel {
+
+ /** {@inheritDoc} */
+ public int getSize() {
+ return StringCodec.ALL_CODECS.size();
+ }
+
+ /** {@inheritDoc} */
+ public Object getElementAt(final int i) {
+ return StringCodec.ALL_CODECS.get(i);
+ }
+
+ /** {@inheritDoc} */
+ public void addListDataListener(final ListDataListener listDataListener) {
+ // Because we don't fire events, we ignore listeners.
+ }
+
+ /** {@inheritDoc} */
+ public void removeListDataListener(final ListDataListener listDataListener) {
+ // Because we don't fire events, we ignore listeners.
+ }
+
+} // class CodecListModel
Property changes on: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecListModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Modified: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecSelectionPanel.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecSelectionPanel.java 2007-01-30 20:48:22 UTC (rev 321)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecSelectionPanel.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -23,20 +23,29 @@
import javax.swing.JList;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
+import javax.swing.DefaultListModel;
+import javax.swing.JFrame;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.ListSelectionEvent;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
+import net.sf.japi.swing.ActionFactory;
+import org.jetbrains.annotations.NotNull;
/**
* 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 {
+public class CodecSelectionPanel extends JPanel implements ListSelectionListener {
+ /** Action Factory. */
+ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.string2bytes");
+
/** The list with the available codecs. */
- private JList availableCodecsList = new JList();
+ private JList availableCodecsList = new JList(new CodecListModel());
/** The list with the configured codec steps. */
- private JList configuredCodecSteps = new JList();
+ private JList configuredCodecSteps = new JList(new CodecStepsListModel());
/**
* Creates a CodecSelectionPanel.
@@ -44,10 +53,25 @@
public CodecSelectionPanel() {
super(new GridBagLayout());
final GridBagConstraints gbc = new GridBagConstraints();
- add(new JLabel("Available Codec"), gbc);
- add(new JLabel("Selected Codecs"), gbc);
+ gbc.fill = GridBagConstraints.BOTH;
+ gbc.weightx = 1.0;
+ gbc.gridx = 1;
+ gbc.gridy = 1;
+ add(new JLabel(ACTION_FACTORY.getString("availableCodecs.label")), gbc);
+ gbc.gridx = 3;
+ add(new JLabel(ACTION_FACTORY.getString("selectedCodecs.label")), gbc);
+ gbc.gridx = 1;
+ gbc.weighty = 1.0;
+ gbc.gridy = 2;
add(new JScrollPane(availableCodecsList), gbc);
+ gbc.gridx = 3;
add(new JScrollPane(configuredCodecSteps), gbc);
+ gbc.weightx = 0.0;
+ gbc.gridx = 2;
+ add(new DoubleListController(availableCodecsList, configuredCodecSteps), gbc);
+ gbc.gridx = 4;
+ add(new ListOrderController((DefaultListModel) configuredCodecSteps.getModel(), configuredCodecSteps.getSelectionModel()), gbc);
+ configuredCodecSteps.addListSelectionListener(this);
}
/**
@@ -55,6 +79,15 @@
* @param args Command line arguments (ignored)
*/
public static void main(final String... args) {
+ JFrame f = new JFrame();
+ f.add(new CodecSelectionPanel());
+ f.pack();
+ f.setVisible(true);
}
+ /** {@inheritDoc} */
+ public void valueChanged(@NotNull final ListSelectionEvent listSelectionEvent) {
+ // TODO
+ }
+
} // class CodecSelectionPanel
Modified: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStep.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStep.java 2007-01-30 20:48:22 UTC (rev 321)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStep.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -75,4 +75,9 @@
this.codec = codec;
}
+ /** {@inheritDoc} */
+ public String toString() {
+ return codec + " [" + getCharset() + "]";
+ }
+
} // class CodecStep
Modified: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStepsListModel.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStepsListModel.java 2007-01-30 20:48:22 UTC (rev 321)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/CodecStepsListModel.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -28,4 +28,13 @@
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
public class CodecStepsListModel extends DefaultListModel {
+
+ /** {@inheritDoc} */
+ @Override public void insertElementAt(final Object object, final int i) {
+ if (!(object instanceof StringCodec)) {
+ throw new IllegalArgumentException(object + " not instanceof " + StringCodec.class);
+ }
+ super.insertElementAt(new CodecStep((StringCodec) object, "utf-8"), i);
+ }
+
} // class CodecStepsListModel
Added: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/DoubleListController.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/DoubleListController.java (rev 0)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/DoubleListController.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -0,0 +1,133 @@
+/*
+ * 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 java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import javax.swing.Action;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JList;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import net.sf.japi.swing.ActionFactory;
+import net.sf.japi.swing.ActionMethod;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * A Controller that controles two lists, offering to add or remove elements from the second list.
+ * Elements from the first list can be added to the second list based on the selection made in the first list.
+ * Elements from the second list can be removed from the second list based on the selection made in the second list.
+ * The first list, which is not modified by this controller, is called source list.
+ * The second list, which can be modified by this controller, is called target list.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class DoubleListController extends JComponent implements ListSelectionListener {
+
+ /** Action Factory. */
+ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.string2bytes");
+
+ /**
+ * The first list (source list) to operate on.
+ */
+ @NotNull private final JList sourceList;
+
+ /**
+ * The second list (target list) to operate on.
+ */
+ @NotNull private final JList targetList;
+
+ /**
+ * The Action for adding elements to the second (target) list based on the selection from the first list.
+ */
+ @NotNull private final Action add = ACTION_FACTORY.createAction(false, "add", this);
+
+ /**
+ * The Action for removing elements from the second (target) list.
+ */
+ @NotNull private final Action remove = ACTION_FACTORY.createAction(false, "remove", this);
+
+ /**
+ * Create a DoubleListController.
+ * @param sourceList First list to operate on (source list).
+ * @param targetList Second list to operate on (target list).
+ */
+ public DoubleListController(@NotNull final JList sourceList, @NotNull final JList targetList) {
+ this.sourceList = sourceList;
+ this.targetList = targetList;
+ setLayout(new GridBagLayout());
+ final GridBagConstraints gbc = new GridBagConstraints();
+ gbc.weighty = 1.0;
+ gbc.gridx = 1;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ gbc.insets = new Insets(5, 5, 5, 5);
+ gbc.anchor = GridBagConstraints.SOUTH;
+ gbc.gridy = 1;
+ add(new JButton(add), gbc);
+ gbc.anchor = GridBagConstraints.NORTH;
+ gbc.gridy = 2;
+ add(new JButton(remove), gbc);
+ sourceList.addListSelectionListener(this);
+ targetList.addListSelectionListener(this);
+ valueChanged(null);
+ }
+
+ /**
+ * Action for adding an element to the target list based on the selection from the source list.
+ */
+ @ActionMethod public void add() {
+ final int index = sourceList.getSelectionModel().getMinSelectionIndex();
+ if (index == -1) {
+ return;
+ }
+ final Object element = sourceList.getModel().getElementAt(index);
+ int targetIndex = targetList.getSelectionModel().getMaxSelectionIndex();
+ if (targetIndex == -1) {
+ targetIndex = targetList.getModel().getSize();
+ }
+ ((DefaultListModel) targetList.getModel()).insertElementAt(element, targetIndex);
+ }
+
+ /**
+ * Action for removing an element from the target list.
+ */
+ @ActionMethod public void remove() {
+ final int index = targetList.getSelectionModel().getMinSelectionIndex();
+ if (index == -1) {
+ return;
+ }
+ ((DefaultListModel) targetList.getModel()).remove(index);
+ }
+
+ /** {@inheritDoc} */
+ public void valueChanged(@Nullable final ListSelectionEvent listSelectionEvent) {
+ @Nullable final Object source = listSelectionEvent != null ? listSelectionEvent.getSource() : null;
+ if (source == null || source == sourceList || source == sourceList.getSelectionModel()) {
+ add.setEnabled(sourceList.getSelectionModel().getMinSelectionIndex() >= 0);
+ }
+ if (source == null || source == targetList || source == targetList.getSelectionModel()) {
+ remove.setEnabled(targetList.getSelectionModel().getMinSelectionIndex() >= 0);
+ }
+ }
+
+} // class DoubleListController
Property changes on: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/DoubleListController.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Modified: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/EntityCodec.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/EntityCodec.java 2007-01-30 20:48:22 UTC (rev 321)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/EntityCodec.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -23,15 +23,17 @@
import java.util.Formatter;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.NotNull;
/**
* A Codec which encodes a String by adding Entities.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public class EntityCodec implements StringCodec {
+public class EntityCodec extends AbstractStringCodec {
/** {@inheritDoc} */
- public String code(final String input, final String charsetName) throws UnsupportedEncodingException {
+ @NotNull public String code(@NotNull final String input, final String charsetName) throws UnsupportedEncodingException {
final Charset charset = Charset.forName(charsetName);
final CharsetEncoder encoder = charset.newEncoder();
final StringBuilder cooked = new StringBuilder();
@@ -47,4 +49,9 @@
return cooked.toString();
}
+ /** {@inheritDoc} */
+ @Nullable public String getDisplayName() {
+ return "XML entities";
+ }
+
} // class EntityCodec
Modified: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/IdentityCodec.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/IdentityCodec.java 2007-01-30 20:48:22 UTC (rev 321)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/IdentityCodec.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -20,16 +20,23 @@
package net.sf.japi.string2bytes;
import java.io.UnsupportedEncodingException;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.NotNull;
/**
* A Codec that doesn't perform any conversion.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public class IdentityCodec implements StringCodec {
+public class IdentityCodec extends AbstractStringCodec {
/** {@inheritDoc} */
- public String code(final String input, final String charsetName) throws UnsupportedEncodingException {
+ @NotNull public String code(@NotNull final String input, final String charsetName) throws UnsupportedEncodingException {
return input;
}
+ /** {@inheritDoc} */
+ @Nullable public String getDisplayName() {
+ return "Identity";
+ }
+
} // class IdentityCodec
Modified: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/JavaBytesCodec.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/JavaBytesCodec.java 2007-01-30 20:48:22 UTC (rev 321)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/JavaBytesCodec.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -21,15 +21,17 @@
import java.io.UnsupportedEncodingException;
import java.util.Formatter;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.NotNull;
/**
* A Codec which converts the input String into a suitable Java Array source code.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public class JavaBytesCodec implements StringCodec {
+public class JavaBytesCodec extends AbstractStringCodec {
/** {@inheritDoc} */
- public String code(final String input, final String charsetName) throws UnsupportedEncodingException {
+ @NotNull public String code(@NotNull final String input, final String charsetName) throws UnsupportedEncodingException {
final Formatter result = new Formatter();
result.format("{ ");
final byte[] bytes = input.getBytes(charsetName);
@@ -44,4 +46,9 @@
return result.toString();
}
+ /** {@inheritDoc} */
+ @Nullable public String getDisplayName() {
+ return "Java Bytes";
+ }
+
} // class JavaBytesCodec
Added: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/ListOrderController.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/ListOrderController.java (rev 0)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/ListOrderController.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -0,0 +1,260 @@
+/*
+ * 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 java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import javax.swing.Action;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JList;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import net.sf.japi.swing.ActionFactory;
+import net.sf.japi.swing.ActionMethod;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * A Control for changing the order of items in a {@link JList}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class ListOrderController extends JComponent implements ListSelectionListener {
+
+ /** Action Factory. */
+ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.string2bytes");
+
+ /**
+ * The JList to operate on.
+ * If <code>null</code>, this ListOrderController is currently disconnected.
+ */
+ @Nullable private DefaultListModel listModel;
+
+ /**
+ * The list selection model to operate on.
+ * If <code>null</code>, this ListOrderController is currently disconnected.
+ */
+ @Nullable private ListSelectionModel selectionModel;
+
+ /**
+ * Action for top.
+ */
+ @NotNull private final Action top = ACTION_FACTORY.createAction(false, "top", this);
+
+ /**
+ * Action for up.
+ */
+ @NotNull private final Action up = ACTION_FACTORY.createAction(false, "up", this);
+
+ /**
+ * Action for down.
+ */
+ @NotNull private final Action down = ACTION_FACTORY.createAction(false, "down", this);
+
+ /**
+ * Action for bottom.
+ */
+ @NotNull private final Action bottom = ACTION_FACTORY.createAction(false, "bottom", this);
+
+ /**
+ * Create a ListOrderController that's not yet connected to a list.
+ */
+ public ListOrderController() {
+ this(null, null);
+ }
+
+ /**
+ * Create a ListOrderController for a list.
+ * @param listModel List model to create ListOrderController for.
+ * @param selectionModel Selection model to create ListOrderController for.
+ */
+ public ListOrderController(@Nullable final DefaultListModel listModel, @Nullable final ListSelectionModel selectionModel) {
+ setLayout(new GridBagLayout());
+ setListAndSelectionModels(listModel, selectionModel);
+ final GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ gbc.insets = new Insets(5, 5, 5, 5);
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ gbc.anchor = GridBagConstraints.SOUTH;
+ gbc.weighty = 1.0;
+ add(new JButton(top), gbc);
+ gbc.anchor = GridBagConstraints.CENTER;
+ gbc.weighty = 0.0;
+ add(new JButton(up), gbc);
+ add(new JButton(down), gbc);
+ gbc.anchor = GridBagConstraints.NORTH;
+ gbc.weighty = 1.0;
+ add(new JButton(bottom), gbc);
+ }
+
+ /**
+ * Sets the list model to use.
+ * @param listModel The list model to use.
+ */
+ public void setListModel(@Nullable final DefaultListModel listModel) {
+ if (this.listModel == listModel) {
+ return;
+ }
+ this.listModel = listModel;
+ updateActions();
+ }
+
+ /**
+ * Returns the list model that's currently used.
+ * @return Currently used list model.
+ */
+ @Nullable public DefaultListModel getListModel() {
+ return listModel;
+ }
+
+ /**
+ * Sets the selection model to use.
+ * @param selectionModel The selection model to use.
+ */
+ public void setSelectionModel(@Nullable final ListSelectionModel selectionModel) {
+ if (this.selectionModel == selectionModel) {
+ return;
+ }
+ if (this.selectionModel != null) {
+ this.selectionModel.removeListSelectionListener(this);
+ }
+ this.selectionModel = selectionModel;
+ if (selectionModel != null) {
+ selectionModel.addListSelectionListener(this);
+ }
+ updateActions();
+ }
+
+ /**
+ * Returns the selection model that's currently used.
+ * @return Currently used selection model.
+ */
+ @Nullable public ListSelectionModel getSelectionModel() {
+ return selectionModel;
+ }
+
+ /**
+ * Sets the list and selection model to use.
+ * @param listModel The list model to use.
+ * @param selectionModel The selection model to use.
+ */
+ public void setListAndSelectionModels(@Nullable final DefaultListModel listModel, @Nullable final ListSelectionModel selectionModel) {
+ if (this.selectionModel == selectionModel && this.listModel == listModel) {
+ return;
+ }
+ this.listModel = listModel;
+ setSelectionModel(selectionModel);
+ }
+
+ /**
+ * Updates the enabled state of the actions.
+ * Use this in case all actions need to be updated.
+ */
+ private void updateActions() {
+ final boolean globalEnabled = listModel != null && selectionModel != null;
+ final int index = selectionModel != null ? selectionModel.getMinSelectionIndex() : -1;
+ final int maxIndex = listModel != null ? listModel.size() : -1;
+ top.setEnabled(globalEnabled && index > 0);
+ up.setEnabled(globalEnabled && index > 0);
+ down.setEnabled(globalEnabled && index != -1 && index < maxIndex - 1);
+ bottom.setEnabled(globalEnabled && index != -1 && index < maxIndex - 1);
+ }
+
+ /**
+ * Mode the currently selected entry to top.
+ */
+ @ActionMethod public void top() {
+ final ListSelectionModel tmpSelectionModel = selectionModel;
+ final DefaultListModel tmpListModel = listModel;
+ if (tmpSelectionModel == null || tmpListModel == null) {
+ return;
+ }
+ final int oldIndex = tmpSelectionModel.getMinSelectionIndex();
+ final int newIndex = 0;
+ if (oldIndex <= 0) {
+ return;
+ }
+ tmpListModel.insertElementAt(tmpListModel.remove(oldIndex), newIndex);
+ tmpSelectionModel.setSelectionInterval(newIndex, newIndex);
+ }
+
+ /**
+ * Move the currently selected entry up.
+ */
+ @ActionMethod public void up() {
+ final ListSelectionModel tmpSelectionModel = selectionModel;
+ final DefaultListModel tmpListModel = listModel;
+ if (tmpSelectionModel == null || tmpListModel == null) {
+ return;
+ }
+ final int oldIndex = tmpSelectionModel.getMinSelectionIndex();
+ final int newIndex = oldIndex - 1;
+ if (oldIndex <= 0) {
+ return;
+ }
+ tmpListModel.insertElementAt(tmpListModel.remove(oldIndex), newIndex);
+ tmpSelectionModel.setSelectionInterval(newIndex, newIndex);
+ }
+
+ /**
+ * Move the currently selected entry down.
+ */
+ @ActionMethod public void down() {
+ final ListSelectionModel tmpSelectionModel = selectionModel;
+ final DefaultListModel tmpListModel = listModel;
+ if (tmpSelectionModel == null || tmpListModel == null) {
+ return;
+ }
+ final int oldIndex = tmpSelectionModel.getMinSelectionIndex();
+ final int newIndex = oldIndex + 1;
+ if (oldIndex >= tmpListModel.size() - 1 || oldIndex < 0) {
+ return;
+ }
+ tmpListModel.insertElementAt(tmpListModel.remove(oldIndex), newIndex);
+ tmpSelectionModel.setSelectionInterval(newIndex, newIndex);
+ }
+
+ /**
+ * Move the currently selected entry to bottom.
+ */
+ @ActionMethod public void bottom() {
+ final ListSelectionModel tmpSelectionModel = selectionModel;
+ final DefaultListModel tmpListModel = listModel;
+ if (tmpSelectionModel == null || tmpListModel == null) {
+ return;
+ }
+ final int oldIndex = tmpSelectionModel.getMinSelectionIndex();
+ final int newIndex = tmpListModel.size() - 1;
+ if (oldIndex >= tmpListModel.size() - 1 || oldIndex < 0) {
+ return;
+ }
+ tmpListModel.insertElementAt(tmpListModel.remove(oldIndex), newIndex);
+ tmpSelectionModel.setSelectionInterval(newIndex, newIndex);
+ }
+
+ /** {@inheritDoc} */
+ public void valueChanged(@NotNull final ListSelectionEvent listSelectionEvent) {
+ updateActions();
+ }
+
+} // class ListOrderController
Property changes on: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/ListOrderController.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ LF
Modified: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/StringCodec.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/StringCodec.java 2007-01-30 20:48:22 UTC (rev 321)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/StringCodec.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -23,6 +23,8 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
/**
* A StringCodec is a class that can convert Strings into other Strings.
@@ -32,8 +34,9 @@
/**
* Unmodifiable list with all Codecs.
+ * @deprecated This will be replaced using a registry.
*/
- List<StringCodec> ALL_CODECS = Collections.unmodifiableList(Arrays.asList(new IdentityCodec(), new JavaBytesCodec(), new EntityCodec(), new URLEncodeCodec()));
+ @Deprecated List<? extends StringCodec> ALL_CODECS = Collections.unmodifiableList(Arrays.asList(new IdentityCodec(), new JavaBytesCodec(), new EntityCodec(), new URLEncodeCodec()));
/**
* Convert a String into another String.
@@ -42,6 +45,12 @@
* @return Converted String.
* @throws UnsupportedEncodingException In case the specified encoding is not supported.
*/
- String code(String input, String charsetName) throws UnsupportedEncodingException;
+ @NotNull String code(@NotNull String input, @Nullable String charsetName) throws UnsupportedEncodingException;
+ /**
+ * Returns a display name for this Codec.
+ * @return A display name for this Codec.
+ */
+ @Nullable String getDisplayName();
+
} // interface StringCodec
Modified: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/URLEncodeCodec.java
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/URLEncodeCodec.java 2007-01-30 20:48:22 UTC (rev 321)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/URLEncodeCodec.java 2007-01-30 20:51:18 UTC (rev 322)
@@ -21,17 +21,24 @@
import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.NotNull;
/**
* A Codec which converts a String into a URLEncoded String.
* @note When using this Codec, using UTF-8 is strongly recommended.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-public class URLEncodeCodec implements StringCodec {
+public class URLEncodeCodec extends AbstractStringCodec {
/** {@inheritDoc} */
- public String code(String input, String charsetName) throws UnsupportedEncodingException {
+ @NotNull public String code(@NotNull final String input, final String charsetName) throws UnsupportedEncodingException {
return URLEncoder.encode(input, charsetName);
}
+ /** {@inheritDoc} */
+ @Nullable public String getDisplayName() {
+ return "URLEncode";
+ }
+
} // clsas URLEncodeCodec
Modified: tools/string2bytes/trunk/src/net/sf/japi/string2bytes/action.properties
===================================================================
--- tools/string2bytes/trunk/src/net/sf/japi/string2bytes/action.properties 2007-01-30 20:48:22 UTC (rev 321)
+++ tools/string2bytes/trunk/src/net/sf/japi/string2bytes/action.properties 2007-01-30 20:51:18 UTC (rev 322)
@@ -70,4 +70,15 @@
license.1.title=String2Bytes
license.1.file=COPYING
license.2.title=japi-libs
-license.2.file=LICENSE-japi-libs
\ No newline at end of file
+license.2.file=LICENSE-japi-libs
+
+availableCodecs.label=Available Codecs
+selectedCodecs.label=Selected Codecs
+
+up.text=Up
+down.text=Down
+top.text=Top
+bottom.text=Bottom
+
+add.text=Add ->
+remove.text=<- Remove
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|