de.sciss.gui
Class PathField

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 de.sciss.gui.SpringPanel
                      extended by de.sciss.gui.PathField
All Implemented Interfaces:
EventManager.Processor, PathListener, java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible
Direct Known Subclasses:
PrefPathField

public class PathField
extends SpringPanel
implements java.awt.event.ActionListener, PathListener, EventManager.Processor

This class is an updated (slim) version of FScape's PathField and provides a GUI object that displays a file's or folder's path, optionally with format information, and allows the user to browse the harddisk to change to a different file.

Version:
0.33, 28-Jun-08
Author:
Hanns Holger Rutz
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class de.sciss.gui.SpringPanel
SpringPanel.ComponentHeightRatioSpring, SpringPanel.ComponentWidthRatioSpring, SpringPanel.RatioSpring
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected static java.awt.Color COLOR_PROPSET
           
protected  ColouredTextField ggFormat
           
protected  de.sciss.gui.PathField.IOTextField ggPath
           
protected static int myMeta
           
protected  java.lang.String protoScheme
           
protected  java.lang.String scheme
           
static int TYPE_BASICMASK
          type flag : the bitmask for all path types
static int TYPE_FOLDER
          type flag : path to be chosen is a folder
static int TYPE_FORMATFIELD
          type flag : request an extra gadget to view file information
static int TYPE_INPUTFILE
          type flag : file is used for input / reading
static int TYPE_OUTPUTFILE
          type flag : file is used for output / writing
protected static PathList userPaths
           
 
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
PathField()
           
PathField(int type)
           
PathField(int type, java.lang.String dlgTxt)
          Create a new PathField
 
Method Summary
protected  java.lang.String abbrScheme(java.lang.String orig)
           
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void addPathListener(PathListener listener)
          Registers a PathListener which will be informed about changes of the path (i.e. user selections in the file chooser or text editing).
protected  PathButton createPathButton(int buttonType)
           
 void deriveFrom(PathField[] sp, java.lang.String s)
          PathField offers a mechanism to automatically derive a path name from a "mother" PathField.
protected  java.lang.String evalScheme(java.lang.String s)
           
protected  java.lang.String expandScheme(java.lang.String orig)
           
 java.lang.String getFormat()
          Get the string displayed in the format gadget.
 java.io.File getPath()
          Returns the path displayed in the gadget.
 int getType()
          Gets the type of the path field.
 void pathChanged(PathEvent e)
          Notifies the listener that a path changed occured.
 void processEvent(BasicEvent e)
          Processes the next event in the queue.
 void removePathListener(PathListener listener)
          Unregisters a PathListener from receiving path change events.
 boolean requestFocusInWindow()
           
 void selectFileName(boolean extention)
          Selects the file name portion of the text contents.
 void setErrWhenExistsOn(boolean onOff)
           
 void setErrWhenWriteProtected(boolean onOff)
           
 void setFormat(java.lang.String txt, boolean success)
          Change the contents of the format gadget.
 void setPath(java.io.File path)
          Sets the gadget's path.
protected  void setPathAndDispatchEvent(java.io.File path)
          Sets a new path and dispatches a PathEvent to registered listeners
 void setWarnWhenExists(boolean onOff)
           
protected  java.lang.String udirScheme(java.lang.String orig, int idx)
           
 
Methods inherited from class de.sciss.gui.SpringPanel
gridAdd, gridAdd, gridAdd, makeCompactGrid, makeCompactGrid, makeGrid, setInitialX, setInitialY, setPadding, setTitle, setXPad, setYPad
 
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, 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, 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, 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
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, 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

TYPE_BASICMASK

public static final int TYPE_BASICMASK
type flag : the bitmask for all path types

See Also:
Constant Field Values

TYPE_INPUTFILE

public static final int TYPE_INPUTFILE
type flag : file is used for input / reading

See Also:
Constant Field Values

TYPE_FORMATFIELD

public static final int TYPE_FORMATFIELD
type flag : request an extra gadget to view file information

See Also:
Constant Field Values

TYPE_OUTPUTFILE

public static final int TYPE_OUTPUTFILE
type flag : file is used for output / writing

See Also:
Constant Field Values

TYPE_FOLDER

public static final int TYPE_FOLDER
type flag : path to be chosen is a folder

See Also:
Constant Field Values

userPaths

protected static PathList userPaths

ggPath

protected final de.sciss.gui.PathField.IOTextField ggPath

ggFormat

protected ColouredTextField ggFormat

COLOR_PROPSET

protected static final java.awt.Color COLOR_PROPSET

scheme

protected java.lang.String scheme

protoScheme

protected java.lang.String protoScheme

myMeta

protected static final int myMeta
Constructor Detail

PathField

public PathField()

PathField

public PathField(int type)

PathField

public PathField(int type,
                 java.lang.String dlgTxt)
Create a new PathField

Parameters:
type - one of the types covered by TYPE_BASICMASK bitwise-OR optional displays like TYPE_FORMATFIELD
dlgTxt - the text string to display in the filechooser or null
Method Detail

setPath

public void setPath(java.io.File path)
Sets the gadget's path. This is path will be used as default setting when the file chooser is shown

Parameters:
path - the new path for the button

setWarnWhenExists

public void setWarnWhenExists(boolean onOff)

setErrWhenExistsOn

public void setErrWhenExistsOn(boolean onOff)

setErrWhenWriteProtected

public void setErrWhenWriteProtected(boolean onOff)

setPathAndDispatchEvent

protected void setPathAndDispatchEvent(java.io.File path)
Sets a new path and dispatches a PathEvent to registered listeners

Parameters:
path - the new path for the gadget and the event

getPath

public java.io.File getPath()
Returns the path displayed in the gadget.

Returns:
the File corresponding to the path string in the gadget

setFormat

public void setFormat(java.lang.String txt,
                      boolean success)
Change the contents of the format gadget.

Parameters:
txt - Text to be displayed in the format gadget
success - false indicates file format parse error and will render the format gadget red.
Throws:
java.lang.IllegalStateException - if the path field doesn't have a format gadget

getFormat

public java.lang.String getFormat()
Get the string displayed in the format gadget.

Returns:
the currently displayed format text or null if the path field has no format gadget.

getType

public int getType()
Gets the type of the path field.

Returns:
the gadget's type as specified in the constructor use bitwise-AND with TYPE_BASICMASK to query the file access type.

selectFileName

public void selectFileName(boolean extention)
Selects the file name portion of the text contents.

Parameters:
extention - whether to include the file name suffix or not

requestFocusInWindow

public boolean requestFocusInWindow()
Overrides:
requestFocusInWindow in class javax.swing.JComponent

deriveFrom

public void deriveFrom(PathField[] sp,
                       java.lang.String s)
PathField offers a mechanism to automatically derive a path name from a "mother" PathField. This applies usually to output files whose names are derived from PathFields which represent input paths. The provided 'scheme' String can contain the Tags
  $Dx = Directory of superPath x; $Fx = Filename; $E = Extension; $Bx = Brief filename
  
where 'x' is the index in the provided array of mother PathFields. Whenever the mother contents changes, the child PathField will recalculate its name. When the user changes the contents of the child PathField, an algorithm tries to find out which components are related to the mother's pathname, parts that cannot be identified will not be automatically changing any more unless the user completely clears the PathField (i.e. restores full automation).

The user can abbreviate or extend filenames by pressing the appropriate key; in this case the $F and $B tags are exchanged in the scheme.

Parameters:
sp - array of mother path fields to listen to
s - automatic formatting scheme which can incorporate placeholders for the mother fields' paths.

addPathListener

public void addPathListener(PathListener listener)
Registers a PathListener which will be informed about changes of the path (i.e. user selections in the file chooser or text editing).

Parameters:
listener - the PathListener to register
See Also:
EventManager.addListener( Object )

removePathListener

public void removePathListener(PathListener listener)
Unregisters a PathListener from receiving path change events.

Parameters:
listener - the PathListener to unregister
See Also:
EventManager.removeListener( Object )

processEvent

public void processEvent(BasicEvent e)
Description copied from interface: EventManager.Processor
Processes the next event in the queue. This gets called in the event thread. Usually implementing classes should loop through all listeners by calling elm.countListeners() and elm.getListener(), and invoke specific dispatching methods on these listeners.

Specified by:
processEvent in interface EventManager.Processor

evalScheme

protected java.lang.String evalScheme(java.lang.String s)

abbrScheme

protected java.lang.String abbrScheme(java.lang.String orig)

expandScheme

protected java.lang.String expandScheme(java.lang.String orig)

udirScheme

protected java.lang.String udirScheme(java.lang.String orig,
                                      int idx)

createPathButton

protected PathButton createPathButton(int buttonType)

pathChanged

public void pathChanged(PathEvent e)
Description copied from interface: PathListener
Notifies the listener that a path changed occured.

Specified by:
pathChanged in interface PathListener
Parameters:
e - the event describing the path change

actionPerformed

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