Public Member Functions | Static Public Member Functions | Protected Attributes | Package Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes

jscicalc.CalculatorApplet Class Reference

This class is effectively the controller class for the calculator. More...

Collaboration diagram for jscicalc.CalculatorApplet:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CalculatorApplet (String args[])
 Constructor.
void init ()
 Used to construct the applet.
void setup ()
 This sets up the calculator for either the applet of the standalone application.
void clearHistory ()
 As you might expect this clears the calculator history.
void upHistory ()
 Moves up the history list (if possible).
boolean downHistory ()
 Moves down the history list (if possible).
void pushHistory ()
 This is called by EqualsButton and its subclasses and stores an expression in the history list before evaluating it.
void right ()
 Moves right through the current expression.
void left ()
 Moves left through the current expression.
javax.swing.Action backward ()
 This was an experimental feature that I couldn’t get to work.
void newExpression ()
 When we evaluate an expression, we need to create a new one.
DisplayPanel displayPanel ()
 Designed so that CalculatorPanel and its subclasses can use the displayPanel object as required.
void clear ()
 We use this when we want to clear the expresion in the LCD window.
void delete ()
 Delete at the current caret position.
void copy ()
 Copy from displayPanel to system clipboard.
void insert (PObject p)
 Insert at the current caret position.
void updateDisplay (boolean entry, boolean extra)
 Used to tell the view that we want the display changed, for example, in response to pressing the shift button.
int displayHeight (int minSize)
 Find the display height at minSize.
int buttonHeight (int minSize)
 Find the button height at minSize.
int buttonWidth (int minSize)
 Find the button width at minSize.
int strutSize (int minSize)
 Find the strut size at minSize.
int displayHeight ()
 The height of the LCD display in pixels.
int buttonHeight ()
 The height of a standard button.
int buttonWidth ()
 The width of a standard button.
int strutSize ()
 If you look at the CalculatorPanel objects, you’ll see that the buttons are grouped.
void setMinSize (int mSize)
 An important little function.
int minSize ()
 If you look at the CalculatorPanel objects, you’ll see that there’s a minimum gap between most objects.
float buttonTextSize ()
 Get the size of text to use on buttons.
float entryTextSize ()
 Get the size of text to use on the EntryLabel object.
float displayTextSize ()
 Get the size of text to use on the DisplayPanel.This reports the size of text for calculator ‘output’.
float extraTextSize ()
 Get the size of small text to use on the DisplayPanel object.
void setShift (boolean value)
 Set the shift button to pressed or unpressed.
void setOn (boolean value)
 Called when we set the calculator on or off.
boolean getOn ()
 Tells us if the calculator is switched on.
boolean getShift ()
 Tells us if the shift button is down.
Parser getParser ()
 The Parser class is the model that this class controls.
OObject getValue ()
 This is used internally, but it’s also useful if you want to use the calculator as part of something else.
void setValue (OObject o)
 when an EqualsButton calculates a value it has to transfer it from the Parser object to this and setValue() is the function we use.
void setMemory (OObject o)
 The calculator can store one value and this is how we do it.
OObject getMemory ()
void setAngleType (AngleType angleType)
 We can work with degrees or radians and this is how we set them.
AngleType getAngleType ()
boolean getStat ()
void setStat (boolean stat)
 Set stat mode on or off.
int getMode ()
 As you’d expect for something emulating a real calculator, we’d better have a mode button.
void setMode (int i)
 Sets the mode.
void setMode (PObject p)
 Sets the mode.
void clearStatMemory ()
 Clear statistical memory.
Complex statAdd (Complex d)
 Add a Complex to statistical memory.
Complex statSub (Complex d)
 Removes a Complex from statistical memory.
Mean statMean ()
 Calculate the mean value.
Complex statSumSquares ()
 Calculate sum of squares - used in standard deviation/variance calculations.
StDev statSampleStDev ()
 Calculate the sample standard deviation.
PopStDev statPopulationStDev ()
 Calculate the population standard deviation.
void frame (javax.swing.JFrame jframe)
 Used to set value of jframe.
javax.swing.JFrame frame ()
 Another function whose purpose eludes me.
void keyPressed (java.awt.event.KeyEvent keyEvent)
 Some keys don’t generate keyTyped Events.
void keyReleased (java.awt.event.KeyEvent keyEvent)
 Some keys don’t generate keyTyped Events.
void keyTyped (java.awt.event.KeyEvent keyEvent)
 Handle typed keys.
Base getBase ()
 We work in various bases.
void setBase (Base b)
 This is where we set the base.
void setTextComponent (javax.swing.text.JTextComponent textComponent)
 This function is useful if you want to attach a JTextComponent such as JTextField to the calculator so that when you calculate a value, it gets transferred to the JTextComponent.
final
javax.swing.text.JTextComponent 
getTextComponent ()
 Get the JTextComponent associated with this oject.
Notation getNotation ()
 Get notation (scientific, polar, complex).
void setNotation (Notation notation)
 Set notation (scientific, polar, complex).
final java.awt.Insets getFrameInsets ()
 Get the frame Insets.
int graphHeight ()
 Get height for Graph.
int getSizesSize ()
 Get the value of sizes.size().
int getMinSize ()
 Get the value of minimumSize.
boolean getGraphical ()
 Get whether calculator is graphical or not.
void displayGraph ()
 Display a graph;.

Static Public Member Functions

static void main (final String args[])
 Use this to construct a calculator.
static javax.swing.JFrame createFrame (final String args[])
 Actually create a JFrame so that forby using this as an applet, we can use it as a standalone application.

Protected Attributes

javax.swing.JFrame jframe
 Used by CalcButtonApplet and DisplayPanel.

Package Attributes

HistoryItem tempParserList
 If we roll up the history with a half completed expression, we can change our minds and go back to it.
int historyPosition
 where are we in the history list.

Private Member Functions

void setPanels ()
 The calculator buttons are all set on objects of class CalculatorPanel.
void setCalculatorPanel (SpecialButtonType sbt)
 Choose a CalculatorPanel.
double statSize ()
 Used internally in calculations of mean and standard deviation so that we can get these right even when we’ve removed a number.
int getFrameWidth (int mSize)
 Estimate width of panel at given size.
int getFrameHeight (int mSize)
 Estimate height of panel at given size.
void setSizes ()
 Set the allowable range of sizes for the calulator.
void setGraphical (boolean g)
 Set whether calculator is graphical.
void setCaretToEntry ()
 Set Caret to entry.
void setCaretToDisplay ()
 Set Caret to display.

Static Private Member Functions

static void showFrame (final String args[])
 Shows the frame.
static javax.swing.Spring scale (javax.swing.Spring spring, int s)
 javax.swing.Spring doesn’t have a scale function.

Private Attributes

jscicalc.graph.Graph graph
 A graph.
OObject value
 The value of the last expression evaluated.
AngleType angleType
 DEGREES or RADIANS.
int mode
 The MODE.
boolean stat
 Statistics mode or not.
OObject memory
 The calculator’s memory.
java.util.Vector< ComplexstatMemory
 Statistics memory needs to hold multiple values.
java.util.Vector< ComplexstatMemoryNeg
 Statistics memory needs to know if you’ve removed values.
int frameHeight
 The frame height - I think this is redundant because the frame calculates its own height using pack().
CalculatorApplet applet
 If we create a frame, we create an applet, otherwise, this.
DisplayPanel displayPanel
 The view object.
CalculatorPanel calculatorPanel
 The object that contains all the buttons: the input object.
java.util.HashMap
< SpecialButtonType,
CalculatorPanel
calculatorPanels
 More than one input panel so keep track of all of them with an map and enumerated type.
int mSize
 The parameter that determines how much everything is scaled.
Parser parser
 The model object.
boolean shift
 Is shift button pressed?
java.util.Vector< HistoryItemhistory
 The history.
boolean shiftDown
 Used to tell if a modifier key is being held down for shift—I don’t think it actually does anything at the moment.
Notation notation
 Notation.
javax.swing.text.JTextComponent textComponent
 Can be used to attach a text component to the object.
DataTransfer dataTransfer
 Used to Paste from DisplayPanel to system clipboard.
final int minimumSize = 3
 The minimum value of msize.
java.util.Vector< Integer > sizes
 The range of sizes allowed.
boolean graphical
 Used to indicate whether the calculator should be graphical.

Static Private Attributes

static final int bWidth = 23
 Button width.
static final int bHeight = 10
 Button width.
static final int sSize = 3
 Strut size.
static final int dHeight = 30
 Height of DisplayPanel.
static final float bTextSize = 4
 Button text size.
static final float eTextSize = (float)6.4
 EntryPanel text size.
static final float dTextSize = (float)9.2
 DisplayLabel text size.
static final float sTextSize = (float)2.5
 Small text size.
static final int HISTORY_SIZE = 24
 How many events should we store? Change this to suit yourself.
static final java.awt.Color panelColour = java.awt.Color.LIGHT_GRAY
 This is where you change the DisplayPanel colour.
static final long serialVersionUID = 1L

Detailed Description

This class is effectively the controller class for the calculator.

It creates either a frame or an applet with the calculator in it, stores the results of calculations, a history of calculations done and the state of the calculator. Parser model class, in the sense that it stores and evaluates the current expression. The view of the current expression is handled by DisplayPanel and the classes it contains.

If you want to use the calculator as a convenient dialog for calculating values for some JTextComponent, then attach the component with setTextComponent() and detach it if necessary with setTextComponent( null ).

Author:
J. D. Lamb
Version:
Revision:
1.18

Constructor & Destructor Documentation

jscicalc.CalculatorApplet.CalculatorApplet ( String  args[]  ) 

Constructor.

This is the constructor we use for the applet.

Parameters:
args Acceps -g argument for graphical calculator

References jscicalc.CalculatorApplet.applet, and jscicalc.CalculatorApplet.setGraphical().

Referenced by jscicalc.CalculatorApplet.createFrame().


Member Function Documentation

javax.swing.Action jscicalc.CalculatorApplet.backward (  ) 

This was an experimental feature that I couldn’t get to work.

probably it could be removed.

Returns:
An Action

References jscicalc.DisplayPanel.backward(), and jscicalc.CalculatorApplet.displayPanel().

int jscicalc.CalculatorApplet.buttonHeight ( int  minSize  ) 

Find the button height at minSize.

Parameters:
minSize The minimum size used in the display
Returns:
The button height at minSize

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.bHeight.

Referenced by jscicalc.CalculatorPanel.layoutSprings().

int jscicalc.CalculatorApplet.buttonHeight (  ) 

The height of a standard button.

Used by CalculatorPanel objects.

Returns:
Desired height of a standard button.
See also:
CalculatorButton

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.minSize().

Referenced by jscicalc.CalculatorApplet.getFrameHeight().

float jscicalc.CalculatorApplet.buttonTextSize (  ) 

Get the size of text to use on buttons.

