Package adams.gui.core
Class FilePanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.core.BasePanel
-
- adams.gui.core.FilePanel
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,ListSelectionListener
public class FilePanel extends BasePanel implements ListSelectionListener
Displays files and directories.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FilePanel.FileDoubleClickEvent
Event for double clicks on files.static interface
FilePanel.FileDoubleClickListener
Interface for classes that listen to double clicks on files.-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected FileObjectComparator
m_Comparator
the comparator.protected Set<ChangeListener>
m_DirectoryChangeListeners
the listeners for when the directory gets updated.protected Set<FilePanel.FileDoubleClickListener>
m_FileDoubleClickListeners
the double click listener for a file.protected List<FileObject>
m_Files
the currently listed files.protected Set<ChangeListener>
m_FilesChangeListeners
the listeners for when the files get updated.protected FocusAdapter
m_FocusAdapter
the focus adapter.protected boolean
m_IgnoreChanges
whether to ignore changes.protected KeyAdapter
m_KeyAdapter
the key adapter.protected SearchableBaseList
m_List
the List for the non-detailed view.protected DirectoryLister
m_Lister
for listing the content of the directory.protected MouseAdapter
m_MouseAdapter
the mouse adapter.protected boolean
m_MultiSelection
whether to allow multiple files to be selected.protected SearchPanel
m_PanelSearch
the search panel.protected Set<ChangeListener>
m_SelectionChangeListeners
the listeners for when the selection changes.protected Boolean
m_ShowDetails
whether to show details on the files.protected boolean
m_ShowHidden
whether to show hidden files.protected SortableAndSearchableTable
m_Table
the table for the detailed view.protected SwingWorker
m_Worker
the currently running swingworker.-
Fields inherited from class adams.gui.core.BasePanel
m_FileChooser
-
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
-
Fields inherited from class java.awt.Component
accessibleContext, 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
Constructors Constructor Description FilePanel(boolean showDetails)
Initializes the panel.FilePanel(boolean showDetails, DirectoryLister lister)
Initializes the panel.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDirectoryChangeListener(ChangeListener l)
Adds the listener to the list of listeners that get notified when the directory changes.void
addFileDoubleClickListener(FilePanel.FileDoubleClickListener l)
Adds the listener to the list of listeners that get notified when a file gets double-clicked.void
addFilesChangeListener(ChangeListener l)
Adds the listener to the list of listeners that get notified when the files change.void
addSearchListener(SearchListener l)
Adds the specified search listener.void
addSelectionChangeListener(ChangeListener l)
Adds the listener to the list of listeners that get notified when the selection changes.void
clearSelection()
Clears the selection.protected void
finishInit()
Finalizes the initialization.void
finishUpdate()
Triggers an update after updating several parameters.String
getCurrentDir()
Returns the current directory.DirectoryLister
getDirectoryLister()
Returns the current directory lister.BaseRegExp
getFilter()
Return the filter in use.boolean
getListDirs()
Returns whether directories are listed.boolean
getListFiles()
Returns whether files are listed.File
getSelectedFile()
Returns the currently selected file, if any.protected File
getSelectedFile(boolean skipDotDot)
Returns the currently selected file, if any.FileObject
getSelectedFileObject()
Returns the currently selected file object, if any.protected FileObject
getSelectedFileObject(boolean skipDotDot)
Returns the currently selected file wrapper, if any.FileObject[]
getSelectedFileObjects()
Returns the currently selected file objects, if any.File[]
getSelectedFiles()
Returns the currently selected files, if any.protected void
initGUI()
Initializes the widgets.protected void
initialize()
Initializes the members.boolean
isBusy()
Checks whether we're currently busy.boolean
isCaseSensitive()
Returns whether comparison is case-sensitive.boolean
isIncludeParentDirs()
Returns whether to include parent directories in the comparison.boolean
isListDirsFirst()
Returns whether to list directories first.boolean
isLocal()
Returns whether the files are local or remote.boolean
isMultiSelection()
Returns whether multi-selection is enabled.boolean
isSearchVisible()
Returns whether the search box is visible.boolean
isShowHidden()
Returns whether to show hidden files or not.static void
main(String[] args)
Just for testing.protected void
notifyDirectoryChangeListeners()
Notifies the listeners when the directory has changed.protected void
notifyFileDoubleClickListeners(FilePanel.FileDoubleClickEvent e)
Notifies the listeners when a file got double-clicked.protected void
notifyFilesChangeListeners()
Notifies the listeners when the files have changed.protected void
notifySelectionChangeListeners()
Notifies the listeners when the selection has changed.void
reload()
Updates the files (if not busy).void
removeDirectoryChangeListener(ChangeListener l)
Removes the listener from the list of listeners that get notified when the directory changes.void
removeFileDoubleClickListener(FilePanel.FileDoubleClickListener l)
Removes the listener from the list of listeners that get notified when a file gets double-clicked.void
removeFilesChangeListener(ChangeListener l)
Removes the listener from the list of listeners that get notified when the files change.void
removeSearchListener(SearchListener l)
Removes the specified search listener.void
removeSelectionChangeListener(ChangeListener l)
Removes the listener from the list of listeners that get notified when the selection changes.void
setCaseSensitive(boolean value)
Sets whether to use case-sensitive comparison.void
setCurrentDir(String value)
Sets the directory to list.void
setDirectoryLister(DirectoryLister value)
Sets the directory lister to use.void
setFilter(BaseRegExp value)
Sets the filter to use.void
setIncludeParentDirs(boolean value)
Sets whether to use include the parent directories in the comparison.void
setListDirs(boolean value)
Sets whether to list directories.void
setListDirsFirst(boolean value)
Sets whether to list directories first.void
setListFiles(boolean value)
Sets whether to list files.void
setMultiSelection(boolean value)
Sets whether to allow multi-selection.void
setSearchVisible(boolean value)
Sets the visibility state of the search box.void
setShowHidden(boolean value)
Sets whether to show hidden files or not.void
startUpdate()
Allows the update of several parameters without triggering an update each time.protected void
update()
Updates the view.protected void
updateGUI()
Updates the GUI.void
valueChanged(ListSelectionEvent e)
Gets called when the list selection changes.-
Methods inherited from class adams.gui.core.BasePanel
afterHide, afterShow, beforeHide, beforeShow, closeParent, getParentChild, getParentDialog, getParentFrame, getParentInternalFrame, getParentTitle, initFileChooser, printErrorMessage, printException, saveComponent, setEnabledCascade, setEnabledCascade, setParentTitle, setVisible
-
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, 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
-
m_ShowDetails
protected Boolean m_ShowDetails
whether to show details on the files.
-
m_MultiSelection
protected boolean m_MultiSelection
whether to allow multiple files to be selected.
-
m_ShowHidden
protected boolean m_ShowHidden
whether to show hidden files.
-
m_Lister
protected DirectoryLister m_Lister
for listing the content of the directory.
-
m_Comparator
protected FileObjectComparator m_Comparator
the comparator.
-
m_Files
protected List<FileObject> m_Files
the currently listed files.
-
m_Worker
protected SwingWorker m_Worker
the currently running swingworker.
-
m_IgnoreChanges
protected boolean m_IgnoreChanges
whether to ignore changes.
-
m_List
protected SearchableBaseList m_List
the List for the non-detailed view.
-
m_Table
protected SortableAndSearchableTable m_Table
the table for the detailed view.
-
m_PanelSearch
protected SearchPanel m_PanelSearch
the search panel.
-
m_DirectoryChangeListeners
protected Set<ChangeListener> m_DirectoryChangeListeners
the listeners for when the directory gets updated.
-
m_FilesChangeListeners
protected Set<ChangeListener> m_FilesChangeListeners
the listeners for when the files get updated.
-
m_SelectionChangeListeners
protected Set<ChangeListener> m_SelectionChangeListeners
the listeners for when the selection changes.
-
m_FileDoubleClickListeners
protected Set<FilePanel.FileDoubleClickListener> m_FileDoubleClickListeners
the double click listener for a file.
-
m_FocusAdapter
protected FocusAdapter m_FocusAdapter
the focus adapter.
-
m_KeyAdapter
protected KeyAdapter m_KeyAdapter
the key adapter.
-
m_MouseAdapter
protected MouseAdapter m_MouseAdapter
the mouse adapter.
-
-
Constructor Detail
-
FilePanel
public FilePanel(boolean showDetails)
Initializes the panel.- Parameters:
showDetails
- whether to show details like DIR and size
-
FilePanel
public FilePanel(boolean showDetails, DirectoryLister lister)
Initializes the panel.- Parameters:
showDetails
- whether to show details like DIR and size
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classBasePanel
-
finishInit
protected void finishInit()
Finalizes the initialization.- Overrides:
finishInit
in classBasePanel
-
isLocal
public boolean isLocal()
Returns whether the files are local or remote.- Returns:
- true if local
-
setDirectoryLister
public void setDirectoryLister(DirectoryLister value)
Sets the directory lister to use.- Parameters:
value
- the lister
-
getDirectoryLister
public DirectoryLister getDirectoryLister()
Returns the current directory lister.- Returns:
- the lister
-
setCurrentDir
public void setCurrentDir(String value)
Sets the directory to list.- Parameters:
value
- the directory
-
getCurrentDir
public String getCurrentDir()
Returns the current directory.- Returns:
- the directory
-
setListDirs
public void setListDirs(boolean value)
Sets whether to list directories.- Parameters:
value
- true if to list directories
-
getListDirs
public boolean getListDirs()
Returns whether directories are listed.- Returns:
- true if to list directories
-
setListFiles
public void setListFiles(boolean value)
Sets whether to list files.- Parameters:
value
- true if to list files
-
getListFiles
public boolean getListFiles()
Returns whether files are listed.- Returns:
- true if to list files
-
setFilter
public void setFilter(BaseRegExp value)
Sets the filter to use.- Parameters:
value
- the filter
-
getFilter
public BaseRegExp getFilter()
Return the filter in use.- Returns:
- the filter
-
setCaseSensitive
public void setCaseSensitive(boolean value)
Sets whether to use case-sensitive comparison.- Parameters:
value
- true if case-sensitive
-
isCaseSensitive
public boolean isCaseSensitive()
Returns whether comparison is case-sensitive.- Returns:
- true if case-sensitive
-
setListDirsFirst
public void setListDirsFirst(boolean value)
Sets whether to list directories first.- Parameters:
value
- true if to list directories first
-
isListDirsFirst
public boolean isListDirsFirst()
Returns whether to list directories first.- Returns:
- true if to list dirs first
-
setIncludeParentDirs
public void setIncludeParentDirs(boolean value)
Sets whether to use include the parent directories in the comparison.- Parameters:
value
- true if to include parent directories
-
isIncludeParentDirs
public boolean isIncludeParentDirs()
Returns whether to include parent directories in the comparison.- Returns:
- true if included
-
setShowHidden
public void setShowHidden(boolean value)
Sets whether to show hidden files or not.- Parameters:
value
- true if to show
-
isShowHidden
public boolean isShowHidden()
Returns whether to show hidden files or not.- Returns:
- true if to show
-
setMultiSelection
public void setMultiSelection(boolean value)
Sets whether to allow multi-selection.- Parameters:
value
- true if to allow
-
isMultiSelection
public boolean isMultiSelection()
Returns whether multi-selection is enabled.- Returns:
- true if enabled
-
getSelectedFileObject
protected FileObject getSelectedFileObject(boolean skipDotDot)
Returns the currently selected file wrapper, if any.- Parameters:
skipDotDot
- whether to skip the dot dot file- Returns:
- the file wrapper, null if none selected
-
getSelectedFile
protected File getSelectedFile(boolean skipDotDot)
Returns the currently selected file, if any.- Parameters:
skipDotDot
- whether to skip the dot dot file- Returns:
- the file, null if none selected
-
getSelectedFileObject
public FileObject getSelectedFileObject()
Returns the currently selected file object, if any.- Returns:
- the file object, null if none selected
-
getSelectedFile
public File getSelectedFile()
Returns the currently selected file, if any.- Returns:
- the file, null if none selected
-
getSelectedFileObjects
public FileObject[] getSelectedFileObjects()
Returns the currently selected file objects, if any.- Returns:
- the file objects
-
getSelectedFiles
public File[] getSelectedFiles()
Returns the currently selected files, if any.- Returns:
- the files
-
clearSelection
public void clearSelection()
Clears the selection.
-
startUpdate
public void startUpdate()
Allows the update of several parameters without triggering an update each time.
-
finishUpdate
public void finishUpdate()
Triggers an update after updating several parameters.
-
update
protected void update()
Updates the view.
-
updateGUI
protected void updateGUI()
Updates the GUI.
-
reload
public void reload()
Updates the files (if not busy).
-
setSearchVisible
public void setSearchVisible(boolean value)
Sets the visibility state of the search box. NB: only available when details are shown using a table.- Parameters:
value
- true if visible
-
isSearchVisible
public boolean isSearchVisible()
Returns whether the search box is visible.- Returns:
- true of visible
-
isBusy
public boolean isBusy()
Checks whether we're currently busy.- Returns:
- true if busy
-
addDirectoryChangeListener
public void addDirectoryChangeListener(ChangeListener l)
Adds the listener to the list of listeners that get notified when the directory changes.- Parameters:
l
- the listener to add
-
removeDirectoryChangeListener
public void removeDirectoryChangeListener(ChangeListener l)
Removes the listener from the list of listeners that get notified when the directory changes.- Parameters:
l
- the listener to add
-
notifyDirectoryChangeListeners
protected void notifyDirectoryChangeListeners()
Notifies the listeners when the directory has changed.
-
addFilesChangeListener
public void addFilesChangeListener(ChangeListener l)
Adds the listener to the list of listeners that get notified when the files change.- Parameters:
l
- the listener to add
-
removeFilesChangeListener
public void removeFilesChangeListener(ChangeListener l)
Removes the listener from the list of listeners that get notified when the files change.- Parameters:
l
- the listener to add
-
notifyFilesChangeListeners
protected void notifyFilesChangeListeners()
Notifies the listeners when the files have changed.
-
addSelectionChangeListener
public void addSelectionChangeListener(ChangeListener l)
Adds the listener to the list of listeners that get notified when the selection changes.- Parameters:
l
- the listener to add
-
removeSelectionChangeListener
public void removeSelectionChangeListener(ChangeListener l)
Removes the listener from the list of listeners that get notified when the selection changes.- Parameters:
l
- the listener to add
-
notifySelectionChangeListeners
protected void notifySelectionChangeListeners()
Notifies the listeners when the selection has changed.
-
valueChanged
public void valueChanged(ListSelectionEvent e)
Gets called when the list selection changes.- Specified by:
valueChanged
in interfaceListSelectionListener
- Parameters:
e
- the event
-
addFileDoubleClickListener
public void addFileDoubleClickListener(FilePanel.FileDoubleClickListener l)
Adds the listener to the list of listeners that get notified when a file gets double-clicked.- Parameters:
l
- the listener to add
-
removeFileDoubleClickListener
public void removeFileDoubleClickListener(FilePanel.FileDoubleClickListener l)
Removes the listener from the list of listeners that get notified when a file gets double-clicked.- Parameters:
l
- the listener to add
-
notifyFileDoubleClickListeners
protected void notifyFileDoubleClickListeners(FilePanel.FileDoubleClickEvent e)
Notifies the listeners when a file got double-clicked.
-
addSearchListener
public void addSearchListener(SearchListener l)
Adds the specified search listener.- Parameters:
l
- the listener to add
-
removeSearchListener
public void removeSearchListener(SearchListener l)
Removes the specified search listener.- Parameters:
l
- the listener to remove
-
main
public static void main(String[] args)
Just for testing.- Parameters:
args
- the initial directory
-
-