You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2020/02/04 20:46:50 UTC

[GitHub] [netbeans] pedro-w commented on a change in pull request #1918: [NETBEANS-3785] Implement simplified HeapView widget

pedro-w commented on a change in pull request #1918: [NETBEANS-3785] Implement simplified HeapView widget
URL: https://github.com/apache/netbeans/pull/1918#discussion_r374913322
 
 

 ##########
 File path: platform/openide.actions/src/org/openide/actions/HeapView.java
 ##########
 @@ -465,526 +225,174 @@ private void updateTextWidth() {
      *
      * @param e the MouseEvent
      */
-    @Override protected void processMouseEvent(MouseEvent e) {
+    @Override
+    protected void processMouseEvent(MouseEvent e) {
         super.processMouseEvent(e);
         if (!e.isConsumed()) {
             if (e.isPopupTrigger()) {
                 // Show a popup allowing to configure the various options
                 showPopup(e.getX(), e.getY());
-            }  else if (e.getID() == MouseEvent.MOUSE_ENTERED) {
-                containsMouse = true;
-                cachedBorderVaild = false;
-                repaint();
-            } else if (e.getID() == MouseEvent.MOUSE_EXITED) {
-                containsMouse = false;
-                cachedBorderVaild = false;
-                repaint();
             }
+        }
 
-        } 
-        
-        if (e.getID() == MouseEvent.MOUSE_CLICKED &&
-                SwingUtilities.isLeftMouseButton(e) && 
-                e.getClickCount() == 1) {
+        if (e.getID() == MouseEvent.MOUSE_CLICKED
+                && SwingUtilities.isLeftMouseButton(e)
+                && e.getClickCount() == 1) {
             // Trigger a gc
-            GarbageCollectAction.get(GarbageCollectAction.class).performAction();;
+            GarbageCollectAction.get(GarbageCollectAction.class).performAction();
         }
     }
 
     /**
-     * Shows a popup at the specified location that allows you to configure
-     * the various options.
+     * Shows a popup at the specified location that allows you to configure the
+     * various options.
      */
     private void showPopup(int x, int y) {
         JPopupMenu popup = new JPopupMenu();
         JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(NbBundle.getMessage(HeapView.class, "LBL_ShowText"));
         cbmi.setSelected(getShowText());
         cbmi.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-                setShowText(((JCheckBoxMenuItem)e.getSource()).
+                setShowText(((JCheckBoxMenuItem) e.getSource()).
                         isSelected());
             }
         });
         popup.add(cbmi);
-        cbmi = new JCheckBoxMenuItem(NbBundle.getMessage(HeapView.class, "LBL_DropShadow"));
-        cbmi.setSelected(getShowDropShadow());
-        cbmi.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                setShowDropShadow(((JCheckBoxMenuItem)e.getSource()).
-                        isSelected());
-            }
-        });
-        popup.add(cbmi);
-        cbmi = new JCheckBoxMenuItem(NbBundle.getMessage(HeapView.class, "LBL_OverlayGrid"));
-        cbmi.setSelected(getTickStyle() == STYLE_OVERLAY);
-        cbmi.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                int style = ((JCheckBoxMenuItem)e.getSource()).
-                        isSelected() ? STYLE_OVERLAY : STYLE_DEFAULT;
-                setTickStyle(style);
-            }
-        });
-        popup.add(cbmi);
         popup.show(this, x, y);
     }
 
-    /**
-     * Returns the first index to start rendering from.
-     */
-    private int getGraphStartIndex() {
-        if (graphFilled) {
-            return graphIndex;
-        } else {
-            return 0;
-        }
-    }
-
     /**
      * Paints the component.
      */