Returns:
Desired fontsize for buttons

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.bTextSize, and jscicalc.CalculatorApplet.mSize.

int jscicalc.CalculatorApplet.buttonWidth ( int  minSize  ) 

Find the button width at minSize.

Parameters:
minSize The minimum size used in the display
Returns:
The button width at minSize

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.bWidth.

Referenced by jscicalc.CalculatorPanel.layoutSprings().

int jscicalc.CalculatorApplet.buttonWidth (  ) 

The width of a standard button.

Used by CalculatorPanel objects.

Returns:
Desired width of a standard button.
See also:
CalculatorButton

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.minSize().

Referenced by jscicalc.CalculatorApplet.getFrameWidth().

void jscicalc.CalculatorApplet.clear (  ) 

We use this when we want to clear the expresion in the LCD window.

As usual we delegate this to the view class. The expression doesn’t get cleared until we start typing a new one, which is why we separate this from newexpression().

See also:
DisplayPanel
newExpression()

References jscicalc.DisplayPanel.clear(), jscicalc.CalculatorApplet.displayPanel(), jscicalc.CalculatorApplet.getParser(), jscicalc.CalculatorApplet.parser, and jscicalc.DisplayPanel.setExpression().

Referenced by jscicalc.button.OnButton.actionPerformed().

void jscicalc.CalculatorApplet.clearHistory (  ) 

As you might expect this clears the calculator history.

The only time we use this is when we switch the calculator off. Otherwise we keep a record of the last few expressions together with information about the calculator state (base, degrees or radians, etc.).

References jscicalc.CalculatorApplet.history, and jscicalc.CalculatorApplet.historyPosition.

Referenced by jscicalc.button.OffButton.actionPerformed().

void jscicalc.CalculatorApplet.clearStatMemory (  ) 

Clear statistical memory.

See also:
SclButton

References jscicalc.CalculatorApplet.statMemory, and jscicalc.CalculatorApplet.statMemoryNeg.

Referenced by jscicalc.button.SclButton.actionPerformed().

void jscicalc.CalculatorApplet.copy (  ) 
static javax.swing.JFrame jscicalc.CalculatorApplet.createFrame ( final String  args[]  )  [static]

Actually create a JFrame so that forby using this as an applet, we can use it as a standalone application.

Like init(), this uses setup() to do most of the real work. Additionally it prints out a boilerplate copyright message.

Parameters:
args Acceps -g argument for graphical calculator
Returns:
A JFrame with the calculator in it
See also:
init()
main( String[] )
showFrame()

References jscicalc.CalculatorApplet.CalculatorApplet(), jscicalc.CalculatorApplet.frame(), jscicalc.CalculatorApplet.main(), and jscicalc.CalculatorApplet.setup().

Referenced by jscicalc.CalculatorApplet.showFrame().

void jscicalc.CalculatorApplet.delete (  ) 
void jscicalc.CalculatorApplet.displayGraph (  ) 
int jscicalc.CalculatorApplet.displayHeight ( int  minSize  ) 

Find the display height at minSize.

Parameters:
minSize The minimum size used in the display
Returns:
The display height at minSize

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.dHeight.

Referenced by jscicalc.CalculatorPanel.layoutSprings().

int jscicalc.CalculatorApplet.displayHeight (  ) 

The height of the LCD display in pixels.

Used so that the view can get this information.

Returns:
Desired height of DisplayPanel in pixels.
See also:
DisplayPanel

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.minSize().

Referenced by jscicalc.CalculatorApplet.getFrameHeight().

float jscicalc.CalculatorApplet.displayTextSize (  ) 

Get the size of text to use on the DisplayPanel.This reports the size of text for calculator ‘output’.

Returns:
Desired fontsize for calculator display
See also:
DisplayPanel

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.dTextSize, and jscicalc.CalculatorApplet.mSize.

boolean jscicalc.CalculatorApplet.downHistory (  ) 
float jscicalc.CalculatorApplet.entryTextSize (  ) 

Get the size of text to use on the EntryLabel object.

This is the bit of the DisplayPanel object that’s responsible for showing the current expression.

Returns:
Desired fontsize for the EntryLabel object.
See also:
EntryLabel
DisplayPanel

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.eTextSize, and jscicalc.CalculatorApplet.mSize.

float jscicalc.CalculatorApplet.extraTextSize (  ) 

Get the size of small text to use on the DisplayPanel object.

Small text is for things like “stat”, “radians”, “shift” and the like

Returns:
Desired fontsize for small text
See also:
DisplayPanel

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.mSize, and jscicalc.CalculatorApplet.sTextSize.

void jscicalc.CalculatorApplet.frame ( javax.swing.JFrame  jframe  ) 

Used to set value of jframe.

I can’t remember why we need this, possibly for CalcButtonApplet.

Parameters:
jframe A JFrame

References jscicalc.CalculatorApplet.jframe.

Referenced by jscicalc.CalculatorApplet.createFrame().

javax.swing.JFrame jscicalc.CalculatorApplet.frame (  ) 
AngleType jscicalc.CalculatorApplet.getAngleType (  ) 
Base jscicalc.CalculatorApplet.getBase (  ) 

We work in various bases.

Although numbers are always stored as doubles (i.e. IEE double precision floating point binary representations) so that the Base is essentially just used for formatting and so mainly used by the view, we need to keep a record of base and this is a natural place to keep it, and the Parser object needs to know the base so that it parses numbers entered correctly.

Returns:
The base (default is Base.DECIMAL)

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.Parser.base, and jscicalc.CalculatorApplet.parser.

