cz.cuni.mff.mirovsky.trees
Class NGForestView

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by cz.cuni.mff.mirovsky.trees.NGForestView
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
NGForestDisplay, NGForestPrint

public class NGForestView
extends javax.swing.JComponent

A base class for forest viewing (displaying on a screen, printing on a printer)

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int font_size
          the size of the font used for labels of nodes
protected  NGForest forest
          a forest to be viewed
protected  int forest_height
          the height of the forest (in pixels)
protected  int forest_width
          the width of the forest (in pixels)
protected  int horizontal_space
          horizontal distance between trees in the forest
protected  java.lang.String kodovany
          an auxiliary variable for printing strings
protected  int posunuti_textu_doleva
          labels of nodes will be shifted this amount to the left in order to have their first character just below the node
protected  javax.swing.DefaultListModel reference_patterns
          reference patterns
protected  boolean show_hidden_nodes
          controls whether hidden nodes should be displayed
protected  NGTreeProperties tree_properties
          viewing properties of forests
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
NGForestView(ShowMessagesAble mess)
          Creates an object needed for viewing trees (on a screen or a printer)
 
Method Summary
 void addTree(NGTree tree)
          Adds a tree to be viewed.
protected  void debug(java.lang.String message)
          Displays a debugging message.
protected  java.awt.Color determineColor(TNode node, ReferencePattern pattern, java.lang.String value_depend_value)
          Sets the color for printing a reference.
protected  void drawDescription(java.awt.Graphics g, java.lang.String description, int x, int y)
          Draws one attribute as a part of a label of a node.
protected  void drawTree(NGTree tree, TNode n, TNode parent, int otec_x, int otec_y, java.awt.Graphics2D g2)
          Draws one tree of the forest.
 boolean getEmphasizeChosenNode()
          Returns whether the selected node is set to be emphasized
 boolean getFlagForestChanged()
          Says whether the forest has changed and coordinates of (some of) its trees and their nodes must be calculated.
 int getFontSize()
          Returns the font size for labels at nodes.
 NGForest getForest()
          Gets the forest to be viewed.
 int getForestHeight()
          Returns the height of the forest (in pixels)
 int getForestWidth()
          Returns the width of the forest (in pixels)
 java.awt.Rectangle getMatchingNodesRectangle()
          Returns a rectangle that surrounds all matching nodes in the forest.
 javax.swing.DefaultListModel getReferencePatterns()
          Returns a list of reference patterns
 boolean getShowHiddenNodes()
          Returns whether the hidden nodes are set to be shown
 NGTreeProperties getTreeProperties()
          Returns the properties of the tree.
 boolean changeReferenceStatus(int i)
          Changes the state of (non-)displaying the i-th reference
protected  void inform(java.lang.String message)
          Displays an informative message.
 void paintComponent(java.awt.Graphics g)
          Paints the forest.
 void printChosen(java.awt.Graphics2D g, NGTreeProperties properties)
          Emphasizes the selected node.
protected  void printReferences(java.awt.Graphics2D g2)
          Prints all references in the actual forest.
 void setEmphasizeChosenNode(boolean emphasize)
          Sets whether the selected node should be emphasized
 void setFlagWholeForestChanged(boolean flag)
          Signals whether the whole forest has changed and coordinates of all its trees and their nodes must be calculated.
 void setFontSize(int size)
          Sets the font size for labels at nodes.
 void setForest(NGForest forest)
          Sets a forest to be viewed.
protected  void setGlobalProperties()
          Sets some global variables according to the actual tree propertis
 void setHorizontalSpace(int space)
          Sets the horizontal space between trees in the forest.
 void setChosenNodeByDepthOrder(int order)
          Marks a node with given order as selected, as well as the tree the node is from.
 void setReferencePatterns(javax.swing.DefaultListModel patterns)
          Sets the reference patterns.
 void setShowHiddenNodes(boolean show)
          Sets whether or not the hidden nodes should be shown
 void setTree(NGTree tree)
          Sets a single tree to be viewed.
 void setTreeProperties(NGTreeProperties new_properties)
          Sets properties of the tree.
protected  java.lang.String truncLemma(java.lang.String orig_lemma, int trunc_type)
          PDT-related function that truncates a lemma.
 void vypocti_nakresleni(java.awt.Graphics g)
          It calculates coordinates of all nodes of all trees in the forest.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printComponent, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, checkImage, checkImage, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

forest

protected NGForest forest
a forest to be viewed


tree_properties

protected NGTreeProperties tree_properties
viewing properties of forests


reference_patterns

protected javax.swing.DefaultListModel reference_patterns
reference patterns


forest_width

protected int forest_width
the width of the forest (in pixels)


forest_height

protected int forest_height
the height of the forest (in pixels)


show_hidden_nodes

protected boolean show_hidden_nodes
controls whether hidden nodes should be displayed


kodovany

protected java.lang.String kodovany
an auxiliary variable for printing strings


posunuti_textu_doleva

protected int posunuti_textu_doleva
labels of nodes will be shifted this amount to the left in order to have their first character just below the node


font_size

protected int font_size
the size of the font used for labels of nodes


horizontal_space

protected int horizontal_space
horizontal distance between trees in the forest

Constructor Detail

NGForestView

public NGForestView(ShowMessagesAble mess)
Creates an object needed for viewing trees (on a screen or a printer)

Parameters:
mess - an object capable of displaying messages
Method Detail

debug

protected void debug(java.lang.String message)
Displays a debugging message.

Parameters:
message - a message to be displayed

inform

protected void inform(java.lang.String message)
Displays an informative message.

Parameters:
message - a message to be displayed

getForestWidth

public int getForestWidth()
Returns the width of the forest (in pixels)

