Class JPanelFileSelection
- All Implemented Interfaces:
ActionListener,ImageObserver,MenuContainer,Serializable,EventListener,Accessible
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JFileChooserDOCUMENT ME!private FileDOCUMENT ME!static StringSpecifies the default directory for the panel editor, which is the "user.home" directory, with a separator character appended at the end.private JButtonDOCUMENT ME!private JTextFieldDOCUMENT ME!private static final longUse serialVersionUID for interoperability.Fields inherited from class gov.nih.mipav.view.JPanelEdit
errorComponent, errorString, propertyNameFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionbasic 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(File prechosenFile, String title) custom constructor -- Selection of the starting directory, and the title on the border.JPanelFileSelection(File prechosenFile, String title, boolean browseFiles) custom constructor -- Selection of the starting directory, and the title on the border. -
Method Summary
Modifier and TypeMethodDescriptionvoidactionPerformed(ActionEvent action) Responds to ActionEvents, such as the "Browse" button being clicked.booleanDOCUMENT ME!DOCUMENT ME!DOCUMENT ME!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.voidgets the focus on the textfield and selects all text there.voidsetBrowseForFiles(boolean browseFiles) determines how the file chooser will search.voidsetBrowserFileFilter(FileFilter filter) sets the file filter for the file chooser.voidsetBrowserTitle(String title) Sets the file chooser title independantly of the panel title.voidsetCurrentDirectory(File current) sets the file chooser and the text field to point to a different file.voidsetPanelTitle(String title) Sets the panel title independant of the file chooser title.Methods inherited from class gov.nih.mipav.view.JPanelEdit
getErrorComponent, getErrorString, getPropertyName, setPropertyNameMethods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, updateMethods 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, validateTreeMethods 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 Details
-
serialVersionUID
private static final long serialVersionUIDUse serialVersionUID for interoperability.- See Also:
-
defaultDirectory
Specifies the default directory for the panel editor, which is the "user.home" directory, with a separator character appended at the end. -
chooser
DOCUMENT ME! -
chosenFile
DOCUMENT ME! -
fileBrowse
DOCUMENT ME! -
fileTextField
DOCUMENT ME!
-
-
Constructor Details
-
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
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
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 Details
-
actionPerformed
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:
actionPerformedin interfaceActionListener- Parameters:
action- DOCUMENT ME!
-
checkFields
public boolean checkFields()DOCUMENT ME!- Specified by:
checkFieldsin classJPanelEdit- Returns:
- DOCUMENT ME!
-
getCodedValue
DOCUMENT ME!- Specified by:
getCodedValuein classJPanelEdit- Returns:
- DOCUMENT ME!
-
getPanelValue
DOCUMENT ME!- Specified by:
getPanelValuein classJPanelEdit- Returns:
- DOCUMENT ME!
-
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
gets the focus on the textfield and selects all text there. Recommended for error highlighting.- Throws:
NullPointerException- DOCUMENT ME!
-
setBrowseForFiles
public void setBrowseForFiles(boolean browseFiles) determines how the file chooser will search.truewill set the file chooser to permit viewing both File and directories, where-asfalsewill only let the user select directories.- Parameters:
browseFiles- DOCUMENT ME!
-
setBrowserFileFilter
sets the file filter for the file chooser.- Parameters:
filter- DOCUMENT ME!
-
setBrowserTitle
Sets the file chooser title independantly of the panel title.- Parameters:
title- DOCUMENT ME!
-
setCurrentDirectory
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
Sets the panel title independant of the file chooser title.- See Also:
-