Referenced by jscicalc.DataTransfer.copy(), jscicalc.CalculatorApplet.downHistory(), jscicalc.CalculatorApplet.pushHistory(), jscicalc.CalculatorApplet.setBase(), jscicalc.CalculatorApplet.setShift(), jscicalc.CalculatorApplet.setup(), and jscicalc.CalculatorApplet.upHistory().

int jscicalc.CalculatorApplet.getFrameHeight ( int  mSize  )  [private]

Estimate height of panel at given size.

Parameters:
mSize The size at which to estimate width
Returns:
An estimate (usually correct) of current frame height at given size

References jscicalc.CalculatorApplet.buttonHeight(), jscicalc.CalculatorApplet.displayHeight(), jscicalc.CalculatorApplet.getFrameInsets(), and jscicalc.CalculatorApplet.strutSize().

Referenced by jscicalc.CalculatorApplet.graphHeight(), and jscicalc.CalculatorApplet.setSizes().

final java.awt.Insets jscicalc.CalculatorApplet.getFrameInsets (  ) 
int jscicalc.CalculatorApplet.getFrameWidth ( int  mSize  )  [private]

Estimate width of panel at given size.

Parameters:
mSize The size at which to estimate wdith
Returns:
An estimate (usually correct) of current frame width at given size

References jscicalc.CalculatorApplet.buttonWidth(), jscicalc.CalculatorApplet.getFrameInsets(), and jscicalc.CalculatorApplet.strutSize().

Referenced by jscicalc.CalculatorApplet.setSizes().

boolean jscicalc.CalculatorApplet.getGraphical (  ) 

Get whether calculator is graphical or not.

Returns:
true or false according as calculator graphical or not

References jscicalc.CalculatorApplet.graphical.

Referenced by jscicalc.ShiftPanel.setButtons(), jscicalc.PlainPanel.setButtons(), and jscicalc.CalculatorPanel.setUp().

OObject jscicalc.CalculatorApplet.getMemory (  ) 
int jscicalc.CalculatorApplet.getMinSize (  ) 

Get the value of minimumSize.

Returns:
the value of minimumSize

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.minimumSize.

int jscicalc.CalculatorApplet.getMode (  ) 
Notation jscicalc.CalculatorApplet.getNotation (  ) 
boolean jscicalc.CalculatorApplet.getOn (  ) 

Tells us if the calculator is switched on.

This is useful in view classes because only this class gets to control such information.

Returns:
true or false according as the calculator is on or off

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.displayPanel(), and jscicalc.DisplayPanel.getOn().

Referenced by jscicalc.button.ModeButton.actionPerformed().

Parser jscicalc.CalculatorApplet.getParser (  ) 

The Parser class is the model that this class controls.

When required, for example, so that we can create a view of the current expression, we use this function to make the Parser object accessible. Ideally it would be final, but it’s convenient to allow CalculatorButton objects to modify the Parser object directly.

Returns:
The Parser object

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.parser.

Referenced by jscicalc.button.STOButton.actionPerformed(), jscicalc.button.SplusButton.actionPerformed(), jscicalc.button.SminusButton.actionPerformed(), jscicalc.button.MplusButton.actionPerformed(), jscicalc.button.MminusButton.actionPerformed(), jscicalc.button.EqualsButton.actionPerformed(), jscicalc.CalculatorApplet.clear(), jscicalc.CalculatorApplet.delete(), and jscicalc.CalculatorApplet.insert().

boolean jscicalc.CalculatorApplet.getShift (  ) 

Tells us if the shift button is down.

Returns:
true or false according as the shift button is down or up

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.shift.

Referenced by jscicalc.CalculatorApplet.setStat().

int jscicalc.CalculatorApplet.getSizesSize (  ) 

Get the value of sizes.size().

Returns:
the value of sizes.size()

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.sizes.

boolean jscicalc.CalculatorApplet.getStat (  ) 
Returns:
true or false according as we are in statistics mode or not.

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.stat.

final javax.swing.text.JTextComponent jscicalc.CalculatorApplet.getTextComponent (  ) 

Get the JTextComponent associated with this oject.

This feature is only useful if you want to attach the calculator to a component, for example to calculate some number for you.

Returns:
The component attached

References jscicalc.CalculatorApplet.textComponent.

OObject jscicalc.CalculatorApplet.getValue (  ) 

This is used internally, but it’s also useful if you want to use the calculator as part of something else.

In fact, the calculator was really originally designed because I couldn’t find a calculator applet that emulated the statistical functions on a standard calculator. So it was really just a part of a bigger applet that made confidence intervals. This function was put in the calculator specifically to allow external access to the calculated value, which when it changed would be transferred to a JTextField on another part of the applet.

Returns:
The value, which should be a Double
See also:
Parser

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.value.

Referenced by jscicalc.button.STOButton.actionPerformed(), jscicalc.button.SplusButton.actionPerformed(), jscicalc.button.SminusButton.actionPerformed(), jscicalc.button.MplusButton.actionPerformed(), jscicalc.button.MminusButton.actionPerformed(), jscicalc.button.EqualsButton.actionPerformed(), jscicalc.button.CalculatorButton.add(), jscicalc.DataTransfer.copy(), jscicalc.CalculatorApplet.displayGraph(), jscicalc.CalculatorApplet.updateDisplay(), and jscicalc.CalculatorApplet.upHistory().

int jscicalc.CalculatorApplet.graphHeight (  ) 
void jscicalc.CalculatorApplet.init (  ) 

Used to construct the applet.

Calls setup to do most of the work.

