}
private WebStatusBar createStatusBar ()
{
// Window status bar
final WebStatusBar statusBar = new WebStatusBar ();
// Location breadcrumb
statusBar.add ( getLocationBreadcrumb () );
// Group description
final ExampleGroup sg = getSelectedGroup ();
statusBar.addSpacing ();
final FeatureState fgs = sg.getFeatureGroupState ();
final WebLabel featureState = new WebLabel ();
TooltipManager.setTooltip ( featureState, fgs.getIcon (), fgs.getDescription () );
featureState.setIcon ( fgs.getIcon () );
featureState.addMouseListener ( new MouseAdapter ()
{
@Override
public void mousePressed ( final MouseEvent e )
{
showLegend ( featureState, getSelectedGroup ().getFeatureGroupState () );
}
} );
statusBar.add ( featureState );
statusBar.addSpacing ();
final WebLabel groupDescription = new WebLabel ();
groupDescription.setText ( sg.getGroupDescription () );
statusBar.add ( groupDescription );
exampleTabs.addChangeListener ( new ChangeListener ()
{
@Override
public void stateChanged ( final ChangeEvent e )
{
final ExampleGroup sg = getSelectedGroup ();
final FeatureState fgs = sg.getFeatureGroupState ();
TooltipManager.removeTooltips ( featureState );
TooltipManager.setTooltip ( featureState, fgs.getIcon (), fgs.getDescription () );
featureState.setIcon ( fgs.getIcon () );
groupDescription.setText ( sg.getGroupDescription () );
}
} );
// Update button
final WebButton update = WebButton.createIconWebButton ( getUpdateIcon () );
update.setVisible ( false );
update.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
WebUtils.browseSiteSafely ( WEBLAF_SITE + "download/" );
}
} );
statusBar.addToMiddle ( update );
// Version checker
WebTimer.repeat ( "WebLookAndFeelDemo.versionCheck", 60000L, 10000L, new ActionListener ()
{
private VersionInfo lastVersion = null;
@Override
public void actionPerformed ( final ActionEvent e )
{
try
{
final VersionInfo lv = getLastVersion ();
if ( lv != null && lv.compareTo ( VersionManager.getLibraryVersion () ) > 0 )
{
// Displaying update icon
update.setVisible ( true );
// Updating tips
final ImageIcon updateIcon = getUpdateIcon ();
final WebCustomTooltip versionTip = TooltipManager
.showOneTimeTooltip ( update, null, updateIcon, "New library version available: " + lv.toString () );
update.addMouseListener ( new MouseAdapter ()
{
@Override
public void mouseEntered ( final MouseEvent e )
{
versionTip.closeTooltip ();
update.removeMouseListener ( this );
}
} );
TooltipManager.setTooltip ( update, updateIcon, "Download new version: " + lv.toString () );
// Finishing updater thread
( ( WebTimer ) e.getSource () ).stop ();
}
}
catch ( final Throwable ex )
{
// Ignore version check exceptions
}
}
public VersionInfo getLastVersion ()
{
if ( lastVersion == null )
{
try
{
final String versionUrl = WebLookAndFeelDemo.WEBLAF_SITE + "downloads/version.xml";
lastVersion = XmlUtils.fromXML ( new URL ( versionUrl ) );
}
catch ( final Throwable ex )
{
// Ignore version check exceptions
}
}
return lastVersion;
}
} );
// todo Language chooser button
// final WebButton language = new WebButton ( LanguageManager.getLanguage (),
// LanguageManager.getLanguageIcon ( LanguageManager.getLanguage () ) );
// language.setRound ( StyleConstants.smallRound );
// language.setLeftRightSpacing ( 2 );
// TooltipManager.setTooltip ( language, language.getIcon (), "Application language" );
// language.addActionListener ( new ActionListener ()
// {
// public void actionPerformed ( ActionEvent e )
// {
// WebButtonPopup wbp = new WebButtonPopup ( language, PopupWay.upCenter );
//
// WebButton otherLanguage = new WebButton ( LanguageManager.RUSSIAN,
// LanguageManager.getLanguageIcon ( LanguageManager.RUSSIAN ) );
// otherLanguage.setHorizontalAlignment ( WebButton.LEFT );
// otherLanguage.setUndecorated ( true );
// otherLanguage.setMargin ( 3, 3, 0, 3 );
// otherLanguage.setLeftRightSpacing ( 2 );
// wbp.setContent ( otherLanguage );
//
// PopupManager.showPopup ( language, wbp );
// }
// } );
// statusBar.addToEnd ( language );
// Enabled state toggle
final WebToggleButton enabled = WebToggleButton.createIconWebButton ( enabledIcon );
enabled.addHotkey ( WebLookAndFeelDemo.this, Hotkey.ALT_E );
enabled.setSelected ( true );
final Runnable enabledUpdater = new Runnable ()
{
@Override
public void run ()
{
final boolean e = enabled.isSelected ();
enabled.setIcon ( e ? enabledIcon : disabledIcon );
TooltipManager.removeTooltips ( enabled );
TooltipManager.setTooltip ( enabled, e ? enabledIcon : disabledIcon,
e ? "All examples are enabled" : "All examples are disabled" );
}
};
enabledUpdater.run ();
enabled.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
// Updating button
enabledUpdater.run ();
// Updating examples
final boolean enable = enabled.isSelected ();
for ( int i = 0; i < exampleTabs.getTabCount (); i++ )
{
final Component tabContent = exampleTabs.getComponentAt ( i );
// Workaround to keep focus in window
if ( SwingUtils.hasFocusOwner ( tabContent ) )
{
memoryBar.requestFocusInWindow ();
}
// Enabling/disabling examples
SwingUtils.setEnabledRecursively ( tabContent, enable );
}
}
} );
// Animation toggle
final WebToggleButton animate = WebToggleButton.createIconWebButton ( animationIcon );
TooltipManager.setTooltip ( animate, animationIcon, "Allow heavy animation" );
animate.addHotkey ( WebLookAndFeelDemo.this, Hotkey.ALT_A );
animate.setSelected ( true );
animate.addActionListener ( new ActionListener ()
{
private List<TransitionEffect> oldEffects;
@Override
public void actionPerformed ( final ActionEvent e )
{
if ( animate.isSelected () )
{
containerTransition.setTransitionEffects ( oldEffects );
}
else
{
oldEffects = containerTransition.getTransitionEffects ();
containerTransition.clearTransitionEffects ();
}
}
} );
// Tab names toggle
final WebToggleButton displayTabTitles = WebToggleButton.createIconWebButton ( tabNamesIcon );
TooltipManager.setTooltip ( displayTabTitles, tabNamesIcon, "Display tab titles" );
displayTabTitles.addHotkey ( WebLookAndFeelDemo.this, Hotkey.ALT_T );
displayTabTitles.setSelected ( true );
displayTabTitles.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
if ( displayTabTitles.isSelected () )
{
final List<ExampleGroup> groups = ExamplesManager.getExampleGroups ();
for ( int i = 0; i < exampleTabs.getTabCount (); i++ )
{
exampleTabs.setTitleAt ( i, groups.get ( i ).getGroupName () );
}
}
else
{
for ( int i = 0; i < exampleTabs.getTabCount (); i++ )
{
exampleTabs.setTitleAt ( i, "" );
}
}
}
} );
// Component orientation toggle
final WebToggleButton ltrOrientation = WebToggleButton.createIconWebButton ( orientationIcon );
TooltipManager.setTooltip ( ltrOrientation, orientationIcon, "Use LTR components orientation" );
ltrOrientation.addHotkey ( ltrOrientation, Hotkey.ALT_R );
ltrOrientation.setSelected ( WebLookAndFeel.isLeftToRight () );
ltrOrientation.addActionListener ( new ActionListener ()
{
@Override
public void actionPerformed ( final ActionEvent e )
{
WebLookAndFeel.changeOrientation ();
}
} );
// Special application-wide (global) hotkey
HotkeyManager.registerHotkey ( Hotkey.ALT_R, new HotkeyRunnable ()
{
@Override
public void run ( final KeyEvent e )
{
if ( !ltrOrientation.isFocusOwner () )
{
ltrOrientation.doClick ();
}
}
} );
statusBar.addToEnd ( enabled );
statusBar.addToEnd ( animate );
statusBar.addToEnd ( displayTabTitles );
statusBar.addToEnd ( ltrOrientation );
statusBar.addSeparatorToEnd ();
// Memory bar
memoryBar = new WebMemoryBar ();
memoryBar.setShowMaximumMemory ( false );
memoryBar.setPreferredWidth ( memoryBar.getPreferredSize ().width + 20 );
statusBar.addToEnd ( memoryBar );
NotificationManager.setMargin ( 0, 0, statusBar.getPreferredSize ().height, 0 );
return statusBar;
}