Returns:
the width of the forest (in pixels)

getForestHeight

public int getForestHeight()
Returns the height of the forest (in pixels)

Returns:
the height of the forest (in pixels)

setHorizontalSpace

public void setHorizontalSpace(int space)
Sets the horizontal space between trees in the forest.

Parameters:
space - the horizontal space in pixels

getMatchingNodesRectangle

public java.awt.Rectangle getMatchingNodesRectangle()
Returns a rectangle that surrounds all matching nodes in the forest.

Returns:
the rectangle

setGlobalProperties

protected void setGlobalProperties()
Sets some global variables according to the actual tree propertis


setReferencePatterns

public void setReferencePatterns(javax.swing.DefaultListModel patterns)
Sets the reference patterns.

Parameters:
patterns - a list of reference patterns

getReferencePatterns

public javax.swing.DefaultListModel getReferencePatterns()
Returns a list of reference patterns

Returns:
a list of reference patterns

printChosen

public void printChosen(java.awt.Graphics2D g,
                        NGTreeProperties properties)
Emphasizes the selected node.

Parameters:
g - Graphics2D object to draw to
properties - tree properties

truncLemma

protected java.lang.String truncLemma(java.lang.String orig_lemma,
                                      int trunc_type)
PDT-related function that truncates a lemma. It cuts a suffix of the lemma.

Parameters:
orig_lemma - the original lemma
trunc_type - type of truncation:
    0 - do not truncate
    1 - truncate comments
    2 - truncate variants and comments
Returns:
the truncated lemma

drawDescription

protected void drawDescription(java.awt.Graphics g,
                               java.lang.String description,
                               int x,
                               int y)
Draws one attribute as a part of a label of a node.

Parameters:
g - a graphic object to draw to
description - a description to be drawn
x - the x-coordinate
y - the y-coordinate

drawTree

protected void drawTree(NGTree tree,
                        TNode n,
                        TNode parent,
                        int otec_x,
                        int otec_y,
                        java.awt.Graphics2D g2)
Draws one tree of the forest.

Parameters:
tree - the tree to be drawn
n - the root of the tree (or subtree - it is a recursive function)
parent - the father of node n
otec_x - the x-coordinate of the father
otec_y - the y-coordinate of the father
g2 - a graphic object to draw to

vypocti_nakresleni

public void vypocti_nakresleni(java.awt.Graphics g)
It calculates coordinates of all nodes of all trees in the forest.

Parameters:
g - a graphic object to draw to

setFlagWholeForestChanged

public void setFlagWholeForestChanged(boolean flag)
Signals whether the whole forest has changed and coordinates of all its trees and their nodes must be calculated.

Parameters:
flag - value true signals that the coordinates need to be calculated

getFlagForestChanged

public boolean getFlagForestChanged()
Says whether the forest has changed and coordinates of (some of) its trees and their nodes must be calculated.

Returns:
true iff the coordinates need to be calculated

setForest

public void setForest(NGForest forest)
Sets a forest to be viewed.

Parameters:
forest - a forest to be viewed

getForest

public NGForest getForest()
Gets the forest to be viewed.

Returns:
the forest to be viewed

setTree

public void setTree(NGTree tree)
Sets a single tree to be viewed.

Parameters:
tree - a tree to be veiwed

addTree

public void addTree(NGTree tree)
Adds a tree to be viewed.

Parameters:
tree - a tree to be added at the end of the trees of the forest

setTreeProperties

public void setTreeProperties(NGTreeProperties new_properties)
Sets properties of the tree.

Parameters:
new_properties - properties of the tree

getTreeProperties

public NGTreeProperties getTreeProperties()
Returns the properties of the tree.

Returns:
the properties of the tree

setShowHiddenNodes

public void setShowHiddenNodes(boolean show)
Sets whether or not the hidden nodes should be shown

Parameters:
show - true iff they should be shown

getShowHiddenNodes

public boolean getShowHiddenNodes()
Returns whether the hidden nodes are set to be shown

Returns:
true iff they are set to be shown

setEmphasizeChosenNode

public void setEmphasizeChosenNode(boolean emphasize)
Sets whether the selected node should be emphasized

Parameters:
emphasize - true iff it should be emphasized

getEmphasizeChosenNode

public boolean getEmphasizeChosenNode()
Returns whether the selected node is set to be emphasized

Returns:
true iff it is set to be emphasized

changeReferenceStatus

public boolean changeReferenceStatus(int i)
Changes the state of (non-)displaying the i-th reference

Parameters:
i - the number of the reference, counted from zero
Returns:
the new state; it may be unchanged if the reference patterns forbids changing

paintComponent

public void paintComponent(java.awt.Graphics g)
Paints the forest.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - a graphic object to paint to

setChosenNodeByDepthOrder

public void setChosenNodeByDepthOrder(int order)
Marks a node with given order as selected, as well as the tree the node is from. The root of the first tree has order 1, the first tree has order 1, the first node of each subsequent tree has the order like the last node of the previous tree plus 1.

Parameters:
order - depth-first order of the node to be selected

printReferences

protected void printReferences(java.awt.Graphics2D g2)
Prints all references in the actual forest.

Parameters:
g2 - a graphic object to draw to

determineColor

protected java.awt.Color determineColor(TNode node,
                                        ReferencePattern pattern,
                                        java.lang.String value_depend_value)
Sets the color for printing a reference.

Parameters:
node -
pattern - a reference pattern
value_depend_value - the value of the attribute that may influence the color
Returns:
the color

setFontSize

public void setFontSize(int size)
Sets the font size for labels at nodes.

Parameters:
size - the font size

getFontSize

public int getFontSize()
Returns the font size for labels at nodes.

Returns:
the font size