changeset 1507:dd501e161176

Font tweaks review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-September/010653.html reviewed-by: omajid
author Mario Torre <neugens.limasoftware@gmail.com>
date Mon, 06 Oct 2014 11:16:38 +0200
parents 6222ea3f5803
children 822dc43b44d2
files README client/swing/src/main/java/com/redhat/thermostat/client/swing/UIDefaults.java client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/UIDefaultsImpl.java 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 laf-utils/src/main/native/GTKThemeUtils.c
diffstat 6 files changed, 193 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/README	Mon Sep 29 15:14:32 2014 -0400
+++ b/README	Mon Oct 06 11:16:38 2014 +0200
@@ -12,7 +12,8 @@
 3.1.1 PASSING JVM SPECIFIC OPTIONS
 3.1.2 GNOME KEYRING
 4.  EXTENDING THERMOSTAT
-5.  REFERENCES
+5.  SYSTEM PROPERTIES
+6.  REFERENCES
 
 
 --------------------------------------------------------------------------------
@@ -136,7 +137,69 @@
 The README.api file contains a list of public/support API of thermostat.
 
 --------------------------------------------------------------------------------
-5. REFERENCES
+5. SYSTEM PROPERTIES
+
+Although Thermostat by default is configured to behave in the best possible
+way, there is a number of system properties that allows tweaking the behaviour
+of specific areas of the platform.
+
+Here follows the description for the release
+referred by this README. Please, refer to 
+[3.1.1. PASSING JVM SPECIFIC OPTIONS TO THERMOSTAT] for an explanation
+on how to pass system properties to Thermostat.
+
+IMPORTANT NOTE: Those properties should be considered internal and
+may not be used or available in all the releases. Likewise, defaults may
+change at any given time without notice.
+
+* Font Tweaks, Swing GUI only
+
+  skip.system.fonts=<boolean>
+
+By default, Thermostat tries to use the same fonts used by GTK on the
+currently running Desktop. When this property is set to false, the process
+is skipped.
+
+This property is only valid if the default look and feel is used, otherwise
+is ignored.
+
+* Windows Translucency, Swing GUI only
+
+  com.redhat.thermostat.popup.opaque=<boolean>
+
+By default, Thermostat tries to use translucency popup menus to add a
+subtle effect to its user interface. The user can request fully opaque
+windows to be used instead, by setting this property to false.
+
+Note that not all desktop environment support transparency, so this
+property may not have any effect.
+
+  com.redhat.thermostat.popup.transparency=<float>
+
+If transparent windows are used, this property influences the amount of
+transparency of the windows. The valid range is 0.0 for fully transparent
+and 1.0 for fully opaque, the default value is 0.90.
+
+* Mongo Storage Profiling, Mongo Storage only
+
+  thermostat.storage.mongo.profile=<boolean>
+
+Thermostat has some intstrumentation code to perform analysis of the
+backend databases. In the case of MongoDB, it is possible to run additional
+analysis by using Mongo profiling features. The default is to run MongoDB
+without profiling support, to turn profiling on this property should be set
+to true. This option has only effect when Thermostat is directly responsible
+to start the database backend, is ignored otherwise.
+
+  thermostat.storage.mongo.profile.slowms=<integer>
+
+This property has only effect in conjuction with
+"thermostat.storage.mongo.profile=true" and controls the threshold in
+milliseconds to decide if a database operation is considere a "slow". The
+default is 100.
+
+--------------------------------------------------------------------------------
+6. REFERENCES
 
   User Guide:
     http://icedtea.classpath.org/wiki/Thermostat/UserGuide
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/UIDefaults.java	Mon Sep 29 15:14:32 2014 -0400
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/UIDefaults.java	Mon Oct 06 11:16:38 2014 +0200
@@ -36,17 +36,22 @@
 
 package com.redhat.thermostat.client.swing;
 
+import com.redhat.thermostat.annotations.Service;
 import java.awt.Color;
+import java.awt.Font;
 import java.awt.Paint;
 
-import com.redhat.thermostat.annotations.Service;
-
 /**
  * Returns the default UI defaults used by this Thermostat client.
  */
 @Service
 public interface UIDefaults {
-    
+
+    /**
+     * Returns the default font used by Thermostat.
+     */
+    Font getDefaultFont();
+
     /**
      * Returns the foreground colour for components that are
      * selected, like text or entries in the reference field panel.
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/UIDefaultsImpl.java	Mon Sep 29 15:14:32 2014 -0400
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/vmlist/UIDefaultsImpl.java	Mon Oct 06 11:16:38 2014 +0200
@@ -38,6 +38,8 @@
 
 import java.awt.Color;
 
+import java.awt.Font;
+import javax.swing.JLabel;
 import javax.swing.UIManager;
 
 import com.redhat.thermostat.client.ui.Palette;
@@ -48,7 +50,13 @@
     public static UIDefaultsImpl getInstance() {
         return palette;
     }
-    
+
+    @Override
+    public Font getDefaultFont() {
+        Font font = (Font) UIManager.get("thermostat-default-font");
+        return font != null ? font : new JLabel().getFont();
+    }
+
     public Color getSelectedComponentFGColor() {
         Color color = (Color) UIManager.get("thermostat-selection-fg-color");
         return color != null ? color : Palette.LIGHT_GRAY.getColor();        
--- a/laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/ThemeManager.java	Mon Sep 29 15:14:32 2014 -0400
+++ b/laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/ThemeManager.java	Mon Oct 06 11:16:38 2014 +0200
@@ -138,7 +138,7 @@
         
         if (tryGTKColors) {
             GTKThemeUtils utils = new GTKThemeUtils();
-            utils.setNimbusColours();
+            utils.setNimbusColoursAndFont();
         }
         
         // TODO: document those or place them into a proper UI class
--- a/laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/gtk/GTKThemeUtils.java	Mon Sep 29 15:14:32 2014 -0400
+++ b/laf-utils/src/main/java/com/redhat/thermostat/internal/utils/laf/gtk/GTKThemeUtils.java	Mon Oct 06 11:16:38 2014 +0200
@@ -37,9 +37,11 @@
 package com.redhat.thermostat.internal.utils.laf.gtk;
 
 import java.awt.Color;
+import java.awt.Font;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 
+import javax.swing.JLabel;
 import javax.swing.UIManager;
 
 import com.redhat.thermostat.shared.config.NativeLibraryResolver;
@@ -62,6 +64,7 @@
     native private static boolean init();
     native private static boolean hasColor(String id);
     native private static int getColor(String id);
+    native private static String getDefaultFont();
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     public static Color getColor(String name, float hOffset, float sOffset,
@@ -109,7 +112,7 @@
         return result;
     }
     
-    public void setNimbusColours() {
+    public void setNimbusColoursAndFont() {
 
         if (!nativeLoaded) {
             return;
@@ -120,7 +123,77 @@
         }
         
         initialized = true;
-        
+
+        if (!Boolean.getBoolean("skip.system.fonts")) {
+            String defaultFontDesc = getDefaultFont();
+            if (!defaultFontDesc.isEmpty()) {
+                Font font = Font.decode(defaultFontDesc);
+
+                // Java2D uses 72dpi based size, Gnome sizes are configurable.
+                // Also, it's possible (but unlikely) that Java2D may change this
+                // default to accomodate high resolution displays, so rather than
+                // figuring out what's the real size given the possible
+                // resolution, let's ask this to Java2D directly. This may make
+                // our default fonts different than proper native application,
+                // but we don't care as long as it looks good. If not, use
+                // the property above
+                float size = new JLabel().getFont().getSize2D();
+                font = font.deriveFont(size);
+
+                // The following list applies to Nimbus and is given by the
+                // official documentation at this URL:
+                // http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html
+
+                UIManager.put("FileChooser.font", font);
+                UIManager.put("RootPane.font", font);
+                UIManager.put("TextPane.font", font);
+                UIManager.put("FormattedTextField.font", font);
+                UIManager.put("Spinner.font", font);
+                UIManager.put("PopupMenuSeparator.font", font);
+                UIManager.put("Table.font", font);
+                UIManager.put("TextArea.font", font);
+                UIManager.put("Slider.font", font);
+                UIManager.put("InternalFrameTitlePane.font", font);
+                UIManager.put("DesktopPane.font", font);
+                UIManager.put("Menu.font", font);
+                UIManager.put("PasswordField.font", font);
+                UIManager.put("InternalFrame.font", font);
+                UIManager.put("Button.font", font);
+                UIManager.put("Panel.font", font);
+                UIManager.put("MenuBar.font", font);
+                UIManager.put("ComboBox.font", font);
+                UIManager.put("Tree.font", font);
+                UIManager.put("EditorPane.font", font);
+                UIManager.put("ToggleButton.font", font);
+                UIManager.put("TabbedPane.font", font);
+                UIManager.put("TableHeader.font", font);
+                UIManager.put("List.font", font);
+                UIManager.put("PopupMenu.font", font);
+                UIManager.put("ToolTip.font", font);
+                UIManager.put("Separator.font", font);
+                UIManager.put("RadioButtonMenuItem.font", font);
+                UIManager.put("RadioButton.font", font);
+                UIManager.put("ToolBar.font", font);
+                UIManager.put("ScrollPane.font", font);
+                UIManager.put("CheckBoxMenuItem.font", font);
+                UIManager.put("Viewport.font", font);
+                UIManager.put("TextField.font", font);
+                UIManager.put("SplitPane.font", font);
+                UIManager.put("MenuItem.font", font);
+                UIManager.put("OptionPane.font", font);
+                UIManager.put("ArrowButton.font", font);
+                UIManager.put("Label.font", font);
+                UIManager.put("ProgressBar.font", font);
+                UIManager.put("ScrollBar.font", font);
+                UIManager.put("ScrollBarThumb.font", font);
+                UIManager.put("ScrollBarTrack.font", font);
+                UIManager.put("SliderThumb.font", font);
+                UIManager.put("SliderTrack.font", font);
+                UIManager.put("TitledBorder.font", font);
+
+                UIManager.put("thermostat-default-font", font);
+            }
+        }
         // 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")) {
@@ -147,9 +220,8 @@
             float brightnessOffset = -.300f;
             
             Color nimbusBase = deriveColor("bg_color", UIManager.getDefaults().getColor("nimbusBase"), brightnessOffset);
-            Color control = UIManager.getDefaults().getColor("control");
             int bgColor = getColor("bg_color");
-            control = new Color(bgColor);
+            Color control = new Color(bgColor);
             
             Color info = control;
             
@@ -158,10 +230,9 @@
             UIManager.put("control", control);
             UIManager.put("info", info);
             
-            Color nimbusFocus = UIManager.getDefaults().getColor("nimbusFocus");
             if (hasColor("selected_bg_color")) {
                 int fgColor = getColor("selected_bg_color");
-                nimbusFocus = new Color(fgColor);
+                Color nimbusFocus = new Color(fgColor);
                 
                 UIManager.put("nimbusFocus", nimbusFocus);
                 UIManager.put("nimbusSelectionBackground", nimbusFocus);
--- a/laf-utils/src/main/native/GTKThemeUtils.c	Mon Sep 29 15:14:32 2014 -0400
+++ b/laf-utils/src/main/native/GTKThemeUtils.c	Mon Oct 06 11:16:38 2014 +0200
@@ -142,3 +142,36 @@
     return pixel;
 }
 
+JNIEXPORT jstring JNICALL
+Java_com_redhat_thermostat_internal_utils_laf_gtk_GTKThemeUtils_getDefaultFont
+    (JNIEnv *env, jclass GTKThemeUtils)
+{
+    jstring result = NULL;
+    char* fontName = NULL;
+    GtkWidget *dummy = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    if (dummy == NULL) {
+        goto bailString;
+    }
+
+    gtk_widget_ensure_style(dummy);
+
+    GtkStyle *style = gtk_rc_get_style(dummy);
+    if (style != NULL) {
+        PangoFontDescription *desc = style->font_desc;
+	fontName = pango_font_description_to_string(desc);
+
+        // fprintf(stderr, "default font: %s\n", fontName);
+    }
+
+    gtk_widget_destroy(dummy);
+
+bailString:
+    if (fontName == NULL) {
+        result = (*env)->NewStringUTF(env, "");
+    } else {
+        result = (*env)->NewStringUTF(env, fontName);
+        g_free(fontName);
+    }
+
+    return result;
+}