cafe.gui
Class GuiMain

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by cafe.gui.GuiMain
All Implemented Interfaces:
UserInterface, ViewEventInterface, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants

public class GuiMain
extends javax.swing.JFrame
implements UserInterface, ViewEventInterface

Graphical User Interface's main class. This class is the only class in the GUI component that is connected with the rest of the system. It manages most of the program logic in the gui, by changing views and reacting to events.

Version:
0.9
Author:
Joni Lahtinen, Markus Penttila
See Also:
Serialized Form

Field Summary
static javax.swing.border.Border DEFAULT_BORDER
          Default thin black border used around panels.
static java.awt.Dimension DEFAULT_BUTTON_SIZE
          Size for navigation buttons
static java.awt.Color DEFAULT_COLOR
          Default background color (yellowish)
static javax.swing.border.Border DEFAULT_MARGINS
          A 10 px margin of the same color as the backgroud grey is, used as spacer between frame border and content panel.
static int FINGER_MAX_INDEX
          Maximum index of fingers, corresponding to little finger.
static int FINGER_MIN_INDEX
          Minimum index of fingers, corresponding to thumb.
static java.awt.Dimension GROUP_SCROLL_ARROW_SIZE
          Size for product group scrolling buttons
static java.awt.Dimension LANGUAGE_BUTTON_SIZE
          Size for language change button
static int NO_FINGER_SET
          Constant for indicating that no finger has been selected.
static int NO_FINGERPRINT_SET
          Constant for indicating that a fingerprint is not set on a certain finger.
static java.awt.Dimension PRODUCT_SCROLL_ARROW_SIZE
          Size for product list scrolling buttons
 
Fields inherited from class javax.swing.JFrame
EXIT_ON_CLOSE
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GuiMain()
          Default constructor.
GuiMain(GUISettings guiSettings, UserInterfaceEvent userInterfaceEvent)
          Constructs the GUI and sets it to the start/title view.
 
Method Summary
 void addAlert()
          Confirms that an alert should be added to the currently selected product in the alert view.
 void addFingerprint(int id)
          Adds the fingerprint given as an argument to the current user's currently selected finger if a finger is selected and the GUI is in "waiting for a new fingerprint" state.
 void addingFingerprint(int finger)
          Sets the GUI to fingerprint insert mode, so that it waits for a fingerprint to the finger that is given as a parameter.
 void alertProduct(ImportProduct product)
          Sets the product given as argument as the currently selected product in alert adding view.
 void authenticatedUser(UserInfo user, int fingerprintid)
          Sets the user given as an argument as the current user and changes to the product export view.
 void authenticateUser(java.lang.String username, java.lang.String password)
          Authenticates the user based on the username and password given as an argument.
 void buyProduct(ExportProduct product)
          Debits the product given as an arugement from the current user's account.
 void cancelFingerprintAdd()
          Cancels fingerprint insert mode and returns to normal mode.
 void cancelLastAction()
          Cancels the previous product export transaction from the currently logged on user.
 void changeAlertView()
          Changes the current view to add product alert view
 void changeConfigView()
          Changes the current view to "my settings" view
 void changeImportView()
          Changes the current view to product import view
 void changeLanguage()
          Changes the current language and resets/redraws the current view
 void changeRegisterView()
          Changes the current view to the new user registration view.
 void changeShopView()
          Changes the current view to product export view
 void changeStartView()
          Changes the current view to start view (title screen), saves user data if a user is logged on and logs user out.
 void confirmImport(ImportProduct product, double amount)
          Credits user's account with the value of the import product of a certain size given as an argument.
 void continueProgram()
          This method restores the GUI in its normal state, if it is in error state.
 double getBalance(java.lang.String[] productGroup)
          Returns logged on user's balance in given product group.
 LanguageEnum getCurrentLanguage()
          Gets the current language used in the GUI
 int getErrorTimeout()
          Gets the time to show "finger not recognized" error message.
 java.lang.String getFirstAndLastName()
          Gets current user's first and last name.
 GuiMain getGuiMain()
           
 java.lang.String getGuiText(java.lang.String id)
          Gets the text/string corresponding to the id in the current language.
 int getIdleTimeout()
          Gets the time to wait until automatic logout, if user doesn't do anything.
 javax.swing.ImageIcon getLanguageImage()
          Gets the icon (country flag) used as a symbol for the current language.
 int getPayTimeout()
          Gets the time to wait until automatic debit of export product, if user doesn't make any other choices.
 void groupSelected()
          Stops the countdown timer in import view when a product group is selected.
 void importProduct(ImportProduct product, double amount)
          Sets the currently selected product in import view.
 boolean isCancelAllowed()
          Gets the info about if the user is allowed to cancel previous export transaction.
 void logoutTimerExpired()
          A view in the user interface can use this to logout the current user after a certain time of inactivity has expired.
 void productSelected(ExportProduct product)
          Sets the currently selected export product either in export product view or config view (meaning favorite product selection).
 void removeAlert(ImportProduct product)
          Removes product alert from the product given as parameter
 void setFavoriteProduct(ExportProduct product)
          Sets the current user's favorite product.
 void setUserName(java.lang.String givenName, java.lang.String familyName)
          Sets current user's first and family name
 void stopForProblem(java.lang.String problemStringId)
          This method puts the GUI in a error state where users cannot do anything else but change the language.
 boolean unknownUser()
          Shows an error message if current view is the title (start) view and the GUI is not waiting for a new fingerprint.
 
