sam.ui
Class RulingInterface

java.lang.Object
  |
  +--sam.ui.RulingInterface
Direct Known Subclasses:
RulingInterface, RulingInterface

public abstract class RulingInterface
extends java.lang.Object

Generic ruling interface type. A ruling interface is in charge of parsing command-line and interactively prompt the user for missing parameters


Nested Class Summary
static class RulingInterface.AccessMode
          File access mode
 
Field Summary
static RulingInterface.AccessMode FILE
          Access mode for a readable or writable file
static RulingInterface.AccessMode READABLE_DIRECTORY
          Access mode for a readable and traversable directory
static RulingInterface.AccessMode READABLE_FILE
          Access mode for a readable file
static RulingInterface.AccessMode READABLE_FILE_OR_DIRECTORY
           
static RulingInterface.AccessMode WRITABLE_DIRECTORY
          Access mode for a readable and traversable directory
static RulingInterface.AccessMode WRITABLE_FILE
          Access mode for a writable or creatable file
 
Constructor Summary
RulingInterface()
           
 
Method Summary
protected abstract  java.lang.String choose(java.lang.String title, java.lang.String[] values)
          Prompts the user for entering a string.
 sam.cipher.Specification[] chooseCiphers(sam.cipher.Specification[] ciphers)
          Prompts the user to choose the ciphers and enter the corresponding passwords in ciphering mode.
 int chooseInteger(java.lang.String title, int[] values, int suggestedValue)
          Prompts the user for choosing an integer among several ones.
 java.lang.String chooseString(java.lang.String title, java.lang.String[] values, java.lang.String suggestedValue)
          Prompts the user for choosing a string among several ones.
protected abstract  sam.cipher.Specification[] enterCiphers(java.lang.String title, sam.cipher.Specification[] ciphers, boolean canAddCiphers)
          Prompts the user for entering the ciphers/passwords.
protected abstract  java.io.File enterFileOrDirectory(java.lang.String title, java.io.File suggestedValue, RulingInterface.AccessMode mode)
          Prompts the user for entering a file name.
protected abstract  int enterInteger(java.lang.String title, int suggestedValue, int min, int max)
          Prompts the user for entering an integral number.
 sam.cipher.Specification[] enterPasswords(sam.cipher.Specification[] ciphers)
          Prompts the user to enter the password for specified ciphers in deciphering mode.
protected abstract  java.lang.String enterString(java.lang.String title, java.lang.String suggestedValue)
          Prompts the user for entering a string.
 java.io.File getFileOrDirectory(java.lang.String title, java.io.File suggestedValue, RulingInterface.AccessMode mode)
          Gets a file or directory and ensures it can be read/written as required
 java.io.File getFileOrDirectory(java.lang.String title, java.lang.String suggestedValue, RulingInterface.AccessMode mode)
          Gets a file or directory and ensures it can be read/written as required
 int getInteger(java.lang.String title, int suggestedValue, int min, int max)
          Gets a user-supplied integral number.
 java.lang.String getString(java.lang.String title, java.lang.String suggestedValue)
          Gets a user-supplied string.
 void test()
          Simple test code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE

public static final RulingInterface.AccessMode FILE
Access mode for a readable or writable file


READABLE_FILE

public static final RulingInterface.AccessMode READABLE_FILE
Access mode for a readable file


WRITABLE_FILE

public static final RulingInterface.AccessMode WRITABLE_FILE
Access mode for a writable or creatable file


READABLE_DIRECTORY

public static final RulingInterface.AccessMode READABLE_DIRECTORY
Access mode for a readable and traversable directory


WRITABLE_DIRECTORY

public static final RulingInterface.AccessMode WRITABLE_DIRECTORY
Access mode for a readable and traversable directory


READABLE_FILE_OR_DIRECTORY

public static final RulingInterface.AccessMode READABLE_FILE_OR_DIRECTORY
Constructor Detail

RulingInterface

public RulingInterface()
Method Detail

enterString

protected abstract java.lang.String enterString(java.lang.String title,
                                                java.lang.String suggestedValue)
Prompts the user for entering a string. This is a basic and general-purpose method.

Parameters:
title - the title (or type) of the value to be chosen
suggestedValue - the suggested (yet invalid) value In current implementation this will always be null since this is the only "invalid" String

getString

public java.lang.String getString(java.lang.String title,
                                  java.lang.String suggestedValue)
Gets a user-supplied string. This is a basic and general-purpose method.

Parameters:
title - the title (or type) of the value to be chosen
suggestedValue - the suggested value to be returned if not null

enterInteger

protected abstract int enterInteger(java.lang.String title,
                                    int suggestedValue,
                                    int min,
                                    int max)
                             throws java.lang.NumberFormatException
Prompts the user for entering an integral number.

Parameters:
title - the title (or type) of the value to be chosen
suggestedValue - the suggested number to be returned if valid
min - the minimum allowed value, or Integer.MIN_VALUE
max - the maximum allowed value, or Integer.MAX_VALUE
java.lang.NumberFormatException

getInteger

public final int getInteger(java.lang.String title,
                            int suggestedValue,
                            int min,
                            int max)
Gets a user-supplied integral number.

Parameters:
title - the title (or type) of the value to be chosen
suggestedValue - the suggested number to be returned if valid
min - the minimum allowed value, or Integer.MIN_VALUE
max - the maximum allowed value, or Integer.MAX_VALUE

enterFileOrDirectory

protected abstract java.io.File enterFileOrDirectory(java.lang.String title,
                                                     java.io.File suggestedValue,
                                                     RulingInterface.AccessMode mode)
Prompts the user for entering a file name.

Parameters:
title - the title (or type) of the directory to be chosen
suggestedValue - the suggested (yet invalid) file or directory to be returned
mode - the required access mode for this file

getFileOrDirectory

public java.io.File getFileOrDirectory(java.lang.String title,
                                       java.lang.String suggestedValue,
                                       RulingInterface.AccessMode mode)
Gets a file or directory and ensures it can be read/written as required

Parameters:
title - the title (or type) of the directory to be chosen
suggestedValue - the suggested (yet invalid) file or directory to be returned
mode - the required access mode for this file

getFileOrDirectory

public java.io.File getFileOrDirectory(java.lang.String title,
                                       java.io.File suggestedValue,
                                       RulingInterface.AccessMode mode)
Gets a file or directory and ensures it can be read/written as required

Parameters:
title - the title (or type) of the directory to be chosen
suggestedValue - the suggested (yet invalid) file or directory to be returned
mode - the required access mode for this file

chooseInteger

public int chooseInteger(java.lang.String title,
                         int[] values,
                         int suggestedValue)
Prompts the user for choosing an integer among several ones.

Parameters:
title - the title (or type) of the value to be chosen
values - the list of allowed values
suggestedValue - the suggested value to be returned on cancel

chooseString

public java.lang.String chooseString(java.lang.String title,
                                     java.lang.String[] values,
                                     java.lang.String suggestedValue)
Prompts the user for choosing a string among several ones.

Parameters:
title - the title (or type) of the value to be chosen
values - the list of allowed values
suggestedValue - the suggested value to be returned on cancel
Returns:
the chosen value, or null if cancelled or if values is null

choose

protected abstract java.lang.String choose(java.lang.String title,
                                           java.lang.String[] values)
Prompts the user for entering a string.

Parameters:
title - the title (or type) of the value to be chosen
values - the list of allowed values

enterPasswords

public final sam.cipher.Specification[] enterPasswords(sam.cipher.Specification[] ciphers)
Prompts the user to enter the password for specified ciphers in deciphering mode.

Parameters:
ciphers - the suggested ciphers list

chooseCiphers

public final sam.cipher.Specification[] chooseCiphers(sam.cipher.Specification[] ciphers)
Prompts the user to choose the ciphers and enter the corresponding passwords in ciphering mode.

Parameters:
ciphers - the suggested ciphers list

enterCiphers

protected abstract sam.cipher.Specification[] enterCiphers(java.lang.String title,
                                                           sam.cipher.Specification[] ciphers,
                                                           boolean canAddCiphers)
Prompts the user for entering the ciphers/passwords.

Parameters:
title - the non-null title
ciphers - the suggested ciphers list or null if none specified
canAddCiphers - wether the user can add/remove ciphers or simply supply passwords

test

public void test()
Simple test code.