net.sf.latexdraw.ui
Class WidgetMiniToolbar

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.AbstractButton
                  extended by javax.swing.JToggleButton
                      extended by net.sf.latexdraw.ui.WidgetMiniToolbar
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.WindowFocusListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ChangeListener, javax.swing.SwingConstants, Eventable, Picker

public class WidgetMiniToolbar
extends javax.swing.JToggleButton
implements java.awt.event.ActionListener, javax.swing.event.ChangeListener, java.awt.event.WindowFocusListener, Picker, Eventable

This class defines a button which displays a frame containing others buttons; a kind of menu with buttons.

This file is part of LaTeXDraw
Copyright (c) 2005-2012 Arnaud BLOUIN

LaTeXDraw 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 any later version.

LaTeXDraw 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/02/06

Version:
3.0
Author:
Arnaud BLOUIN
See Also:
Serialized Form

Nested Class Summary
(package private)  class WidgetMiniToolbar.ListToggleButtonAWTEventListener
           
(package private)  class WidgetMiniToolbar.WindowWidgets
           
 
Nested classes/interfaces inherited from class javax.swing.JToggleButton
javax.swing.JToggleButton.AccessibleJToggleButton, javax.swing.JToggleButton.ToggleButtonModel
 
Nested classes/interfaces inherited from class javax.swing.AbstractButton
javax.swing.AbstractButton.AccessibleAbstractButton, javax.swing.AbstractButton.ButtonChangeListener
 
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  WidgetMiniToolbar.WindowWidgets buttonsFrame
          The frame which displays the toolbar
protected  java.awt.Component componentFocusOnClose
          The component to give the focus when the toolbar is closed.
protected  SwingEventManager eventManager
          The event manager that listens events produced by the list of toogle buttons.
private static int HEIGHT_ICON
           
static int HEIGHT_TRIANGLE
          The height of the triangle drawn in the button
protected  int location
          Define the location of the panel of buttons.
static int LOCATION_NORTH
          The frame is at the north of the button.
static int LOCATION_SOUTH
          The frame is at the south of the button.
private static long serialVersionUID
           
protected  MToolBar toolbar
          The toolbar which contains the buttons
private static int TRIANGLE_GAP
           
private static int TRIANGLE_NB_POINT
           
private static int WIDTH_ICON
           
static int WIDTH_TRIANGLE
          The width of the triangle drawn in the button
 
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
 
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 javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
WidgetMiniToolbar(javax.swing.JFrame frame, javax.swing.Icon icon, int locate, java.awt.Component componentFocusOnClose)
          The constructor using an icon.
WidgetMiniToolbar(javax.swing.JFrame frame, java.lang.String txt, int locate, java.awt.Component componentFocusOnClose)
          The constructor using a text.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 java.awt.Component add(java.awt.Component comp)
           
 void addComponent(java.awt.Component comp)
          Adds a button to the toolbar of the listJToggleButton.
 void addSeparator()
          Adds a separator to the toolbar.
private  void attachAddedComponent(java.awt.Component comp)
          Attaches the given component to the event manager of the panel if it exists.
 boolean contains(java.lang.Object obj)
          Tests if the given object is contained by the calling picker.
protected  javax.swing.ImageIcon createTriangleIcon()
           
 void defineToolbarLocation()
          Defines the position of the mini-toolbar.
 SwingEventManager getEventManager()
           
 int getLocationButtonPanel()
           
 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)
           
 MToolBar getToolbar()
           
 boolean hasEventManager()
           
protected  void intializing(javax.swing.JFrame frame, int locate)
          Initialises the ListJToggleButton.
 boolean isContentVisible()
           
private static boolean isContentVisibleContainer(java.awt.Container cont)
           
protected  void paintComponent(java.awt.Graphics g)
           
 void paintTriangle(java.awt.Graphics g, int width, int height)
          Paints the triangle icon in a graphic.
 void repaint()
           
 void setButtonsFrameVisible(boolean visible)
          Sets id the toolbar must be visible or not.
 void setIcon()
          The icon of the button will be the red triangle.
 void setIcon(javax.swing.Icon defaultIcon)
           
 void setLocation(int locat)
          Sets the location of the mini toolbar.
 void setSelected(boolean sel)
           
 void stateChanged(javax.swing.event.ChangeEvent e)
           
 void updateSelected()
          Sets the main button to selected or not following if a button is selected or not.
 void windowGainedFocus(java.awt.event.WindowEvent e)
           
 void windowLostFocus(java.awt.event.WindowEvent e)
           
 
Methods inherited from class javax.swing.JToggleButton
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.AbstractButton
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
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, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, 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
add, add, add, add, addContainerListener, 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, 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, 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, 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

eventManager

protected SwingEventManager eventManager
The event manager that listens events produced by the list of toogle buttons. May be null.


buttonsFrame

protected WidgetMiniToolbar.WindowWidgets buttonsFrame
The frame which displays the toolbar


toolbar

protected MToolBar toolbar
The toolbar which contains the buttons


WIDTH_TRIANGLE

public static final int WIDTH_TRIANGLE
The width of the triangle drawn in the button

