mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.13k stars 234 forks source link

Increase the usage of compound assignment operators #688

Open elfring opened 2 years ago

elfring commented 2 years ago

:eyes: Some source code analysis tools can help to find opportunities for improving software components. :thought_balloon: I propose to increase the usage of compound operators accordingly.

diff --git a/modules/core/src/com/alee/graphics/filters/ContrastFilter.java b/modules/core/src/com/alee/graphics/filters/ContrastFilter.java
index e47a93c9..adf637e0 100644
--- a/modules/core/src/com/alee/graphics/filters/ContrastFilter.java
+++ b/modules/core/src/com/alee/graphics/filters/ContrastFilter.java
@@ -50,7 +50,7 @@ public class ContrastFilter extends TransferFilter
     @Override
     protected float transferFunction ( float f )
     {
-        f = f * brightness;
+        f *= brightness;
         f = ( f - 0.5f ) * contrast + 0.5f;
         return f;
     }
diff --git a/modules/core/src/com/alee/utils/GraphicsUtils.java b/modules/core/src/com/alee/utils/GraphicsUtils.java
index c94bbbb4..28a3a0fc 100644
--- a/modules/core/src/com/alee/utils/GraphicsUtils.java
+++ b/modules/core/src/com/alee/utils/GraphicsUtils.java
@@ -438,7 +438,7 @@ public final class GraphicsUtils
         else
         {
             // Drawing complex gradient shade
-            width = width * 2;
+            width *= 2;
             for ( int i = width; i >= 2; i -= 2 )
             {
                 // float minTransparency = 0.2f;
diff --git a/modules/ninepatch-editor/src/com/alee/extended/ninepatch/NinePatchEditor.java b/modules/ninepatch-editor/src/com/alee/extended/ninepatch/NinePatchEditor.java
index 959830d0..ce5bc71a 100644
--- a/modules/ninepatch-editor/src/com/alee/extended/ninepatch/NinePatchEditor.java
+++ b/modules/ninepatch-editor/src/com/alee/extended/ninepatch/NinePatchEditor.java
@@ -341,7 +341,7 @@ public class NinePatchEditor extends WebPanel
     {
         if ( !isSomeDragged () && historyState > 0 )
         {
-            historyState = historyState - 1;
+            historyState -= 1;
             restoreHistoryState ( history.get ( historyState ) );
         }
     }
@@ -350,7 +350,7 @@ public class NinePatchEditor extends WebPanel
     {
         if ( !isSomeDragged () && historyState < history.size () - 1 )
         {
-            historyState = historyState + 1;
+            historyState += 1;
             restoreHistoryState ( history.get ( historyState ) );
         }
     }
diff --git a/modules/ninepatch-editor/src/com/alee/extended/ninepatch/NinePatchEditorPanel.java b/modules/ninepatch-editor/src/com/alee/extended/ninepatch/NinePatchEditorPanel.java
index ae07f710..cc84e0f4 100644
--- a/modules/ninepatch-editor/src/com/alee/extended/ninepatch/NinePatchEditorPanel.java
+++ b/modules/ninepatch-editor/src/com/alee/extended/ninepatch/NinePatchEditorPanel.java
@@ -948,7 +948,7 @@ public class NinePatchEditorPanel extends WebPanel
         }
         else if ( fullName.endsWith ( subFormat ) )
         {
-            fullName = fullName + format;
+            fullName += format;
         }
         else
         {
@@ -957,7 +957,7 @@ public class NinePatchEditorPanel extends WebPanel
             {
                 fullName = fullName.substring ( 0, dot );
             }
-            fullName = fullName + subFormat + format;
+            fullName += subFormat + format;
         }
         return fullName;
     }