See also:
setup()

References jscicalc.CalculatorApplet.applet, jscicalc.CalculatorApplet.frame(), and jscicalc.CalculatorApplet.setup().

void jscicalc.CalculatorApplet.insert ( PObject  p  ) 
void jscicalc.CalculatorApplet.keyPressed ( java.awt.event.KeyEvent  keyEvent  ) 

Some keys don’t generate keyTyped Events.

This function handles the arrow keys.

Parameters:
keyEvent The event of key pressed

References jscicalc.CalculatorPanel.buttons, jscicalc.CalculatorApplet.calculatorPanel, jscicalc.CalculatorApplet.copy(), and jscicalc.CalculatorApplet.shiftDown.

void jscicalc.CalculatorApplet.keyReleased ( java.awt.event.KeyEvent  keyEvent  ) 

Some keys don’t generate keyTyped Events.

This function handles the release of the AltGraph key associated with the shift button. As far as I can tell Java 2 doesn’t actually generate an event with this key; so this part of the function is probably redundant. I’ve also implemented a crude hack here to recognise when CTRL-C is pressed and generate a copy-to-clipboard event.

Parameters:
keyEvent The event of key pressed

References jscicalc.DataTransfer.copy(), jscicalc.CalculatorApplet.dataTransfer, and jscicalc.CalculatorApplet.shiftDown.

void jscicalc.CalculatorApplet.keyTyped ( java.awt.event.KeyEvent  keyEvent  ) 

Handle typed keys.

This is how we associate keys to buttons. There are too many buttons to ask each to handle its own (and too much risk of confusion); so we handle them together from a list of buttons generated by CalculatorPanel.

Generally this function just finds which key you typed and uses a map to activate the appropriate button.

Parameters:
keyEvent The event of key typed
See also:
CalculatorPanel.keyMap()

References jscicalc.button.CalculatorButton.actionPerformed(), jscicalc.CalculatorPanel.buttons, jscicalc.CalculatorApplet.calculatorPanel, jscicalc.CalculatorPanel.keyMap, and jscicalc.CalculatorApplet.shift.

void jscicalc.CalculatorApplet.left (  ) 

Moves left through the current expression.

We need this so that expressions are editable.

See also:
LeftButton

References jscicalc.CalculatorApplet.displayPanel(), and jscicalc.DisplayPanel.left().

Referenced by jscicalc.button.LeftButton.actionPerformed().

static void jscicalc.CalculatorApplet.main ( final String  args[]  )  [static]

Use this to construct a calculator.

At the moment the args parameter is completely ignored, though there are some useful possibilities. It would be nice if we could specify the size (minSize) by passing some argument. The MODE button currently allows this and a default is hardcoded.

Parameters:
args Acceps -g argument for graphical calculator

References jscicalc.CalculatorApplet.showFrame().

Referenced by jscicalc.CalculatorApplet.createFrame().

int jscicalc.CalculatorApplet.minSize (  ) 
void jscicalc.CalculatorApplet.newExpression (  ) 
void jscicalc.CalculatorApplet.pushHistory (  ) 
void jscicalc.CalculatorApplet.right (  ) 

Moves right through the current expression.

We need this so that expressions are editable.

See also:
RightButton

References jscicalc.CalculatorApplet.displayPanel(), and jscicalc.DisplayPanel.right().

Referenced by jscicalc.button.RightButton.actionPerformed().

static javax.swing.Spring jscicalc.CalculatorApplet.scale ( javax.swing.Spring  spring,
int  s 
) [static, private]

javax.swing.Spring doesn’t have a scale function.

Although we only use this in CalculatorPanel and its derived classes, we define a scale function here. Why? Originally we used this class to generate Springs. It could probably be moved to CalculatorPanel.

Parameters:
spring A spring
s how much we want to scale the spring: a positive integer - negatives and zero are ignored
See also:
CalculatorPanel
void jscicalc.CalculatorApplet.setAngleType ( AngleType  angleType  ) 

We can work with degrees or radians and this is how we set them.

Does anyone use grads? If so you can ay change AngleType etc, to handle. these.

Parameters:
angleType AngleType.DEGREES or AngleType.RADIANS
See also:
AngleType

Referenced by jscicalc.CalculatorApplet.downHistory(), jscicalc.CalculatorApplet.setMode(), and jscicalc.CalculatorApplet.upHistory().

void jscicalc.CalculatorApplet.setBase ( Base  b  ) 

This is where we set the base.

Used by EqualsButton and its derived classed.

Parameters:
b The base
See also:
EqualsButton
HexButton
BinButton
DecButton
OctButton

References jscicalc.Parser.base, jscicalc.CalculatorApplet.getBase(), jscicalc.CalculatorApplet.parser, and jscicalc.CalculatorApplet.setCalculatorPanel().

Referenced by jscicalc.CalculatorApplet.downHistory(), jscicalc.button.EqualsButton.setBase(), jscicalc.CalculatorApplet.setStat(), jscicalc.CalculatorApplet.setup(), and jscicalc.CalculatorApplet.upHistory().

void jscicalc.CalculatorApplet.setCalculatorPanel ( SpecialButtonType  sbt  )  [private]

Choose a CalculatorPanel.

You would do this in response to a button press. The most obvious one is the shift button, but we also change panels for Stat mode and when changing base.

Parameters:
sbt An enumerated type representing the panel we want

References jscicalc.CalculatorApplet.calculatorPanel, jscicalc.CalculatorApplet.calculatorPanels, and jscicalc.CalculatorPanel.setDisplayPanel().

Referenced by jscicalc.CalculatorApplet.setBase(), jscicalc.CalculatorApplet.setPanels(), and jscicalc.CalculatorApplet.setShift().

void jscicalc.CalculatorApplet.setCaretToDisplay (  )  [private]
void jscicalc.CalculatorApplet.setCaretToEntry (  )  [private]
void jscicalc.CalculatorApplet.setGraphical ( boolean  g  )  [private]

Set whether calculator is graphical.

Parameters:
g true or false according as you want a graphical calculator

References jscicalc.CalculatorApplet.graphical.

Referenced by jscicalc.CalculatorApplet.CalculatorApplet().

void jscicalc.CalculatorApplet.setMemory ( OObject  o  ) 

The calculator can store one value and this is how we do it.

Notice that it allows memory addition and subtraction when used in conjunction with getMemory().

Parameters:
o The value to put into memory
See also:
getMemory()

References jscicalc.CalculatorApplet.memory.

Referenced by jscicalc.button.STOButton.actionPerformed(), jscicalc.button.MplusButton.actionPerformed(), jscicalc.button.MminusButton.actionPerformed(), and jscicalc.button.MclButton.actionPerformed().

void jscicalc.CalculatorApplet.setMinSize ( int  mSize  ) 

An important little function.

This effectively defines the size of the calculator. Values in the range 3-6 seem to work well. The CalculatorApplet object stores this value and uses it to calculate everything else. That way it stays in control of sizes but also allows you to scale the calculator.

Parameters:
mSize A small integer determining the smallest unit used in drawing the calculator

References jscicalc.CalculatorApplet.frame(), jscicalc.CalculatorApplet.graph, and jscicalc.CalculatorApplet.setPanels().

Referenced by jscicalc.CalculatorApplet.setMode().

void jscicalc.CalculatorApplet.setMode ( int  i  ) 
void jscicalc.CalculatorApplet.setMode ( PObject  p  ) 

Sets the mode.

Allows us to change from degrees to radians, change calculator size, set STAT mode on or off. CalculatorButton objects generate PObjects rather than integers; so we pass these and act accordingly. This is not a particularly good piece of code, but there’s not much that can go seriously wrong with it; so I'm not planning to fix it.

Parameters:
p A PObject, generated by a Calculator button during change of mode.

References jscicalc.pobject.Numeral.get(), jscicalc.CalculatorApplet.getMode(), jscicalc.CalculatorApplet.minSize(), jscicalc.CalculatorApplet.mode, jscicalc.pobject.Numeral.name(), jscicalc.CalculatorApplet.setAngleType(), jscicalc.CalculatorApplet.setMinSize(), jscicalc.CalculatorApplet.setMode(), jscicalc.CalculatorApplet.setStat(), jscicalc.CalculatorApplet.sizes, and jscicalc.CalculatorApplet.updateDisplay().

void jscicalc.CalculatorApplet.setNotation ( Notation  notation  ) 

Set notation (scientific, polar, complex).

Parameters:
notation The notation to set

Referenced by jscicalc.CalculatorApplet.downHistory(), and jscicalc.CalculatorApplet.upHistory().

void jscicalc.CalculatorApplet.setOn ( boolean  value  ) 

Called when we set the calculator on or off.

Parameters:
value true for on, false for off.
See also:
OnButton
OffButton

References jscicalc.CalculatorApplet.displayPanel(), and jscicalc.DisplayPanel.setOn().

Referenced by jscicalc.button.OnButton.actionPerformed(), jscicalc.button.OffButton.actionPerformed(), and jscicalc.CalculatorApplet.setup().

void jscicalc.CalculatorApplet.setPanels (  )  [private]

The calculator buttons are all set on objects of class CalculatorPanel.

I tried first changing the buttons according to context, but redoing 40 buttons or so every time you press shift slows the calculator down visibly. So this is the alternative. The panels also take some time to generate and so they are created on separate threads. This allows us to see and start using the calculator while some of the panels are still being constructed.

See also:
CalculatorPanel

References jscicalc.CalculatorApplet.calculatorPanel, jscicalc.CalculatorApplet.calculatorPanels, jscicalc.CalculatorPanel.createPanel(), jscicalc.CalculatorApplet.displayPanel(), jscicalc.CalculatorApplet.panelColour, jscicalc.CalculatorApplet.setCalculatorPanel(), and jscicalc.DisplayPanel.setUp().

Referenced by jscicalc.CalculatorApplet.setMinSize(), and jscicalc.CalculatorApplet.setup().

void jscicalc.CalculatorApplet.setShift ( boolean  value  ) 
void jscicalc.CalculatorApplet.setSizes (  )  [private]
void jscicalc.CalculatorApplet.setStat ( boolean  stat  ) 

Set stat mode on or off.

Parameters:
stat A value: true for stat mode.
See also:
StatPanel
getStat()

References jscicalc.CalculatorApplet.getShift(), jscicalc.CalculatorApplet.setBase(), and jscicalc.CalculatorApplet.setShift().

Referenced by jscicalc.CalculatorApplet.setMode().

void jscicalc.CalculatorApplet.setTextComponent ( javax.swing.text.JTextComponent  textComponent  ) 

This function is useful if you want to attach a JTextComponent such as JTextField to the calculator so that when you calculate a value, it gets transferred to the JTextComponent.

Parameters:
textComponent The component you want to attach

References jscicalc.CalculatorApplet.textComponent.

Referenced by jscicalc.CalculatorApplet.setup().