-    @Override protected void paintComponent(Graphics g) {
-        Graphics2D g2 = (Graphics2D)g;
+    @Override
+    protected void paintComponent(Graphics g) {
+        super.paintComponent(g);
         int width = getWidth();
         int height = getHeight();
-        if (width - BORDER_W > 0 && height - BORDER_H > 0) {
+
+        if (width > 0 && height > 0) {
             startTimerIfNecessary();
-            updateCacheIfNecessary(width, height);
-            paintCachedBackground(g2, width, height);
-            g.translate(1, 2);
-            if (containsMouse) {
-                g.clipRect(1, 0, width - 4, height - 4);
-            }
-            else {
-                g.clipRect(0, 0, width - 2, height - 4);
-            }
-            int innerW = width - BORDER_W;
-            int innerH = height - BORDER_H;
-            if (heapGrowTimer != null) {
-                // Render the heap growing animation.
-                Composite lastComposite = ((Graphics2D)g).getComposite();
-                float percent = 1f - heapGrowTimer.getPercent();
-                ((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, percent));
-                g.drawImage(heapGrowTimer.image, 0, 0, null);
-                ((Graphics2D)g).setComposite(lastComposite);
-            }
-            paintTicks(g2, innerW, innerH);
-            if (getTickStyle() == STYLE_OVERLAY) {
-                g2.drawImage(getGridOverlayImage(), 0, 0, null);
-            }
+            Graphics2D g2 = (Graphics2D) g;
+            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+            // Fill background
+            g2.setPaint(BACKGROUND_COLOR);
+            g2.fillRect(0, 0, width + 1, height + 1);
+            // Draw samples
+            g2.setPaint(CHART_COLOR);
+            paintSamples(g2, width, height);
+            // Draw text if enabled
             if (getShowText()) {
-                if (getShowDropShadow()) {
-                    paintDropShadowText(g, innerW, innerH);
-                } else {
-                    g.setColor(textColor);
-                    paintText(g, innerW, innerH);
-                }
+                paintText(g2, width, height);
             }
-            g.translate(-1, -2);
         } else {
             stopTimerIfNecessary();
-            // To honor opaque contract, fill in the background
-            g.setColor(getBackground());
-            g.fillRect(0, 0, width, height);
-        }
-    }
-    
-    private void paintTicks(Graphics2D g, int width, int height) {
-        if (graphIndex > 0 || graphFilled) {
-            int index = getGraphStartIndex();
-            int x = 0;
-            if (!graphFilled) {
-                x = width - graphIndex;
-            }
-            float[] localGraph = graph;
-            if (localGraph == null) {
-                return;
-            }
-            float min = localGraph[index];
-            index = (index + 1) % localGraph.length;
-            while (index != graphIndex) {
-                min = Math.min(min, localGraph[index]);
-                index = (index + 1) % localGraph.length;
-            }
-            int minHeight = (int)(min * (float)height);
-            if (minHeight > 0) {
-               g.drawImage(tickGradientImage, x, height - minHeight, width, height,
-                        x, height - minHeight, width, height, null);
-            }
-            index = getGraphStartIndex();
-            do {
-                int tickHeight = (int)(localGraph[index] * (float)height);
-                if (tickHeight > minHeight) {
-                    g.drawImage(tickGradientImage, x, height - tickHeight, x + 1, height - minHeight,
-                            x, height - tickHeight, x + 1, height - minHeight, null);
-                }
-                index = (index + 1) % localGraph.length;
-                x++;
-            } while (index != graphIndex);
         }
     }
 
     /**
-     * Renders the text.
+     * Renders the text using an optional drop shadow.
      */
-    private void paintText(Graphics g, int w, int h) {
+    private void paintText(Graphics2D g, int w, int h) {
         g.setFont(getFont());
         String text = getHeapSizeText();
         FontMetrics fm = g.getFontMetrics();
         int textWidth = fm.stringWidth(text);
-        g.drawString(text, (w - maxTextWidth) / 2 + (maxTextWidth - textWidth), 
-                h / 2 + fm.getAscent() / 2 - 2);
+        int x = (w - maxTextWidth) / 2 + (maxTextWidth - textWidth);
+        int y = h / 2 + fm.getAscent() / 2 - 2;
+        g.setColor(TEXT_COLOR);
+        g.drawString(text, x, y);
 
 Review comment:
   It _was_ me.. I had that and took it out because it didn't seem to add much to the clarity in the original scheme. Here it is with/without drop shadow, using your theme colours of 0x2e90e8/0xCEDBE6
   ![Screenshot 2020-02-04 at 20 42 55](https://user-images.githubusercontent.com/22172519/73785462-38610800-478f-11ea-8755-3ec6ed1066ba.png)
   ![Screenshot 2020-02-04 at 20 41 51](https://user-images.githubusercontent.com/22172519/73785463-38610800-478f-11ea-8bb5-487dd966b3e1.png)
   I think there is insufficient contrast between white text and the pale blue, even with the drop shadow. May be better to go black text, what do you think?
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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

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