EDU.ksu.cis.calculator.jnlpui
Class JNLPCompatibleUI

java.lang.Object
  |
  +--EDU.ksu.cis.calculator.jnlpui.JNLPCompatibleUI
All Implemented Interfaces:
CalculatorUI

public class JNLPCompatibleUI
extends Object
implements CalculatorUI

A user interface designed to be compatible with the JNLP API, so that it will work properly under Java Web Start. This UI is appropriate for an RPN calculator supporting integer operations. The first argument to the single constructor gives the name of the package containing the classes that implement the model of the calcultator. One of these classes must be named CalculatorImpl and implement the interface Calculator. Furthermore, the CalculatorImpl class must contain a 2-argument constructor whose first argument is of type CalculatorUI and whose second argument is of type int. Other classes in that package which this class will attempt to instantiate include:

In order for these classes to be used, they must have a visible default constructor and implement the interface Operation. If any of these classes are missing or cannot be constructed, their corresponding buttons will be diabled.

This UI supports any radix 2-36 and allows conversion between them. Buttons are provided for the digits 0-9, but any digit valid for the current radix may be entered directly from the keyboard (see Integer.toString(int, int)). Keyboard equivalents are not provided for the operations.

If a JNLP ClipboardService is available, a popup menu is provided for accessing the system clipboard (cut, copy, and paste).

A checkbox is present for changing whether the bases are "sticky"; i.e., if the current radix has changed since a value was pushed onto the stack and the bases are sticky, then if that value is moved to the top of the stack, it is displayed in the current base. Otherwise, it is displayed in the base in which it was originally entered or computed. The model is responsible for implementing this behavior by accepting a Boolean as the first argument to Calculator.changeSettings(Object, String). The Home and End keys move the text caret to the beginning and end, respectively, of the display. Otherwise, editing keys are left to operate as defined by the platform look-and-feel.

Author:
Rod Howell (howell@cis.ksu.edu)

Constructor Summary
JNLPCompatibleUI(String modelLoc, JApplet parent)
          Constructs a new user interface.
 
Method Summary
 String getInput()
          Returns any input the user has provided since the model last updated the display.
 void insert(String s)
          Inserts the given string into the display at the text caret.
 void setBusy(boolean busy)
          Sets the cursor to "Wait" if busy = true or "Default" otherwise.
 void setOutput(String s, int b)
          Displays the given String, and the given radix.
 void showError(Throwable e)
          Displays the given Throwable in a message dialog.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JNLPCompatibleUI

public JNLPCompatibleUI(String modelLoc,
                        JApplet parent)
                 throws ClassNotFoundException,
                        NoSuchMethodException,
                        InstantiationException,
                        IllegalAccessException,
                        InvocationTargetException,
                        ClassCastException
Constructs a new user interface.

Parameters:
modelLoc - The name of the package containing the calculator model. The name must be terminated by a period.
parent - The applet on which the user interface is diplayed. If the calculator is running as an application, the applet behaves like a Panel.
Throws:
ClassNotFoundException - If there is no class CalculatorImpl in the package specified by modelLoc.
NoSuchMethodException - If the CalculatorImpl class does not have a 2-arg constructor whose first argument is of type CalculatorUI and whose second argument is of type int.
IllegalAccessException - If the above constructor is inaccessible.
InvocationTargetException - If the above constructor throws an exception.
InstantiationException - If CalculatorImpl is an abstract class.
ClassCastException - If CalculatorImpl does not implement Calculator.
Method Detail

insert

public void insert(String s)
Inserts the given string into the display at the text caret. If there is a selected region, it is replaced.

Specified by:
insert in interface CalculatorUI

getInput

public String getInput()
Returns any input the user has provided since the model last updated the display. Returns null if there is no such input.

Specified by:
getInput in interface CalculatorUI

setOutput

public void setOutput(String s,
                      int b)
Displays the given String, and the given radix.

Specified by:
setOutput in interface CalculatorUI

showError

public void showError(Throwable e)
Displays the given Throwable in a message dialog.

Specified by:
showError in interface CalculatorUI

setBusy

public void setBusy(boolean busy)
Sets the cursor to "Wait" if busy = true or "Default" otherwise.

Specified by:
setBusy in interface CalculatorUI