jscicalc.DisplayPanel Class Reference

This class is responsible for the LCD-like display in the calculator. More...

Inheritance diagram for jscicalc.DisplayPanel:

jscicalc.ReadOnlyDisplayPanel
Collaboration diagram for jscicalc.DisplayPanel:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 DisplayPanel (final ReadOnlyCalculatorApplet applet)
 The constructor takes a ReadOnlyCalculatorApplet so that it has an interface to the CalculatorApplet object.
void setUp ()
 Set up the panel.
void paintComponent (java.awt.Graphics graphics)
 This probably does nothing.
void left ()
 Used by CalculatorApplet in response to a LeftButton Action to ask the EntryLabel to move the caret on place left.
void right ()
 Used by CalculatorApplet in response to a RightButton Action to ask the EntryLabel to move the caret on place right.
void update (boolean entry, boolean extra)
 Updates the panel.
javax.swing.Action backward ()
 This was designed to collect an Action so we could move the Caret from within the CalculatorApplet, but I couldn’t get it to work so used left() instead.
void setExpression (Parser parser)
 Set the current expression.
void newExpression ()
 Sets a new expression in EntryLabel.
void clear (Parser parser)
 Clears the current expression and the Parser.
void delete (Parser parser)
 Deletes the PObject at the current Caret position.
void insert (PObject p, Parser parser)
 Inserts a PObject at the current Caret position.
void setOn (boolean value)
 Set state (on/off).
boolean getOn ()
 Get state (on/off).
void setValue ()
 Set the diplayLabel value to match the OObject in the applet.
ReadOnlyCalculatorApplet getApplet ()
 Get an interface for the CalculatorApplet object.
final DisplayLabel getDisplayLabel ()
 Udes by CalculatorApplet to get DisplayLabel.
void setCaretToEntry ()
 Set Caret to entry.
void setCaretToDisplay ()
 Set Caret to display.
boolean hasCaret (final ScrollableLabel scrollableLabel)
 Find if scrollableLabel has the Caret.
boolean displayLabelHasCaret ()
 Find if displayLabel has the Caret.

Package Functions

final boolean displayLabelScrollable ()
 Find if it is possible to scroll within the display label.

Private Attributes

ScrollableLabel labelWithCaret
EntryLabel entryLabel
 The entry label: shows what you’ve typed.
DisplayLabel displayLabel
 The display label: shows results of calculations.
ExtraPanel extraPanel
 The panel that shows calculator state: shift, Stat mode, degrees or radians, Base and the like.
MiniPanel leftPanel
 Panel to show left movement of display is possible.
MiniPanel rightPanel
 Panel to show right movement of display is possible.
final ReadOnlyCalculatorApplet applet
 Interface to the CalculatorApplet object that allows us to read values but not to change their state.
boolean on
 State of calculator on or off.

Static Private Attributes

static final long serialVersionUID = 1L


Detailed Description

This class is responsible for the LCD-like display in the calculator.

When a particular CalculatorPanel is made current by CalculatorApplet.setDisplayPanel() through CalculatorPanel.setDisplayPanel() the instance of this class is attached to the the CalculatorPanel. I’m not sure if this is handled entirely correctly yet because the DisplayPanel has actually been added to more than one CalculatorPanel, which I think swing doesn’t permit. However, it works provided we reattach it.

Author:
J. D. Lamb
Version:
Revision
1.8

Constructor & Destructor Documentation

jscicalc.DisplayPanel.DisplayPanel ( final ReadOnlyCalculatorApplet  applet  ) 

The constructor takes a ReadOnlyCalculatorApplet so that it has an interface to the CalculatorApplet object.

It doesn’t need to can modify the CalculatorApplet object and so it doesn’t need access to all members. Forby, despite its general moralistic tendencies, Java doesn’t let you specify that an object is const.

Parameters:
applet The CalculatorApplet object (accessed through a read-only interface)

References jscicalc.DisplayPanel.displayLabel, jscicalc.DisplayPanel.entryLabel, jscicalc.DisplayPanel.extraPanel, jscicalc.DisplayPanel.leftPanel, jscicalc.DisplayPanel.rightPanel, and jscicalc.DisplayPanel.setCaretToEntry().


Member Function Documentation

void jscicalc.DisplayPanel.setUp (  ) 

void jscicalc.DisplayPanel.paintComponent ( java.awt.Graphics  graphics  ) 

This probably does nothing.

I’m not quite sure I've got this right. I'm trying to make sure the background is always white: probably even that should be replaced by a specified colour stored in CalculatorApplet.

Parameters:
graphics The graphics context required.

void jscicalc.DisplayPanel.left (  ) 

Used by CalculatorApplet in response to a LeftButton Action to ask the EntryLabel to move the caret on place left.

It’s important CalculatorApplet controls this as it’s the only thing that can read the Parser and so know whether the caret can move left.

References jscicalc.DisplayPanel.labelWithCaret, and jscicalc.ScrollableLabel.left().

Referenced by jscicalc.CalculatorApplet.left().

void jscicalc.DisplayPanel.right (  ) 

Used by CalculatorApplet in response to a RightButton Action to ask the EntryLabel to move the caret on place right.

It’s important CalculatorApplet controls this as it’s the only thing that can read the Parser and so know whether the caret can move right.

References jscicalc.DisplayPanel.labelWithCaret, and jscicalc.ScrollableLabel.right().

Referenced by jscicalc.CalculatorApplet.right().

void jscicalc.DisplayPanel.update ( boolean  entry,
boolean  extra 
)

Updates the panel.

The second parameter is not used but in principle could let us update only the EntryPanel and not the ExtraPanel. We sometimes don’t want to update the EntryPanel immediately. For example, when we evaluate an expression, we clear the expression in the parser but wait until we start typing a new expression before updating the EntryPanel.

Parameters:
entry Should we update EntryPanel?
extra Should we update ExtraPanel? (ignored anyway)

References jscicalc.BOTH, jscicalc.DisplayPanel.displayLabel, jscicalc.DisplayPanel.displayLabelHasCaret(), jscicalc.DisplayPanel.entryLabel, jscicalc.DisplayPanel.extraPanel, jscicalc.DisplayLabel.getScrollDirections(), jscicalc.LEFT, jscicalc.DisplayPanel.leftPanel, jscicalc.NEITHER, jscicalc.DisplayPanel.on, jscicalc.RIGHT, jscicalc.DisplayPanel.rightPanel, jscicalc.MiniPanel.setIlluminated(), jscicalc.DisplayLabel.update(), and jscicalc.EntryLabel.update().

Referenced by jscicalc.CalculatorApplet.updateDisplay().

final boolean jscicalc.DisplayPanel.displayLabelScrollable (  )  [package]

Find if it is possible to scroll within the display label.

Returns:
true or false according as we can or cannot scroll the display label

References jscicalc.DisplayPanel.displayLabel, and jscicalc.DisplayLabel.getScrollDirections().

Referenced by jscicalc.CalculatorApplet.downHistory().

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

This was designed to collect an Action so we could move the Caret from within the CalculatorApplet, but I couldn’t get it to work so used left() instead.

Returns:
An Action: move Caret left

References jscicalc.EntryLabel.backward(), and jscicalc.DisplayPanel.entryLabel.

Referenced by jscicalc.CalculatorApplet.backward().

void jscicalc.DisplayPanel.setExpression ( Parser  parser  ) 

Set the current expression.

We pass a Parser because this class shouldn’t access the Parser object directly.

Parameters:
parser The Parser, which contains the expression

References jscicalc.DisplayPanel.entryLabel, and jscicalc.EntryLabel.setExpression().

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

void jscicalc.DisplayPanel.newExpression (  ) 

Sets a new expression in EntryLabel.

This doesn’t immediately clear the old expression but does disable Caret movements.

References jscicalc.DisplayPanel.entryLabel, and jscicalc.ScrollableLabel.newExpression.

Referenced by jscicalc.CalculatorApplet.newExpression().

void jscicalc.DisplayPanel.clear ( Parser  parser  ) 

Clears the current expression and the Parser.

Probably it should only clear the expression because CalculatorApplet should be the only object changing the state of the parser.

Parameters:
parser The Parser, which contains the expression

References jscicalc.EntryLabel.clear(), and jscicalc.DisplayPanel.entryLabel.

Referenced by jscicalc.CalculatorApplet.clear().

void jscicalc.DisplayPanel.delete ( Parser  parser  ) 

Deletes the PObject at the current Caret position.

Probably it should only change the expression because CalculatorApplet should be the only object changing the state of the parser.

Parameters:
parser The Parser, which contains the expression

References jscicalc.EntryLabel.delete(), and jscicalc.DisplayPanel.entryLabel.

