puzzled.grid
Class GridCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--puzzled.grid.GridCanvas
All Implemented Interfaces:
javax.accessibility.Accessible, Constants, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable

public class GridCanvas
extends javax.swing.JPanel
implements Constants, java.awt.print.Printable

The canvas class represent the graphical display of the grid, and the relationships between the various items. A reference to an object of this class is kept by the Grid object.

Version:
1.0 26 Aug 99
Author:
Frédéric Demers
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface puzzled.Constants
ACTION_TOKEN, AND_TOKEN, AND_TOKENS, IS_ACTION, IS_TOKEN, IS_TOKENS, ISNOT_ACTION, JUNCTION_TOKEN, LESS_ACTION, LESS_TOKEN, LESS_TOKENS, MORE_ACTION, MORE_TOKEN, MORE_TOKENS, NEXT_ACTION, NEXT_TOKEN, NEXT_TOKENS, NO_ACTION, NOR_TOKEN, NOT_TOKEN, NOT_TOKENS, NOT_VALID, NOTNEXT_ACTION, NOTNEXT_TOKEN, NUMBER_TOKEN, NUMBER_TOKENS, OR_ACTION, OR_TOKEN, OR_TOKENS, PREVIOUS_CLUE_TOKEN, RESET_TOKEN, THAN_TOKEN, TO_TOKEN, VALUE_NO, VALUE_UNKNOWN, VALUE_YES
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GridCanvas(ProblemSolver parent_arg, Grid myGrid_arg)
          Constructor.
 
Method Summary
 void addRelation(Relation rel)
          Method used to add a relationship to the relationship vector.
 void drawGrid(java.awt.Graphics2D g2)
          Draws the grid.
 void drawRelationship(java.awt.Graphics2D g2, Relation rel)
          Method used to draw a relationship given as parameter.
 void paintComponent(java.awt.Graphics g)
          Overriden method which is invoked when the component needs to be repainted.
 int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int pi)
          Prints the current GridCanvas on the printer.
 void reset()
          Method used to remove all relations and redraw a plain grid.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GridCanvas

public GridCanvas(ProblemSolver parent_arg,
                  Grid myGrid_arg)
Constructor. Receive the required information as parameter, and creates the GridCanvas with the proper dimensions, which depend on the size of the problem. The painting is automatical- ly called when added to the scrollpane, where the paintCompo- nent method is called.
Parameters:
catNumber_arg - The number of categories.
itemNumber_arg - The number of items per category.
categories - Array representing the names of the categories.
items - 2D array representing the names of the items.
Method Detail

drawGrid

public void drawGrid(java.awt.Graphics2D g2)
Draws the grid. A series of for loops is being used after the top and side headers are drawn. Consideration is given for the category separators with respect to thickness and color. This method is called from the paintComponent method, which passes its graphics (Graphics2D) context as a parameter. It also paints the string representing the names of the categories and the items.
Parameters:
g2 - The graphic contexts used to draw the grid.

paintComponent

public void paintComponent(java.awt.Graphics g)
Overriden method which is invoked when the component needs to be repainted. It involves a grid painting (drawGrid) following drawing of all the know relationships (contained in a vector. (The other way would not work because of the multiple translations/rotations done in the drawGrid method.
Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - The graphic context used to draw the grid.

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pf,
                 int pi)
          throws java.awt.print.PrinterException
Prints the current GridCanvas on the printer. In order to do so, we must first find the upper left and lower right corners of the single line diagram printed on this Woksheet. Then we scale the single line diagram in both width and height, using the maximum scaling value for both, in in order to keep the same aspect ratio. Once this is done, the single line diagram is rotated 90 degress in order to be printed in landscape format. we also have to move the diagram to the right by the same value as the height.
Specified by:
print in interface java.awt.print.Printable
Parameters:
g - the graphics context
pf - the page format
pi - page index

drawRelationship

public void drawRelationship(java.awt.Graphics2D g2,
                             Relation rel)
Method used to draw a relationship given as parameter. The relation is given with a value a coordinates allowing to locate the exact location of the relationship symbol. A circle represent a definite match, and an X represent a definite no-match.
Parameters:
g2 - The graphic context used to draw the symbol.
rel - The reference to the relation to be drawn. See class Relation.

addRelation

public void addRelation(Relation rel)
Method used to add a relationship to the relationship vector. It is called by the grid's equivalent method, which takes care of the logical consequences. This method is only responsible for representing the graphical symbol where appropriate.
Parameters:
rel - The relationship that needs to be represented.

reset

public void reset()
Method used to remove all relations and redraw a plain grid.