diff --git a/src/main/java/com/weis/darklaf/DarkLaf.java b/src/main/java/com/weis/darklaf/DarkLaf.java index ba06bc51..374c8aab 100644 --- a/src/main/java/com/weis/darklaf/DarkLaf.java +++ b/src/main/java/com/weis/darklaf/DarkLaf.java @@ -1,10 +1,9 @@ package com.weis.darklaf; -import com.bulenkov.darcula.DarculaMetalTheme; -import com.bulenkov.iconloader.util.SystemInfo; import com.weis.darklaf.platform.windows.JNIDecorations; import com.weis.darklaf.ui.menu.DarkPopupMenuUI; import com.weis.darklaf.util.LafUtil; +import com.weis.darklaf.util.SystemInfo; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import sun.awt.AppContext; @@ -45,7 +44,7 @@ public class DarkLaf extends BasicLookAndFeel { try { if (SystemInfo.isWindows || SystemInfo.isLinux) { base = new MetalLookAndFeel(); - MetalLookAndFeel.setCurrentTheme(new DarculaMetalTheme()); + MetalLookAndFeel.setCurrentTheme(new DarkMetalTheme()); } else { final String name = UIManager.getSystemLookAndFeelClassName(); base = (BasicLookAndFeel) Class.forName(name).getDeclaredConstructor().newInstance(); diff --git a/src/main/java/com/weis/darklaf/DarkMetalTheme.java b/src/main/java/com/weis/darklaf/DarkMetalTheme.java new file mode 100644 index 00000000..047ace6c --- /dev/null +++ b/src/main/java/com/weis/darklaf/DarkMetalTheme.java @@ -0,0 +1,75 @@ +package com.weis.darklaf; + +import javax.swing.plaf.ColorUIResource; +import javax.swing.plaf.metal.DefaultMetalTheme; +import java.awt.*; + +public class DarkMetalTheme extends DefaultMetalTheme { + private final ColorUIResource myControlHighlightColor = new ColorUIResource(108, 111, 113); + private final ColorUIResource myControlDarkShadowColor = new ColorUIResource(39, 42, 44); + private final ColorUIResource myControlColor = new ColorUIResource(3948353); + private static final ColorUIResource white = new ColorUIResource(128, 128, 128); + private static final ColorUIResource darkBlue = new ColorUIResource(0, 44, 63); + private static final ColorUIResource lightGray = new ColorUIResource(109, 109, 109); + private final ColorUIResource mySeparatorForeground = new ColorUIResource(53, 56, 58); + public static final ColorUIResource primary1 = new ColorUIResource(53, 56, 58); + private static final ColorUIResource primary2 = new ColorUIResource(50, 66, 114); + private static final ColorUIResource primary3 = new ColorUIResource(53, 69, 91); + + public String getName() { + return "Darcula theme"; + } + + public ColorUIResource getControl() { + return this.myControlColor; + } + + public ColorUIResource getControlHighlight() { + return this.myControlHighlightColor; + } + + public ColorUIResource getControlDarkShadow() { + return this.myControlDarkShadowColor; + } + + public ColorUIResource getSeparatorBackground() { + return this.getControl(); + } + + public ColorUIResource getSeparatorForeground() { + return this.mySeparatorForeground; + } + + public ColorUIResource getMenuBackground() { + return lightGray; + } + + public ColorUIResource getMenuSelectedBackground() { + return darkBlue; + } + + public ColorUIResource getMenuSelectedForeground() { + return white; + } + + public ColorUIResource getAcceleratorSelectedForeground() { + return white; + } + + public ColorUIResource getFocusColor() { + return new ColorUIResource(Color.black); + } + + protected ColorUIResource getPrimary1() { + return primary1; + } + + protected ColorUIResource getPrimary2() { + return primary2; + } + + protected ColorUIResource getPrimary3() { + return primary3; + } +} + diff --git a/src/main/java/com/weis/darklaf/LightLaf.java b/src/main/java/com/weis/darklaf/LightLaf.java index e0c8e6e1..31d2ef48 100644 --- a/src/main/java/com/weis/darklaf/LightLaf.java +++ b/src/main/java/com/weis/darklaf/LightLaf.java @@ -1,6 +1,7 @@ package com.weis.darklaf; -import com.bulenkov.iconloader.util.SystemInfo; + +import com.weis.darklaf.util.SystemInfo; import org.jetbrains.annotations.NotNull; import javax.swing.plaf.metal.MetalLookAndFeel; @@ -19,7 +20,6 @@ public class LightLaf extends DarkLaf { * Create new light Darcula LaF. */ public LightLaf() { - super(); if (SystemInfo.isWindows || SystemInfo.isLinux) { MetalLookAndFeel.setCurrentTheme(new LightMetalTheme()); } diff --git a/src/main/java/com/weis/darklaf/components/ColorPipetteBase.java b/src/main/java/com/weis/darklaf/components/ColorPipetteBase.java index aa923186..72e7c6eb 100644 --- a/src/main/java/com/weis/darklaf/components/ColorPipetteBase.java +++ b/src/main/java/com/weis/darklaf/components/ColorPipetteBase.java @@ -1,6 +1,6 @@ package com.weis.darklaf.components; -import com.bulenkov.iconloader.util.SystemInfo; + import com.weis.darklaf.ui.colorchooser.ColorListener; import com.weis.darklaf.ui.colorchooser.ColorPipette; import com.weis.darklaf.util.DarkUIUtil; @@ -226,12 +226,6 @@ public abstract class ColorPipetteBase implements ColorPipette, AWTEventListener setCursor(blankCursor); } - @NotNull - @Override - public Cursor getCursor() { - return super.getCursor(); - } - @Override protected JRootPane createRootPane() { return new JRootPane() { diff --git a/src/main/java/com/weis/darklaf/components/ScrollPopupMenu.java b/src/main/java/com/weis/darklaf/components/ScrollPopupMenu.java index 5842b268..42550e51 100644 --- a/src/main/java/com/weis/darklaf/components/ScrollPopupMenu.java +++ b/src/main/java/com/weis/darklaf/components/ScrollPopupMenu.java @@ -11,29 +11,6 @@ import java.awt.*; public class ScrollPopupMenu extends JPopupMenu { - private final MenuKeyListener menuKeyListener = new MenuKeyListener() { - @Override - public void menuKeyTyped(final MenuKeyEvent e) { - } - - @Override - public void menuKeyPressed(final MenuKeyEvent e) { - SwingUtilities.invokeLater(() -> { - var path = e.getMenuSelectionManager().getSelectedPath(); - if (path.length == 0) { - return; - } - var bounds = path[path.length - 1].getComponent().getBounds(); - var r = SwingUtilities.convertRectangle(ScrollPopupMenu.this, bounds, scrollPane); - scrollPane.getViewport().scrollRectToVisible(r); - }); - } - - @Override - public void menuKeyReleased(final MenuKeyEvent e) { - - } - }; private int maxHeight; private final JPanel contentPane; private final JScrollPane scrollPane; @@ -49,6 +26,29 @@ public class ScrollPopupMenu extends JPopupMenu { contentPane.add(overlayScrollPane, BorderLayout.CENTER); contentPane.setBorder(getBorder()); setDoubleBuffered(true); + MenuKeyListener menuKeyListener = new MenuKeyListener() { + @Override + public void menuKeyTyped(final MenuKeyEvent e) { + } + + @Override + public void menuKeyPressed(final MenuKeyEvent e) { + SwingUtilities.invokeLater(() -> { + var path = e.getMenuSelectionManager().getSelectedPath(); + if (path.length == 0) { + return; + } + var bounds = path[path.length - 1].getComponent().getBounds(); + var r = SwingUtilities.convertRectangle(ScrollPopupMenu.this, bounds, scrollPane); + scrollPane.getViewport().scrollRectToVisible(r); + }); + } + + @Override + public void menuKeyReleased(final MenuKeyEvent e) { + + } + }; addMenuKeyListener(menuKeyListener); } diff --git a/src/main/java/com/weis/darklaf/components/border/DropShadowBorder.java b/src/main/java/com/weis/darklaf/components/border/DropShadowBorder.java index 570a9185..2ec5378b 100644 --- a/src/main/java/com/weis/darklaf/components/border/DropShadowBorder.java +++ b/src/main/java/com/weis/darklaf/components/border/DropShadowBorder.java @@ -46,7 +46,7 @@ public class DropShadowBorder implements Border, Serializable { } private static final Map> CACHE - = new HashMap>(); + = new HashMap<>(); private Color shadowColor; @@ -146,9 +146,9 @@ public class DropShadowBorder implements Border, Serializable { topLeftShadowPoint = new Point(); if (showLeftShadow && !showTopShadow) { topLeftShadowPoint.setLocation(x, y + shadowOffset); - } else if (showLeftShadow && showTopShadow) { + } else if (showLeftShadow) { topLeftShadowPoint.setLocation(x, y); - } else if (!showLeftShadow && showTopShadow) { + } else { topLeftShadowPoint.setLocation(x + shadowSize, y); } } @@ -158,9 +158,9 @@ public class DropShadowBorder implements Border, Serializable { bottomLeftShadowPoint = new Point(); if (showLeftShadow && !showBottomShadow) { bottomLeftShadowPoint.setLocation(x, y + height - shadowSize - shadowSize); - } else if (showLeftShadow && showBottomShadow) { + } else if (showLeftShadow) { bottomLeftShadowPoint.setLocation(x, y + height - shadowSize); - } else if (!showLeftShadow && showBottomShadow) { + } else { bottomLeftShadowPoint.setLocation(x + shadowSize, y + height - shadowSize); } } @@ -170,9 +170,9 @@ public class DropShadowBorder implements Border, Serializable { bottomRightShadowPoint = new Point(); if (showRightShadow && !showBottomShadow) { bottomRightShadowPoint.setLocation(x + width - shadowSize, y + height - shadowSize - shadowSize); - } else if (showRightShadow && showBottomShadow) { + } else if (showRightShadow) { bottomRightShadowPoint.setLocation(x + width - shadowSize, y + height - shadowSize); - } else if (!showRightShadow && showBottomShadow) { + } else { bottomRightShadowPoint.setLocation(x + width - shadowSize - shadowSize, y + height - shadowSize); } } @@ -182,9 +182,9 @@ public class DropShadowBorder implements Border, Serializable { topRightShadowPoint = new Point(); if (showRightShadow && !showTopShadow) { topRightShadowPoint.setLocation(x + width - shadowSize, y + shadowOffset); - } else if (showRightShadow && showTopShadow) { + } else if (showRightShadow) { topRightShadowPoint.setLocation(x + width - shadowSize, y); - } else if (!showRightShadow && showTopShadow) { + } else { topRightShadowPoint.setLocation(x + width - shadowSize - shadowSize, y); } } @@ -256,11 +256,12 @@ public class DropShadowBorder implements Border, Serializable { } } + @SuppressWarnings("SuspiciousNameCombination") @NotNull private Map getImages(Graphics2D g2) { //first, check to see if an image for this size has already been rendered //if so, use the cache. Else, draw and save - Map images = CACHE.get(shadowSize + (shadowColor.hashCode() * .3) + (shadowOpacity * .12));//TODO do a real hash + Map images = CACHE.get(shadowSize + (shadowColor.hashCode() * .3) + (shadowOpacity * .12));//(TUDU) do a real hash if (images == null) { images = new HashMap<>(); @@ -344,7 +345,7 @@ public class DropShadowBorder implements Border, Serializable { image.flush(); CACHE.put(shadowSize + (shadowColor.hashCode() * .3) + (shadowOpacity * .12), - images); //TODO do a real hash + images); //TUDU do a real hash } return images; } diff --git a/src/main/java/com/weis/darklaf/icons/IconLoader.java b/src/main/java/com/weis/darklaf/icons/IconLoader.java index 5f8fe8e5..0216d33e 100644 --- a/src/main/java/com/weis/darklaf/icons/IconLoader.java +++ b/src/main/java/com/weis/darklaf/icons/IconLoader.java @@ -93,7 +93,7 @@ public final class IconLoader { } public static final class IconKey { - String path; + final String path; int w; int h; diff --git a/src/main/java/com/weis/darklaf/platform/windows/JNIDecorations.java b/src/main/java/com/weis/darklaf/platform/windows/JNIDecorations.java index 0d90e65f..4bfc631a 100644 --- a/src/main/java/com/weis/darklaf/platform/windows/JNIDecorations.java +++ b/src/main/java/com/weis/darklaf/platform/windows/JNIDecorations.java @@ -1,10 +1,10 @@ package com.weis.darklaf.platform.windows; -import com.bulenkov.iconloader.util.SystemInfo; import com.sun.jna.Native; import com.sun.jna.Pointer; import com.weis.darklaf.DarkLaf; import com.weis.darklaf.platform.NativeUtil; +import com.weis.darklaf.util.SystemInfo; import org.jetbrains.annotations.Contract; import java.awt.*; @@ -35,8 +35,6 @@ public class JNIDecorations { } private static final Logger LOGGER = Logger.getLogger(JNIDecorations.class.getName()); - private static final String X86 = "32"; - private static final String X64 = "64"; private static boolean supported; private static boolean loaded; @@ -63,13 +61,14 @@ public class JNIDecorations { } if (loaded) return true; try { - String model = System.getProperty("sun.arch.data.model"); - if (X86.equals(model)) { + if (SystemInfo.isX86) { NativeUtil.loadLibraryFromJar("/library/x86/jniplatform.dll"); - } else if (X64.equals(model)) { + } else if (SystemInfo.isX64) { NativeUtil.loadLibraryFromJar("/library/x64/jniplatform.dll"); } else { - LOGGER.warning("Could not determine jre model '" + model + "'. Decorations will be disabled"); + LOGGER.warning("Could not determine jre model '" + + SystemInfo.jreArchitecture + + "'. Decorations will be disabled"); return false; } loaded = true; diff --git a/src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java b/src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java index e9536c63..28795502 100644 --- a/src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java +++ b/src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java @@ -1,6 +1,5 @@ package com.weis.darklaf.ui.button; -import com.bulenkov.darcula.ui.DarculaButtonPainter; import com.weis.darklaf.util.DarkUIUtil; import com.weis.darklaf.util.GraphicsContext; import org.jetbrains.annotations.Contract; @@ -15,8 +14,6 @@ import java.awt.geom.Area; import java.awt.geom.RoundRectangle2D; /** - * Custom adaption of {@link DarculaButtonPainter}. - * * @author Jannis Weis * @since 2019 */ diff --git a/src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java b/src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java index 9e154641..2bb6bb7f 100644 --- a/src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java +++ b/src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java @@ -1,9 +1,8 @@ package com.weis.darklaf.ui.button; -import com.bulenkov.darcula.ui.DarculaButtonUI; -import com.bulenkov.iconloader.util.SystemInfo; import com.weis.darklaf.util.GraphicsContext; import com.weis.darklaf.util.GraphicsUtil; +import com.weis.darklaf.util.SystemInfo; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; @@ -19,8 +18,6 @@ import java.awt.*; import java.awt.geom.RoundRectangle2D; /** - * Custom adaption of {@link DarculaButtonUI}. - * * @author Jannis Weis * @since 2019 */ diff --git a/src/main/java/com/weis/darklaf/ui/checkbox/DarkCheckBoxBorder.java b/src/main/java/com/weis/darklaf/ui/checkbox/DarkCheckBoxBorder.java index b1834e41..4001f7ac 100644 --- a/src/main/java/com/weis/darklaf/ui/checkbox/DarkCheckBoxBorder.java +++ b/src/main/java/com/weis/darklaf/ui/checkbox/DarkCheckBoxBorder.java @@ -1,7 +1,8 @@ package com.weis.darklaf.ui.checkbox; -import com.bulenkov.iconloader.util.SystemInfo; + import com.weis.darklaf.util.DarkUIUtil; +import com.weis.darklaf.util.SystemInfo; import javax.swing.border.Border; import javax.swing.plaf.InsetsUIResource; diff --git a/src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelImageProducer.java b/src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelImageProducer.java index c0b9475d..bd9923ed 100644 --- a/src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelImageProducer.java +++ b/src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelImageProducer.java @@ -9,7 +9,7 @@ public class ColorWheelImageProducer extends MemoryImageSource { private final int[] myPixels; private final int myWidth; private final int myHeight; - private float myBrightness = 1f; + private float myBrightness; private float[] myHues; private float[] mySat; diff --git a/src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelPanel.java b/src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelPanel.java index 2bcc45f5..5cef2438 100644 --- a/src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelPanel.java +++ b/src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelPanel.java @@ -9,7 +9,6 @@ import java.awt.*; public class ColorWheelPanel extends JPanel { private final ColorWheel myColorWheel; private final SlideComponent myBrightnessComponent; - private final boolean opacityInPercent; private SlideComponent myOpacityComponent = null; private boolean enableOpacity; @@ -19,7 +18,6 @@ public class ColorWheelPanel extends JPanel { setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); this.enableOpacity = enableOpacity; - this.opacityInPercent = opacityInPercent; myColorWheel = new ColorWheel(); add(myColorWheel, BorderLayout.CENTER); diff --git a/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java b/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java index 8349fbf8..10e643dd 100644 --- a/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java +++ b/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java @@ -11,8 +11,6 @@ import javax.swing.colorchooser.AbstractColorChooserPanel; import javax.swing.event.AncestorEvent; import javax.swing.event.AncestorListener; import java.awt.*; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; import java.awt.event.KeyEvent; public class DarkColorChooserPanel extends AbstractColorChooserPanel implements ColorListener { diff --git a/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java b/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java index 66121bed..d656ca9c 100644 --- a/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java +++ b/src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java @@ -13,9 +13,6 @@ import javax.swing.event.AncestorListener; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicColorChooserUI; import java.awt.*; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; import java.beans.PropertyChangeListener; public class DarkColorChooserUI extends BasicColorChooserUI { diff --git a/src/main/java/com/weis/darklaf/ui/menu/DarkPopupMenuUI.java b/src/main/java/com/weis/darklaf/ui/menu/DarkPopupMenuUI.java index e284a847..b407de7d 100644 --- a/src/main/java/com/weis/darklaf/ui/menu/DarkPopupMenuUI.java +++ b/src/main/java/com/weis/darklaf/ui/menu/DarkPopupMenuUI.java @@ -85,7 +85,7 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI { MenuSelectionManager msm = MenuSelectionManager.defaultManager(); MenuElement[] p = msm.getSelectedPath(); - List list = new ArrayList(p.length); + List list = new ArrayList<>(p.length); for (MenuElement element : p) { if (element instanceof JPopupMenu) { list.add((JPopupMenu) element); diff --git a/src/main/java/com/weis/darklaf/ui/radiobutton/DarkRadioButtonBorder.java b/src/main/java/com/weis/darklaf/ui/radiobutton/DarkRadioButtonBorder.java index a1c47654..a714d6d2 100644 --- a/src/main/java/com/weis/darklaf/ui/radiobutton/DarkRadioButtonBorder.java +++ b/src/main/java/com/weis/darklaf/ui/radiobutton/DarkRadioButtonBorder.java @@ -1,7 +1,8 @@ package com.weis.darklaf.ui.radiobutton; -import com.bulenkov.iconloader.util.SystemInfo; + import com.weis.darklaf.util.DarkUIUtil; +import com.weis.darklaf.util.SystemInfo; import javax.swing.border.Border; import javax.swing.plaf.InsetsUIResource; diff --git a/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerBorder.java b/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerBorder.java index 708f5cc3..f40730a9 100644 --- a/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerBorder.java +++ b/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerBorder.java @@ -14,8 +14,8 @@ import java.awt.*; public class DarkSpinnerBorder implements Border, UIResource { - public static int BORDER_SIZE = DarkTextBorder.BORDER_SIZE; - public static int ARC_SIZE = DarkTextFieldUI.SEARCH_ARC_SIZE; + public static final int BORDER_SIZE = DarkTextBorder.BORDER_SIZE; + public static final int ARC_SIZE = DarkTextFieldUI.SEARCH_ARC_SIZE; @Override public void paintBorder(@NotNull final Component c, final Graphics g2, diff --git a/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java b/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java index 8ac51401..a9c88c04 100644 --- a/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java +++ b/src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java @@ -31,7 +31,6 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe private Component component; private JComponent editor; private Color compColor; - private JButton nextButton; private JButton prevButton; private final FocusListener focusListener = new FocusAdapter() { @@ -128,7 +127,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe @Override protected Component createNextButton() { - nextButton = createArrow(SwingConstants.NORTH); + JButton nextButton = createArrow(SwingConstants.NORTH); nextButton.setName("Spinner.nextButton"); nextButton.setBorder(new EmptyBorder(1, 1, 1, 1)); installNextButtonListeners(nextButton); diff --git a/src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java b/src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java index be9b8ce4..ae404d28 100644 --- a/src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java +++ b/src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java @@ -941,6 +941,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { } + @SuppressWarnings("SuspiciousNameCombination") @Override protected void calculateTabRects(final int tabPlacement, final int tabCount) { FontMetrics metrics = getFontMetrics(); diff --git a/src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java b/src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java index aae961bd..92025629 100644 --- a/src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java +++ b/src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java @@ -35,6 +35,7 @@ import java.awt.event.MouseMotionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Hashtable; +import java.util.Objects; import java.util.Vector; /** @@ -196,8 +197,8 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan // Private instance data - protected Insets currentPadInsets = new Insets(0, 0, 0, 0); - protected Insets currentTabAreaInsets = new Insets(0, 0, 0, 0); + protected final Insets currentPadInsets = new Insets(0, 0, 0, 0); + protected final Insets currentTabAreaInsets = new Insets(0, 0, 0, 0); protected Component visibleComponent; // PENDING(api): See comment for ContainerHandler @@ -220,7 +221,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan * A rectangle used for general layout calculations in order * to avoid constructing many new Rectangles on the fly. */ - protected transient Rectangle calcRect = new Rectangle(0, 0, 0, 0); + protected final transient Rectangle calcRect = new Rectangle(0, 0, 0, 0); /** * Tab that has focus. @@ -644,6 +645,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan /** * Adds the specified mnemonic at the specified index. */ + @SuppressWarnings("MagicConstant") protected void addMnemonic(final int index, final int mnemonic) { if (mnemonicToIndexMap == null) { initMnemonics(); @@ -653,14 +655,14 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan mnemonicInputMap.put(KeyStroke.getKeyStroke(mnemonic, InputEvent.ALT_GRAPH_DOWN_MASK | DarkUIUtil.getFocusAcceleratorKeyMask()), "setSelectedIndex"); - mnemonicToIndexMap.put(Integer.valueOf(mnemonic), Integer.valueOf(index)); + mnemonicToIndexMap.put(mnemonic, index); } /** * Installs the state needed for mnemonics. */ protected void initMnemonics() { - mnemonicToIndexMap = new Hashtable(); + mnemonicToIndexMap = new Hashtable<>(); mnemonicInputMap = new ComponentInputMapUIResource(tabPane); mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(tabPane, JComponent.WHEN_IN_FOCUSED_WINDOW)); @@ -733,16 +735,14 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan Insets tabAreaInsets = getTabAreaInsets(placement); switch (placement) { case JTabbedPane.TOP: + case JTabbedPane.LEFT: + case JTabbedPane.RIGHT: baseline += insets.top + tabAreaInsets.top; return baseline; case JTabbedPane.BOTTOM: baseline = height - insets.bottom - tabAreaInsets.bottom - maxTabHeight + baseline; return baseline; - case JTabbedPane.LEFT: - case JTabbedPane.RIGHT: - baseline += insets.top + tabAreaInsets.top; - return baseline; } } return -1; @@ -1025,8 +1025,8 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan * subtracting xCropLen[i] from (tab.y + tab.height) and adding yCropLen[i] * to (tab.x). */ - protected static int[] xCropLen = {1, 1, 0, 0, 1, 1, 2, 2}; - protected static int[] yCropLen = {0, 3, 3, 6, 6, 9, 9, 12}; + protected static final int[] xCropLen = {1, 1, 0, 0, 1, 1, 2, 2}; + protected static final int[] yCropLen = {0, 3, 3, 6, 6, 9, 9, 12}; protected static final int CROP_SEGMENT = 12; protected static Polygon createCroppedTabShape(final int tabPlacement, final Rectangle tabRect, final int cropline) { @@ -2511,7 +2511,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan */ protected int getPreviousTabIndex(final int base) { int tabIndex = (base - 1 >= 0 ? base - 1 : tabPane.getTabCount() - 1); - return (tabIndex >= 0 ? tabIndex : 0); + return (Math.max(tabIndex, 0)); } /** @@ -2570,7 +2570,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan */ protected int getPreviousTabRun(final int baseRun) { int runIndex = (baseRun - 1 >= 0 ? baseRun - 1 : runCount - 1); - return (runIndex >= 0 ? runIndex : 0); + return (Math.max(runIndex, 0)); } /** @@ -2590,6 +2590,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan * @param targetInsets the target insets * @param targetPlacement the target placement */ + @SuppressWarnings("SuspiciousNameCombination") protected static void rotateInsets(final Insets topInsets, final Insets targetInsets, final int targetPlacement) { switch (targetPlacement) { @@ -2658,37 +2659,37 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan if (ui == null) { return; } - if (key == NEXT) { + if (Objects.equals(key, NEXT)) { ui.navigateSelectedTab(SwingConstants.NEXT); - } else if (key == PREVIOUS) { + } else if (Objects.equals(key, PREVIOUS)) { ui.navigateSelectedTab(SwingConstants.PREVIOUS); - } else if (key == RIGHT) { + } else if (Objects.equals(key, RIGHT)) { ui.navigateSelectedTab(SwingConstants.EAST); - } else if (key == LEFT) { + } else if (Objects.equals(key, LEFT)) { ui.navigateSelectedTab(SwingConstants.WEST); - } else if (key == UP) { + } else if (Objects.equals(key, UP)) { ui.navigateSelectedTab(SwingConstants.NORTH); - } else if (key == DOWN) { + } else if (Objects.equals(key, DOWN)) { ui.navigateSelectedTab(SwingConstants.SOUTH); - } else if (key == PAGE_UP) { + } else if (Objects.equals(key, PAGE_UP)) { int tabPlacement = pane.getTabPlacement(); if (tabPlacement == TOP || tabPlacement == BOTTOM) { ui.navigateSelectedTab(SwingConstants.WEST); } else { ui.navigateSelectedTab(SwingConstants.NORTH); } - } else if (key == PAGE_DOWN) { + } else if (Objects.equals(key, PAGE_DOWN)) { int tabPlacement = pane.getTabPlacement(); if (tabPlacement == TOP || tabPlacement == BOTTOM) { ui.navigateSelectedTab(SwingConstants.EAST); } else { ui.navigateSelectedTab(SwingConstants.SOUTH); } - } else if (key == REQUEST_FOCUS) { + } else if (Objects.equals(key, REQUEST_FOCUS)) { pane.requestFocus(); - } else if (key == REQUEST_FOCUS_FOR_VISIBLE) { + } else if (Objects.equals(key, REQUEST_FOCUS_FOR_VISIBLE)) { ui.requestFocusForVisibleComponent(); - } else if (key == SET_SELECTED) { + } else if (Objects.equals(key, SET_SELECTED)) { String command = e.getActionCommand(); if (command != null && command.length() > 0) { @@ -2696,21 +2697,21 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan if (mnemonic >= 'a' && mnemonic <= 'z') { mnemonic -= ('a' - 'A'); } - Integer index = ui.mnemonicToIndexMap.get(Integer.valueOf(mnemonic)); - if (index != null && pane.isEnabledAt(index.intValue())) { - pane.setSelectedIndex(index.intValue()); + Integer index = ui.mnemonicToIndexMap.get(mnemonic); + if (index != null && pane.isEnabledAt(index)) { + pane.setSelectedIndex(index); } } - } else if (key == SELECT_FOCUSED) { + } else if (Objects.equals(key, SELECT_FOCUSED)) { int focusIndex = ui.getFocusIndex(); if (focusIndex != -1) { pane.setSelectedIndex(focusIndex); } - } else if (key == SCROLL_FORWARD) { + } else if (Objects.equals(key, SCROLL_FORWARD)) { if (ui.scrollableTabLayoutEnabled()) { ui.tabScroller.scrollForward(pane.getTabPlacement()); } - } else if (key == SCROLL_BACKWARD) { + } else if (Objects.equals(key, SCROLL_BACKWARD)) { if (ui.scrollableTabLayoutEnabled()) { ui.tabScroller.scrollBackward(pane.getTabPlacement()); } @@ -3228,9 +3229,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan protected void rotateTabRuns(final int tabPlacement, final int selectedRun) { for (int i = 0; i < selectedRun; i++) { int save = tabRuns[0]; - for (int j = 1; j < runCount; j++) { - tabRuns[j - 1] = tabRuns[j]; - } + if (runCount - 1 >= 0) System.arraycopy(tabRuns, 1, tabRuns, 0, runCount - 1); tabRuns[runCount - 1] = save; } } @@ -3577,8 +3576,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan } else if (tabScroller != null && (child == tabScroller.scrollForwardButton || child == tabScroller.scrollBackwardButton)) { - Component scrollbutton = child; - Dimension bsize = scrollbutton.getPreferredSize(); + Dimension bsize = child.getPreferredSize(); int bx = 0; int by = 0; int bw = bsize.width; @@ -3764,10 +3762,10 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan public ScrollableTabPanel tabPanel; public JButton scrollForwardButton; public JButton scrollBackwardButton; - public CroppedEdge croppedEdge; + public final CroppedEdge croppedEdge; public int leadingTabIndex; - protected Point tabViewPosition = new Point(0, 0); + protected final Point tabViewPosition = new Point(0, 0); ScrollableTabSupport(final int tabPlacement) { viewport = new ScrollableTabViewport(); @@ -4012,7 +4010,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan } @SuppressWarnings("serial") // Superclass is not serializable across versions - protected class ScrollableTabButton extends BasicArrowButton implements UIResource, + protected static class ScrollableTabButton extends BasicArrowButton implements UIResource, SwingConstants { public ScrollableTabButton(final int direction) { super(direction, @@ -4036,36 +4034,36 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan JTabbedPane pane = (JTabbedPane) e.getSource(); String name = e.getPropertyName(); boolean isScrollLayout = scrollableTabLayoutEnabled(); - if (name == "mnemonicAt") { + if (Objects.equals(name, "mnemonicAt")) { updateMnemonics(); pane.repaint(); - } else if (name == "displayedMnemonicIndexAt") { + } else if (Objects.equals(name, "displayedMnemonicIndexAt")) { pane.repaint(); - } else if (name == "indexForTitle") { + } else if (Objects.equals(name, "indexForTitle")) { calculatedBaseline = false; Integer index = (Integer) e.getNewValue(); updateHtmlViews(index, false); - } else if (name == "tabLayoutPolicy") { + } else if (Objects.equals(name, "tabLayoutPolicy")) { DarkTabbedPaneUIBridge.this.uninstallUI(pane); DarkTabbedPaneUIBridge.this.installUI(pane); calculatedBaseline = false; - } else if (name == "tabPlacement") { + } else if (Objects.equals(name, "tabPlacement")) { if (scrollableTabLayoutEnabled()) { tabScroller.createButtons(); } calculatedBaseline = false; - } else if (name == "opaque" && isScrollLayout) { - boolean newVal = ((Boolean) e.getNewValue()).booleanValue(); + } else if (Objects.equals(name, "opaque") && isScrollLayout) { + boolean newVal = (Boolean) e.getNewValue(); tabScroller.tabPanel.setOpaque(newVal); tabScroller.viewport.setOpaque(newVal); - } else if (name == "background" && isScrollLayout) { + } else if (Objects.equals(name, "background") && isScrollLayout) { Color newVal = (Color) e.getNewValue(); tabScroller.tabPanel.setBackground(newVal); tabScroller.viewport.setBackground(newVal); Color newColor = selectedColor == null ? newVal : selectedColor; tabScroller.scrollForwardButton.setBackground(newColor); tabScroller.scrollBackwardButton.setBackground(newColor); - } else if (name == "indexForTabComponent") { + } else if (Objects.equals(name, "indexForTabComponent")) { if (tabContainer != null) { tabContainer.removeUnusedTabComponents(); } @@ -4081,10 +4079,10 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan tabPane.revalidate(); tabPane.repaint(); calculatedBaseline = false; - } else if (name == "indexForNullComponent") { + } else if (Objects.equals(name, "indexForNullComponent")) { isRunsDirty = true; updateHtmlViews((Integer) e.getNewValue(), true); - } else if (name == "font" || SwingUtilities2.isScaleChanged(e)) { + } else if (Objects.equals(name, "font") || SwingUtilities2.isScaleChanged(e)) { calculatedBaseline = false; } } @@ -4252,7 +4250,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan Integer indexObj = (Integer) tp.getClientProperty("__index_to_remove__"); if (indexObj != null) { - int index = indexObj.intValue(); + int index = indexObj; if (htmlViews != null && htmlViews.size() > index) { htmlViews.removeElementAt(index); } @@ -4326,7 +4324,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan } protected Vector createHTMLVector() { - Vector htmlViews = new Vector(); + Vector htmlViews = new Vector<>(); int count = tabPane.getTabCount(); if (count > 0) { for (int i = 0; i < count; i++) { diff --git a/src/main/java/com/weis/darklaf/ui/tabbedpane/TabbedPaneTransferHandler.java b/src/main/java/com/weis/darklaf/ui/tabbedpane/TabbedPaneTransferHandler.java index 886a9021..adcca720 100644 --- a/src/main/java/com/weis/darklaf/ui/tabbedpane/TabbedPaneTransferHandler.java +++ b/src/main/java/com/weis/darklaf/ui/tabbedpane/TabbedPaneTransferHandler.java @@ -274,6 +274,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa } dropRect.y = destRect.y + destRect.height - dropRect.height; } else if (placement == LEFT || placement == RIGHT) { + //Todo } } } @@ -525,6 +526,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa return new Rectangle(transferData.tabBounds); } + @NotNull @Override public Object getTransferData(final DataFlavor flavor) throws UnsupportedFlavorException { if (!isDataFlavorSupported(flavor)) { diff --git a/src/main/java/com/weis/darklaf/ui/table/DarkTableBorder.java b/src/main/java/com/weis/darklaf/ui/table/DarkTableBorder.java index 00905d56..adad8544 100644 --- a/src/main/java/com/weis/darklaf/ui/table/DarkTableBorder.java +++ b/src/main/java/com/weis/darklaf/ui/table/DarkTableBorder.java @@ -1,6 +1,7 @@ package com.weis.darklaf.ui.table; import com.weis.darklaf.components.border.MutableLineBorder; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.UIResource; @@ -13,7 +14,7 @@ public class DarkTableBorder extends MutableLineBorder implements UIResource { } @Override - public void paintBorder(final Component c, final Graphics g, final int x, final int y, + public void paintBorder(final Component c, @NotNull final Graphics g, final int x, final int y, final int width, final int height) { setColor(getBorderColor()); super.paintBorder(c, g, x, y, width, height); diff --git a/src/main/java/com/weis/darklaf/ui/table/DarkTableCellRenderer.java b/src/main/java/com/weis/darklaf/ui/table/DarkTableCellRenderer.java index dc3922c8..7a3729f6 100644 --- a/src/main/java/com/weis/darklaf/ui/table/DarkTableCellRenderer.java +++ b/src/main/java/com/weis/darklaf/ui/table/DarkTableCellRenderer.java @@ -48,11 +48,11 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer { if (!isSelected) { if (row % 2 == 1) { component.setBackground(alternativeRowColor); - setDefaultCellRenderWithAllType(table, value, isSelected, hasFocus, row, column, + setDefaultCellRenderWithAllType(table, value, false, hasFocus, row, column, alternativeRowColor); } else { component.setBackground(normalColor); - setDefaultCellRenderWithAllType(table, value, isSelected, hasFocus, row, column, normalColor); + setDefaultCellRenderWithAllType(table, value, false, hasFocus, row, column, normalColor); } component.setForeground(table.getSelectionForeground()); } diff --git a/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderBorder.java b/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderBorder.java index 1fbfbc00..52986167 100644 --- a/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderBorder.java +++ b/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderBorder.java @@ -1,6 +1,7 @@ package com.weis.darklaf.ui.table; import com.weis.darklaf.components.border.MutableLineBorder; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.UIResource; @@ -13,7 +14,7 @@ public class DarkTableHeaderBorder extends MutableLineBorder implements UIResour } @Override - public void paintBorder(final Component c, final Graphics g, final int x, final int y, + public void paintBorder(final Component c, @NotNull final Graphics g, final int x, final int y, final int width, final int height) { setColor(getBorderColor()); super.paintBorder(c, g, x, y, width, height); diff --git a/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUI.java b/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUI.java index 89a68df8..9a2dda7e 100644 --- a/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUI.java +++ b/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUI.java @@ -1,6 +1,6 @@ package com.weis.darklaf.ui.table; -import com.bulenkov.iconloader.util.GraphicsConfig; +import com.weis.darklaf.util.GraphicsContext; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -50,7 +50,7 @@ public class DarkTableHeaderUI extends DarkTableHeaderUIBridge { @Override public void paint(final Graphics g2, final @NotNull JComponent c) { final Graphics2D g = (Graphics2D) g2; - final GraphicsConfig config = new GraphicsConfig(g); + final GraphicsContext config = new GraphicsContext(g); int h = c.getHeight(); int w = c.getWidth(); diff --git a/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUIBridge.java b/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUIBridge.java index d6a9d47b..945933ed 100644 --- a/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUIBridge.java +++ b/src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUIBridge.java @@ -19,15 +19,16 @@ import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.MouseEvent; import java.util.Enumeration; +import java.util.Objects; public class DarkTableHeaderUIBridge extends BasicTableHeaderUI { - protected static Cursor resizeCursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR); + protected static final Cursor resizeCursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR); // // Instance Variables // - protected static FocusListener focusListener = new FocusListener() { + protected static final FocusListener focusListener = new FocusListener() { public void focusGained(@NotNull final FocusEvent e) { repaintHeader(e.getSource()); } @@ -242,7 +243,6 @@ public class DarkTableHeaderUIBridge extends BasicTableHeaderUI { if (doScroll) { scrollToColumn(newColIndex); } - return; } /** @@ -585,16 +585,16 @@ public class DarkTableHeaderUIBridge extends BasicTableHeaderUI { DarkTableHeaderUIBridge ui = (DarkTableHeaderUIBridge) DarkUIUtil.getUIOfType(th.getUI(), DarkTableHeaderUIBridge.class); if (ui != null) { - if (key == MOVE_COLUMN_LEFT) { + if (Objects.equals(key, MOVE_COLUMN_LEFT)) { return th.getReorderingAllowed() && maybeMoveColumn(true, th, ui, false); - } else if (key == MOVE_COLUMN_RIGHT) { + } else if (Objects.equals(key, MOVE_COLUMN_RIGHT)) { return th.getReorderingAllowed() && maybeMoveColumn(false, th, ui, false); - } else if (key == RESIZE_LEFT || - key == RESIZE_RIGHT) { + } else if (Objects.equals(key, RESIZE_LEFT) || + Objects.equals(key, RESIZE_RIGHT)) { return canResize(cm.getColumn(ui.getSelectedColumnIndex()), th); - } else if (key == FOCUS_TABLE) { + } else if (Objects.equals(key, FOCUS_TABLE)) { return (th.getTable() != null); } } @@ -611,7 +611,7 @@ public class DarkTableHeaderUIBridge extends BasicTableHeaderUI { } String name = getName(); - if (TOGGLE_SORT_ORDER == name) { + if (Objects.equals(TOGGLE_SORT_ORDER, name)) { JTable table = th.getTable(); RowSorter sorter = table == null ? null : table.getRowSorter(); if (sorter != null) { @@ -620,27 +620,27 @@ public class DarkTableHeaderUIBridge extends BasicTableHeaderUI { columnIndex); sorter.toggleSortOrder(columnIndex); } - } else if (SELECT_COLUMN_TO_LEFT == name) { + } else if (Objects.equals(SELECT_COLUMN_TO_LEFT, name)) { if (th.getComponentOrientation().isLeftToRight()) { ui.selectPreviousColumn(true); } else { ui.selectNextColumn(true); } - } else if (SELECT_COLUMN_TO_RIGHT == name) { + } else if (Objects.equals(SELECT_COLUMN_TO_RIGHT, name)) { if (th.getComponentOrientation().isLeftToRight()) { ui.selectNextColumn(true); } else { ui.selectPreviousColumn(true); } - } else if (MOVE_COLUMN_LEFT == name) { + } else if (Objects.equals(MOVE_COLUMN_LEFT, name)) { moveColumn(true, th, ui); - } else if (MOVE_COLUMN_RIGHT == name) { + } else if (Objects.equals(MOVE_COLUMN_RIGHT, name)) { moveColumn(false, th, ui); - } else if (RESIZE_LEFT == name) { + } else if (Objects.equals(RESIZE_LEFT, name)) { resize(true, th, ui); - } else if (RESIZE_RIGHT == name) { + } else if (Objects.equals(RESIZE_RIGHT, name)) { resize(false, th, ui); - } else if (FOCUS_TABLE == name) { + } else if (Objects.equals(FOCUS_TABLE, name)) { JTable table = th.getTable(); if (table != null) { table.requestFocusInWindow(); diff --git a/src/main/java/com/weis/darklaf/ui/table/DarkTableUIBridge.java b/src/main/java/com/weis/darklaf/ui/table/DarkTableUIBridge.java index 802a638d..bb92b138 100644 --- a/src/main/java/com/weis/darklaf/ui/table/DarkTableUIBridge.java +++ b/src/main/java/com/weis/darklaf/ui/table/DarkTableUIBridge.java @@ -23,8 +23,8 @@ public class DarkTableUIBridge extends BasicTableUI { } protected static int getAdjustedLead(final JTable table, final boolean row) { - return row ? getAdjustedLead(table, row, table.getSelectionModel()) - : getAdjustedLead(table, row, table.getColumnModel().getSelectionModel()); + return row ? getAdjustedLead(table, true, table.getSelectionModel()) + : getAdjustedLead(table, false, table.getColumnModel().getSelectionModel()); } /** @@ -233,7 +233,7 @@ public class DarkTableUIBridge extends BasicTableUI { protected Rectangle extendRect(final Rectangle rect, final boolean horizontal) { if (rect == null) { - return rect; + return null; } if (horizontal) { diff --git a/src/main/java/com/weis/darklaf/ui/text/DarkEditorPaneUI.java b/src/main/java/com/weis/darklaf/ui/text/DarkEditorPaneUI.java index be6a03b6..9bf20b9f 100644 --- a/src/main/java/com/weis/darklaf/ui/text/DarkEditorPaneUI.java +++ b/src/main/java/com/weis/darklaf/ui/text/DarkEditorPaneUI.java @@ -173,16 +173,14 @@ public class DarkEditorPaneUI extends DarkTextUI { void removeActions(final ActionMap map, final Action[] actions) { int n = actions.length; - for (int i = 0; i < n; i++) { - Action a = actions[i]; + for (Action a : actions) { map.remove(a.getValue(Action.NAME)); } } void addActions(final ActionMap map, final Action[] actions) { int n = actions.length; - for (int i = 0; i < n; i++) { - Action a = actions[i]; + for (Action a : actions) { map.put(a.getValue(Action.NAME), a); } } diff --git a/src/main/java/com/weis/darklaf/ui/text/DarkTextAreaUI.java b/src/main/java/com/weis/darklaf/ui/text/DarkTextAreaUI.java index 35a327b7..959e8622 100644 --- a/src/main/java/com/weis/darklaf/ui/text/DarkTextAreaUI.java +++ b/src/main/java/com/weis/darklaf/ui/text/DarkTextAreaUI.java @@ -46,11 +46,6 @@ public class DarkTextAreaUI extends DarkTextUI { return "TextArea"; } - protected void installDefaults() { - super.installDefaults(); - //the fix for 4785160 is undone - } - /** * This method gets called when a bound property is changed * on the associated JTextComponent. This is a hook diff --git a/src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java b/src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java index 14e7d1c9..553f9fb3 100644 --- a/src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java +++ b/src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java @@ -1,12 +1,13 @@ package com.weis.darklaf.ui.text; -import com.bulenkov.darcula.ui.DarculaTextBorder; import com.weis.darklaf.util.DarkUIUtil; import com.weis.darklaf.util.GraphicsContext; import com.weis.darklaf.util.GraphicsUtil; import org.jetbrains.annotations.Contract; import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.plaf.UIResource; import java.awt.*; /** @@ -15,7 +16,7 @@ import java.awt.*; * @author Jannis Weis * @since 2019 */ -public class DarkTextBorder extends DarculaTextBorder { +public class DarkTextBorder implements Border, UIResource { public final static int BORDER_SIZE = 2; public final static int PADDING = 4; @@ -77,4 +78,9 @@ public class DarkTextBorder extends DarculaTextBorder { } return insets; } + + @Override + public boolean isBorderOpaque() { + return false; + } } diff --git a/src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java b/src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java index 2ad98b00..49003aef 100644 --- a/src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java +++ b/src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java @@ -1,6 +1,5 @@ package com.weis.darklaf.ui.text; -import com.bulenkov.darcula.ui.DarculaTextBorder; import com.weis.darklaf.decorators.MouseClickListener; import com.weis.darklaf.decorators.MouseMovementListener; import com.weis.darklaf.decorators.PopupMenuAdapter; @@ -134,7 +133,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh Border border = c.getBorder(); if (isSearchField(c)) { paintSearchField(g, c); - } else if (border instanceof DarculaTextBorder) { + } else if (border instanceof DarkTextBorder) { paintBorderBackground(g, c); } else { super.paintBackground(g); diff --git a/src/main/java/com/weis/darklaf/ui/text/SelectLineAction.java b/src/main/java/com/weis/darklaf/ui/text/SelectLineAction.java index fc23f30b..dfffb537 100644 --- a/src/main/java/com/weis/darklaf/ui/text/SelectLineAction.java +++ b/src/main/java/com/weis/darklaf/ui/text/SelectLineAction.java @@ -39,7 +39,7 @@ public class SelectLineAction extends TextAction { @Override public void actionPerformed(final ActionEvent e) { - int newPos = 0; + int newPos; try { var textArea = getTextComponent(e); int caretPosition = textArea.getCaretPosition(); diff --git a/src/main/java/com/weis/darklaf/ui/text/SelectWordAction.java b/src/main/java/com/weis/darklaf/ui/text/SelectWordAction.java index 06dd32e0..d0c4ebf0 100644 --- a/src/main/java/com/weis/darklaf/ui/text/SelectWordAction.java +++ b/src/main/java/com/weis/darklaf/ui/text/SelectWordAction.java @@ -10,8 +10,8 @@ import java.awt.event.ActionEvent; public class SelectWordAction extends TextAction { - protected Action start; - protected Action end; + protected final Action start; + protected final Action end; public SelectWordAction() { super(DefaultEditorKit.selectWordAction); diff --git a/src/main/java/com/weis/darklaf/util/DarkUIUtil.java b/src/main/java/com/weis/darklaf/util/DarkUIUtil.java index 467ebc65..7cf0c678 100644 --- a/src/main/java/com/weis/darklaf/util/DarkUIUtil.java +++ b/src/main/java/com/weis/darklaf/util/DarkUIUtil.java @@ -1,8 +1,5 @@ package com.weis.darklaf.util; -import com.bulenkov.iconloader.util.ColorUtil; -import com.bulenkov.iconloader.util.DoubleColor; -import com.bulenkov.iconloader.util.Gray; import com.weis.darklaf.decorators.CellRenderer; import com.weis.darklaf.ui.menu.DarkPopupMenuUI; import org.jetbrains.annotations.Contract; @@ -181,8 +178,8 @@ public final class DarkUIUtil { } public static Color getTreeUnfocusedSelectionBackground() { - Color background = getTreeTextBackground(); - return ColorUtil.isDark(background) ? new DoubleColor(Gray._30, new Color(13, 41, 62)) : Gray._212; +// Color background = getTreeTextBackground(); + return new Color(13, 41, 62); } public static Color getTreeTextBackground() { diff --git a/src/main/java/com/weis/darklaf/util/LafUtil.java b/src/main/java/com/weis/darklaf/util/LafUtil.java index 8a9911de..7c4384f2 100644 --- a/src/main/java/com/weis/darklaf/util/LafUtil.java +++ b/src/main/java/com/weis/darklaf/util/LafUtil.java @@ -1,8 +1,5 @@ package com.weis.darklaf.util; -import com.bulenkov.iconloader.util.ColorUtil; -import com.bulenkov.iconloader.util.StringUtil; -import com.bulenkov.iconloader.util.SystemInfo; import com.weis.darklaf.DarkLaf; import com.weis.darklaf.icons.EmptyIcon; import com.weis.darklaf.icons.IconLoader; @@ -170,11 +167,8 @@ public final class LafUtil { private static final class LoadError { - private final String message; - @Contract(pure = true) private LoadError(final String message) { - this.message = message; } } diff --git a/src/main/java/com/weis/darklaf/util/StringUtil.java b/src/main/java/com/weis/darklaf/util/StringUtil.java index c92f860a..ec6b28e6 100644 --- a/src/main/java/com/weis/darklaf/util/StringUtil.java +++ b/src/main/java/com/weis/darklaf/util/StringUtil.java @@ -1,6 +1,11 @@ package com.weis.darklaf.util; import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; public final class StringUtil { @@ -53,4 +58,40 @@ public final class StringUtil { return a; } } + + public static List split(String s, String separator) { + return split(s, separator, true); + } + + public static List split(String s, String separator, boolean excludeSeparator) { + return split(s, separator, excludeSeparator, true); + } + + public static List split(String s, @NotNull String separator, boolean excludeSeparator, boolean excludeEmptyStrings) { + if (separator.isEmpty()) { + return Collections.singletonList(s); + } else { + List result = new ArrayList<>(); + int pos = 0; + + while(true) { + int index = s.indexOf(separator, pos); + if (index == -1) { + if (pos < s.length() || !excludeEmptyStrings && pos == s.length()) { + result.add(s.substring(pos, s.length())); + } + + return result; + } + + int nextPos = index + separator.length(); + String token = s.substring(pos, excludeSeparator ? index : nextPos); + if (!token.isEmpty() || !excludeEmptyStrings) { + result.add(token); + } + + pos = nextPos; + } + } + } } diff --git a/src/main/java/com/weis/darklaf/util/SystemInfo.java b/src/main/java/com/weis/darklaf/util/SystemInfo.java new file mode 100644 index 00000000..d0351032 --- /dev/null +++ b/src/main/java/com/weis/darklaf/util/SystemInfo.java @@ -0,0 +1,137 @@ +package com.weis.darklaf.util; + + +import org.jetbrains.annotations.Contract; + +/** + * @author Konstantin Bulenkov + */ +public class SystemInfo { + public static final String X86 = "32"; + public static final String X64 = "64"; + public static final String OS_NAME = System.getProperty("os.name"); + public static final String OS_VERSION = System.getProperty("os.version").toLowerCase(); + public static final String JAVA_VERSION = System.getProperty("java.version"); + public static final String JAVA_RUNTIME_VERSION = System.getProperty("java.runtime.version"); + protected static final String _OS_NAME; + public static final boolean isWindows; + public static final boolean isOS2; + public static final boolean isMac; + public static final boolean isLinux; + public static final boolean isUnix; + public static final boolean isFileSystemCaseSensitive; + public static final boolean isMacOSLion; + public static final boolean isAppleJvm; + public static final boolean isOracleJvm; + public static final boolean isSunJvm; + public static final String jreArchitecture = System.getProperty("sun.arch.data.model"); + public static final boolean isX86; + public static final boolean isX64; + public static final boolean isUndefined; + + @Contract(pure = true) + public SystemInfo() { + } + + public static boolean isOsVersionAtLeast(String version) { + return compareVersionNumbers(OS_VERSION, version) >= 0; + } + + private static boolean isTiger() { + return isMac && !OS_VERSION.startsWith("10.0") + && !OS_VERSION.startsWith("10.1") + && !OS_VERSION.startsWith("10.2") + && !OS_VERSION.startsWith("10.3"); + } + + private static boolean isLeopard() { + return isMac && isTiger() && !OS_VERSION.startsWith("10.4"); + } + + private static boolean isSnowLeopard() { + return isMac && isLeopard() && !OS_VERSION.startsWith("10.5"); + } + + private static boolean isLion() { + return isMac && isSnowLeopard() && !OS_VERSION.startsWith("10.6"); + } + + private static boolean isMountainLion() { + return isMac && isLion() && !OS_VERSION.startsWith("10.7"); + } + + public static int compareVersionNumbers(String v1, String v2) { + if (v1 == null && v2 == null) { + return 0; + } else if (v1 == null) { + return -1; + } else if (v2 == null) { + return 1; + } else { + String[] part1 = v1.split("[.\\_-]"); + String[] part2 = v2.split("[._\\-]"); + + int idx; + for(idx = 0; idx < part1.length && idx < part2.length; ++idx) { + String p1 = part1[idx]; + String p2 = part2[idx]; + int cmp; + if (p1.matches("\\d+") && p2.matches("\\d+")) { + cmp = (Integer.valueOf(p1)).compareTo(Integer.valueOf(p2)); + } else { + cmp = part1[idx].compareTo(part2[idx]); + } + + if (cmp != 0) { + return cmp; + } + } + + if (part1.length == part2.length) { + return 0; + } else { + return part1.length > idx ? 1 : -1; + } + } + } + + public static boolean isJavaVersionAtLeast(String v) { + return com.bulenkov.iconloader.util.StringUtil.compareVersionNumbers(JAVA_RUNTIME_VERSION, v) >= 0; + } + + private static boolean isOracleJvm() { + String vendor = getJavaVmVendor(); + return vendor != null && com.bulenkov.iconloader.util.StringUtil.containsIgnoreCase(vendor, "Oracle"); + } + + private static boolean isSunJvm() { + String vendor = getJavaVmVendor(); + return vendor != null && com.bulenkov.iconloader.util.StringUtil.containsIgnoreCase(vendor, "Sun") && com.bulenkov.iconloader.util.StringUtil.containsIgnoreCase(vendor, "Microsystems"); + } + + private static boolean isAppleJvm() { + String vendor = getJavaVmVendor(); + return vendor != null && com.bulenkov.iconloader.util.StringUtil.containsIgnoreCase(vendor, "Apple"); + } + + public static String getJavaVmVendor() { + return System.getProperty("java.vm.vendor"); + } + + static { + _OS_NAME = OS_NAME.toLowerCase(); + isWindows = _OS_NAME.startsWith("windows"); + isOS2 = _OS_NAME.startsWith("os/2") || _OS_NAME.startsWith("os2"); + isMac = _OS_NAME.startsWith("mac"); + isLinux = _OS_NAME.startsWith("linux"); + isUnix = !isWindows && !isOS2; + isFileSystemCaseSensitive = isUnix && !isMac; + isMacOSLion = isLion(); + isAppleJvm = isAppleJvm(); + isOracleJvm = isOracleJvm(); + isSunJvm = isSunJvm(); + isX64 = X64.equals(jreArchitecture); + isX86 = X86.equals(jreArchitecture); + isUndefined = !isX86 & !isX64; + } +} \ No newline at end of file