org.malai.widget
Class MPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.malai.widget.MPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, Eventable, Picker, Scrollable
Direct Known Subclasses:
LCanvas, LCodePanel

public class MPanel
extends javax.swing.JPanel
implements Picker, Eventable, Scrollable

Extends the Java JPanel to conform malai requirements.

This file is part of Malai.
Copyright (c) 2009-2012 Arnaud BLOUIN

Malai is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Malai is distributed without any warranty; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

05/10/2010

Since:
0.1
Version:
0.1
Author:
Arnaud BLOUIN
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  SwingEventManager eventManager
          The event manager that listens events produced by the panel.
protected  MScrollPane scrollpane
          The possible scrollpane that contains the panel.
private static long serialVersionUID
           
 
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
MPanel(boolean withScrollPane, boolean withEvtManager)
          Creates and initialises a panel.
 
Method Summary
 java.awt.Component add(java.awt.Component comp)
           
 java.awt.Component add(java.awt.Component comp, int index)
           
 void add(java.awt.Component comp, java.lang.Object constraints)
           
 void add(java.awt.Component comp, java.lang.Object constraints, int index)
           
 java.awt.Component add(java.lang.String name, java.awt.Component comp)
           
 boolean contains(java.lang.Object obj)
          Tests if the given object is contained by the calling picker.
 SwingEventManager getEventManager()
           
 Pickable getPickableAt(double x, double y)
           
 Picker getPickerAt(double x, double y)
           
 java.awt.geom.Point2D getRelativePoint(double x, double y, java.lang.Object o)
           
protected  javax.swing.JScrollBar getScrollbar(boolean vertical)
           
 MScrollPane getScrollpane()
           
 boolean hasEventManager()
           
 boolean hasScrollPane()
           
 boolean isHorizontalScrollbarVisible()
           
 boolean isVerticalScrollbarVisible()
           
protected  void scroll(int increment, boolean vertical)
          Scroll the vertical or horizontal scroll bar, if possible, using the given increment.
 void scrollHorizontally(int increment)
          Scroll the vertical scroll bar, if possible, using the given increment.
 void scrollVertically(int increment)
          Scroll the vertical scroll bar, if possible, using the given increment.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, 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
 
Methods inherited from class java.awt.Container
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, checkImage, checkImage, 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, 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

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

scrollpane

protected MScrollPane scrollpane
The possible scrollpane that contains the panel.


eventManager

protected SwingEventManager eventManager
The event manager that listens events produced by the panel. May be null.

Constructor Detail

MPanel

public MPanel(boolean withScrollPane,
              boolean withEvtManager)
Creates and initialises a panel.

Parameters:
withScrollPane - True: a scrollpane will be created and will contain the panel.
withEvtManager - True: the panel will have an event manager.
Since:
0.1
Method Detail

getRelativePoint

public java.awt.geom.Point2D getRelativePoint(double x,
                                              double y,
                                              java.lang.Object o)
Specified by:
getRelativePoint in interface Picker
Parameters:
x - The x-coordinate of the position to convert.
y - The y-coordinate of the position to convert.
o - An object contained by the calling picker. This function will computed the real position of the given point in o.
Returns:
Converts the given point in to fit the coordinates of the given object contained by the picker. For instance, given an object o1 that contains an other object o2 at position (10, 10). o1.getRelativePoint(30, 30, o2) will return (20, 20).

getPickableAt

public Pickable getPickableAt(double x,
                              double y)
Specified by:
getPickableAt in interface Picker
Parameters:
x - The x-coordinate of the position used to get the pickable object.
y - The y-coordinate of the position used to get the pickable object.
Returns:
The pickable object at the given position.

getPickerAt

public Picker getPickerAt(double x,
                          double y)
Specified by:
getPickerAt in interface Picker
Parameters:
x - The x-coordinate of the position used to get the picker object.
y - The y-coordinate of the position used to get the picker object.
Returns:
The pickable object at the given position.

contains

public boolean contains(java.lang.Object obj)
Description copied from interface: Picker
Tests if the given object is contained by the calling picker.

Specified by:
contains in interface Picker
Parameters:
obj - The object to test.
Returns:
True: the given object is contained by the calling picker.

hasScrollPane

public boolean hasScrollPane()
Specified by:
hasScrollPane in interface Scrollable
Returns:
True if the panel is in a scroll pane.

getScrollpane

public MScrollPane getScrollpane()
Specified by:
getScrollpane in interface Scrollable
Returns:
The scroll pane of the panel (may be null).

isHorizontalScrollbarVisible

public boolean isHorizontalScrollbarVisible()
Returns:
True if the horizontal scroll bar is visible.
Since:
0.1

isVerticalScrollbarVisible

public boolean isVerticalScrollbarVisible()
Returns:
True if the vertical scrool bar is visible.
Since:
0.1

getScrollbar

protected javax.swing.JScrollBar getScrollbar(boolean vertical)
Parameters:
vertical - True: the vertical scrollbar is returned. Otherwise, the horizontal scroll bar.
Returns:
The required scroll bar or null if the panel has no scrollpane.
Since:
0.1

scrollHorizontally

public void scrollHorizontally(int increment)
Scroll the vertical scroll bar, if possible, using the given increment.

Parameters:
increment - The increment to apply on the vertical scroll bar.
Since:
0.1

scrollVertically

public void scrollVertically(int increment)
Scroll the vertical scroll bar, if possible, using the given increment.

Parameters:
increment - The increment to apply on the vertical scroll bar.
Since:
0.1

scroll

protected void scroll(int increment,
                      boolean vertical)
Scroll the vertical or horizontal scroll bar, if possible, using the given increment.

Parameters:
increment - The increment to apply on the vertical scroll bar.
vertical - True: the vertical scroll bar is
Since:
0.1

getEventManager

public SwingEventManager getEventManager()
Specified by:
getEventManager in interface Eventable
Returns:
The event manager that gathers events the Eventable object produces.

add

public java.awt.Component add(java.awt.Component comp,
                              int index)
Overrides:
add in class java.awt.Container

add

public void add(java.awt.Component comp,
                java.lang.Object constraints,
                int index)
Overrides:
add in class java.awt.Container

add

public void add(java.awt.Component comp,
                java.lang.Object constraints)
Overrides:
add in class java.awt.Container

add

public java.awt.Component add(java.awt.Component comp)
Overrides:
add in class java.awt.Container

add

public java.awt.Component add(java.lang.String name,
                              java.awt.Component comp)
Overrides:
add in class java.awt.Container

hasEventManager

public boolean hasEventManager()
Specified by:
hasEventManager in interface Eventable
Returns:
True: the Eventable object has an event manager that gathers events it produces.