Patch for a couple of issues

Request new features and improvements you want to see in WebLaF.
I will answer any request so don't hesitate and post it!

Patch for a couple of issues

Postby robert » Thu Apr 04, 2013 6:07 am

I'm attaching a patch for a couple of issues I found with the current SVN build. If there's some kind of weird issue applying the patch from an Eclipse project into an Idea one, let me know. I just created the patch from the top-level WebLookAndFeel project.

1. MenuItemLayoutHelper doesn't check text for length > 0 in two places before passing it to SwingUtilities2.getLeftSideBearing(). That method expects a string of length > 0. In most places you defensively check for this, but in two places you don't. That beaks some panels in the demo application for me.

2. I added two system properties to WebLookAndFeel, and a method to SwingUtils that checks them. The idea is that the user can specify whether WebLaF should honor user borders (i.e. Borders not implementing UIResource) either globally or per-component. The user can set the system property WebLookAndFeel.PROPERTY_HONOR_USER_BORDERS to "true" to have all user-defined borders in the application honored, or set a client property named WebLookAndFeel.PROPERTY_HONOR_USER_BORDER on any single component to have it honor user borders on just that one component. In order for this to work, each UI delegate class would have to check for this in e.g. its updateBorder() method, and not install the WebLookAndFeel border if SwingUtils.getHonorUserBorders(JComponent) returns true. The patch only has this check done in WebPanelUI, since it's the most useful there (in my opinion) - since EmptyBorders are so useful to space things out in dialogs, etc.

#2 will probably take more consideration than #1 of course, but I think it's a worthy addition. Most consumers of the library can use its own concepts of borders and margins, but those of us who want to use it for aesthetics but keep user borders (at least in some instances) can still do so.

Code: Select all
Index: src/com/alee/laf/WebLookAndFeel.java
===================================================================
--- src/com/alee/laf/WebLookAndFeel.java   (revision 57)
+++ src/com/alee/laf/WebLookAndFeel.java   (working copy)
@@ -84,6 +84,21 @@
 
 public class WebLookAndFeel extends BasicLookAndFeel
 {
+   
+   /**
+    * If this client property is set to {@link Boolean#TRUE} on a component,
+    * UI delegates should follow the typical Swing behavior of not overriding
+    * a user-defined border on it.
+    */
+   public static final String PROPERTY_HONOR_USER_BORDER = "WebLookAndFeel.honorUserBorder";
+   
+   /**
+    * If this system property is set to <code>true</code>,  UI delegates should
+    * follow the typical Swing behavior of not overriding a user-defined border
+    * if one is installed on components.
+    */
+   public static final String PROPERTY_HONOR_USER_BORDERS = "WebLookAndFeel.honorUserBorders";
+
     /**
      * Some known UI constants.
      */
Index: src/com/alee/laf/menu/MenuItemLayoutHelper.java
===================================================================
--- src/com/alee/laf/menu/MenuItemLayoutHelper.java   (revision 57)
+++ src/com/alee/laf/menu/MenuItemLayoutHelper.java   (working copy)
@@ -787,7 +787,7 @@
      */
     private void fixTextRects ( LayoutResult lr )
     {
-        if ( htmlView == null )
+        if ( htmlView == null && text.length()>0)
         { // The text isn't a HTML
             int lsb = SwingUtilities2.getLeftSideBearing ( mi, fm, text );
             if ( lsb < 0 )
@@ -803,11 +803,14 @@
      */
     private void fixAccTextRect ( LayoutResult lr )
     {
-        int lsb = SwingUtilities2.getLeftSideBearing ( mi, accFm, accText );
-        if ( lsb < 0 )
-        {
-            lr.accRect.x -= lsb;
-        }
+       if (accText.length()>0)
+       {
+           int lsb = SwingUtilities2.getLeftSideBearing ( mi, accFm, accText );
+           if ( lsb < 0 )
+           {
+               lr.accRect.x -= lsb;
+           }
+       }
     }
 
     /**
Index: src/com/alee/laf/panel/WebPanelUI.java
===================================================================
--- src/com/alee/laf/panel/WebPanelUI.java   (revision 57)
+++ src/com/alee/laf/panel/WebPanelUI.java   (working copy)
@@ -27,6 +27,8 @@
 import com.alee.utils.laf.ShapeProvider;
 
 import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.plaf.BorderUIResource;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicPanelUI;
 import java.awt.*;
@@ -144,6 +146,15 @@
 
     private void updateBorder ()
     {
+       if (SwingUtils.getHonorUserBorders(panel))
+       {
+          Border oldBorder = panel.getBorder();
+          if (!(oldBorder instanceof BorderUIResource))
+          {
+             return;
+          }
+       }
+       
         if ( panel != null )
         {
             // Actual margin
Index: src/com/alee/utils/SwingUtils.java
===================================================================
--- src/com/alee/utils/SwingUtils.java   (revision 57)
+++ src/com/alee/utils/SwingUtils.java   (working copy)
@@ -23,6 +23,7 @@
 import com.alee.extended.filechooser.WebPathField;
 import com.alee.extended.panel.WebCollapsiblePane;
 import com.alee.laf.StyleConstants;
+import com.alee.laf.WebLookAndFeel;
 import com.alee.managers.hotkey.HotkeyData;
 import com.alee.managers.hotkey.HotkeyRunnable;
 import com.alee.managers.language.LanguageManager;
@@ -1449,6 +1450,21 @@
     }
 
     /**
+     * Returns whether UI delegates should honor a user-specified border on
+     * this component.
+     */
+    public static boolean getHonorUserBorders(JComponent component)
+    {
+       if (Boolean.getBoolean(WebLookAndFeel.PROPERTY_HONOR_USER_BORDERS))
+       {
+          return true;
+       }
+       Object prop = component.getClientProperty(WebLookAndFeel.
+                               PROPERTY_HONOR_USER_BORDER);
+       return Boolean.TRUE.equals(prop);
+    }
+   
+    /**
      * Returns hotkey data extracted from the specified key stroke.
      *
      * @param keyStroke key stroke to process
robert
 
Posts: 4
Joined: Fri Mar 15, 2013 3:07 am

Re: Patch for a couple of issues

Postby mgarin » Fri Apr 05, 2013 6:55 pm

I understood the idea of the patch, it is indeed a good way to allow user to control borders.
I will this patch into the next update (not commit), maybe a bit modified but it will be there.

Thanks for the assistance!
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg


Return to Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron