You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by eb...@apache.org on 2019/06/07 02:46:02 UTC

[netbeans] 02/10: Use Icon.paintIcon instead of Graphics.drawImage (one example).

This is an automated email from the ASF dual-hosted git repository.

ebakke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git

commit d7d467c342a7ab4d0759f67c276d4d75ef8fb275
Author: Eirik Bakke <eb...@ultorg.com>
AuthorDate: Wed May 29 15:36:42 2019 -0400

    Use Icon.paintIcon instead of Graphics.drawImage (one example).
    
    Most of the icons that are seen in the IDE during a standard Java editing
    session are already painted via a call to Icon.paintIcon. One exception is the
    separator icon that is used in the breadcrumb component under the code editor,
    which is painted via Graphics.drawImage. Migrate this one to Icon.paintIcon to
    make the icon look better on HiDPI displays (taking advantage of the HiDPI
    scaling hints that were recently implemented in ImageUtilities).
    
    This also serves as an example of how to fix other similar cases in the future.
---
 .../modules/editor/breadcrumbs/BreadCrumbComponent.java   | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/ide/editor.breadcrumbs/src/org/netbeans/modules/editor/breadcrumbs/BreadCrumbComponent.java b/ide/editor.breadcrumbs/src/org/netbeans/modules/editor/breadcrumbs/BreadCrumbComponent.java
index 3a5ad9d..3d60c65 100644
--- a/ide/editor.breadcrumbs/src/org/netbeans/modules/editor/breadcrumbs/BreadCrumbComponent.java
+++ b/ide/editor.breadcrumbs/src/org/netbeans/modules/editor/breadcrumbs/BreadCrumbComponent.java
@@ -64,7 +64,8 @@ import org.openide.util.WeakListeners;
  */
 public class BreadCrumbComponent<T extends JLabel&Renderer> extends JComponent implements PropertyChangeListener {
 
-    private final Image SEPARATOR = ImageUtilities.loadImage("org/netbeans/modules/editor/breadcrumbs/resources/separator.png");
+    private final Icon SEPARATOR =
+        ImageUtilities.image2Icon(ImageUtilities.loadImage("org/netbeans/modules/editor/breadcrumbs/resources/separator.png"));
     
     public BreadCrumbComponent() {
         setPreferredSize(new Dimension(0, COMPONENT_HEIGHT));
@@ -119,7 +120,7 @@ public class BreadCrumbComponent<T extends JLabel&Renderer> extends JComponent i
         int height = getHeight();
         
         if (nodes.length == 0) {
-            g.drawImage(SEPARATOR, START_INSET, (height - SEPARATOR.getHeight(null)) / 2, null);
+            SEPARATOR.paintIcon(this, g, START_INSET, (height - SEPARATOR.getIconHeight()) / 2);
             return ;
         }
         
@@ -135,10 +136,10 @@ public class BreadCrumbComponent<T extends JLabel&Renderer> extends JComponent i
             g.translate(-x, -labelY);
 
             x += sizes[i];
-            
-            g.drawImage(SEPARATOR, x + LEFT_SEPARATOR_INSET, (height - SEPARATOR.getHeight(null)) / 2, null);
 
-            x += LEFT_SEPARATOR_INSET + SEPARATOR.getWidth(null) + RIGHT_SEPARATOR_INSET;
+            SEPARATOR.paintIcon(this, g, x + LEFT_SEPARATOR_INSET, (height - SEPARATOR.getIconHeight()) / 2);
+
+            x += LEFT_SEPARATOR_INSET + SEPARATOR.getIconWidth() + RIGHT_SEPARATOR_INSET;
         }
     }
 
@@ -169,7 +170,7 @@ public class BreadCrumbComponent<T extends JLabel&Renderer> extends JComponent i
             i++;
         }
 
-        setPreferredSize(new Dimension((int) (xTotal + (nodes.length - 1) * (LEFT_SEPARATOR_INSET + SEPARATOR.getWidth(null) + RIGHT_SEPARATOR_INSET) + START_INSET), USABLE_HEIGHT/*(int) (height + 2 * INSET_HEIGHT)*/));
+        setPreferredSize(new Dimension((int) (xTotal + (nodes.length - 1) * (LEFT_SEPARATOR_INSET + SEPARATOR.getIconWidth() + RIGHT_SEPARATOR_INSET) + START_INSET), USABLE_HEIGHT/*(int) (height + 2 * INSET_HEIGHT)*/));
     }
     
     @Override
@@ -206,7 +207,7 @@ public class BreadCrumbComponent<T extends JLabel&Renderer> extends JComponent i
             }
             
             startX = elemX;
-            elemX += SEPARATOR.getWidth(null);
+            elemX += SEPARATOR.getIconWidth();
             
             if (clickX <= elemX) {
                 //found:


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists