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...> - 2006-10-14 12:43:03
|
Revision: 183 http://svn.sourceforge.net/japi/?rev=183&view=rev Author: christianhujer Date: 2006-10-14 05:42:28 -0700 (Sat, 14 Oct 2006) Log Message: ----------- Copied keyboard preferences classes from historic to swing-keyprefs subproject. Added Paths: ----------- libs/swing-keyprefs/trunk/src/ libs/swing-keyprefs/trunk/src/net/ libs/swing-keyprefs/trunk/src/net/sf/ libs/swing-keyprefs/trunk/src/net/sf/japi/ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/AbstractSimpleNode.java libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionKeyDisplay.java libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionMapNode.java libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionNode.java libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokePrefs.java libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokeRootNode.java libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokeTreeTableModel.java libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/SimpleNode.java libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/action.properties libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/package.html Copied: libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/AbstractSimpleNode.java (from rev 181, historic/trunk/src/app/net/sf/japi/swing/prefs/keys/AbstractSimpleNode.java) =================================================================== --- libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/AbstractSimpleNode.java (rev 0) +++ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/AbstractSimpleNode.java 2006-10-14 12:42:28 UTC (rev 183) @@ -0,0 +1,67 @@ +/* JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2004-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 net.sf.japi.swing.prefs.keys; + +import org.jetbrains.annotations.Nullable; + +/** Base class for simple nodes. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public abstract class AbstractSimpleNode<C> implements SimpleNode<C> { + + /** The Children. */ + @Nullable private final C[] children; + + /** The number of children. */ + private final int length; + + /** Create an AbstractSimpleNode. + * @param children + */ + protected AbstractSimpleNode(@Nullable final C[] children) { + if (children != null) { + this.children = children.clone(); + assert this.children != null; + length = this.children.length; + } else { + this.children = null; + length = 0; + } + } + + /** {@inheritDoc} */ + @Nullable public final C getChild(final int index) { + if (children == null) { + return null; + } + try { + return children[index]; + } catch (final ArrayIndexOutOfBoundsException e) { + return null; + } + } + + /** {@inheritDoc} */ + public final int getChildCount() { + return length; + } + +} // class AbstractSimpleNode Copied: libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionKeyDisplay.java (from rev 181, historic/trunk/src/app/net/sf/japi/swing/prefs/keys/ActionKeyDisplay.java) =================================================================== --- libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionKeyDisplay.java (rev 0) +++ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionKeyDisplay.java 2006-10-14 12:42:28 UTC (rev 183) @@ -0,0 +1,184 @@ +/* JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2004-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 net.sf.japi.swing.prefs.keys; + +import java.awt.FlowLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import javax.swing.JComponent; +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JRadioButton; +import javax.swing.JButton; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.KeyStroke; +import javax.swing.border.LineBorder; +import org.jetbrains.annotations.Nullable; +import net.sf.japi.swing.ActionFactory; + +/** A component for displaying the accellerators of an Action. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +// This class is only public to get the action methods working. +public class ActionKeyDisplay extends JComponent { + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.swing.prefs.keys"); + + /** The action of the button that displays the keystroke and allows changing it. */ + private final ActionKeyAction actionKeyAction = new ActionKeyAction(this); + + /** The action that is currently handled. */ + @Nullable private Action action; + + /** The radio actions. */ + private final Action[] radioActions = ACTION_FACTORY.createActions(true, this, "keystrokeNone", "keystrokeStandard", "keystrokeUserdefined"); + + /** Create an ActionKeyDisplay. */ + public ActionKeyDisplay() { + final JButton keyboardButton = new JButton(actionKeyAction); + setBorder(BorderFactory.createTitledBorder(ACTION_FACTORY.getString("keystroke.border.title"))); + setLayout(new FlowLayout(FlowLayout.LEADING)); + final ButtonGroup bg = new ButtonGroup(); + for (final Action radioAction : radioActions) { + final JRadioButton button = new JRadioButton(radioAction); + add(button); + bg.add(button); + } + keyboardButton.setBorder(new LineBorder(Color.BLACK, 4, true)); + keyboardButton.setPreferredSize(new Dimension(140, 30)); + keyboardButton.setText("ctrl alt shift pressed N"); + add(keyboardButton); + actionKeyAction.setAction(ACTION_FACTORY.createAction(true, "save")); + setEnabled(false); + } + + /** {@inheritDoc} */ + @Override public void setEnabled(final boolean enabled) { + super.setEnabled(enabled); + actionKeyAction.setEnabled(enabled); + for (final Action radioAction : radioActions) { + radioAction.setEnabled(enabled); + } + } + + /** Action method for using no keystroke. */ + public void keystrokeNone() { + actionKeyAction.setEnabled(false); + } + + /** Action method for using standard keystroke. */ + public void keystrokeStandard() { + actionKeyAction.setEnabled(false); + } + + /** Action method for using a user defined keystroke. */ + public void keystrokeUserdefined() { + actionKeyAction.setEnabled(true); + } + + /** Returns the action that is currently handled. + * @return the action that is currently handled + */ + public Action getAction() { + return action; + } + + /** Sets the action that is currently handled. + * @param action the action that is currently handled + */ + public void setAction(@Nullable final Action action) { + this.action = action; + actionKeyAction.setAction(action); + } + +} // class KeyChooser + +class ActionKeyAction extends AbstractAction { + + /** The Action to be displayed. */ + private Action action; + + private final Component parent; + + ActionKeyAction(final Component parent) { + this.parent = parent; + } + + /** {@inheritDoc} */ + public void actionPerformed(final ActionEvent e) { + //TODO + } + + /** Set the Action to be displayed. + * @param action Action to be displayed and changed + */ + public void setAction(@Nullable final Action action) { + this.action = action; + putValue(Action.NAME, getLocalizedKeyStrokeText(action)); + setEnabled(action != null); + } + + /** Get the localized text of the keystroke of an Action. + * @param action Action to get text for + * @return localized text for the accelerator of <var>action</var> + * @retval "" if <var>action</var> == null + * @retval "" if the accelerator of <var>action</var> == null + * @retval String containing localized text for the accelerator of <var>action</var> + * @throws ClassCastException in case the bound accelerator property is not a {@link KeyStroke} + */ + public static String getLocalizedKeyStrokeText(final Action action) { + if (action == null) { + return ""; + } + return getLocalizedKeyStrokeText((KeyStroke) action.getValue(Action.ACCELERATOR_KEY)); + } + + /** Get the localized text of a KeyStroke. + * @param keyStroke KeyStroke to get text for + * @return localized text for the accelerator of <var>action</var> + * @retval "" if <var>keyStroke</var> == null + * @retval String containing localized text for <var>keyStroke</var> + */ + public static String getLocalizedKeyStrokeText(final KeyStroke keyStroke) { + if (keyStroke == null) { + return ""; + } + final StringBuilder newName = new StringBuilder(); + final int modifiers = keyStroke.getModifiers(); + if (modifiers != 0) { + newName.append(KeyEvent.getKeyModifiersText(modifiers)); + newName.append('+'); + } + final int keyCode = keyStroke.getKeyCode(); + if (keyCode == 0) { + newName.append(keyStroke.getKeyChar()); + } else { + newName.append(KeyEvent.getKeyText(keyCode)); + } + return newName.toString(); + } + +} // class ActionKeyAction Copied: libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionMapNode.java (from rev 181, historic/trunk/src/app/net/sf/japi/swing/prefs/keys/ActionMapNode.java) =================================================================== --- libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionMapNode.java (rev 0) +++ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionMapNode.java 2006-10-14 12:42:28 UTC (rev 183) @@ -0,0 +1,71 @@ +/* JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2004-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 net.sf.japi.swing.prefs.keys; + +import java.util.Arrays; +import javax.swing.ActionMap; +import net.sf.japi.swing.NamedActionMap; + +/** Node object for an ActionMap. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +class ActionMapNode extends AbstractSimpleNode<ActionNode> { + + /** The ActionMap. */ + private final ActionMap actionMap; + + /** Create an ActionMapNode. + * @param actionMap ActionMap + */ + ActionMapNode(final ActionMap actionMap) { + super(createChildren(actionMap)); + this.actionMap = actionMap; + } + + /** Create the children from ActionFactories. + * @param actionMap ActionMap + * @return children + */ + @SuppressWarnings({"ObjectAllocationInLoop"}) + private static ActionNode[] createChildren(final ActionMap actionMap) { + final ActionNode[] children = new ActionNode[actionMap.size()]; + final Object[] allKeys = actionMap.allKeys(); + Arrays.sort(allKeys); + for (int i = 0; i < children.length; i++) { + children[i] = new ActionNode(actionMap.get(allKeys[i])); + } + return children; + } + + /** {@inheritDoc} */ + @Override public String toString() { + //noinspection ObjectToString + return actionMap instanceof NamedActionMap ? + ((NamedActionMap) actionMap).getName() : + actionMap.toString(); + } + + /** {@inheritDoc} */ + public Object getValueAt(final int column) { + return null; //TODO + } + +} // class ActionMapNode Copied: libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionNode.java (from rev 181, historic/trunk/src/app/net/sf/japi/swing/prefs/keys/ActionNode.java) =================================================================== --- libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionNode.java (rev 0) +++ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/ActionNode.java 2006-10-14 12:42:28 UTC (rev 183) @@ -0,0 +1,72 @@ +/* JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2004-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 net.sf.japi.swing.prefs.keys; + +import javax.swing.Action; +import org.jetbrains.annotations.Nullable; + +/** Node object for an Action. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +class ActionNode extends AbstractSimpleNode<SimpleNode> { + + /** The action of this node. */ + private final Action action; + + /** Create an ActionNode. + * @param action Action for this node. + */ + ActionNode(final Action action) { + super(null); + this.action = action; + } + + /** Returns the action of this node. + * @return the action of this node + */ + public Action getAction() { + return action; + } + + /** {@inheritDoc} */ + @Override public boolean equals(final Object obj) { + return obj instanceof ActionNode && ((ActionNode) obj).action == action; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return action.hashCode(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return String.valueOf(action.getValue(Action.NAME)); + } + + /** {@inheritDoc} */ + @Nullable public Object getValueAt(final int column) { + switch (column) { + case 1: return ActionKeyAction.getLocalizedKeyStrokeText(action); + default: return null; + } + } + +} // class ActionNode Copied: libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokePrefs.java (from rev 181, historic/trunk/src/app/net/sf/japi/swing/prefs/keys/KeyStrokePrefs.java) =================================================================== --- libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokePrefs.java (rev 0) +++ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokePrefs.java 2006-10-14 12:42:28 UTC (rev 183) @@ -0,0 +1,107 @@ +/* JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2004-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 net.sf.japi.swing.prefs.keys; + +import java.awt.BorderLayout; +import static java.util.Arrays.asList; +import java.util.List; +import javax.swing.JScrollPane; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import net.sf.japi.swing.ActionFactory; +import net.sf.japi.swing.prefs.AbstractPrefs; +import net.sf.japi.swing.treetable.JTreeTable; + +/** Prefs implementation for configuring keystrokes of one or more {@link ActionFactory ActionFactories}. + * TODO + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class KeyStrokePrefs extends AbstractPrefs implements ListSelectionListener { + + /** Action Factory. */ + private static final ActionFactory ACTION_FACOTRY = ActionFactory.getFactory("net.sf.japi.swing.prefs.keys"); + + /** The ActionKeyDisplay. */ + private final ActionKeyDisplay actionKeyDisplay; + + /** The table. */ + private final JTreeTable<KeyStrokeRootNode, AbstractSimpleNode<AbstractSimpleNode>> table; + + /** Create KeyStrokePrefs for a list of ActionFactories. + * @param actionFactories ActionFactories + */ + public KeyStrokePrefs(final ActionFactory... actionFactories) { + setListLabelText(ACTION_FACOTRY.getString("prefs.listLabelText")); + setLabelText(ACTION_FACOTRY.getString("prefs.labelText")); + final List<ActionFactory> factories = asList(actionFactories); + setLayout(new BorderLayout()); + table = new JTreeTable<KeyStrokeRootNode, AbstractSimpleNode<AbstractSimpleNode>>(new KeyStrokeTreeTableModel(factories)); + add(new JScrollPane(table)); + table.getSelectionModel().addListSelectionListener(this); + actionKeyDisplay = new ActionKeyDisplay(); + add(actionKeyDisplay, BorderLayout.SOUTH); + } + + /** Create KeyStrokePrefs for a list of named ActionFactories. + * @param factoryNames names of ActionFactories + */ + public KeyStrokePrefs(final String... factoryNames) { + this(getFactoriesForNames(factoryNames)); + } + + private static ActionFactory[] getFactoriesForNames(final String[] factoryNames) { + final ActionFactory[] factories = new ActionFactory[factoryNames.length]; + for (int i = 0; i < factoryNames.length; i++) { + factories[i] = ActionFactory.getFactory(factoryNames[i]); + } + return factories; + } + + /** {@inheritDoc} */ + public boolean isChanged() { + return false; //TODO + } + + /** {@inheritDoc} */ + public void defaults() { + //TODO + } + + /** {@inheritDoc} */ + public void revert() { + //TODO + } + + /** {@inheritDoc} */ + public void apply() { + //TODO + } + + /** {@inheritDoc} */ + public void valueChanged(final ListSelectionEvent e) { + if (table.getSelectedRow() == -1) { + actionKeyDisplay.setAction(null); + } else { + System.err.println(table.getTreeTableModel().getValueAt(null, table.getSelectedRow())); + } + } + +} // class KeyStrokePrefs Copied: libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokeRootNode.java (from rev 181, historic/trunk/src/app/net/sf/japi/swing/prefs/keys/KeyStrokeRootNode.java) =================================================================== --- libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokeRootNode.java (rev 0) +++ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokeRootNode.java 2006-10-14 12:42:28 UTC (rev 183) @@ -0,0 +1,57 @@ +/* JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2004-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 net.sf.japi.swing.prefs.keys; + +import java.util.List; +import net.sf.japi.swing.ActionFactory; + +/** + * TODO + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class KeyStrokeRootNode extends AbstractSimpleNode<ActionMapNode> { + + /** Create a KeyStrokeRootNode. + * @param factories ActionFactories + */ + public KeyStrokeRootNode(final List<ActionFactory> factories) { + super(createChildren(factories)); + } + + /** Create the children from ActionFactories. + * @param factories ActionFactories + * @return children + */ + @SuppressWarnings({"ObjectAllocationInLoop"}) + private static ActionMapNode[] createChildren(final List<ActionFactory> factories) { + final ActionMapNode[] children = new ActionMapNode[factories.size()]; + for (int i = 0; i < children.length; i++) { + children[i] = new ActionMapNode(factories.get(i).getActionMap()); + } + return children; + } + + /** {@inheritDoc} */ + public Object getValueAt(final int column) { + return null; //TODO + } + +} // class KeyStrokeRootNode Copied: libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokeTreeTableModel.java (from rev 181, historic/trunk/src/app/net/sf/japi/swing/prefs/keys/KeyStrokeTreeTableModel.java) =================================================================== --- libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokeTreeTableModel.java (rev 0) +++ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/KeyStrokeTreeTableModel.java 2006-10-14 12:42:28 UTC (rev 183) @@ -0,0 +1,79 @@ +/* JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2004-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 net.sf.japi.swing.prefs.keys; + +import java.util.List; +import net.sf.japi.swing.ActionFactory; +import net.sf.japi.swing.treetable.AbstractTreeTableModel; +import net.sf.japi.swing.treetable.TreeTableModel; + +/** + * TODO + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class KeyStrokeTreeTableModel extends AbstractTreeTableModel<KeyStrokeRootNode, AbstractSimpleNode<AbstractSimpleNode>> { + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.japi.swing.prefs.keys"); + + /** Column names. */ + private static final String[] COLUMN_NAMES = { + ACTION_FACTORY.getString("keystroke.table.column.action.title"), + ACTION_FACTORY.getString("keystroke.table.column.keystroke.title"), + }; + + /** Create a KeyStrokeTreeTableModel. */ + public KeyStrokeTreeTableModel(final List<ActionFactory> factories) { + super(new KeyStrokeRootNode(factories)); + } + + /** {@inheritDoc} */ + public AbstractSimpleNode<AbstractSimpleNode> getChild(final AbstractSimpleNode<AbstractSimpleNode> parent, final int index) { + //noinspection unchecked + return (AbstractSimpleNode<AbstractSimpleNode>) parent.getChild(index); + } + + /** {@inheritDoc} */ + public int getChildCount(final AbstractSimpleNode<AbstractSimpleNode> node) { + return node.getChildCount(); + } + + /** {@inheritDoc} */ + public int getColumnCount() { + return 2; + } + + /** {@inheritDoc} */ + public String getColumnName(final int column) { + return COLUMN_NAMES[column]; + } + + /** {@inheritDoc} */ + public Object getValueAt(final AbstractSimpleNode<AbstractSimpleNode> node, final int column) { + return node != null ? node.getValueAt(column) : null; + } + + /** {@inheritDoc} */ + @Override public Class<?> getColumnClass(final int column) { + return new Class[] { TreeTableModel.class, String.class}[column]; + } + +} // class KeyStrokeTreeTableModel Copied: libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/SimpleNode.java (from rev 181, historic/trunk/src/app/net/sf/japi/swing/prefs/keys/SimpleNode.java) =================================================================== --- libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/SimpleNode.java (rev 0) +++ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/SimpleNode.java 2006-10-14 12:42:28 UTC (rev 183) @@ -0,0 +1,47 @@ +/* JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2004-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 net.sf.japi.swing.prefs.keys; + +import org.jetbrains.annotations.Nullable; + +/** Interface for simple nodes. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +interface SimpleNode<C> { + + /** Gets a child with a specific index. + * @param index Index of desired child + * @return child with index or <code>null</code> if no such child. + */ + @Nullable C getChild(int index); + + /** Get the number of children. + * @return number of children + */ + int getChildCount(); + + /** Get the value of this node at a certain value index. + * @param column Index of desired value + * @return value at index + */ + Object getValueAt(int column); + +} // interface SimpleNode Copied: libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/action.properties (from rev 181, historic/trunk/src/app/net/sf/japi/swing/prefs/keys/action.properties) =================================================================== --- libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/action.properties (rev 0) +++ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/action.properties 2006-10-14 12:42:28 UTC (rev 183) @@ -0,0 +1,11 @@ +save.text=Save +save.accel=ctrl pressed S + +prefs.labelText=Configure keyboard shortcuts +prefs.listLabelText=Keymap +keystroke.table.column.action.title=Action +keystroke.table.column.keystroke.title=Keystroke +keystroke.border.title=Keystroke for the chosen action +keystrokeNone.text=None +keystrokeStandard.text=Standard +keystrokeUserdefined.text=Userdefined \ No newline at end of file Copied: libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/package.html (from rev 181, historic/trunk/src/app/net/sf/japi/swing/prefs/keys/package.html) =================================================================== --- libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/package.html (rev 0) +++ libs/swing-keyprefs/trunk/src/net/sf/japi/swing/prefs/keys/package.html 2006-10-14 12:42:28 UTC (rev 183) @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. + --> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de"> + <head> + <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> + <meta name="Date" content="$Date: 2006-04-03 23:00:14 +0200 (Mon, 03 Apr 2006) $" /> + <title>net.sf.japi.swing.prefs.keys</title> + </head> + <body> + <p> + Keyboard preferences. + </p> + </body> +</html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-09 21:41:32
|
Revision: 182 http://svn.sourceforge.net/japi/?rev=182&view=rev Author: christianhujer Date: 2006-10-09 14:41:23 -0700 (Mon, 09 Oct 2006) Log Message: ----------- Added common directory. Added Paths: ----------- common/ common/branches/ common/tags/ common/trunk/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-09 21:25:57
|
Revision: 181 http://svn.sourceforge.net/japi/?rev=181&view=rev Author: christianhujer Date: 2006-10-09 14:25:47 -0700 (Mon, 09 Oct 2006) Log Message: ----------- Added structure for util library. Added Paths: ----------- libs/util/ libs/util/branches/ libs/util/tags/ libs/util/trunk/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-10-06 19:15:04
|
Revision: 180 http://svn.sourceforge.net/japi/?rev=180&view=rev Author: christianhujer Date: 2006-10-06 12:14:48 -0700 (Fri, 06 Oct 2006) Log Message: ----------- Added build.xml Added Paths: ----------- libs/argparser/trunk/build.xml Added: libs/argparser/trunk/build.xml =================================================================== --- libs/argparser/trunk/build.xml (rev 0) +++ libs/argparser/trunk/build.xml 2006-10-06 19:14:48 UTC (rev 180) @@ -0,0 +1,149 @@ +<?xml version="1.0" encoding="utf-8"?> +<project name="japi lib argparser" default="compile"> + <property name="module.version" value="0.1" /> + <property name="module.name" value="japi-lib-argparser" /> + <taskdef name="pack200" classpath="lib/Pack200Task.jar" classname="com.sun.tools.apache.ant.pack200.Pack200Task" /> + <target name="compile"> + <mkdir dir="classes/production/argparser" /> + <mkdir dir="classes/test/argparser" /> + <javac + srcdir="src" + destdir="classes" + encoding="utf-8" + source="1.5" + target="1.5" + > + <classpath> + <fileset dir="lib" includes="*.jar" /> + </classpath> + </javac> + </target> + <target + name = "dist" + description = "Packs distribution archives."> + <!--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" excludes="production/**,test/**"/> + <manifest> + <attribute name="Implementation-Title" value="JAPI" /> + <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 = "apiDoc" + description = "Creates public javadoc documentation." + > + <mkdir dir="dest/doc/api/${module.version}" /> + <!--copy todir="dest/doc/api/${module.version}" file="src/doc/api/public/copyright.html" /> + <copy todir="dest/doc/api/${module.version}" file="src/doc/api/public/.htaccess" /--> + <javadoc + destdir = "dest/doc/api/${module.version}" + access = "protected" + author = "yes" + version = "yes" + locale = "en_US" + use = "yes" + splitindex = "yes" + windowtitle = "JAPI Library ArgParser ${module.version} API documentation" + doctitle = "JAPI<br />Yet another Java API<br />Library ArgParser ${module.version} API documentation" + header = "JAPI Library ArgParser ${module.version}<br />API Documentation" + footer = "JAPI<br />Yet another Java API<br />Library ArgParser ${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" /> + </sourcepath> + <packageset + dir="src" + 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:" /> + <tag enabled="true" name="fixme" description="Fixme:" /> + <tag enabled="true" name="xxx" description="XXX:" /> + </javadoc> + </target> +</project> Property changes on: libs/argparser/trunk/build.xml ___________________________________________________________________ Name: svn:mime-type + text/xml Name: 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...> - 2006-10-03 23:32:18
|
Revision: 179 http://svn.sourceforge.net/japi/?rev=179&view=rev Author: christianhujer Date: 2006-10-03 16:31:53 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Adding new feature: BasicCommand which handles --help and --version, i18n/l10n for --help output. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java libs/argparser/trunk/src/net/sf/japi/io/args/Command.java libs/argparser/trunk/src/net/sf/japi/io/args/Option.java libs/argparser/trunk/src/net/sf/japi/io/args/OptionType.java libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Added Paths: ----------- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties libs/argparser/trunk/src/net/sf/japi/io/args/messages_de.properties Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-25 22:42:46 UTC (rev 178) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-10-03 23:31:53 UTC (rev 179) @@ -28,10 +28,11 @@ /** * Parser for command line arguments. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * TODO: automatic argument conversion for option method invokation. + * TODO: automatic argument conversion for option method invocation. * TODO: Handling of --help * TODO: Handling of --version - * TODO: Handling of - for STDIN as input argument filestrea + * TODO: Handling of - for STDIN as input argument filestream + * TODO: Support for I18N/L10N */ public class ArgParser { @@ -83,7 +84,7 @@ for (final Method requiredMethod : requiredMethods) { final Option option = requiredMethod.getAnnotation(Option.class); assert option != null; - missingOptions.add(option.name()[0]); + missingOptions.add(option.names()[0]); } throw new RequiredOptionsMissingException(missingOptions.toArray(new String[missingOptions.size()])); } @@ -95,24 +96,48 @@ * All required methods are additionally stored in {@link #requiredMethods}. */ private void initMethods() { - for (final Method method : commandClass.getMethods()) { + for (final Method method : getOptionMethods(commandClass)) { final Option option = method.getAnnotation(Option.class); - if (option != null) { - for (final String optionName : option.name()) { - if (argumentMethods.containsKey(optionName)) { - throw new IllegalArgumentException(commandClass.getName() + " declared option " + optionName + " twice."); - } - argumentMethods.put(optionName, method); + assert option != null; + for (final String optionName : option.names()) { + if (argumentMethods.containsKey(optionName)) { + throw new IllegalArgumentException(commandClass.getName() + " declared option " + optionName + " twice."); } - final OptionType type = option.type(); - if (type == OptionType.REQUIRED) { - requiredMethods.add(method); - } + argumentMethods.put(optionName, method); } + final OptionType type = option.type(); + if (type == OptionType.REQUIRED) { + requiredMethods.add(method); + } } } /** + * Get all option methods from a command. + * @param command Command to get option methods for + * @return option methods for the command. + */ + public static Set<Method> getOptionMethods(final Command command) { + return getOptionMethods(command.getClass()); + } + + /** + * Get all option methods from a command class. + * @param commandClass Class of the Command to get option methods for + * @return Option methods for the command class. + */ + public static Set<Method> getOptionMethods(final Class<? extends Command> commandClass) { + final Method[] methods = commandClass.getMethods(); + final Set<Method> optionMethods = new HashSet<Method>(); + for (final Method method : methods) { + if (method.isAnnotationPresent(Option.class)) { + optionMethods.add(method); + } + } + return optionMethods; + } + + /** * Parses arguments into an arguments container and invokes the Command's {@link Command#run(List<String>)} method. * @throws TerminalException in case argument parsing was stopped */ Added: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-10-03 23:31:53 UTC (rev 179) @@ -0,0 +1,100 @@ +package net.sf.japi.io.args; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Formatter; +import java.util.HashSet; +import java.util.List; +import java.util.MissingResourceException; +import java.util.ResourceBundle; +import java.util.Set; + +/** + * BasicCommand is a base class for commands that provides the options --help and --version. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public abstract class BasicCommand implements Command { + + /** The ResourceBundle for locale-specific output. */ + private final ResourceBundle resourceBundle = ResourceBundle.getBundle("net.sf.japi.io.args.messages"); + + /** The maximum width of the option type field. */ + private final int maxOptionTypeWidth; + + /** Create a BasicCommand. */ + protected BasicCommand() { + int tmpMaxOptionTypeWidth = 0; + for (final OptionType optionType : OptionType.values()) { + tmpMaxOptionTypeWidth = Math.max(tmpMaxOptionTypeWidth, optionType.toString().length()); + } + maxOptionTypeWidth = tmpMaxOptionTypeWidth; + } + + /** Version Option. */ + @Option(type = OptionType.TERMINAL, names = {"v", "version"}) + public void version() { + // TODO + } + + /** Help Option. */ + @Option(type = OptionType.TERMINAL, names = {"h", "help"}) + public void help() { + final Set<Method> optionMethods = ArgParser.getOptionMethods(this); + final Set<Class<?>> parameterTypes = new HashSet<Class<?>>(); + int maxLong = 0; + int maxShort = 0; + for (final Method optionMethod : optionMethods) { + final Option option = optionMethod.getAnnotation(Option.class); + final String[] names = option.names(); + int currentLong = 0; + int currentShort = 0; + for (final String name : names) { + if (name.length() > 1) { + currentLong += name.length() + ", --".length(); + } else { + currentShort += name.length() + ", -".length(); + } + } + maxLong = Math.max(maxLong, currentLong - ", ".length()); + maxShort = Math.max(maxShort, currentShort - ", ".length()); + for (final Class<?> parameterType : optionMethod.getParameterTypes()) { + parameterTypes.add(parameterType); + } + } + final String formatString = "%-" + maxShort + "s%s%-" + maxLong + "s: (%-" + maxOptionTypeWidth + "s) %s%n"; + final Formatter format = new Formatter(System.err); + for (final Method optionMethod : optionMethods) { + final Option option = optionMethod.getAnnotation(Option.class); + final OptionType optionType = option.type(); + final String[] names = option.names(); + final List<String> shortNames = new ArrayList<String>(); + final List<String> longNames = new ArrayList<String>(); + for (final String name : names) { + if (name.length() > 1) { + longNames.add("--" + name); + } else { + shortNames.add("-" + name); + } + } + final String delim = shortNames.size() > 0 && longNames.size() > 0 ? ", " : " "; + String description; + try { + final String optionKey = option.key().equals("") ? optionMethod.getName() : option.key(); + description = getBundle().getString(optionKey); + } catch (final MissingResourceException ignore) { + description = ""; + } + format.format(formatString, StringJoiner.join(", ", shortNames), delim, StringJoiner.join(", ", longNames), optionType.toString(), description); + } + format.flush(); + } + + /** + * Get the ResourceBundle for the default locale. + * If you override this method be sure to declare the bundle returned by the overridden method as parent of your bundle. + */ + public ResourceBundle getBundle() { + return resourceBundle; + } + +} // class BasicCommand Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Command.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-09-25 22:42:46 UTC (rev 178) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-10-03 23:31:53 UTC (rev 179) @@ -22,6 +22,7 @@ package net.sf.japi.io.args; import java.util.List; +import org.jetbrains.annotations.NotNull; /** * Shell commands can implement this interface and make use of ArgParser. @@ -30,11 +31,11 @@ public interface Command { /** - * Run the command. + * Run this command. * This method is invoked by {@link ArgParser} once it is finnished with parsing the arguments. * @param args the argument strings that were not parsed away by {@link ArgParser}. */ @SuppressWarnings({"InstanceMethodNamingConvention"}) - void run(List<String> args); + void run(@NotNull List<String> args); } // interface Command Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Option.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-09-25 22:42:46 UTC (rev 178) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-10-03 23:31:53 UTC (rev 179) @@ -48,6 +48,13 @@ * @note the supplied string values MUST consist of ASCII-letters only (match regex <code>[a-zA-Z]+</code>). * @return option names */ - String[] name(); + String[] names(); + /** + * The option key, used for i18n/l10n. + * Default is <code>""</code> (empty String) which is interpreted as the associated method's name being the key. + * @return option key + */ + String key() default ""; + } // @interface Option Modified: libs/argparser/trunk/src/net/sf/japi/io/args/OptionType.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/OptionType.java 2006-09-25 22:42:46 UTC (rev 178) +++ libs/argparser/trunk/src/net/sf/japi/io/args/OptionType.java 2006-10-03 23:31:53 UTC (rev 179) @@ -20,6 +20,10 @@ */ package net.sf.japi.io.args; +import java.util.ResourceBundle; +import java.util.MissingResourceException; +import java.util.Locale; + /** * The type of an option. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> @@ -33,6 +37,43 @@ OPTIONAL, /** Terminal options terminate argument parsing, no matter what happens. */ - TERMINAL + TERMINAL; + /** + * Returns the localized name of this OptionType in the default locale if available, otherwise the lowercase enum constant name. + * @return The localized name of this OptionType. + */ + public String getName() { + String name; + try { + name = ResourceBundle.getBundle("net.sf.japi.io.args.messages").getString(getClass().getName() + "." + name()); + } catch (final MissingResourceException e) { + name = name(); + } + return name; + } + + /** + * Returns the localized name of this OptionType in the specified locale if available, otherwise the lowercase enum constant name. + * @param locale Locale + * @return The localized name of this OptionType. + */ + public String getName(final Locale locale) { + String name; + try { + name = ResourceBundle.getBundle("net.sf.japi.io.args.messages", locale).getString(getClass().getName() + "." + name()); + } catch (final MissingResourceException e) { + name = name(); + } + return name; + } + + /** + * {@inheritDoc} + * Returns the same as {@link #getName()}. + */ + @Override public String toString() { + return getName(); + } + } // OptionType Added: libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties 2006-10-03 23:31:53 UTC (rev 179) @@ -0,0 +1,5 @@ +net.sf.japi.io.args.OptionType.REQUIRED=required +net.sf.japi.io.args.OptionType.OPTIONAL=optional +net.sf.japi.io.args.OptionType.TERMINAL=terminal +help=Display this help and exit. +version=Display version information and exit. \ No newline at end of file Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/net/sf/japi/io/args/messages_de.properties =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/messages_de.properties (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/messages_de.properties 2006-10-03 23:31:53 UTC (rev 179) @@ -0,0 +1,5 @@ +net.sf.japi.io.args.OptionType.REQUIRED=erforderlich +net.sf.japi.io.args.OptionType.OPTIONAL=optional +net.sf.japi.io.args.OptionType.TERMINAL=abbrechend +help=Diese Hilfe anzeigen und beenden. +version=Versionsinformation anzeigen und beenden. \ No newline at end of file Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/messages_de.properties ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 22:42:46 UTC (rev 178) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-10-03 23:31:53 UTC (rev 179) @@ -1,7 +1,7 @@ package test.net.sf.japi.io.args; import net.sf.japi.io.args.ArgParser; -import net.sf.japi.io.args.Command; +import net.sf.japi.io.args.BasicCommand; import net.sf.japi.io.args.MissingArgumentException; import net.sf.japi.io.args.Option; import net.sf.japi.io.args.OptionType; @@ -22,7 +22,7 @@ * This MockCommand serves as a command for performing simple tests. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ - public static class MockCommand implements Command { + public static class MockCommand extends BasicCommand { /** The input option value. */ private String input; @@ -52,12 +52,21 @@ * Set the value of the input option. * @param input Value of the input option. */ - @Option(type = OptionType.REQUIRED, name = {"i", "input"}) + @Option(type = OptionType.REQUIRED, names = {"i", "input"}) public void setInput(final String input) { this.input = input; } /** + * Set the value of the foo option. + * @param foo Value of the foo option. + */ + @Option(names = {"f", "b", "foo", "bar", "buzz"}) + public void setFoo(final String foo) { + // ignored + } + + /** * Get the value of the input option. * @return Value of the input option. */ @@ -190,4 +199,17 @@ Assert.assertEquals("Argument list for invocation without arguments must be empty.", 0, command.getArgs().size()); } + /** + * Tests whether help works. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ + @Test(expected = TerminalException.class) + public void testHelp() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + final MockCommand command = new MockCommand(); + ArgParser.parseAndRun(command, "-h"); + } + } // class ArgParserTest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 22:42:52
|
Revision: 178 http://svn.sourceforge.net/japi/?rev=178&view=rev Author: christianhujer Date: 2006-09-25 15:42:46 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Changed mock method accessibility to clarify which methods of the mock are mock/test methods. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 22:30:23 UTC (rev 177) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 22:42:46 UTC (rev 178) @@ -44,7 +44,7 @@ * Get the command line arguments. * @return Command line arguments. */ - public List<String> getArgs() { + private List<String> getArgs() { return args; } @@ -61,7 +61,7 @@ * Get the value of the input option. * @return Value of the input option. */ - public String getInput() { + private String getInput() { return input; } @@ -69,7 +69,7 @@ * Return whether run was called. * @return whether run was called. */ - public boolean isRunCalled() { + private boolean isRunCalled() { return runCalled; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 22:30:28
|
Revision: 177 http://svn.sourceforge.net/japi/?rev=177&view=rev Author: christianhujer Date: 2006-09-25 15:30:23 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Added more todos. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-25 11:51:57 UTC (rev 176) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-25 22:30:23 UTC (rev 177) @@ -29,6 +29,9 @@ * Parser for command line arguments. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * TODO: automatic argument conversion for option method invokation. + * TODO: Handling of --help + * TODO: Handling of --version + * TODO: Handling of - for STDIN as input argument filestrea */ public class ArgParser { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 11:52:06
|
Revision: 176 http://svn.sourceforge.net/japi/?rev=176&view=rev Author: christianhujer Date: 2006-09-25 04:51:57 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Updated TODO text. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-25 11:50:15 UTC (rev 175) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-25 11:51:57 UTC (rev 176) @@ -28,7 +28,7 @@ /** * Parser for command line arguments. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * TODO: arguments for options, argument conversion for the method invokation. + * TODO: automatic argument conversion for option method invokation. */ public class ArgParser { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 11:50:21
|
Revision: 175 http://svn.sourceforge.net/japi/?rev=175&view=rev Author: christianhujer Date: 2006-09-25 04:50:15 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Fixed javadoc error. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 11:49:14 UTC (rev 174) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 11:50:15 UTC (rev 175) @@ -50,7 +50,7 @@ /** * Set the value of the input option. - * @return Value of the input option. + * @param input Value of the input option. */ @Option(type = OptionType.REQUIRED, name = {"i", "input"}) public void setInput(final String input) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 11:49:21
|
Revision: 174 http://svn.sourceforge.net/japi/?rev=174&view=rev Author: christianhujer Date: 2006-09-25 04:49:14 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Bug: Unlike documented, OptionType.OPTIONAL was not the default. Fixed. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/Option.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Option.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-09-25 10:23:45 UTC (rev 173) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-09-25 11:49:14 UTC (rev 174) @@ -39,7 +39,7 @@ * Default is {@link OptionType#OPTIONAL}. * @return option type */ - OptionType type(); + OptionType type() default OptionType.OPTIONAL; /** * The option names. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 10:23:54
|
Revision: 173 http://svn.sourceforge.net/japi/?rev=173&view=rev Author: christianhujer Date: 2006-09-25 03:23:45 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Added new assertions about invocation and arguments of run() method. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 10:16:26 UTC (rev 172) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 10:23:45 UTC (rev 173) @@ -27,12 +27,16 @@ /** The input option value. */ private String input; + /** Remembers whether {@link #run(java.util.List<java.lang.String>)} was called. */ + private boolean runCalled; + /** The command line arguments received from the parser. */ private List<String> args; /** {@inheritDoc} */ @SuppressWarnings({"InstanceMethodNamingConvention"}) public void run(final List<String> args) { + runCalled = true; this.args = args; } @@ -61,6 +65,14 @@ return input; } + /** + * Return whether run was called. + * @return whether run was called. + */ + public boolean isRunCalled() { + return runCalled; + } + } // class MockCommand /** @@ -75,6 +87,8 @@ final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "-i", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + Assert.assertTrue("Run must be called even with zero arguments.", command.isRunCalled()); + Assert.assertEquals("Argument list for invocation without arguments must be empty.", 0, command.getArgs().size()); } /** @@ -89,6 +103,8 @@ final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "--input", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + Assert.assertTrue("Run must be called even with zero arguments.", command.isRunCalled()); + Assert.assertEquals("Argument list for invocation without arguments must be empty.", 0, command.getArgs().size()); } /** @@ -103,6 +119,8 @@ final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "--input=fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + Assert.assertTrue("Run must be called even with zero arguments.", command.isRunCalled()); + Assert.assertEquals("Argument list for invocation without arguments must be empty.", 0, command.getArgs().size()); } /** @@ -115,7 +133,11 @@ @Test(expected=RequiredOptionsMissingException.class) public void testCommandRequiredOptionMissing() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { final MockCommand command = new MockCommand(); - ArgParser.parseAndRun(command); + try { + ArgParser.parseAndRun(command); + } finally { + Assert.assertFalse("Run must not be called in exception case.", command.isRunCalled()); + } } /** @@ -128,7 +150,11 @@ @Test(expected=UnknownOptionException.class) public void testCommandUnknownOption() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { final MockCommand command = new MockCommand(); - ArgParser.parseAndRun(command, "--output"); + try { + ArgParser.parseAndRun(command, "--output"); + } finally { + Assert.assertFalse("Run must not be called in exception case.", command.isRunCalled()); + } } /** @@ -141,7 +167,11 @@ @Test(expected=MissingArgumentException.class) public void testCommandMissingArgument() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { final MockCommand command = new MockCommand(); - ArgParser.parseAndRun(command, "--input"); + try { + ArgParser.parseAndRun(command, "--input"); + } finally { + Assert.assertFalse("Run must not be called in exception case.", command.isRunCalled()); + } } /** @@ -156,6 +186,8 @@ final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "-i", "barBuzz", "-i", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + Assert.assertTrue("Run must be called even with zero arguments.", command.isRunCalled()); + Assert.assertEquals("Argument list for invocation without arguments must be empty.", 0, command.getArgs().size()); } } // class ArgParserTest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 10:16:34
|
Revision: 172 http://svn.sourceforge.net/japi/?rev=172&view=rev Author: christianhujer Date: 2006-09-25 03:16:26 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Improved test for argument parsing, added new test cases. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 10:04:00 UTC (rev 171) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 10:16:26 UTC (rev 172) @@ -1,16 +1,28 @@ package test.net.sf.japi.io.args; -import net.sf.japi.io.args.*; +import net.sf.japi.io.args.ArgParser; +import net.sf.japi.io.args.Command; +import net.sf.japi.io.args.MissingArgumentException; +import net.sf.japi.io.args.Option; +import net.sf.japi.io.args.OptionType; +import net.sf.japi.io.args.RequiredOptionsMissingException; +import net.sf.japi.io.args.TerminalException; +import net.sf.japi.io.args.UnknownOptionException; import java.util.List; import org.junit.Test; import org.junit.Assert; /** * Test for {@link ArgParser}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public class ArgParserTest { - public static class MockCommand1 implements Command { + /** + * This MockCommand serves as a command for performing simple tests. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ + public static class MockCommand implements Command { /** The input option value. */ private String input; @@ -49,44 +61,101 @@ return input; } - } // class MockCommand1 + } // class MockCommand + /** + * Tests whether supplying a required option with argument in short form works. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test - public void testCommand1A() { - final MockCommand1 command = new MockCommand1(); - ArgParser.simpleParseAndRun(command, "-i", "fooInput"); + public void testCommandWithShortOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + final MockCommand command = new MockCommand(); + ArgParser.parseAndRun(command, "-i", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); } + /** + * Tests whether supplying a required option with argument in long form with separate argument works. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test - public void testCommand1B() { - final MockCommand1 command = new MockCommand1(); - ArgParser.simpleParseAndRun(command, "--input", "fooInput"); + public void testCommandWithLongOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + final MockCommand command = new MockCommand(); + ArgParser.parseAndRun(command, "--input", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); } + /** + * Tests whether supplying a required option with argument in long form with integrated argument works. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test - public void testCommand1C() { - final MockCommand1 command = new MockCommand1(); - ArgParser.simpleParseAndRun(command, "--input=fooInput"); + public void testCommandWithLongOptEq() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + final MockCommand command = new MockCommand(); + ArgParser.parseAndRun(command, "--input=fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); } + /** + * Tests whether it's detected that a required option is missing. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test(expected=RequiredOptionsMissingException.class) - public void testCommand1D() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { - final MockCommand1 command = new MockCommand1(); + public void testCommandRequiredOptionMissing() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command); } + /** + * Tests whether it's detected that an unknown option was given. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test(expected=UnknownOptionException.class) - public void testCommand1E() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { - final MockCommand1 command = new MockCommand1(); + public void testCommandUnknownOption() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "--output"); } + /** + * Tests whether it's detected that the argument of an option that requires an argument is missing. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ @Test(expected=MissingArgumentException.class) - public void testCommand1F() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { - final MockCommand1 command = new MockCommand1(); + public void testCommandMissingArgument() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + final MockCommand command = new MockCommand(); ArgParser.parseAndRun(command, "--input"); } + + /** + * Tests whether specifying an option twice works. + * @throws RequiredOptionsMissingException + * @throws TerminalException + * @throws UnknownOptionException + * @throws MissingArgumentException + */ + @Test + public void testCommandDuplicateOption() throws RequiredOptionsMissingException, MissingArgumentException, TerminalException, UnknownOptionException { + final MockCommand command = new MockCommand(); + ArgParser.parseAndRun(command, "-i", "barBuzz", "-i", "fooInput"); + Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + } + } // class ArgParserTest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 10:04:23
|
Revision: 171 http://svn.sourceforge.net/japi/?rev=171&view=rev Author: christianhujer Date: 2006-09-25 03:04:00 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Added proper handling of unknown options and missing option arguments. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java libs/argparser/trunk/src/net/sf/japi/io/args/RequiredOptionsMissingException.java libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Added Paths: ----------- libs/argparser/trunk/src/net/sf/japi/io/args/MissingArgumentException.java libs/argparser/trunk/src/net/sf/japi/io/args/UnknownOptionException.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-25 09:36:21 UTC (rev 170) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-25 10:04:00 UTC (rev 171) @@ -57,19 +57,15 @@ * @param args Arguments to parse * @throws RequiredOptionsMissingException in case an option is missing * @throws TerminalException in case argument parsing was stopped + * @throws MissingArgumentException in the required argument for an option was missing */ - private ArgParser(final Command command, final String... args) throws TerminalException, RequiredOptionsMissingException { + private ArgParser(final Command command, final String... args) throws TerminalException, RequiredOptionsMissingException, UnknownOptionException, MissingArgumentException { this.command = command; commandClass = command.getClass(); initMethods(); final List<String> argList = new ArrayList<String>(Arrays.asList(args)); argIterator = argList.listIterator(); - try { - parse(); - } catch (final NoSuchElementException e) { - System.err.println("Missing argument for option " + currentOption); - return; - } + parse(); checkRequiredMethods(); command.run(argList); } @@ -117,7 +113,7 @@ * Parses arguments into an arguments container and invokes the Command's {@link Command#run(List<String>)} method. * @throws TerminalException in case argument parsing was stopped */ - private void parse() throws TerminalException { + private void parse() throws TerminalException, UnknownOptionException, MissingArgumentException { try { for (; argIterator.hasNext(); ) { final String arg = argIterator.next(); @@ -148,7 +144,7 @@ // empty arguments are intentionally not removed. } } catch (final NoSuchElementException e) { - System.err.println("Missing argument for option " + currentOption); + throw new MissingArgumentException(currentOption); } } @@ -156,10 +152,10 @@ * Invoke the argument method for the current option. * @throws TerminalException in case the invoked exception was terminal */ - private void invokeMethod() throws TerminalException { + private void invokeMethod() throws TerminalException, UnknownOptionException { final Method method = argumentMethods.get(currentOption); if (method == null) { - throw new RuntimeException("Unknown argument Exception"); + throw new UnknownOptionException(currentOption); } requiredMethods.remove(method); try { @@ -192,14 +188,31 @@ * @param command Command to run * @param args Arguments to parse */ - public static void parseAndRun(final Command command, final String... args) { + public static void simpleParseAndRun(final Command command, final String... args) { try { - new ArgParser(command, args); + parseAndRun(command, args); } catch (final TerminalException e) { /* ignore, nothing serious has happend. */ } catch (final RequiredOptionsMissingException e) { System.err.println(e); + } catch (final UnknownOptionException e) { + System.err.println(e); + } catch (final MissingArgumentException e) { + System.err.println(e); } } + /** + * Parses arguments of a command and runs that command. + * @param command Command to run + * @param args Arguments to parse + * @throws RequiredOptionsMissingException in case one or more required options were missing. + * @throws TerminalException in case a terminal option was encountered. + * @throws UnknownOptionException in case an option given was not known. + * @throws MissingArgumentException in case an option was missing its argument + */ + public static void parseAndRun(final Command command, final String... args) throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + new ArgParser(command, args); + } + } // class ArgParser Added: libs/argparser/trunk/src/net/sf/japi/io/args/MissingArgumentException.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/MissingArgumentException.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/MissingArgumentException.java 2006-09-25 10:04:00 UTC (rev 171) @@ -0,0 +1,31 @@ +package net.sf.japi.io.args; + +import org.jetbrains.annotations.NotNull; + +/** + * This exception is thrown in case a required argument for an option is missing. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class MissingArgumentException extends Exception { + + /** The option that was missing its argument. */ + @NotNull private final String option; + + /** + * Create a RequiredOptionsMissingException. + * @param option that was missing its argument + */ + public MissingArgumentException(@NotNull final String option) { + super("Argument missing for option " + option); + this.option = option; + } + + /** + * Get the option that is missing its argument. + * @return option that is missing its argument. + */ + public String getOption() { + return option; + } + +} // class MissingArgumentException Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/MissingArgumentException.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/net/sf/japi/io/args/RequiredOptionsMissingException.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/RequiredOptionsMissingException.java 2006-09-25 09:36:21 UTC (rev 170) +++ libs/argparser/trunk/src/net/sf/japi/io/args/RequiredOptionsMissingException.java 2006-09-25 10:04:00 UTC (rev 171) @@ -36,7 +36,7 @@ * @param missingOptions options that were missing. * @throws IllegalArgumentException in case <var>missingOptions</var> was null or of zero length */ - public RequiredOptionsMissingException(@NotNull final String[] missingOptions) { + public RequiredOptionsMissingException(@NotNull final String... missingOptions) { super(createMessage(missingOptions)); this.missingOptions = missingOptions.clone(); } @@ -47,7 +47,7 @@ * @return message string * @throws IllegalArgumentException in case <var>missingOptions</var> was null or of zero length */ - private static String createMessage(final String[] missingOptions) { + private static String createMessage(final String... missingOptions) { if (missingOptions == null || missingOptions.length < 1) { throw new IllegalArgumentException("RequiredOptionsMissingException created but no missing options given."); } Added: libs/argparser/trunk/src/net/sf/japi/io/args/UnknownOptionException.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/UnknownOptionException.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/UnknownOptionException.java 2006-09-25 10:04:00 UTC (rev 171) @@ -0,0 +1,66 @@ +/* + * 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 net.sf.japi.io.args; + +import org.jetbrains.annotations.NotNull; + +/** + * This exception is thrown in case one or more unknown options were encountered. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class UnknownOptionException extends Exception { + + /** The list of options that were unknown. */ + @NotNull + private final String[] unknownOptions; + + /** + * Create a RequiredOptionsMissingException. + * @param unknownOptions options that were missing. + * @throws IllegalArgumentException in case <var>unknownOptions</var> was null or of zero length + */ + public UnknownOptionException(@NotNull final String... unknownOptions) { + super(createMessage(unknownOptions)); + this.unknownOptions = unknownOptions.clone(); + } + + /** + * Creates the message. + * @param unknownOptions options that were missing + * @return message string + * @throws IllegalArgumentException in case <var>unknownOptions</var> was null or of zero length + */ + private static String createMessage(final String... unknownOptions) { + if (unknownOptions == null || unknownOptions.length < 1) { + throw new IllegalArgumentException("UnknownOptionException created but no unknown options given."); + } + return StringJoiner.join(new StringBuilder("unknown options: "), ", ", unknownOptions).toString(); + } + + /** + * Get the options that were missing. + * @return options that were missing + */ + public String[] getUnknownOptions() { + return unknownOptions.clone(); + } + +} // class UnknownOptionException Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/UnknownOptionException.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 09:36:21 UTC (rev 170) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 10:04:00 UTC (rev 171) @@ -1,9 +1,6 @@ package test.net.sf.japi.io.args; -import net.sf.japi.io.args.Command; -import net.sf.japi.io.args.ArgParser; -import net.sf.japi.io.args.Option; -import net.sf.japi.io.args.OptionType; +import net.sf.japi.io.args.*; import java.util.List; import org.junit.Test; import org.junit.Assert; @@ -54,22 +51,42 @@ } // class MockCommand1 - @Test public void testCommand1A() { + @Test + public void testCommand1A() { final MockCommand1 command = new MockCommand1(); - ArgParser.parseAndRun(command, "-i", "fooInput"); + ArgParser.simpleParseAndRun(command, "-i", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); } - @Test public void testCommand1B() { + @Test + public void testCommand1B() { final MockCommand1 command = new MockCommand1(); - ArgParser.parseAndRun(command, "--input", "fooInput"); + ArgParser.simpleParseAndRun(command, "--input", "fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); } - @Test public void testCommand1C() { + @Test + public void testCommand1C() { final MockCommand1 command = new MockCommand1(); - ArgParser.parseAndRun(command, "--input=fooInput"); + ArgParser.simpleParseAndRun(command, "--input=fooInput"); Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); } + @Test(expected=RequiredOptionsMissingException.class) + public void testCommand1D() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + final MockCommand1 command = new MockCommand1(); + ArgParser.parseAndRun(command); + } + + @Test(expected=UnknownOptionException.class) + public void testCommand1E() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + final MockCommand1 command = new MockCommand1(); + ArgParser.parseAndRun(command, "--output"); + } + + @Test(expected=MissingArgumentException.class) + public void testCommand1F() throws RequiredOptionsMissingException, TerminalException, UnknownOptionException, MissingArgumentException { + final MockCommand1 command = new MockCommand1(); + ArgParser.parseAndRun(command, "--input"); + } } // class ArgParserTest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-25 09:36:36
|
Revision: 170 http://svn.sourceforge.net/japi/?rev=170&view=rev Author: christianhujer Date: 2006-09-25 02:36:21 -0700 (Mon, 25 Sep 2006) Log Message: ----------- Added test cases. Added handling of = in long options. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java libs/argparser/trunk/src/net/sf/japi/io/args/Option.java Added Paths: ----------- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-24 22:37:21 UTC (rev 169) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-25 09:36:21 UTC (rev 170) @@ -45,7 +45,7 @@ private final Set<Method> requiredMethods = new HashSet<Method>(); /** The iterator for the arguments. */ - private final Iterator<String> argIterator; + private final ListIterator<String> argIterator; /** The currently used option. */ private String currentOption; @@ -63,7 +63,7 @@ commandClass = command.getClass(); initMethods(); final List<String> argList = new ArrayList<String>(Arrays.asList(args)); - argIterator = argList.iterator(); + argIterator = argList.listIterator(); try { parse(); } catch (final NoSuchElementException e) { @@ -84,7 +84,7 @@ for (final Method requiredMethod : requiredMethods) { final Option option = requiredMethod.getAnnotation(Option.class); assert option != null; - missingOptions.add(option.value()[0]); + missingOptions.add(option.name()[0]); } throw new RequiredOptionsMissingException(missingOptions.toArray(new String[missingOptions.size()])); } @@ -99,8 +99,7 @@ for (final Method method : commandClass.getMethods()) { final Option option = method.getAnnotation(Option.class); if (option != null) { - for (final String optionString : option.value()) { - final String optionName = optionString.length() > 1 ? '-' + optionString : optionString; + for (final String optionName : option.name()) { if (argumentMethods.containsKey(optionName)) { throw new IllegalArgumentException(commandClass.getName() + " declared option " + optionName + " twice."); } @@ -129,12 +128,20 @@ break; } if (arg.charAt(1) == '-') { - currentOption = arg.substring(1); + currentOption = arg.substring(2); + final int indexOfEq = currentOption.indexOf('='); + if (indexOfEq != -1) { + argIterator.add(currentOption.substring(indexOfEq + 1)); + argIterator.previous(); + currentOption = currentOption.substring(0, indexOfEq); + } invokeMethod(); } else { for (final String co : arg.substring(1).split("")) { - currentOption = co; - invokeMethod(); + if (co.length() == 1) { + currentOption = co; + invokeMethod(); + } } } } @@ -156,7 +163,16 @@ } requiredMethods.remove(method); try { - method.invoke(command); + final Class<?>[] parameterTypes = method.getParameterTypes(); + final int parameterCount = parameterTypes.length; + if (parameterCount == 1) { + final String arg = argIterator.next(); + method.invoke(command, arg); + argIterator.remove(); + } else { + assert parameterCount == 0; + method.invoke(command); + } } catch (final IllegalAccessException e) { System.err.println(e); } catch (final InvocationTargetException e) { Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Option.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-09-24 22:37:21 UTC (rev 169) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-09-25 09:36:21 UTC (rev 170) @@ -48,6 +48,6 @@ * @note the supplied string values MUST consist of ASCII-letters only (match regex <code>[a-zA-Z]+</code>). * @return option names */ - String[] value(); + String[] name(); } // @interface Option Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.java 2006-09-25 09:36:21 UTC (rev 170) @@ -0,0 +1,75 @@ +package test.net.sf.japi.io.args; + +import net.sf.japi.io.args.Command; +import net.sf.japi.io.args.ArgParser; +import net.sf.japi.io.args.Option; +import net.sf.japi.io.args.OptionType; +import java.util.List; +import org.junit.Test; +import org.junit.Assert; + +/** + * Test for {@link ArgParser}. + */ +public class ArgParserTest { + + public static class MockCommand1 implements Command { + + /** The input option value. */ + private String input; + + /** The command line arguments received from the parser. */ + private List<String> args; + + /** {@inheritDoc} */ + @SuppressWarnings({"InstanceMethodNamingConvention"}) + public void run(final List<String> args) { + this.args = args; + } + + /** + * Get the command line arguments. + * @return Command line arguments. + */ + public List<String> getArgs() { + return args; + } + + /** + * Set the value of the input option. + * @return Value of the input option. + */ + @Option(type = OptionType.REQUIRED, name = {"i", "input"}) + public void setInput(final String input) { + this.input = input; + } + + /** + * Get the value of the input option. + * @return Value of the input option. + */ + public String getInput() { + return input; + } + + } // class MockCommand1 + + @Test public void testCommand1A() { + final MockCommand1 command = new MockCommand1(); + ArgParser.parseAndRun(command, "-i", "fooInput"); + Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + } + + @Test public void testCommand1B() { + final MockCommand1 command = new MockCommand1(); + ArgParser.parseAndRun(command, "--input", "fooInput"); + Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + } + + @Test public void testCommand1C() { + final MockCommand1 command = new MockCommand1(); + ArgParser.parseAndRun(command, "--input=fooInput"); + Assert.assertEquals("Option value must be stored.", "fooInput", command.getInput()); + } + +} // class ArgParserTest Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/ArgParserTest.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. |
From: <chr...@us...> - 2006-09-24 22:37:27
|
Revision: 169 http://svn.sourceforge.net/japi/?rev=169&view=rev Author: christianhujer Date: 2006-09-24 15:37:21 -0700 (Sun, 24 Sep 2006) Log Message: ----------- Added more test cases. Modified Paths: -------------- libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java 2006-09-24 22:23:20 UTC (rev 168) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java 2006-09-24 22:37:21 UTC (rev 169) @@ -1,22 +1,58 @@ package test.net.sf.japi.io.args; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import net.sf.japi.io.args.StringJoiner; import org.junit.Test; +import java.util.Arrays; + /** * TestCase for {@link StringJoiner}. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public class StringJoinerTestCase { + /** Expected String. */ + private static final String EXPECTED = "foo, bar, buzz"; + + /** Argument values. */ + private static final String[] args = { "foo", "bar", "buzz" }; + /** + * Empty constructor for JUnit. + */ + public StringJoinerTestCase() { + } + + /** * Tests whether {@link StringJoiner#join(CharSequence, CharSequence...)} works. */ @Test public void testJoinCSCS() { - final String expected = "foo, bar, buzz"; - final String actual = StringJoiner.join(", ", "foo", "bar", "buzz"); - assertEquals(expected, actual); + final String[] nargs = args.clone(); + final String actual = StringJoiner.join(", ", nargs); + assertEquals("arguments must be joined correctly.", EXPECTED, actual); + assertTrue("arguments must not be changed by join().", Arrays.equals(args, nargs)); } + /** + * Tests whether {@link StringJoiner#join(CharSequence, Iterable<? extends java.lang.CharSequence>)} works. + */ + @Test public void testJoinCSIe() { + final String[] nargs = args.clone(); + final String actual = StringJoiner.join(", ", Arrays.asList(nargs)); + assertEquals("arguments must be joined correctly.", EXPECTED, actual); + assertTrue("arguments must not be changed by join().", Arrays.equals(args, nargs)); + } + + /** + * Tests whether {@link StringJoiner#join(CharSequence, java.util.Iterator<? extends java.lang.CharSequence>)} works. + */ + @Test public void testJoinCSIr() { + final String[] nargs = args.clone(); + final String actual = StringJoiner.join(", ", Arrays.asList(nargs).iterator()); + assertEquals("arguments must be joined correctly.", EXPECTED, actual); + assertTrue("arguments must not be changed by join().", Arrays.equals(args, nargs)); + } + } // class StringJoinerTestCase This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-24 22:23:33
|
Revision: 168 http://svn.sourceforge.net/japi/?rev=168&view=rev Author: christianhujer Date: 2006-09-24 15:23:20 -0700 (Sun, 24 Sep 2006) Log Message: ----------- Adding first test case. Added Paths: ----------- libs/argparser/trunk/src/test/ libs/argparser/trunk/src/test/net/ libs/argparser/trunk/src/test/net/sf/ libs/argparser/trunk/src/test/net/sf/japi/ libs/argparser/trunk/src/test/net/sf/japi/io/ libs/argparser/trunk/src/test/net/sf/japi/io/args/ libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java Added: libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java (rev 0) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.java 2006-09-24 22:23:20 UTC (rev 168) @@ -0,0 +1,22 @@ +package test.net.sf.japi.io.args; + +import static org.junit.Assert.assertEquals; +import net.sf.japi.io.args.StringJoiner; +import org.junit.Test; + +/** + * TestCase for {@link StringJoiner}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class StringJoinerTestCase { + + /** + * Tests whether {@link StringJoiner#join(CharSequence, CharSequence...)} works. + */ + @Test public void testJoinCSCS() { + final String expected = "foo, bar, buzz"; + final String actual = StringJoiner.join(", ", "foo", "bar", "buzz"); + assertEquals(expected, actual); + } + +} // class StringJoinerTestCase Property changes on: libs/argparser/trunk/src/test/net/sf/japi/io/args/StringJoinerTestCase.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. |
From: <chr...@us...> - 2006-09-24 11:43:57
|
Revision: 167 http://svn.sourceforge.net/japi/?rev=167&view=rev Author: christianhujer Date: 2006-09-24 04:43:34 -0700 (Sun, 24 Sep 2006) Log Message: ----------- Cosmetic rework of argument parser library. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java libs/argparser/trunk/src/net/sf/japi/io/args/Command.java libs/argparser/trunk/src/net/sf/japi/io/args/Option.java libs/argparser/trunk/src/net/sf/japi/io/args/RequiredOptionsMissingException.java libs/argparser/trunk/src/net/sf/japi/io/args/TerminalException.java Added Paths: ----------- libs/argparser/trunk/src/net/sf/japi/io/args/StringJoiner.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-24 10:28:58 UTC (rev 166) +++ libs/argparser/trunk/src/net/sf/japi/io/args/ArgParser.java 2006-09-24 11:43:34 UTC (rev 167) @@ -25,7 +25,8 @@ import java.lang.reflect.Method; import java.util.*; -/** Parser for command line arguments. +/** + * Parser for command line arguments. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * TODO: arguments for options, argument conversion for the method invokation. */ @@ -54,6 +55,8 @@ * This ArgParser uses {@link System#in}, {@link System#out} and {@link System#err}. * @param command Command to initialize and run * @param args Arguments to parse + * @throws RequiredOptionsMissingException in case an option is missing + * @throws TerminalException in case argument parsing was stopped */ private ArgParser(final Command command, final String... args) throws TerminalException, RequiredOptionsMissingException { this.command = command; @@ -73,6 +76,7 @@ /** * Checks that all required methods have been invoked. + * @throws RequiredOptionsMissingException in case a required command line argument was missing */ private void checkRequiredMethods() throws RequiredOptionsMissingException { if (requiredMethods.size() > 0) { @@ -112,6 +116,7 @@ /** * Parses arguments into an arguments container and invokes the Command's {@link Command#run(List<String>)} method. + * @throws TerminalException in case argument parsing was stopped */ private void parse() throws TerminalException { try { Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Command.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-09-24 10:28:58 UTC (rev 166) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-09-24 11:43:34 UTC (rev 167) @@ -23,12 +23,14 @@ import java.util.List; -/** Shell commands can implement this interface and make use of ArgParser. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> +/** + * Shell commands can implement this interface and make use of ArgParser. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public interface Command { - /** Run the command. + /** + * Run the command. * This method is invoked by {@link ArgParser} once it is finnished with parsing the arguments. * @param args the argument strings that were not parsed away by {@link ArgParser}. */ Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Option.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-09-24 10:28:58 UTC (rev 166) +++ libs/argparser/trunk/src/net/sf/japi/io/args/Option.java 2006-09-24 11:43:34 UTC (rev 167) @@ -26,8 +26,9 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Target; -/** Annotation to mark a method as command argument method. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> +/** + * Annotation to mark a method as command argument method. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ @Retention(RUNTIME) @Target(METHOD) @@ -43,7 +44,8 @@ /** * The option names. * Usually this is two Strings, a single letter and a descriptive String. - * @note the supplied string values should contain neither spaces nor non-ascii characters. + * Multiple descriptive Strings as well as no single letter String are allowed. + * @note the supplied string values MUST consist of ASCII-letters only (match regex <code>[a-zA-Z]+</code>). * @return option names */ String[] value(); Modified: libs/argparser/trunk/src/net/sf/japi/io/args/RequiredOptionsMissingException.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/RequiredOptionsMissingException.java 2006-09-24 10:28:58 UTC (rev 166) +++ libs/argparser/trunk/src/net/sf/japi/io/args/RequiredOptionsMissingException.java 2006-09-24 11:43:34 UTC (rev 167) @@ -24,6 +24,7 @@ /** * This exception is thrown in case required options are missing. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public class RequiredOptionsMissingException extends Exception { @@ -33,23 +34,32 @@ /** * Create a RequiredOptionsMissingException. * @param missingOptions options that were missing. + * @throws IllegalArgumentException in case <var>missingOptions</var> was null or of zero length */ public RequiredOptionsMissingException(@NotNull final String[] missingOptions) { + super(createMessage(missingOptions)); + this.missingOptions = missingOptions.clone(); + } + + /** + * Creates the message. + * @param missingOptions options that were missing + * @return message string + * @throws IllegalArgumentException in case <var>missingOptions</var> was null or of zero length + */ + private static String createMessage(final String[] missingOptions) { if (missingOptions == null || missingOptions.length < 1) { throw new IllegalArgumentException("RequiredOptionsMissingException created but no missing options given."); } - this.missingOptions = missingOptions.clone(); + return StringJoiner.join(new StringBuilder("required options missing: "), ", ", missingOptions).toString(); } - /** {@inheritDoc} */ - public String toString() { - final StringBuilder msg = new StringBuilder("required options missing: "); - for (final String missingOption : missingOptions) { - msg.append(missingOption); - msg.append(", "); - } - msg.setLength(msg.length() - 2); - return msg.toString(); + /** + * Get the options that were missing. + * @return options that were missing + */ + public String[] getMissingOptions() { + return missingOptions.clone(); } } // class RequiredOptionsMissingException Added: libs/argparser/trunk/src/net/sf/japi/io/args/StringJoiner.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/StringJoiner.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/StringJoiner.java 2006-09-24 11:43:34 UTC (rev 167) @@ -0,0 +1,192 @@ +package net.sf.japi.io.args; + +import java.io.IOException; +import java.util.Iterator; + +/** + * Class with utility methods for joining strings. + * The class is intended to be as flexible and convenient as possible. + * Therefore it mostly operates on {@link CharSequence} instead of {@link String}, so you're free to use other kinds of "Strings" as well, not only {@link String} itself. + * Apart from methods that create a new {@link String}, you will also find methods that work on {@link Appendable}s so you can use these methods to append on implementations of {@link Appendable}. + * <p /> + * Because {@link Appendable#append(CharSequence)} throws {@link IOException}, methods that work on {@link Appendable} have been overloaded to work on certain known {@link Appendable}-implementations that do not throw an {@link IOException} when appending. + * Currently this is namely {@link StringBuilder} and {@link StringBuffer}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public final class StringJoiner { + + /** + * Utility class - do not instanciate. + */ + private StringJoiner() { + } + + /** + * Join Strings. + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return joined string + */ + public static String join(final CharSequence delim, final CharSequence... strings) { + return join(new StringBuilder(), delim, strings).toString(); + } + + /** + * Join Strings. + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return joined string + */ + public static String join(final CharSequence delim, final Iterable<? extends CharSequence> strings) { + return join(new StringBuilder(), delim, strings).toString(); + } + + /** + * Join Strings. + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return joined string + */ + public static String join(final CharSequence delim, final Iterator<? extends CharSequence> strings) { + return join(new StringBuilder(), delim, strings).toString(); + } + + /** + * Join Strings to an Appendable. + * @param dest Appendable to join Strings to + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return Appendable + */ + public static Appendable join(final Appendable dest, final CharSequence delim, final CharSequence... strings) throws IOException { + for (int i = 0; i < strings.length; i++) { + if (i > 0) { + dest.append(delim); + } + dest.append(strings[i]); + } + return dest; + } + + /** + * Join Strings to an Appendable. + * @param dest Appendable to join Strings to + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return Appendable + */ + public static Appendable join(final Appendable dest, final CharSequence delim, final Iterable<? extends CharSequence> strings) throws IOException { + return join(dest, delim, strings.iterator()); + } + + /** + * Join Strings to an Appendable. + * @param dest Appendable to join Strings to + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return Appendable + */ + public static Appendable join(final Appendable dest, final CharSequence delim, final Iterator<? extends CharSequence> strings) throws IOException { + if (strings.hasNext()) { + dest.append(strings.next()); + } + while (strings.hasNext()) { + dest.append(delim); + dest.append(strings.next()); + } + return dest; + } + + /** + * Join Strings to a StringBuilder. + * @param dest StringBuilder to join Strings to + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return supplied StringBuilder (<var>dest</var>) + */ + public static StringBuilder join(final StringBuilder dest, final CharSequence delim, final CharSequence... strings) { + for (int i = 0; i < strings.length; i++) { + if (i > 0) { + dest.append(delim); + } + dest.append(strings[i]); + } + return dest; + } + + /** + * Join Strings to a StringBuilder. + * @param dest StringBuilder to join Strings to + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return supplied StringBuilder (<var>dest</var>) + */ + public static StringBuilder join(final StringBuilder dest, final CharSequence delim, final Iterable<? extends CharSequence> strings) { + return join(dest, delim, strings.iterator()); + } + + /** + * Join Strings to a StringBuilder. + * @param dest StringBuilder to join Strings to + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return supplied StringBuilder (<var>dest</var>) + */ + public static StringBuilder join(final StringBuilder dest, final CharSequence delim, final Iterator<? extends CharSequence> strings) { + if (strings.hasNext()) { + dest.append(strings.next()); + } + while (strings.hasNext()) { + dest.append(delim); + dest.append(strings.next()); + } + return dest; + } + + /** + * Join Strings to a StringBuffer. + * @param dest StringBuffer to join Strings to + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return supplied StringBuffer (<var>dest</var>) + */ + public static StringBuffer join(final StringBuffer dest, final CharSequence delim, final CharSequence... strings) { + for (int i = 0; i < strings.length; i++) { + if (i > 0) { + dest.append(delim); + } + dest.append(strings[i]); + } + return dest; + } + + /** + * Join Strings to a StringBuffer. + * @param dest StringBuffer to join Strings to + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return supplied StringBuffer (<var>dest</var>) + */ + public static StringBuffer join(final StringBuffer dest, final CharSequence delim, final Iterable<? extends CharSequence> strings) { + return join(dest, delim, strings.iterator()); + } + + /** + * Join Strings to a StringBuffer. + * @param dest StringBuffer to join Strings to + * @param delim delimiter to use for joining the strings + * @param strings Strings to join + * @return supplied StringBuffer (<var>dest</var>) + */ + public static StringBuffer join(final StringBuffer dest, final CharSequence delim, final Iterator<? extends CharSequence> strings) { + if (strings.hasNext()) { + dest.append(strings.next()); + } + while (strings.hasNext()) { + dest.append(delim); + dest.append(strings.next()); + } + return dest; + } + +} // class StringJoiner Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/StringJoiner.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: libs/argparser/trunk/src/net/sf/japi/io/args/TerminalException.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/TerminalException.java 2006-09-24 10:28:58 UTC (rev 166) +++ libs/argparser/trunk/src/net/sf/japi/io/args/TerminalException.java 2006-09-24 11:43:34 UTC (rev 167) @@ -22,6 +22,7 @@ /** * This exception is thrown when an argument method is terminal, i.e. stops further command processing. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ public class TerminalException extends Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-24 10:29:10
|
Revision: 166 http://svn.sourceforge.net/japi/?rev=166&view=rev Author: christianhujer Date: 2006-09-24 03:28:58 -0700 (Sun, 24 Sep 2006) Log Message: ----------- Added contents of argparser library. Added Paths: ----------- libs/argparser/trunk/src/ libs/argparser/trunk/src/net/ libs/argparser/trunk/src/net/sf/ libs/argparser/trunk/src/net/sf/japi/ libs/argparser/trunk/src/net/sf/japi/io/ libs/argparser/trunk/src/net/sf/japi/io/args/ Copied: libs/argparser/trunk/src/net/sf/japi/io/args (from rev 165, historic/trunk/src/app/net/sf/japi/io/args) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-05 19:32:22
|
Revision: 165 http://svn.sourceforge.net/japi/?rev=165&view=rev Author: christianhujer Date: 2006-09-05 12:32:09 -0700 (Tue, 05 Sep 2006) Log Message: ----------- Creating top directory for site. Added Paths: ----------- site/ site/branches/ site/tags/ site/trunk/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-05 19:17:40
|
Revision: 164 http://svn.sourceforge.net/japi/?rev=164&view=rev Author: christianhujer Date: 2006-09-05 12:16:57 -0700 (Tue, 05 Sep 2006) Log Message: ----------- Creating ttb structures. Added Paths: ----------- libs/argparser/branches/ libs/argparser/tags/ libs/argparser/trunk/ libs/finance/branches/ libs/finance/tags/ libs/finance/trunk/ libs/logging/branches/ libs/logging/tags/ libs/logging/trunk/ libs/swing-action/branches/ libs/swing-action/tags/ libs/swing-action/trunk/ libs/swing-bookmarks/branches/ libs/swing-bookmarks/tags/ libs/swing-bookmarks/trunk/ libs/swing-extlib/branches/ libs/swing-extlib/tags/ libs/swing-extlib/trunk/ libs/swing-font/branches/ libs/swing-font/tags/ libs/swing-font/trunk/ libs/swing-keyprefs/branches/ libs/swing-keyprefs/tags/ libs/swing-keyprefs/trunk/ libs/swing-misc/branches/ libs/swing-misc/tags/ libs/swing-misc/trunk/ libs/swing-prefs/branches/ libs/swing-prefs/tags/ libs/swing-prefs/trunk/ libs/swing-proxyprefs/branches/ libs/swing-proxyprefs/tags/ libs/swing-proxyprefs/trunk/ libs/swing-recent/branches/ libs/swing-recent/tags/ libs/swing-recent/trunk/ libs/swing-tod/branches/ libs/swing-tod/tags/ libs/swing-tod/trunk/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-05 19:13:01
|
Revision: 163 http://svn.sourceforge.net/japi/?rev=163&view=rev Author: christianhujer Date: 2006-09-05 12:12:54 -0700 (Tue, 05 Sep 2006) Log Message: ----------- Creating library for command line argument parsing. Added Paths: ----------- libs/argparser/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-05 19:12:18
|
Revision: 162 http://svn.sourceforge.net/japi/?rev=162&view=rev Author: christianhujer Date: 2006-09-05 12:12:11 -0700 (Tue, 05 Sep 2006) Log Message: ----------- Creating library for swing proxy preferences. Added Paths: ----------- libs/swing-proxyprefs/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-05 19:11:58
|
Revision: 161 http://svn.sourceforge.net/japi/?rev=161&view=rev Author: christianhujer Date: 2006-09-05 12:11:49 -0700 (Tue, 05 Sep 2006) Log Message: ----------- Creating library for swing keyboard preferences. Added Paths: ----------- libs/swing-keyprefs/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-05 19:11:39
|
Revision: 160 http://svn.sourceforge.net/japi/?rev=160&view=rev Author: christianhujer Date: 2006-09-05 12:11:31 -0700 (Tue, 05 Sep 2006) Log Message: ----------- Creating library for swing extension library. Added Paths: ----------- libs/swing-extlib/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-05 19:11:10
|
Revision: 159 http://svn.sourceforge.net/japi/?rev=159&view=rev Author: christianhujer Date: 2006-09-05 12:11:03 -0700 (Tue, 05 Sep 2006) Log Message: ----------- Creating library for miscellaneous swing extensions. Added Paths: ----------- libs/swing-misc/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |