history.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
final WebPopupMenu historyPopup = new WebPopupMenu ();
final WebList historyList = new WebList ( navigationHistory );
historyList.setOpaque ( false );
historyList.setVisibleRowCount ( Math.min ( 10, navigationHistory.size () ) );
historyList.setRolloverSelectionEnabled ( true );
historyList.setCellRenderer ( new WebComboBoxCellRenderer ()
{
@Override
public Component getListCellRendererComponent ( final JList list, final Object value, final int index,
final boolean isSelected, final boolean cellHasFocus )
{
final WebComboBoxElement renderer =
( WebComboBoxElement ) super.getListCellRendererComponent ( list, value, index, isSelected, cellHasFocus );
final File file = ( File ) value;
if ( file == null )
{
renderer.setIcon ( FileUtils.getMyComputerIcon () );
renderer.setText ( LanguageManager.get ( "weblaf.filechooser.root" ) );
}
else
{
renderer.setIcon ( FileUtils.getFileIcon ( file ) );
renderer.setText ( TextUtils.shortenText ( FileUtils.getDisplayFileName ( file ), 40, true ) );
}
renderer.setBoldFont ( index == currentHistoryIndex );
return renderer;
}
} );
historyList.addMouseListener ( new MouseAdapter ()
{
@Override
public void mouseReleased ( final MouseEvent e )
{
updateHistoryState ( historyList.getSelectedIndex () );
historyPopup.setVisible ( false );
}
} );
final WebScrollPane scrollPane = new WebScrollPane ( historyList, false, false );
scrollPane.setOpaque ( false );
scrollPane.getViewport ().setOpaque ( false );
scrollPane.setShadeWidth ( 0 );
final WebScrollBar vsb = scrollPane.getWebVerticalScrollBar ();
vsb.setMargin ( WebComboBoxStyle.scrollBarMargin );
vsb.setPaintButtons ( WebComboBoxStyle.scrollBarButtonsVisible );
vsb.setPaintTrack ( WebComboBoxStyle.scrollBarTrackVisible );
LafUtils.setScrollBarStyleId ( scrollPane, "combo-box" );
historyPopup.add ( scrollPane );
historyPopup.showBelowMiddle ( history );
historyList.setSelectedIndex ( currentHistoryIndex );
historyList.scrollToCell ( currentHistoryIndex );
}
} );
pathField = new WebPathField ();
pathFieldListener = new PathFieldListener ()
{
@Override
public void directoryChanged ( final File newDirectory )
{
updateCurrentFolder ( newDirectory, UpdateSource.path );
}
};
pathField.addPathFieldListener ( pathFieldListener );
folderUp = new WebButton ( FOLDER_UP_ICON );
folderUp.setLanguage ( "weblaf.filechooser.folderup" );
folderUp.addHotkey ( WebFileChooserPanel.this, Hotkey.ALT_UP ).setHotkeyDisplayWay ( TooltipWay.down );
folderUp.setRolloverDecoratedOnly ( true );
folderUp.setFocusable ( false );
folderUp.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
if ( hotkeysAllowed.provide () && currentFolder != null )
{
updateCurrentFolder ( currentFolder.getParentFile (), UpdateSource.toolbar );
}
}
} );
folderHome = new WebButton ( FOLDER_HOME_ICON );
folderHome.setLanguage ( "weblaf.filechooser.home" );
folderHome.addHotkey ( WebFileChooserPanel.this, Hotkey.ALT_HOME ).setHotkeyDisplayWay ( TooltipWay.down );
folderHome.setRolloverDecoratedOnly ( true );
folderHome.setFocusable ( false );
folderHome.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
if ( hotkeysAllowed.provide () )
{
updateCurrentFolder ( FileUtils.getUserHome (), UpdateSource.toolbar );
}
}
} );
refresh = new WebButton ( REFRESH_ICON );
refresh.setLanguage ( "weblaf.filechooser.refresh" );
refresh.addHotkey ( WebFileChooserPanel.this, Hotkey.F5 ).setHotkeyDisplayWay ( TooltipWay.down );
refresh.setRolloverDecoratedOnly ( true );
refresh.setFocusable ( false );
refresh.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
if ( hotkeysAllowed.provide () )
{
reloadCurrentFolder ();
}
}
} );
folderNew = new WebButton ( FOLDER_NEW_ICON );
folderNew.setLanguage ( "weblaf.filechooser.newfolder" );
folderNew.addHotkey ( WebFileChooserPanel.this, Hotkey.CTRL_N ).setHotkeyDisplayWay ( TooltipWay.down );
folderNew.setRolloverDecoratedOnly ( true );
folderNew.setFocusable ( false );
folderNew.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
if ( hotkeysAllowed.provide () && currentFolder != null )
{
final String defaultName = LanguageManager.get ( "weblaf.filechooser.newfolder.name" );
final String freeName = FileUtils.getAvailableName ( currentFolder, defaultName );
final File file = new File ( currentFolder, freeName );
if ( file.mkdir () )
{
// Update view
// This action can be optimized, but that will make a lot of additional actions and most likely cause some troubles
reloadCurrentFolder ();
// Chaging folder name
setSelectedFile ( file );
editSelectedFileName ();
}
else
{
final String message = LanguageManager.get ( "weblaf.filechooser.newfolder.error.text" );
final String title = LanguageManager.get ( "weblaf.filechooser.newfolder.error.title" );
WebOptionPane.showMessageDialog ( WebFileChooserPanel.this, message, title, WebOptionPane.ERROR_MESSAGE );
}
}
}
} );
remove = new WebButton ( REMOVE_ICON );
remove.setLanguage ( "weblaf.filechooser.delete" );
remove.addHotkey ( WebFileChooserPanel.this, Hotkey.DELETE ).setHotkeyDisplayWay ( TooltipWay.down );
remove.setRolloverDecoratedOnly ( true );
remove.setEnabled ( false );
remove.setFocusable ( false );
remove.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
if ( hotkeysAllowed.provide () )
{
deleteSelectedFiles ();
}
}
} );
view = new WebButton ( VIEW_ICON );
view.setLanguage ( "weblaf.filechooser.view" );
view.setRolloverDecoratedOnly ( true );
view.setFocusable ( false );
view.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
final WebPopupMenu viewChoose = new WebPopupMenu ();
final WebRadioButtonMenuItem icons = new WebRadioButtonMenuItem ( VIEW_ICONS_ICON );
icons.setLanguage ( "weblaf.filechooser.view.icons" );
icons.setSelected ( getViewType ().equals ( FileChooserViewType.icons ) );
icons.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
setViewType ( FileChooserViewType.icons );
}
} );
viewChoose.add ( icons );
final WebRadioButtonMenuItem tiles = new WebRadioButtonMenuItem ( VIEW_TILES_ICON );
tiles.setLanguage ( "weblaf.filechooser.view.tiles" );
tiles.setSelected ( getViewType ().equals ( FileChooserViewType.tiles ) );
tiles.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
setViewType ( FileChooserViewType.tiles );
}
} );
viewChoose.add ( tiles );
final WebRadioButtonMenuItem table = new WebRadioButtonMenuItem ( VIEW_TABLE_ICON );
table.setLanguage ( "weblaf.filechooser.view.table" );
table.setSelected ( getViewType ().equals ( FileChooserViewType.table ) );
table.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
setViewType ( FileChooserViewType.table );
}
} );
viewChoose.add ( table );
final ButtonGroup viewGroup = new ButtonGroup ();
viewGroup.add ( icons );
viewGroup.add ( tiles );
viewGroup.add ( table );
viewChoose.showBelowMiddle ( view );
}
} );
toolBar.add ( backward );
toolBar.add ( forward );