Skip to content

Commit

Permalink
Fixed some small bugs found by testing on other platforms:
Browse files Browse the repository at this point in the history
- the L&F was not always correctly set due to the order
  in which bundles are started. This could lead to half-
  applied L&F;
- the application icon on OSX wasn't set correctly;
- the run batch file for Windows didn't work correctly
  with latest JRE.
  • Loading branch information
jawi committed Nov 18, 2011
1 parent aa658a0 commit 74f96f1
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 148 deletions.
5 changes: 5 additions & 0 deletions client/src/main/java/nl/lxtreme/ols/client/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ public void init( final BundleContext aContext, final DependencyManager aManager
.setCallbacks( "addTool", "removeTool" ) //
.setRequired( false ) //
) //
.add( createServiceDependency() //
.setService( Exporter.class ) //
.setCallbacks( "addExporter", "removeExporter" ) //
.setRequired( false ) //
) //
);
}
}
Expand Down
149 changes: 134 additions & 15 deletions client/src/main/java/nl/lxtreme/ols/client/ClientController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.List;
Expand Down Expand Up @@ -72,6 +73,40 @@ protected void run( final List<Void> aArgs )
}
}

/**
* Provides an {@link Action} for closing a {@link JOptionPane}.
*/
static final class CloseOptionPaneAction extends AbstractAction
{
private static final long serialVersionUID = 1L;

/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed( final ActionEvent aEvent )
{
final JOptionPane optionPane = ( JOptionPane )aEvent.getSource();
optionPane.setValue( Integer.valueOf( JOptionPane.CLOSED_OPTION ) );
}
}

/**
* Provides a hack to ensure the system class loader is used at all times when
* loading UI classes/resources/...
*/
static class CLValue implements UIDefaults.ActiveValue
{
/**
* @see javax.swing.UIDefaults.ActiveValue#createValue(javax.swing.UIDefaults)
*/
public @Override
ClassLoader createValue( final UIDefaults aDefaults )
{
return Activator.class.getClassLoader();
}
}

/**
* Provides a default tool context implementation.
*/
Expand Down Expand Up @@ -234,15 +269,6 @@ public ClientController( final BundleContext aBundleContext )

this.progressAccumulatingRunnable = new ProgressUpdatingRunnable();
this.repaintAccumulatingRunnable = new AccumulatingRepaintingRunnable();

SwingComponentUtils.invokeOnEDT( new Runnable()
{
@Override
public void run()
{
ClientController.this.mainFrame = new MainFrame( ClientController.this );
}
} );
}

// METHODS
Expand Down Expand Up @@ -1351,6 +1377,10 @@ public void showPreferencesDialog( final Window aParent )
*/
public void start()
{
final HostProperties hostProperties = getHostProperties();

initOSSpecifics( hostProperties.getShortName() );

// Make sure we're running on the EDT to ensure the Swing threading model is
// correctly defined...
SwingUtilities.invokeLater( new Runnable()
Expand All @@ -1361,14 +1391,12 @@ public void run()
// Cause exceptions to be shown in a more user-friendly way...
JErrorDialog.installSwingExceptionHandler();

ClientController.this.mainFrame = new MainFrame( ClientController.this );

final MainFrame mainFrame = getMainFrame();

HostProperties hostProperties = getHostProperties();
if ( hostProperties != null )
{
mainFrame.setTitle( hostProperties.getFullName() );
mainFrame.setStatus( "{0} v{1} ready ...", hostProperties.getShortName(), hostProperties.getVersion() );
}
mainFrame.setTitle( hostProperties.getFullName() );
mainFrame.setStatus( "{0} v{1} ready ...", hostProperties.getShortName(), hostProperties.getVersion() );

LOG.info( "Client started ..." );

Expand Down Expand Up @@ -1880,6 +1908,68 @@ private Tool<?> getTool( final String aName ) throws IllegalArgumentException
return null;
}

/**
* Initializes the OS-specific stuff.
*
* @param aApplicationName
* the name of the application (when this needs to be passed to the
* guest OS);
* @param aApplicationCallback
* the application callback used to report application events on some
* platforms (Mac OS), may be <code>null</code>.
*/
private void initOSSpecifics( final String aApplicationName )
{
final HostInfo hostInfo = HostUtils.getHostInfo();
if ( hostInfo.isMacOS() )
{
// Moves the main menu bar to the screen menu bar location...
System.setProperty( "apple.laf.useScreenMenuBar", "true" );
System.setProperty( "apple.awt.graphics.EnableQ2DX", "true" );
System.setProperty( "com.apple.mrj.application.apple.menu.about.name", aApplicationName );
System.setProperty( "com.apple.mrj.application.growbox.intrudes", "false" );
System.setProperty( "com.apple.mrj.application.live-resize", "false" );
System.setProperty( "com.apple.macos.smallTabs", "true" );
System.setProperty( "apple.eawt.quitStrategy", "CLOSE_ALL_WINDOWS" );

// Install an additional accelerator (Cmd+W) for closing option panes...
ActionMap map = ( ActionMap )UIManager.get( "OptionPane.actionMap" );
if ( map == null )
{
map = new ActionMap();
UIManager.put( "OptionPane.actionMap", map );
}
map.put( "close", new CloseOptionPaneAction() );

UIManager.put( "OptionPane.windowBindings", //
new Object[] { SwingComponentUtils.createMenuKeyMask( KeyEvent.VK_W ), "close", "ESCAPE", "close" } );
}
else if ( hostInfo.isUnix() )
{
try
{
UIManager.put( "Application.useSystemFontSettings", Boolean.FALSE );
setLookAndFeel( "com.jgoodies.looks.plastic.Plastic3DLookAndFeel" );
}
catch ( Exception exception )
{
Logger.getAnonymousLogger().log( Level.WARNING, "Failed to set look and feel!", exception );
}
}
else if ( hostInfo.isWindows() )
{
try
{
UIManager.put( "Application.useSystemFontSettings", Boolean.TRUE );
setLookAndFeel( "com.jgoodies.looks.plastic.PlasticXPLookAndFeel" );
}
catch ( Exception exception )
{
Logger.getAnonymousLogger().log( Level.WARNING, "Failed to set look and feel!", exception );
}
}
}

/**
* Dispatches a request to repaint the entire main frame.
*/
Expand Down Expand Up @@ -1944,4 +2034,33 @@ private void setCursorData( final Long[] aCursorData, final boolean aCursorsEnab
this.dataContainer.setCursorPosition( i, aCursorData[i] );
}
}

/**
* @param aLookAndFeelClass
*/
private void setLookAndFeel( final String aLookAndFeelClassName )
{
final UIDefaults defaults = UIManager.getDefaults();
// to make sure we always use system class loader
defaults.put( "ClassLoader", new CLValue() );

final ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
try
{
Thread.currentThread().setContextClassLoader( Activator.class.getClassLoader() );
UIManager.setLookAndFeel( aLookAndFeelClassName );
}
catch ( Exception exception )
{
// Make sure to handle IO-interrupted exceptions properly!
if ( !HostUtils.handleInterruptedException( exception ) )
{
Logger.getAnonymousLogger().log( Level.WARNING, "Failed to set look and feel!", exception );
}
}
finally
{
Thread.currentThread().setContextClassLoader( oldCL );
}
}
}
2 changes: 1 addition & 1 deletion ols.distribution/src/main/assembly/ext/app-bundle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</target>

<target name="package" depends="init" description="Creates the OSX app bundle" if="isMac">
<jarbundler dir="${project.targetapp}" bundleid="nl.lxtreme.ols" name="${ols.project.name}" shortname="${ols.project.name}" mainclass="nl.lxtreme.ols.runner.Runner" version="${project.version}" build="1" jvmversion="1.6+" arguments="-Dnl.lxtreme.ols.bundle.dir=$JAVAROOT/plugins" workingdirectory="$APP_PACKAGE/Contents/Resources/Java" vmoptions="-Xmx1024m" icon="${basedir}/../resources/LogicSniffer.icns">
<jarbundler dir="${project.targetapp}" bundleid="nl.lxtreme.ols" name="${ols.project.name}" shortname="${ols.project.name}" mainclass="nl.lxtreme.ols.runner.Runner" version="${project.version}" build="1" jvmversion="1.6+" arguments="-Dnl.lxtreme.ols.bundle.dir=$JAVAROOT/plugins" workingdirectory="$APP_PACKAGE/Contents/Resources/Java" vmoptions="-Xmx1024m" icon="${basedir}/../../resources/LogicSniffer.icns">
<!-- put all bin/*.jar files on the class path -->
<jarfileset dir="${project.targetapp-tmp}">
<include name="bin/*.jar" />
Expand Down
2 changes: 1 addition & 1 deletion ols.distribution/src/main/resources/run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rem determine the location this script is run in...
set BASEDIR=%~dp0
rem all paths are used relatively from the base dir...
set PLUGINDIR=%BASEDIR%\plugins
set CLASSPATH=%BASEDIR%\bin\*
set CLASSPATH=.;%BASEDIR%\bin\*
set MEMSETTINGS=-Xmx1024m

rem For now, use the "console enabled" java for Windows...
Expand Down
131 changes: 0 additions & 131 deletions util/src/main/java/nl/lxtreme/ols/util/internal/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
package nl.lxtreme.ols.util.internal;


import java.awt.event.*;
import java.util.logging.*;

import javax.swing.*;

import nl.lxtreme.ols.util.*;
import nl.lxtreme.ols.util.swing.*;
import nl.lxtreme.ols.util.swing.component.*;
Expand All @@ -39,42 +36,6 @@
*/
public class Activator extends DependencyActivatorBase
{
// INNER TYPES

/**
* Provides an {@link Action} for closing a {@link JOptionPane}.
*/
static final class CloseOptionPaneAction extends AbstractAction
{
private static final long serialVersionUID = 1L;

/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed( final ActionEvent aEvent )
{
final JOptionPane optionPane = ( JOptionPane )aEvent.getSource();
optionPane.setValue( Integer.valueOf( JOptionPane.CLOSED_OPTION ) );
}
}

/**
* Provides a hack to ensure the system class loader is used at all times when
* loading UI classes/resources/...
*/
static class CLValue implements UIDefaults.ActiveValue
{
/**
* @see javax.swing.UIDefaults.ActiveValue#createValue(javax.swing.UIDefaults)
*/
public @Override
ClassLoader createValue( final UIDefaults aDefaults )
{
return Activator.class.getClassLoader();
}
}

// METHODS

/**
Expand All @@ -94,8 +55,6 @@ public void init( final BundleContext aContext, final DependencyManager aManager
{
final HostProperties hostProperties = new HostResourceProperties( aContext );

initOSSpecifics( hostProperties.getShortName() );

logEnvironment( hostProperties );

aManager.add( createComponent() //
Expand Down Expand Up @@ -123,68 +82,6 @@ public void init( final BundleContext aContext, final DependencyManager aManager
}
}

/**
* Initializes the OS-specific stuff.
*
* @param aApplicationName
* the name of the application (when this needs to be passed to the
* guest OS);
* @param aApplicationCallback
* the application callback used to report application events on some
* platforms (Mac OS), may be <code>null</code>.
*/
private void initOSSpecifics( final String aApplicationName )
{
final HostInfo hostInfo = HostUtils.getHostInfo();
if ( hostInfo.isMacOS() )
{
// Moves the main menu bar to the screen menu bar location...
System.setProperty( "apple.laf.useScreenMenuBar", "true" );
System.setProperty( "apple.awt.graphics.EnableQ2DX", "true" );
System.setProperty( "com.apple.mrj.application.apple.menu.about.name", aApplicationName );
System.setProperty( "com.apple.mrj.application.growbox.intrudes", "false" );
System.setProperty( "com.apple.mrj.application.live-resize", "false" );
System.setProperty( "com.apple.macos.smallTabs", "true" );
System.setProperty( "apple.eawt.quitStrategy", "CLOSE_ALL_WINDOWS" );

// Install an additional accelerator (Cmd+W) for closing option panes...
ActionMap map = ( ActionMap )UIManager.get( "OptionPane.actionMap" );
if ( map == null )
{
map = new ActionMap();
UIManager.put( "OptionPane.actionMap", map );
}
map.put( "close", new CloseOptionPaneAction() );

UIManager.put( "OptionPane.windowBindings", //
new Object[] { SwingComponentUtils.createMenuKeyMask( KeyEvent.VK_W ), "close", "ESCAPE", "close" } );
}
else if ( hostInfo.isUnix() )
{
try
{
UIManager.put( "Application.useSystemFontSettings", Boolean.FALSE );
setLookAndFeel( "com.jgoodies.looks.plastic.Plastic3DLookAndFeel" );
}
catch ( Exception exception )
{
Logger.getAnonymousLogger().log( Level.WARNING, "Failed to set look and feel!", exception );
}
}
else if ( hostInfo.isWindows() )
{
try
{
UIManager.put( "Application.useSystemFontSettings", Boolean.TRUE );
setLookAndFeel( "com.jgoodies.looks.plastic.PlasticXPLookAndFeel" );
}
catch ( Exception exception )
{
Logger.getAnonymousLogger().log( Level.WARNING, "Failed to set look and feel!", exception );
}
}
}

/**
* @param aContext
*/
Expand All @@ -203,32 +100,4 @@ private void logEnvironment( final HostProperties aProperties )
Logger.getLogger( getClass().getName() ).info( sb.toString() );
}

/**
* @param aLookAndFeelClass
*/
private void setLookAndFeel( final String aLookAndFeelClassName )
{
final UIDefaults defaults = UIManager.getDefaults();
// to make sure we always use system class loader
defaults.put( "ClassLoader", new CLValue() );

final ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
try
{
Thread.currentThread().setContextClassLoader( Activator.class.getClassLoader() );
UIManager.setLookAndFeel( aLookAndFeelClassName );
}
catch ( Exception exception )
{
// Make sure to handle IO-interrupted exceptions properly!
if ( !HostUtils.handleInterruptedException( exception ) )
{
Logger.getAnonymousLogger().log( Level.WARNING, "Failed to set look and feel!", exception );
}
}
finally
{
Thread.currentThread().setContextClassLoader( oldCL );
}
}
}

0 comments on commit 74f96f1

Please sign in to comment.