changeset 1269:38d89cb2112d

Small fixlet for colour schemes http://icedtea.classpath.org/pipermail/thermostat/2013-October/008358.html reviewed-by: vanaltj
author Mario Torre <neugens.limasoftware@gmail.com>
date Fri, 04 Oct 2013 14:23:39 +0200
parents 4b1cf77f0f90
children 11bb959f9814
files client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/ReferenceComponent.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/ReferenceComponentPainter.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/UIDefaults.java laf-utils/pom.xml laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/ThemeManager.java laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/gtk/GTKThemeUtils.java
diffstat 6 files changed, 45 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/ReferenceComponent.java	Thu Oct 03 17:18:38 2013 -0600
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/ReferenceComponent.java	Fri Oct 04 14:23:39 2013 +0200
@@ -67,11 +67,14 @@
     private Icon selectedIcon;
     private Icon icon;
     
+    private ReferenceComponentPainter painter;
+    
     private Ref vm;
     
     public ReferenceComponent(Ref vm) {
         
         this.vm = vm;
+        this.painter = new ReferenceComponentPainter();
         
         setLayout(new BorderLayout());
 
@@ -120,26 +123,7 @@
     
     @Override
     protected void paintComponent(Graphics g) {
-        
-        super.paintComponent(g);
-        
-        UIDefaults palette = UIDefaults.getInstance();
-
-        GraphicsUtils utils = GraphicsUtils.getInstance();
-        Graphics2D graphics = utils.createAAGraphics(g);
-        if (isSelected()) {
-
-            Color start = utils.deriveWithAlpha(palette.getSelectedComponentBGColor(), 0.6f);
-            Color stop = utils.deriveWithAlpha(palette.getSelectedComponentBGColor(), 0.80f);
-            utils.setGradientPaint(graphics, 0, getHeight(), start, stop);
-        
-        } else {
-            graphics.setColor(getBackground());
-        }
-
-        Rectangle bounds = graphics.getClipBounds();
-        graphics.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);            
-        graphics.dispose();
+        painter.paint((Graphics2D) g, this, getWidth(), getHeight());
     }
     
     public void setIcon(Icon icon) {
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/ReferenceComponentPainter.java	Thu Oct 03 17:18:38 2013 -0600
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/ReferenceComponentPainter.java	Fri Oct 04 14:23:39 2013 +0200
@@ -63,10 +63,7 @@
         GraphicsUtils utils = GraphicsUtils.getInstance();
         Graphics2D graphics = utils.createAAGraphics(g);
         if (component.isSelected()) {
-
-            Color start = utils.deriveWithAlpha(palette.getSelectedComponentBGColor(), 0.6f);
-            Color stop = utils.deriveWithAlpha(palette.getSelectedComponentBGColor(), 0.80f);
-            utils.setGradientPaint(graphics, 0, component.getUiComponent().getHeight(), start, stop);
+            graphics.setColor(palette.getSelectedComponentBGColor());
         } else {
             graphics.setColor(component.getUiComponent().getBackground());
         }
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/UIDefaults.java	Thu Oct 03 17:18:38 2013 -0600
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/UIDefaults.java	Fri Oct 04 14:23:39 2013 +0200
@@ -38,6 +38,8 @@
 
 import java.awt.Color;
 
+import javax.swing.UIManager;
+
 import com.redhat.thermostat.client.ui.Palette;
 
 /**
@@ -50,15 +52,18 @@
     }
     
     public Color getSelectedComponentFGColor() {
-        return Palette.DROID_GRAY.getColor();
+        Color color = (Color) UIManager.get("thermostat-selection-fg-color");
+        return color != null ? color : Palette.LIGHT_GRAY.getColor();        
     }
 
     public Color getComponentFGColor() {
-        return Palette.DROID_BLACK.getColor();
+        Color color = (Color) UIManager.get("thermostat-fg-color");
+        return color != null ? color : Palette.DROID_BLACK.getColor();            
     }
 
     public Color getSelectedComponentBGColor() {
-        return Palette.AZUREUS.getColor();
+        Color color = (Color) UIManager.get("thermostat-selection-bg-color");
+        return color != null ? color : Palette.THERMOSTAT_BLU.getColor();
     }
 
     public int getIconSize() {
--- a/laf-utils/pom.xml	Thu Oct 03 17:18:38 2013 -0600
+++ b/laf-utils/pom.xml	Fri Oct 04 14:23:39 2013 +0200
@@ -114,6 +114,11 @@
       <artifactId>thermostat-shared-config</artifactId>
       <version>${project.version}</version>
     </dependency>
-
+    
+    <dependency>
+      <groupId>com.redhat.thermostat</groupId>
+      <artifactId>thermostat-client-core</artifactId>
+      <version>${project.version}</version>
+    </dependency>
   </dependencies>
 </project>
--- a/laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/ThemeManager.java	Thu Oct 03 17:18:38 2013 -0600
+++ b/laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/ThemeManager.java	Fri Oct 04 14:23:39 2013 +0200
@@ -43,11 +43,11 @@
 import javax.swing.JPopupMenu;
 import javax.swing.SwingConstants;
 import javax.swing.SwingUtilities;
-import javax.swing.UIDefaults;
 import javax.swing.UIManager;
 import javax.swing.UnsupportedLookAndFeelException;
 import javax.swing.plaf.nimbus.NimbusLookAndFeel;
 
+import com.redhat.thermostat.client.ui.Palette;
 import com.redhat.thermostat.internal.utils.laf.gtk.GTKThemeUtils;
 
 public class ThemeManager {
@@ -144,12 +144,22 @@
             utils.setNimbusColours();
         }
         
+        // TODO: document those or place them into a proper UI class
+        UIManager.put("thermostat-fg-color", Palette.DROID_BLACK);
+        UIManager.put("thermostat-selection-fg-color", Palette.THERMOSTAT_BLU);        
+        UIManager.put("thermostat-selection-bg-color", Palette.LIGHT_GRAY);
         if (nimbusBased) {
             // very internal and very secret for now, should be moved
             // to a proper location but first needs to be appropriately tested
             // on multiple different look and feel
             Color color = UIManager.getDefaults().getColor("nimbusSelectionBackground");
             UIManager.put("thermostat-selection-bg-color", color);
+            
+            color = UIManager.getDefaults().getColor("textHighlightText");
+            UIManager.put("thermostat-selection-fg-color", color);
+            
+            color = UIManager.getDefaults().getColor("text");
+            UIManager.put("thermostat-fg-color", color);            
         }
     }
 }
--- a/laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/gtk/GTKThemeUtils.java	Thu Oct 03 17:18:38 2013 -0600
+++ b/laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/gtk/GTKThemeUtils.java	Fri Oct 04 14:23:39 2013 +0200
@@ -121,8 +121,20 @@
         
         initialized = true;
         
-        // if we at least have the bg colour we can try the rest,
-        // otherwise, just skip everything and use nimbus defaults
+        // if we at least have the fg colour we can try the rest,
+        // otherwise, just skip everything and use nimbus defaults        
+        if (hasColor("fg_color")) {
+            int fgColor = getColor("fg_color");
+            Color text = new Color(fgColor);
+            UIManager.put("text", text);
+            if (hasColor("selected_fg_color")) {
+                fgColor = getColor("selected_fg_color");
+                text = new Color(fgColor);
+                UIManager.put("textHighlightText", text);
+            }
+        }
+
+        // same as before, but with bg colours
         if (hasColor("bg_color")) {
             
             // Those numbers are some kind of magic, they represent the
@@ -158,5 +170,6 @@
                 UIManager.put("Menu.background", nimbusFocus);
             }
         }
+        
     }
 }