See Also:
Constant Field Values

HEIGHT_TRIANGLE

public static final int HEIGHT_TRIANGLE
The height of the triangle drawn in the button

See Also:
Constant Field Values

location

protected int location
Define the location of the panel of buttons.


componentFocusOnClose

protected java.awt.Component componentFocusOnClose
The component to give the focus when the toolbar is closed.


LOCATION_NORTH

public static final int LOCATION_NORTH
The frame is at the north of the button.

See Also:
Constant Field Values

LOCATION_SOUTH

public static final int LOCATION_SOUTH
The frame is at the south of the button.

See Also:
Constant Field Values

WIDTH_ICON

private static final int WIDTH_ICON
See Also:
Constant Field Values

HEIGHT_ICON

private static final int HEIGHT_ICON
See Also:
Constant Field Values

TRIANGLE_NB_POINT

private static final int TRIANGLE_NB_POINT
See Also:
Constant Field Values

TRIANGLE_GAP

private static final int TRIANGLE_GAP
See Also:
Constant Field Values
Constructor Detail

WidgetMiniToolbar

public WidgetMiniToolbar(javax.swing.JFrame frame,
                         java.lang.String txt,
                         int locate,
                         java.awt.Component componentFocusOnClose)
The constructor using a text.

Parameters:
frame - The main frame containing the ListJToggleButton.
txt - The text of the ListJToggleButton.
locate - The position of the mini toolbar.
componentFocusOnClose - The component to give the focus when the toolbar is closed. Can be null.
Since:
3.0

WidgetMiniToolbar

public WidgetMiniToolbar(javax.swing.JFrame frame,
                         javax.swing.Icon icon,
                         int locate,
                         java.awt.Component componentFocusOnClose)
The constructor using an icon.

Parameters:
icon - The icon of the ListJToggleButton.
locate - The position of the mini toolbar.
frame - The main frame containing the ListJToggleButton.
componentFocusOnClose - The component to give the focus when the toolbar is closed. Can be null.
Method Detail

intializing

protected void intializing(javax.swing.JFrame frame,
                           int locate)
Initialises the ListJToggleButton.

Parameters:
frame - The main frame containing the ListJToggleButton.
locate - The position of the mini toolbar.
Since:
1.9.1

isContentVisible

public boolean isContentVisible()
Returns:
True if at least one of the widgets of the list is visible.
Since:
3.0

isContentVisibleContainer

private static boolean isContentVisibleContainer(java.awt.Container cont)

createTriangleIcon

protected javax.swing.ImageIcon createTriangleIcon()
Returns:
Creates an imageIcon containing the triangle icon.
Since:
1.9.1

setLocation

public void setLocation(int locat)
Sets the location of the mini toolbar.

Parameters:
locat - The position of the mini toolbar.
Throws:
java.lang.IllegalArgumentException - If the location is neither LOCATION_NORTH nor LOCATION_SOUTH.

setSelected

public void setSelected(boolean sel)
Overrides:
setSelected in class javax.swing.AbstractButton

addSeparator

public void addSeparator()
Adds a separator to the toolbar.


addComponent

public void addComponent(java.awt.Component comp)
Adds a button to the toolbar of the listJToggleButton.

Parameters:
comp - The new button to add.

add

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

paintTriangle

public void paintTriangle(java.awt.Graphics g,
                          int width,
                          int height)
Paints the triangle icon in a graphic.

Parameters:
g - The graphic.
width - The width of the object.
height - The height of the object.
Since:
1.9.1

paintComponent

protected void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

defineToolbarLocation

public void defineToolbarLocation()
Defines the position of the mini-toolbar.

Since:
1.9.1

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

setButtonsFrameVisible

public void setButtonsFrameVisible(boolean visible)
Sets id the toolbar must be visible or not.

Parameters:
visible - True: the toolbar will be visible.
Since:
3.0

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
Specified by:
stateChanged in interface javax.swing.event.ChangeListener

getLocationButtonPanel

public int getLocationButtonPanel()
Returns:
The location of the panel of buttons.

updateSelected

public void updateSelected()
Sets the main button to selected or not following if a button is selected or not.


windowGainedFocus

public void windowGainedFocus(java.awt.event.WindowEvent e)
Specified by:
windowGainedFocus in interface java.awt.event.WindowFocusListener

windowLostFocus

public void windowLostFocus(java.awt.event.WindowEvent e)
Specified by:
windowLostFocus in interface java.awt.event.WindowFocusListener

setIcon

public void setIcon()
The icon of the button will be the red triangle.

Since:
1.9.1

setIcon

public void setIcon(javax.swing.Icon defaultIcon)
Overrides:
setIcon in class javax.swing.AbstractButton

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.

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.

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).

attachAddedComponent

private void attachAddedComponent(java.awt.Component comp)
Attaches the given component to the event manager of the panel if it exists.

Parameters:
comp -
Since:
3.0

hasEventManager

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

getEventManager

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

getToolbar

public MToolBar getToolbar()
Returns:
The toolbar associated to the toggle button.
Since:
3.0

repaint

public void repaint()
Overrides:
repaint in class java.awt.Component