# HG changeset patch # User Mario Torre # Date 1372101861 -7200 # Node ID d3a24826cf5da40f041824e1cbbb6ec54f863140 # Parent ed73c0796267e2c5730ff9868bd34d68828db544 Fix UI of ValueFields review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-June/007092.html reviewed-by: vanaltj diff -r ed73c0796267 -r d3a24826cf5d client/swing/src/main/java/com/redhat/thermostat/client/swing/components/ValueField.java --- 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); } - } - diff -r ed73c0796267 -r d3a24826cf5d client/swing/src/main/java/com/redhat/thermostat/client/swing/components/ValueFieldUI.java --- /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 + * . + * + * 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 +} diff -r ed73c0796267 -r d3a24826cf5d laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/ThemeManager.java --- 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); + } } }