Methods inherited from class javax.swing.JFrame
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

DEFAULT_COLOR

public static final java.awt.Color DEFAULT_COLOR
Default background color (yellowish)


DEFAULT_BORDER

public static final javax.swing.border.Border DEFAULT_BORDER
Default thin black border used around panels.


DEFAULT_MARGINS

public static final javax.swing.border.Border DEFAULT_MARGINS
A 10 px margin of the same color as the backgroud grey is, used as spacer between frame border and content panel.


DEFAULT_BUTTON_SIZE

public static final java.awt.Dimension DEFAULT_BUTTON_SIZE
Size for navigation buttons


LANGUAGE_BUTTON_SIZE

public static final java.awt.Dimension LANGUAGE_BUTTON_SIZE
Size for language change button


PRODUCT_SCROLL_ARROW_SIZE

public static final java.awt.Dimension PRODUCT_SCROLL_ARROW_SIZE
Size for product list scrolling buttons


GROUP_SCROLL_ARROW_SIZE

public static final java.awt.Dimension GROUP_SCROLL_ARROW_SIZE
Size for product group scrolling buttons


FINGER_MIN_INDEX

public static final int FINGER_MIN_INDEX
Minimum index of fingers, corresponding to thumb.

See Also:
Constant Field Values

FINGER_MAX_INDEX

public static final int FINGER_MAX_INDEX
Maximum index of fingers, corresponding to little finger.

See Also:
Constant Field Values

NO_FINGERPRINT_SET

public static final int NO_FINGERPRINT_SET
Constant for indicating that a fingerprint is not set on a certain finger.

See Also:
Constant Field Values

NO_FINGER_SET

public static final int NO_FINGER_SET
Constant for indicating that no finger has been selected.

See Also:
Constant Field Values
Constructor Detail

GuiMain

public GuiMain(GUISettings guiSettings,
               UserInterfaceEvent userInterfaceEvent)
Constructs the GUI and sets it to the start/title view.

Parameters:
guiSettings - Properties for the gui component.
userInterfaceEvent - Interface used to communicate with the rest of the system.

GuiMain

public GuiMain()
Default constructor. Sets the look & feel and window properties.

Method Detail

authenticatedUser

public void authenticatedUser(UserInfo user,
                              int fingerprintid)
Sets the user given as an argument as the current user and changes to the product export view. If there is a different user already logged on, logs that user out and saves that user's data. If GUI is waiting for a new fingerprint and the fingerprint given as an argument belongs to the current user, add's the fingerprint to currently selected fingerprint and does not logout current user.

Specified by:
authenticatedUser in interface UserInterface
Parameters:
user - user's information
fingerprintid - the id of the fingerprint that was recognized

unknownUser

public boolean unknownUser()
Shows an error message if current view is the title (start) view and the GUI is not waiting for a new fingerprint. If it is waiting for a print, this only returns true.

Specified by:
unknownUser in interface UserInterface
Returns:
true if GUI is currently waiting for a new fingerprint, false if not

addFingerprint

public void addFingerprint(int id)
Adds the fingerprint given as an argument to the current user's currently selected finger if a finger is selected and the GUI is in "waiting for a new fingerprint" state. If there already was a fingerprint set on the selected finger and that print is no longer needed, it gets deleted.