void jscicalc.CalculatorApplet.setup (  ) 
void jscicalc.CalculatorApplet.setValue ( OObject  o  ) 

when an EqualsButton calculates a value it has to transfer it from the Parser object to this and setValue() is the function we use.

The object should be a Complex, but we can’t represent errors as Complex numbers and it's convenient just to extract what we can as an object and use instanceof to check if needed.

You could modify this function to put a value directly into some other Component. One of the design objectives of the calculator is that you should can use it as part of some applet as a pop up calculator. A better approach might be to use EqualsButton to send the value where you want or to tell the Component to set its value using getValue().

Have a look at CalcButtonApplet if you want to see how you can make the calculator pop up on demand.

Parameters:
o The value (should be gotten from the Parser Object)
See also:
Parser
EqualsButton
getValue()
CalcButtonApplet

References jscicalc.CalculatorApplet.displayPanel(), jscicalc.DisplayPanel.setValue(), and jscicalc.CalculatorApplet.value.

Referenced by jscicalc.button.STOButton.actionPerformed(), jscicalc.button.SplusButton.actionPerformed(), jscicalc.button.SminusButton.actionPerformed(), jscicalc.button.RCLButton.actionPerformed(), jscicalc.button.OnButton.actionPerformed(), jscicalc.button.MminusButton.actionPerformed(), jscicalc.button.EqualsButton.actionPerformed(), jscicalc.button.AnsButton.actionPerformed(), jscicalc.CalculatorApplet.setup(), and jscicalc.CalculatorApplet.upHistory().

static void jscicalc.CalculatorApplet.showFrame ( final String  args[]  )  [static, private]

Shows the frame.

This is used by main to make sure the calculator JFrame is created on the event-dispatching thread if we don’t run it as an applet. I haven’t checked that this all works as it should.

Parameters:
args Acceps -g argument for graphical calculator

References jscicalc.CalculatorApplet.createFrame(), and jscicalc.CalculatorApplet.frame().

Referenced by jscicalc.CalculatorApplet.main().

Complex jscicalc.CalculatorApplet.statAdd ( Complex  d  ) 

Add a Complex to statistical memory.

Statistical memory holds a list of these numbers so that mean, standard deviation and the like can be calcualted at will. The function also returns the number of objects in statistical memory as an Object. An object is used because it conveniently fits what we typically want to do with the return result: display it in the calculator where the expression was evaluated.

Parameters:
d The Complex to put into memory
Returns:
The number of objects in statistical memory.

References jscicalc.CalculatorApplet.statMemory, and jscicalc.CalculatorApplet.statSize().

Mean jscicalc.CalculatorApplet.statMean (  ) 
PopStDev jscicalc.CalculatorApplet.statPopulationStDev (  ) 
StDev jscicalc.CalculatorApplet.statSampleStDev (  ) 
double jscicalc.CalculatorApplet.statSize (  )  [private]

Used internally in calculations of mean and standard deviation so that we can get these right even when we’ve removed a number.

Returns:
The number to use in statistical calculations

References jscicalc.CalculatorApplet.statMemory, and jscicalc.CalculatorApplet.statMemoryNeg.

Referenced by jscicalc.CalculatorApplet.statAdd(), jscicalc.CalculatorApplet.statMean(), jscicalc.CalculatorApplet.statPopulationStDev(), jscicalc.CalculatorApplet.statSampleStDev(), and jscicalc.CalculatorApplet.statSub().

Complex jscicalc.CalculatorApplet.statSub ( Complex  d  ) 

Removes a Complex from statistical memory.

Parameters:
d The Complex to put into memory
Returns:
The number of objects in statistcal memory.
See also:
statAdd( Complex )

References jscicalc.CalculatorApplet.statMemoryNeg, and jscicalc.CalculatorApplet.statSize().

Complex jscicalc.CalculatorApplet.statSumSquares (  ) 
int jscicalc.CalculatorApplet.strutSize (  ) 

If you look at the CalculatorPanel objects, you’ll see that the buttons are grouped.

This defines the width of the gap between groups. CalculatorApplet keep control of such things and this function reports them to CalculatorPanel objects when required.

Returns:
Desired size of button-group separation
See also:
CalculatorPanel

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.minSize().

Referenced by jscicalc.CalculatorApplet.getFrameHeight(), and jscicalc.CalculatorApplet.getFrameWidth().

int jscicalc.CalculatorApplet.strutSize ( int  minSize  ) 

Find the strut size at minSize.

Parameters:
minSize The minimum size used in the display
Returns:
The strut size at minSize

Implements jscicalc.ReadOnlyCalculatorApplet.

References jscicalc.CalculatorApplet.sSize.

Referenced by jscicalc.CalculatorPanel.layoutSprings().

void jscicalc.CalculatorApplet.updateDisplay ( boolean  entry,
boolean  extra 
)

Used to tell the view that we want the display changed, for example, in response to pressing the shift button.

We sometimes want to update the display but not the expression in the EntryLabel object.

Additionally this function will send a copy of the calculated value as a string to any JTextComponent you happen to have attached to the calculator.

Parameters:
entry Set to true or false according as we want the entry label updated or not
extra Designed so that we can specify whether the ExtraPanel object should be updated, but not currently used
See also:
DisplayPanel
EntryLabel

References jscicalc.CalculatorApplet.displayPanel(), jscicalc.CalculatorApplet.getValue(), jscicalc.CalculatorApplet.textComponent, and jscicalc.DisplayPanel.update().

