classSearchField = new WebTextField ( 20, false );
classSearchField.setHideInputPromptOnFocus ( false );
classSearchField.setInputPrompt ( "Enter class name here..." );
HotkeyManager.registerHotkey ( classSearchField, Hotkey.ESCAPE, new HotkeyRunnable ()
{
@Override
public void run ( final KeyEvent e )
{
hideClassSearchPopup ();
}
} );
final WebImage leadingComponent = new WebImage ( classSearchIcon );
leadingComponent.setMargin ( 2 );
classSearchField.setLeadingComponent ( leadingComponent );
classSearchPopup = new WebPopup ();
classSearchPopup.setCloseOnFocusLoss ( true );
classSearchPopup.add ( classSearchField );
classSearchPopup.setDefaultFocusComponent ( classSearchField );
classSearchHintsPopup = new WebWindow ( classSearchPopup )
{
@Override
public Dimension getPreferredSize ()
{
final Dimension ps = super.getPreferredSize ();
ps.width = Math.max ( classSearchField.getWidth (), ps.width );
return ps;
}
};
classSearchHintsPopup.setFocusable ( false );
classSearchHintsPopup.setAlwaysOnTop ( true );
classSearchPopup.addFocusableChild ( classSearchHintsPopup );
classSearchHintsList = new WebList ( new DefaultListModel () );
classSearchHintsList.setFocusable ( false );
classSearchHintsList.setRolloverSelectionEnabled ( true );
classSearchHintsList.setSelectionMode ( ListSelectionModel.SINGLE_SELECTION );
classSearchHintsList.setCellRenderer ( new WebListCellRenderer ()
{
@Override
public Component getListCellRendererComponent ( final JList list, final Object value, final int index, final boolean isSelected,
final boolean cellHasFocus )
{
final JarEntry entry = ( JarEntry ) value;
final WebListElement renderer =
( WebListElement ) super.getListCellRendererComponent ( list, value, index, isSelected, cellHasFocus );
renderer.setIcon ( entry.getIcon () );
renderer.setText ( entry.getName () );
return renderer;
}
} );
classSearchHintsList.addMouseListener ( new MouseAdapter ()
{
@Override
public void mousePressed ( final MouseEvent e )
{
if ( SwingUtils.isLeftMouseButton ( e ) )
{
openSelectedHint ();
}
}
} );
HotkeyManager.registerHotkey ( classSearchField, Hotkey.HOME, new HotkeyRunnable ()
{
@Override
public void run ( final KeyEvent e )
{
if ( classSearchHintsList.getModelSize () > 0 )
{
classSearchHintsList.setSelectedIndex ( 0 );
}
}
} );
HotkeyManager.registerHotkey ( classSearchField, Hotkey.UP, new HotkeyRunnable ()
{
@Override
public void run ( final KeyEvent e )
{
if ( classSearchHintsList.getModelSize () > 0 )
{
final int index = classSearchHintsList.getSelectedIndex ();
if ( index > 0 )
{
classSearchHintsList.setSelectedIndex ( index - 1 );
}
else
{
classSearchHintsList.setSelectedIndex ( classSearchHintsList.getModelSize () - 1 );
}
}
}
} );
HotkeyManager.registerHotkey ( classSearchField, Hotkey.DOWN, new HotkeyRunnable ()
{
@Override
public void run ( final KeyEvent e )
{
if ( classSearchHintsList.getModelSize () > 0 )
{
final int index = classSearchHintsList.getSelectedIndex ();
if ( index < classSearchHintsList.getModelSize () - 1 )
{
classSearchHintsList.setSelectedIndex ( index + 1 );
}
else
{
classSearchHintsList.setSelectedIndex ( 0 );
}
}
}
} );
HotkeyManager.registerHotkey ( classSearchField, Hotkey.END, new HotkeyRunnable ()
{
@Override
public void run ( final KeyEvent e )
{
if ( classSearchHintsList.getModelSize () > 0 )
{
classSearchHintsList.setSelectedIndex ( classSearchHintsList.getModelSize () - 1 );
}
}
} );
HotkeyManager.registerHotkey ( classSearchField, Hotkey.ENTER, new HotkeyRunnable ()
{
@Override
public void run ( final KeyEvent e )
{
openSelectedHint ();