Permalink
Browse files

Made element group and signal element no longer carry their own color,

but instead take (and set) the one from the UIManager directly. Storing
this color does not yet work.
  • Loading branch information...
1 parent 901caf8 commit 9af011db8fce49ce5bc601191ee3ff1ba1bc3848 @jawi committed Aug 16, 2012
@@ -234,7 +234,7 @@ void start()
fis = new FileInputStream( dataFile );
getManager().getPersistenceDelegate().apply( fis );
}
- catch ( FileNotFoundException exception )
+ catch ( Throwable exception )
{
// Ignore; we shouldn't be here anyways due to dataFile.exists...
}
@@ -263,7 +263,7 @@ void stop()
fos = new FileOutputStream( dataFile );
getManager().getPersistenceDelegate().save( fos );
}
- catch ( FileNotFoundException exception )
+ catch ( Throwable exception )
{
// Ignore; we shouldn't be here anyways due to dataFile.exists...
}
@@ -151,13 +151,15 @@ private void applyOlsSpecificKeys( final Dictionary aProperties ) throws Configu
// Replace all placeholders with real values...
replacePlaceholders( config );
+ final UIDefaults defaults = UIManager.getDefaults();
+
// Write all values to the UIManager...
for ( Map.Entry<Object, Object> entry : config.entrySet() )
{
Object key = entry.getKey();
Object value = entry.getValue();
- UIManager.put( key, value );
+ defaults.put( key, value );
}
}
@@ -251,13 +253,15 @@ private Object parseFontValue( final String value )
*/
private void removeOlsSpecificKeys()
{
- final Enumeration<Object> keys = UIManager.getDefaults().keys();
+ final UIDefaults defaults = UIManager.getDefaults();
+
+ final Enumeration<Object> keys = defaults.keys();
while ( keys.hasMoreElements() )
{
Object key = keys.nextElement();
if ( key.toString().startsWith( PREFIX ) )
{
- UIManager.put( key, null );
+ defaults.put( key, null );
}
}
}
@@ -95,8 +95,6 @@ public int getMask()
private String summaryLabel;
/** The label used for the analog signal. */
private String analogSignalLabel;
- /** The color used as default for this channel group. */
- private Color color;
private boolean visible;
private int viewOptions;
@@ -259,13 +257,11 @@ public SignalElement getChannelByIndex( final int aChannelIndex )
*/
public Color getColor()
{
- Color result = this.color;
-
+ Color result = UIManager.getColor( getColorKey() );
if ( result == null )
{
- result = getDefaultGroupColor( this.index );
+ result = Color.WHITE;
}
-
return result;
}
@@ -472,7 +468,11 @@ public void setAnalogSignalLabel( final String aSignalLabel )
*/
public void setColor( final Color aColor )
{
- this.color = aColor;
+ if ( aColor == null )
+ {
+ throw new IllegalArgumentException( "Color cannot be null!" );
+ }
+ UIManager.put( getColorKey(), aColor );
}
/**
@@ -668,31 +668,22 @@ final void removeElement( final SignalElement aElement )
}
/**
- * Crafts a default name for use when an analog scope has no label set.
- *
- * @return an analog scope name, never <code>null</code>.
+ * @return a key to access the color for this element group, never
+ * <code>null</code>.
*/
- private String getDefaultAnalogSignalName()
+ private String getColorKey()
{
- return String.format( "Scope-%d", Integer.valueOf( getIndex() + 1 ) );
+ return String.format( "ols.channelgroup%d.default.color", Integer.valueOf( ( this.index % 4 ) + 1 ) );
}
/**
- * Returns the default group color, as stored in the UIManager.
+ * Crafts a default name for use when an analog scope has no label set.
*
- * @param aIndex
- * the group index to return the color for.
- * @return a color, never <code>null</code>.
+ * @return an analog scope name, never <code>null</code>.
*/
- private Color getDefaultGroupColor( final int aIndex )
+ private String getDefaultAnalogSignalName()
{
- String key = String.format( "ols.channelgroup%d.default.color", Integer.valueOf( ( aIndex + 1 ) % 4 ) );
- Color defaultColor = UIManager.getColor( key );
- if ( defaultColor == null )
- {
- defaultColor = Color.WHITE;
- }
- return defaultColor;
+ return String.format( "Scope-%d", Integer.valueOf( getIndex() + 1 ) );
}
/**
@@ -59,7 +59,6 @@
private Channel channel;
/** the group we belong to, should always be non-null. */
private ElementGroup group;
- private Color color;
private int height;
private int yPosition;
@@ -248,11 +247,27 @@ public Channel getChannel()
*/
public Color getColor()
{
- Color result = this.color;
+ Color result = null;
+
+ if ( this.group != null )
+ {
+ if ( isDigitalSignal() )
+ {
+ String key = getColorKey();
+ result = UIManager.getColor( key );
+ }
+
+ if ( result == null )
+ {
+ // Fall back to group color...
+ result = this.group.getColor();
+ }
+ }
if ( result == null )
{
- result = getDefaultColor();
+ // Fall back to a constant value...
+ result = Color.WHITE;
}
return result;
@@ -507,7 +522,7 @@ public void setColor( final Color aColor )
{
throw new IllegalArgumentException( "Color cannot be null!" );
}
- this.color = aColor;
+ UIManager.put( getColorKey(), aColor );
}
/**
@@ -664,38 +679,13 @@ final void setYposition( final int aYPosition )
}
/**
- * Returns the default color for this signal element.
- *
- * @return a color, never <code>null</code>.
+ * @return
*/
- private Color getDefaultColor()
+ private String getColorKey()
{
- Color result = null;
-
- if ( this.group != null )
- {
- if ( isDigitalSignal() )
- {
- Integer groupIdx = Integer.valueOf( ( this.group.getIndex() + 1 ) % 4 );
- Integer channelIdx = Integer.valueOf( this.channel.getIndex() + 1 );
- String key = String.format( "ols.channelgroup%d.channel%d.default.color", groupIdx, channelIdx );
- result = UIManager.getColor( key );
- }
-
- if ( result == null )
- {
- // Fall back to group color...
- result = this.group.getColor();
- }
- }
-
- if ( result == null )
- {
- // Fall back to a constant value...
- result = Color.white;
- }
-
- return result;
+ Integer groupIdx = Integer.valueOf( ( this.group.getIndex() % 4 ) + 1 );
+ Integer channelIdx = Integer.valueOf( ( this.channel.getIndex() % 8 ) + 1 );
+ return String.format( "ols.channelgroup%d.channel%d.default.color", groupIdx, channelIdx );
}
/**

0 comments on commit 9af011d

Please sign in to comment.