public class MidicaFileChooser
extends javax.swing.JFileChooser
This class provides a file chooser that allows to choose a file together with a charset, a config icon etc.
It can add a charset combobox and a description to the inherited JFileChooser
, an ConfigIcon
and so on.
Moreover this class also adjusts the look and feel of buttons for nimbus.
javax.swing.JFileChooser.AccessibleJFileChooser
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
private javax.swing.JComboBox<ComboboxStringOption> |
cbxCharset |
private javax.swing.JCheckBox |
cbxDirectImport |
private ConfigIcon |
configIcon |
private java.lang.String |
confKeyForeignExe |
private static int |
DESC_CHARS |
private static int |
DESC_PREF_WIDTH |
private javax.swing.JTextField |
fldForeignExec |
private boolean |
needCharsetSel |
private boolean |
needConfigIcon |
private boolean |
needDirectImport |
private boolean |
needForeignExe |
private FileSelector |
parentWindow |
private byte |
purpose |
private static long |
serialVersionUID |
private java.lang.String |
type |
private static int |
WIDTH_CORRECTION |
ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY, accessibleContext, ACCESSORY_CHANGED_PROPERTY, APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY, APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY, APPROVE_OPTION, APPROVE_SELECTION, CANCEL_OPTION, CANCEL_SELECTION, CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY, CUSTOM_DIALOG, DIALOG_TITLE_CHANGED_PROPERTY, DIALOG_TYPE_CHANGED_PROPERTY, DIRECTORIES_ONLY, DIRECTORY_CHANGED_PROPERTY, ERROR_OPTION, FILE_FILTER_CHANGED_PROPERTY, FILE_HIDING_CHANGED_PROPERTY, FILE_SELECTION_MODE_CHANGED_PROPERTY, FILE_SYSTEM_VIEW_CHANGED_PROPERTY, FILE_VIEW_CHANGED_PROPERTY, FILES_AND_DIRECTORIES, FILES_ONLY, MULTI_SELECTION_ENABLED_CHANGED_PROPERTY, OPEN_DIALOG, SAVE_DIALOG, SELECTED_FILE_CHANGED_PROPERTY, SELECTED_FILES_CHANGED_PROPERTY
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
MidicaFileChooser(java.lang.String type,
byte purpose,
java.lang.String directory,
boolean charsetSel,
java.lang.String confKeyForeignExe,
FileSelector parent)
Creates a new file chooser defaulting to the given directory.
|
Modifier and Type | Method and Description |
---|---|
private void |
changeButtonColors()
Adjusts the colors of buttons for the nimbus look and feel.
|
private javax.swing.JComponent[] |
createCharsetAreas(java.awt.Component leftElement,
java.awt.Component rightElement)
Creates the new widgets, needed for the charset selection.
|
private java.awt.Container |
createConfigArea(java.awt.Component leftElement,
int configType)
Creates the config area.
|
private java.awt.Container |
createDirectImportArea(java.awt.Component leftElement)
Creates the direct import area.
|
private javax.swing.JComponent[] |
createForeignExeAreas(java.awt.Component leftElement,
java.awt.Component rightElement)
Creates the widgets, needed to configure the execution command or path of the foreign program.
|
private javax.swing.JComponent |
createForeignUrlArea(java.lang.String url,
java.awt.Component leftElement)
Creates widgets for the URL of the foreign program.
|
private void |
execPathChanged()
Handles changes in the text field for the executable path.
|
javax.swing.JComboBox<?> |
getCharsetSelectionCbx()
Returns the charset selection combobox, if available, or otherwise null.
|
ConfigIcon |
getConfigIcon()
Returns the config icon, if available, or otherwise null.
|
javax.swing.JTextField |
getForeignExecField()
Returns the text field for the foreign program, if available, or otherwise null.
|
java.lang.String |
getType()
Returns the file type.
|
private void |
insertExtraWidgets(int configType)
Creates extra widgets and inserts them into the right places inside the parent file chooser.
|
boolean |
mustDirectlyImport()
Returns true if the direct import checkbox is available and checked.
|
private void |
transferButtonProperties(javax.swing.JButton source,
MidicaButton target)
Transfers properties from a default file chooser button to a self-created button with different look and feel.
|
accept, addActionListener, addChoosableFileFilter, approveSelection, cancelSelection, changeToParentDirectory, createDialog, ensureFileIsVisible, fireActionPerformed, getAcceptAllFileFilter, getAccessibleContext, getAccessory, getActionListeners, getApproveButtonMnemonic, getApproveButtonText, getApproveButtonToolTipText, getChoosableFileFilters, getControlButtonsAreShown, getCurrentDirectory, getDescription, getDialogTitle, getDialogType, getDragEnabled, getFileFilter, getFileSelectionMode, getFileSystemView, getFileView, getIcon, getName, getSelectedFile, getSelectedFiles, getTypeDescription, getUI, getUIClassID, isAcceptAllFileFilterUsed, isDirectorySelectionEnabled, isFileHidingEnabled, isFileSelectionEnabled, isMultiSelectionEnabled, isTraversable, paramString, removeActionListener, removeChoosableFileFilter, rescanCurrentDirectory, resetChoosableFileFilters, setAcceptAllFileFilterUsed, setAccessory, setApproveButtonMnemonic, setApproveButtonMnemonic, setApproveButtonText, setApproveButtonToolTipText, setControlButtonsAreShown, setCurrentDirectory, setDialogTitle, setDialogType, setDragEnabled, setFileFilter, setFileHidingEnabled, setFileSelectionMode, setFileSystemView, setFileView, setMultiSelectionEnabled, setSelectedFile, setSelectedFiles, setup, showDialog, showOpenDialog, showSaveDialog, updateUI
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
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
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, 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, transferFocusBackward, transferFocusUpCycle
private static final long serialVersionUID
private static final int DESC_CHARS
private static final int DESC_PREF_WIDTH
private static final int WIDTH_CORRECTION
private FileSelector parentWindow
private java.lang.String type
private byte purpose
private boolean needCharsetSel
private boolean needForeignExe
private java.lang.String confKeyForeignExe
private boolean needConfigIcon
private boolean needDirectImport
private javax.swing.JComboBox<ComboboxStringOption> cbxCharset
private ConfigIcon configIcon
private javax.swing.JCheckBox cbxDirectImport
private javax.swing.JTextField fldForeignExec
public MidicaFileChooser(java.lang.String type, byte purpose, java.lang.String directory, boolean charsetSel, java.lang.String confKeyForeignExe, FileSelector parent)
Creates a new file chooser defaulting to the given directory.
type
- File type.purpose
- 1: read; 2: writedirectory
- Default directory.charsetSel
- true, if the the charset selection combobox shall be shown. Otherwise false.confKeyForeignExe
- config key for the foreign executable command or path, if a foreign program is needed. Otherwise: null.parent
- the parent window (only needed for exporters with a config icon)public java.lang.String getType()
Returns the file type.
public javax.swing.JComboBox<?> getCharsetSelectionCbx()
Returns the charset selection combobox, if available, or otherwise null.
public ConfigIcon getConfigIcon()
Returns the config icon, if available, or otherwise null.
public javax.swing.JTextField getForeignExecField()
Returns the text field for the foreign program, if available, or otherwise null.
public boolean mustDirectlyImport()
Returns true if the direct import checkbox is available and checked. Returns false if the checkbox is not available or not checked.
private javax.swing.JComponent[] createCharsetAreas(java.awt.Component leftElement, java.awt.Component rightElement)
Creates the new widgets, needed for the charset selection. These are:
leftElement
- file name label (used to copy the dimension)rightElement
- file type combobox (used to copy the dimension)private javax.swing.JComponent[] createForeignExeAreas(java.awt.Component leftElement, java.awt.Component rightElement)
Creates the widgets, needed to configure the execution command or path of the foreign program. These are:
leftElement
- file name label (used to copy the dimension)rightElement
- file type combobox (used to copy the dimension)private javax.swing.JComponent createForeignUrlArea(java.lang.String url, java.awt.Component leftElement)
Creates widgets for the URL of the foreign program.
These are:
url
- the URL to the foreign programleftElement
- file name label (used to copy the dimension)private java.awt.Container createConfigArea(java.awt.Component leftElement, int configType)
Creates the config area. It consists of a spacer on the left side and the icon on the right side.
leftElement
- file name label (used to copy the dimension)configType
- one of the available types in ConfigIcon
private java.awt.Container createDirectImportArea(java.awt.Component leftElement)
Creates the direct import area. It consists of a spacer on the left side and the (labelled) checkbox on the right side.
leftElement
- file name label (used to copy the dimension)private void insertExtraWidgets(int configType)
Creates extra widgets and inserts them into the right places inside the parent file chooser.
The extra widgets are:
The code in this method is really ugly but necessary because JFileChooser
doesn’t provide any other possibility to add extra elements.
configType
- one of the available types in ConfigIcon
private void changeButtonColors()
Adjusts the colors of buttons for the nimbus look and feel.
The buttons to be adjusted are:
The buttons with icons are adjusted directly.
The open and close buttons are replaced by custom buttons with the same functionality. That’s necessary because directly applying the changes is somehow not enough to make them look like other buttons in the application.
private void transferButtonProperties(javax.swing.JButton source, MidicaButton target)
Transfers properties from a default file chooser button to a self-created button with different look and feel.
source
- the default button.target
- the new button.private void execPathChanged()
Handles changes in the text field for the executable path.
Updates the config accordingly.