Referenced by jscicalc.CalculatorApplet.delete().

void jscicalc.DisplayPanel.insert ( PObject  p,
Parser  parser 
)

Inserts a PObject at the current Caret position.

Probably it should only change the expression because CalculatorApplet should be the only object changing the state of the parser.

Parameters:
p The PObject: typically generated by a CalculatorButton
parser The Parser, which contains the expression

References jscicalc.DisplayPanel.entryLabel, and jscicalc.EntryLabel.insert().

Referenced by jscicalc.CalculatorApplet.insert().

void jscicalc.DisplayPanel.setOn ( boolean  value  ) 

Set state (on/off).

Probably should always get this state from CalculatorApplet because the states should match.

Parameters:
value true for on, false for off.

References jscicalc.DisplayPanel.on.

Referenced by jscicalc.CalculatorApplet.setOn().

boolean jscicalc.DisplayPanel.getOn (  ) 

Get state (on/off).

Probably should always get this state from CalculatorApplet because the states should match.

Returns:
true for on, false for off.

Implements jscicalc.ReadOnlyDisplayPanel.

References jscicalc.DisplayPanel.on.

Referenced by jscicalc.CalculatorApplet.getOn().

void jscicalc.DisplayPanel.setValue (  ) 

Set the diplayLabel value to match the OObject in the applet.

References jscicalc.DisplayPanel.displayLabel, and jscicalc.DisplayLabel.setNewExpression().

Referenced by jscicalc.CalculatorApplet.setValue().

ReadOnlyCalculatorApplet jscicalc.DisplayPanel.getApplet (  ) 

Get an interface for the CalculatorApplet object.

Returns:
an interface for the CalculatorApplet object.

Implements jscicalc.ReadOnlyDisplayPanel.

References jscicalc.DisplayPanel.applet.

Referenced by jscicalc.DisplayPanel.setUp().

final DisplayLabel jscicalc.DisplayPanel.getDisplayLabel (  ) 

void jscicalc.DisplayPanel.setCaretToEntry (  ) 

void jscicalc.DisplayPanel.setCaretToDisplay (  ) 

boolean jscicalc.DisplayPanel.hasCaret ( final ScrollableLabel  scrollableLabel  ) 

Find if scrollableLabel has the Caret.

This allows us to query the interface and find whether EntryPanel or DisplayPanel has permission to display a Caret

Parameters:
scrollableLabel The Scrollable label we wish to know about
Returns:
true or false according as scrollableLabel has or has not permission to show a Caret

Implements jscicalc.ReadOnlyDisplayPanel.

References jscicalc.DisplayPanel.labelWithCaret.

Referenced by jscicalc.DisplayPanel.displayLabelHasCaret().

boolean jscicalc.DisplayPanel.displayLabelHasCaret (  ) 

Find if displayLabel has the Caret.

This allows us to query the interface and find whether EntryPanel or DisplayPanel has permission to display a Caret

Returns:
true or false according as displayLabel has or has not permission to show a Caret

References jscicalc.DisplayPanel.displayLabel, and jscicalc.DisplayPanel.hasCaret().

Referenced by jscicalc.DisplayPanel.update(), and jscicalc.CalculatorApplet.upHistory().


Member Data Documentation

The panel that shows calculator state: shift, Stat mode, degrees or radians, Base and the like.

Referenced by jscicalc.DisplayPanel.DisplayPanel(), jscicalc.DisplayPanel.setUp(), and jscicalc.DisplayPanel.update().

Panel to show left movement of display is possible.

Referenced by jscicalc.DisplayPanel.DisplayPanel(), jscicalc.DisplayPanel.setUp(), and jscicalc.DisplayPanel.update().

Panel to show right movement of display is possible.

Referenced by jscicalc.DisplayPanel.DisplayPanel(), jscicalc.DisplayPanel.setUp(), and jscicalc.DisplayPanel.update().

Interface to the CalculatorApplet object that allows us to read values but not to change their state.

Referenced by jscicalc.DisplayPanel.getApplet().

boolean jscicalc.DisplayPanel.on [private]

State of calculator on or off.

This should be removed because only the CalculatorApplet should have this information.

Referenced by jscicalc.DisplayPanel.getOn(), jscicalc.DisplayPanel.setOn(), and jscicalc.DisplayPanel.update().

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


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

Generated on Sun Jun 1 08:57:41 2008 for Java Scientific Calculator by  doxygen 1.5.5