Class JPanelFileSelection
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- gov.nih.mipav.view.JPanelEdit
-
- gov.nih.mipav.view.JPanelFileSelection
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,java.util.EventListener
,javax.accessibility.Accessible
public class JPanelFileSelection extends JPanelEdit implements java.awt.event.ActionListener
provides a nice plug-in swing panel to simplify the file-selection process. Contains a textfield on the left and a browse button on the right to bring a JFileChooser front, either of which may be used to indicate the file. This object should work just fine for both "open" applications as well as "save-as" applications, and indeed, "folder-select" applications. The Panel may choose between permitting selection of folders and both folders and directories in its file chooser.This panel has an etched, titled border.
Handles its own button clicks and text, and when the file it points to is requested. The preferred file is chosen based on the text in the textfield, as there is no way to ensure that a mouseExit event or focusExit event will occur before some kind of OKAY button ActionEvent which requests the file. SO.. the file is translated from the text when the file is requested. If it can't find the chosen file from the text (ie., the path does not exist, or the text was left blank), then the file comes from the button choice, which should be otherwise no different from the textfield. Be aware that if a file does not exist in the textfield, a file of that name can still be returned -- this Panel is designed to be perfectly fine with save-as type of applications.
The file that comes back is unadulterated and not made. Possible future expansion may be for specialising this for File input, or output, ensuring that the file exists, or finding a way to set up this panel to fire notification when a file is chosen (using either the text or the file chooser).
- 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
-
-
Field Summary
Fields Modifier and Type Field Description private javax.swing.JFileChooser
chooser
DOCUMENT ME!private java.io.File
chosenFile
DOCUMENT ME!static java.lang.String
defaultDirectory
Specifies the default directory for the panel editor, which is the "user.home" directory, with a separator character appended at the end.private javax.swing.JButton
fileBrowse
DOCUMENT ME!private javax.swing.JTextField
fileTextField
DOCUMENT ME!private static long
serialVersionUID
Use serialVersionUID for interoperability.-
Fields inherited from class gov.nih.mipav.view.JPanelEdit
errorComponent, errorString, propertyName
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description JPanelFileSelection()
basic constructor, creates a panel with textfield and browser. defaults to pointing at the user's default directory, There is no title for either the file chooser or the panel itself, and the file chooser will search for both files and directories.JPanelFileSelection(boolean browseFiles)
custom constructor -- selects the preference for the file chooser to permit choice of selection of directories only or both files and directories.JPanelFileSelection(java.io.File prechosenFile, java.lang.String title)
custom constructor -- Selection of the starting directory, and the title on the border.JPanelFileSelection(java.io.File prechosenFile, java.lang.String title, boolean browseFiles)
custom constructor -- Selection of the starting directory, and the title on the border.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent action)
Responds to ActionEvents, such as the "Browse" button being clicked.boolean
checkFields()
DOCUMENT ME!java.lang.Object
getCodedValue()
DOCUMENT ME!java.lang.String
getPanelValue()
DOCUMENT ME!java.io.File
getSelectedFile()
we are enforcing existance at the calling/owning object level this panel doens't care if the file exists, nor if there are read rights or write rights there. returns the File pointed to by the text field, unless it is empty; at that point, we assume the file chooser was used to point to a file and the chosen file is stored there.void
highlight()
gets the focus on the textfield and selects all text there.void
setBrowseForFiles(boolean browseFiles)
determines how the file chooser will search.void
setBrowserFileFilter(javax.swing.filechooser.FileFilter filter)
sets the file filter for the file chooser.void
setBrowserTitle(java.lang.String title)
Sets the file chooser title independantly of the panel title.void
setCurrentDirectory(java.io.File current)
sets the file chooser and the text field to point to a different file.void
setPanelTitle(java.lang.String title)
Sets the panel title independant of the file chooser title.-
Methods inherited from class gov.nih.mipav.view.JPanelEdit
getErrorComponent, getErrorString, getPropertyName, setPropertyName
-
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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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
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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Use serialVersionUID for interoperability.- See Also:
- Constant Field Values
-
defaultDirectory
public static java.lang.String defaultDirectory
Specifies the default directory for the panel editor, which is the "user.home" directory, with a separator character appended at the end.
-
chooser
private javax.swing.JFileChooser chooser
DOCUMENT ME!
-
chosenFile
private java.io.File chosenFile
DOCUMENT ME!
-
fileBrowse
private javax.swing.JButton fileBrowse
DOCUMENT ME!
-
fileTextField
private javax.swing.JTextField fileTextField
DOCUMENT ME!
-
-
Constructor Detail
-
JPanelFileSelection
public JPanelFileSelection()
basic constructor, creates a panel with textfield and browser. defaults to pointing at the user's default directory, There is no title for either the file chooser or the panel itself, and the file chooser will search for both files and directories.
-
JPanelFileSelection
public JPanelFileSelection(boolean browseFiles)
custom constructor -- selects the preference for the file chooser to permit choice of selection of directories only or both files and directories. Uses the default user - directory location in the text field, and will have no title on the border.- Parameters:
browseFiles
- DOCUMENT ME!
-
JPanelFileSelection
public JPanelFileSelection(java.io.File prechosenFile, java.lang.String title)
custom constructor -- Selection of the starting directory, and the title on the border. Chooser selects both files and directories.- Parameters:
prechosenFile
- DOCUMENT ME!title
- DOCUMENT ME!
-
JPanelFileSelection
public JPanelFileSelection(java.io.File prechosenFile, java.lang.String title, boolean browseFiles)
custom constructor -- Selection of the starting directory, and the title on the border. Chooser selects based on argument.- Parameters:
prechosenFile
- DOCUMENT ME!title
- DOCUMENT ME!browseFiles
- DOCUMENT ME!
-
-
Method Detail
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent action)
Responds to ActionEvents, such as the "Browse" button being clicked. When the Browse button is selected, if it returns a file, it will provide the path of the chosen file to the text field. It then fires a property change for all interested listeners.- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
- Parameters:
action
- DOCUMENT ME!
-
checkFields
public boolean checkFields()
DOCUMENT ME!- Specified by:
checkFields
in classJPanelEdit
- Returns:
- DOCUMENT ME!
-
getCodedValue
public java.lang.Object getCodedValue()
DOCUMENT ME!- Specified by:
getCodedValue
in classJPanelEdit
- Returns:
- DOCUMENT ME!
-
getPanelValue
public java.lang.String getPanelValue()
DOCUMENT ME!- Specified by:
getPanelValue
in classJPanelEdit
- Returns:
- DOCUMENT ME!
-
getSelectedFile
public java.io.File getSelectedFile()
we are enforcing existance at the calling/owning object level this panel doens't care if the file exists, nor if there are read rights or write rights there. returns the File pointed to by the text field, unless it is empty; at that point, we assume the file chooser was used to point to a file and the chosen file is stored there.- Returns:
- DOCUMENT ME!
-
highlight
public void highlight() throws java.lang.NullPointerException
gets the focus on the textfield and selects all text there. Recommended for error highlighting.- Throws:
java.lang.NullPointerException
- DOCUMENT ME!
-
setBrowseForFiles
public void setBrowseForFiles(boolean browseFiles)
determines how the file chooser will search.true
will set the file chooser to permit viewing both File and directories, where-asfalse
will only let the user select directories.- Parameters:
browseFiles
- DOCUMENT ME!
-
setBrowserFileFilter
public void setBrowserFileFilter(javax.swing.filechooser.FileFilter filter)
sets the file filter for the file chooser.- Parameters:
filter
- DOCUMENT ME!
-
setBrowserTitle
public void setBrowserTitle(java.lang.String title)
Sets the file chooser title independantly of the panel title.- Parameters:
title
- DOCUMENT ME!
-
setCurrentDirectory
public void setCurrentDirectory(java.io.File current)
sets the file chooser and the text field to point to a different file. See JFileChooser.setCurrentDirectory for the resetting process if an invalid File is provided.- Parameters:
current
- DOCUMENT ME!
-
setPanelTitle
public void setPanelTitle(java.lang.String title)
Sets the panel title independant of the file chooser title.- See Also:
#setBrowserTitle()
-
-