diff --git a/modules/ui/src/com/alee/extended/button/WebSwitch.java b/modules/ui/src/com/alee/extended/button/WebSwitch.java
index f1c8b9bc..7b05216d 100644
--- a/modules/ui/src/com/alee/extended/button/WebSwitch.java
+++ b/modules/ui/src/com/alee/extended/button/WebSwitch.java
@@ -162,7 +162,7 @@ public class WebSwitch extends WebPanel implements ItemSelectable
             public void actionPerformed ( final ActionEvent e )
             {
                 // Updating gripper location
-                gripperLocation = gripperLocation + ( selected ? 0.1f : -0.1f );
+                gripperLocation += ( selected ? 0.1f : -0.1f );

                 // Checking what to do
                 if ( selected && gripperLocation >= 1f || !selected && gripperLocation <= 0f )
diff --git a/modules/ui/src/com/alee/extended/checkbox/TristateCheckBoxModel.java b/modules/ui/src/com/alee/extended/checkbox/TristateCheckBoxModel.java
index 567fa454..27fc1c47 100644
--- a/modules/ui/src/com/alee/extended/checkbox/TristateCheckBoxModel.java
+++ b/modules/ui/src/com/alee/extended/checkbox/TristateCheckBoxModel.java
@@ -160,7 +160,7 @@ public class TristateCheckBoxModel extends JToggleButton.ToggleButtonModel
         final boolean mixed = isMixed ();
         if ( mixed )
         {
-            stateMask = stateMask & ~MIXED;
+            stateMask &= ~MIXED;
             stateMask = selected ? stateMask & ~SELECTED : stateMask | SELECTED;
         }
         super.setSelected ( selected );
diff --git a/modules/ui/src/com/alee/extended/dock/WebDockablePaneModel.java b/modules/ui/src/com/alee/extended/dock/WebDockablePaneModel.java
index bb32e66a..31c57616 100644
--- a/modules/ui/src/com/alee/extended/dock/WebDockablePaneModel.java
+++ b/modules/ui/src/com/alee/extended/dock/WebDockablePaneModel.java
@@ -486,7 +486,7 @@ public class WebDockablePaneModel extends AbstractGroupingLayout implements Dock
                     break;

                 case east:
-                    bounds.x = bounds.x + bounds.width - xSide;
+                    bounds.x += bounds.width - xSide;
                     bounds.width = xSide;
                     break;

@@ -495,7 +495,7 @@ public class WebDockablePaneModel extends AbstractGroupingLayout implements Dock
                     break;

                 case south:
-                    bounds.y = bounds.y + bounds.height - ySide;
+                    bounds.y += bounds.height - ySide;
                     bounds.height = ySide;
                     break;
             }
diff --git a/modules/ui/src/com/alee/extended/panel/ResizablePanel.java b/modules/ui/src/com/alee/extended/panel/ResizablePanel.java
index 52dbd668..3342e3d8 100644
--- a/modules/ui/src/com/alee/extended/panel/ResizablePanel.java
+++ b/modules/ui/src/com/alee/extended/panel/ResizablePanel.java
@@ -206,8 +206,8 @@ public class ResizablePanel extends WebPanel
     {
         // todo This is wrong due to SizeMethods implementation below
         final Dimension ps = super.getPreferredSize ();
-        ps.width = ps.width + widthChange;
-        ps.height = ps.height + heightChange;
+        ps.width += widthChange;
+        ps.height += heightChange;
         return ps;
     }

diff --git a/modules/ui/src/com/alee/extended/split/MultiSplitLayoutHelper.java b/modules/ui/src/com/alee/extended/split/MultiSplitLayoutHelper.java
index 7279efd2..2c580839 100644
--- a/modules/ui/src/com/alee/extended/split/MultiSplitLayoutHelper.java
+++ b/modules/ui/src/com/alee/extended/split/MultiSplitLayoutHelper.java
@@ -210,7 +210,7 @@ public class MultiSplitLayoutHelper

             // Variables for normalizing percentage and fill views
             this.fillViewSize = totalPercentViews > 0.0 ? totalPercentViews : 1.0;
-            this.totalPercentViews = totalPercentViews + fillViewSize * fillViewsCount;
+            this.totalPercentViews += fillViewSize * fillViewsCount;

             // Space available for percentage views
             spaceForPercentViews = Math.max ( 0, space - totalPixelViews );
diff --git a/modules/ui/src/com/alee/extended/transition/effects/blocks/BlocksTransitionEffect.java b/modules/ui/src/com/alee/extended/transition/effects/blocks/BlocksTransitionEffect.java
index 89671075..61549344 100644
--- a/modules/ui/src/com/alee/extended/transition/effects/blocks/BlocksTransitionEffect.java
+++ b/modules/ui/src/com/alee/extended/transition/effects/blocks/BlocksTransitionEffect.java
@@ -123,9 +123,9 @@ public class BlocksTransitionEffect extends DefaultTransitionEffect

         // Updating runtime values
         int h = imageTransition.getHeight ();
-        h = h % size == 0 ? h : ( h / size ) * size + size;
+        h %= size == 0 ? h : ( h / size ) * size + size;
         int w = imageTransition.getWidth ();