Specified by:
addFingerprint in interface UserInterface
Parameters:
id - id of the new fingerprint
Throws:
java.lang.IllegalStateException - When there is no user currently logged on or GUI is not waiting for a fingerprint.

stopForProblem

public void stopForProblem(java.lang.String problemStringId)
This method puts the GUI in a error state where users cannot do anything else but change the language. An error message is displayed on the screen.

Specified by:
stopForProblem in interface UserInterface
Parameters:
problemStringId - name of the string to be displayed (corresponding to a name of a string in the language files, e.g. finnish.xml)

continueProgram

public void continueProgram()
This method restores the GUI in its normal state, if it is in error state. Used when the problem causing the error has been resolved.

Specified by:
continueProgram in interface UserInterface

changeStartView

public void changeStartView()
Changes the current view to start view (title screen), saves user data if a user is logged on and logs user out.

Specified by:
changeStartView in interface ViewEventInterface

changeShopView

public void changeShopView()
Changes the current view to product export view

Specified by:
changeShopView in interface ViewEventInterface
Throws:
java.lang.IllegalStateException - When there is no user currently logged on.

changeImportView

public void changeImportView()
Changes the current view to product import view

Specified by:
changeImportView in interface ViewEventInterface
Throws:
java.lang.IllegalStateException - When there is no user currently logged on.

changeConfigView

public void changeConfigView()
Changes the current view to "my settings" view

Specified by:
changeConfigView in interface ViewEventInterface
Throws:
java.lang.IllegalStateException - When there is no user currently logged on.

changeAlertView

public void changeAlertView()
Changes the current view to add product alert view

Specified by:
changeAlertView in interface ViewEventInterface

changeRegisterView

public void changeRegisterView()
Changes the current view to the new user registration view.

Specified by:
changeRegisterView in interface ViewEventInterface

changeLanguage

public void changeLanguage()
Changes the current language and resets/redraws the current view

Specified by:
changeLanguage in interface ViewEventInterface

getGuiText

public java.lang.String getGuiText(java.lang.String id)
Gets the text/string corresponding to the id in the current language.

Specified by:
getGuiText in interface ViewEventInterface
Parameters:
id - name of the string to get. Valid string names are those defined in the language XML files (e.g. finnish.xml).
Returns:
the GUI string in current language

importProduct

public void importProduct(ImportProduct product,
                          double amount)
Sets the currently selected product in import view.

Specified by:
importProduct in interface ViewEventInterface
Parameters:
product - the selected import product
amount - the selected amount/size of the product

confirmImport

public void confirmImport(ImportProduct product,
                          double amount)
Credits user's account with the value of the import product of a certain size given as an argument.

Specified by:
confirmImport in interface ViewEventInterface
Parameters:
product - the product user wants to import
amount - the selected import amount/size
Throws:
java.lang.IllegalStateException - When there is no user currently logged on.

setFavoriteProduct

public void setFavoriteProduct(ExportProduct product)
Sets the current user's favorite product.

Specified by:
setFavoriteProduct in interface ViewEventInterface
Parameters:
product - the export product to set as the favorite
Throws:
java.lang.IllegalStateException - When there is no user currently logged on.

addAlert

public void addAlert()
Confirms that an alert should be added to the currently selected product in the alert view.

Specified by:
addAlert in interface ViewEventInterface

authenticateUser

public void authenticateUser(java.lang.String username,
                             java.lang.String password)
Authenticates the user based on the username and password given as an argument. If the authentication is successful, the view is changed to config view. If the user is a new user, with given and family name not set, textfields for entering them are shown instead. If the authentication was not successful, an error message indicating this is shown.

Specified by:
authenticateUser in interface ViewEventInterface
Parameters:
username - username to use in the authentication
password - password to use in the authentication

setUserName

public void setUserName(java.lang.String givenName,
                        java.lang.String familyName)
Sets current user's first and family name

Specified by:
setUserName in interface ViewEventInterface
Parameters:
givenName - user's given name
familyName - user's family name
Throws:
java.lang.IllegalStateException - When there is no user currently logged on.

buyProduct

public void buyProduct(ExportProduct product)
Debits the product given as an arugement from the current user's account.

