changeset 1146:d3a24826cf5d

Fix UI of ValueFields review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-June/007092.html reviewed-by: vanaltj
author Mario Torre <neugens.limasoftware@gmail.com>
date Mon, 24 Jun 2013 21:24:21 +0200
parents ed73c0796267
children 52736b6a71d2
files client/swing/src/main/java/com/redhat/thermostat/client/swing/components/ValueField.java client/swing/src/main/java/com/redhat/thermostat/client/swing/components/ValueFieldUI.java laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/ThemeManager.java
diffstat 3 files changed, 75 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/ValueField.java	Mon Jun 24 16:44:23 2013 +0200
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/ValueField.java	Mon Jun 24 21:24:21 2013 +0200
@@ -36,6 +36,8 @@
 
 package com.redhat.thermostat.client.swing.components;
 
+import java.awt.Color;
+
 import javax.swing.JEditorPane;
 import javax.swing.UIManager;
 import javax.swing.text.DefaultCaret;
@@ -48,14 +50,29 @@
 public class ValueField extends JEditorPane {
 
     public ValueField(String text) {
+        setUI(new ValueFieldUI());
+
         setText(text);
         setBorder(null);
         setOpaque(false);
+        
+        // TODO: we should cleanup those properties and define
+        // Thermostat specific ones based on the actual look and feel, since
+        // not all look and feel will necessarily have those set
         setBackground(UIManager.getColor("Label.background"));
         setForeground(UIManager.getColor("Label.foreground"));
+        setSelectedTextColor(UIManager.getColor("Label.background"));
+        
+        Color selectionColor = UIManager.getColor("thermostat-selection-bg-color");
+        if (selectionColor == null) {
+            selectionColor = UIManager.getColor("Label.foreground");
+        }
+        setSelectionColor(selectionColor);
+
         setFont(UIManager.getFont("Label.font"));
+        
         setEditable(false);
-
+        
         /*
          * The default caret update policy forces any scroll pane this
          * component is added to to scroll so that this component is visible.
@@ -67,6 +84,4 @@
          */
         ((DefaultCaret) getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
     }
-
 }
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/ValueFieldUI.java	Mon Jun 24 21:24:21 2013 +0200
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2012, 2013 Red Hat, Inc.
+ * 
+ * This file is part of Thermostat.
+ * 
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ * 
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ * 
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ * 
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.client.swing.components;
+
+import javax.swing.plaf.basic.BasicEditorPaneUI;
+
+class ValueFieldUI extends BasicEditorPaneUI {
+
+    // NOTE: used to bypass SynthUI checks
+}
--- a/laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/ThemeManager.java	Mon Jun 24 16:44:23 2013 +0200
+++ b/laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/ThemeManager.java	Mon Jun 24 21:24:21 2013 +0200
@@ -36,12 +36,14 @@
 
 package com.redhat.thermostat.internal.utils.laf;
 
+import java.awt.Color;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 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;
@@ -92,6 +94,7 @@
         }
         
         boolean tryGTKColors = false;
+        boolean nimbusBased = false;
         
         // check if the user has other preferences...
         String laf = System.getProperty("swing.defaultlaf");
@@ -106,6 +109,7 @@
                 break;
             case "nimbus":
                 laf = NimbusLookAndFeel.class.getName();
+                nimbusBased = true;
                 break;
             case "dolphin":
                 laf = "com.redhat.swing.laf.dolphin.DolphinLookAndFeel";
@@ -116,6 +120,7 @@
 
         if (!setLAF(laf)) {
             setLAF(NimbusLookAndFeel.class.getName());
+            nimbusBased = true;
         }
         
         // Thermostat JPopupMenu instances should all be
@@ -138,5 +143,13 @@
             GTKThemeUtils utils = new GTKThemeUtils();
             utils.setNimbusColours();
         }
+        
+        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);
+        }
     }
 }