-        w = w % size == 0 ? w : ( w / size ) * size + size;
+        w %= size == 0 ? w : ( w / size ) * size + size;
         final int cols = w / size;
         final int rows = h / size;
         progress = new int[ cols ][ rows ];
diff --git a/modules/ui/src/com/alee/laf/colorchooser/PaletteColorChooserPaint.java b/modules/ui/src/com/alee/laf/colorchooser/PaletteColorChooserPaint.java
index ce7b2387..602e3a96 100644
--- a/modules/ui/src/com/alee/laf/colorchooser/PaletteColorChooserPaint.java
+++ b/modules/ui/src/com/alee/laf/colorchooser/PaletteColorChooserPaint.java
@@ -133,21 +133,21 @@ public class PaletteColorChooserPaint implements Paint
     private int getRed ( final int xCoord, final int yCoord )
     {
         int red = 255 - ( 255 - cornerColor.getRed () ) * ( xCoord - x ) / width;
-        red = red - ( red ) * ( yCoord - y ) / height;
+        red -= red * ( yCoord - y ) / height;
         return getWebSafe ( red );
     }

     private int getGreen ( final int xCoord, final int yCoord )
     {
         int green = 255 - ( 255 - cornerColor.getGreen () ) * ( xCoord - x ) / width;
-        green = green - ( green ) * ( yCoord - y ) / height;
+        green -= green * ( yCoord - y ) / height;
         return getWebSafe ( green );
     }

     private int getBlue ( final int xCoord, final int yCoord )
     {
         int blue = 255 - ( 255 - cornerColor.getBlue () ) * ( xCoord - x ) / width;
-        blue = blue - ( blue ) * ( yCoord - y ) / height;
+        blue -= blue * ( yCoord - y ) / height;
         return getWebSafe ( blue );
     }

diff --git a/modules/ui/src/com/alee/laf/filechooser/WebFileChooserPanel.java b/modules/ui/src/com/alee/laf/filechooser/WebFileChooserPanel.java
index 79a2c0d7..ea2ff2ec 100644
--- a/modules/ui/src/com/alee/laf/filechooser/WebFileChooserPanel.java
+++ b/modules/ui/src/com/alee/laf/filechooser/WebFileChooserPanel.java
@@ -1789,7 +1789,7 @@ public class WebFileChooserPanel extends WebPanel
                 final JScrollBar vsb = getVerticalScrollBar ();
                 if ( vsb != null && vsb.isShowing () )
                 {
-                    ps.width = ps.width + vsb.getPreferredSize ().width;
+                    ps.width += vsb.getPreferredSize().width;
                 }

                 ps.height = Math.min ( ps.height, 100 );
diff --git a/modules/ui/src/com/alee/laf/table/TablePainter.java b/modules/ui/src/com/alee/laf/table/TablePainter.java
index 79de1cbf..95da8178 100644
--- a/modules/ui/src/com/alee/laf/table/TablePainter.java
+++ b/modules/ui/src/com/alee/laf/table/TablePainter.java
@@ -925,12 +925,12 @@ public class TablePainter<C extends JTable, U extends WTableUI, D extends IDecor
                 rect = component.getCellRect ( location.getRow (), col, true );
                 if ( ltr )
                 {
-                    rect.x = rect.x + rect.width;
+                    rect.x += rect.width;
                 }
             }
             else if ( !ltr )
             {
-                rect.x = rect.x + rect.width;
+                rect.x += rect.width;
             }

             if ( rect.x == 0 )
diff --git a/modules/ui/src/com/alee/laf/tree/TreeDropLocationPainter.java b/modules/ui/src/com/alee/laf/tree/TreeDropLocationPainter.java
index 74d6d95f..2d2e56d2 100644
--- a/modules/ui/src/com/alee/laf/tree/TreeDropLocationPainter.java
+++ b/modules/ui/src/com/alee/laf/tree/TreeDropLocationPainter.java
@@ -152,7 +152,7 @@ public class TreeDropLocationPainter<C extends JTree, U extends WTreeUI, D exten
             final Dimension ps = getPreferredSize ();
             if ( !ltr )
             {
-                bounds.x = bounds.x + bounds.width - ps.width;
+                bounds.x += bounds.width - ps.width;
             }

             // Adjusting to start or end of the node bounds
diff --git a/modules/ui/src/com/alee/laf/tree/TreePainter.java b/modules/ui/src/com/alee/laf/tree/TreePainter.java
index 27ee6845..2f9c6a6b 100644
--- a/modules/ui/src/com/alee/laf/tree/TreePainter.java
+++ b/modules/ui/src/com/alee/laf/tree/TreePainter.java
@@ -1344,7 +1344,7 @@ public class TreePainter<C extends JTree, U extends WTreeUI, D extends IDecorati
                 int lineX = getRowX ( -1, depth + 1 );
                 if ( ltr )
                 {
-                    lineX = lineX - ui.getRightChildIndent () + insets.left;
+                    lineX -= ui.getRightChildIndent() - insets.left;
                 }
                 else
                 {
diff --git a/modules/ui/src/com/alee/laf/tree/WebTree.java b/modules/ui/src/com/alee/laf/tree/WebTree.java
index 43b53119..b6078212 100644
--- a/modules/ui/src/com/alee/laf/tree/WebTree.java
+++ b/modules/ui/src/com/alee/laf/tree/WebTree.java
@@ -1417,12 +1417,12 @@ public class WebTree<N extends MutableTreeNode> extends JTree implements Styleab
             {
                 // Leave additional 1/2 of visible height on top of the node
                 // Otherwise it is hard to look where this node is located
-                bounds.y = bounds.y + bounds.height / 2 - vr.height / 2;
+                bounds.y += bounds.height / 2 - vr.height / 2;

                 // Put node into the middle of visible area
                 if ( vr.width > bounds.width )
                 {
-                    bounds.x = bounds.x + bounds.width / 2 - vr.width / 2;
+                    bounds.x += bounds.width / 2 - vr.width / 2;
                 }

                 // Setup width and height we want to see
@@ -1470,7 +1470,7 @@ public class WebTree<N extends MutableTreeNode> extends JTree implements Styleab
                 }
                 if ( centered )
                 {
-                    nodeBounds.y = nodeBounds.y + nodeBounds.height / 2 - visibleBounds.height / 2;
+                    nodeBounds.y += nodeBounds.height / 2 - visibleBounds.height / 2;
                     nodeBounds.height = visibleBounds.height;
                 }
                 scrollRectToVisible ( nodeBounds );
diff --git a/modules/ui/src/com/alee/managers/notification/NotificationsLayoutUtils.java b/modules/ui/src/com/alee/managers/notification/NotificationsLayoutUtils.java
index c6f5a3c4..24f38aae 100644
--- a/modules/ui/src/com/alee/managers/notification/NotificationsLayoutUtils.java
+++ b/modules/ui/src/com/alee/managers/notification/NotificationsLayoutUtils.java
@@ -76,7 +76,7 @@ public final class NotificationsLayoutUtils implements SwingConstants
             maxWidth = Math.max ( maxWidth, ps.width );

             // Incrementing notification position
-            y = y + ( south ? -1 : 1 ) * ( flowDisplayType ? ps.height + gap : gap );
+            y += ( south ? -1 : 1 ) * ( flowDisplayType ? ps.height + gap : gap );
             if ( cascade )
             {
                 count++;
diff --git a/modules/ui/src/com/alee/managers/tooltip/AbstractComponentArea.java b/modules/ui/src/com/alee/managers/tooltip/AbstractComponentArea.java
index 3ce311a9..b4474b3b 100644
--- a/modules/ui/src/com/alee/managers/tooltip/AbstractComponentArea.java
+++ b/modules/ui/src/com/alee/managers/tooltip/AbstractComponentArea.java
@@ -85,7 +85,7 @@ public abstract class AbstractComponentArea<V, C extends JComponent> implements
         {
             // Content is on the right
             final Dimension preferred = content.getPreferredSize ();
-            bounds.x = bounds.x + bounds.width - preferred.width;
+            bounds.x += bounds.width - preferred.width;
             bounds.width = preferred.width;
         }
     }
diff --git a/modules/ui/src/com/alee/utils/SelectorUtils.java b/modules/ui/src/com/alee/utils/SelectorUtils.java
index d847d4d9..851662ab 100644
--- a/modules/ui/src/com/alee/utils/SelectorUtils.java
+++ b/modules/ui/src/com/alee/utils/SelectorUtils.java
@@ -388,13 +388,13 @@ public final class SelectorUtils
             final int width = Math.abs ( rect.width );
             if ( rect.width < 0 )
             {
-                x = x - width;
+                x -= width;
             }
             int y = rect.y;
             final int height = Math.abs ( rect.height );
             if ( rect.height < 0 )
             {
-                y = y - height;
+                y -= height;
             }
             result = new Rectangle ( x, y, width, height );
         }