Specified by:
buyProduct in interface ViewEventInterface
Parameters:
product - the product to export/debit
Throws:
java.lang.IllegalStateException - When there is no user currently logged on.

productSelected

public void productSelected(ExportProduct product)
Sets the currently selected export product either in export product view or config view (meaning favorite product selection). In export product view this selected product will be debited from user's account if user accept's the debit or the debit timer counts down to zero.

Specified by:
productSelected in interface ViewEventInterface
Parameters:
product - the selected product

removeAlert

public void removeAlert(ImportProduct product)
Removes product alert from the product given as parameter

Specified by:
removeAlert in interface ViewEventInterface
Parameters:
product - the product to remove the alert from

getCurrentLanguage

public LanguageEnum getCurrentLanguage()
Gets the current language used in the GUI

Specified by:
getCurrentLanguage in interface ViewEventInterface
Returns:
the current language

getLanguageImage

public javax.swing.ImageIcon getLanguageImage()
Gets the icon (country flag) used as a symbol for the current language.

Specified by:
getLanguageImage in interface ViewEventInterface
Returns:
icon for the current language

addingFingerprint

public void addingFingerprint(int finger)
Sets the GUI to fingerprint insert mode, so that it waits for a fingerprint to the finger that is given as a parameter.

Specified by:
addingFingerprint in interface ViewEventInterface
Parameters:
finger - the finger to wait the fingerprint for, from 0-4, where 0 means thumb and 4 means little finger.
Throws:
java.lang.IllegalArgumentException - When fingerprint index is not between 0 and 4.

cancelFingerprintAdd

public void cancelFingerprintAdd()
Cancels fingerprint insert mode and returns to normal mode.

Specified by:
cancelFingerprintAdd in interface ViewEventInterface

cancelLastAction

public void cancelLastAction()
Cancels the previous product export transaction from the currently logged on user.

Specified by:
cancelLastAction in interface ViewEventInterface
Throws:
java.lang.IllegalStateException - When there is no user currently logged on or cancel is not allowed.

alertProduct

public void alertProduct(ImportProduct product)
Sets the product given as argument as the currently selected product in alert adding view. When the alert is accepted by the user, an alert will be set to this product in the database.

Specified by:
alertProduct in interface ViewEventInterface
Parameters:
product - product that has been selected for alert adding

getBalance

public double getBalance(java.lang.String[] productGroup)
Returns logged on user's balance in given product group.

Specified by:
getBalance in interface ViewEventInterface
Parameters:
productGroup - the product group
Returns:
user's balance in the given product group
Throws:
java.lang.IllegalStateException - When there is no user currently logged on.

isCancelAllowed

public boolean isCancelAllowed()
Gets the info about if the user is allowed to cancel previous export transaction.

Specified by:
isCancelAllowed in interface ViewEventInterface
Returns:
true if cancelling is allowed, false if not
Throws:
java.lang.IllegalStateException - When there is no user currently logged on.

logoutTimerExpired

public void logoutTimerExpired()
A view in the user interface can use this to logout the current user after a certain time of inactivity has expired.

Specified by:
logoutTimerExpired in interface ViewEventInterface

getIdleTimeout

public int getIdleTimeout()
Gets the time to wait until automatic logout, if user doesn't do anything. Time is set in the main settings file.

Specified by:
getIdleTimeout in interface ViewEventInterface
Returns:
the time to wait

getPayTimeout

public int getPayTimeout()
Gets the time to wait until automatic debit of export product, if user doesn't make any other choices. Time is set in the main settings file.

Specified by:
getPayTimeout in interface ViewEventInterface
Returns:
the time to wait

getErrorTimeout

public int getErrorTimeout()
Gets the time to show "finger not recognized" error message. Time is set in the main settings file.

Specified by:
getErrorTimeout in interface ViewEventInterface
Returns:
the time to show the message

getFirstAndLastName

public java.lang.String getFirstAndLastName()
Gets current user's first and last name.

Specified by:
getFirstAndLastName in interface ViewEventInterface
Returns:
first and last name in the form "firstname lastname"
Throws:
java.lang.IllegalStateException - When there is no user currently logged on.

groupSelected

public void groupSelected()
Stops the countdown timer in import view when a product group is selected.

Specified by:
groupSelected in interface ViewEventInterface

getGuiMain

public GuiMain getGuiMain()
Specified by:
getGuiMain in interface ViewEventInterface