Referenced by jscicalc.button.UpButton.actionPerformed(), jscicalc.button.STOButton.actionPerformed(), jscicalc.button.SplusButton.actionPerformed(), jscicalc.button.SminusButton.actionPerformed(), jscicalc.button.ShiftButton.actionPerformed(), jscicalc.button.SclButton.actionPerformed(), jscicalc.button.SciButton.actionPerformed(), jscicalc.button.RightButton.actionPerformed(), jscicalc.button.RCLButton.actionPerformed(), jscicalc.button.PolButton.actionPerformed(), jscicalc.button.OrigButton.actionPerformed(), jscicalc.button.OnButton.actionPerformed(), jscicalc.button.OffButton.actionPerformed(), jscicalc.button.MplusButton.actionPerformed(), jscicalc.button.ModeButton.actionPerformed(), jscicalc.button.MminusButton.actionPerformed(), jscicalc.button.MclButton.actionPerformed(), jscicalc.button.LeftButton.actionPerformed(), jscicalc.button.GraphButton.actionPerformed(), jscicalc.button.EqualsButton.actionPerformed(), jscicalc.button.DownButton.actionPerformed(), jscicalc.button.DelButton.actionPerformed(), jscicalc.button.CplxButton.actionPerformed(), jscicalc.button.CopyButton.actionPerformed(), jscicalc.button.CalculatorButton.actionPerformed(), jscicalc.button.AnsButton.actionPerformed(), jscicalc.button.CalculatorButton.add(), jscicalc.CalculatorApplet.setMode(), and jscicalc.CalculatorApplet.setup().

void jscicalc.CalculatorApplet.upHistory (  ) 

Member Data Documentation

If we create a frame, we create an applet, otherwise, this.

Referenced by jscicalc.CalculatorApplet.CalculatorApplet(), and jscicalc.CalculatorApplet.init().

final int jscicalc.CalculatorApplet.bHeight = 10 [static, private]

Button width.

Referenced by jscicalc.CalculatorApplet.buttonHeight().

final float jscicalc.CalculatorApplet.bTextSize = 4 [static, private]

Button text size.

Referenced by jscicalc.CalculatorApplet.buttonTextSize().

final int jscicalc.CalculatorApplet.bWidth = 23 [static, private]

Button width.

Referenced by jscicalc.CalculatorApplet.buttonWidth().

More than one input panel so keep track of all of them with an map and enumerated type.

Referenced by jscicalc.CalculatorApplet.setCalculatorPanel(), and jscicalc.CalculatorApplet.setPanels().

final int jscicalc.CalculatorApplet.dHeight = 30 [static, private]
final float jscicalc.CalculatorApplet.dTextSize = (float)9.2 [static, private]
final float jscicalc.CalculatorApplet.eTextSize = (float)6.4 [static, private]

EntryPanel text size.

Referenced by jscicalc.CalculatorApplet.entryTextSize().

The frame height - I think this is redundant because the frame calculates its own height using pack().

Used to indicate whether the calculator should be graphical.

Referenced by jscicalc.CalculatorApplet.getGraphical(), and jscicalc.CalculatorApplet.setGraphical().

java.util.Vector<HistoryItem> jscicalc.CalculatorApplet.history [private]
final int jscicalc.CalculatorApplet.HISTORY_SIZE = 24 [static, private]

How many events should we store? Change this to suit yourself.

Referenced by jscicalc.CalculatorApplet.pushHistory().

javax.swing.JFrame jscicalc.CalculatorApplet.jframe [protected]
final int jscicalc.CalculatorApplet.minimumSize = 3 [private]

The minimum value of msize.

Referenced by jscicalc.CalculatorApplet.getMinSize(), and jscicalc.CalculatorApplet.setSizes().

final java.awt.Color jscicalc.CalculatorApplet.panelColour = java.awt.Color.LIGHT_GRAY [static, private]

This is where you change the DisplayPanel colour.

I haven’t checked that it actually works, but in principle you could have (say) a red or blue calculator if you want.

Referenced by jscicalc.CalculatorApplet.setPanels().

final long jscicalc.CalculatorApplet.serialVersionUID = 1L [static, private]

Used to tell if a modifier key is being held down for shift—I don’t think it actually does anything at the moment.

Referenced by jscicalc.CalculatorApplet.keyPressed(), jscicalc.CalculatorApplet.keyReleased(), and jscicalc.CalculatorApplet.setup().

java.util.Vector<Integer> jscicalc.CalculatorApplet.sizes [private]
final int jscicalc.CalculatorApplet.sSize = 3 [static, private]

Strut size.

Referenced by jscicalc.CalculatorApplet.strutSize().

boolean jscicalc.CalculatorApplet.stat [private]
java.util.Vector<Complex> jscicalc.CalculatorApplet.statMemory [private]
java.util.Vector<Complex> jscicalc.CalculatorApplet.statMemoryNeg [private]
final float jscicalc.CalculatorApplet.sTextSize = (float)2.5 [static, private]

Small text size.

Referenced by jscicalc.CalculatorApplet.extraTextSize().

If we roll up the history with a half completed expression, we can change our minds and go back to it.

Referenced by jscicalc.CalculatorApplet.downHistory(), jscicalc.CalculatorApplet.setup(), and jscicalc.CalculatorApplet.upHistory().

javax.swing.text.JTextComponent jscicalc.CalculatorApplet.textComponent [private]

The value of the last expression evaluated.

Usually a Double unless an error occurred.

Referenced by jscicalc.CalculatorApplet.getValue(), and jscicalc.CalculatorApplet.setValue().


The documentation for this class was generated from the following file: