|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JPanel net.lucidviews.util.gui.swing.JFileSaver
public class JFileSaver
A panel that allows the user to choose a file and, optionally edit its path
before hitting the save button.
The main benefit of this method of choosing a file is that the user needs only
too choose a folder (or an initial file). If the name of the file can be
programmatically generated then the user does not need to browser or enter a new
file name, just keep hitting the save button.
Nested Class Summary |
---|
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.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected JButton |
chooseButton
Button that opens the file chooser dialog. |
protected JTextField |
path
The text field used to display/input the file path. |
static String |
SAVE_COMMAND
The command associated with save events. |
static int |
SAVE_ID
The id of save events. |
protected JButton |
saveButton
Button that triggers the file to be saved. |
protected ActionListener |
saveListener
The listener that will react to the save button being pressed, or null if no listener is registered. |
private static long |
serialVersionUID
Serialisation version id. |
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 | |
---|---|
JFileSaver(String filePath)
Create a file chooser panel, defaulting to the given file location. |
Method Summary | |
---|---|
void |
actionPerformed(ActionEvent e)
|
int |
chooseFile()
Open a dialog to allow the user to choose a file. |
static boolean |
ensureParentFolderExists(File file,
Component component)
Ensure the parent folder for a given file exists. |
File |
getFile()
Get the chosen file. |
boolean |
isValidFile()
Check if the current file chosen is valid. |
void |
saveFile()
Trigger the file to be saved. |
void |
setEditable(boolean editable)
Decide whether the user can hand-edit the file path. |
void |
setFile(File file)
Set the file chosen. |
void |
setFileName(String fileName)
Change the name of the file chosen. |
void |
setSaveListener(ActionListener listener)
Set the save listener. |
boolean |
validateFile()
Check the file path entered is valid. |
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int SAVE_ID
public static final String SAVE_COMMAND
private static final long serialVersionUID
protected JTextField path
protected JButton chooseButton
protected JButton saveButton
protected ActionListener saveListener
null
if no listener is registered.
Constructor Detail |
---|
public JFileSaver(String filePath)
filePath
- the initial pathMethod Detail |
---|
public void setEditable(boolean editable)
editable
- true
if the path can be edited,
false
if the user must use the file chooserpublic void setSaveListener(ActionListener listener)
listener
- the listener that will save the filesaveListener
public File getFile()
public boolean isValidFile()
true
if the file returned from getFile
can be written topublic void setFile(File file)
file
- the file to be chosenpublic void setFileName(String fileName)
fileName
- the name of the filepublic int chooseFile()
JFileChooser.APPROVE_OPTION
if the user confirmed a new file locationpublic boolean validateFile() throws IOException
true
if the file path is now valid,
will be false
if the user has chosen to cancel
the changes needed to make the file path valid
IOException
- if the file path could not be validatedpublic void saveFile()
public void actionPerformed(ActionEvent e)
actionPerformed
in interface ActionListener
public static boolean ensureParentFolderExists(File file, Component component)
file
- the target filecomponent
- the UI component used to associate question dialogs
true
if the parent folder for the given file exists
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |