Class SubscriptionSystem

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 SubscriptionSystem
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.KeyListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants

public class SubscriptionSystem
extends javax.swing.JFrame
implements java.awt.event.ActionListener, java.awt.event.KeyListener

This class provides a minimalistic user interface to our the business logic layer of our subscription system. This logic layer is provided by the class ApplicationLogic in the package Subscription.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private static java.lang.String ADD
           
private  ApplicationLogic appLogic
          Here is the variable holding the underlying business logic.
private static java.lang.String ARG_INCOMPL
           
private static java.lang.String CLEAR
           
private static java.lang.String CLN
           
private static java.lang.String COLLON
           
private static java.lang.String COMMA
           
private  javax.swing.JTextField commandField
           
private  java.util.List<java.lang.String> commandHistory
           
private static java.lang.String CUST
           
private static java.lang.String DONE
           
private static java.lang.String HELP
           
private  int historyCursor
           
private static java.lang.String PASS_PINT
           
private static java.lang.String REMOVE
           
private  javax.swing.JScrollPane scrollpane
           
private static java.lang.String SERVICE
           
private static java.lang.String SHOW
           
private static java.lang.String SUBSCRIPTION
           
private static java.lang.String TAB
           
private  javax.swing.JTextArea textArea
           
private static int TEXTWIDTH
           
private static java.lang.String UNKNOWN_COMMAND
           
private static java.lang.String UNKNOWN_SELECTOR
           
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
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
SubscriptionSystem()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          This reacts to the command typed in the command box.
private  void addCustomer(java.lang.String name, java.lang.String email)
          Implementing the command for adding a new customer.
private  void addService(java.lang.String name, java.lang.String price)
          Implementing a command to add a new service.
private  void addSubscription(java.lang.String custID, java.lang.String serviceID)
          Implementing a command to add a new subscription.
private  void clear()
          Implementing the command to clear the screen.
private  void commandInterpreter(java.lang.String input)
          This interpret the commands, and calls the right functions based on the given command.
private  void echo(java.lang.String s)
           
private  void help()
          Implementing the command for printing help to the screen.
 void keyPressed(java.awt.event.KeyEvent e)
          React to arrow-up and arrow-down in the command box to scroll through commands history.
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
static void main(java.lang.String[] args)
          The main method that will launch this application.
private  java.lang.String padLeft(java.lang.String s, int width)
           
private  java.lang.String padRight(java.lang.String s, int width)
           
private static java.lang.Integer parseInt(java.lang.String i)
           
private  void removeCustomer(java.lang.String id)
          Implementing a command to remove a customer.
private  void removeService(java.lang.String id)
          Implementing a command to remove a service.
private  void removeSubscription(java.lang.String id)
          Implementing a command to remove a subscription.
private  void showAllCustomers()
          Implementing the command for showing all customers.
private  void showAllServices()
          Implementing the command for showing all services.
private  void showSubscriptions(java.lang.String custID)
          Implementing the command for showing the data of a particular customer.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, 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, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, 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, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

ADD

private static final java.lang.String ADD
See Also:
Constant Field Values

appLogic

private ApplicationLogic appLogic
Here is the variable holding the underlying business logic.


ARG_INCOMPL

private static final java.lang.String ARG_INCOMPL
See Also:
Constant Field Values

CLEAR

private static final java.lang.String CLEAR
See Also:
Constant Field Values

CLN

private static final java.lang.String CLN
See Also:
Constant Field Values

COLLON

private static final java.lang.String COLLON
See Also:
Constant Field Values

COMMA

private static final java.lang.String COMMA
See Also:
Constant Field Values

commandField

private javax.swing.JTextField commandField

commandHistory

private java.util.List<java.lang.String> commandHistory

CUST

private static final java.lang.String CUST
See Also:
Constant Field Values

DONE

private static final java.lang.String DONE
See Also:
Constant Field Values

HELP

private static final java.lang.String HELP
See Also:
Constant Field Values

historyCursor

private int historyCursor

PASS_PINT

private static final java.lang.String PASS_PINT
See Also:
Constant Field Values

REMOVE

private static final java.lang.String REMOVE
See Also:
Constant Field Values

scrollpane

private javax.swing.JScrollPane scrollpane

SERVICE

private static final java.lang.String SERVICE
See Also:
Constant Field Values

SHOW

private static final java.lang.String SHOW
See Also:
Constant Field Values

SUBSCRIPTION

private static final java.lang.String SUBSCRIPTION
See Also:
Constant Field Values

TAB

private static final java.lang.String TAB
See Also:
Constant Field Values

textArea

private javax.swing.JTextArea textArea

TEXTWIDTH

private static int TEXTWIDTH

UNKNOWN_COMMAND

private static final java.lang.String UNKNOWN_COMMAND
See Also:
Constant Field Values

UNKNOWN_SELECTOR

private static final java.lang.String UNKNOWN_SELECTOR
See Also:
Constant Field Values
Constructor Detail

SubscriptionSystem

public SubscriptionSystem()
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
This reacts to the command typed in the command box.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

addCustomer

private void addCustomer(java.lang.String name,
                         java.lang.String email)
Implementing the command for adding a new customer.


addService

private void addService(java.lang.String name,
                        java.lang.String price)
Implementing a command to add a new service. Price is a yearly price of that service in euro-cent.


addSubscription

private void addSubscription(java.lang.String custID,
                             java.lang.String serviceID)
Implementing a command to add a new subscription. The arguments are the id of the customer that gets the subscription, and the id of the service he subscribes to.


clear

private void clear()
Implementing the command to clear the screen.


commandInterpreter

private void commandInterpreter(java.lang.String input)
This interpret the commands, and calls the right functions based on the given command. It also handles error messaging.


echo

private void echo(java.lang.String s)

help

private void help()
Implementing the command for printing help to the screen.


keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
React to arrow-up and arrow-down in the command box to scroll through commands history. (Yes we have that too! :)

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

main

public static void main(java.lang.String[] args)
The main method that will launch this application.


padLeft

private java.lang.String padLeft(java.lang.String s,
                                 int width)

padRight

private java.lang.String padRight(java.lang.String s,
                                  int width)

parseInt

private static java.lang.Integer parseInt(java.lang.String i)

removeCustomer

private void removeCustomer(java.lang.String id)
Implementing a command to remove a customer.


removeService

private void removeService(java.lang.String id)
Implementing a command to remove a service.


removeSubscription

private void removeSubscription(java.lang.String id)
Implementing a command to remove a subscription.


showAllCustomers

private void showAllCustomers()
Implementing the command for showing all customers.


showAllServices

private void showAllServices()
Implementing the command for showing all services.


showSubscriptions

private void showSubscriptions(java.lang.String custID)
Implementing the command for showing the data of a particular customer.