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

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< Complex > | statMemory |
| Statistics memory needs to hold multiple values. | |
| java.util.Vector< Complex > | statMemoryNeg |
| 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< HistoryItem > | history |
| 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 |
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 ).
| jscicalc.CalculatorApplet.CalculatorApplet | ( | String | args[] | ) |
Constructor.
This is the constructor we use for the applet.
| args | Acceps -g argument for graphical calculator |
References jscicalc.CalculatorApplet.applet, and jscicalc.CalculatorApplet.setGraphical().
Referenced by jscicalc.CalculatorApplet.createFrame().
| javax.swing.Action jscicalc.CalculatorApplet.backward | ( | ) |
This was an experimental feature that I couldn’t get to work.
probably it could be removed.
References jscicalc.DisplayPanel.backward(), and jscicalc.CalculatorApplet.displayPanel().
| int jscicalc.CalculatorApplet.buttonHeight | ( | int | minSize | ) |
Find the button height at minSize.
| minSize | The minimum size used in the display |
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.
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.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.bTextSize, and jscicalc.CalculatorApplet.mSize.
| int jscicalc.CalculatorApplet.buttonWidth | ( | int | minSize | ) |
Find the button width at minSize.
| minSize | The minimum size used in the display |
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.
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().
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.
References jscicalc.CalculatorApplet.statMemory, and jscicalc.CalculatorApplet.statMemoryNeg.
Referenced by jscicalc.button.SclButton.actionPerformed().
| void jscicalc.CalculatorApplet.copy | ( | ) |
Copy from displayPanel to system clipboard.
References jscicalc.DataTransfer.copy(), and jscicalc.CalculatorApplet.dataTransfer.
Referenced by jscicalc.button.CopyButton.actionPerformed(), and jscicalc.CalculatorApplet.keyPressed().
| 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.
| args | Acceps -g argument for graphical calculator |
References jscicalc.CalculatorApplet.CalculatorApplet(), jscicalc.CalculatorApplet.frame(), jscicalc.CalculatorApplet.main(), and jscicalc.CalculatorApplet.setup().
Referenced by jscicalc.CalculatorApplet.showFrame().
| void jscicalc.CalculatorApplet.delete | ( | ) |
Delete at the current caret position.
Delegated to DisplayPanel.
References jscicalc.DisplayPanel.delete(), jscicalc.CalculatorApplet.displayPanel(), and jscicalc.CalculatorApplet.getParser().
Referenced by jscicalc.button.DelButton.actionPerformed().
| void jscicalc.CalculatorApplet.displayGraph | ( | ) |
Display a graph;.
References jscicalc.CalculatorApplet.getValue(), and jscicalc.CalculatorApplet.graph.
Referenced by jscicalc.button.GraphButton.actionPerformed().
| int jscicalc.CalculatorApplet.displayHeight | ( | int | minSize | ) |
Find the display height at minSize.
| minSize | The minimum size used in the display |
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.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.minSize().
Referenced by jscicalc.CalculatorApplet.getFrameHeight().
Designed so that CalculatorPanel and its subclasses can use the displayPanel object as required.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.displayPanel.
Referenced by jscicalc.CalculatorApplet.backward(), jscicalc.CalculatorApplet.clear(), jscicalc.CalculatorApplet.delete(), jscicalc.CalculatorApplet.downHistory(), jscicalc.CalculatorApplet.getOn(), jscicalc.CalculatorApplet.insert(), jscicalc.CalculatorApplet.left(), jscicalc.CalculatorApplet.newExpression(), jscicalc.CalculatorApplet.right(), jscicalc.CalculatorApplet.setCaretToDisplay(), jscicalc.CalculatorApplet.setCaretToEntry(), jscicalc.CalculatorApplet.setOn(), jscicalc.CalculatorApplet.setPanels(), jscicalc.CalculatorApplet.setup(), jscicalc.CalculatorApplet.setValue(), jscicalc.CalculatorApplet.updateDisplay(), and jscicalc.CalculatorApplet.upHistory().
| float jscicalc.CalculatorApplet.displayTextSize | ( | ) |
Get the size of text to use on the DisplayPanel.This reports the size of text for calculator ‘output’.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.dTextSize, and jscicalc.CalculatorApplet.mSize.
| boolean jscicalc.CalculatorApplet.downHistory | ( | ) |
Moves down the history list (if possible).
References jscicalc.HistoryItem.angleType, jscicalc.HistoryItem.base, jscicalc.DisplayPanel.displayLabelScrollable(), jscicalc.CalculatorApplet.displayPanel(), jscicalc.CalculatorApplet.getAngleType(), jscicalc.CalculatorApplet.getBase(), jscicalc.Parser.getList(), jscicalc.CalculatorApplet.getNotation(), jscicalc.CalculatorApplet.history, jscicalc.CalculatorApplet.historyPosition, jscicalc.HistoryItem.list, jscicalc.HistoryItem.notation, jscicalc.CalculatorApplet.parser, jscicalc.CalculatorApplet.setAngleType(), jscicalc.CalculatorApplet.setBase(), jscicalc.CalculatorApplet.setCaretToDisplay(), jscicalc.DisplayPanel.setExpression(), jscicalc.Parser.setList(), jscicalc.CalculatorApplet.setNotation(), and jscicalc.CalculatorApplet.tempParserList.
| 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.
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
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.
| jframe | A JFrame |
References jscicalc.CalculatorApplet.jframe.
Referenced by jscicalc.CalculatorApplet.createFrame().
| javax.swing.JFrame jscicalc.CalculatorApplet.frame | ( | ) |
Another function whose purpose eludes me.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.jframe.
Referenced by jscicalc.CalculatorApplet.createFrame(), jscicalc.CalculatorApplet.init(), jscicalc.CalculatorApplet.setMinSize(), jscicalc.CalculatorApplet.setMode(), and jscicalc.CalculatorApplet.showFrame().
| AngleType jscicalc.CalculatorApplet.getAngleType | ( | ) |
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.angleType.
Referenced by jscicalc.button.CalculatorButton.actionPerformed(), jscicalc.DataTransfer.copy(), jscicalc.CalculatorApplet.downHistory(), jscicalc.CalculatorApplet.pushHistory(), jscicalc.CalculatorApplet.setup(), and jscicalc.CalculatorApplet.upHistory().
| 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.
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.
| mSize | The size at which to estimate width |
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 | ( | ) |
Get the frame Insets.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.jframe.
Referenced by jscicalc.CalculatorApplet.getFrameHeight(), and jscicalc.CalculatorApplet.getFrameWidth().
| int jscicalc.CalculatorApplet.getFrameWidth | ( | int | mSize | ) | [private] |
Estimate width of panel at given size.
| mSize | The size at which to estimate wdith |
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.
References jscicalc.CalculatorApplet.graphical.
Referenced by jscicalc.ShiftPanel.setButtons(), jscicalc.PlainPanel.setButtons(), and jscicalc.CalculatorPanel.setUp().
| OObject jscicalc.CalculatorApplet.getMemory | ( | ) |
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.memory.
Referenced by jscicalc.button.MplusButton.actionPerformed(), and jscicalc.button.MminusButton.actionPerformed().
| int jscicalc.CalculatorApplet.getMinSize | ( | ) |
Get the value of minimumSize.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.minimumSize.
| int jscicalc.CalculatorApplet.getMode | ( | ) |
As you’d expect for something emulating a real calculator, we’d better have a mode button.
This one uses integers rather than enumerated types and you get the current mode with this function.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.mode.
Referenced by 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.RCLButton.actionPerformed(), jscicalc.button.PolButton.actionPerformed(), jscicalc.button.OrigButton.actionPerformed(), jscicalc.button.OnButton.actionPerformed(), jscicalc.button.MplusButton.actionPerformed(), jscicalc.button.MminusButton.actionPerformed(), jscicalc.button.MclButton.actionPerformed(), jscicalc.button.EqualsButton.actionPerformed(), jscicalc.button.DelButton.actionPerformed(), jscicalc.button.CplxButton.actionPerformed(), jscicalc.button.CopyButton.actionPerformed(), jscicalc.button.CalculatorButton.actionPerformed(), jscicalc.button.AnsButton.actionPerformed(), and jscicalc.CalculatorApplet.setMode().
| Notation jscicalc.CalculatorApplet.getNotation | ( | ) |
Get notation (scientific, polar, complex).
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.notation.
Referenced by jscicalc.button.SciButton.actionPerformed(), jscicalc.button.PolButton.actionPerformed(), jscicalc.button.CplxButton.actionPerformed(), jscicalc.CalculatorApplet.downHistory(), jscicalc.CalculatorApplet.pushHistory(), jscicalc.CalculatorApplet.setup(), and jscicalc.CalculatorApplet.upHistory().
| 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.
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.
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.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.shift.
Referenced by jscicalc.CalculatorApplet.setStat().
| int jscicalc.CalculatorApplet.getSizesSize | ( | ) |
Get the value of sizes.size().
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.sizes.
| boolean jscicalc.CalculatorApplet.getStat | ( | ) |
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.
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.
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 | ( | ) |
Get height for Graph.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.getFrameHeight(), jscicalc.CalculatorApplet.jframe, and jscicalc.CalculatorApplet.mSize.
| void jscicalc.CalculatorApplet.init | ( | ) |
Used to construct the applet.
Calls setup to do most of the work.
References jscicalc.CalculatorApplet.applet, jscicalc.CalculatorApplet.frame(), and jscicalc.CalculatorApplet.setup().
| void jscicalc.CalculatorApplet.insert | ( | PObject | p | ) |
Insert at the current caret position.
Delegated to DisplayPanel.
| p | The PObject representing whatever we’re trying to insert |
References jscicalc.CalculatorApplet.displayPanel(), jscicalc.CalculatorApplet.getParser(), and jscicalc.DisplayPanel.insert().
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(), and jscicalc.button.CalculatorButton.add().
| void jscicalc.CalculatorApplet.keyPressed | ( | java.awt.event.KeyEvent | keyEvent | ) |
Some keys don’t generate keyTyped Events.
This function handles the arrow keys.
| 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.
| 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.
| keyEvent | The event of key typed |
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.
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.
| args | Acceps -g argument for graphical calculator |
References jscicalc.CalculatorApplet.showFrame().
Referenced by jscicalc.CalculatorApplet.createFrame().
| int jscicalc.CalculatorApplet.minSize | ( | ) |
If you look at the CalculatorPanel objects, you’ll see that there’s a minimum gap between most objects.
CalculatorApplet keep control of such things and this function reports them to CalculatorPanel objects when required.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.CalculatorApplet.mSize.
Referenced by jscicalc.CalculatorApplet.buttonHeight(), jscicalc.CalculatorApplet.buttonWidth(), jscicalc.CalculatorApplet.displayHeight(), jscicalc.button.DownButton.DownButton(), jscicalc.button.InfoButton.InfoButton(), jscicalc.CalculatorPanel.layoutSprings(), jscicalc.button.LeftButton.LeftButton(), jscicalc.button.RightButton.RightButton(), jscicalc.CalculatorApplet.setMode(), jscicalc.CalculatorApplet.strutSize(), and jscicalc.button.UpButton.UpButton().
| void jscicalc.CalculatorApplet.newExpression | ( | ) |
When we evaluate an expression, we need to create a new one.
This function delegates the job to the DisplayPanel.
References jscicalc.CalculatorApplet.displayPanel(), and jscicalc.DisplayPanel.newExpression().
Referenced by jscicalc.button.STOButton.actionPerformed(), jscicalc.button.SplusButton.actionPerformed(), jscicalc.button.SminusButton.actionPerformed(), jscicalc.button.MplusButton.actionPerformed(), jscicalc.button.MminusButton.actionPerformed(), and jscicalc.button.EqualsButton.actionPerformed().
| void jscicalc.CalculatorApplet.pushHistory | ( | ) |
This is called by EqualsButton and its subclasses and stores an expression in the history list before evaluating it.
This allows the possibility of going back and editing a mistyped expression.
References jscicalc.CalculatorApplet.getAngleType(), jscicalc.CalculatorApplet.getBase(), jscicalc.Parser.getList(), jscicalc.CalculatorApplet.getNotation(), jscicalc.CalculatorApplet.history, jscicalc.CalculatorApplet.HISTORY_SIZE, jscicalc.CalculatorApplet.historyPosition, and 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(), and jscicalc.button.EqualsButton.actionPerformed().
| void jscicalc.CalculatorApplet.right | ( | ) |
Moves right through the current expression.
We need this so that expressions are editable.
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.
| spring | A spring | |
| s | how much we want to scale the spring: a positive integer - negatives and zero are ignored |
| 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.
| angleType | AngleType.DEGREES or AngleType.RADIANS |
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.
| b | The base |
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.
| 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] |
Set Caret to display.
References jscicalc.CalculatorApplet.displayPanel(), and jscicalc.DisplayPanel.setCaretToDisplay().
Referenced by jscicalc.CalculatorApplet.downHistory().
| void jscicalc.CalculatorApplet.setCaretToEntry | ( | ) | [private] |
Set Caret to entry.
References jscicalc.CalculatorApplet.displayPanel(), and jscicalc.DisplayPanel.setCaretToEntry().
Referenced by jscicalc.CalculatorApplet.upHistory().
| void jscicalc.CalculatorApplet.setGraphical | ( | boolean | g | ) | [private] |
Set whether calculator is graphical.
| 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().
| o | The value to put into memory |
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.
| 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 | ) |
Sets the mode.
Allows us to change from degrees to radians, change calculator size, set STAT mode on or off.
| i | The new mode: it’s forced into the right range even if you give an illegal value. |
References jscicalc.CalculatorApplet.frame(), jscicalc.CalculatorApplet.mode, and jscicalc.CalculatorApplet.sizes.
Referenced by 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.RCLButton.actionPerformed(), jscicalc.button.PolButton.actionPerformed(), jscicalc.button.OrigButton.actionPerformed(), jscicalc.button.OnButton.actionPerformed(), jscicalc.button.MplusButton.actionPerformed(), jscicalc.button.ModeButton.actionPerformed(), jscicalc.button.MminusButton.actionPerformed(), jscicalc.button.MclButton.actionPerformed(), jscicalc.button.EqualsButton.actionPerformed(), jscicalc.button.DelButton.actionPerformed(), jscicalc.button.CplxButton.actionPerformed(), jscicalc.button.CopyButton.actionPerformed(), jscicalc.button.CalculatorButton.actionPerformed(), jscicalc.button.AnsButton.actionPerformed(), and jscicalc.CalculatorApplet.setMode().
| 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.
| 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).
| 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.
| value | true for on, false for off. |
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.
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 | ) |
Set the shift button to pressed or unpressed.
Obviously, it will be called by ShiftButton, but it’s also called when a shifted key is pressed and on some other occasions.
| value | true or false according as the shift button is pressed or not. |
References jscicalc.CalculatorApplet.getBase(), jscicalc.CalculatorApplet.setCalculatorPanel(), jscicalc.CalculatorApplet.shift, and jscicalc.CalculatorApplet.stat.
Referenced by 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.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.GraphButton.actionPerformed(), jscicalc.button.EqualsButton.actionPerformed(), jscicalc.button.CplxButton.actionPerformed(), jscicalc.button.CopyButton.actionPerformed(), jscicalc.button.CalculatorButton.actionPerformed(), jscicalc.button.AnsButton.actionPerformed(), and jscicalc.CalculatorApplet.setStat().
| void jscicalc.CalculatorApplet.setSizes | ( | ) | [private] |
Set the allowable range of sizes for the calulator.
These are the values that mSize may take.
References jscicalc.CalculatorApplet.getFrameHeight(), jscicalc.CalculatorApplet.getFrameWidth(), jscicalc.CalculatorApplet.jframe, jscicalc.CalculatorApplet.minimumSize, jscicalc.CalculatorApplet.mSize, and jscicalc.CalculatorApplet.sizes.
Referenced by jscicalc.CalculatorApplet.setup().
| void jscicalc.CalculatorApplet.setStat | ( | boolean | stat | ) |
Set stat mode on or off.
| stat | A value: true for stat mode. |
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.
| textComponent | The component you want to attach |
References jscicalc.CalculatorApplet.textComponent.
Referenced by jscicalc.CalculatorApplet.setup().
| void jscicalc.CalculatorApplet.setup | ( | ) |
This sets up the calculator for either the applet of the standalone application.
I’m not sure why the function is public because it probably should be private.
References jscicalc.CalculatorApplet.angleType, jscicalc.CalculatorApplet.calculatorPanel, jscicalc.CalculatorApplet.dataTransfer, jscicalc.CalculatorApplet.displayPanel(), jscicalc.CalculatorApplet.getAngleType(), jscicalc.CalculatorApplet.getBase(), jscicalc.CalculatorApplet.getNotation(), jscicalc.CalculatorApplet.graph, jscicalc.CalculatorApplet.history, jscicalc.CalculatorApplet.historyPosition, jscicalc.CalculatorApplet.memory, jscicalc.CalculatorApplet.mode, jscicalc.CalculatorApplet.notation, jscicalc.CalculatorApplet.parser, jscicalc.CalculatorApplet.setBase(), jscicalc.CalculatorApplet.setOn(), jscicalc.CalculatorApplet.setPanels(), jscicalc.CalculatorApplet.setSizes(), jscicalc.CalculatorApplet.setTextComponent(), jscicalc.CalculatorApplet.setValue(), jscicalc.CalculatorApplet.shift, jscicalc.CalculatorApplet.shiftDown, jscicalc.CalculatorApplet.stat, jscicalc.CalculatorApplet.statMemory, jscicalc.CalculatorApplet.statMemoryNeg, jscicalc.CalculatorApplet.tempParserList, and jscicalc.CalculatorApplet.updateDisplay().
Referenced by jscicalc.CalculatorApplet.createFrame(), and jscicalc.CalculatorApplet.init().
| 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.
| o | The value (should be gotten from the Parser Object) |
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.
| args | Acceps -g argument for graphical calculator |
References jscicalc.CalculatorApplet.createFrame(), and jscicalc.CalculatorApplet.frame().
Referenced by jscicalc.CalculatorApplet.main().
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.
| d | The Complex to put into memory |
References jscicalc.CalculatorApplet.statMemory, and jscicalc.CalculatorApplet.statSize().
| Mean jscicalc.CalculatorApplet.statMean | ( | ) |
Calculate the mean value.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.complex.Complex.add(), jscicalc.complex.Complex.divide(), jscicalc.pobject.Mean.setError(), jscicalc.pobject.Mean.setValue(), jscicalc.CalculatorApplet.statMemory, jscicalc.CalculatorApplet.statMemoryNeg, jscicalc.CalculatorApplet.statSize(), and jscicalc.complex.Complex.subtract().
Referenced by jscicalc.CalculatorApplet.statSumSquares().
| PopStDev jscicalc.CalculatorApplet.statPopulationStDev | ( | ) |
Calculate the population standard deviation.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.complex.Complex.divide(), jscicalc.pobject.PopStDev.setError(), jscicalc.pobject.PopStDev.setValue(), jscicalc.complex.Complex.sqrt(), jscicalc.CalculatorApplet.statSize(), and jscicalc.CalculatorApplet.statSumSquares().
| StDev jscicalc.CalculatorApplet.statSampleStDev | ( | ) |
Calculate the sample standard deviation.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.complex.Complex.divide(), jscicalc.pobject.StDev.setError(), jscicalc.pobject.StDev.setValue(), jscicalc.complex.Complex.sqrt(), jscicalc.CalculatorApplet.statSize(), and jscicalc.CalculatorApplet.statSumSquares().
| 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.
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().
Removes a Complex from statistical memory.
| d | The Complex to put into memory |
References jscicalc.CalculatorApplet.statMemoryNeg, and jscicalc.CalculatorApplet.statSize().
| Complex jscicalc.CalculatorApplet.statSumSquares | ( | ) |
Calculate sum of squares - used in standard deviation/variance calculations.
Implements jscicalc.ReadOnlyCalculatorApplet.
References jscicalc.complex.Complex.add(), jscicalc.pobject.Container.error, jscicalc.complex.Complex.square(), jscicalc.CalculatorApplet.statMean(), jscicalc.CalculatorApplet.statMemory, jscicalc.CalculatorApplet.statMemoryNeg, jscicalc.complex.Complex.subtract(), and jscicalc.pobject.Container.value().
Referenced by jscicalc.CalculatorApplet.statPopulationStDev(), and jscicalc.CalculatorApplet.statSampleStDev().
| 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.
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.
| minSize | The minimum size used in the display |
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.
| 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 |
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 | ( | ) |
Moves up the history list (if possible).
CalculatorApplet maintains a list of previously evaluated expressions and this function allows you to move backward through them. It’s called by UpButton and is particularly useful if you want to reedit some expression.
References jscicalc.HistoryItem.angleType, jscicalc.HistoryItem.base, jscicalc.DisplayPanel.displayLabelHasCaret(), jscicalc.CalculatorApplet.displayPanel(), jscicalc.CalculatorApplet.getAngleType(), jscicalc.CalculatorApplet.getBase(), jscicalc.Parser.getList(), jscicalc.CalculatorApplet.getNotation(), jscicalc.CalculatorApplet.getValue(), jscicalc.CalculatorApplet.history, jscicalc.CalculatorApplet.historyPosition, jscicalc.HistoryItem.list, jscicalc.HistoryItem.notation, jscicalc.CalculatorApplet.parser, jscicalc.CalculatorApplet.setAngleType(), jscicalc.CalculatorApplet.setBase(), jscicalc.CalculatorApplet.setCaretToEntry(), jscicalc.DisplayPanel.setExpression(), jscicalc.Parser.setList(), jscicalc.CalculatorApplet.setNotation(), jscicalc.CalculatorApplet.setValue(), and jscicalc.CalculatorApplet.tempParserList.
Referenced by jscicalc.button.UpButton.actionPerformed().
AngleType jscicalc.CalculatorApplet.angleType [private] |
DEGREES or RADIANS.
Referenced by jscicalc.CalculatorApplet.getAngleType(), and jscicalc.CalculatorApplet.setup().
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().
The object that contains all the buttons: the input object.
Referenced by jscicalc.CalculatorApplet.keyPressed(), jscicalc.CalculatorApplet.keyTyped(), jscicalc.CalculatorApplet.setCalculatorPanel(), jscicalc.CalculatorApplet.setPanels(), and jscicalc.CalculatorApplet.setup().
java.util.HashMap<SpecialButtonType,CalculatorPanel> jscicalc.CalculatorApplet.calculatorPanels [private] |
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().
Used to Paste from DisplayPanel to system clipboard.
Referenced by jscicalc.CalculatorApplet.copy(), jscicalc.CalculatorApplet.keyReleased(), and jscicalc.CalculatorApplet.setup().
final int jscicalc.CalculatorApplet.dHeight = 30 [static, private] |
Height of DisplayPanel.
Referenced by jscicalc.CalculatorApplet.displayHeight().
The view object.
Referenced by jscicalc.CalculatorApplet.displayPanel(), and jscicalc.CalculatorPanel.setDisplayPanel().
final float jscicalc.CalculatorApplet.dTextSize = (float)9.2 [static, private] |
DisplayLabel text size.
Referenced by jscicalc.CalculatorApplet.displayTextSize().
final float jscicalc.CalculatorApplet.eTextSize = (float)6.4 [static, private] |
EntryPanel text size.
Referenced by jscicalc.CalculatorApplet.entryTextSize().
int jscicalc.CalculatorApplet.frameHeight [private] |
The frame height - I think this is redundant because the frame calculates its own height using pack().
A graph.
Initially null.
Referenced by jscicalc.CalculatorApplet.displayGraph(), jscicalc.CalculatorApplet.setMinSize(), and jscicalc.CalculatorApplet.setup().
boolean jscicalc.CalculatorApplet.graphical [private] |
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().
int jscicalc.CalculatorApplet.historyPosition [package] |
where are we in the history list.
Referenced by jscicalc.CalculatorApplet.clearHistory(), jscicalc.CalculatorApplet.downHistory(), jscicalc.CalculatorApplet.pushHistory(), jscicalc.CalculatorApplet.setup(), and jscicalc.CalculatorApplet.upHistory().
javax.swing.JFrame jscicalc.CalculatorApplet.jframe [protected] |
OObject jscicalc.CalculatorApplet.memory [private] |
The calculator’s memory.
Referenced by jscicalc.CalculatorApplet.getMemory(), jscicalc.CalculatorApplet.setMemory(), and jscicalc.CalculatorApplet.setup().
final int jscicalc.CalculatorApplet.minimumSize = 3 [private] |
The minimum value of msize.
Referenced by jscicalc.CalculatorApplet.getMinSize(), and jscicalc.CalculatorApplet.setSizes().
int jscicalc.CalculatorApplet.mode [private] |
The MODE.
Referenced by jscicalc.CalculatorApplet.getMode(), jscicalc.CalculatorApplet.setMode(), and jscicalc.CalculatorApplet.setup().
int jscicalc.CalculatorApplet.mSize [private] |
The parameter that determines how much everything is scaled.
Referenced by jscicalc.CalculatorApplet.buttonTextSize(), jscicalc.CalculatorApplet.displayTextSize(), jscicalc.CalculatorApplet.entryTextSize(), jscicalc.CalculatorApplet.extraTextSize(), jscicalc.CalculatorApplet.graphHeight(), jscicalc.CalculatorApplet.minSize(), and jscicalc.CalculatorApplet.setSizes().
Notation jscicalc.CalculatorApplet.notation [private] |
Referenced by jscicalc.CalculatorApplet.getNotation(), and jscicalc.CalculatorApplet.setup().
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().
Parser jscicalc.CalculatorApplet.parser [private] |
The model object.
It parses expressions and is actually the real power behind the calculator. Nearly everything else is just interface.
Referenced by jscicalc.CalculatorApplet.clear(), jscicalc.CalculatorApplet.downHistory(), jscicalc.CalculatorApplet.getBase(), jscicalc.CalculatorApplet.getParser(), jscicalc.CalculatorApplet.pushHistory(), jscicalc.CalculatorApplet.setBase(), jscicalc.CalculatorApplet.setup(), and jscicalc.CalculatorApplet.upHistory().
final long jscicalc.CalculatorApplet.serialVersionUID = 1L [static, private] |
boolean jscicalc.CalculatorApplet.shift [private] |
Is shift button pressed?
Referenced by jscicalc.CalculatorApplet.getShift(), jscicalc.CalculatorApplet.keyTyped(), jscicalc.CalculatorApplet.setShift(), and jscicalc.CalculatorApplet.setup().
boolean jscicalc.CalculatorApplet.shiftDown [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] |
The range of sizes allowed.
Referenced by jscicalc.CalculatorApplet.getSizesSize(), jscicalc.CalculatorApplet.setMode(), and jscicalc.CalculatorApplet.setSizes().
final int jscicalc.CalculatorApplet.sSize = 3 [static, private] |
Strut size.
Referenced by jscicalc.CalculatorApplet.strutSize().
boolean jscicalc.CalculatorApplet.stat [private] |
Statistics mode or not.
Referenced by jscicalc.CalculatorApplet.getStat(), jscicalc.CalculatorApplet.setShift(), and jscicalc.CalculatorApplet.setup().
java.util.Vector<Complex> jscicalc.CalculatorApplet.statMemory [private] |
Statistics memory needs to hold multiple values.
Referenced by jscicalc.CalculatorApplet.clearStatMemory(), jscicalc.CalculatorApplet.setup(), jscicalc.CalculatorApplet.statAdd(), jscicalc.CalculatorApplet.statMean(), jscicalc.CalculatorApplet.statSize(), and jscicalc.CalculatorApplet.statSumSquares().
java.util.Vector<Complex> jscicalc.CalculatorApplet.statMemoryNeg [private] |
Statistics memory needs to know if you’ve removed values.
Referenced by jscicalc.CalculatorApplet.clearStatMemory(), jscicalc.CalculatorApplet.setup(), jscicalc.CalculatorApplet.statMean(), jscicalc.CalculatorApplet.statSize(), jscicalc.CalculatorApplet.statSub(), and jscicalc.CalculatorApplet.statSumSquares().
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] |
Can be used to attach a text component to the object.
Referenced by jscicalc.CalculatorApplet.getTextComponent(), jscicalc.CalculatorApplet.setTextComponent(), and jscicalc.CalculatorApplet.updateDisplay().
OObject jscicalc.CalculatorApplet.value [private] |
The value of the last expression evaluated.
Usually a Double unless an error occurred.
Referenced by jscicalc.CalculatorApplet.getValue(), and jscicalc.CalculatorApplet.setValue().
1.7.1