diff --git a/build.gradle b/build.gradle index 8e49762c..b391d15d 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,6 @@ repositories { dependencies { compile 'com.metsci.ext.com.kitfox.svg:svg-salamander:[0.1.19,)' - compile 'org.jetbrains:annotations:16.0.1' compile 'net.java.dev.jna:jna:4.1.0' compile 'org.swinglabs:jxlayer:3.0.4' compileOnly 'org.swinglabs:swingx:1.6.1' diff --git a/src/main/java/com/github/weisj/darklaf/DarkLaf.java b/src/main/java/com/github/weisj/darklaf/DarkLaf.java index 920df15d..bd123472 100644 --- a/src/main/java/com/github/weisj/darklaf/DarkLaf.java +++ b/src/main/java/com/github/weisj/darklaf/DarkLaf.java @@ -29,8 +29,6 @@ import com.github.weisj.darklaf.theme.Theme; import com.github.weisj.darklaf.ui.popupmenu.DarkPopupMenuUI; import com.github.weisj.darklaf.util.PropertyLoader; import com.github.weisj.darklaf.util.SystemInfo; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.awt.AppContext; import javax.swing.*; @@ -72,13 +70,13 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener final String name = UIManager.getSystemLookAndFeelClassName(); base = (BasicLookAndFeel) Class.forName(name).getDeclaredConstructor().newInstance(); } - } catch (@NotNull final Exception e) { + } catch (final Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e.getStackTrace()); throw new IllegalStateException("Could not load base LaF class." + e.getMessage()); } } - @Contract(pure = true) + public static boolean isDecorationsEnabled() { return LafManager.getTheme().useCustomDecorations() && decorationsEnabled; } @@ -113,7 +111,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener JDialog.setDefaultLookAndFeelDecorated(true); return defaults; - } catch (@NotNull final Exception e) { + } catch (final Exception e) { LOGGER.log(Level.SEVERE, e.toString(), e.getStackTrace()); } return super.getDefaults(); @@ -128,14 +126,14 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener } } - @NotNull + @Override public String getName() { return NAME; } @SuppressWarnings({"HardCodedStringLiteral"}) - private static void initInputMapDefaults(@NotNull final UIDefaults defaults) { + private static void initInputMapDefaults(final UIDefaults defaults) { // Make ENTER work in JTrees final InputMap treeInputMap = (InputMap) defaults.get("Tree.focusInputMap"); if (treeInputMap != null) { @@ -172,7 +170,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener } } - private void loadThemeDefaults(@NotNull final UIDefaults defaults) { + private void loadThemeDefaults(final UIDefaults defaults) { Properties uiProps = new Properties(); final Theme currentTheme = LafManager.getTheme(); currentTheme.loadDefaults(uiProps, defaults); @@ -189,7 +187,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener } @SuppressWarnings({"HardCodedStringLiteral"}) - private void initIdeaDefaults(@NotNull final UIDefaults defaults) { + private void initIdeaDefaults(final UIDefaults defaults) { defaults.put("Table.ancestorInputMap", new UIDefaults.LazyInputMap( new Object[]{ "ctrl C", "copy", @@ -244,20 +242,20 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener })); } - @NotNull + @Override public String getID() { return getName(); } - private static void patchComboBox(@NotNull final UIDefaults metalDefaults, @NotNull final UIDefaults defaults) { + private static void patchComboBox(final UIDefaults metalDefaults, final UIDefaults defaults) { defaults.remove("ComboBox.ancestorInputMap"); defaults.remove("ComboBox.actionMap"); defaults.put("ComboBox.ancestorInputMap", metalDefaults.get("ComboBox.ancestorInputMap")); defaults.put("ComboBox.actionMap", metalDefaults.get("ComboBox.actionMap")); } - private static void installCutCopyPasteShortcuts(@NotNull final InputMap inputMap, + private static void installCutCopyPasteShortcuts(final InputMap inputMap, final boolean useSimpleActionKeys) { final String copyActionKey = useSimpleActionKeys ? "copy" : DefaultEditorKit.copyAction; final String pasteActionKey = useSimpleActionKeys ? "paste" : DefaultEditorKit.pasteAction; @@ -272,7 +270,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_DOWN_MASK), DefaultEditorKit.cutAction); } - private void installGlobals(@NotNull final Properties uiProps, final UIDefaults defaults) { + private void installGlobals(final Properties uiProps, final UIDefaults defaults) { final HashMap globalSettings = new HashMap<>(); final String prefix = "global."; for (final Object key : uiProps.keySet()) { @@ -292,7 +290,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener } } - @NotNull + @Override public String getDescription() { return "Dark Look and feel based on Darcula-LAF"; @@ -341,7 +339,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener "loadSystemColors", UIDefaults.class, String[].class, boolean.class); superMethod.setAccessible(true); superMethod.invoke(base, defaults, systemColors, useNative); - } catch (@NotNull final Exception e) { + } catch (final Exception e) { LOGGER.log(Level.SEVERE, e.toString(), e.getStackTrace()); } } @@ -355,28 +353,28 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener return true; } - private void callInit(@NotNull final String method, final UIDefaults defaults) { + private void callInit(final String method, final UIDefaults defaults) { try { final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method, UIDefaults.class); superMethod.setAccessible(true); superMethod.invoke(base, defaults); - } catch (@NotNull final Exception e) { + } catch (final Exception e) { LOGGER.log(Level.SEVERE, e.toString(), e.getStackTrace()); } } - private void call(@NotNull final String method) { + private void call(final String method) { try { final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method); superMethod.setAccessible(true); superMethod.invoke(base); - } catch (@NotNull final Exception e) { + } catch (final Exception e) { LOGGER.log(Level.SEVERE, e.toString(), e.getStackTrace()); } } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { if ("lookAndFeel".equals(evt.getPropertyName())) { if (UIManager.getLookAndFeel() == this) { PropertyLoader.finish(); diff --git a/src/main/java/com/github/weisj/darklaf/LafManager.java b/src/main/java/com/github/weisj/darklaf/LafManager.java index b2e31174..5a3f0115 100644 --- a/src/main/java/com/github/weisj/darklaf/LafManager.java +++ b/src/main/java/com/github/weisj/darklaf/LafManager.java @@ -26,7 +26,6 @@ package com.github.weisj.darklaf; import com.github.weisj.darklaf.theme.DarculaTheme; import com.github.weisj.darklaf.theme.IntelliJTheme; import com.github.weisj.darklaf.theme.Theme; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -139,7 +138,7 @@ public final class LafManager { try { UIManager.setLookAndFeel(DarkLaf.class.getCanonicalName()); updateLaf(); - } catch (@NotNull final ClassNotFoundException + } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { @@ -156,7 +155,7 @@ public final class LafManager { } } - private static void updateLafRecursively(@NotNull final Window window) { + private static void updateLafRecursively(final Window window) { for (final Window childWindow : window.getOwnedWindows()) { updateLafRecursively(childWindow); } diff --git a/src/main/java/com/github/weisj/darklaf/color/DarkColorModel.java b/src/main/java/com/github/weisj/darklaf/color/DarkColorModel.java index 080b5186..2651ab17 100644 --- a/src/main/java/com/github/weisj/darklaf/color/DarkColorModel.java +++ b/src/main/java/com/github/weisj/darklaf/color/DarkColorModel.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.color; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; @@ -37,12 +34,12 @@ public class DarkColorModel { private final String prefix; private final String[] labels; - @Contract(pure = true) + public DarkColorModel() { this("rgb", "Red", "Green", "Blue"); } - @Contract(pure = true) + public DarkColorModel(final String name, final String... labels) { this.prefix = "ColorChooser." + name; this.labels = labels; @@ -64,7 +61,7 @@ public class DarkColorModel { return 0; } - public final String getText(@NotNull final Component component, final String suffix) { + public final String getText(final Component component, final String suffix) { return UIManager.getString(this.prefix + suffix + "Text", component.getLocale()); } @@ -85,11 +82,11 @@ public class DarkColorModel { return new char[]{Character.MIN_VALUE, Character.MIN_VALUE, Character.MIN_VALUE, Character.MIN_VALUE}; } - public int[] getValuesFromColor(@NotNull final Color color) { + public int[] getValuesFromColor(final Color color) { return new int[]{color.getRed(), color.getGreen(), color.getBlue()}; } - public Color getColorFromValues(@NotNull final int[] values) { + public Color getColorFromValues(final int[] values) { return new Color(values[0], values[1], values[2]); } } diff --git a/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java b/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java index e44ee49e..e8e5ee53 100644 --- a/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java +++ b/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.color; -import org.jetbrains.annotations.NotNull; - import java.awt.*; /** @@ -65,11 +63,11 @@ public class DarkColorModelCMYK extends DarkColorModel { } @Override - public int[] getValuesFromColor(@NotNull final Color color) { + public int[] getValuesFromColor(final Color color) { return RGBtoCMYK(color.getRed(), color.getGreen(), color.getBlue()); } - @NotNull + private static int[] RGBtoCMYK(final int r, final int g, final int b) { double max = DarkColorModelHSL.max(r / 255.0, g / 255.0, b / 255.0); if (max > 0.0f) { @@ -86,12 +84,12 @@ public class DarkColorModelCMYK extends DarkColorModel { } @Override - public Color getColorFromValues(@NotNull final int[] values) { + public Color getColorFromValues(final int[] values) { int[] rgb = CMYKtoRGB(values[0] / 100.0, values[1] / 100.0, values[2] / 100.0, values[3] / 100.0); return new Color(rgb[0], rgb[1], rgb[2]); } - @NotNull + private static int[] CMYKtoRGB(final double c, final double m, final double y, final double k) { rgb[0] = (int) Math.round(255 * (1.0f + c * k - k - c)); rgb[1] = (int) Math.round(255 * (1.0f + m * k - k - m)); diff --git a/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSB.java b/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSB.java index d15ba9e8..11e4dc88 100644 --- a/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSB.java +++ b/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSB.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.color; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import java.awt.*; /** @@ -61,12 +58,11 @@ public class DarkColorModelHSB extends DarkColorModel { } @Override - public int[] getValuesFromColor(@NotNull final Color color) { + public int[] getValuesFromColor(final Color color) { return RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue()); } - @Contract("_, _, _ -> new") - @NotNull + public static int[] RGBtoHSB(final int r, final int g, final int b) { double hue, saturation, brightness; int cmax = Math.max(r, g); @@ -105,7 +101,7 @@ public class DarkColorModelHSB extends DarkColorModel { } @Override - public Color getColorFromValues(@NotNull final int[] values) { + public Color getColorFromValues(final int[] values) { int[] rgb = HSBtoRGB(values[0] / 360.0, values[1] / 100.0, values[2] / 100.0); return new Color(rgb[0], rgb[1], rgb[2]); } diff --git a/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSL.java b/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSL.java index 8133a07e..f8483ab2 100644 --- a/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSL.java +++ b/src/main/java/com/github/weisj/darklaf/color/DarkColorModelHSL.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.color; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import java.awt.*; /** @@ -61,11 +58,11 @@ public class DarkColorModelHSL extends DarkColorModel { } @Override - public int[] getValuesFromColor(@NotNull final Color color) { + public int[] getValuesFromColor(final Color color) { return RGBtoHSL(color.getRed(), color.getGreen(), color.getBlue()); } - @NotNull + private static int[] RGBtoHSL(final int r, final int g, final int b) { double max = max(r, g, b) / 255.0; double min = min(r, g, b) / 255.0; @@ -83,7 +80,7 @@ public class DarkColorModelHSL extends DarkColorModel { return hsl; } - @Contract(pure = true) + protected static double max(final double red, final double green, final double blue) { double max = Math.max(red, green); return Math.max(max, blue); @@ -94,7 +91,7 @@ public class DarkColorModelHSL extends DarkColorModel { return Math.min(min, blue); } - @Contract(pure = true) + private static double getHue(final double red, final double green, final double blue, final double max, final double min) { double hue = max - min; @@ -115,12 +112,12 @@ public class DarkColorModelHSL extends DarkColorModel { } @Override - public Color getColorFromValues(@NotNull final int[] values) { + public Color getColorFromValues(final int[] values) { int[] rgb = HSLtoRGB(values[0] / 360.0, values[1] / 100.0, values[2] / 100.0); return new Color(rgb[0], rgb[1], rgb[2]); } - @NotNull + private static int[] HSLtoRGB(final double h, final double saturation, final double lightness) { double hue = h; @@ -139,7 +136,7 @@ public class DarkColorModelHSL extends DarkColorModel { return rgb; } - @Contract(pure = true) + private static double normalize(final double q, final double p, final double color) { if (color < 1.0f) { return p + (q - p) * color; diff --git a/src/main/java/com/github/weisj/darklaf/components/ArrowButton.java b/src/main/java/com/github/weisj/darklaf/components/ArrowButton.java index fc636f78..6e006c59 100644 --- a/src/main/java/com/github/weisj/darklaf/components/ArrowButton.java +++ b/src/main/java/com/github/weisj/darklaf/components/ArrowButton.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.components; import com.github.weisj.darklaf.icons.UIAwareIcon; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.DimensionUIResource; @@ -37,18 +35,18 @@ import java.awt.*; */ public final class ArrowButton implements SwingConstants { - @Contract(pure = true) + private ArrowButton() { } - @NotNull + public static JButton createUpDownArrow(final JComponent parent, final int orientation, final boolean center) { return createUpDownArrow(parent, orientation, center, false, new Insets(0, 0, 0, 0)); } - @NotNull + public static JButton createUpDownArrow(final JComponent parent, final int orientation, final boolean center, final boolean applyInsetsOnSize, final Insets insets) { @@ -66,8 +64,7 @@ public final class ArrowButton implements SwingConstants { return createUpDownArrow(parent, icon, icon.getDual(), orientation, center, applyInsetsOnSize, insets); } - @Contract("_, _, _, _, _, _, _ -> new") - @NotNull + public static JButton createUpDownArrow(final JComponent parent, final Icon activeIcon, final Icon inactiveIcon, final int orientation, final boolean center, @@ -103,14 +100,13 @@ public final class ArrowButton implements SwingConstants { getIcon().paintIcon(this, g, x, y); } - @NotNull + @Override public Insets getInsets() { return getInsets(new Insets(0, 0, 0, 0)); } - @NotNull - @Contract("_ -> param1") + @Override public Insets getInsets(final Insets i) { i.left = insets.left; @@ -120,7 +116,7 @@ public final class ArrowButton implements SwingConstants { return i; } - @Contract(pure = true) + @Override public boolean isOpaque() { return false; diff --git a/src/main/java/com/github/weisj/darklaf/components/ClosableTabbedPane.java b/src/main/java/com/github/weisj/darklaf/components/ClosableTabbedPane.java index 17f55b0d..948f6f4f 100644 --- a/src/main/java/com/github/weisj/darklaf/components/ClosableTabbedPane.java +++ b/src/main/java/com/github/weisj/darklaf/components/ClosableTabbedPane.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.components; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; import java.beans.PropertyVetoException; @@ -85,7 +83,7 @@ public class ClosableTabbedPane extends JTabbedPane { return false; } - private void notifyTabListeners(@NotNull final TabEvent event) { + private void notifyTabListeners(final TabEvent event) { TabListener[] listeners = listenerList.getListeners(TabListener.class); switch (event.getID()) { case TabEvent.TAB_CLOSED: diff --git a/src/main/java/com/github/weisj/darklaf/components/ColorPipetteBase.java b/src/main/java/com/github/weisj/darklaf/components/ColorPipetteBase.java index 92610636..77a23e68 100644 --- a/src/main/java/com/github/weisj/darklaf/components/ColorPipetteBase.java +++ b/src/main/java/com/github/weisj/darklaf/components/ColorPipetteBase.java @@ -28,8 +28,6 @@ package com.github.weisj.darklaf.components; import com.github.weisj.darklaf.ui.colorchooser.ColorListener; import com.github.weisj.darklaf.ui.colorchooser.ColorPipette; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.plaf.basic.BasicRootPaneUI; @@ -51,13 +49,13 @@ public abstract class ColorPipetteBase implements ColorPipette, AWTEventListener private Color currentColor; private Color initialColor; - public ColorPipetteBase(@NotNull final JComponent parent, @NotNull final ColorListener colorListener) { + public ColorPipetteBase(final JComponent parent, final ColorListener colorListener) { this.parent = parent; this.colorListener = colorListener; robot = createRobot(); } - @Nullable + private static Robot createRobot() { try { return new Robot(); @@ -78,28 +76,28 @@ public abstract class ColorPipetteBase implements ColorPipette, AWTEventListener this.closeAction = closeAction; } - protected Color getPixelColor(@NotNull final Point location) { + protected Color getPixelColor(final Point location) { return robot.getPixelColor(location.x, location.y); } - @Nullable + protected Color getInitialColor() { return initialColor; } @Override - public void setInitialColor(@Nullable final Color initialColor) { + public void setInitialColor(final Color initialColor) { this.initialColor = initialColor; setColor(initialColor); } - @Nullable + @Override public Color getColor() { return currentColor; } - protected void setColor(@Nullable final Color color) { + protected void setColor(final Color color) { currentColor = color; } @@ -140,7 +138,7 @@ public abstract class ColorPipetteBase implements ColorPipette, AWTEventListener Toolkit.getDefaultToolkit().removeAWTEventListener(this); } - @NotNull + protected Window getOrCreatePickerWindow() { if (pickerWindow == null) { Window owner = SwingUtilities.getWindowAncestor(parent); @@ -152,7 +150,7 @@ public abstract class ColorPipetteBase implements ColorPipette, AWTEventListener return pickerWindow; } - @Nullable + protected Point updateLocation() { PointerInfo pointerInfo = MouseInfo.getPointerInfo(); if (pointerInfo == null) return null; @@ -169,18 +167,18 @@ public abstract class ColorPipetteBase implements ColorPipette, AWTEventListener return new PickerWindow(parent); } - @Nullable + protected Window getPickerWindow() { return pickerWindow; } - protected Point adjustPickerLocation(@NotNull final Point mouseLocation, @NotNull final Window pickerWindow) { + protected Point adjustPickerLocation(final Point mouseLocation, final Window pickerWindow) { return new Point(mouseLocation.x - pickerWindow.getWidth() / 2, mouseLocation.y - pickerWindow.getHeight() / 2); } @Override - public void eventDispatched(@NotNull final AWTEvent event) { + public void eventDispatched(final AWTEvent event) { if (pickerWindow == null || !pickerWindow.isVisible()) return; switch (event.getID()) { case MouseEvent.MOUSE_PRESSED: @@ -221,7 +219,7 @@ public abstract class ColorPipetteBase implements ColorPipette, AWTEventListener protected abstract void updatePipette(final boolean force); - protected void notifyListener(@NotNull final Color c) { + protected void notifyListener(final Color c) { colorListener.colorChanged(c, this); } diff --git a/src/main/java/com/github/weisj/darklaf/components/DefaultColorPipette.java b/src/main/java/com/github/weisj/darklaf/components/DefaultColorPipette.java index ffe0f132..b0b160e8 100644 --- a/src/main/java/com/github/weisj/darklaf/components/DefaultColorPipette.java +++ b/src/main/java/com/github/weisj/darklaf/components/DefaultColorPipette.java @@ -27,7 +27,6 @@ import com.github.weisj.darklaf.ui.colorchooser.ColorListener; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; import com.github.weisj.darklaf.util.TimerUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -52,7 +51,7 @@ public class DefaultColorPipette extends ColorPipetteBase { private Graphics2D zoomGraphics; private BufferedImage zoomImage; - public DefaultColorPipette(@NotNull final JComponent parent, @NotNull final ColorListener colorListener) { + public DefaultColorPipette(final JComponent parent, final ColorListener colorListener) { super(parent, colorListener); timer = TimerUtil.createNamedTimer("DefaultColorPipette", 5, e -> updatePipette()); borderColor = UIManager.getColor("ColorChooser.pipetteBorderColor"); @@ -63,7 +62,7 @@ public class DefaultColorPipette extends ColorPipetteBase { } @Override - protected Color getPixelColor(@NotNull final Point location) { + protected Color getPixelColor(final Point location) { return super.getPixelColor(getHotSPot(location)); } @@ -81,7 +80,7 @@ public class DefaultColorPipette extends ColorPipetteBase { } @Override - @NotNull + protected Window getOrCreatePickerWindow() { Window pickerWindow = getPickerWindow(); if (pickerWindow == null) { @@ -122,7 +121,7 @@ public class DefaultColorPipette extends ColorPipetteBase { } @Override - protected Point adjustPickerLocation(@NotNull final Point mouseLocation, @NotNull final Window pickerWindow) { + protected Point adjustPickerLocation(final Point mouseLocation, final Window pickerWindow) { Point p = super.adjustPickerLocation(mouseLocation, pickerWindow); p.x += DIALOG_SIZE / 2 - MOUSE_OFF_X; p.y -= DIALOG_SIZE / 2 + MOUSE_OFF_Y; @@ -164,7 +163,7 @@ public class DefaultColorPipette extends ColorPipetteBase { zoomImage = null; } - protected Point getHotSPot(@NotNull final Point location) { + protected Point getHotSPot(final Point location) { location.x -= MOUSE_OFF_X - 2; location.y -= MOUSE_OFF_Y + 2; return location; diff --git a/src/main/java/com/github/weisj/darklaf/components/OverlayScrollPane.java b/src/main/java/com/github/weisj/darklaf/components/OverlayScrollPane.java index f4f03a90..5851860a 100644 --- a/src/main/java/com/github/weisj/darklaf/components/OverlayScrollPane.java +++ b/src/main/java/com/github/weisj/darklaf/components/OverlayScrollPane.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.components; import com.github.weisj.darklaf.ui.scrollpane.ScrollLayoutManagerDelegate; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ScrollPaneUI; @@ -91,7 +89,7 @@ public class OverlayScrollPane extends JLayeredPane { * * @return the scrollPane */ - @NotNull + public JScrollPane getScrollPane() { return scrollPane; } @@ -113,8 +111,7 @@ public class OverlayScrollPane extends JLayeredPane { controlPanel.showHorizontalScrollBar(policy != JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); } - @Contract(pure = true) - @NotNull + public JScrollBar getVerticalScrollBar() { return scrollPane.verticalScrollBar; } @@ -124,8 +121,7 @@ public class OverlayScrollPane extends JLayeredPane { return scrollPane.getPreferredSize(); } - @Contract(pure = true) - @NotNull + public JScrollBar getHorizontalScrollBar() { return scrollPane.horizontalScrollBar; } @@ -145,7 +141,7 @@ public class OverlayScrollPane extends JLayeredPane { setOpaque(false); } - @Contract(pure = true) + @Override public boolean isOpaque() { return false; @@ -259,7 +255,7 @@ public class OverlayScrollPane extends JLayeredPane { private boolean showVertical; private boolean showHorizontal; - private ControlPanel(@NotNull final OScrollPane scrollPane) { + private ControlPanel(final OScrollPane scrollPane) { setLayout(null); scrollPane.setVerticalScrollBar(scrollPane.verticalScrollBar); @@ -301,7 +297,7 @@ public class OverlayScrollPane extends JLayeredPane { && scrollPane.verticalScrollBar.getBounds().contains(x, y); } - @Contract(pure = true) + @Override public boolean isOpaque() { return false; diff --git a/src/main/java/com/github/weisj/darklaf/components/ScrollPopupMenu.java b/src/main/java/com/github/weisj/darklaf/components/ScrollPopupMenu.java index 89427e85..831b8571 100644 --- a/src/main/java/com/github/weisj/darklaf/components/ScrollPopupMenu.java +++ b/src/main/java/com/github/weisj/darklaf/components/ScrollPopupMenu.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.components; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.MenuKeyEvent; @@ -79,7 +77,7 @@ public class ScrollPopupMenu extends JPopupMenu { addMenuKeyListener(menuKeyListener); } - @NotNull + private OverlayScrollPane createScrollPane() { view = new JPanel(new BorderLayout()); view.add(this, BorderLayout.CENTER); @@ -106,7 +104,7 @@ public class ScrollPopupMenu extends JPopupMenu { } @Override - public JMenuItem add(@NotNull final JMenuItem menuItem) { + public JMenuItem add(final JMenuItem menuItem) { menuItem.getModel().addChangeListener(e -> contentPane.repaint(menuItem.getBounds())); return super.add(menuItem); } @@ -133,7 +131,7 @@ public class ScrollPopupMenu extends JPopupMenu { * * @return scroll pane; */ - @Nullable + public JScrollPane getScrollPane() { return scrollPane; } diff --git a/src/main/java/com/github/weisj/darklaf/components/alignment/Alignment.java b/src/main/java/com/github/weisj/darklaf/components/alignment/Alignment.java index c48f77b2..e18e6eb5 100644 --- a/src/main/java/com/github/weisj/darklaf/components/alignment/Alignment.java +++ b/src/main/java/com/github/weisj/darklaf/components/alignment/Alignment.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.components.alignment; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import java.awt.*; import java.util.function.BiFunction; @@ -67,7 +64,7 @@ public enum Alignment { private final BiFunction alignInside; private final BiFunction alignOutside; - @Contract(pure = true) + Alignment(final BiFunction alignInside, final BiFunction alignOutside) { this.alignInside = alignInside; @@ -83,11 +80,11 @@ public enum Alignment { * @param hint preferred alignment. * @return fitting alignment. If none is found the default is {@link Alignment#CENTER}. */ - @NotNull - public static Alignment getAlignment(@NotNull final Point point, - @NotNull final Dimension size, - @NotNull final Rectangle outerBounds, - @NotNull final Alignment hint) { + + public static Alignment getAlignment(final Point point, + final Dimension size, + final Rectangle outerBounds, + final Alignment hint) { if (hint.canBeAligned(point, size, outerBounds)) { return hint; } @@ -108,9 +105,9 @@ public enum Alignment { * @param outerBounds boundaries. * @return true if can be aligned. */ - public boolean canBeAligned(@NotNull final Point point, - @NotNull final Dimension size, - @NotNull final Rectangle outerBounds) { + public boolean canBeAligned(final Point point, + final Dimension size, + final Rectangle outerBounds) { Point p = relativePos(size, point); return p.x >= outerBounds.x && p.y >= outerBounds.y && p.x + size.width < outerBounds.x + outerBounds.width @@ -124,7 +121,7 @@ public enum Alignment { * @param alignAt point to align at. * @return top/left position of aligned rectangle */ - public Point relativePos(@NotNull final Dimension toAlign, @NotNull final Point alignAt) { + public Point relativePos(final Dimension toAlign, final Point alignAt) { return alignOutside(toAlign, new Rectangle(alignAt.x, alignAt.y, 0, 0)); } @@ -135,8 +132,8 @@ public enum Alignment { * @param innerBounds bounds of inside rectangle * @return top/left point of aligned rectangle */ - public Point alignOutside(@NotNull final Dimension toAlign, - @NotNull final Rectangle innerBounds) { + public Point alignOutside(final Dimension toAlign, + final Rectangle innerBounds) { return this.alignOutside.apply(toAlign, innerBounds); } @@ -146,7 +143,7 @@ public enum Alignment { * * @return the index. */ - @Contract(pure = true) + public int getIndex() { return this.ordinal(); } @@ -156,8 +153,8 @@ public enum Alignment { * * @return Alignment opposite on the compass. */ - @Contract(pure = true) - @NotNull + + @SuppressWarnings("Duplicates") public Alignment opposite() { switch (this) { @@ -184,8 +181,7 @@ public enum Alignment { } } - @NotNull - @Contract(pure = true) + @SuppressWarnings("Duplicates") public Alignment anticlockwise() { switch (this) { @@ -212,8 +208,7 @@ public enum Alignment { } } - @NotNull - @Contract(pure = true) + @SuppressWarnings("Duplicates") public Alignment clockwise() { switch (this) { @@ -240,9 +235,8 @@ public enum Alignment { } } - @NotNull - @Contract(pure = true) - public Insets maskInsets(@NotNull final Insets insets) { + + public Insets maskInsets(final Insets insets) { switch (this) { case NORTH: return new Insets(insets.top, 0, 0, 0); @@ -274,8 +268,8 @@ public enum Alignment { * @param outerBounds bounds of outer rectangle * @return top/left point of aligned rectangle */ - public Point alignInside(@NotNull final Dimension toAlign, - @NotNull final Rectangle outerBounds) { + public Point alignInside(final Dimension toAlign, + final Rectangle outerBounds) { return this.alignInside.apply(toAlign, outerBounds); } } diff --git a/src/main/java/com/github/weisj/darklaf/components/alignment/AlignmentHelper.java b/src/main/java/com/github/weisj/darklaf/components/alignment/AlignmentHelper.java index 61d30dc3..38629a09 100644 --- a/src/main/java/com/github/weisj/darklaf/components/alignment/AlignmentHelper.java +++ b/src/main/java/com/github/weisj/darklaf/components/alignment/AlignmentHelper.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.components.alignment; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import java.awt.*; import java.util.function.BiFunction; @@ -58,10 +55,10 @@ final class AlignmentHelper { * @param mapperY y component mapper. * @return mapper that aligns a rectangle relative to other rectangle. */ - @NotNull - @Contract(pure = true) - static BiFunction align(@NotNull final Mapper mapperX, - @NotNull final Mapper mapperY) { + + + static BiFunction align(final Mapper mapperX, + final Mapper mapperY) { return (d, p) -> new Point(mapperX.apply(d, p), mapperY.apply(d, p)); } diff --git a/src/main/java/com/github/weisj/darklaf/components/border/BubbleBorder.java b/src/main/java/com/github/weisj/darklaf/components/border/BubbleBorder.java index e239268d..3d576281 100644 --- a/src/main/java/com/github/weisj/darklaf/components/border/BubbleBorder.java +++ b/src/main/java/com/github/weisj/darklaf/components/border/BubbleBorder.java @@ -26,8 +26,6 @@ package com.github.weisj.darklaf.components.border; import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.border.AbstractBorder; import java.awt.*; @@ -95,7 +93,7 @@ public class BubbleBorder extends AbstractBorder { * @param color border colour * @return this */ - @NotNull + public BubbleBorder setColor(final Color color) { this.color = color; return this; @@ -137,7 +135,7 @@ public class BubbleBorder extends AbstractBorder { * @param n new thickness * @return this */ - @NotNull + public BubbleBorder setThickness(final int n) { thickness = Math.max(n, 0); stroke = new BasicStroke(thickness); @@ -153,34 +151,13 @@ public class BubbleBorder extends AbstractBorder { return radius; } - /** - * Set the corner radius. - * - * @param radius radius of corner. - * @return this - */ - @NotNull - public BubbleBorder setRadius(final int radius) { - this.radius = radius; - return setPointerSize(pointerSize); - } - - /** - * Get the pointer size. - * - * @return size of pointer. - */ - public int getPointerSize() { - return pointerSize; - } - /** * Set the pointer size Clips at 0. * * @param size size of pointer. * @return this */ - @NotNull + public BubbleBorder setPointerSize(final int size) { pointerSize = Math.max(size, 0); int left = thickness; @@ -212,6 +189,27 @@ public class BubbleBorder extends AbstractBorder { return this; } + /** + * Get the pointer size. + * + * @return size of pointer. + */ + public int getPointerSize() { + return pointerSize; + } + + /** + * Set the corner radius. + * + * @param radius radius of corner. + * @return this + */ + + public BubbleBorder setRadius(final int radius) { + this.radius = radius; + return setPointerSize(pointerSize); + } + /** * Get the Alignment the pointer follows. Default is {@link Alignment#NORTH} * @@ -229,7 +227,7 @@ public class BubbleBorder extends AbstractBorder { * @param side direction in which the pointer should point. * @return this. */ - @NotNull + public BubbleBorder setPointerSide(final Alignment side) { this.pointerSide = side; setPointerSize(pointerSize); @@ -240,7 +238,7 @@ public class BubbleBorder extends AbstractBorder { return (int) calculatePointerPad(w, h, Alignment.NORTH_WEST); } - @Contract(pure = true) + private double calculatePointerPad(final int width, final int height, final Alignment side) { double pointerPad; switch (side) { @@ -268,19 +266,19 @@ public class BubbleBorder extends AbstractBorder { } @Override - public void paintBorder(@NotNull final Component c, final Graphics g, + public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { Area area = getInnerArea(x, y, width, height); paintBorder(g, area); } - @NotNull + @Override public Insets getBorderInsets(final Component c) { return new Insets(insets.top, insets.left, insets.bottom, insets.right); } - @NotNull + @Override public Insets getBorderInsets(final Component c, final Insets insets) { return getBorderInsets(c); @@ -306,15 +304,15 @@ public class BubbleBorder extends AbstractBorder { config.restore(); } - @Contract("_, _, _, _ -> new") + public RoundRectangle2D.Double calculateBubbleRect(final int x, final int y, final int width, final int height) { return new RoundRectangle2D.Double(x + insets.left, y + insets.top, width - insets.left - insets.right, height - insets.top - insets.bottom, radius, radius); } - @NotNull - private Path2D creatPointerShape(final double pointerPad, @NotNull final RoundRectangle2D.Double bubble) { + + private Path2D creatPointerShape(final double pointerPad, final RoundRectangle2D.Double bubble) { final double w = pointerWidth / 2.0; final Path2D pointer = new Path2D.Double(Path2D.WIND_EVEN_ODD); double x = bubble.x; diff --git a/src/main/java/com/github/weisj/darklaf/components/border/DarkBorders.java b/src/main/java/com/github/weisj/darklaf/components/border/DarkBorders.java index 1178daeb..4c7602ad 100644 --- a/src/main/java/com/github/weisj/darklaf/components/border/DarkBorders.java +++ b/src/main/java/com/github/weisj/darklaf/components/border/DarkBorders.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.components.border; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.border.Border; import java.util.Map; @@ -36,14 +34,14 @@ public final class DarkBorders { private static Map lineBorderMap = new WeakHashMap<>(); private static Map lineWidgetBorderMap = new WeakHashMap<>(); - @NotNull + public static Border createLineBorder(final int top, final int left, final int bottom, final int right) { return createBorder(top, left, bottom, right, lineBorderMap, "border"); } - @NotNull + private static Border createBorder(final int top, final int left, final int bottom, final int right, - @NotNull final Map map, final String key) { + final Map map, final String key) { WeakLineBorder border = null; KEY.setInsets(top, left, bottom, right); if (map.containsKey(KEY)) { @@ -57,7 +55,7 @@ public final class DarkBorders { return border; } - @NotNull + public static Border createWidgetLineBorder(final int top, final int left, final int bottom, final int right) { return createBorder(top, left, bottom, right, lineWidgetBorderMap, "borderSecondary"); } diff --git a/src/main/java/com/github/weisj/darklaf/components/border/DropShadowBorder.java b/src/main/java/com/github/weisj/darklaf/components/border/DropShadowBorder.java index 9f33dda9..7d3c36bd 100644 --- a/src/main/java/com/github/weisj/darklaf/components/border/DropShadowBorder.java +++ b/src/main/java/com/github/weisj/darklaf/components/border/DropShadowBorder.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.components.border; import com.github.weisj.darklaf.util.ImageUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.border.Border; import java.awt.*; @@ -65,18 +63,18 @@ public class DropShadowBorder implements Border, Serializable { private boolean showBottomShadow; private boolean showRightShadow; - @Contract(pure = true) + public DropShadowBorder() { this(Color.BLACK, 5); } - @Contract(pure = true) + public DropShadowBorder(final Color shadowColor, final int shadowSize) { this(shadowColor, shadowSize, .5f, 12, false, true, true, true); } - @Contract(pure = true) + public DropShadowBorder(final Color shadowColor, final int shadowSize, final float shadowOpacity, final int cornerSize, final boolean showTopShadow, final boolean showLeftShadow, final boolean showBottomShadow, final boolean showRightShadow) { @@ -90,7 +88,7 @@ public class DropShadowBorder implements Border, Serializable { this.showRightShadow = showRightShadow; } - @Contract(pure = true) + public DropShadowBorder(final boolean showLeftShadow) { this(Color.BLACK, 5, .5f, 12, false, showLeftShadow, true, true); @@ -99,7 +97,7 @@ public class DropShadowBorder implements Border, Serializable { /** * {@inheritDoc} */ - public void paintBorder(final Component c, @NotNull final Graphics graphics, + public void paintBorder(final Component c, final Graphics graphics, final int x, final int y, final int width, final int height) { /* * 1) Get images for this border @@ -235,7 +233,7 @@ public class DropShadowBorder implements Border, Serializable { } @SuppressWarnings("SuspiciousNameCombination") - @NotNull + private Map getImages(final 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 @@ -337,7 +335,7 @@ public class DropShadowBorder implements Border, Serializable { * Returns a new BufferedImage that represents a subregion of the given BufferedImage. (Note that this method does * not use BufferedImage.getSubimage(), which will defeat image acceleration strategies on later JDKs.) */ - @NotNull + private BufferedImage getSubImage(final BufferedImage img, final int x, final int y, final int w, final int h) { BufferedImage ret = ImageUtil.createCompatibleTranslucentImage(w, h); Graphics2D g2 = ret.createGraphics(); diff --git a/src/main/java/com/github/weisj/darklaf/components/border/MutableLineBorder.java b/src/main/java/com/github/weisj/darklaf/components/border/MutableLineBorder.java index 81bb7bca..fe7fd2fa 100644 --- a/src/main/java/com/github/weisj/darklaf/components/border/MutableLineBorder.java +++ b/src/main/java/com/github/weisj/darklaf/components/border/MutableLineBorder.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.components.border; -import org.jetbrains.annotations.NotNull; - import javax.swing.border.EmptyBorder; import java.awt.*; @@ -42,7 +40,7 @@ public class MutableLineBorder extends EmptyBorder { } @Override - public void paintBorder(final Component c, @NotNull final Graphics g, final int x, final int y, + public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { g.setColor(getColor()); g.fillRect(x, y, width - right, top); diff --git a/src/main/java/com/github/weisj/darklaf/components/border/WeakLineBorder.java b/src/main/java/com/github/weisj/darklaf/components/border/WeakLineBorder.java index d7a7f5f2..5c5221f6 100644 --- a/src/main/java/com/github/weisj/darklaf/components/border/WeakLineBorder.java +++ b/src/main/java/com/github/weisj/darklaf/components/border/WeakLineBorder.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.components.border; -import org.jetbrains.annotations.Contract; - class WeakLineBorder extends MutableLineBorder { private int left; @@ -49,7 +47,7 @@ class WeakLineBorder extends MutableLineBorder { return result; } - @Contract(value = "null -> false", pure = true) + @Override public boolean equals(final Object o) { if (this == o) return true; diff --git a/src/main/java/com/github/weisj/darklaf/components/tabframe/JTabFrame.java b/src/main/java/com/github/weisj/darklaf/components/tabframe/JTabFrame.java index 3afe2016..7f6b3951 100644 --- a/src/main/java/com/github/weisj/darklaf/components/tabframe/JTabFrame.java +++ b/src/main/java/com/github/weisj/darklaf/components/tabframe/JTabFrame.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.components.tabframe; import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.ui.tabframe.TabFrameTransferHandler; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -170,13 +168,15 @@ public class JTabFrame extends JComponent { } /** - * Get a list of tab components at the given alignment position. + * Insert a tab. A default tab component and popup component will be created. * - * @param a the alignment position. - * @return list of tab components at position. + * @param c the component to add. + * @param a the alignment position to add at.{@link TabFramePosition#getAlignment()} + * @param index the index to insert at.{@link TabFramePosition#getIndex()} */ - public List tabsForAlignment(@NotNull final Alignment a) { - return tabLists[a.ordinal()]; + public void insertTab(final Component c, final Alignment a, final int index) { + String title = c.getName(); + insertTab(c, title == null ? "" : title, a, index); } /** @@ -242,18 +242,6 @@ public class JTabFrame extends JComponent { return new TabFrameContentPane(); } - /** - * Insert a tab. A default tab component and popup component will be created. - * - * @param c the component to add. - * @param a the alignment position to add at.{@link TabFramePosition#getAlignment()} - * @param index the index to insert at.{@link TabFramePosition#getIndex()} - */ - public void insertTab(@NotNull final Component c, final Alignment a, final int index) { - String title = c.getName(); - insertTab(c, title == null ? "" : title, a, index); - } - /** * Insert a tab. A default tab component and popup component will be created. * @@ -262,7 +250,7 @@ public class JTabFrame extends JComponent { * @param a the alignment position to add at.{@link TabFramePosition#getAlignment()} * @param index the index to insert at.{@link TabFramePosition#getIndex()} */ - public void insertTab(@NotNull final Component c, final String title, final Alignment a, final int index) { + public void insertTab(final Component c, final String title, final Alignment a, final int index) { insertTab(c, title, null, a, index); } @@ -275,7 +263,7 @@ public class JTabFrame extends JComponent { * @param a the alignment position to add at.{@link TabFramePosition#getAlignment()} * @param index the index to insert at.{@link TabFramePosition#getIndex()} */ - public void insertTab(@NotNull final Component c, final String title, final Icon icon, final Alignment a, + public void insertTab(final Component c, final String title, final Icon icon, final Alignment a, final int index) { TabFramePopup popup = new PanelPopup(title, icon, c); insertTab(popup, title, icon, a, index); @@ -290,7 +278,7 @@ public class JTabFrame extends JComponent { * @param a the alignment position to add at.{@link TabFramePosition#getAlignment()} * @param index the index to insert at.{@link TabFramePosition#getIndex()} */ - public void insertTab(@NotNull final TabFramePopup c, final String title, final Icon icon, final Alignment a, + public void insertTab(final TabFramePopup c, final String title, final Icon icon, final Alignment a, final int index) { if (a == Alignment.CENTER) { return; @@ -306,7 +294,7 @@ public class JTabFrame extends JComponent { * @param a the alignment position to add at.{@link TabFramePosition#getAlignment()} * @param index the index to insert at.{@link TabFramePosition#getIndex()} */ - public void insertTab(@NotNull final TabFramePopup c, final TabFrameTab tab, final Alignment a, final int index) { + public void insertTab(final TabFramePopup c, final TabFrameTab tab, final Alignment a, final int index) { if (a == Alignment.CENTER) { return; } @@ -318,14 +306,10 @@ public class JTabFrame extends JComponent { c.setIndex(index); } - protected TabFrameTab createDefaultTab(final String text, final Icon icon, final Alignment a, final int index) { - return new TabFrameTabLabel(text, icon, a, index, this); - } - /* * Inserts a tab component at the given position. */ - private void insertTabComp(@NotNull final TabFrameTab tabComp, final Alignment a, final int index) { + private void insertTabComp(final TabFrameTab tabComp, final Alignment a, final int index) { tabComp.setOrientation(a); getTabContainer(a).add(tabComp.getComponent()); List tabs = tabsForAlignment(a); @@ -340,13 +324,17 @@ public class JTabFrame extends JComponent { tabs.add(index, tabComp); } + protected TabFrameTab createDefaultTab(final String text, final Icon icon, final Alignment a, final int index) { + return new TabFrameTabLabel(text, icon, a, index, this); + } + /** * Get a list of components at the given alignment position. * * @param a the alignment position. * @return list of components at position. */ - public List compsForAlignment(@NotNull final Alignment a) { + public List compsForAlignment(final Alignment a) { return popupLists[a.ordinal()]; } @@ -356,8 +344,8 @@ public class JTabFrame extends JComponent { * @param a the alignment position.{@link TabFramePosition#getAlignment()} * @return the tab container. */ - @Contract(pure = true) - public JComponent getTabContainer(@NotNull final Alignment a) { + + public JComponent getTabContainer(final Alignment a) { switch (a) { case NORTH: case NORTH_EAST: @@ -378,6 +366,16 @@ public class JTabFrame extends JComponent { } } + /** + * Get a list of tab components at the given alignment position. + * + * @param a the alignment position. + * @return list of tab components at position. + */ + public List tabsForAlignment(final Alignment a) { + return tabLists[a.ordinal()]; + } + /** * Get the container that holds the top tab components. * @@ -461,7 +459,7 @@ public class JTabFrame extends JComponent { /* * Set the tab component at the given position. */ - private void setTabComponent(@NotNull final TabFrameTab tab, final Alignment a, final int index) { + private void setTabComponent(final TabFrameTab tab, final Alignment a, final int index) { List tabs = tabsForAlignment(a); TabFrameTab oldComp = tabs.get(index); getTabContainer(a).remove(oldComp.getComponent()); @@ -528,7 +526,7 @@ public class JTabFrame extends JComponent { * @param index the index.{@link TabFramePosition#getIndex()} * @param enabled true if visible. */ - public void toggleTab(@NotNull final Alignment a, final int index, final boolean enabled) { + public void toggleTab(final Alignment a, final int index, final boolean enabled) { int oldIndex = selectedIndices[a.getIndex()]; if (content.isEnabled(a) == enabled && oldIndex == index) return; TabFrameTab compAtIndex = getTabComponentAt(a, index); @@ -565,7 +563,7 @@ public class JTabFrame extends JComponent { /* * Set the visibility of the popup. */ - private void setPopupVisibility(@NotNull final TabFrameTab tabComponent, + private void setPopupVisibility(final TabFrameTab tabComponent, final boolean selected) { Alignment a = tabComponent.getOrientation(); TabFramePopup c = compsForAlignment(a).get(tabComponent.getIndex()); @@ -669,7 +667,7 @@ public class JTabFrame extends JComponent { * @param tabComp the tab to move. * @param a the new alignment position.{@link TabFramePosition#getAlignment()} */ - public void moveTab(@NotNull final TabFrameTab tabComp, final Alignment a) { + public void moveTab(final TabFrameTab tabComp, final Alignment a) { if (a == tabComp.getOrientation()) { return; } @@ -823,7 +821,7 @@ public class JTabFrame extends JComponent { * @param a the alignment position.{@link TabFramePosition#getAlignment()} * @return the peer position.{@link TabFramePosition#getAlignment()} */ - public Alignment getPeer(@NotNull final Alignment a) { + public Alignment getPeer(final Alignment a) { switch (a) { case NORTH: case SOUTH: @@ -889,7 +887,7 @@ public class JTabFrame extends JComponent { * @param a the alignment position.{@link TabFramePosition#getAlignment()} * @return the current selected index at the alignment position. */ - public int getSelectedIndex(@NotNull final Alignment a) { + public int getSelectedIndex(final Alignment a) { return selectedIndices[a.ordinal()]; } @@ -954,7 +952,7 @@ public class JTabFrame extends JComponent { private Alignment a; private int index; - @Contract(pure = true) + public TabFramePosition(final Alignment a, final int index) { this.a = a; this.index = index; diff --git a/src/main/java/com/github/weisj/darklaf/components/tabframe/PanelPopup.java b/src/main/java/com/github/weisj/darklaf/components/tabframe/PanelPopup.java index f69bc803..7feef01c 100644 --- a/src/main/java/com/github/weisj/darklaf/components/tabframe/PanelPopup.java +++ b/src/main/java/com/github/weisj/darklaf/components/tabframe/PanelPopup.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.components.tabframe; import com.github.weisj.darklaf.components.alignment.Alignment; -import org.jetbrains.annotations.Contract; import javax.swing.*; import java.awt.*; @@ -132,7 +131,7 @@ public class PanelPopup extends JPanel implements TabFramePopup { } } - @Contract(pure = true) + private boolean isOpen() { return open; } diff --git a/src/main/java/com/github/weisj/darklaf/components/tabframe/TabArea.java b/src/main/java/com/github/weisj/darklaf/components/tabframe/TabArea.java index dac68118..c5cb1ba4 100644 --- a/src/main/java/com/github/weisj/darklaf/components/tabframe/TabArea.java +++ b/src/main/java/com/github/weisj/darklaf/components/tabframe/TabArea.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.components.tabframe; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; @@ -36,7 +34,7 @@ public final class TabArea extends JPanel { } @Override - public void paint(@NotNull final Graphics g) { + public void paint(final Graphics g) { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); paintChildren(g); diff --git a/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContentPane.java b/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContentPane.java index 9e693c41..ace286e1 100644 --- a/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContentPane.java +++ b/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameContentPane.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.components.tabframe; import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.decorators.AncestorAdapter; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.AncestorEvent; @@ -137,15 +135,15 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { return new TabFrameSplitPane(name); } - protected void setupSplitterPanes(@NotNull final BiConsumer consumer, - final T flag) { + protected void setupSplitterPanes(final BiConsumer consumer, + final T flag) { consumer.accept(bottomSplitter, flag); consumer.accept(leftSplitter, flag); consumer.accept(rightSplitter, flag); consumer.accept(topSplitter, flag); } - protected void setupSplitPanes(@NotNull final BiConsumer consumer, + protected void setupSplitPanes(final BiConsumer consumer, final T flag) { consumer.accept(topSplit, flag); consumer.accept(leftSplit, flag); @@ -169,6 +167,16 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { } } + /** + * Show or hide the corresponding panel. + * + * @param a position of panel. + * @param enabled true if should be shown. + */ + public void setEnabled(final Alignment a, final boolean enabled) { + setEnabled(a, enabled, false); + } + /** * Show or hide the corresponding panel. * @@ -176,7 +184,7 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { * @param enabled true if should be shown. * @param force whether to force the layout process. */ - public void setEnabled(@NotNull final Alignment a, final boolean enabled, final boolean force) { + public void setEnabled(final Alignment a, final boolean enabled, final boolean force) { if (enabled == isEnabled(a) && !force) return; switch (a) { case NORTH: @@ -251,11 +259,11 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { * @param proportions the layout proportions * @param weights the layout weights */ - private void changeStatus(final boolean enabled, @NotNull final Alignment peer, - @NotNull final ToggleSplitPane split, - @NotNull final ToggleSplitPane splitter, - @NotNull final LayoutProportions proportions, - @NotNull final LayoutWeights weights) { + private void changeStatus(final boolean enabled, final Alignment peer, + final ToggleSplitPane split, + final ToggleSplitPane splitter, + final LayoutProportions proportions, + final LayoutWeights weights) { if (enabled) { enable(split, weights.splitEnable); if (!isEnabled(peer)) { @@ -274,13 +282,13 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { /* * Update the flags. */ - private void setEnabledFlag(@NotNull final Alignment a, final boolean e) { + private void setEnabledFlag(final Alignment a, final boolean e) { if (a != Alignment.CENTER) { enabled[a.getIndex()] = e; } } - private void enable(@NotNull final ToggleSplitPane splitPane, final double weight) { + private void enable(final ToggleSplitPane splitPane, final double weight) { boolean restore = !splitPane.isResizable(); splitPane.setEnabled(true); splitPane.setResizable(true); @@ -290,16 +298,6 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { } } - private void disable(@NotNull final ToggleSplitPane splitPane, final double weight, final double location) { - if (splitPane.isResizable()) { - splitPane.savePosition(); - } - splitPane.setResizeWeight(weight); - splitPane.forceSetDividerLocation(location); - splitPane.setEnabled(false); - splitPane.setResizable(false); - } - public Component getContent() { return cont; } @@ -309,14 +307,14 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { rightSplit.setLeftComponent(pane); } - /** - * Show or hide the corresponding panel. - * - * @param a position of panel. - * @param enabled true if should be shown. - */ - public void setEnabled(@NotNull final Alignment a, final boolean enabled) { - setEnabled(a, enabled, false); + private void disable(final ToggleSplitPane splitPane, final double weight, final double location) { + if (splitPane.isResizable()) { + splitPane.savePosition(); + } + splitPane.setResizeWeight(weight); + splitPane.forceSetDividerLocation(location); + splitPane.setEnabled(false); + splitPane.setResizable(false); } /** @@ -325,7 +323,7 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { * @param a the position of the panel. * @return true if enabled. */ - public boolean isEnabled(@NotNull final Alignment a) { + public boolean isEnabled(final Alignment a) { if (a == Alignment.CENTER) { return false; } else { @@ -333,7 +331,7 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { } } - public void setComponentAt(@NotNull final Alignment a, final Component c) { + public void setComponentAt(final Alignment a, final Component c) { switch (a) { case NORTH: ((PopupContainer) topSplitter.getLeftComponent()).setPopup(c); @@ -374,13 +372,13 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { * * @return array of status of panels. */ - @NotNull + public boolean[] getStatus() { return enabled; } @Override - public PopupContainer getContainer(@NotNull final Alignment alignment) { + public PopupContainer getContainer(final Alignment alignment) { PopupContainer popupComponent; switch (alignment) { case NORTH: @@ -419,8 +417,8 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { * @param a the position. * @return the popup component at position. */ - @NotNull - public Component getPopupComponent(@NotNull final Alignment a) { + + public Component getPopupComponent(final Alignment a) { return getContainer(a).getPopup(); } @@ -430,7 +428,7 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { protected final double splitDisable; protected final double splitterDisable; - @Contract(pure = true) + public LayoutProportions(final double splitRestore, final double splitterPeerDisable, final double splitDisable, final double splitterDisable) { this.splitRestore = splitRestore; @@ -446,7 +444,7 @@ public class TabFrameContentPane extends JPanel implements TabFrameContent { protected final double splitDisable; protected final double splitterPeerDisable; - @Contract(pure = true) + public LayoutWeights(final double splitEnable, final double splitterDisable, final double splitDisable, final double splitterPeerDisable) { this.splitEnable = splitEnable; diff --git a/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabLabel.java b/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabLabel.java index d0ee9ae1..f3d91dc8 100644 --- a/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabLabel.java +++ b/src/main/java/com/github/weisj/darklaf/components/tabframe/TabFrameTabLabel.java @@ -26,8 +26,6 @@ package com.github.weisj.darklaf.components.tabframe; import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.icons.EmptyIcon; import com.github.weisj.darklaf.ui.tabframe.DarkTabFrameTabLabelUI; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -57,7 +55,7 @@ public class TabFrameTabLabel extends JLabel implements TabFrameTab { * @param parent the parent layout manager. */ public TabFrameTabLabel(final String title, final Icon icon, final Alignment orientation, - final int index, @NotNull final JTabFrame parent) { + final int index, final JTabFrame parent) { this.index = index; this.accelerator = -1; this.parent = parent; @@ -157,7 +155,7 @@ public class TabFrameTabLabel extends JLabel implements TabFrameTab { * * @param title the title */ - public void setTitle(@Nullable final String title) { + public void setTitle(final String title) { if (Objects.equals(title, this.title)) return; String oldTitle = this.title; this.title = title; diff --git a/src/main/java/com/github/weisj/darklaf/components/text/LineHighlighter.java b/src/main/java/com/github/weisj/darklaf/components/text/LineHighlighter.java index 518710b4..060b266a 100644 --- a/src/main/java/com/github/weisj/darklaf/components/text/LineHighlighter.java +++ b/src/main/java/com/github/weisj/darklaf/components/text/LineHighlighter.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.components.text; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -59,8 +57,8 @@ public class LineHighlighter implements Highlighter.HighlightPainter, ChangeList this.color = color; } - public void paint(@NotNull final Graphics g, final int p0, final int p1, final Shape bounds, - @NotNull final JTextComponent c) { + public void paint(final Graphics g, final int p0, final int p1, final Shape bounds, + final JTextComponent c) { try { Rectangle r = c.modelToView(c.getCaretPosition()); g.setColor(color); diff --git a/src/main/java/com/github/weisj/darklaf/components/text/TextFieldHistoryPopup.java b/src/main/java/com/github/weisj/darklaf/components/text/TextFieldHistoryPopup.java index 0a41830f..24d2aba2 100644 --- a/src/main/java/com/github/weisj/darklaf/components/text/TextFieldHistoryPopup.java +++ b/src/main/java/com/github/weisj/darklaf/components/text/TextFieldHistoryPopup.java @@ -26,7 +26,6 @@ package com.github.weisj.darklaf.components.text; import com.github.weisj.darklaf.components.ScrollPopupMenu; import com.github.weisj.darklaf.decorators.PlainAction; import com.github.weisj.darklaf.util.StringUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -55,7 +54,7 @@ public class TextFieldHistoryPopup extends ScrollPopupMenu implements SearchList * @param capacity the length of the history. * @param maxH maximum height. */ - public TextFieldHistoryPopup(@NotNull final SearchTextField textField, final int capacity, final int maxH) { + public TextFieldHistoryPopup(final SearchTextField textField, final int capacity, final int maxH) { super(maxH); this.textField = textField; textField.addSearchListener(this); @@ -107,7 +106,7 @@ public class TextFieldHistoryPopup extends ScrollPopupMenu implements SearchList } @Override - public void searchPerformed(@NotNull final SearchEvent e) { + public void searchPerformed(final SearchEvent e) { String text = e.getText(); if (!StringUtil.isBlank(text)) { addEntry(text); diff --git a/src/main/java/com/github/weisj/darklaf/components/tooltip/DarkToolTip.java b/src/main/java/com/github/weisj/darklaf/components/tooltip/DarkToolTip.java index f33130d2..3199ddf1 100644 --- a/src/main/java/com/github/weisj/darklaf/components/tooltip/DarkToolTip.java +++ b/src/main/java/com/github/weisj/darklaf/components/tooltip/DarkToolTip.java @@ -28,7 +28,6 @@ import com.github.weisj.darklaf.decorators.AncestorAdapter; import com.github.weisj.darklaf.ui.tooltip.DarkTooltipBorder; import com.github.weisj.darklaf.util.Animator; import com.github.weisj.darklaf.util.GraphicsContext; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -134,7 +133,7 @@ public class DarkToolTip extends JToolTip implements PropertyChangeListener { } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { if ("tiptext".equals(evt.getPropertyName())) { setPreferredSize(getUI().getPreferredSize(this)); if (!Objects.equals(evt.getNewValue(), evt.getOldValue())) { diff --git a/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java b/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java index 6167312b..6e40a637 100644 --- a/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java +++ b/src/main/java/com/github/weisj/darklaf/components/tooltip/ToolTipContext.java @@ -27,9 +27,6 @@ import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.alignment.AlignmentStrategy; import com.github.weisj.darklaf.ui.tooltip.DarkTooltipBorder; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -90,7 +87,7 @@ public class ToolTipContext implements ToolTipListener { * * @param c the component which the tooltip belongs to. */ - @Contract("null -> fail") + public ToolTipContext(final JComponent c) { this(c, null, null, null, true, null); } @@ -105,7 +102,7 @@ public class ToolTipContext implements ToolTipListener { * @param alignInside {@link #setAlignInside(boolean)} * @param toolTipRectSupplier {@link #setToolTipRectSupplier(Function)} */ - @Contract("null, _, _, _, _, _ -> fail") + public ToolTipContext(final JComponent c, final Alignment alignment, final Alignment centerAlignment, final AlignmentStrategy alignmentStrategy, final boolean alignInside, final Function toolTipRectSupplier) { @@ -274,7 +271,7 @@ public class ToolTipContext implements ToolTipListener { * @param c the component which the tooltip belongs to. * @param alignment {@link #setAlignment(Alignment)} */ - @Contract("null, _ -> fail") + public ToolTipContext(final JComponent c, final Alignment alignment) { this(c, alignment, null, null, true, null); } @@ -286,7 +283,7 @@ public class ToolTipContext implements ToolTipListener { * @param alignment {@link #setAlignment(Alignment)} * @param centerAlignment {@link #setCenterAlignment(Alignment)} */ - @Contract("null, _, _ -> fail") + public ToolTipContext(final JComponent c, final Alignment alignment, final Alignment centerAlignment) { this(c, alignment, centerAlignment, null, true, null); } @@ -298,7 +295,7 @@ public class ToolTipContext implements ToolTipListener { * @param alignment {@link #setAlignment(Alignment)} * @param alignInside {@link #setAlignInside(boolean)} */ - @Contract("null, _, _ -> fail") + public ToolTipContext(final JComponent c, final Alignment alignment, final boolean alignInside) { this(c, alignment, null, null, alignInside, null); } @@ -311,7 +308,7 @@ public class ToolTipContext implements ToolTipListener { * @param centerAlignment {@link #setCenterAlignment(Alignment)} * @param alignInside {@link #setAlignInside(boolean)} */ - @Contract("null, _, _, _ -> fail") + public ToolTipContext(final JComponent c, final Alignment alignment, final Alignment centerAlignment, final boolean alignInside) { this(c, alignment, centerAlignment, null, alignInside, null); @@ -324,7 +321,7 @@ public class ToolTipContext implements ToolTipListener { * @param alignment {@link #setAlignment(Alignment)} * @param alignmentStrategy {@link #setAlignmentStrategy(AlignmentStrategy)} */ - @Contract("null, _, _ -> fail") + public ToolTipContext(final JComponent c, final Alignment alignment, final AlignmentStrategy alignmentStrategy) { this(c, alignment, null, alignmentStrategy, true, null); } @@ -337,7 +334,7 @@ public class ToolTipContext implements ToolTipListener { * @param centerAlignment {@link #setCenterAlignment(Alignment)} * @param alignmentStrategy {@link #setAlignmentStrategy(AlignmentStrategy)} */ - @Contract("null, _, _, _ -> fail") + public ToolTipContext(final JComponent c, final Alignment alignment, final Alignment centerAlignment, final AlignmentStrategy alignmentStrategy) { this(c, alignment, centerAlignment, alignmentStrategy, true, null); @@ -351,7 +348,7 @@ public class ToolTipContext implements ToolTipListener { * @param alignmentStrategy {@link #setAlignmentStrategy(AlignmentStrategy)} * @param alignInside {@link #setAlignInside(boolean)} */ - @Contract("null, _, _, _ -> fail") + public ToolTipContext(final JComponent c, final Alignment alignment, final AlignmentStrategy alignmentStrategy, final boolean alignInside) { this(c, alignment, null, alignmentStrategy, alignInside, null); @@ -410,11 +407,11 @@ public class ToolTipContext implements ToolTipListener { /** * Calculates the tooltip location. * - * @see JComponent#getToolTipLocation(MouseEvent) * @param event the mouse event. * @return the tooltip location. + * @see JComponent#getToolTipLocation(MouseEvent) */ - public Point getToolTipLocation(@NotNull final MouseEvent event) { + public Point getToolTipLocation(final MouseEvent event) { Rectangle rect = toolTipRectSupplier.apply(event); if (applyInsetsToRect) { DarkUIUtil.applyInsets(rect, c.getInsets(calcInsets)); @@ -471,8 +468,8 @@ public class ToolTipContext implements ToolTipListener { return dim; } - @Nullable - private Point alignCenter(final Dimension dim, @NotNull final Rectangle rect) { + + private Point alignCenter(final Dimension dim, final Rectangle rect) { rect.x += rect.width / 2; rect.y += rect.height / 2; rect.width = 1; @@ -492,7 +489,7 @@ public class ToolTipContext implements ToolTipListener { return adjustPoint(p, alignment, dim, true); } - @Contract("_, _, _, _ -> param1") + private Point adjustPoint(final Point p, final Alignment align, final Dimension dim, final boolean outside) { int factor = outside ? 1 : -1; if (align == Alignment.NORTH_EAST || align == Alignment.SOUTH_EAST) { diff --git a/src/main/java/com/github/weisj/darklaf/components/tristate/TristateCheckBox.java b/src/main/java/com/github/weisj/darklaf/components/tristate/TristateCheckBox.java index c9a8dcc7..bd873093 100644 --- a/src/main/java/com/github/weisj/darklaf/components/tristate/TristateCheckBox.java +++ b/src/main/java/com/github/weisj/darklaf/components/tristate/TristateCheckBox.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.components.tristate; import com.github.weisj.darklaf.DarkLaf; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.ChangeListener; @@ -76,8 +74,7 @@ public class TristateCheckBox extends JCheckBox { return (TristateButtonModel) super.getModel(); } - @NotNull - @Contract(pure = true) + public String getUIClassID() { if (UIManager.getLookAndFeel() instanceof DarkLaf) { return "TristateCheckBoxUI"; diff --git a/src/main/java/com/github/weisj/darklaf/components/uiresource/Insets2D.java b/src/main/java/com/github/weisj/darklaf/components/uiresource/Insets2D.java index 7367ea3c..d8a5bba6 100644 --- a/src/main/java/com/github/weisj/darklaf/components/uiresource/Insets2D.java +++ b/src/main/java/com/github/weisj/darklaf/components/uiresource/Insets2D.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.components.uiresource; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - public final class Insets2D implements Cloneable { public double top; @@ -41,7 +38,7 @@ public final class Insets2D implements Cloneable { * @param bottom the inset from the bottom. * @param right the inset from the right. */ - @Contract(pure = true) + public Insets2D(final double top, final double left, final double bottom, final double right) { this.top = top; this.left = left; @@ -65,7 +62,7 @@ public final class Insets2D implements Cloneable { this.right = right; } - @Contract(pure = true) + @Override public int hashCode() { double sum1 = left + bottom; @@ -76,7 +73,7 @@ public final class Insets2D implements Cloneable { return (int) (sum3 * (sum3 + 1) / 2 + val2); } - @Contract(value = "null -> false", pure = true) + @Override public boolean equals(final Object obj) { if (obj instanceof Insets2D) { @@ -87,14 +84,13 @@ public final class Insets2D implements Cloneable { return false; } - @NotNull - @Contract(value = " -> new", pure = true) + @Override public Insets2D clone() { return new Insets2D(top, left, bottom, right); } - @NotNull + public String toString() { return getClass().getName() + "[top=" + top + ",left=" + left + ",bottom=" + bottom + ",right=" + right + "]"; } diff --git a/src/main/java/com/github/weisj/darklaf/decorators/HoverListener.java b/src/main/java/com/github/weisj/darklaf/decorators/HoverListener.java index 3f3da8d6..5fc076ef 100644 --- a/src/main/java/com/github/weisj/darklaf/decorators/HoverListener.java +++ b/src/main/java/com/github/weisj/darklaf/decorators/HoverListener.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.decorators; -import org.jetbrains.annotations.Contract; - import javax.swing.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -38,7 +36,7 @@ public class HoverListener implements MouseListener { private boolean hover = false; private boolean scheduled = false; - @Contract(pure = true) + public HoverListener(final JComponent component) { this.component = component; } diff --git a/src/main/java/com/github/weisj/darklaf/decorators/LayoutManagerDelegate.java b/src/main/java/com/github/weisj/darklaf/decorators/LayoutManagerDelegate.java index 0682d53b..a4ef9451 100644 --- a/src/main/java/com/github/weisj/darklaf/decorators/LayoutManagerDelegate.java +++ b/src/main/java/com/github/weisj/darklaf/decorators/LayoutManagerDelegate.java @@ -23,14 +23,12 @@ */ package com.github.weisj.darklaf.decorators; -import org.jetbrains.annotations.Contract; - import java.awt.*; public class LayoutManagerDelegate implements LayoutManager { private final LayoutManager delegate; - @Contract(pure = true) + public LayoutManagerDelegate(final LayoutManager delegate) { if (delegate == null) { throw new IllegalArgumentException("Delegate is null"); diff --git a/src/main/java/com/github/weisj/darklaf/decorators/MouseResponder.java b/src/main/java/com/github/weisj/darklaf/decorators/MouseResponder.java index 59da7322..bec06845 100644 --- a/src/main/java/com/github/weisj/darklaf/decorators/MouseResponder.java +++ b/src/main/java/com/github/weisj/darklaf/decorators/MouseResponder.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.decorators; -import org.jetbrains.annotations.Contract; - import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.function.Consumer; @@ -33,7 +31,7 @@ public class MouseResponder implements MouseListener { private final Consumer consumer; - @Contract(pure = true) + public MouseResponder(final Consumer consumer) { this.consumer = consumer; } diff --git a/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java b/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java index 8cccc290..9ecf9f8b 100644 --- a/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java +++ b/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.icons; import com.kitfox.svg.app.beans.SVGIcon; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -56,7 +54,7 @@ public class DarkSVGIcon implements Icon, Serializable { * @param displayWidth display width of icon. * @param displayHeight display height of icon. */ - public DarkSVGIcon(@NotNull final URI uri, final int displayWidth, final int displayHeight) { + public DarkSVGIcon(final URI uri, final int displayWidth, final int displayHeight) { this.uri = uri; size = new Dimension(displayWidth, displayHeight); icon = new SVGIcon(); @@ -65,8 +63,8 @@ public class DarkSVGIcon implements Icon, Serializable { loaded = new AtomicBoolean(false); } - @Contract(pure = true) - private DarkSVGIcon(final int width, final int height, @NotNull final DarkSVGIcon icon) { + + private DarkSVGIcon(final int width, final int height, final DarkSVGIcon icon) { this.size = new Dimension(width, height); this.icon = icon.icon; this.uri = icon.uri; @@ -104,7 +102,7 @@ public class DarkSVGIcon implements Icon, Serializable { * @param y the y coordinate * @param rotation the rotation in radians. */ - public void paintIcon(final Component c, @NotNull final Graphics g, final int x, final int y, + public void paintIcon(final Component c, final Graphics g, final int x, final int y, final double rotation) { ensureLoaded(); Graphics2D g2 = (Graphics2D) g.create(); diff --git a/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java b/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java index a4cde8e0..35a98b3f 100644 --- a/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java +++ b/src/main/java/com/github/weisj/darklaf/icons/DarkUIAwareIcon.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.icons; import com.github.weisj.darklaf.LafManager; import com.github.weisj.darklaf.theme.Theme; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.UIResource; @@ -61,7 +59,7 @@ public class DarkUIAwareIcon implements UIAwareIcon, UIResource, Serializable { * @param h height of icon. * @param parentClass the class to resolve the path while lazy loading. */ - @Contract(pure = true) + public DarkUIAwareIcon(final String darkKey, final String lightKey, final int w, final int h, final Class parentClass) { this.darkKey = darkKey; @@ -72,8 +70,8 @@ public class DarkUIAwareIcon implements UIAwareIcon, UIResource, Serializable { this.dual = new DarkUIAwareIcon(this); } - @Contract(pure = true) - private DarkUIAwareIcon(@NotNull final DarkUIAwareIcon dual) { + + private DarkUIAwareIcon(final DarkUIAwareIcon dual) { this.darkKey = dual.lightKey; this.lightKey = dual.darkKey; this.dual = dual; @@ -82,7 +80,7 @@ public class DarkUIAwareIcon implements UIAwareIcon, UIResource, Serializable { this.parentClass = dual.parentClass; } - public void paintIcon(final Component c, @NotNull final Graphics g2, + public void paintIcon(final Component c, final Graphics g2, final int x, final int y, final double scale) { ensureLoaded(); Graphics2D g = (Graphics2D) g2.create(); @@ -98,7 +96,7 @@ public class DarkUIAwareIcon implements UIAwareIcon, UIResource, Serializable { } } - @Contract(pure = true) + private boolean isLoaded() { return loaded && LafManager.getTheme().equals(currentTheme); } diff --git a/src/main/java/com/github/weisj/darklaf/icons/EmptyIcon.java b/src/main/java/com/github/weisj/darklaf/icons/EmptyIcon.java index 8775168d..e02551a5 100644 --- a/src/main/java/com/github/weisj/darklaf/icons/EmptyIcon.java +++ b/src/main/java/com/github/weisj/darklaf/icons/EmptyIcon.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.icons; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.UIResource; import java.awt.*; @@ -41,23 +38,23 @@ public final class EmptyIcon implements Icon, UIResource { private final int width; private final int height; - @Contract(pure = true) + private EmptyIcon(final int width, final int height) { this.width = width; this.height = height; } - @NotNull - public static Icon create(@NotNull final Icon base) { + + public static Icon create(final Icon base) { return create(base.getIconWidth(), base.getIconHeight()); } - @NotNull + public static Icon create(final int width, final int height) { return width == height ? create(width) : new EmptyIcon(width, height); } - @NotNull + public static Icon create(final int size) { Icon icon = cache.get(size); if (icon == null && size < 129) { @@ -69,23 +66,23 @@ public final class EmptyIcon implements Icon, UIResource { public void paintIcon(final Component component, final Graphics g, final int i, final int j) { } - @Contract(pure = true) + public int getIconWidth() { return this.width; } - @Contract(pure = true) + public int getIconHeight() { return this.height; } - @Contract(pure = true) + public int hashCode() { int sum = this.width + this.height; return sum * (sum + 1) / 2 + this.width; } - @Contract(value = "null -> false", pure = true) + public boolean equals(final Object o) { if (this == o) { return true; diff --git a/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java b/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java index a6c1f21a..0a488e9f 100644 --- a/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java +++ b/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java @@ -32,7 +32,6 @@ import com.kitfox.svg.SVGRoot; import com.kitfox.svg.SVGUniverse; import com.kitfox.svg.animation.AnimationElement; import com.kitfox.svg.app.beans.SVGIcon; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -46,7 +45,7 @@ import java.util.logging.Logger; public final class IconColorMapper { private static final Logger LOGGER = Logger.getLogger(IconLoader.class.getName()); - public static void patchColors(@NotNull final SVGIcon svgIcon) { + public static void patchColors(final SVGIcon svgIcon) { SVGUniverse universe = svgIcon.getSvgUniverse(); SVGDiagram diagram = universe.getDiagram(svgIcon.getSvgURI()); try { @@ -56,7 +55,7 @@ public final class IconColorMapper { } } - private static void loadColors(@NotNull final SVGDiagram diagram) throws SVGElementException { + private static void loadColors(final SVGDiagram diagram) throws SVGElementException { SVGRoot root = diagram.getRoot(); SVGElement defs = diagram.getElement("colors"); if (defs == null) return; @@ -80,7 +79,7 @@ public final class IconColorMapper { } } - @NotNull + private static LinearGradient createColor(final Color c, final String name) throws SVGElementException { LinearGradient grad = new LinearGradient(); grad.addAttribute("id", AnimationElement.AT_XML, name); diff --git a/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java b/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java index 04303976..589c297b 100644 --- a/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java +++ b/src/main/java/com/github/weisj/darklaf/icons/IconLoader.java @@ -23,10 +23,6 @@ */ package com.github.weisj.darklaf.icons; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - import javax.swing.*; import java.net.URISyntaxException; import java.util.HashMap; @@ -48,13 +44,13 @@ public final class IconLoader { private final Map awareIconMap = new HashMap<>(); private final Map iconMap = new HashMap<>(); - @Contract(pure = true) + private IconLoader(final Class parentClass) { this.parentClass = parentClass; iconLoaderMap.put(parentClass, this); } - @Contract(pure = true) + public static IconLoader get() { return instance; } @@ -87,9 +83,9 @@ public final class IconLoader { /* * Helper method to create the icons. */ - @Contract(value = "_, _, _ -> new", pure = true) - @NotNull - public DarkUIAwareIcon create(@NotNull final String name, final int w, final int h) { + + + public DarkUIAwareIcon create(final String name, final int w, final int h) { return new DarkUIAwareIcon("dark/" + name, "light/" + name, w, h, parentClass); } @@ -133,8 +129,11 @@ public final class IconLoader { } } - @NotNull - public Icon loadSVGIcon(@NotNull final String name, final int w, final int h, final boolean themed) { + public Icon loadSVGIcon(final String name, final boolean themed) { + return loadSVGIcon(name, DEFAULT_W, DEFAULT_H, themed); + } + + public Icon loadSVGIcon(final String name, final int w, final int h, final boolean themed) { try { if (themed) { return new ThemedSVGIcon(Objects.requireNonNull(parentClass.getResource(name).toURI()), w, h); @@ -148,12 +147,7 @@ public final class IconLoader { return EmptyIcon.create(0); } - @NotNull - public Icon loadSVGIcon(@NotNull final String name, final boolean themed) { - return loadSVGIcon(name, DEFAULT_W, DEFAULT_H, themed); - } - @Nullable public ImageIcon createImageIcon(final String path, final String description) { java.net.URL imgURL = parentClass.getResource(path); @@ -170,7 +164,7 @@ public final class IconLoader { int w; int h; - @Contract(pure = true) + private IconKey(final String path, final int w, final int h) { this.path = path; this.w = w; @@ -182,7 +176,7 @@ public final class IconLoader { return Objects.hash(path, w, h); } - @Contract(value = "null -> false", pure = true) + @Override public boolean equals(final Object o) { if (this == o) return true; @@ -199,8 +193,7 @@ public final class IconLoader { return Objects.equals(path, iconKey.path); } - @NotNull - @Contract(pure = true) + @Override public String toString() { return "[path=" + path + ", w=" + w + ", h=" + h + "]"; diff --git a/src/main/java/com/github/weisj/darklaf/icons/LazyIcon.java b/src/main/java/com/github/weisj/darklaf/icons/LazyIcon.java index b0d920ec..50ebb6d5 100644 --- a/src/main/java/com/github/weisj/darklaf/icons/LazyIcon.java +++ b/src/main/java/com/github/weisj/darklaf/icons/LazyIcon.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.icons; -import org.jetbrains.annotations.Contract; - import javax.swing.*; import javax.swing.plaf.UIResource; import java.awt.*; @@ -42,7 +40,7 @@ public abstract class LazyIcon implements Icon, UIResource { private boolean loaded; private Icon icon; - @Contract(pure = true) + public LazyIcon(final String path, final IconLoader.IconKey key, final Class parentClass) { this.path = path; this.key = key; diff --git a/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java b/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java index bc2c080d..1cf774fc 100644 --- a/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java +++ b/src/main/java/com/github/weisj/darklaf/icons/RotatableIcon.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.icons; import com.github.weisj.darklaf.components.alignment.Alignment; -import org.jetbrains.annotations.Contract; import javax.swing.*; import java.awt.*; @@ -35,12 +34,12 @@ public class RotatableIcon implements Icon { private Icon icon; private Alignment alignment; - @Contract(pure = true) + public RotatableIcon() { this(null); } - @Contract(pure = true) + public RotatableIcon(final Icon icon) { setIcon(icon); this.alignment = null; @@ -63,7 +62,7 @@ public class RotatableIcon implements Icon { } } - @Contract(pure = true) + private double getAngle() { double angle = 0.0; switch (alignment) { diff --git a/src/main/java/com/github/weisj/darklaf/icons/ScaledIcon.java b/src/main/java/com/github/weisj/darklaf/icons/ScaledIcon.java index ba31e6a0..ad37c17f 100644 --- a/src/main/java/com/github/weisj/darklaf/icons/ScaledIcon.java +++ b/src/main/java/com/github/weisj/darklaf/icons/ScaledIcon.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.icons; import com.github.weisj.darklaf.util.Scale; -import org.jetbrains.annotations.Contract; import javax.swing.*; import java.awt.*; @@ -33,7 +32,7 @@ public class ScaledIcon implements Icon { private Image img; - @Contract(pure = true) + public ScaledIcon(final Image img) { this.img = img; } diff --git a/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java b/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java index ee2a76a8..c283a102 100644 --- a/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java +++ b/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java @@ -25,7 +25,6 @@ package com.github.weisj.darklaf.icons; import com.github.weisj.darklaf.LafManager; import com.github.weisj.darklaf.theme.Theme; -import org.jetbrains.annotations.NotNull; import java.awt.*; import java.net.URI; @@ -37,7 +36,7 @@ public class ThemedSVGIcon extends DarkSVGIcon { private Theme currentTheme; - public ThemedSVGIcon(@NotNull final URI uri, final int displayWidth, final int displayHeight) { + public ThemedSVGIcon(final URI uri, final int displayWidth, final int displayHeight) { super(uri, displayWidth, displayHeight); } diff --git a/src/main/java/com/github/weisj/darklaf/log/LogFormatter.java b/src/main/java/com/github/weisj/darklaf/log/LogFormatter.java index e49aab8c..4694e9a3 100644 --- a/src/main/java/com/github/weisj/darklaf/log/LogFormatter.java +++ b/src/main/java/com/github/weisj/darklaf/log/LogFormatter.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.log; import com.github.weisj.darklaf.util.StringUtil; -import org.jetbrains.annotations.NotNull; import java.text.SimpleDateFormat; import java.util.Date; @@ -49,7 +48,7 @@ public class LogFormatter extends Formatter { public static final String ANSI_BOLD_OFF = "\u001B[2m"; @Override - public String format(@NotNull final LogRecord record) { + public String format(final LogRecord record) { StringBuilder builder = new StringBuilder(); builder.append(ANSI_BLUE); @@ -99,14 +98,14 @@ public class LogFormatter extends Formatter { return builder.toString(); } - @NotNull + private String calculateDateString(final long milliseconds) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(milliseconds); return dateFormat.format(date); } - private String getMessageColor(@NotNull final LogRecord record) { + private String getMessageColor(final LogRecord record) { if (record.getLevel() == Level.SEVERE) { return ANSI_RED; } else if (record.getLevel() == Level.WARNING) { diff --git a/src/main/java/com/github/weisj/darklaf/platform/NativeUtil.java b/src/main/java/com/github/weisj/darklaf/platform/NativeUtil.java index eb5378ed..d26d328e 100644 --- a/src/main/java/com/github/weisj/darklaf/platform/NativeUtil.java +++ b/src/main/java/com/github/weisj/darklaf/platform/NativeUtil.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.platform; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -55,7 +52,7 @@ public class NativeUtil { */ private static File temporaryDir; - @Contract(pure = true) + private NativeUtil() { } @@ -73,7 +70,7 @@ public class NativeUtil { * java.lang.String)}). * @throws FileNotFoundException If the file could not be found inside the JAR. */ - @Contract("null -> fail") + public static void loadLibraryFromJar(final String path) throws IOException { if (null == path || !path.startsWith("/")) { @@ -120,7 +117,7 @@ public class NativeUtil { } } - @NotNull + private static File createTempDirectory(final String prefix) throws IOException { String tempDir = System.getProperty("java.io.tmpdir"); File generatedDir = new File(tempDir, prefix + System.nanoTime()); diff --git a/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorations.java b/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorations.java index 15bf4521..1af9e7d7 100644 --- a/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorations.java +++ b/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorations.java @@ -28,7 +28,6 @@ import com.github.weisj.darklaf.platform.NativeUtil; import com.github.weisj.darklaf.util.SystemInfo; import com.sun.jna.Native; import com.sun.jna.Pointer; -import org.jetbrains.annotations.Contract; import java.awt.*; import java.io.IOException; @@ -107,7 +106,7 @@ public class JNIDecorations { } } - @Contract(pure = true) + public static boolean isCustomDecorationSupported() { return supported; } diff --git a/src/main/java/com/github/weisj/darklaf/theme/Theme.java b/src/main/java/com/github/weisj/darklaf/theme/Theme.java index 4c99eacc..7b76e73c 100644 --- a/src/main/java/com/github/weisj/darklaf/theme/Theme.java +++ b/src/main/java/com/github/weisj/darklaf/theme/Theme.java @@ -27,7 +27,6 @@ import com.github.weisj.darklaf.DarkLaf; import com.github.weisj.darklaf.DarkMetalTheme; import com.github.weisj.darklaf.util.PropertyLoader; import com.github.weisj.darklaf.util.SystemInfo; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.metal.MetalLookAndFeel; @@ -76,7 +75,7 @@ public abstract class Theme { * @param properties the properties to load the values into. * @param currentDefaults the current ui defaults. */ - public void loadDefaults(@NotNull final Properties properties, final UIDefaults currentDefaults) { + public void loadDefaults(final Properties properties, final UIDefaults currentDefaults) { String name = getResourcePath() + getName() + "_defaults.properties"; PropertyLoader.putProperties(load(name), properties, currentDefaults); } @@ -87,7 +86,7 @@ public abstract class Theme { * @param properties the properties to load the values into. * @param currentDefaults the current ui defaults. */ - public void loadGlobals(@NotNull final Properties properties, final UIDefaults currentDefaults) { + public void loadGlobals(final Properties properties, final UIDefaults currentDefaults) { PropertyLoader.putProperties(PropertyLoader.loadProperties(DarkLaf.class, "globals", "properties/"), properties, currentDefaults); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java b/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java index d6f60a1d..4c7b8b70 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java +++ b/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.ui.button; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -72,7 +70,7 @@ public class DarkButtonBorder implements Border, UIResource { } @Override - public void paintBorder(final Component c, @NotNull final Graphics g, + public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { if (DarkButtonUI.isShadowVariant(c) || DarkButtonUI.isLabelButton(c)) { return; @@ -116,7 +114,7 @@ public class DarkButtonBorder implements Border, UIResource { return square ? alt ? focusArc : squareFocusArc : alt ? squareFocusArc : focusArc; } - private void paintShadow(@NotNull final Graphics2D g2, final int width, final int height, final int arc) { + private void paintShadow(final Graphics2D g2, final int width, final int height, final int arc) { GraphicsContext context = new GraphicsContext(g2); int borderSize = getBorderSize(); int shadowSize = getShadowSize(); @@ -142,7 +140,7 @@ public class DarkButtonBorder implements Border, UIResource { return borderSize; } - protected Color getBorderColor(@NotNull final Component c) { + protected Color getBorderColor(final Component c) { if (c.hasFocus()) { return focusBorderColor; } else if (c instanceof JButton && ((JButton) c).isDefaultButton() && c.isEnabled()) { @@ -171,7 +169,7 @@ public class DarkButtonBorder implements Border, UIResource { return false; } - @Contract("null -> false") + public static boolean isThin(final Component c) { return c instanceof JButton && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.thin")); diff --git a/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java b/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java index fb40be9a..11ba8e1a 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java @@ -27,8 +27,6 @@ import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; import com.github.weisj.darklaf.util.SystemInfo; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -69,8 +67,7 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene private int arc; private int squareArc; - @NotNull - @Contract(value = "_ -> new", pure = true) + public static ComponentUI createUI(final JComponent c) { return new DarkButtonUI(); } @@ -102,7 +99,7 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene squareArc = UIManager.getInt("Button.squareArc"); } - @Contract("null -> false") + public static boolean isSquare(final Component c) { return c instanceof JButton && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.square")); } @@ -120,7 +117,7 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene } @Override - protected void paintText(@NotNull final Graphics g, final JComponent c, + protected void paintText(final Graphics g, final JComponent c, final Rectangle textRect, final String text) { GraphicsContext config = GraphicsUtil.setupAntialiasing(g); AbstractButton button = (AbstractButton) c; @@ -159,7 +156,15 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene return c instanceof JButton && ((JButton) c).isDefaultButton(); } - protected void paintButton(final Graphics g, @NotNull final JComponent c) { + protected Color getForeground(final AbstractButton button) { + Color fg = button.getForeground(); + if (fg instanceof UIResource && isDefaultButton(button) && !isShadowVariant(button)) { + fg = defaultForeground; + } + return fg; + } + + protected void paintButton(final Graphics g, final JComponent c) { Graphics2D g2 = (Graphics2D) g; if (shouldDrawBackground(c)) { AbstractButton b = (AbstractButton) c; @@ -191,62 +196,21 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene } } - protected String layout(@NotNull final AbstractButton b, final JComponent c, final FontMetrics fm, - final int width, final int height) { - Insets i = b.getInsets(); - viewRect.x = i.left; - viewRect.y = i.top; - viewRect.width = width - (i.right + viewRect.x); - viewRect.height = height - (i.bottom + viewRect.y); - - textRect.x = textRect.y = textRect.width = textRect.height = 0; - iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0; - - // layout the text and icon - return SwingUtilities.layoutCompoundLabel( - b, fm, b.getText(), b.getIcon(), - b.getVerticalAlignment(), b.getHorizontalAlignment(), - b.getVerticalTextPosition(), b.getHorizontalTextPosition(), - viewRect, iconRect, textRect, - b.getText() == null ? 0 : b.getIconTextGap()); - } - - protected void paintIcon(final Graphics g, @NotNull final AbstractButton b, final JComponent c) { - if (b.getIcon() != null) { - g.setClip(iconRect); - paintIcon(g, c, iconRect); - } - } - - protected Color getShadowColor(@NotNull final AbstractButton c) { - Object colorHover = c.getClientProperty("JButton.shadow.hover"); - Object colorClick = c.getClientProperty("JButton.shadow.click"); - return c.getModel().isArmed() ? colorClick instanceof Color ? (Color) colorClick : shadowClick - : colorHover instanceof Color ? (Color) colorHover : shadowHover; - } - - private boolean shouldDrawBackground(@NotNull final JComponent c) { + private boolean shouldDrawBackground(final JComponent c) { if (isLabelButton(c)) return false; AbstractButton button = (AbstractButton) c; Border border = c.getBorder(); return c.isEnabled() && border != null && button.isContentAreaFilled(); } - protected int getArc(final Component c) { - if (DarkButtonUI.isNoArc(c)) return 0; - boolean square = DarkButtonUI.isSquare(c); - boolean alt = DarkButtonUI.chooseAlternativeArc(c); - return square ? alt ? arc : squareArc : alt ? squareArc : arc; - } - - @Contract("null -> false") - public static boolean isShadowVariant(final Component c) { - if (isFullShadow(c)) return true; - return c instanceof JButton - && "shadow".equals(((JButton) c).getClientProperty("JButton.variant")); + protected Color getShadowColor(final AbstractButton c) { + Object colorHover = c.getClientProperty("JButton.shadow.hover"); + Object colorClick = c.getClientProperty("JButton.shadow.click"); + return c.getModel().isArmed() ? colorClick instanceof Color ? (Color) colorClick : shadowClick + : colorHover instanceof Color ? (Color) colorHover : shadowHover; } - protected Color getBackgroundColor(@NotNull final JComponent c) { + protected Color getBackgroundColor(final JComponent c) { boolean defaultButton = isDefaultButton(c); boolean rollOver = (c instanceof JButton && (((JButton) c).isRolloverEnabled() && (((JButton) c).getModel().isRollover()))); @@ -274,7 +238,41 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene } } - @Contract("null -> false") + protected int getArc(final Component c) { + if (DarkButtonUI.isNoArc(c)) return 0; + boolean square = DarkButtonUI.isSquare(c); + boolean alt = DarkButtonUI.chooseAlternativeArc(c); + return square ? alt ? arc : squareArc : alt ? squareArc : arc; + } + + + public static boolean isShadowVariant(final Component c) { + if (isFullShadow(c)) return true; + return c instanceof JButton + && "shadow".equals(((JButton) c).getClientProperty("JButton.variant")); + } + + protected String layout(final AbstractButton b, final JComponent c, final FontMetrics fm, + final int width, final int height) { + Insets i = b.getInsets(); + viewRect.x = i.left; + viewRect.y = i.top; + viewRect.width = width - (i.right + viewRect.x); + viewRect.height = height - (i.bottom + viewRect.y); + + textRect.x = textRect.y = textRect.width = textRect.height = 0; + iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0; + + // layout the text and icon + return SwingUtilities.layoutCompoundLabel( + b, fm, b.getText(), b.getIcon(), + b.getVerticalAlignment(), b.getHorizontalAlignment(), + b.getVerticalTextPosition(), b.getHorizontalTextPosition(), + viewRect, iconRect, textRect, + b.getText() == null ? 0 : b.getIconTextGap()); + } + + public static boolean isFullShadow(final Component c) { return c instanceof JButton && "fullShadow".equals(((JButton) c).getClientProperty("JButton.variant")); @@ -299,27 +297,26 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene context.restore(); } - protected Color getForeground(@NotNull final AbstractButton button) { - Color fg = button.getForeground(); - if (fg instanceof UIResource && isDefaultButton(button) && !isShadowVariant(button)) { - fg = defaultForeground; + protected void paintIcon(final Graphics g, final AbstractButton b, final JComponent c) { + if (b.getIcon() != null) { + g.setClip(iconRect); + paintIcon(g, c, iconRect); } - return fg; } - @Contract("null -> false") + public static boolean chooseAlternativeArc(final Component c) { return c instanceof JButton && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.alternativeArc")); } - @Contract("null -> false") + public static boolean isLabelButton(final Component c) { return c instanceof JButton && "onlyLabel".equals(((JButton) c).getClientProperty("JButton.variant")); } - @Contract("null -> false") + public static boolean isNoArc(final Component c) { return c instanceof JButton && Boolean.TRUE.equals(((JButton) c).getClientProperty("JButton.noArc")); @@ -337,7 +334,7 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene } @Override - public boolean contains(@NotNull final JComponent c, final int x, final int y) { + public boolean contains(final JComponent c, final int x, final int y) { if (isLabelButton(c)) { return super.contains(c, x, y); } @@ -349,7 +346,7 @@ public class DarkButtonUI extends BasicButtonUI implements PropertyChangeListene } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if (key.startsWith("JButton.")) { button.repaint(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/button/DarkToggleButtonUI.java b/src/main/java/com/github/weisj/darklaf/ui/button/DarkToggleButtonUI.java index 70186a79..adc7da48 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/button/DarkToggleButtonUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/button/DarkToggleButtonUI.java @@ -26,8 +26,6 @@ package com.github.weisj.darklaf.ui.button; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -71,8 +69,7 @@ public class DarkToggleButtonUI extends DarkButtonUI { protected Color sliderBorderColor; protected Color inactiveSliderBorderColor; - @NotNull - @Contract(value = "_ -> new", pure = true) + public static ComponentUI createUI(final JComponent c) { return new DarkToggleButtonUI(); } @@ -93,7 +90,7 @@ public class DarkToggleButtonUI extends DarkButtonUI { } @Override - public void paint(final Graphics g, @NotNull final JComponent c) { + public void paint(final Graphics g, final JComponent c) { if (isSlider(c)) { GraphicsContext config = GraphicsUtil.setupStrokePainting(g); AbstractButton b = (AbstractButton) c; @@ -109,8 +106,19 @@ public class DarkToggleButtonUI extends DarkButtonUI { } } + protected Color getBackgroundColor(final JComponent c) { + if (c instanceof JToggleButton && c.isEnabled()) { + if (((JToggleButton) c).isSelected()) { + return background; + } else { + return backgroundInactive; + } + } + return super.getBackgroundColor(c); + } + @Override - protected String layout(@NotNull final AbstractButton b, final JComponent c, + protected String layout(final AbstractButton b, final JComponent c, final FontMetrics fm, final int width, final int height) { if (isSlider(c)) { Insets i = b.getInsets(); @@ -139,19 +147,8 @@ public class DarkToggleButtonUI extends DarkButtonUI { } } - protected Color getBackgroundColor(@NotNull final JComponent c) { - if (c instanceof JToggleButton && c.isEnabled()) { - if (((JToggleButton) c).isSelected()) { - return background; - } else { - return backgroundInactive; - } - } - return super.getBackgroundColor(c); - } - @Override - public boolean contains(@NotNull final JComponent c, final int x, final int y) { + public boolean contains(final JComponent c, final int x, final int y) { if (!isSlider(c)) return super.contains(c, x, y); if (!(x >= 0 && x <= c.getWidth() && y >= 0 && y <= c.getHeight())) return false; Rectangle bounds = getSliderBounds(c); @@ -159,13 +156,13 @@ public class DarkToggleButtonUI extends DarkButtonUI { bounds.height, bounds.height).contains(x, y); } - @Contract("null -> false") + private static boolean isSlider(final JComponent c) { return c instanceof JToggleButton && "slider".equals(c.getClientProperty("JToggleButton.variant")); } - private void paintSlider(@NotNull final Graphics2D g, final AbstractButton c) { + private void paintSlider(final Graphics2D g, final AbstractButton c) { Rectangle bounds = getSliderBounds(c); g.translate(bounds.x, bounds.y); @@ -198,8 +195,8 @@ public class DarkToggleButtonUI extends DarkButtonUI { config.restore(); } - @NotNull - private Rectangle getSliderBounds(@NotNull final JComponent c) { + + private Rectangle getSliderBounds(final JComponent c) { int x = borderSize; int y = (c.getHeight() - sliderSize.height) / 2; rect.x = x; @@ -212,18 +209,18 @@ public class DarkToggleButtonUI extends DarkButtonUI { return rect; } - protected Color getToggleBorderColor(@NotNull final AbstractButton b) { + protected Color getToggleBorderColor(final AbstractButton b) { if (b.hasFocus()) { return focusBorderColor; } return b.isEnabled() ? borderColor : inactiveBorderColor; } - protected Color getSliderColor(@NotNull final AbstractButton b) { + protected Color getSliderColor(final AbstractButton b) { return b.isEnabled() ? sliderColor : inactiveSliderColor; } - protected Color getSliderBorderColor(@NotNull final AbstractButton b) { + protected Color getSliderBorderColor(final AbstractButton b) { return b.isEnabled() ? sliderBorderColor : inactiveSliderBorderColor; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java b/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java index dded5669..59174585 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java +++ b/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java @@ -27,7 +27,6 @@ import com.github.weisj.darklaf.components.SelectableTreeNode; import com.github.weisj.darklaf.decorators.CellRenderer; import com.github.weisj.darklaf.ui.tree.DarkTreeCellRenderer; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.table.TableCellRenderer; @@ -45,7 +44,7 @@ public class DarkCellRendererToggleButton new") + public static ComponentUI createUI(final JComponent c) { return new DarkCheckBoxUI(); } @@ -133,7 +130,7 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis } @Override - public synchronized void paint(final Graphics g2d, @NotNull final JComponent c) { + public synchronized void paint(final Graphics g2d, final JComponent c) { Graphics2D g = (Graphics2D) g2d; JCheckBox b = (JCheckBox) c; FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, c.getFont()); @@ -159,7 +156,7 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis } } - protected String layoutCheckBox(@NotNull final JCheckBox b, final FontMetrics fm) { + protected String layoutCheckBox(final JCheckBox b, final FontMetrics fm) { Insets i = b.getInsets(); size = b.getSize(size); viewRect.x = i.left; @@ -179,14 +176,14 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis return text; } - private void paintBackground(@NotNull final JComponent c, final Graphics2D g) { + private void paintBackground(final JComponent c, final Graphics2D g) { if (c.isOpaque()) { g.setColor(c.getBackground()); g.fillRect(0, 0, c.getWidth(), c.getHeight()); } } - public static Icon getIconBullet(final JComponent c, final Graphics2D g, @NotNull final AbstractButton b) { + public static Icon getIconBullet(final JComponent c, final Graphics2D g, final AbstractButton b) { ButtonModel model = b.getModel(); Icon icon = b.getIcon(); if (!model.isEnabled()) { @@ -220,7 +217,7 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis return icon; } - protected Icon getCheckIcon(@NotNull final AbstractButton b) { + protected Icon getCheckIcon(final AbstractButton b) { boolean selected = b.isSelected(); boolean enabled = b.isEnabled(); boolean hasFocus = b.hasFocus(); @@ -230,7 +227,7 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis : checkBoxDisabledIcon; } - protected void paintDarkCheck(final JComponent c, final Graphics2D g, @NotNull final JCheckBox b) { + protected void paintDarkCheck(final JComponent c, final Graphics2D g, final JCheckBox b) { GraphicsContext config = new GraphicsContext(g); boolean enabled = b.isEnabled(); g.translate(iconRect.x + ICON_OFF, iconRect.y + ICON_OFF); @@ -243,7 +240,7 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis config.restore(); } - public static void paintText(@NotNull final Graphics2D g, @NotNull final AbstractButton b, + public static void paintText(final Graphics2D g, final AbstractButton b, final Rectangle textRect, final String text, final FontMetrics fm, final Color disabledTextColor) { GraphicsContext context = GraphicsUtil.setupAntialiasing(g); @@ -266,7 +263,7 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis return new IconUIResource(EmptyIcon.create(20)); } - protected void paintCheckBorder(@NotNull final Graphics2D g, final boolean enabled, final boolean focus, + protected void paintCheckBorder(final Graphics2D g, final boolean enabled, final boolean focus, final boolean selected, final int arcSize, final int borderSize) { Graphics2D g2 = (Graphics2D) g.create(); Color bgColor = getFillColor(selected, enabled); @@ -287,7 +284,7 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis g2.dispose(); } - protected void paintCheckArrow(@NotNull final Graphics2D g, final boolean enabled, final boolean focus) { + protected void paintCheckArrow(final Graphics2D g, final boolean enabled, final boolean focus) { GraphicsContext config = GraphicsUtil.setupStrokePainting(g); g.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); Color color = getCheckColor(focus, enabled); @@ -318,7 +315,7 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis } @Override - public boolean contains(@NotNull final JComponent c, final int x, final int y) { + public boolean contains(final JComponent c, final int x, final int y) { if (hitArea.isEmpty() && c instanceof JCheckBox) { layoutCheckBox((JCheckBox) c, c.getFontMetrics(c.getFont())); } @@ -326,7 +323,7 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if ("componentOrientation".equals(key)) { checkBox.repaint(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorPipette.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorPipette.java index fede81e1..fc5c1e35 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorPipette.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorPipette.java @@ -25,7 +25,6 @@ package com.github.weisj.darklaf.ui.colorchooser; import com.github.weisj.darklaf.components.Disposable; -import org.jetbrains.annotations.Nullable; import java.awt.*; import java.awt.image.ImageObserver; @@ -35,9 +34,9 @@ import java.awt.image.ImageObserver; * @author Konstantin Bulenkov */ public interface ColorPipette extends ImageObserver, Disposable { - void setInitialColor(@Nullable Color initialColor); + void setInitialColor(Color initialColor); + - @Nullable Color getColor(); Window show(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorPreviewComponent.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorPreviewComponent.java index 899c0637..9f2cd3b6 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorPreviewComponent.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorPreviewComponent.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.colorchooser; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; @@ -47,7 +44,7 @@ final class ColorPreviewComponent extends JComponent { } @Override - protected void paintComponent(@NotNull final Graphics g) { + protected void paintComponent(final Graphics g) { final Insets i = getInsets(); final Rectangle r = getBounds(); @@ -67,8 +64,7 @@ final class ColorPreviewComponent extends JComponent { g.fillRect(i.left, i.top + height - 1, width, 1); } - @NotNull - @Contract(value = " -> new", pure = true) + @Override public Dimension getPreferredSize() { return new Dimension(100, 32); diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorValueFormatter.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorValueFormatter.java index ee42ec6e..15eb9d63 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorValueFormatter.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorValueFormatter.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.colorchooser; import com.github.weisj.darklaf.color.DarkColorModel; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.text.AttributeSet; @@ -56,7 +54,7 @@ public final class ColorValueFormatter extends JFormattedTextField.AbstractForma private JFormattedTextField text; private final DocumentFilter filter = new DocumentFilter() { @Override - public void remove(@NotNull final FilterBypass fb, final int offset, + public void remove(final FilterBypass fb, final int offset, final int length) throws BadLocationException { if (isValid(fb.getDocument().getLength() - length)) { fb.remove(offset, length); @@ -67,8 +65,8 @@ public final class ColorValueFormatter extends JFormattedTextField.AbstractForma } @Override - public void insertString(@NotNull final FilterBypass fb, final int offset, - @NotNull final String text, final AttributeSet set) throws BadLocationException { + public void insertString(final FilterBypass fb, final int offset, + final String text, final AttributeSet set) throws BadLocationException { if (isValid(fb.getDocument().getLength() + text.length()) && isValid(text)) { StringBuilder newText = new StringBuilder(fb.getDocument().getText(0, fb.getDocument().getLength())); @@ -83,8 +81,8 @@ public final class ColorValueFormatter extends JFormattedTextField.AbstractForma } @Override - public void replace(@NotNull final FilterBypass fb, final int offset, final int length, - @NotNull final String text, final AttributeSet set) throws BadLocationException { + public void replace(final FilterBypass fb, final int offset, final int length, + final String text, final AttributeSet set) throws BadLocationException { if (isValid(fb.getDocument().getLength() + text.length() - length) && isValid(text)) { StringBuilder newText = new StringBuilder(fb.getDocument().getText(0, fb.getDocument().getLength())); newText.replace(offset, offset + length, text); @@ -107,9 +105,9 @@ public final class ColorValueFormatter extends JFormattedTextField.AbstractForma errorTimer.setRepeats(false); } - @NotNull + static ColorValueFormatter init(final DarkColorModel model, final int index, - final boolean hex, @NotNull final JFormattedTextField text) { + final boolean hex, final JFormattedTextField text) { ColorValueFormatter formatter = new ColorValueFormatter(model, index, hex); text.setFormatterFactory(new DefaultFormatterFactory(formatter)); text.setMinimumSize(text.getPreferredSize()); @@ -151,7 +149,7 @@ public final class ColorValueFormatter extends JFormattedTextField.AbstractForma this.transparencyEnabled = transparencyEnabled; } - public void focusGained(@NotNull final FocusEvent event) { + public void focusGained(final FocusEvent event) { Object source = event.getSource(); if (source instanceof JFormattedTextField) { this.text = (JFormattedTextField) source; @@ -167,7 +165,7 @@ public final class ColorValueFormatter extends JFormattedTextField.AbstractForma SwingUtilities.invokeLater(() -> text.select(0, 0)); } - @Contract(pure = true) + private boolean isValid(final int length) { return (0 <= length) && (length <= getLength()); } @@ -176,12 +174,12 @@ public final class ColorValueFormatter extends JFormattedTextField.AbstractForma return hex ? getHexLength() : String.valueOf(model.getMaximum(fieldIndex)).length(); } - @Contract(pure = true) + private int getHexLength() { return transparencyEnabled ? 8 : 6; } - private boolean isValid(@NotNull final String text) { + private boolean isValid(final String text) { int length = text.length(); for (int i = 0; i < length; i++) { char ch = text.charAt(i); @@ -202,7 +200,7 @@ public final class ColorValueFormatter extends JFormattedTextField.AbstractForma } @Override - public Object stringToValue(@NotNull final String text) throws ParseException { + public Object stringToValue(final String text) throws ParseException { try { if (text.isEmpty()) { return model.getDefault(fieldIndex); @@ -238,7 +236,7 @@ public final class ColorValueFormatter extends JFormattedTextField.AbstractForma } } - @Contract("null -> fail") + @Override public String valueToString(final Object object) throws ParseException { if (object instanceof Integer && !hex) { @@ -258,7 +256,7 @@ public final class ColorValueFormatter extends JFormattedTextField.AbstractForma throw new ParseException("illegal object", 0); } - @Contract(pure = true) + @Override protected DocumentFilter getDocumentFilter() { return this.filter; diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorWheel.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorWheel.java index e045be95..5f113dfe 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorWheel.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorWheel.java @@ -27,7 +27,6 @@ package com.github.weisj.darklaf.ui.colorchooser; import com.github.weisj.darklaf.util.ColorUtil; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -118,7 +117,7 @@ public class ColorWheel extends JComponent { setColor(ColorUtil.toAlpha(rgb, opacity), this, h, s, b); } - public void setColor(@NotNull final Color color, final Object source, + public void setColor(final Color color, final Object source, final float h, final float s, final float b) { myColor = color; myHue = h; diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorWheelPanel.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorWheelPanel.java index 2f93b302..8adb9ac1 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorWheelPanel.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorWheelPanel.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.colorchooser; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.colorchooser.AbstractColorChooserPanel; import java.awt.*; @@ -77,7 +75,7 @@ public class ColorWheelPanel extends JPanel { } } - public void setColor(@NotNull final Color color, final Object source) { + public void setColor(final Color color, final Object source) { float[] hsb = new float[3]; Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb); diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java index 6e3af00f..9fb70f5c 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java @@ -28,8 +28,6 @@ import com.github.weisj.darklaf.color.DarkColorModel; import com.github.weisj.darklaf.components.DefaultColorPipette; import com.github.weisj.darklaf.decorators.AncestorAdapter; import com.github.weisj.darklaf.util.ColorUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.colorchooser.AbstractColorChooserPanel; @@ -68,7 +66,7 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements private Icon pipetteIcon; private Icon pipetteHoverIcon; - @Contract("null -> fail") + public DarkColorChooserPanel(final DarkColorModel... colorModels) { if (colorModels == null || colorModels.length == 0) { throw new IllegalArgumentException("Must pass at least one valid colorModel"); @@ -186,7 +184,7 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements return (DarkColorModel) formatBox.getSelectedItem(); } - @NotNull + private JComponent buildTopPanel(final boolean enablePipette) { final JPanel result = new JPanel(new BorderLayout()); @@ -241,7 +239,7 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements return result; } - @NotNull + private JFormattedTextField createColorField(final boolean hex) { JFormattedTextField field = new JFormattedTextField(0); field.setColumns(hex ? 8 : 4); @@ -399,7 +397,7 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements } - private void applyColorToHEX(@NotNull final Color c) { + private void applyColorToHEX(final Color c) { boolean changingOld = isChanging; isChanging = true; boolean transparencyEnabled = isColorTransparencySelectionEnabled(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java index b80c2c9a..a828277f 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserUI.java @@ -27,8 +27,6 @@ import com.github.weisj.darklaf.color.DarkColorModel; import com.github.weisj.darklaf.color.DarkColorModelCMYK; import com.github.weisj.darklaf.color.DarkColorModelHSL; import com.github.weisj.darklaf.decorators.AncestorAdapter; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.colorchooser.AbstractColorChooserPanel; @@ -73,8 +71,7 @@ public class DarkColorChooserUI extends BasicColorChooserUI { } }; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkColorChooserUI(); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java index 3cdf8027..c133543f 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java @@ -25,7 +25,6 @@ package com.github.weisj.darklaf.ui.colorchooser; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -80,7 +79,7 @@ public class DarkPreviewPanel extends JPanel { return new Dimension(x, y); } - private int paintSquares(@NotNull final Graphics g, final int offsetX) { + private int paintSquares(final Graphics g, final int offsetX) { Color color = getForeground(); g.setColor(Color.white); @@ -146,7 +145,7 @@ public class DarkPreviewPanel extends JPanel { } - private int paintText(@NotNull final Graphics g, final int offsetX) { + private int paintText(final Graphics g, final int offsetX) { GraphicsContext config = GraphicsUtil.setupAntialiasing(g); g.setFont(getFont()); JComponent host = getColorChooser(); @@ -183,7 +182,7 @@ public class DarkPreviewPanel extends JPanel { return width + TEXT_GAP * 3; } - private int paintSwatch(@NotNull final Graphics g, final int offsetX) { + private int paintSwatch(final Graphics g, final int offsetX) { g.setColor(oldColor); g.fillRect(offsetX, 0, SWATCH_WIDTH, SQUARE_SIZE + SQUARE_GAP / 2); g.setColor(getForeground()); diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/MainSwatchPanel.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/MainSwatchPanel.java index 62c3c8dc..a113938e 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/MainSwatchPanel.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/MainSwatchPanel.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.colorchooser; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; @@ -50,8 +47,7 @@ class MainSwatchPanel extends SwatchPanel { } } - @NotNull - @Contract(value = " -> new", pure = true) + private int[] initRawValues() { return new int[]{ 0, 0, 0, diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/RecentSwatchPanel.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/RecentSwatchPanel.java index 12e478ff..eb8d4fb2 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/RecentSwatchPanel.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/RecentSwatchPanel.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.colorchooser; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; @@ -54,7 +52,7 @@ class RecentSwatchPanel extends SwatchPanel { } @Override - public String getToolTipText(@NotNull final MouseEvent e) { + public String getToolTipText(final MouseEvent e) { Color color = getColorForLocation(e.getX(), e.getY()); if (color == defaultRecentColor || color == null) return null; return color.getRed() + ", " + color.getGreen() + ", " + color.getBlue(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SlideComponent.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SlideComponent.java index b35479bf..0c19fd58 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SlideComponent.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SlideComponent.java @@ -28,8 +28,6 @@ import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tooltip.ToolTipContext; import com.github.weisj.darklaf.util.ColorUtil; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -118,8 +116,7 @@ class SlideComponent extends JComponent implements ColorListener { setToolTipText(getToolTipText(null)); } - @NotNull - @Contract(" -> new") + private Rectangle getKnobRect() { if (vertical) { return new Rectangle(1, pointerValue - 6, 12, 12); @@ -221,7 +218,7 @@ class SlideComponent extends JComponent implements ColorListener { drawKnob(g2d, vertical ? 7 : pointerValue, vertical ? pointerValue : 7, vertical); } - protected void drawKnob(@NotNull final Graphics2D g2d, int x, int y, final boolean vertical) { + protected void drawKnob(final Graphics2D g2d, int x, int y, final boolean vertical) { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (vertical) { y -= 6; @@ -309,7 +306,7 @@ class SlideComponent extends JComponent implements ColorListener { } } - @Contract(pure = true) + private static float getMaxValue(final Unit unit) { return LEVEL.equals(unit) ? LEVEL_MAX_VALUE : PERCENT_MAX_VALUE; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SwatchPanel.java b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SwatchPanel.java index 937ef1cd..1059ccaa 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SwatchPanel.java +++ b/src/main/java/com/github/weisj/darklaf/ui/colorchooser/SwatchPanel.java @@ -27,9 +27,6 @@ import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tooltip.ToolTipContext; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -134,15 +131,14 @@ abstract class SwatchPanel extends JPanel { return getColorForCell(selCol, selRow); } - @Nullable - @Contract(pure = true) + private Color getColorForCell(final int column, final int row) { int index = (row * numSwatches.width) + column; if (index >= colors.length) return null; return colors[(row * numSwatches.width) + column]; } - public void paintComponent(@NotNull final Graphics g) { + public void paintComponent(final Graphics g) { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); for (int row = 0; row < numSwatches.height; row++) { @@ -167,7 +163,7 @@ abstract class SwatchPanel extends JPanel { } } - @Contract(pure = true) + private int getYForRow(final int row) { return row * (swatchSize.height + gap.height); } @@ -186,7 +182,7 @@ abstract class SwatchPanel extends JPanel { return new Dimension(x, y); } - public String getToolTipText(@NotNull final MouseEvent e) { + public String getToolTipText(final MouseEvent e) { Color color = getColorForLocation(e.getX(), e.getY()); if (color == null) return null; return color.getRed() + ", " + color.getGreen() + ", " + color.getBlue(); @@ -218,8 +214,8 @@ abstract class SwatchPanel extends JPanel { return new Point(column, row); } - @NotNull - protected Rectangle getSwatchBounds(@NotNull final MouseEvent e) { + + protected Rectangle getSwatchBounds(final MouseEvent e) { Point p = getCoordinatesForLocation(e.getX(), e.getY()); int x = getXForColumn(p.x); int y = getYForRow(p.y); diff --git a/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java b/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java index 41255f38..fc55f146 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java @@ -27,8 +27,6 @@ import com.github.weisj.darklaf.components.ArrowButton; import com.github.weisj.darklaf.ui.list.DarkListCellRenderer; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -76,8 +74,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC protected Color arrowBackgroundEnd; private Insets boxPadding; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkComboBoxUI(); } @@ -140,7 +137,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC process(e); } - private void process(@NotNull final KeyEvent e) { + private void process(final KeyEvent e) { final int code = e.getKeyCode(); if ((code == KeyEvent.VK_UP || code == KeyEvent.VK_DOWN) && e.getModifiersEx() == 0) { comboBox.dispatchEvent(e); @@ -187,7 +184,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC paintCurrentValue(g, r, hasFocus); } - private void paintBackground(final Graphics g, @NotNull final JComponent c, final int width, final int height) { + private void paintBackground(final Graphics g, final JComponent c, final int width, final int height) { final Container parent = c.getParent(); if (parent != null && parent.isOpaque()) { g.setColor(parent.getBackground()); @@ -207,18 +204,18 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC } } - protected Color getBackground(@NotNull final JComboBox c) { + protected Color getBackground(final JComboBox c) { if (!c.isEnabled()) return inactiveBackground; if (c.isEditable()) return editBackground; return background; } - protected static boolean isTableCellEditor(@NotNull final Component c) { + protected static boolean isTableCellEditor(final Component c) { return c instanceof JComponent && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JComboBox.isTableCellEditor")); } - protected static boolean isTreeCellEditor(@NotNull final Component c) { + protected static boolean isTreeCellEditor(final Component c) { return c instanceof JComponent && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JComboBox.isTreeCellEditor")); } @@ -396,7 +393,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC } } - protected Paint getArrowBackground(@NotNull final JComboBox c) { + protected Paint getArrowBackground(final JComboBox c) { if (!c.isEnabled()) return inactiveBackground; if (c.isEditable()) { return new GradientPaint(0, borderSize, arrowBackgroundStart, @@ -427,7 +424,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyC } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if ("componentOrientation".equals(key)) { comboBox.doLayout(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java b/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java index 01864031..bdfc6958 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.ui.filechooser; import com.github.weisj.darklaf.components.tooltip.TooltipAwareButton; import com.github.weisj.darklaf.components.tooltip.TooltipAwareToggleButton; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.swing.FilePane; import javax.accessibility.AccessibleContext; @@ -47,8 +45,7 @@ public class DarkFileChooserUI extends DarkFileChooserUIBridge { super(b); } - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkFileChooserUI((JFileChooser) c); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java b/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java index e7e1cdc8..e53cdf43 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java +++ b/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java @@ -27,7 +27,6 @@ import com.github.weisj.darklaf.ui.list.DarkListCellRenderer; import com.github.weisj.darklaf.ui.table.DarkTableCellEditor; import com.github.weisj.darklaf.ui.table.DarkTableCellRenderer; import com.github.weisj.darklaf.ui.table.TextFieldTableCellEditorBorder; -import org.jetbrains.annotations.NotNull; import sun.awt.AWTAccessor; import sun.awt.shell.ShellFolder; import sun.awt.shell.ShellFolderColumnInfo; @@ -1765,7 +1764,7 @@ public class DarkFilePaneUIBridge extends JPanel implements PropertyChangeListen JFileChooser chooser; DateFormat df; - DetailsTableCellRenderer(@NotNull final JFileChooser chooser) { + DetailsTableCellRenderer(final JFileChooser chooser) { this.chooser = chooser; df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, chooser.getLocale()); @@ -1898,7 +1897,7 @@ public class DarkFilePaneUIBridge extends JPanel implements PropertyChangeListen @SuppressWarnings("serial") // JDK-implementation class protected class FileRenderer extends DarkListCellRenderer { - public Component getListCellRendererComponent(@NotNull final JList list, final Object value, + public Component getListCellRendererComponent(final JList list, final Object value, final int index, boolean isSelected, final boolean cellHasFocus) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkDesktopIconUI.java b/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkDesktopIconUI.java index 176a3561..f3822464 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkDesktopIconUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkDesktopIconUI.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.internalframe; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.border.MatteBorder; import javax.swing.plaf.ComponentUI; @@ -112,7 +110,7 @@ public class DarkDesktopIconUI extends BasicDesktopIconUI { } class TitleListener implements PropertyChangeListener { - public void propertyChange(@NotNull final PropertyChangeEvent e) { + public void propertyChange(final PropertyChangeEvent e) { if (e.getPropertyName().equals("title")) { button.setText((String) e.getNewValue()); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameBorder.java b/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameBorder.java index 427a2ac7..e41a200c 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameBorder.java +++ b/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameBorder.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.ui.internalframe; import com.github.weisj.darklaf.components.border.DropShadowBorder; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.InsetsUIResource; @@ -43,7 +42,7 @@ public class DarkInternalFrameBorder extends DropShadowBorder implements UIResou } @Override - public void paintBorder(final Component c, @NotNull final Graphics graphics, final int x, final int y, + public void paintBorder(final Component c, final Graphics graphics, final int x, final int y, final int width, final int height) { if (c instanceof JInternalFrame && ((JInternalFrame) c).isMaximum()) { return; diff --git a/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java b/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java index b2068e0f..f9ae89f2 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java +++ b/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java @@ -25,7 +25,6 @@ package com.github.weisj.darklaf.ui.internalframe; import com.github.weisj.darklaf.icons.EmptyIcon; import com.github.weisj.darklaf.ui.rootpane.TitlePaneIcon; -import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; import javax.accessibility.AccessibleContext; @@ -153,7 +152,7 @@ public class DarkInternalFrameTitlePane extends BasicInternalFrameTitlePane { setButtonIcons(); } - protected void addSystemMenuItems(@NotNull final JMenu systemMenu) { + protected void addSystemMenuItems(final JMenu systemMenu) { JMenuItem mi = systemMenu.add(restoreAction); mi.setMnemonic(getButtonMnemonic("restore")); mi.setIcon(minimizeIcon); @@ -184,7 +183,7 @@ public class DarkInternalFrameTitlePane extends BasicInternalFrameTitlePane { } @Override - public void paintComponent(@NotNull final Graphics g) { + public void paintComponent(final Graphics g) { g.setColor(getTitleBackground()); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(border); @@ -208,7 +207,7 @@ public class DarkInternalFrameTitlePane extends BasicInternalFrameTitlePane { return frame.isSelected() ? selectedTitleColor : notSelectedTitleColor; } - @NotNull + private static JButton createButton(final String accessibleName) { JButton button = new JButton(); button.setFocusable(false); diff --git a/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameUI.java b/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameUI.java index 7d02aa2f..70e5175a 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameUI.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.internalframe; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicInternalFrameUI; @@ -40,8 +37,7 @@ public class DarkInternalFrameUI extends BasicInternalFrameUI { super(b); } - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent b) { return new DarkInternalFrameUI((JInternalFrame) b); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java b/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java index 84769ede..de81b910 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java @@ -25,7 +25,6 @@ package com.github.weisj.darklaf.ui.label; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -39,7 +38,7 @@ public class DarkLabelUI extends BasicLabelUI { protected static final DarkLabelUI darkLabelUI = new DarkLabelUI(); - @Contract(pure = true) + public static ComponentUI createUI(final JComponent c) { return darkLabelUI; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java b/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java index fe35f3d2..3d4d61e1 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java +++ b/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRenderer.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.ui.list; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ListUI; @@ -33,7 +32,7 @@ import java.awt.*; public class DarkListCellRenderer extends DefaultListCellRenderer { @Override - public Component getListCellRendererComponent(@NotNull final JList list, final Object value, + public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { if (getHorizontalAlignment() != CENTER) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java b/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java index 679c25bd..d75da2f5 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.list; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -42,8 +40,7 @@ public class DarkListUI extends DarkListUIBridge { UIManager.put("List.cellRenderer", new DarkListCellRenderer()); } - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent list) { return new DarkListUI(); } @@ -141,10 +138,10 @@ public class DarkListUI extends DarkListUIBridge { rendererPane.removeAll(); } - protected void paintCell(final Graphics g, final int index, @NotNull final Rectangle rowBounds, - @NotNull final ListCellRenderer cellRenderer, - @NotNull final ListModel dataModel, - @NotNull final ListSelectionModel selModel, final int leadIndex, final int row) { + protected void paintCell(final Graphics g, final int index, final Rectangle rowBounds, + final ListCellRenderer cellRenderer, + final ListModel dataModel, + final ListSelectionModel selModel, final int leadIndex, final int row) { boolean empty = index >= list.getModel().getSize(); Object value = empty ? null : dataModel.getElementAt(index); boolean cellHasFocus = list.hasFocus() && (index == leadIndex); diff --git a/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java b/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java index c98a323e..e694e6c4 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java +++ b/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java @@ -28,7 +28,6 @@ import com.github.weisj.darklaf.ui.DragRecognitionSupport; import com.github.weisj.darklaf.util.DarkSwingUtil; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.LazyActionMap; -import org.jetbrains.annotations.NotNull; import sun.swing.DefaultLookup; import sun.swing.SwingUtilities2; import sun.swing.UIAction; @@ -251,7 +250,7 @@ public class DarkListUIBridge extends BasicListUI { * * @param map the map */ - public static void loadActionMap(@NotNull final LazyActionMap map) { + public static void loadActionMap(final LazyActionMap map) { map.put(new Actions(Actions.SELECT_PREVIOUS_COLUMN)); map.put(new Actions(Actions.SELECT_PREVIOUS_COLUMN_EXTEND)); map.put(new Actions(Actions.SELECT_PREVIOUS_COLUMN_CHANGE_LEAD)); diff --git a/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuBarBorder.java b/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuBarBorder.java index 7b66ddb8..f4aa1ef8 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuBarBorder.java +++ b/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuBarBorder.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.menu; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.border.Border; import javax.swing.plaf.InsetsUIResource; @@ -43,7 +41,7 @@ public class DarkMenuBarBorder implements Border, UIResource { } @Override - public void paintBorder(final Component c, @NotNull final Graphics g, final int x, final int y, + public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) { g.setColor(borderColor); g.fillRect(x, y + h - 1, w, 1); diff --git a/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuBarUI.java b/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuBarUI.java index 798af601..787ec72d 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuBarUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuBarUI.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.menu; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.metal.MetalMenuBarUI; import java.awt.*; @@ -44,7 +42,7 @@ public class DarkMenuBarUI extends MetalMenuBarUI { } @Override - public void paint(@NotNull final Graphics g, @NotNull final JComponent c) { + public void paint(final Graphics g, final JComponent c) { g.setColor(background); g.fillRect(0, 0, c.getWidth(), c.getHeight()); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java b/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java index 0bfb0aeb..ff79e5c2 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java +++ b/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java @@ -28,8 +28,6 @@ import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; import com.github.weisj.darklaf.util.LazyActionMap; import com.github.weisj.darklaf.util.StringUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.swing.MenuItemLayoutHelper; import sun.swing.SwingUtilities2; import sun.swing.UIAction; @@ -46,13 +44,12 @@ import java.awt.event.ActionEvent; */ public class DarkMenuItemUIBase extends BasicMenuItemUI { - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkMenuItemUIBase(); } - public static void loadActionMap(@NotNull final LazyActionMap map) { + public static void loadActionMap(final LazyActionMap map) { map.put(new Actions(Actions.CLICK)); } @@ -76,7 +73,51 @@ public class DarkMenuItemUIBase extends BasicMenuItemUI { return menuItem.isEnabled() && ((JMenuItem) menuItem).isArmed(); } - protected void paintCheckIcon(final Graphics g, @NotNull final MenuItemLayoutHelper lh, + private static void rightAlignAccText(final MenuItemLayoutHelper lh, + final MenuItemLayoutHelper.LayoutResult lr) { + Rectangle accRect = lr.getAccRect(); + ButtonModel model = lh.getMenuItem().getModel(); + if (model.isEnabled()) { + accRect.x = lh.getViewRect().x + lh.getViewRect().width + - lh.getMenuItem().getIconTextGap() - lr.getAccRect().width; + } + } + + protected void paintMenuItem(final Graphics g, final JComponent c, + final Icon checkIcon, final Icon arrowIcon, + final Color background, final Color foreground, + final int defaultTextIconGap) { + // Save original graphics font and color + Font holdf = g.getFont(); + Color holdc = g.getColor(); + + JMenuItem mi = (JMenuItem) c; + g.setFont(mi.getFont()); + + Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight()); + DarkUIUtil.applyInsets(viewRect, mi.getInsets()); + + MenuItemLayoutHelper lh = new MenuItemLayoutHelper(mi, checkIcon, + arrowIcon, viewRect, defaultTextIconGap, acceleratorDelimiter, + mi.getComponentOrientation().isLeftToRight(), mi.getFont(), + acceleratorFont, MenuItemLayoutHelper.useCheckAndArrow(menuItem), + getPropertyPrefix()); + MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem(); + + paintBackground(g, mi, background); + paintCheckIcon(g, lh, lr, holdc, foreground); + paintIcon(g, lh, lr, holdc); + g.setColor(foreground); + paintText(g, lh, lr); + paintAccText(g, lh, lr); + paintArrowIcon(g, lh, lr, foreground); + + // Restore original graphics font and color + g.setColor(holdc); + g.setFont(holdf); + } + + protected void paintCheckIcon(final Graphics g, final MenuItemLayoutHelper lh, final MenuItemLayoutHelper.LayoutResult lr, final Color holdc, final Color foreground) { if (lh.getCheckIcon() != null) { @@ -95,45 +136,6 @@ public class DarkMenuItemUIBase extends BasicMenuItemUI { } } - protected void paintIcon(final Graphics g, @NotNull final MenuItemLayoutHelper lh, - final MenuItemLayoutHelper.LayoutResult lr, final Color holdc) { - if (lh.getIcon() != null) { - Icon icon; - ButtonModel model = lh.getMenuItem().getModel(); - if (!model.isEnabled()) { - icon = lh.getMenuItem().getDisabledIcon(); - } else if (model.isPressed() && model.isArmed()) { - icon = lh.getMenuItem().getPressedIcon(); - if (icon == null) { - // Use default icon - icon = lh.getMenuItem().getIcon(); - } - } else { - icon = lh.getMenuItem().getIcon(); - } - - if (icon != null) { - icon.paintIcon(lh.getMenuItem(), g, lr.getIconRect().x, lr.getIconRect().y); - g.setColor(holdc); - } - } - } - - protected void paintText(final Graphics g, @NotNull final MenuItemLayoutHelper lh, - final MenuItemLayoutHelper.LayoutResult lr) { - GraphicsContext config = GraphicsUtil.setupAntialiasing(g); - if (!StringUtil.isBlank(lh.getText())) { - if (lh.getHtmlView() != null) { - // Text is HTML - lh.getHtmlView().paint(g, lr.getTextRect()); - } else { - // Text isn't HTML - paintText(g, lh.getMenuItem(), lr.getTextRect(), lh.getText()); - } - } - config.restore(); - } - protected void paintAccText(final Graphics g, final MenuItemLayoutHelper lh, final MenuItemLayoutHelper.LayoutResult lr) { GraphicsContext config = GraphicsUtil.setupAntialiasing(g); @@ -175,7 +177,46 @@ public class DarkMenuItemUIBase extends BasicMenuItemUI { config.restore(); } - protected void paintArrowIcon(final Graphics g, @NotNull final MenuItemLayoutHelper lh, + protected void paintIcon(final Graphics g, final MenuItemLayoutHelper lh, + final MenuItemLayoutHelper.LayoutResult lr, final Color holdc) { + if (lh.getIcon() != null) { + Icon icon; + ButtonModel model = lh.getMenuItem().getModel(); + if (!model.isEnabled()) { + icon = lh.getMenuItem().getDisabledIcon(); + } else if (model.isPressed() && model.isArmed()) { + icon = lh.getMenuItem().getPressedIcon(); + if (icon == null) { + // Use default icon + icon = lh.getMenuItem().getIcon(); + } + } else { + icon = lh.getMenuItem().getIcon(); + } + + if (icon != null) { + icon.paintIcon(lh.getMenuItem(), g, lr.getIconRect().x, lr.getIconRect().y); + g.setColor(holdc); + } + } + } + + protected void paintText(final Graphics g, final MenuItemLayoutHelper lh, + final MenuItemLayoutHelper.LayoutResult lr) { + GraphicsContext config = GraphicsUtil.setupAntialiasing(g); + if (!StringUtil.isBlank(lh.getText())) { + if (lh.getHtmlView() != null) { + // Text is HTML + lh.getHtmlView().paint(g, lr.getTextRect()); + } else { + // Text isn't HTML + paintText(g, lh.getMenuItem(), lr.getTextRect(), lh.getText()); + } + } + config.restore(); + } + + protected void paintArrowIcon(final Graphics g, final MenuItemLayoutHelper lh, final MenuItemLayoutHelper.LayoutResult lr, final Color foreground) { if (lh.getArrowIcon() != null) { @@ -191,52 +232,8 @@ public class DarkMenuItemUIBase extends BasicMenuItemUI { } } - private static void rightAlignAccText(@NotNull final MenuItemLayoutHelper lh, - @NotNull final MenuItemLayoutHelper.LayoutResult lr) { - Rectangle accRect = lr.getAccRect(); - ButtonModel model = lh.getMenuItem().getModel(); - if (model.isEnabled()) { - accRect.x = lh.getViewRect().x + lh.getViewRect().width - - lh.getMenuItem().getIconTextGap() - lr.getAccRect().width; - } - } - - protected void paintMenuItem(@NotNull final Graphics g, final JComponent c, - final Icon checkIcon, final Icon arrowIcon, - final Color background, final Color foreground, - final int defaultTextIconGap) { - // Save original graphics font and color - Font holdf = g.getFont(); - Color holdc = g.getColor(); - - JMenuItem mi = (JMenuItem) c; - g.setFont(mi.getFont()); - - Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight()); - DarkUIUtil.applyInsets(viewRect, mi.getInsets()); - - MenuItemLayoutHelper lh = new MenuItemLayoutHelper(mi, checkIcon, - arrowIcon, viewRect, defaultTextIconGap, acceleratorDelimiter, - mi.getComponentOrientation().isLeftToRight(), mi.getFont(), - acceleratorFont, MenuItemLayoutHelper.useCheckAndArrow(menuItem), - getPropertyPrefix()); - MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem(); - - paintBackground(g, mi, background); - paintCheckIcon(g, lh, lr, holdc, foreground); - paintIcon(g, lh, lr, holdc); - g.setColor(foreground); - paintText(g, lh, lr); - paintAccText(g, lh, lr); - paintArrowIcon(g, lh, lr, foreground); - - // Restore original graphics font and color - g.setColor(holdc); - g.setFont(holdf); - } - @Override - protected void paintBackground(@NotNull final Graphics g, @NotNull final JMenuItem menuItem, final Color bgColor) { + protected void paintBackground(final Graphics g, final JMenuItem menuItem, final Color bgColor) { ButtonModel model = menuItem.getModel(); Color oldColor = g.getColor(); int menuWidth = menuItem.getWidth(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuUI.java b/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuUI.java index ddbcf73e..129800d0 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuUI.java @@ -27,7 +27,6 @@ import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; import com.github.weisj.darklaf.util.StringUtil; -import org.jetbrains.annotations.NotNull; import sun.swing.MenuItemLayoutHelper; import sun.swing.SwingUtilities2; @@ -70,7 +69,51 @@ public class DarkMenuUI extends BasicMenuUI { return menuItem.isEnabled() && ((JMenuItem) menuItem).isArmed(); } - protected void paintCheckIcon(final Graphics g, @NotNull final MenuItemLayoutHelper lh, + private static void rightAlignAccText(final MenuItemLayoutHelper lh, + final MenuItemLayoutHelper.LayoutResult lr) { + Rectangle accRect = lr.getAccRect(); + ButtonModel model = lh.getMenuItem().getModel(); + if (model.isEnabled()) { + accRect.x = lh.getViewRect().x + lh.getViewRect().width + - lh.getMenuItem().getIconTextGap() - lr.getAccRect().width; + } + } + + protected void paintMenuItem(final Graphics g, final JComponent c, + final Icon checkIcon, final Icon arrowIcon, + final Color background, final Color foreground, + final int defaultTextIconGap) { + // Save original graphics font and color + Font holdf = g.getFont(); + Color holdc = g.getColor(); + + JMenuItem mi = (JMenuItem) c; + g.setFont(mi.getFont()); + + Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight()); + DarkUIUtil.applyInsets(viewRect, mi.getInsets()); + + MenuItemLayoutHelper lh = new MenuItemLayoutHelper(mi, checkIcon, + arrowIcon, viewRect, defaultTextIconGap, acceleratorDelimiter, + mi.getComponentOrientation().isLeftToRight(), mi.getFont(), + acceleratorFont, MenuItemLayoutHelper.useCheckAndArrow(menuItem), + getPropertyPrefix()); + MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem(); + + paintBackground(g, mi, background); + paintCheckIcon(g, lh, lr, holdc, foreground); + paintIcon(g, lh, lr, holdc); + g.setColor(foreground); + paintText(g, lh, lr); + paintAccText(g, lh, lr); + paintArrowIcon(g, lh, lr, foreground); + + // Restore original graphics font and color + g.setColor(holdc); + g.setFont(holdf); + } + + protected void paintCheckIcon(final Graphics g, final MenuItemLayoutHelper lh, final MenuItemLayoutHelper.LayoutResult lr, final Color holdc, final Color foreground) { if (lh.getCheckIcon() != null) { @@ -89,45 +132,6 @@ public class DarkMenuUI extends BasicMenuUI { } } - protected void paintIcon(final Graphics g, @NotNull final MenuItemLayoutHelper lh, - final MenuItemLayoutHelper.LayoutResult lr, final Color holdc) { - if (lh.getIcon() != null) { - Icon icon; - ButtonModel model = lh.getMenuItem().getModel(); - if (!model.isEnabled()) { - icon = lh.getMenuItem().getDisabledIcon(); - } else if (model.isPressed() && model.isArmed()) { - icon = lh.getMenuItem().getPressedIcon(); - if (icon == null) { - // Use default icon - icon = lh.getMenuItem().getIcon(); - } - } else { - icon = lh.getMenuItem().getIcon(); - } - - if (icon != null) { - icon.paintIcon(lh.getMenuItem(), g, lr.getIconRect().x, lr.getIconRect().y); - g.setColor(holdc); - } - } - } - - protected void paintText(final Graphics g, @NotNull final MenuItemLayoutHelper lh, - final MenuItemLayoutHelper.LayoutResult lr) { - GraphicsContext config = GraphicsUtil.setupAntialiasing(g); - if (!StringUtil.isBlank(lh.getText())) { - if (lh.getHtmlView() != null) { - // Text is HTML - lh.getHtmlView().paint(g, lr.getTextRect()); - } else { - // Text isn't HTML - paintText(g, lh.getMenuItem(), lr.getTextRect(), lh.getText()); - } - } - config.restore(); - } - protected void paintAccText(final Graphics g, final MenuItemLayoutHelper lh, final MenuItemLayoutHelper.LayoutResult lr) { GraphicsContext config = GraphicsUtil.setupAntialiasing(g); @@ -169,7 +173,46 @@ public class DarkMenuUI extends BasicMenuUI { config.restore(); } - protected void paintArrowIcon(final Graphics g, @NotNull final MenuItemLayoutHelper lh, + protected void paintIcon(final Graphics g, final MenuItemLayoutHelper lh, + final MenuItemLayoutHelper.LayoutResult lr, final Color holdc) { + if (lh.getIcon() != null) { + Icon icon; + ButtonModel model = lh.getMenuItem().getModel(); + if (!model.isEnabled()) { + icon = lh.getMenuItem().getDisabledIcon(); + } else if (model.isPressed() && model.isArmed()) { + icon = lh.getMenuItem().getPressedIcon(); + if (icon == null) { + // Use default icon + icon = lh.getMenuItem().getIcon(); + } + } else { + icon = lh.getMenuItem().getIcon(); + } + + if (icon != null) { + icon.paintIcon(lh.getMenuItem(), g, lr.getIconRect().x, lr.getIconRect().y); + g.setColor(holdc); + } + } + } + + protected void paintText(final Graphics g, final MenuItemLayoutHelper lh, + final MenuItemLayoutHelper.LayoutResult lr) { + GraphicsContext config = GraphicsUtil.setupAntialiasing(g); + if (!StringUtil.isBlank(lh.getText())) { + if (lh.getHtmlView() != null) { + // Text is HTML + lh.getHtmlView().paint(g, lr.getTextRect()); + } else { + // Text isn't HTML + paintText(g, lh.getMenuItem(), lr.getTextRect(), lh.getText()); + } + } + config.restore(); + } + + protected void paintArrowIcon(final Graphics g, final MenuItemLayoutHelper lh, final MenuItemLayoutHelper.LayoutResult lr, final Color foreground) { if (lh.getArrowIcon() != null) { @@ -185,52 +228,8 @@ public class DarkMenuUI extends BasicMenuUI { } } - private static void rightAlignAccText(@NotNull final MenuItemLayoutHelper lh, - @NotNull final MenuItemLayoutHelper.LayoutResult lr) { - Rectangle accRect = lr.getAccRect(); - ButtonModel model = lh.getMenuItem().getModel(); - if (model.isEnabled()) { - accRect.x = lh.getViewRect().x + lh.getViewRect().width - - lh.getMenuItem().getIconTextGap() - lr.getAccRect().width; - } - } - - protected void paintMenuItem(@NotNull final Graphics g, final JComponent c, - final Icon checkIcon, final Icon arrowIcon, - final Color background, final Color foreground, - final int defaultTextIconGap) { - // Save original graphics font and color - Font holdf = g.getFont(); - Color holdc = g.getColor(); - - JMenuItem mi = (JMenuItem) c; - g.setFont(mi.getFont()); - - Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight()); - DarkUIUtil.applyInsets(viewRect, mi.getInsets()); - - MenuItemLayoutHelper lh = new MenuItemLayoutHelper(mi, checkIcon, - arrowIcon, viewRect, defaultTextIconGap, acceleratorDelimiter, - mi.getComponentOrientation().isLeftToRight(), mi.getFont(), - acceleratorFont, MenuItemLayoutHelper.useCheckAndArrow(menuItem), - getPropertyPrefix()); - MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem(); - - paintBackground(g, mi, background); - paintCheckIcon(g, lh, lr, holdc, foreground); - paintIcon(g, lh, lr, holdc); - g.setColor(foreground); - paintText(g, lh, lr); - paintAccText(g, lh, lr); - paintArrowIcon(g, lh, lr, foreground); - - // Restore original graphics font and color - g.setColor(holdc); - g.setFont(holdf); - } - @Override - protected void paintBackground(@NotNull final Graphics g, @NotNull final JMenuItem menuItem, final Color bgColor) { + protected void paintBackground(final Graphics g, final JMenuItem menuItem, final Color bgColor) { ButtonModel model = menuItem.getModel(); Color oldColor = g.getColor(); int menuWidth = menuItem.getWidth(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java b/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java index 112d6d29..d413e47e 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/numberingpane/DarkNumberingPaneUI.java @@ -30,8 +30,6 @@ import com.github.weisj.darklaf.components.text.NumberingPane; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -69,8 +67,7 @@ public class DarkNumberingPaneUI extends ComponentUI { protected int maxIconWidth = 0; protected Color oldBackground; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkNumberingPaneUI(); } @@ -149,7 +146,7 @@ public class DarkNumberingPaneUI extends ComponentUI { } @Override - public void paint(final Graphics g, @NotNull final JComponent c) { + public void paint(final Graphics g, final JComponent c) { if (c.isOpaque()) { g.setColor(c.getBackground()); g.fillRect(0, 0, c.getWidth(), c.getHeight()); @@ -185,7 +182,7 @@ public class DarkNumberingPaneUI extends ComponentUI { return new Dimension(maxIconWidth + pad + textWidth, viewport.getView().getHeight()); } - protected int drawHighlightBackground(@NotNull final Graphics g, final int currOffset) { + protected int drawHighlightBackground(final Graphics g, final int currOffset) { g.setColor(backgroundHighlight); Rectangle rect; try { @@ -197,8 +194,8 @@ public class DarkNumberingPaneUI extends ComponentUI { return rect.y; } - protected void drawNumbering(@NotNull final Graphics g, final int startLine, final int endLine, final int yCur, - @NotNull final Element root, final int descent) { + protected void drawNumbering(final Graphics g, final int startLine, final int endLine, final int yCur, + final Element root, final int descent) { GraphicsContext config = GraphicsUtil.setupAntialiasing(g); g.setColor(numberingPane.getForeground()); int digits = String.valueOf(root.getElementCount()).length(); @@ -214,7 +211,7 @@ public class DarkNumberingPaneUI extends ComponentUI { config.restore(); } - protected void paintIcons(final Graphics g, final int startLine, final int endLine, @NotNull final Element root) { + protected void paintIcons(final Graphics g, final int startLine, final int endLine, final Element root) { List> icons = numberingPane.getIconsInRange(root.getElement(startLine).getStartOffset(), root.getElement(endLine).getEndOffset()); for (Map.Entry icon : icons) { @@ -323,7 +320,7 @@ public class DarkNumberingPaneUI extends ComponentUI { } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if ("caret".equals(key)) { if (evt.getNewValue() instanceof Caret) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/optionpane/DarkOptionPaneUI.java b/src/main/java/com/github/weisj/darklaf/ui/optionpane/DarkOptionPaneUI.java index e0524455..82289457 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/optionpane/DarkOptionPaneUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/optionpane/DarkOptionPaneUI.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.optionpane; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.swing.DefaultLookup; import javax.swing.*; @@ -36,8 +34,6 @@ import java.awt.*; public class DarkOptionPaneUI extends BasicOptionPaneUI { - @NotNull - @Contract("_ -> new") public static ComponentUI createUI(final JComponent x) { return new DarkOptionPaneUI(); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/panel/DarkPanelUI.java b/src/main/java/com/github/weisj/darklaf/ui/panel/DarkPanelUI.java index 4036a124..c9e2cf9e 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/panel/DarkPanelUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/panel/DarkPanelUI.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.panel; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicPanelUI; @@ -35,8 +32,7 @@ import javax.swing.plaf.basic.BasicPanelUI; */ public class DarkPanelUI extends BasicPanelUI { - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkPanelUI(); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuBorder.java b/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuBorder.java index 3ea9b90d..431c46bd 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuBorder.java +++ b/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuBorder.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.ui.popupmenu; import com.github.weisj.darklaf.components.border.MutableLineBorder; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.InsetsUIResource; @@ -41,12 +40,12 @@ public class DarkPopupMenuBorder extends MutableLineBorder implements UIResource } @Override - public void paintBorder(final Component c, @NotNull final Graphics g, final int x, final int y, final int width, final int height) { + public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { setColor(UIManager.getDefaults().getColor("PopupMenu.borderColor")); super.paintBorder(c, g, x, y, width, height); } - @NotNull + @Override public Insets getBorderInsets(final Component c) { return new InsetsUIResource(1, 1, 1, 1); diff --git a/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuSeparatorUI.java b/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuSeparatorUI.java index c7408982..ff176466 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuSeparatorUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuSeparatorUI.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.popupmenu; import com.github.weisj.darklaf.ui.separator.DarkSeparatorUI; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -36,15 +34,14 @@ import java.awt.*; */ public class DarkPopupMenuSeparatorUI extends DarkSeparatorUI { - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkPopupMenuSeparatorUI(); } @Override - public void paint(@NotNull final Graphics g, @NotNull final JComponent c) { + public void paint(final Graphics g, final JComponent c) { Dimension s = c.getSize(); g.setColor(UIManager.getDefaults().getColor("PopupMenu.borderColor")); g.fillRect(0, 0, s.width, 1); diff --git a/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java b/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java index bf3832a6..c2a37ef1 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.popupmenu; import com.github.weisj.darklaf.util.ReflectionUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.awt.AppContext; import sun.awt.SunToolkit; @@ -63,13 +61,12 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI { public static final StringBuilder MOUSE_GRABBER_KEY = new StringBuilder( "javax.swing.plaf.basic.BasicPopupMenuUI.MouseGrabber"); - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent x) { return new DarkPopupMenuUI(); } - @NotNull + static List getPopups() { MenuSelectionManager msm = MenuSelectionManager.defaultManager(); MenuElement[] p = msm.getSelectedPath(); @@ -138,7 +135,7 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI { } } - void grabWindow(@NotNull final MenuElement[] newPath) { + void grabWindow(final MenuElement[] newPath) { // A grab needs to be added final Toolkit tk = Toolkit.getDefaultToolkit(); java.security.AccessController.doPrivileged( @@ -377,12 +374,12 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI { protected static class StringBufferWrapper { private final StringBuffer buffer; - @Contract(pure = true) + protected StringBufferWrapper(final StringBuffer buffer) { this.buffer = buffer; } - @Contract(value = "null -> false", pure = true) + @Override public boolean equals(final Object obj) { if (obj instanceof StringBuffer) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarUI.java b/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarUI.java index b101923c..dc4f2734 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/progressbar/DarkProgressBarUI.java @@ -26,8 +26,6 @@ package com.github.weisj.darklaf.ui.progressbar; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -59,8 +57,7 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha private Color passedColor; private Color passedEndColor; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkProgressBarUI(); } @@ -99,7 +96,7 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha } @Override - protected void paintIndeterminate(@NotNull final Graphics g, @NotNull final JComponent c) { + protected void paintIndeterminate(final Graphics g, final JComponent c) { Graphics2D g2 = (Graphics2D) g.create(); try { @@ -183,11 +180,11 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha } } - protected static boolean hasFailed(@NotNull final JComponent c) { + protected static boolean hasFailed(final JComponent c) { return Boolean.TRUE.equals(c.getClientProperty("JProgressBar.failed")); } - protected static boolean hasPassed(@NotNull final JComponent c) { + protected static boolean hasPassed(final JComponent c) { return Boolean.TRUE.equals(c.getClientProperty("JProgressBar.passed")); } @@ -199,14 +196,43 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha return indeterminateEndColor; } - @NotNull - @Contract("_, _, _, _, _ -> new") + private Shape getShapedRect(final float x, final float y, final float w, final float h, final float ar) { return new RoundRectangle2D.Float(x, y, w, h, ar, ar); } + private void paintString(final Graphics2D g, final int x, final int y, + final int w, final int h, final int fillStart, final int amountFull) { + GraphicsContext config = GraphicsUtil.setupAntialiasing(g); + String progressString = progressBar.getString(); + g.setFont(progressBar.getFont()); + Point renderLocation = getStringPlacement(g, progressString, x, y, w, h); + + if (progressBar.getOrientation() == SwingConstants.HORIZONTAL) { + g.setColor(getSelectionBackground()); + g.drawString(progressString, renderLocation.x, renderLocation.y); + + g.setColor(getSelectionForeground()); + g.clipRect(fillStart, y, amountFull, h); + g.drawString(progressString, renderLocation.x, renderLocation.y); + + } else { // VERTICAL + AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2); + g.setFont(progressBar.getFont().deriveFont(rotate)); + renderLocation = getStringPlacement(g, progressString, x, y, w, h); + + g.setColor(getSelectionBackground()); + g.drawString(progressString, renderLocation.x, renderLocation.y); + + g.clipRect(x, fillStart, w, amountFull); + g.setColor(getSelectionForeground()); + g.drawString(progressString, renderLocation.x, renderLocation.y); + } + config.restore(); + } + @Override - protected void paintDeterminate(@NotNull final Graphics g, final JComponent c) { + protected void paintDeterminate(final Graphics g, final JComponent c) { Graphics2D g2 = (Graphics2D) g.create(); try { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -275,36 +301,6 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha } } - private void paintString(@NotNull final Graphics2D g, final int x, final int y, - final int w, final int h, final int fillStart, final int amountFull) { - GraphicsContext config = GraphicsUtil.setupAntialiasing(g); - String progressString = progressBar.getString(); - g.setFont(progressBar.getFont()); - Point renderLocation = getStringPlacement(g, progressString, x, y, w, h); - - if (progressBar.getOrientation() == SwingConstants.HORIZONTAL) { - g.setColor(getSelectionBackground()); - g.drawString(progressString, renderLocation.x, renderLocation.y); - - g.setColor(getSelectionForeground()); - g.clipRect(fillStart, y, amountFull, h); - g.drawString(progressString, renderLocation.x, renderLocation.y); - - } else { // VERTICAL - AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2); - g.setFont(progressBar.getFont().deriveFont(rotate)); - renderLocation = getStringPlacement(g, progressString, x, y, w, h); - - g.setColor(getSelectionBackground()); - g.drawString(progressString, renderLocation.x, renderLocation.y); - - g.clipRect(x, fillStart, w, amountFull); - g.setColor(getSelectionForeground()); - g.drawString(progressString, renderLocation.x, renderLocation.y); - } - config.restore(); - } - protected Color getRemainderColor() { return trackColor; } @@ -342,7 +338,7 @@ public class DarkProgressBarUI extends BasicProgressBarUI implements PropertyCha } } - @Contract(pure = true) + private static boolean isSimplified() { return UIManager.getBoolean("ProgressBar.isSimplified"); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonMenuItemUI.java b/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonMenuItemUI.java index aba7f1a4..5e9734f2 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonMenuItemUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonMenuItemUI.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.ui.radiobutton; import com.github.weisj.darklaf.decorators.MouseClickListener; import com.github.weisj.darklaf.ui.menu.DarkMenuItemUIBase; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.swing.MenuItemLayoutHelper; import javax.swing.*; @@ -48,8 +46,7 @@ public class DarkRadioButtonMenuItemUI extends DarkMenuItemUIBase { private Icon radioSelectedDisabledIcon; private Icon radioSelectedFocusedIcon; - @NotNull - @Contract(value = "_ -> new", pure = true) + public static ComponentUI createUI(final JComponent c) { return new DarkRadioButtonMenuItemUI(); } @@ -64,14 +61,14 @@ public class DarkRadioButtonMenuItemUI extends DarkMenuItemUIBase { } @Override - protected void paintCheckIcon(final Graphics g2, @NotNull final MenuItemLayoutHelper lh, - @NotNull final MenuItemLayoutHelper.LayoutResult lr, + protected void paintCheckIcon(final Graphics g2, final MenuItemLayoutHelper lh, + final MenuItemLayoutHelper.LayoutResult lr, final Color holdc, final Color foreground) { Rectangle rect = lr.getCheckRect(); getRadioIcon(lh.getMenuItem()).paintIcon(lh.getMenuItem(), g2, rect.x, rect.y); } - protected Icon getRadioIcon(@NotNull final AbstractButton b) { + protected Icon getRadioIcon(final AbstractButton b) { boolean selected = b.isSelected(); boolean enabled = b.isEnabled(); boolean hasFocus = b.hasFocus(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java b/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java index 867659de..60b5a79f 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java @@ -28,8 +28,6 @@ import com.github.weisj.darklaf.ui.checkbox.DarkCheckBoxUI; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -74,8 +72,7 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha private Icon radioSelectedDisabledIcon; private Icon radioSelectedFocusedIcon; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkRadioButtonUI(); } @@ -116,7 +113,7 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha } @Override - public synchronized void paint(final Graphics g2d, @NotNull final JComponent c) { + public synchronized void paint(final Graphics g2d, final JComponent c) { Graphics2D g = (Graphics2D) g2d; AbstractButton b = (AbstractButton) c; @@ -157,7 +154,7 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha button.removePropertyChangeListener(this); } - protected String layoutRadioButton(@NotNull final AbstractButton b, final FontMetrics fm) { + protected String layoutRadioButton(final AbstractButton b, final FontMetrics fm) { Insets i = b.getInsets(); size = b.getSize(size); viewRect.x = i.left; @@ -178,14 +175,14 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha return text; } - private void paintBackground(@NotNull final JComponent c, final Graphics2D g) { + private void paintBackground(final JComponent c, final Graphics2D g) { if (c.isOpaque()) { g.setColor(c.getBackground()); g.fillRect(0, 0, c.getWidth(), c.getHeight()); } } - protected Icon getRadioIcon(@NotNull final AbstractButton b) { + protected Icon getRadioIcon(final AbstractButton b) { boolean selected = b.isSelected(); boolean enabled = b.isEnabled(); boolean hasFocus = b.hasFocus(); @@ -195,7 +192,7 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha : radioDisabledIcon; } - protected void paintDarkBullet(final JComponent c, final Graphics2D g, @NotNull final AbstractButton b) { + protected void paintDarkBullet(final JComponent c, final Graphics2D g, final AbstractButton b) { GraphicsContext config = GraphicsUtil.setupStrokePainting(g); boolean enabled = b.isEnabled(); g.translate(iconRect.x + ICON_OFF, iconRect.y + ICON_OFF); @@ -214,7 +211,7 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha return new IconUIResource(EmptyIcon.create(20)); } - protected void paintCheckBorder(@NotNull final Graphics2D g, final boolean enabled, final boolean focus, + protected void paintCheckBorder(final Graphics2D g, final boolean enabled, final boolean focus, final boolean selected) { Graphics2D g2 = (Graphics2D) g.create(); Color bgColor = getFillColor(selected, enabled); @@ -233,7 +230,7 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha g2.dispose(); } - protected void paintCheckBullet(@NotNull final Graphics2D g, final boolean enabled, final boolean focus) { + protected void paintCheckBullet(final Graphics2D g, final boolean enabled, final boolean focus) { Color color = getCheckColor(focus, enabled); g.setColor(color); g.translate(0.2, 0.2); @@ -266,7 +263,7 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if ("componentOrientation".equals(key)) { radioButton.repaint(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/rootpane/CloseButtonUI.java b/src/main/java/com/github/weisj/darklaf/ui/rootpane/CloseButtonUI.java index 14ea45ae..5adf62d2 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/rootpane/CloseButtonUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/rootpane/CloseButtonUI.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.ui.rootpane; import com.github.weisj.darklaf.ui.button.DarkButtonUI; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -45,7 +44,7 @@ public class CloseButtonUI extends DarkButtonUI { } @Override - protected Color getShadowColor(@NotNull final AbstractButton c) { + protected Color getShadowColor(final AbstractButton c) { return c.getModel().isArmed() ? closeClick : closeHover; } } diff --git a/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java b/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java index 47ebd3a9..1c824805 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.ui.rootpane; import com.github.weisj.darklaf.platform.windows.JNIDecorations; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -53,8 +51,6 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener private PropertyChangeListener propertyChangeListener; - @NotNull - @Contract("_ -> new") public static ComponentUI createUI(final JComponent comp) { return new DarkRootPaneUI(); } @@ -159,7 +155,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener } } - public void installBorder(@NotNull final JRootPane root) { + public void installBorder(final JRootPane root) { int style = root.getWindowDecorationStyle(); if (style == JRootPane.NONE) { LookAndFeel.uninstallBorder(root); @@ -172,7 +168,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener return new DarkTitlePane(root); } - private void setTitlePane(@NotNull final JRootPane root, final DarkTitlePane titlePane) { + private void setTitlePane(final JRootPane root, final DarkTitlePane titlePane) { JLayeredPane layeredPane = root.getLayeredPane(); JComponent oldTitlePane = getTitlePane(); @@ -202,7 +198,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener root.setLayout(layoutManager); } - @Contract(pure = true) + protected JComponent getTitlePane() { return titlePane; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java b/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java index 17fa2eb2..487a05e5 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java +++ b/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java @@ -28,9 +28,6 @@ import com.github.weisj.darklaf.decorators.AncestorAdapter; import com.github.weisj.darklaf.icons.ScaledIcon; import com.github.weisj.darklaf.platform.windows.JNIDecorations; import com.github.weisj.darklaf.util.Scale; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import sun.awt.SunToolkit; import javax.accessibility.AccessibleContext; @@ -60,19 +57,23 @@ public class DarkTitlePane extends JComponent { private static final int ICON_WIDTH = 32; private static final int ICON_SIZE = ICON_WIDTH - 3 * PAD; private final JRootPane rootPane; - private final ContainerListener rootPaneContainerListener = new ContainerListener() { + private final ContainerListener layeredPaneContainerListener = new ContainerListener() { @Override - public void componentAdded(@NotNull final ContainerEvent e) { - if (e.getChild() instanceof JLayeredPane) { - ((JLayeredPane) e.getChild()).addContainerListener(layeredPaneContainerListener); + public void componentAdded(final ContainerEvent e) { + if (e.getChild() instanceof JMenuBar) { + menuBar = getRootPane().getJMenuBar(); + //Otherwise a white bar will appear where the menuBar used to be. + menuBar.setPreferredSize(new Dimension(0, 0)); + add(menuBar); + } + if (getRootPane().getJMenuBar() == null && menuBar != null) { + remove(menuBar); + menuBar = null; } } @Override - public void componentRemoved(@NotNull final ContainerEvent e) { - if (e.getChild() instanceof JLayeredPane) { - ((JLayeredPane) e.getChild()).removeContainerListener(layeredPaneContainerListener); - } + public void componentRemoved(final ContainerEvent e) { } }; private boolean oldResizable; @@ -109,23 +110,19 @@ public class DarkTitlePane extends JComponent { }; private long windowHandle; private JMenuBar menuBar; - private final ContainerListener layeredPaneContainerListener = new ContainerListener() { + private final ContainerListener rootPaneContainerListener = new ContainerListener() { @Override - public void componentAdded(@NotNull final ContainerEvent e) { - if (e.getChild() instanceof JMenuBar) { - menuBar = getRootPane().getJMenuBar(); - //Otherwise a white bar will appear where the menuBar used to be. - menuBar.setPreferredSize(new Dimension(0, 0)); - add(menuBar); - } - if (getRootPane().getJMenuBar() == null && menuBar != null) { - remove(menuBar); - menuBar = null; + public void componentAdded(final ContainerEvent e) { + if (e.getChild() instanceof JLayeredPane) { + ((JLayeredPane) e.getChild()).addContainerListener(layeredPaneContainerListener); } } @Override public void componentRemoved(final ContainerEvent e) { + if (e.getChild() instanceof JLayeredPane) { + ((JLayeredPane) e.getChild()).removeContainerListener(layeredPaneContainerListener); + } } }; private int state; @@ -148,12 +145,12 @@ public class DarkTitlePane extends JComponent { setLayout(createLayout()); } - @NotNull + private static JButton createButton(final String accessibleName, final Icon icon, final Action action) { return createButton(accessibleName, icon, action, false); } - @NotNull + private static JButton createButton(final String accessibleName, final Icon icon, final Action action, final boolean close) { JButton button; @@ -241,14 +238,12 @@ public class DarkTitlePane extends JComponent { addAncestorListener(ancestorListener); } - @NotNull - @Contract(" -> new") + private WindowListener createWindowListener() { return new DarkTitlePane.WindowHandler(); } - @NotNull - @Contract(value = " -> new", pure = true) + private PropertyChangeListener createWindowPropertyChangeListener() { return new PropertyChangeHandler(); } @@ -328,7 +323,7 @@ public class DarkTitlePane extends JComponent { return windowIconButton; } - @NotNull + private JPopupMenu createMenu() { JPopupMenu menu = new JPopupMenu(); if (getWindowDecorationStyle() == JRootPane.FRAME) { @@ -337,7 +332,7 @@ public class DarkTitlePane extends JComponent { return menu; } - private void addMenuItems(@NotNull final JPopupMenu menu) { + private void addMenuItems(final JPopupMenu menu) { menu.add(new JMenuItem(restoreAction) {{ setDisabledIcon(restoreIcon); }}); @@ -362,7 +357,7 @@ public class DarkTitlePane extends JComponent { } } - @Contract(pure = true) + private Window getWindow() { return window; } @@ -409,8 +404,7 @@ public class DarkTitlePane extends JComponent { } } - @NotNull - @Contract(value = " -> new", pure = true) + private LayoutManager createLayout() { return new TitlePaneLayout(); } @@ -461,8 +455,7 @@ public class DarkTitlePane extends JComponent { return rootPane; } - @Nullable - @Contract(pure = true) + private Frame getFrame() { Window window = getWindow(); @@ -543,7 +536,7 @@ public class DarkTitlePane extends JComponent { } } - protected boolean isResizable(final Window window, @NotNull final JRootPane rootPane) { + protected boolean isResizable(final Window window, final JRootPane rootPane) { if (JRootPane.NONE == rootPane.getWindowDecorationStyle()) { return false; } else { @@ -747,7 +740,7 @@ public class DarkTitlePane extends JComponent { } protected class PropertyChangeHandler implements PropertyChangeListener { - public void propertyChange(@NotNull final PropertyChangeEvent pce) { + public void propertyChange(final PropertyChangeEvent pce) { String name = pce.getPropertyName(); if ("resizable".equals(name) || "state".equals(name)) { Frame frame = getFrame(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/rootpane/SubstanceRootLayout.java b/src/main/java/com/github/weisj/darklaf/ui/rootpane/SubstanceRootLayout.java index daa89a81..20d15fd5 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/rootpane/SubstanceRootLayout.java +++ b/src/main/java/com/github/weisj/darklaf/ui/rootpane/SubstanceRootLayout.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.rootpane; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; @@ -40,7 +38,7 @@ class SubstanceRootLayout implements LayoutManager2 { public void removeLayoutComponent(final Component comp) { } - public Dimension preferredLayoutSize(@NotNull final Container parent) { + public Dimension preferredLayoutSize(final Container parent) { Dimension cpd, mbd, tpd; int cpWidth = 0; int cpHeight = 0; @@ -86,7 +84,7 @@ class SubstanceRootLayout implements LayoutManager2 { cpHeight + mbHeight + tpHeight + i.top + i.bottom); } - public Dimension minimumLayoutSize(@NotNull final Container parent) { + public Dimension minimumLayoutSize(final Container parent) { Dimension cpd, mbd, tpd; int cpWidth = 0; int cpHeight = 0; @@ -174,7 +172,7 @@ class SubstanceRootLayout implements LayoutManager2 { public void addLayoutComponent(final Component comp, final Object constraints) { } - public Dimension maximumLayoutSize(@NotNull final Container target) { + public Dimension maximumLayoutSize(final Container target) { Dimension cpd, mbd, tpd; int cpWidth = Integer.MAX_VALUE; int cpHeight = Integer.MAX_VALUE; diff --git a/src/main/java/com/github/weisj/darklaf/ui/rootpane/TitlePaneIcon.java b/src/main/java/com/github/weisj/darklaf/ui/rootpane/TitlePaneIcon.java index abf4a621..dd6e6b4c 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/rootpane/TitlePaneIcon.java +++ b/src/main/java/com/github/weisj/darklaf/ui/rootpane/TitlePaneIcon.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.rootpane; -import org.jetbrains.annotations.Contract; - import javax.swing.*; import java.awt.*; @@ -37,7 +35,7 @@ public class TitlePaneIcon implements Icon { private final Icon inactiveIcon; private boolean active = true; - @Contract(pure = true) + public TitlePaneIcon(final Icon active, final Icon inactive) { this.activeIcon = active; this.inactiveIcon = inactive; @@ -52,7 +50,7 @@ public class TitlePaneIcon implements Icon { currentIcon().paintIcon(c, g, x, y); } - @Contract(pure = true) + private Icon currentIcon() { return active ? activeIcon : inactiveIcon; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarUI.java b/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarUI.java index bc79e8bf..c2a41280 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarUI.java @@ -26,8 +26,6 @@ package com.github.weisj.darklaf.ui.scrollpane; import com.github.weisj.darklaf.decorators.MouseMovementListener; import com.github.weisj.darklaf.util.Animator; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -109,7 +107,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { }; private final AdjustmentListener adjustmentListener = new AdjustmentListener() { @Override - public void adjustmentValueChanged(@NotNull final AdjustmentEvent e) { + public void adjustmentValueChanged(final AdjustmentEvent e) { if (!e.getValueIsAdjusting()) return; JScrollBar scrollBar = (JScrollBar) e.getAdjustable(); @@ -130,7 +128,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { private final MouseListener mouseListener = new MouseAdapter() { @Override - public void mouseReleased(@NotNull final MouseEvent e) { + public void mouseReleased(final MouseEvent e) { if (!getTrackBounds().contains(e.getPoint())) { mouseOverTrack = false; resetTrackAnimator(); @@ -166,15 +164,14 @@ public class DarkScrollBarUI extends BasicScrollBarUI { } }; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkScrollBarUI(); } @SuppressWarnings("MagicConstant") - public static void doScroll(@NotNull final JScrollBar toScroll, final JViewport vp, - @NotNull final MouseWheelEvent e, final boolean leftToRight) { + public static void doScroll(final JScrollBar toScroll, final JViewport vp, + final MouseWheelEvent e, final boolean leftToRight) { int direction = e.getWheelRotation() < 0 ? -1 : 1; int orientation = toScroll.getOrientation(); if (!leftToRight && orientation == JScrollBar.HORIZONTAL) { @@ -325,7 +322,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { } } - static void scrollByBlock(@NotNull final JScrollBar scrollbar, final int direction) { + static void scrollByBlock(final JScrollBar scrollbar, final int direction) { // This method is called from BasicScrollPaneUI to implement wheel // scrolling, and also from scrollByBlock(). int oldValue = scrollbar.getValue(); @@ -436,7 +433,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { return new EmptyButton(); } - protected void paintTrack(@NotNull final Graphics g, @NotNull final JComponent c, @NotNull final Rectangle bounds) { + protected void paintTrack(final Graphics g, final JComponent c, final Rectangle bounds) { if (c.isOpaque()) { g.setColor(scrollbar.getBackground()); g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); @@ -448,13 +445,13 @@ public class DarkScrollBarUI extends BasicScrollBarUI { g2.dispose(); } - protected void paintThumb(@NotNull final Graphics g, final JComponent c, @NotNull final Rectangle thumbBounds) { + protected void paintThumb(final Graphics g, final JComponent c, final Rectangle thumbBounds) { if (!thumbBounds.isEmpty() && scrollbar.isEnabled()) { paintMaxiThumb((Graphics2D) g, thumbBounds); } } - protected void paintMaxiThumb(@NotNull final Graphics2D g, @NotNull final Rectangle rect) { + protected void paintMaxiThumb(final Graphics2D g, final Rectangle rect) { final Composite c = g.getComposite(); g.setComposite(COMPOSITE.derive(THUMB_ALPHA)); Color thumbColor = getThumbColor(); @@ -466,7 +463,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { g.setComposite(c); } - @NotNull + private Color getThumbColor() { return DarkUIUtil.blendColors(thumbFadeEndColor, thumbFadeStartColor, thumbAlpha); } @@ -492,8 +489,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { return true; } - @NotNull - @Contract(value = " -> new", pure = true) + protected Color getTrackColor() { return trackBackground; } @@ -515,8 +511,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { return scrollbar.getClientProperty("ScrollBar.thin") == Boolean.TRUE; } - @NotNull - @Contract(" -> new") + private Animator createTrackFadeoutAnimator() { return new Animator("Track fadeout", FADEOUT_FRAMES_COUNT, FADEOUT_FRAMES_COUNT * FADEOUT_FRAME_COUNT_FACTOR, false) { @@ -540,8 +535,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { }; } - @NotNull - @Contract(" -> new") + private Animator createThumbFadeoutAnimator() { return new Animator("Adjustment fadeout", FADEOUT_FRAMES_COUNT, FADEOUT_FRAMES_COUNT * FADEOUT_FRAME_COUNT_FACTOR, false) { @@ -566,8 +560,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { }; } - @NotNull - @Contract(" -> new") + private Animator createTrackFadeinAnimator() { return new Animator("Track fadein", FADEIN_FRAMES_COUNT, FADEIN_FRAMES_COUNT * FADEIN_FRAME_COUNT_FACTOR, false) { @@ -588,8 +581,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { }; } - @NotNull - @Contract(" -> new") + private Animator createThumbFadeinAnimator() { return new Animator("Adjustment fadein", FADEIN_FRAMES_COUNT / 2, FADEIN_FRAMES_COUNT * FADEIN_FRAME_COUNT_FACTOR, false) { @@ -621,7 +613,7 @@ public class DarkScrollBarUI extends BasicScrollBarUI { resetAnimators(thumbFadeinAnimator, thumbFadeoutAnimator, mouseOverThumb, thumbAlpha, MAX_THUMB_ALPHA); } - private void resetAnimators(@NotNull final Animator fadeInAnimator, @NotNull final Animator fadeOutAnimator, + private void resetAnimators(final Animator fadeInAnimator, final Animator fadeOutAnimator, final boolean overAnimatedComponent, final float currentAlpha, final float maxAlpha) { fadeInAnimator.reset(); fadeOutAnimator.reset(); @@ -654,22 +646,19 @@ public class DarkScrollBarUI extends BasicScrollBarUI { setRequestFocusEnabled(false); } - @NotNull - @Contract(pure = true) + @Override public Dimension getPreferredSize() { return getMaximumSize(); } - @NotNull - @Contract(value = " -> new", pure = true) + @Override public Dimension getMaximumSize() { return new Dimension(0, 0); } - @NotNull - @Contract(pure = true) + @Override public Dimension getMinimumSize() { return getMaximumSize(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java b/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java index 44e3edac..ed240764 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollPaneUI.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.scrollpane; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollPaneUI; @@ -96,8 +93,7 @@ public class DarkScrollPaneUI extends BasicScrollPaneUI { }; private ScrollPaneLayout oldLayout; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkScrollPaneUI(); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollLayoutManagerDelegate.java b/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollLayoutManagerDelegate.java index 8255a660..33e8ce7b 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollLayoutManagerDelegate.java +++ b/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollLayoutManagerDelegate.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.scrollpane; -import org.jetbrains.annotations.Contract; - import javax.swing.*; import java.awt.*; @@ -34,7 +32,7 @@ import java.awt.*; public class ScrollLayoutManagerDelegate extends ScrollPaneLayout { private final ScrollPaneLayout delegate; - @Contract(pure = true) + public ScrollLayoutManagerDelegate(final ScrollPaneLayout delegate) { if (delegate == null) { throw new IllegalArgumentException("Delegate is null"); diff --git a/src/main/java/com/github/weisj/darklaf/ui/separator/DarkSeparatorUI.java b/src/main/java/com/github/weisj/darklaf/ui/separator/DarkSeparatorUI.java index efa87e82..6d9b1541 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/separator/DarkSeparatorUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/separator/DarkSeparatorUI.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.separator; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicSeparatorUI; @@ -36,13 +33,12 @@ import java.awt.*; */ public class DarkSeparatorUI extends BasicSeparatorUI { - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkSeparatorUI(); } - public void paint(final Graphics g, @NotNull final JComponent c) { + public void paint(final Graphics g, final JComponent c) { Dimension s = c.getSize(); g.setColor(UIManager.getDefaults().getColor("Separator.foreground")); diff --git a/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java b/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java index 96b7a729..55902609 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java @@ -27,8 +27,6 @@ import com.github.weisj.darklaf.decorators.MouseClickListener; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -102,8 +100,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene super(b); } - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkSliderUI((JSlider) c); } @@ -205,7 +202,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene } @Override - public void paint(@NotNull final Graphics g2, final JComponent c) { + public void paint(final Graphics g2, final JComponent c) { super.paint(g2, c); if (showVolumeIcon(c)) { getVolumeIcon().paintIcon(c, g2, iconRect.x, iconRect.y); @@ -326,7 +323,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene } } - @NotNull + protected Color getDisabledTickColor() { return inactiveTickForeground; } @@ -364,8 +361,24 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene } } - private static boolean isVolumeSlider(@NotNull final JComponent c) { - return "volume".equals(c.getClientProperty("Slider.variant")); + private Area getHorizontalSliderShape(final Area track) { + double x = thumbRect.x + thumbRect.width / 2.0; + Area leftArea = new Area(new Rectangle2D.Double(0, 0, x, slider.getHeight())); + Area rightArea = new Area(new Rectangle2D.Double(x, 0, slider.getWidth() - x, slider.getHeight())); + if (slider.getComponentOrientation().isLeftToRight()) { + if (slider.getInverted()) { + track.intersect(rightArea); + } else { + track.intersect(leftArea); + } + } else { + if (!slider.getInverted()) { + track.intersect(rightArea); + } else { + track.intersect(leftArea); + } + } + return track; } protected Icon getVolumeIcon() { @@ -390,8 +403,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene return slider.getOrientation() == JSlider.HORIZONTAL; } - @NotNull - @Contract(" -> new") + private Area getHorizontalTrackShape() { int arc = arcSize; int yOff = (trackRect.height / 2) - trackSize / 2; @@ -405,30 +417,17 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene } } - @Contract("_ -> param1") - @NotNull - private Area getHorizontalSliderShape(@NotNull final Area track) { - double x = thumbRect.x + thumbRect.width / 2.0; - Area leftArea = new Area(new Rectangle2D.Double(0, 0, x, slider.getHeight())); - Area rightArea = new Area(new Rectangle2D.Double(x, 0, slider.getWidth() - x, slider.getHeight())); - if (slider.getComponentOrientation().isLeftToRight()) { - if (slider.getInverted()) { - track.intersect(rightArea); - } else { - track.intersect(leftArea); - } + private Area getVerticalSliderShape(final Area track) { + int y = thumbRect.y + thumbRect.height / 2; + if (slider.getInverted()) { + track.intersect(new Area(new Rectangle2D.Double(0, 0, slider.getWidth(), y))); } else { - if (!slider.getInverted()) { - track.intersect(rightArea); - } else { - track.intersect(leftArea); - } + track.intersect(new Area(new Rectangle2D.Double(0, y, slider.getWidth(), slider.getHeight() - y))); } return track; } - @NotNull - @Contract(" -> new") + private Area getVerticalTrackShape() { int arc = arcSize; int xOff = (trackRect.width / 2) - trackSize / 2; @@ -447,19 +446,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene return isPlainThumb() && showVolumeIcon(slider) ? ICON_BAR_EXT : 0; } - @Contract("_ -> param1") - @NotNull - private Area getVerticalSliderShape(@NotNull final Area track) { - int y = thumbRect.y + thumbRect.height / 2; - if (slider.getInverted()) { - track.intersect(new Area(new Rectangle2D.Double(0, 0, slider.getWidth(), y))); - } else { - track.intersect(new Area(new Rectangle2D.Double(0, y, slider.getWidth(), slider.getHeight() - y))); - } - return track; - } - - private void paintPlainSliderThumb(@NotNull final Graphics2D g) { + private void paintPlainSliderThumb(final Graphics2D g) { int r = plainThumbRadius; int x = isHorizontal() ? 4 : (thumbRect.width - r) / 2; int y = isHorizontal() ? (thumbRect.height - r) / 2 : 4; @@ -481,6 +468,10 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene g.translate(-x, -y); } + private static boolean isVolumeSlider(final JComponent c) { + return "volume".equals(c.getClientProperty("Slider.variant")); + } + private void paintSliderThumb(final Graphics2D g) { Path2D thumb = getThumbShape(); if (paintFocus()) { @@ -511,7 +502,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene } } - @NotNull + private Path2D getHorizontalThumbShape() { int w = thumbRect.width; int h = thumbRect.height; @@ -526,7 +517,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene return shape; } - @NotNull + private Path2D getVerticalThumbShapeLR() { int w = thumbRect.width; int h = thumbRect.height; @@ -541,7 +532,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene return shape; } - @NotNull + private Path2D getVerticalThumbShapeRL() { int w = thumbRect.width; int h = thumbRect.height; @@ -556,7 +547,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene return shape; } - @NotNull + protected Color getThumbColor() { if (isVolumeSlider(slider)) { return slider.isEnabled() ? volumeThumbBackground : volumeThumbInactiveBackground; @@ -565,17 +556,17 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene } } - @NotNull + protected Color getThumbBorderColor() { return slider.isEnabled() ? thumbBorderColor : thumbInactiveBorderColor; } - @NotNull + protected Color getTrackBackground() { return trackBackground; } - @NotNull + protected Color getSelectedTrackColor() { if (isVolumeSlider(slider)) { return slider.isEnabled() ? selectedVolumeTrackBackground : selectedVolumeTrackInactiveBackground; @@ -584,12 +575,12 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene } } - private boolean instantScrollEnabled(@NotNull final JComponent c) { + private boolean instantScrollEnabled(final JComponent c) { return Boolean.TRUE.equals(c.getClientProperty("Slider.instantScrollEnabled")); } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if ("Slider.variant".equals(key)) { slider.repaint(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java b/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java index df00f028..2a51afa1 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java +++ b/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerBorder.java @@ -25,7 +25,6 @@ package com.github.weisj.darklaf.ui.spinner; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -54,7 +53,7 @@ public class DarkSpinnerBorder implements Border, UIResource { } @Override - public void paintBorder(@NotNull final Component c, final Graphics g2, + public void paintBorder(final Component c, final Graphics g2, final int x, final int y, final int width, final int height) { boolean tableCellEditor = DarkSpinnerUI.isTableCellEditor(c); boolean treeCellEditor = !tableCellEditor && DarkSpinnerUI.isTreeCellEditor(c); @@ -109,7 +108,7 @@ public class DarkSpinnerBorder implements Border, UIResource { config.restore(); } - protected Color getBorderColor(@NotNull final Component c) { + protected Color getBorderColor(final Component c) { return c.isEnabled() ? borderColor : inactiveBorderColor; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java b/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java index 587d2107..3eeca669 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java @@ -26,8 +26,6 @@ package com.github.weisj.darklaf.ui.spinner; import com.github.weisj.darklaf.components.ArrowButton; import com.github.weisj.darklaf.decorators.LayoutManagerDelegate; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -92,13 +90,12 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe private JButton prevButton; private Component editorComponent; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkSpinnerUI(); } - protected static boolean usePlusMinusIcons(@NotNull final JSpinner spinner) { + protected static boolean usePlusMinusIcons(final JSpinner spinner) { return "plusMinus".equals(spinner.getClientProperty("JSpinner.variant")); } @@ -205,7 +202,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe } } - @NotNull + private JButton createArrow(final int direction) { Insets insets = new Insets(0, BUTTON_PAD, 0, BUTTON_PAD); JButton button = ArrowButton.createUpDownArrow(spinner, @@ -241,7 +238,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe } @Override - public void paint(final Graphics g, @NotNull final JComponent c) { + public void paint(final Graphics g, final JComponent c) { int size = borderSize; int width = c.getWidth(); int height = c.getHeight(); @@ -280,17 +277,17 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe return c == null || !c.isEnabled() ? inactiveBackground : background; } - protected static boolean isTableCellEditor(@NotNull final Component c) { + protected static boolean isTableCellEditor(final Component c) { return c instanceof JComponent && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JSpinner.isTableCellEditor")); } - protected static boolean isTreeCellEditor(@NotNull final Component c) { + protected static boolean isTreeCellEditor(final Component c) { return c instanceof JComponent && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JSpinner.isTreeCellEditor")); } - private void paintSpinBackground(@NotNull final Graphics2D g, final int width, final int height, + private void paintSpinBackground(final Graphics2D g, final int width, final int height, final int bSize, final int arc) { Rectangle bounds = prevButton.getBounds(); boolean leftToRight = spinner.getComponentOrientation().isLeftToRight(); @@ -314,7 +311,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if ("opaque".equals(key)) { boolean val = Boolean.TRUE.equals(evt.getNewValue()); @@ -351,7 +348,6 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe private final Icon mathIcon; - @Contract(pure = true) public SpinnerIcon(final JSpinner spinner, final Icon icon, final Icon mathIcon) { this.spinner = spinner; this.icon = icon; diff --git a/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneDivider.java b/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneDivider.java index fa17c18e..616c4781 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneDivider.java +++ b/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneDivider.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.ui.splitpane; import com.github.weisj.darklaf.icons.EmptyIcon; -import org.jetbrains.annotations.Contract; import javax.swing.*; import javax.swing.plaf.UIResource; @@ -113,7 +112,7 @@ public class DarkSplitPaneDivider extends BasicSplitPaneDivider { setFocusPainted(false); } - @Contract(pure = true) + @SuppressWarnings("deprecation") public boolean isFocusTraversable() { return false; diff --git a/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneUI.java b/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneUI.java index 0d19a19e..be7428db 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/splitpane/DarkSplitPaneUI.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.splitpane; import com.github.weisj.darklaf.decorators.LayoutManagerDelegate; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -49,8 +47,7 @@ public class DarkSplitPaneUI extends BasicSplitPaneUI implements PropertyChangeL this.style = style; } - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkSplitPaneUI(Style.DEFAULT); } @@ -121,7 +118,7 @@ public class DarkSplitPaneUI extends BasicSplitPaneUI implements PropertyChangeL } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if ("JSplitPane.style".equals(key)) { Object val = evt.getNewValue(); @@ -156,7 +153,7 @@ public class DarkSplitPaneUI extends BasicSplitPaneUI implements PropertyChangeL final private String name; - @Contract(pure = true) + Style(final String name) { this.name = name; } @@ -164,18 +161,18 @@ public class DarkSplitPaneUI extends BasicSplitPaneUI implements PropertyChangeL private final class ThinDivider extends BasicSplitPaneDivider { - private ThinDivider(@NotNull final BasicSplitPaneUI ui) { + private ThinDivider(final BasicSplitPaneUI ui) { super(ui); } - @Contract(pure = true) + @Override public int getDividerSize() { return style == Style.LINE ? 1 : 0; } @Override - public void paint(@NotNull final Graphics g) { + public void paint(final Graphics g) { if (style == Style.LINE) { g.setColor(getDividerLineColor()); if (orientation == JSplitPane.HORIZONTAL_SPLIT) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/statusbar/DarkStatusBarUI.java b/src/main/java/com/github/weisj/darklaf/ui/statusbar/DarkStatusBarUI.java index 26bb4409..c8312e2f 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/statusbar/DarkStatusBarUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/statusbar/DarkStatusBarUI.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.ui.statusbar; import org.jdesktop.swingx.JXStatusBar; import org.jdesktop.swingx.plaf.basic.BasicStatusBarUI; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -41,8 +39,7 @@ public class DarkStatusBarUI extends BasicStatusBarUI { protected Color background; protected Color borderColor; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkStatusBarUI(); } @@ -55,7 +52,7 @@ public class DarkStatusBarUI extends BasicStatusBarUI { } @Override - protected void paintBackground(final Graphics2D g, @NotNull final JXStatusBar bar) { + protected void paintBackground(final Graphics2D g, final JXStatusBar bar) { if (bar.isOpaque()) { g.setColor(background); g.fillRect(0, 0, bar.getWidth(), bar.getHeight()); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java index ebb37c87..1989743f 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkHandler.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.tabbedpane; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.plaf.UIResource; @@ -47,7 +45,7 @@ public class DarkHandler extends TabbedPaneHandler { } @Override - public void propertyChange(@NotNull final PropertyChangeEvent e) { + public void propertyChange(final PropertyChangeEvent e) { super.propertyChange(e); String key = e.getPropertyName(); if ("TabbedPane.maxPopupHeight".equals(key)) { @@ -154,7 +152,7 @@ public class DarkHandler extends TabbedPaneHandler { } } - public void stateChanged(@NotNull final ChangeEvent e) { + public void stateChanged(final ChangeEvent e) { JTabbedPane tabPane = (JTabbedPane) e.getSource(); ui.setFocusIndex(tabPane.getSelectedIndex(), true); } @@ -227,7 +225,7 @@ public class DarkHandler extends TabbedPaneHandler { } @Override - public void componentAdded(@NotNull final ContainerEvent e) { + public void componentAdded(final ContainerEvent e) { if (!(e.getChild() instanceof UIResource)) { e.getChild().addFocusListener(ui.focusListener); } @@ -235,7 +233,7 @@ public class DarkHandler extends TabbedPaneHandler { } @Override - public void componentRemoved(@NotNull final ContainerEvent e) { + public void componentRemoved(final ContainerEvent e) { if (!(e.getChild() instanceof UIResource)) { e.getChild().removeFocusListener(ui.focusListener); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollHandler.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollHandler.java index ef33bfe6..fbdab7e7 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollHandler.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollHandler.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.tabbedpane; -import org.jetbrains.annotations.NotNull; - import java.awt.event.MouseEvent; public class DarkScrollHandler extends DarkHandler { @@ -34,7 +32,7 @@ public class DarkScrollHandler extends DarkHandler { } @Override - public void mousePressed(@NotNull final MouseEvent e) { + public void mousePressed(final MouseEvent e) { ui.scrollableTabSupport.timer.stop(); super.mousePressed(ui.convertEvent(e)); ui.scrollableTabSupport.endScroll(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java index a61ed5db..00142f40 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabSupport.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.ui.tabbedpane; import com.github.weisj.darklaf.components.ScrollPopupMenu; import com.github.weisj.darklaf.decorators.PopupMenuAdapter; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.PopupMenuEvent; @@ -66,7 +64,7 @@ public class DarkScrollableTabSupport extends ScrollableTabSupport implements Mo scrollPopupMenu = new ScrollPopupMenu(UIManager.getInt("TabbedPane.maxPopupHeight")); PopupMenuListener popupMenuListener = new PopupMenuAdapter() { @Override - public void popupMenuWillBecomeInvisible(@NotNull final PopupMenuEvent e) { + public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) { lastClickEvent = System.currentTimeMillis(); } }; @@ -220,8 +218,7 @@ public class DarkScrollableTabSupport extends ScrollableTabSupport implements Mo moreTabsButton.repaint(); } - @NotNull - @Contract("_ -> new") + protected JMenuItem createMenuItem(final int i) { Icon icon = ui.tabPane.getIconAt(i); if (icon != null && !ui.tabPane.getComponentAt(i).isEnabled()) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabViewport.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabViewport.java index fcf1844f..eedc22ae 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabViewport.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkScrollableTabViewport.java @@ -23,14 +23,12 @@ */ package com.github.weisj.darklaf.ui.tabbedpane; -import org.jetbrains.annotations.NotNull; - import java.awt.*; public class DarkScrollableTabViewport extends ScrollableTabViewport { protected final Point viewPos = new Point(0, 0); - public DarkScrollableTabViewport(@NotNull final DarkTabbedPaneUIBridge ui) { + public DarkScrollableTabViewport(final DarkTabbedPaneUIBridge ui) { super(ui); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java index c2e60a79..cdfb124c 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneScrollLayout.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.tabbedpane; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; import java.util.function.Function; @@ -406,8 +403,8 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout { } @SuppressWarnings("SuspiciousNameCombination") - @NotNull - @Contract("_ -> new") + + protected Point getMargins(final int tabPlacement) { Dimension size = ui.tabPane.getSize(); Insets insets = ui.tabPane.getInsets(); @@ -500,7 +497,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout { } } - protected void shiftBoundsToVisibleX(@NotNull final Rectangle selectedBounds, final int leftMargin, + protected void shiftBoundsToVisibleX(final Rectangle selectedBounds, final int leftMargin, final int rightMargin, final int tabCount) { if (selectedBounds.x + selectedBounds.width > rightMargin) { //SelectedTab is not fully visible. Covered on right side. @@ -512,7 +509,7 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout { } } - protected void shiftBoundsToVisibleY(@NotNull final Rectangle selectedBounds, final int topMargin, + protected void shiftBoundsToVisibleY(final Rectangle selectedBounds, final int topMargin, final int bottomMargin, final int tabCount) { if (selectedBounds.y + selectedBounds.height > bottomMargin) { //SelectedTab is not fully visible. Covered on right side. @@ -686,14 +683,14 @@ public class DarkTabbedPaneScrollLayout extends TabbedPaneScrollLayout { } } - @Contract(pure = true) + protected boolean isVisibleX(final int i, final int shift, final int minX, final int maxX) { int begin = ui.rects[i].x + shift; int end = begin + ui.rects[i].width; return !(begin >= maxX || end < minX); } - @Contract(pure = true) + protected boolean isVisibleY(final int i, final int shift, final int minX, final int maxX) { int begin = ui.rects[i].y + shift; int end = begin + ui.rects[i].height; diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java index 2864863d..0f2820f4 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java @@ -27,8 +27,6 @@ import com.github.weisj.darklaf.components.uiresource.UIResourceWrapper; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -107,8 +105,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { protected Component southComp; protected Component westComp; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTabbedPaneUI(); } @@ -194,14 +191,14 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { } @Override - protected void paintTabArea(@NotNull final Graphics g, final int tabPlacement, final int selectedIndex) { + protected void paintTabArea(final Graphics g, final int tabPlacement, final int selectedIndex) { paintTabAreaBackground(g, tabPlacement); paintTabAreaBorder(g, tabPlacement); super.paintTabArea(g, tabPlacement, selectedIndex); } @Override - protected void paintTabBackground(@NotNull final Graphics g, final int tabPlacement, final int tabIndex, + protected void paintTabBackground(final Graphics g, final int tabPlacement, final int tabIndex, final int x, final int y, final int w, final int h, final boolean isSelected) { @@ -210,7 +207,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { } @Override - protected void paintTabBorder(@NotNull final Graphics g, final int tabPlacement, final int tabIndex, + protected void paintTabBorder(final Graphics g, final int tabPlacement, final int tabIndex, final int x, final int y, final int w, final int h, final boolean isSelected) { g.setColor(getTabBorderColor()); @@ -277,27 +274,25 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { installTabContainer(); } - protected void paintDrop(@NotNull final Graphics g) { - g.setColor(getDropColor()); - GraphicsContext context = new GraphicsContext(g); - if (!scrollableTabLayoutEnabled()) { - ((Graphics2D) g).setComposite(DarkUIUtil.DROP_ALPHA); + protected void paintTabAreaBackground(final Graphics g, final int tabPlacement) { + g.setColor(getTabAreaBackground()); + Rectangle b = getTabAreaBounds(); + if (scrollableTabLayoutEnabled()) { + b.setLocation(0, 0); } - switch (tabPane.getTabPlacement()) { - case TOP: - g.fillRect(dropRect.x, dropRect.y, dropRect.width, dropRect.height - 1); - break; + switch (tabPlacement) { case BOTTOM: - g.fillRect(dropRect.x, dropRect.y + 1, dropRect.width, dropRect.height - 1); - break; - case LEFT: - g.fillRect(dropRect.x, dropRect.y, dropRect.width - 1, dropRect.height); + b.y++; + case TOP: + b.height--; break; case RIGHT: - g.fillRect(dropRect.x + 1, dropRect.y, dropRect.width - 1, dropRect.height); + b.x++; + case LEFT: + b.width--; break; } - context.restore(); + g.fillRect(b.x, b.y, b.width, b.height); } protected Component wrapClientComponent(final Component component) { @@ -365,25 +360,25 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { final boolean isSelected) { } - protected void paintTabAreaBackground(@NotNull final Graphics g, final int tabPlacement) { - g.setColor(getTabAreaBackground()); - Rectangle b = getTabAreaBounds(); - if (scrollableTabLayoutEnabled()) { - b.setLocation(0, 0); - } + private void paintTabAreaBorder(final Graphics g, final int tabPlacement) { + int width = tabPane.getWidth(); + int height = tabPane.getHeight(); + int y = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); + int x = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); switch (tabPlacement) { - case BOTTOM: - b.y++; case TOP: - b.height--; + paintTabAreaBorder(g, tabPlacement, 0, 0, width, y); + break; + case BOTTOM: + paintTabAreaBorder(g, tabPlacement, 0, height - y, width, y + 1); break; - case RIGHT: - b.x++; case LEFT: - b.width--; + paintTabAreaBorder(g, tabPlacement, 0, 0, x, height); + break; + case RIGHT: + paintTabAreaBorder(g, tabPlacement, width - x, 0, x, height); break; } - g.fillRect(b.x, b.y, b.width, b.height); } protected boolean shouldRotateTabRuns(final int tabPlacement) { @@ -487,23 +482,21 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { } } - private void paintTabAreaBorder(@NotNull final Graphics g, final int tabPlacement) { - int width = tabPane.getWidth(); - int height = tabPane.getHeight(); - int y = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); - int x = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); + protected void paintTabAreaBorder(final Graphics g, final int tabPlacement, + final int x, final int y, final int w, final int h) { + g.setColor(getTabBorderColor()); switch (tabPlacement) { case TOP: - paintTabAreaBorder(g, tabPlacement, 0, 0, width, y); + g.fillRect(x, y + h - 1, w, 1); break; case BOTTOM: - paintTabAreaBorder(g, tabPlacement, 0, height - y, width, y + 1); + g.fillRect(x, y, w, 1); break; case LEFT: - paintTabAreaBorder(g, tabPlacement, 0, 0, x, height); + g.fillRect(w - 1, y, 1, h); break; case RIGHT: - paintTabAreaBorder(g, tabPlacement, width - x, 0, x, height); + g.fillRect(x, y, 1, h); break; } } @@ -512,23 +505,27 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { return tabAreaBackground; } - protected void paintTabAreaBorder(@NotNull final Graphics g, final int tabPlacement, - final int x, final int y, final int w, final int h) { - g.setColor(getTabBorderColor()); - switch (tabPlacement) { + protected void paintDrop(final Graphics g) { + g.setColor(getDropColor()); + GraphicsContext context = new GraphicsContext(g); + if (!scrollableTabLayoutEnabled()) { + ((Graphics2D) g).setComposite(DarkUIUtil.DROP_ALPHA); + } + switch (tabPane.getTabPlacement()) { case TOP: - g.fillRect(x, y + h - 1, w, 1); + g.fillRect(dropRect.x, dropRect.y, dropRect.width, dropRect.height - 1); break; case BOTTOM: - g.fillRect(x, y, w, 1); + g.fillRect(dropRect.x, dropRect.y + 1, dropRect.width, dropRect.height - 1); break; case LEFT: - g.fillRect(w - 1, y, 1, h); + g.fillRect(dropRect.x, dropRect.y, dropRect.width - 1, dropRect.height); break; case RIGHT: - g.fillRect(x, y, 1, h); + g.fillRect(dropRect.x + 1, dropRect.y, dropRect.width - 1, dropRect.height); break; } + context.restore(); } protected void layoutLeadingComponent(final Component comp, final int tabWidth, final int tabHeight, @@ -611,7 +608,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge { tabPane.repaint(); } - protected MouseEvent convertEvent(@NotNull final MouseEvent e) { + protected MouseEvent convertEvent(final MouseEvent e) { Point p = e.getPoint(); Point pos = scrollableTabSupport.viewport.getLocation(); p.x += pos.x; diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java index 60c03fcc..46bdd3bd 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java @@ -25,7 +25,6 @@ package com.github.weisj.darklaf.ui.tabbedpane; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.LazyActionMap; -import org.jetbrains.annotations.NotNull; import sun.swing.DefaultLookup; import sun.swing.SwingUtilities2; import sun.swing.UIAction; @@ -257,7 +256,7 @@ public abstract class DarkTabbedPaneUIBridge extends TabbedPaneUI implements Swi * * @param map the map */ - public static void loadActionMap(@NotNull final LazyActionMap map) { + public static void loadActionMap(final LazyActionMap map) { map.put(new Actions(Actions.NEXT)); map.put(new Actions(Actions.PREVIOUS)); map.put(new Actions(Actions.RIGHT)); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/MoreTabsButton.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/MoreTabsButton.java index eca1dcc3..ff6bd551 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/MoreTabsButton.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/MoreTabsButton.java @@ -26,7 +26,6 @@ package com.github.weisj.darklaf.ui.tabbedpane; import com.github.weisj.darklaf.icons.EmptyIcon; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -54,7 +53,7 @@ public class MoreTabsButton extends DarkTabAreaButton { return ui.getTabAreaBackground(); } - protected void paintButton(@NotNull final Graphics g) { + protected void paintButton(final Graphics g) { FontMetrics metrics = g.getFontMetrics(); String label = getLabelString(); int labelWidth = metrics.stringWidth(label); @@ -83,7 +82,7 @@ public class MoreTabsButton extends DarkTabAreaButton { config.restore(); } - @NotNull + protected String getLabelString() { int invisible = Math.min(ui.minVisible - 1 + ui.tabPane.getTabCount() - ui.maxVisible, ui.tabPane.getTabCount()); return invisible >= 100 ? INFINITY : String.valueOf(invisible); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/NewTabButton.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/NewTabButton.java index 3142cbf3..0634ffe7 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/NewTabButton.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/NewTabButton.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.tabbedpane; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.UIResource; import java.awt.*; @@ -34,7 +32,7 @@ public class NewTabButton extends JPanel implements UIResource { protected final JButton button; protected DarkTabbedPaneUI ui; - protected NewTabButton(@NotNull final DarkTabbedPaneUI ui) { + protected NewTabButton(final DarkTabbedPaneUI ui) { this.ui = ui; button = createButton(); button.addActionListener(e -> { diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/ScrollableTabPanel.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/ScrollableTabPanel.java index fce35980..ba3141d7 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/ScrollableTabPanel.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/ScrollableTabPanel.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.tabbedpane; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.UIResource; import java.awt.*; @@ -32,7 +30,7 @@ import java.awt.*; public class ScrollableTabPanel extends JPanel implements UIResource { private DarkTabbedPaneUIBridge ui; - public ScrollableTabPanel(@NotNull final DarkTabbedPaneUIBridge ui) { + public ScrollableTabPanel(final DarkTabbedPaneUIBridge ui) { super(null); this.ui = ui; setOpaque(ui.tabPane.isOpaque()); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/ScrollableTabViewport.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/ScrollableTabViewport.java index fbb13117..3f687bb2 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/ScrollableTabViewport.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/ScrollableTabViewport.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.tabbedpane; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.UIResource; import java.awt.*; @@ -33,7 +31,7 @@ import java.awt.*; // Superclass is not serializable across versions class ScrollableTabViewport extends JViewport implements UIResource { - public ScrollableTabViewport(@NotNull final DarkTabbedPaneUIBridge ui) { + public ScrollableTabViewport(final DarkTabbedPaneUIBridge ui) { super(); setName("TabbedPane.scrollableViewport"); setScrollMode(SIMPLE_SCROLL_MODE); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneHandler.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneHandler.java index 3d172cfd..1cbc7acd 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneHandler.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneHandler.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.tabbedpane; import com.github.weisj.darklaf.util.DarkSwingUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -52,13 +50,13 @@ public class TabbedPaneHandler implements ChangeListener, ContainerListener, Foc // // PropertyChangeListener // - @Contract(pure = true) + protected TabbedPaneHandler(final DarkTabbedPaneUIBridge ui) { this.ui = ui; } - public void propertyChange(@NotNull final PropertyChangeEvent e) { + public void propertyChange(final PropertyChangeEvent e) { JTabbedPane pane = (JTabbedPane) e.getSource(); String name = e.getPropertyName(); boolean isScrollLayout = ui.scrollableTabLayoutEnabled(); @@ -250,7 +248,7 @@ public class TabbedPaneHandler implements ChangeListener, ContainerListener, Foc changes to tab text, this code should be removed and replaced by something which uses that. */ - public void componentAdded(@NotNull final ContainerEvent e) { + public void componentAdded(final ContainerEvent e) { JTabbedPane tp = (JTabbedPane) e.getContainer(); Component child = e.getChild(); if (child instanceof UIResource) { @@ -260,7 +258,7 @@ public class TabbedPaneHandler implements ChangeListener, ContainerListener, Foc updateHtmlViews(tp.indexOfComponent(child), true); } - public void componentRemoved(@NotNull final ContainerEvent e) { + public void componentRemoved(final ContainerEvent e) { JTabbedPane tp = (JTabbedPane) e.getContainer(); Component child = e.getChild(); if (child instanceof UIResource) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneTransferHandler.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneTransferHandler.java index cd7c0311..0ba321cc 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneTransferHandler.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneTransferHandler.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.tabbedpane; import com.github.weisj.darklaf.util.ImageUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -111,7 +109,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa * @return Whether or not the import was successful. */ @Override - public boolean importData(final JComponent c, @NotNull final Transferable t) { + public boolean importData(final JComponent c, final Transferable t) { boolean successful = false; if (hasTabFlavor(t.getTransferDataFlavors()) && mouseLocation != null) { @@ -185,7 +183,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa return currentTransferable; } - protected void createDragImage(@NotNull final JTabbedPane tabbedPane, final DarkTabbedPaneUI ui) { + protected void createDragImage(final JTabbedPane tabbedPane, final DarkTabbedPaneUI ui) { Image tabImage = ImageUtil.scaledImageFromComponent(tabbedPane, currentTransferable.transferData.tabBounds); int w = tabImage.getWidth(null); int h = tabImage.getHeight(null); @@ -220,7 +218,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa return false; } - @Contract("null -> null") + private DarkTabbedPaneUI supportsIndicator(final Component c) { JComponent jc = (JComponent) c; ComponentUI ui; @@ -242,7 +240,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa } @Override - public void dragOver(@NotNull final DropTargetDragEvent e) { + public void dragOver(final DropTargetDragEvent e) { e.getDropTargetContext().getComponent().setCursor(Cursor.getDefaultCursor()); mouseLocation = e.getLocation(); @@ -275,7 +273,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa } @Override - public void dragExit(@NotNull final DropTargetEvent e) { + public void dragExit(final DropTargetEvent e) { Component c = e.getDropTargetContext().getComponent(); lastTab = -1; DarkTabbedPaneUI ui = supportsIndicator(c); @@ -285,7 +283,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa } @Override - public void drop(@NotNull final DropTargetDropEvent e) { + public void drop(final DropTargetDropEvent e) { Component c = e.getDropTargetContext().getComponent(); DarkTabbedPaneUI ui = supportsIndicator(c); if (ui != null) { @@ -333,7 +331,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa private final TabTransferData transferData; - public TabTransferable(@NotNull final JTabbedPane tabbedPane) { + public TabTransferable(final JTabbedPane tabbedPane) { int index = tabbedPane.getSelectedIndex(); transferData = new TabTransferData(tabbedPane, index); } @@ -353,7 +351,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa return tabFlavor.equals(flavor); } - @NotNull + @Override public Object getTransferData(final DataFlavor flavor) throws UnsupportedFlavorException { if (!isDataFlavorSupported(flavor)) { @@ -371,8 +369,8 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa private final int tabIndex; private final Rectangle tabBounds; - @Contract(pure = true) - public TabTransferData(@NotNull final JTabbedPane tabbedPane, final int tabIndex) { + + public TabTransferData(final JTabbedPane tabbedPane, final int tabIndex) { this.sourceTabbedPane = tabbedPane; this.tabIndex = tabIndex; this.tabBounds = tabbedPane.getBoundsAt(tabIndex); @@ -391,7 +389,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa /** * a Drag gesture has been recognized */ - public void dragGestureRecognized(@NotNull final DragGestureEvent dge) { + public void dragGestureRecognized(final DragGestureEvent dge) { JComponent c = (JComponent) dge.getComponent(); TabbedPaneTransferHandler th = (TabbedPaneTransferHandler) c.getTransferHandler(); Transferable t = th.createTransferable(c); @@ -440,7 +438,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa /** * as the operation completes */ - public void dragDropEnd(@NotNull final DragSourceDropEvent dsde) { + public void dragDropEnd(final DragSourceDropEvent dsde) { DragSourceContext dsc = dsde.getDragSourceContext(); JComponent c = (JComponent) dsc.getComponent(); if (dsde.getDropSuccess()) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneUtil.java b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneUtil.java index 3f85b352..9eb9a155 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneUtil.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneUtil.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.tabbedpane; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -38,9 +36,9 @@ public class TabbedPaneUtil implements SwingConstants { private static final Rectangle EMPTY_RECT = new Rectangle(0, 0, 0, 0); public static int getDroppedTabIndex(final Rectangle tabBounds, - @NotNull final JTabbedPane tabbedPane, + final JTabbedPane tabbedPane, final DarkTabbedPaneUI ui, - @NotNull final Point p) { + final Point p) { int tab = tabbedPane.indexAtLocation(p.x, p.y); if (ui != null) { if (tab == -1) { @@ -113,9 +111,9 @@ public class TabbedPaneUtil implements SwingConstants { return tab; } - @Contract("_, _, _, _, _, _, _, _ -> param5") - public static Rectangle getDropRect(@NotNull final DarkTabbedPaneUI ui, - @NotNull final JTabbedPane destTabbedPane, final JTabbedPane source, + + public static Rectangle getDropRect(final DarkTabbedPaneUI ui, + final JTabbedPane destTabbedPane, final JTabbedPane source, final Point mouseLocation, final Rectangle tabBounds, final int tab, final int sourceIndex, final int lastTab) { if (destTabbedPane.getTabCount() == 0) return new Rectangle(0, 0, 0, 0); @@ -131,7 +129,7 @@ public class TabbedPaneUtil implements SwingConstants { return tabBounds; } - private static void calculateDropRectScrollLayout(@NotNull final JTabbedPane destTabbedPane, final JTabbedPane source, + private static void calculateDropRectScrollLayout(final JTabbedPane destTabbedPane, final JTabbedPane source, final Rectangle tabBounds, final int tab, final int sourceIndex, final int lastTab, final int tabPlacement, final Rectangle destRect) { boolean lastInSource = false; @@ -181,8 +179,8 @@ public class TabbedPaneUtil implements SwingConstants { } } - private static void calculateDropRectWrapLayout(@NotNull final DarkTabbedPaneUI ui, - @NotNull final JTabbedPane destTabbedPane, + private static void calculateDropRectWrapLayout(final DarkTabbedPaneUI ui, + final JTabbedPane destTabbedPane, final JTabbedPane source, final Point mouseLocation, final Rectangle tabBounds, final int tab, final int sourceIndex, final Rectangle destRect) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java index ed224661..399f229d 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java @@ -31,8 +31,6 @@ import com.github.weisj.darklaf.components.tooltip.ToolTipContext; import com.github.weisj.darklaf.components.uiresource.JLabelUIResource; import com.github.weisj.darklaf.ui.panel.DarkPanelUI; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.FocusManager; import javax.swing.*; @@ -73,8 +71,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe private MutableLineBorder contentBorder; private boolean oldFocus; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkPanelPopupUI(); } @@ -204,7 +201,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe } } - public final Dimension getPreferredSize(@NotNull final JComponent c) { + public final Dimension getPreferredSize(final JComponent c) { if (!c.isEnabled()) { return new Dimension(0, 0); } else { @@ -213,7 +210,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe } @Override - public Dimension getMinimumSize(@NotNull final JComponent c) { + public Dimension getMinimumSize(final JComponent c) { if (!c.isEnabled()) { return new Dimension(0, 0); } else { @@ -222,7 +219,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe } @Override - public Dimension getMaximumSize(@NotNull final JComponent c) { + public Dimension getMaximumSize(final JComponent c) { if (!c.isEnabled()) { return new Dimension(0, 0); } else { @@ -231,7 +228,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if ("open".equals(key)) { if (Boolean.TRUE.equals(evt.getNewValue())) { @@ -297,8 +294,8 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe tabFrame.getContentPane().isEnabled(tabFrame.getPeer(popupComponent.getAlignment()))); } - @NotNull - protected Insets getBorderSize(@NotNull final Alignment a, final boolean[] info) { + + protected Insets getBorderSize(final Alignment a, final boolean[] info) { Insets insets = new Insets(0, 0, 0, 0); switch (a) { case NORTH: @@ -342,7 +339,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe } } - protected void applyBorderInsets(@NotNull final Insets insets) { + protected void applyBorderInsets(final Insets insets) { headerBorder.setInsets(insets.top, insets.left, 1, insets.right); contentBorder.setInsets(0, insets.left, insets.bottom, insets.right); } @@ -352,7 +349,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe } @Override - public void eventDispatched(@NotNull final AWTEvent event) { + public void eventDispatched(final AWTEvent event) { if (event.getID() == FocusEvent.FOCUS_GAINED) { Component focusOwner = FocusManager.getCurrentManager().getFocusOwner(); if (focusOwner instanceof JTabFrame) return; @@ -371,7 +368,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe protected final ToolTipContext context = new ToolTipContext(this); protected final DarkPanelPopupUI ui; - public HeaderButton(@NotNull final Icon icon, final DarkPanelPopupUI ui) { + public HeaderButton(final Icon icon, final DarkPanelPopupUI ui) { super(icon); this.ui = ui; putClientProperty("JButton.square", true); @@ -401,7 +398,7 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe return context.getToolTip(); } - protected void setAlignment(@NotNull final Alignment a, final boolean peerEnabled) { + protected void setAlignment(final Alignment a, final boolean peerEnabled) { switch (a) { case NORTH: context.setCenterAlignment(peerEnabled ? Alignment.SOUTH : Alignment.SOUTH_WEST); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameComponentPopupMenu.java b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameComponentPopupMenu.java index e4b0bb5f..07f2d8fb 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameComponentPopupMenu.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameComponentPopupMenu.java @@ -27,7 +27,6 @@ import com.github.weisj.darklaf.components.JXPopupMenu; import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tabframe.TabFrameTab; import com.github.weisj.darklaf.icons.EmptyIcon; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.UIResource; @@ -61,7 +60,7 @@ public class DarkTabFrameComponentPopupMenu extends JXPopupMenu implements Prope tab.getComponent().addPropertyChangeListener(this); } - protected void createAndAdd(final Alignment a, @NotNull final JMenu menu) { + protected void createAndAdd(final Alignment a, final JMenu menu) { JMenuItem menuItem = createMenuItem(a); actions[a.ordinal()] = menuItem; menu.add(menuItem); @@ -76,7 +75,7 @@ public class DarkTabFrameComponentPopupMenu extends JXPopupMenu implements Prope return menuItem; } - protected void moveTo(@NotNull final Alignment a) { + protected void moveTo(final Alignment a) { if (disabled >= 0) { actions[disabled].setEnabled(true); } @@ -85,7 +84,7 @@ public class DarkTabFrameComponentPopupMenu extends JXPopupMenu implements Prope tab.getTabFrame().moveTab(tab, a); } - protected String getDescription(@NotNull final Alignment a) { + protected String getDescription(final Alignment a) { switch (a) { case NORTH: return "Top Left"; @@ -109,7 +108,7 @@ public class DarkTabFrameComponentPopupMenu extends JXPopupMenu implements Prope } } - protected Icon createIcon(@NotNull final Alignment a, final boolean enabled) { + protected Icon createIcon(final Alignment a, final boolean enabled) { String suffix = enabled ? "" : "Disabled"; switch (a) { case NORTH: @@ -135,7 +134,7 @@ public class DarkTabFrameComponentPopupMenu extends JXPopupMenu implements Prope } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { if ("orientation".equals(evt.getPropertyName())) { Object a = evt.getNewValue(); if (a instanceof Alignment) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabContainerUI.java b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabContainerUI.java index 83bfdd65..9b46acb9 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabContainerUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabContainerUI.java @@ -29,8 +29,6 @@ import com.github.weisj.darklaf.components.tabframe.TabFrameTabContainer; import com.github.weisj.darklaf.decorators.HoverListener; import com.github.weisj.darklaf.ui.panel.DarkPanelUI; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -60,8 +58,7 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC private Color hoverColor; private boolean printing; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTabFrameTabContainerUI(); } @@ -162,7 +159,7 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if ("content".equals(key)) { Object oldVal = evt.getOldValue(); @@ -199,13 +196,13 @@ public class DarkTabFrameTabContainerUI extends DarkPanelUI implements PropertyC } @Override - public void paint(@NotNull final Graphics g, @NotNull final JComponent c) { + public void paint(final Graphics g, final JComponent c) { g.setColor(getBackground(tabContainer)); g.fillRect(0, 0, c.getWidth(), c.getHeight()); super.paint(g, c); } - public Color getBackground(@NotNull final TabFrameTabContainer tab) { + public Color getBackground(final TabFrameTabContainer tab) { if (printing) return tab.getBackground(); return tab.isSelected() ? selectedColor : hoverListener.isHover() && !tab.getTabFrame().isInTransfer() diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java index 8bc1759d..681039b4 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java @@ -30,8 +30,6 @@ import com.github.weisj.darklaf.decorators.HoverListener; import com.github.weisj.darklaf.icons.RotatableIcon; import com.github.weisj.darklaf.ui.label.DarkLabelUI; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -70,14 +68,13 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang private Rectangle paintTextR = new Rectangle(); private boolean printing; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTabFrameTabLabelUI(); } @Override - public void paint(@NotNull final Graphics g, final JComponent c) { + public void paint(final Graphics g, final JComponent c) { g.setColor(getBackground(tabComponent)); g.fillRect(0, 0, tabComponent.getWidth(), tabComponent.getHeight()); @@ -245,7 +242,7 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang tabFrame.getActionMap().remove(accAction); } - public Color getBackground(@NotNull final TabFrameTabLabel tab) { + public Color getBackground(final TabFrameTabLabel tab) { if (printing) return tab.getBackground(); return tab.isSelected() ? selectedColor : hoverListener.isHover() && !tab.getTabFrame().isInTransfer() @@ -261,7 +258,7 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang return rotatableIcon; } - private String layout(@NotNull final JLabel label, final FontMetrics fm, + private String layout(final JLabel label, final FontMetrics fm, final int width, final int height) { Insets insets = label.getInsets(null); String text = label.getText(); @@ -275,7 +272,7 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang return layoutCL(label, fm, text, getIcon(), paintViewR, paintIconR, paintTextR); } - protected Alignment mapOrientation(@NotNull final Alignment newValue) { + protected Alignment mapOrientation(final Alignment newValue) { switch (newValue) { case CENTER: case NORTH: diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameUI.java b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameUI.java index 73b4690d..8456210f 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameUI.java @@ -33,8 +33,6 @@ import com.github.weisj.darklaf.components.tabframe.TabFrameUI; import com.github.weisj.darklaf.components.uiresource.JPanelUIResource; import com.github.weisj.darklaf.util.Pair; import org.jdesktop.jxlayer.JXLayer; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import org.pbjar.jxlayer.plaf.ext.transform.DefaultTransformModel; import org.pbjar.jxlayer.plaf.ext.transform.TransformUtils; @@ -78,14 +76,13 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener { private Alignment destAlign; private int destIndex; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTabFrameUI(); } @Override - public void installUI(@NotNull final JComponent c) { + public void installUI(final JComponent c) { tabFrame = (JTabFrame) c; installDefaults(); installComponents(); @@ -232,11 +229,37 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener { } @Override - public JTabFrame.TabFramePosition getTabIndexAt(final JTabFrame tabFrame, @NotNull final Point p) { + public JTabFrame.TabFramePosition getTabIndexAt(final JTabFrame tabFrame, final Point p) { return getTabIndexAtImpl(tabFrame, p).getFirst(); } - public Rectangle getTabContainerBounds(final JTabFrame tabFrame, @NotNull final Alignment a) { + @Override + public int getTabWidth(final JTabFrame tabFrame, final Alignment a, final int index) { + return layout.getTabWidth(tabFrame.getTabComponentAt(a, index).getComponent()); + } + + public JComponent getTopContainer() { + return tabFrame.getTopTabContainer(); + } + + public JComponent getBottomContainer() { + return tabFrame.getBottomTabContainer(); + } + + public JComponent getLeftContainer() { + return rotatePaneLeft; + } + + public JComponent getRightContainer() { + return rotatePaneRight; + } + + @Override + public int getTabHeight(final JTabFrame tabFrame, final Alignment a, final int index) { + return tabFrame.getTabSize(); + } + + public Rectangle getTabContainerBounds(final JTabFrame tabFrame, final Alignment a) { switch (a) { case NORTH: case NORTH_EAST: @@ -262,23 +285,113 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener { } } - public JComponent getTopContainer() { - return tabFrame.getTopTabContainer(); - } - - public JComponent getBottomContainer() { - return tabFrame.getBottomTabContainer(); + protected Pair getTabIndexAtImpl(final JTabFrame tabFrame, + final Point p) { + Component tabComp = null; + Alignment a = null; + Point pos = null; + if (!layout.isDraggedOver(Alignment.NORTH)) { + getTopContainer().getBounds(calcRect); + if (p.y >= calcRect.y && p.y <= calcRect.y + calcRect.height) { + tabComp = getTopContainer(); + a = Alignment.NORTH; + pos = SwingUtilities.convertPoint(tabFrame, p, tabComp); + if (pos.x > tabComp.getWidth() / 2) { + a = Alignment.NORTH_EAST; + } + } + } + if (tabComp == null && !layout.isDraggedOver(Alignment.SOUTH)) { + getBottomContainer().getBounds(calcRect); + if (p.y >= calcRect.y && p.y <= calcRect.y + calcRect.height) { + tabComp = getBottomContainer(); + a = Alignment.SOUTH; + pos = SwingUtilities.convertPoint(tabFrame, p, tabComp); + if (pos.x <= tabComp.getWidth() / 2) { + a = Alignment.SOUTH_WEST; + } + } + } + if (tabComp == null && !layout.isDraggedOver(Alignment.WEST)) { + getLeftContainer().getBounds(calcRect); + if (p.x >= calcRect.x && p.x <= calcRect.x + calcRect.width) { + tabComp = getLeftContainer(); + a = Alignment.WEST; + pos = SwingUtilities.convertPoint(tabFrame, p, tabComp); + if (pos.y < tabComp.getHeight() / 2) { + a = Alignment.NORTH_WEST; + } + int tmp = pos.x; + pos.x = tabComp.getHeight() - pos.y; + pos.y = tmp; + } + } + if (tabComp == null && !layout.isDraggedOver(Alignment.EAST)) { + getRightContainer().getBounds(calcRect); + if (p.x >= calcRect.x && p.x <= calcRect.x + calcRect.width) { + tabComp = getRightContainer(); + a = Alignment.EAST; + pos = SwingUtilities.convertPoint(tabFrame, p, tabComp); + if (pos.y > tabComp.getHeight() / 2) { + a = Alignment.SOUTH_EAST; + } + int tmp = pos.x; + //noinspection SuspiciousNameCombination + pos.x = pos.y; + pos.y = tmp; + } + } + if (tabComp == null) { + JTabFrame.TabFramePosition tab = maybeRestoreTabContainer(tabFrame, p); + if (tab.getAlignment() != null) { + return new Pair<>(tab, pos); + } + } else { + layout.setDraggedOver(false); + } + if (tabComp == null) { + return new Pair<>(new JTabFrame.TabFramePosition(null, -1), pos); + } + List tabs = tabFrame.tabsForAlignment(a); + for (TabFrameTab tab : tabs) { + Rectangle rect = getTabRect(tab, a, tabComp, true); + if (rect.contains(pos)) { + return new Pair<>(new JTabFrame.TabFramePosition(a, tab.getIndex()), pos); + } + } + return new Pair<>(new JTabFrame.TabFramePosition(a, -1), pos); } - public JComponent getLeftContainer() { - return rotatePaneLeft; + @Override + public JTabFrame.TabFramePosition getNearestTabIndexAt(final JTabFrame tabFrame, final Point pos) { + return getNearestTabIndexAtImpl(tabFrame, pos).getFirst(); } - public JComponent getRightContainer() { - return rotatePaneRight; + public JTabFrame.TabFramePosition getDropPosition(final JTabFrame tabFrame, final Point p) { + Pair res = getNearestTabIndexAtImpl(tabFrame, p); + JTabFrame.TabFramePosition tab = res.getFirst(); + if (tab.getAlignment() != null) { + Alignment a = tab.getAlignment(); + int index = tab.getIndex(); + if (index >= 0) { + Rectangle rect = getTabRect(tabFrame.getTabComponentAt(a, index), a, + tabFrame.getTabContainer(a), false); + Point pos = res.getSecond(); + if (isForward(a)) { + if (pos.x <= rect.x + rect.width / 2 && pos.x >= rect.x) { + tab.setIndex(tab.getIndex() - 1); + } + } else { + if (pos.x >= rect.x + rect.width / 2) { + tab.setIndex(tab.getIndex() - 1); + } + } + } + } + return tab; } - protected JTabFrame.TabFramePosition maybeRestoreTabContainer(@NotNull final JTabFrame tabFrame, final Point p) { + protected JTabFrame.TabFramePosition maybeRestoreTabContainer(final JTabFrame tabFrame, final Point p) { Alignment a = null; int size = tabFrame.getTabSize(); int threshold = size; @@ -318,7 +431,11 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener { return new JTabFrame.TabFramePosition(a, index); } - protected Rectangle getTabRect(@NotNull final TabFrameTab tab, final Alignment a, final Component tabComp, + public void setDropSize(final int width, final int height) { + dropSize.setSize(width, height); + } + + protected Rectangle getTabRect(final TabFrameTab tab, final Alignment a, final Component tabComp, final boolean includeDropRect) { tab.getComponent().getBounds(calcRect); SwingUtilities.convertRectangle(tab.getComponent(), calcRect, tabComp); @@ -335,7 +452,7 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener { return calcRect; } - protected boolean isForward(@NotNull final Alignment a) { + protected boolean isForward(final Alignment a) { switch (a) { case NORTH: case EAST: @@ -351,67 +468,6 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener { } } - @Override - public JTabFrame.TabFramePosition getNearestTabIndexAt(final JTabFrame tabFrame, final Point pos) { - return getNearestTabIndexAtImpl(tabFrame, pos).getFirst(); - } - - public JTabFrame.TabFramePosition getDropPosition(final JTabFrame tabFrame, final Point p) { - Pair res = getNearestTabIndexAtImpl(tabFrame, p); - JTabFrame.TabFramePosition tab = res.getFirst(); - if (tab.getAlignment() != null) { - Alignment a = tab.getAlignment(); - int index = tab.getIndex(); - if (index >= 0) { - Rectangle rect = getTabRect(tabFrame.getTabComponentAt(a, index), a, - tabFrame.getTabContainer(a), false); - Point pos = res.getSecond(); - if (isForward(a)) { - if (pos.x <= rect.x + rect.width / 2 && pos.x >= rect.x) { - tab.setIndex(tab.getIndex() - 1); - } - } else { - if (pos.x >= rect.x + rect.width / 2) { - tab.setIndex(tab.getIndex() - 1); - } - } - } - } - return tab; - } - - protected Component getTabContainer(@NotNull final Alignment a) { - switch (a) { - case NORTH: - case NORTH_EAST: - return getTopContainer(); - case EAST: - case SOUTH_EAST: - return getRightContainer(); - case SOUTH: - case SOUTH_WEST: - return getBottomContainer(); - case WEST: - case NORTH_WEST: - return getLeftContainer(); - } - return null; - } - - public void setDropSize(final int width, final int height) { - dropSize.setSize(width, height); - } - - @Override - public int getTabWidth(@NotNull final JTabFrame tabFrame, final Alignment a, final int index) { - return layout.getTabWidth(tabFrame.getTabComponentAt(a, index).getComponent()); - } - - @Override - public int getTabHeight(@NotNull final JTabFrame tabFrame, final Alignment a, final int index) { - return tabFrame.getTabSize(); - } - protected Pair getNearestTabIndexAtImpl(final JTabFrame tabFrame, final Point pos) { Pair res = getTabIndexAtImpl(tabFrame, pos); @@ -455,81 +511,22 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener { return res; } - protected Pair getTabIndexAtImpl(final JTabFrame tabFrame, - @NotNull final Point p) { - Component tabComp = null; - Alignment a = null; - Point pos = null; - if (!layout.isDraggedOver(Alignment.NORTH)) { - getTopContainer().getBounds(calcRect); - if (p.y >= calcRect.y && p.y <= calcRect.y + calcRect.height) { - tabComp = getTopContainer(); - a = Alignment.NORTH; - pos = SwingUtilities.convertPoint(tabFrame, p, tabComp); - if (pos.x > tabComp.getWidth() / 2) { - a = Alignment.NORTH_EAST; - } - } - } - if (tabComp == null && !layout.isDraggedOver(Alignment.SOUTH)) { - getBottomContainer().getBounds(calcRect); - if (p.y >= calcRect.y && p.y <= calcRect.y + calcRect.height) { - tabComp = getBottomContainer(); - a = Alignment.SOUTH; - pos = SwingUtilities.convertPoint(tabFrame, p, tabComp); - if (pos.x <= tabComp.getWidth() / 2) { - a = Alignment.SOUTH_WEST; - } - } - } - if (tabComp == null && !layout.isDraggedOver(Alignment.WEST)) { - getLeftContainer().getBounds(calcRect); - if (p.x >= calcRect.x && p.x <= calcRect.x + calcRect.width) { - tabComp = getLeftContainer(); - a = Alignment.WEST; - pos = SwingUtilities.convertPoint(tabFrame, p, tabComp); - if (pos.y < tabComp.getHeight() / 2) { - a = Alignment.NORTH_WEST; - } - int tmp = pos.x; - pos.x = tabComp.getHeight() - pos.y; - pos.y = tmp; - } - } - if (tabComp == null && !layout.isDraggedOver(Alignment.EAST)) { - getRightContainer().getBounds(calcRect); - if (p.x >= calcRect.x && p.x <= calcRect.x + calcRect.width) { - tabComp = getRightContainer(); - a = Alignment.EAST; - pos = SwingUtilities.convertPoint(tabFrame, p, tabComp); - if (pos.y > tabComp.getHeight() / 2) { - a = Alignment.SOUTH_EAST; - } - int tmp = pos.x; - //noinspection SuspiciousNameCombination - pos.x = pos.y; - pos.y = tmp; - } - } - if (tabComp == null) { - JTabFrame.TabFramePosition tab = maybeRestoreTabContainer(tabFrame, p); - if (tab.getAlignment() != null) { - return new Pair<>(tab, pos); - } - } else { - layout.setDraggedOver(false); - } - if (tabComp == null) { - return new Pair<>(new JTabFrame.TabFramePosition(null, -1), pos); - } - List tabs = tabFrame.tabsForAlignment(a); - for (TabFrameTab tab : tabs) { - Rectangle rect = getTabRect(tab, a, tabComp, true); - if (rect.contains(pos)) { - return new Pair<>(new JTabFrame.TabFramePosition(a, tab.getIndex()), pos); - } + protected Component getTabContainer(final Alignment a) { + switch (a) { + case NORTH: + case NORTH_EAST: + return getTopContainer(); + case EAST: + case SOUTH_EAST: + return getRightContainer(); + case SOUTH: + case SOUTH_WEST: + return getBottomContainer(); + case WEST: + case NORTH_WEST: + return getLeftContainer(); } - return new Pair<>(new JTabFrame.TabFramePosition(a, -1), pos); + return null; } public Alignment getSourceAlign() { @@ -549,7 +546,7 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener { } @Override - public void eventDispatched(@NotNull final AWTEvent event) { + public void eventDispatched(final AWTEvent event) { if (event.getID() == MouseEvent.MOUSE_PRESSED) { MouseEvent e = (MouseEvent) event; Component comp = e.getComponent().getComponentAt(e.getPoint()); @@ -563,7 +560,7 @@ public class DarkTabFrameUI extends TabFrameUI implements AWTEventListener { return dropSize; } - public JComponent getDropComponent(@NotNull final Alignment a) { + public JComponent getDropComponent(final Alignment a) { switch (a) { default: case CENTER: diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabbedPopupUI.java b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabbedPopupUI.java index 95c691aa..77224426 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabbedPopupUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabbedPopupUI.java @@ -29,8 +29,6 @@ import com.github.weisj.darklaf.components.uiresource.JPanelUIResource; import com.github.weisj.darklaf.ui.tabbedpane.DarkTabbedPaneUI; import com.github.weisj.darklaf.ui.tabbedpane.MoreTabsButton; import com.github.weisj.darklaf.ui.tabbedpane.NewTabButton; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -53,8 +51,7 @@ public class DarkTabbedPopupUI extends DarkPanelPopupUI { private JPanel holder; private JButton newTabButton; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTabbedPopupUI(); } @@ -134,7 +131,7 @@ public class DarkTabbedPopupUI extends DarkPanelPopupUI { } @Override - protected void applyBorderInsets(@NotNull final Insets insets) { + protected void applyBorderInsets(final Insets insets) { border.setInsets(insets.top, insets.left, insets.bottom, insets.right); } @@ -146,7 +143,7 @@ public class DarkTabbedPopupUI extends DarkPanelPopupUI { protected class TabFrameNewTabButton extends NewTabButton { - protected TabFrameNewTabButton(@NotNull final DarkTabbedPaneUI ui) { + protected TabFrameNewTabButton(final DarkTabbedPaneUI ui) { super(ui); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabDragListener.java b/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabDragListener.java index 9c3d899f..562b4e03 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabDragListener.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabDragListener.java @@ -27,7 +27,6 @@ import com.github.weisj.darklaf.components.tabframe.TabFrameTab; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.SwingXUtilities; import org.jdesktop.jxlayer.JXLayer; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -44,7 +43,7 @@ public class TabDragListener extends MouseAdapter { } @Override - public void mousePressed(@NotNull final MouseEvent e) { + public void mousePressed(final MouseEvent e) { origin = e.getPoint(); } @@ -54,7 +53,7 @@ public class TabDragListener extends MouseAdapter { } @Override - public void mouseDragged(@NotNull final MouseEvent e) { + public void mouseDragged(final MouseEvent e) { if (origin == null) origin = e.getPoint(); if (distance(origin, e.getPoint()) < 100) return; TransferHandler th = tabComponent.getTabFrame().getTransferHandler(); @@ -72,7 +71,7 @@ public class TabDragListener extends MouseAdapter { } } - protected int distance(@NotNull final Point p1, @NotNull final Point p2) { + protected int distance(final Point p1, final Point p2) { return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y); } } diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameLayout.java b/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameLayout.java index a353f3be..410590ce 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameLayout.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameLayout.java @@ -26,8 +26,6 @@ package com.github.weisj.darklaf.ui.tabframe; import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.components.tabframe.JTabFrame; import com.github.weisj.darklaf.components.tabframe.TabFrameTab; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import java.awt.*; import java.util.Arrays; @@ -47,8 +45,8 @@ public class TabFrameLayout implements LayoutManager { private int rightHeight; private int bottomHeight; - @Contract(pure = true) - public TabFrameLayout(@NotNull final JTabFrame tabFrame, final DarkTabFrameUI ui) { + + public TabFrameLayout(final JTabFrame tabFrame, final DarkTabFrameUI ui) { this.tabFrame = tabFrame; this.ui = ui; shift = new int[4]; @@ -63,7 +61,7 @@ public class TabFrameLayout implements LayoutManager { public void removeLayoutComponent(final Component comp) { } - @NotNull + @Override public Dimension preferredLayoutSize(final Container parent) { Dimension b = tabFrame.getContentPane().getComponent().getPreferredSize(); @@ -73,7 +71,7 @@ public class TabFrameLayout implements LayoutManager { + tabFrame.getBottomTabContainer().getHeight() + b.height); } - @NotNull + @Override public Dimension minimumLayoutSize(final Container parent) { Dimension b = tabFrame.getContentPane().getComponent().getMinimumSize(); @@ -84,7 +82,7 @@ public class TabFrameLayout implements LayoutManager { } @Override - public void layoutContainer(@NotNull final Container parent) { + public void layoutContainer(final Container parent) { Dimension dim = parent.getSize(); int topSize = tabFrame.getTopTabCount(); int bottomSize = tabFrame.getBottomTabCount(); @@ -268,7 +266,7 @@ public class TabFrameLayout implements LayoutManager { } } - public int getShift(@NotNull final Alignment a) { + public int getShift(final Alignment a) { switch (a) { case NORTH: case EAST: @@ -279,7 +277,7 @@ public class TabFrameLayout implements LayoutManager { return shift[getIndex(a)]; } - protected int getIndex(@NotNull final Alignment a) { + protected int getIndex(final Alignment a) { switch (a) { case NORTH: case NORTH_EAST: @@ -301,7 +299,7 @@ public class TabFrameLayout implements LayoutManager { draggedOver[getIndex(a)] = b; } - protected int layoutTabArea(@NotNull final Point start, @NotNull final Alignment a, + protected int layoutTabArea(final Point start, final Alignment a, final boolean forward, final int size) { int x = start.x; int y = start.y; @@ -355,7 +353,7 @@ public class TabFrameLayout implements LayoutManager { return x; } - public int getTabWidth(@NotNull final Component c) { + public int getTabWidth(final Component c) { int maxWidth = tabFrame.getMaxTabWidth(); int width = c.getPreferredSize().width; if (maxWidth < 0) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameTransferHandler.java b/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameTransferHandler.java index d61a9073..1c21bf48 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameTransferHandler.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tabframe/TabFrameTransferHandler.java @@ -29,8 +29,6 @@ import com.github.weisj.darklaf.components.tabframe.TabFramePopup; import com.github.weisj.darklaf.components.tabframe.TabFrameTab; import com.github.weisj.darklaf.components.tabframe.TabFrameUI; import com.github.weisj.darklaf.util.ImageUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -100,7 +98,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg startTimer.setRepeats(false); } - @Contract("null -> null") + private TabFrameUI getUI(final Component c) { if (c instanceof JTabFrame) return ((JTabFrame) c).getUI(); return null; @@ -135,7 +133,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg } @Override - public void dragOver(@NotNull final DropTargetDragEvent e) { + public void dragOver(final DropTargetDragEvent e) { e.getDropTargetContext().getComponent().setCursor(Cursor.getDefaultCursor()); mouseLocation = e.getLocation(); @@ -204,7 +202,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg } @Override - public void dragExit(@NotNull final DropTargetEvent e) { + public void dragExit(final DropTargetEvent e) { Component c = e.getDropTargetContext().getComponent(); TabFrameUI ui = getUI(c); if (ui != null) { @@ -215,7 +213,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg } @Override - public void drop(@NotNull final DropTargetDropEvent e) { + public void drop(final DropTargetDropEvent e) { Component c = e.getDropTargetContext().getComponent(); TabFrameUI ui = getUI(c); if (ui != null) { @@ -241,7 +239,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg * @return Whether or not the import was successful. */ @Override - public boolean importData(final JComponent c, @NotNull final Transferable t) { + public boolean importData(final JComponent c, final Transferable t) { boolean successful = false; if (hasTabFlavor(t.getTransferDataFlavors()) && mouseLocation != null) { try { @@ -293,7 +291,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg public void dropActionChanged(final DropTargetDragEvent e) { } - protected Transferable createTransferable(final JComponent c, @NotNull final DragGestureEvent dge) { + protected Transferable createTransferable(final JComponent c, final DragGestureEvent dge) { JTabFrame tabFrame = (JTabFrame) c; if (tabFrame.isInTransfer()) { currentTransferable = new TabTransferable(tabFrame, tabFrame.getTransferInfo()); @@ -312,7 +310,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg return currentTransferable; } - protected void createDragImage(@NotNull final TabFrameUI ui) { + protected void createDragImage(final TabFrameUI ui) { Component comp = currentTransferable.transferData.tab.getComponent(); Image tabImage = ImageUtil.scaledImageFromComponent(comp, new Rectangle(0, 0, comp.getWidth(), comp.getHeight())); @@ -372,7 +370,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg private final TabTransferData transferData; - public TabTransferable(@NotNull final JTabFrame tabFrame, @NotNull final JTabFrame.TabFramePosition ind) { + public TabTransferable(final JTabFrame tabFrame, final JTabFrame.TabFramePosition ind) { transferData = new TabTransferData(tabFrame, ind.getAlignment(), ind.getIndex()); } @@ -391,7 +389,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg return tabFlavor.equals(flavor); } - @NotNull + @Override public Object getTransferData(final DataFlavor flavor) throws UnsupportedFlavorException { if (!isDataFlavorSupported(flavor)) { @@ -411,8 +409,8 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg private final TabFrameTab tab; private final boolean wasSelected; - @Contract(pure = true) - public TabTransferData(@NotNull final JTabFrame tabbedPane, final Alignment tabAlignment, + + public TabTransferData(final JTabFrame tabbedPane, final Alignment tabAlignment, final int tabIndex) { this.sourceTabFrame = tabbedPane; this.tabAlignment = tabAlignment; @@ -434,7 +432,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg /** * a Drag gesture has been recognized */ - public void dragGestureRecognized(@NotNull final DragGestureEvent dge) { + public void dragGestureRecognized(final DragGestureEvent dge) { JComponent c = (JComponent) dge.getComponent(); TabFrameTransferHandler th = (TabFrameTransferHandler) c.getTransferHandler(); Transferable t = th.createTransferable(c, dge); @@ -483,7 +481,7 @@ public class TabFrameTransferHandler extends TransferHandler implements DropTarg /** * as the operation completes */ - public void dragDropEnd(@NotNull final DragSourceDropEvent dsde) { + public void dragDropEnd(final DragSourceDropEvent dsde) { DragSourceContext dsc = dsde.getDragSourceContext(); JComponent c = (JComponent) dsc.getComponent(); if (dsde.getDropSuccess()) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java index 1eddbab3..d99d082f 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java +++ b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellEditor.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.table; import com.github.weisj.darklaf.ui.combobox.DarkComboBoxUI; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -89,7 +87,7 @@ public class DarkTableCellEditor extends DefaultCellEditor { setClickCountToStart(2); } - public DarkTableCellEditor(@NotNull final JSpinner spinner) { + public DarkTableCellEditor(final JSpinner spinner) { super(dummyCheckBox); editorComponent = spinner; spinner.putClientProperty("JSpinner.isTableCellEditor", Boolean.TRUE); @@ -129,7 +127,7 @@ public class DarkTableCellEditor extends DefaultCellEditor { this((JToggleButton) checkBox); } - public DarkTableCellEditor(@NotNull final JToggleButton toggleButton) { + public DarkTableCellEditor(final JToggleButton toggleButton) { super(dummyCheckBox); editorComponent = toggleButton; delegate = new EditorDelegate() { @@ -259,13 +257,13 @@ public class DarkTableCellEditor extends DefaultCellEditor { return comp; } - @Contract("null, _ -> false") + private boolean useBooleanEditor(final Object value, final JTable table) { return value instanceof Boolean && DarkTableCellRenderer.isBooleanRenderingEnabled(table) && !(editorComponent instanceof JCheckBox || editorComponent instanceof JRadioButton); } - protected TableCellEditor getBooleanEditor(@NotNull final JTable table) { + protected TableCellEditor getBooleanEditor(final JTable table) { if ("radioButton".equals(table.getClientProperty("JTable.booleanRenderType"))) { return radioButtonEditor; } @@ -289,7 +287,7 @@ public class DarkTableCellEditor extends DefaultCellEditor { this.iconGap = iconGap; } - protected void init(@NotNull final JComponent component, final Icon icon, final boolean ltr) { + protected void init(final JComponent component, final Icon icon, final boolean ltr) { setComponentOrientation(ltr ? ComponentOrientation.LEFT_TO_RIGHT : ComponentOrientation.RIGHT_TO_LEFT); if (c != null) { remove(c); diff --git a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java index b843b9be..93f879b4 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java +++ b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableCellRenderer.java @@ -25,7 +25,6 @@ package com.github.weisj.darklaf.ui.table; import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.table.DefaultTableCellRenderer; @@ -99,11 +98,11 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer { return component; } - protected static boolean isBooleanRenderingEnabled(@NotNull final JTable table) { + protected static boolean isBooleanRenderingEnabled(final JTable table) { return Boolean.TRUE.equals(table.getClientProperty("JTable.renderBooleanAsCheckBox")); } - protected TableCellRenderer getBooleanRenderer(@NotNull final JTable table) { + protected TableCellRenderer getBooleanRenderer(final JTable table) { if ("radioButton".equals(table.getClientProperty("JTable.booleanRenderType"))) { return radioRenderer; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUI.java b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUI.java index d2d94b4b..32519153 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUI.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.table; import com.github.weisj.darklaf.util.GraphicsContext; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -44,8 +42,7 @@ public class DarkTableHeaderUI extends DarkTableHeaderUIBridge { protected Color borderColor; protected Color background; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTableHeaderUI(); } @@ -82,7 +79,7 @@ public class DarkTableHeaderUI extends DarkTableHeaderUIBridge { } @Override - public void paint(final Graphics g2, final @NotNull JComponent c) { + public void paint(final Graphics g2, final JComponent c) { final Graphics2D g = (Graphics2D) g2; final GraphicsContext config = new GraphicsContext(g); diff --git a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUIBridge.java b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUIBridge.java index bec67f15..80b3c6e4 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUIBridge.java +++ b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableHeaderUIBridge.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.ui.table; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; import sun.swing.UIAction; @@ -63,11 +62,11 @@ public class DarkTableHeaderUIBridge extends BasicTableHeaderUI { // Instance Variables // protected static final FocusListener focusListener = new FocusListener() { - public void focusGained(@NotNull final FocusEvent e) { + public void focusGained(final FocusEvent e) { repaintHeader(e.getSource()); } - public void focusLost(@NotNull final FocusEvent e) { + public void focusLost(final FocusEvent e) { repaintHeader(e.getSource()); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java index ce8fbb52..b5300c74 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.ui.table; import com.github.weisj.darklaf.components.OverlayScrollPane; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -103,8 +101,7 @@ public class DarkTableUI extends DarkTableUIBridge { }; protected Color borderColor; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTableUI(); } @@ -135,7 +132,7 @@ public class DarkTableUI extends DarkTableUIBridge { table.removePropertyChangeListener(propertyChangeListener); } - protected static void setupRendererComponents(@NotNull final JTable table) { + protected static void setupRendererComponents(final JTable table) { DarkTableCellRenderer cellRenderer = new DarkTableCellRenderer(); DarkTableCellEditor cellEditor = new DarkTableCellEditor(); DarkColorTableCellRendererEditor colorRendererEditor = new DarkColorTableCellRendererEditor(); @@ -196,7 +193,7 @@ public class DarkTableUI extends DarkTableUIBridge { @Override - protected void paintGrid(@NotNull final Graphics g, + protected void paintGrid(final Graphics g, final int rMin, final int rMax, final int cMin, final int cMax) { g.setColor(table.getGridColor()); @@ -312,18 +309,88 @@ public class DarkTableUI extends DarkTableUIBridge { return comp instanceof JScrollPane; } - protected static int adjustDistance(final int distance, @NotNull final Rectangle rect, - @NotNull final JTable comp) { - int dist = distance; - int min = 0; - int max = comp.getX() + comp.getWidth(); - if (rect.x + dist <= min) { - dist = min - rect.x; + @Override + protected void paintDraggedArea(final Graphics g, final int rMin, final int rMax, + final int cMin, final int cMax, + final TableColumn draggedColumn, final int distance) { + int draggedColumnIndex = viewIndexForColumn(draggedColumn); + + Rectangle minCell = table.getCellRect(rMin, draggedColumnIndex, true); + Rectangle maxCell = table.getCellRect(rMax, draggedColumnIndex, true); + + Rectangle vacatedColumnRect = minCell.union(maxCell); + + int dist = adjustDistance(distance, vacatedColumnRect, table); + + // Paint a gray well in place of the moving column. + Container parent = table.getParent(); + if (isInScrollPane()) { + JScrollPane par = DarkUIUtil.getParentOfType(JScrollPane.class, table); + if (par != null && par.getParent() != null) { + parent = par.getParent(); + } } - if (rect.x + rect.width + dist >= max) { - dist = max - rect.x - rect.width; + int tableHeight = getPreferredSize(table).height; + g.setColor(parent.getBackground()); + g.fillRect(vacatedColumnRect.x, 0, vacatedColumnRect.width - 1, tableHeight); + + + // Move to the where the cell has been dragged. + vacatedColumnRect.x += dist; + + boolean ltr = table.getComponentOrientation().isLeftToRight(); + + // Fill the background. + g.setColor(table.getBackground()); + g.fillRect(vacatedColumnRect.x, 0, vacatedColumnRect.width, tableHeight); + + + // Paint the vertical grid lines if necessary. + if (table.getShowVerticalLines()) { + g.setColor(table.getGridColor()); + int x1 = vacatedColumnRect.x; + int y1 = 0; + int x2 = x1 + vacatedColumnRect.width - 1; + int y2 = y1 + tableHeight; + + boolean onLeftEdge = ltr ? draggedColumnIndex == cMin : draggedColumnIndex == cMax; + boolean onRightEdge = ltr ? draggedColumnIndex == cMax : draggedColumnIndex == cMin; + if (scrollBarVisible()) { + if (isScrollPaneRtl()) { + onLeftEdge = false; + } else { + onRightEdge = false; + } + } + // Left + if (dist != 0 || !onLeftEdge) { + if (draggedColumnIndex == cMin && scrollBarVisible() && isScrollPaneRtl()) x1++; + g.fillRect(x1 - 1, y1, 1, y2 - y1); + } + // Right + if (dist != 0 || !onRightEdge) { + g.fillRect(x2, y1, 1, y2 - y1); + } + } + + for (int row = rMin; row <= rMax; row++) { + // Render the cell value + Rectangle r = table.getCellRect(row, draggedColumnIndex, false); + r.x += dist; + paintCell(g, r, row, draggedColumnIndex); + + // Paint the (lower) horizontal grid line if necessary. + if (table.getShowHorizontalLines()) { + g.setColor(table.getGridColor()); + Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true); + rcr.x += distance; + int x1 = rcr.x; + int y1 = rcr.y; + int x2 = x1 + rcr.width; + int y2 = y1 + rcr.height - 1; + g.fillRect(x1, y2, x2 - x1, 1); + } } - return dist; } protected class DarkHandler extends Handler { @@ -437,91 +504,19 @@ public class DarkTableUI extends DarkTableUIBridge { } } - @Override - protected void paintDraggedArea(@NotNull final Graphics g, final int rMin, final int rMax, - final int cMin, final int cMax, - final TableColumn draggedColumn, final int distance) { - int draggedColumnIndex = viewIndexForColumn(draggedColumn); - - Rectangle minCell = table.getCellRect(rMin, draggedColumnIndex, true); - Rectangle maxCell = table.getCellRect(rMax, draggedColumnIndex, true); - - Rectangle vacatedColumnRect = minCell.union(maxCell); - - int dist = adjustDistance(distance, vacatedColumnRect, table); - - // Paint a gray well in place of the moving column. - Container parent = table.getParent(); - if (isInScrollPane()) { - JScrollPane par = DarkUIUtil.getParentOfType(JScrollPane.class, table); - if (par != null && par.getParent() != null) { - parent = par.getParent(); - } - } - int tableHeight = getPreferredSize(table).height; - g.setColor(parent.getBackground()); - g.fillRect(vacatedColumnRect.x, 0, vacatedColumnRect.width - 1, tableHeight); - - - // Move to the where the cell has been dragged. - vacatedColumnRect.x += dist; - - boolean ltr = table.getComponentOrientation().isLeftToRight(); - - // Fill the background. - g.setColor(table.getBackground()); - g.fillRect(vacatedColumnRect.x, 0, vacatedColumnRect.width, tableHeight); - - - // Paint the vertical grid lines if necessary. - if (table.getShowVerticalLines()) { - g.setColor(table.getGridColor()); - int x1 = vacatedColumnRect.x; - int y1 = 0; - int x2 = x1 + vacatedColumnRect.width - 1; - int y2 = y1 + tableHeight; - - boolean onLeftEdge = ltr ? draggedColumnIndex == cMin : draggedColumnIndex == cMax; - boolean onRightEdge = ltr ? draggedColumnIndex == cMax : draggedColumnIndex == cMin; - if (scrollBarVisible()) { - if (isScrollPaneRtl()) { - onLeftEdge = false; - } else { - onRightEdge = false; - } - } - // Left - if (dist != 0 || !onLeftEdge) { - if (draggedColumnIndex == cMin && scrollBarVisible() && isScrollPaneRtl()) x1++; - g.fillRect(x1 - 1, y1, 1, y2 - y1); - } - // Right - if (dist != 0 || !onRightEdge) { - g.fillRect(x2, y1, 1, y2 - y1); - } + protected static int adjustDistance(final int distance, final Rectangle rect, + final JTable comp) { + int dist = distance; + int min = 0; + int max = comp.getX() + comp.getWidth(); + if (rect.x + dist <= min) { + dist = min - rect.x; } - - for (int row = rMin; row <= rMax; row++) { - // Render the cell value - Rectangle r = table.getCellRect(row, draggedColumnIndex, false); - r.x += dist; - paintCell(g, r, row, draggedColumnIndex); - - // Paint the (lower) horizontal grid line if necessary. - if (table.getShowHorizontalLines()) { - g.setColor(table.getGridColor()); - Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true); - rcr.x += distance; - int x1 = rcr.x; - int y1 = rcr.y; - int x2 = x1 + rcr.width; - int y2 = y1 + rcr.height - 1; - g.fillRect(x1, y2, x2 - x1, 1); - } + if (rect.x + rect.width + dist >= max) { + dist = max - rect.x - rect.width; } + return dist; } - - } diff --git a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUIBridge.java b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUIBridge.java index f0c30ff8..93dcc6aa 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUIBridge.java +++ b/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUIBridge.java @@ -23,7 +23,6 @@ */ package com.github.weisj.darklaf.ui.table; -import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -51,7 +50,7 @@ public class DarkTableUIBridge extends TableUIBridge { /** * Paint a representation of the table instance that was set in installUI(). */ - public void paint(@NotNull final Graphics g, final JComponent c) { + public void paint(final Graphics g, final JComponent c) { Rectangle clip = g.getClipBounds(); Rectangle bounds = table.getBounds(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/table/TextFieldTableCellEditorBorder.java b/src/main/java/com/github/weisj/darklaf/ui/table/TextFieldTableCellEditorBorder.java index 7e7e4cb8..e7acc32e 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/table/TextFieldTableCellEditorBorder.java +++ b/src/main/java/com/github/weisj/darklaf/ui/table/TextFieldTableCellEditorBorder.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.table; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -41,8 +39,12 @@ public class TextFieldTableCellEditorBorder extends DarkTableCellBorder { borderColor = UIManager.getColor("TextField.border.enabled"); } + protected static boolean parentLTR(final Component c) { + return c.getParent().getComponentOrientation().isLeftToRight(); + } + @Override - public void paintBorder(@NotNull final Component c, @NotNull final Graphics g, final int x, final int y, + public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { g.setColor(borderColor); JTable table = DarkUIUtil.getParentOfType(JTable.class, c); @@ -66,10 +68,6 @@ public class TextFieldTableCellEditorBorder extends DarkTableCellBorder { } } - protected static boolean isInWrapper(@NotNull final Component c) { - return c.getParent() instanceof DarkTableCellEditor.IconWrapper; - } - @Override public Insets getBorderInsets(final Component c) { Insets ins = super.getBorderInsets(); @@ -92,11 +90,11 @@ public class TextFieldTableCellEditorBorder extends DarkTableCellBorder { return ins; } - protected static boolean parentLTR(@NotNull final Component c) { - return c.getParent().getComponentOrientation().isLeftToRight(); + protected static boolean isInWrapper(final Component c) { + return c.getParent() instanceof DarkTableCellEditor.IconWrapper; } - @Contract("null -> false") + protected static boolean isListEditor(final Component c) { return c instanceof JComponent && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JTextField.listCellEditor")) diff --git a/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneContainerUI.java b/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneContainerUI.java index 2870e04a..68c0bc06 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneContainerUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneContainerUI.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.taskpane; import org.jdesktop.swingx.plaf.basic.BasicTaskPaneContainerUI; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -33,8 +31,6 @@ import javax.swing.plaf.ComponentUI; public class DarkTaskPaneContainerUI extends BasicTaskPaneContainerUI { - @NotNull - @Contract("_ -> new") public static ComponentUI createUI(final JComponent c) { return new DarkTaskPaneContainerUI(); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneUI.java b/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneUI.java index fffd6386..f7099061 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/taskpane/DarkTaskPaneUI.java @@ -28,8 +28,6 @@ import org.jdesktop.swingx.JXCollapsiblePane; import org.jdesktop.swingx.JXHyperlink; import org.jdesktop.swingx.JXTaskPane; import org.jdesktop.swingx.plaf.metal.MetalTaskPaneUI; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -46,8 +44,7 @@ public class DarkTaskPaneUI extends MetalTaskPaneUI { protected Icon openIcon; protected int arc; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTaskPaneUI(); } @@ -98,13 +95,13 @@ public class DarkTaskPaneUI extends MetalTaskPaneUI { protected Color color; protected int arc; - @Contract(pure = true) + public DarkContentPaneBorder(final Color color, final int arc) { this.arc = arc; this.color = color; } - public void paintBorder(final Component c, @NotNull final Graphics g, final int x, final int y, + public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { Rectangle clip = g.getClip().getBounds(); int h = height + arc; @@ -134,7 +131,7 @@ public class DarkTaskPaneUI extends MetalTaskPaneUI { protected class DarkPaneBorder extends PaneBorder { @Override - protected void paintTitleBackground(@NotNull final JXTaskPane group, final Graphics g2) { + protected void paintTitleBackground(final JXTaskPane group, final Graphics g2) { Graphics2D g = (Graphics2D) g2; int w = group.getWidth(); int h = getTitleHeight(group); @@ -170,7 +167,7 @@ public class DarkTaskPaneUI extends MetalTaskPaneUI { } @Override - protected void paintExpandedControls(final JXTaskPane group, @NotNull final Graphics g, final int x, + protected void paintExpandedControls(final JXTaskPane group, final Graphics g, final int x, final int y, final int width, final int height) { ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(getPaintColor(group)); diff --git a/src/main/java/com/github/weisj/darklaf/ui/text/DarkCaret.java b/src/main/java/com/github/weisj/darklaf/ui/text/DarkCaret.java index 0ecd0328..bb87b5e6 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/text/DarkCaret.java +++ b/src/main/java/com/github/weisj/darklaf/ui/text/DarkCaret.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.ui.text; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.TextUI; @@ -135,7 +134,7 @@ public class DarkCaret extends DefaultCaret implements UIResource { * @param e the mouse event */ @Override - public void mouseClicked(@NotNull final MouseEvent e) { + public void mouseClicked(final MouseEvent e) { if (!e.isConsumed()) { JTextComponent textArea = getComponent(); int clickCount = e.getClickCount(); @@ -193,7 +192,7 @@ public class DarkCaret extends DefaultCaret implements UIResource { } } - private void adjustCaretLocation(@NotNull final MouseEvent e) { + private void adjustCaretLocation(final MouseEvent e) { if (e.isShiftDown() && getDot() != -1) { moveCaret(e); } else { diff --git a/src/main/java/com/github/weisj/darklaf/ui/text/DarkEditorPaneUI.java b/src/main/java/com/github/weisj/darklaf/ui/text/DarkEditorPaneUI.java index 3b603f93..69547cd6 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/text/DarkEditorPaneUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/text/DarkEditorPaneUI.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.text; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.ActionMapUIResource; import javax.swing.plaf.ComponentUI; @@ -65,8 +62,7 @@ public class DarkEditorPaneUI extends DarkTextUI { * Implementation of DarkEditorPaneUI */ - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkEditorPaneUI(); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/text/DarkFormattedTextFieldUI.java b/src/main/java/com/github/weisj/darklaf/ui/text/DarkFormattedTextFieldUI.java index 14075527..824e2fc4 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/text/DarkFormattedTextFieldUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/text/DarkFormattedTextFieldUI.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.text; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -42,8 +39,7 @@ public class DarkFormattedTextFieldUI extends DarkTextFieldUI implements Propert private JFormattedTextField textField; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkFormattedTextFieldUI(); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java b/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java index 71b79c11..4a77b533 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/text/DarkPasswordFieldUI.java @@ -26,8 +26,6 @@ package com.github.weisj.darklaf.ui.text; import com.github.weisj.darklaf.decorators.MouseMovementListener; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -80,7 +78,7 @@ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge { private boolean showTriggered = false; private final MouseListener mouseListener = new MouseAdapter() { @Override - public void mousePressed(@NotNull final MouseEvent e) { + public void mousePressed(final MouseEvent e) { if (hasShowIcon(editor) && isOverEye(e.getPoint())) { ((JPasswordField) getComponent()).setEchoChar((char) 0); showTriggered = true; @@ -98,8 +96,7 @@ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge { } }; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkPasswordFieldUI(); } @@ -188,13 +185,13 @@ public class DarkPasswordFieldUI extends DarkPasswordFieldUIBridge { return showPressed; } - @Contract("null -> false") + public static boolean hasShowIcon(final Component c) { return c instanceof JPasswordField && Boolean.TRUE.equals(((JComponent) c).getClientProperty("PasswordField.view")); } - @NotNull + private Point getShowIconCoord() { Rectangle r = getDrawingRect(getComponent()); int w = getShowIcon().getIconWidth(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextAreaUI.java b/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextAreaUI.java index 6520a99f..94aa539d 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextAreaUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextAreaUI.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.text; import com.github.weisj.darklaf.ui.html.DarkHTML; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -51,8 +49,7 @@ import java.beans.PropertyChangeEvent; */ public class DarkTextAreaUI extends DarkTextUI { - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent ta) { return new DarkTextAreaUI(); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java b/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java index 340b87cd..9fe188f6 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java +++ b/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextBorder.java @@ -27,8 +27,6 @@ import com.github.weisj.darklaf.ui.table.TextFieldTableCellEditorBorder; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -109,7 +107,7 @@ public class DarkTextBorder implements Border, UIResource { config.restore(); } - @Contract("null -> false") + protected static boolean isCellEditor(final Component c) { return c instanceof JComponent && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JTextField.cellEditor")); @@ -131,13 +129,13 @@ public class DarkTextBorder implements Border, UIResource { return DarkTextFieldUI.isSearchField(c) ? (alt ? arc : searchArc) : (alt ? searchArc : arc); } - @Contract("null -> false") + protected static boolean hasError(final Component c) { return c instanceof JComponent && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JTextField.hasError")); } - protected Color getBorderColor(@NotNull final Component c) { + protected Color getBorderColor(final Component c) { boolean editable = !(c instanceof JTextComponent) || ((JTextComponent) c).isEditable(); boolean focus = DarkUIUtil.hasFocus(c); boolean error = hasError(c); diff --git a/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java b/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java index 563a0f30..44d65b59 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java @@ -28,9 +28,6 @@ import com.github.weisj.darklaf.decorators.MouseMovementListener; import com.github.weisj.darklaf.decorators.PopupMenuAdapter; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.GraphicsContext; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.Border; @@ -77,7 +74,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh private long lastSearchEvent; private final PopupMenuListener searchPopupListener = new PopupMenuAdapter() { @Override - public void popupMenuWillBecomeInvisible(@NotNull final PopupMenuEvent e) { + public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) { lastSearchEvent = System.currentTimeMillis(); } }; @@ -102,30 +99,29 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh } }; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTextFieldUI(); } - @Contract(pure = true) + protected static Icon getClearIcon(final boolean clearHovered) { return clearHovered ? clearHover : clear; } - @NotNull - public static Rectangle getTextRect(@NotNull final JComponent c) { + + public static Rectangle getTextRect(final JComponent c) { Insets i = c.getInsets(); Dimension dim = c.getSize(); return new Rectangle(i.left, i.top, dim.width - i.left - i.right, dim.height - i.top - i.bottom); } - public static boolean chooseAlternativeArc(@NotNull final Component c) { + public static boolean chooseAlternativeArc(final Component c) { return c instanceof JComponent && Boolean.TRUE.equals(((JComponent) c).getClientProperty("JTextField.alternativeArc")); } - public static boolean isOver(@NotNull final Point p, @NotNull final Icon icon, final Point e) { + public static boolean isOver(final Point p, final Icon icon, final Point e) { return new Rectangle(p.x, p.y, icon.getIconWidth(), icon.getIconHeight()).contains(e); } @@ -166,8 +162,8 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh return ClickAction.NONE; } - @Nullable - private static JPopupMenu getSearchPopup(@NotNull final JComponent c) { + + private static JPopupMenu getSearchPopup(final JComponent c) { Object value = c.getClientProperty("JTextField.Search.FindPopup"); return value instanceof JPopupMenu ? (JPopupMenu) value : null; } @@ -178,11 +174,11 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh return new Point(r.x + DarkTextBorder.PADDING, r.y + (r.height - w) / 2); } - @NotNull - @Contract("_ -> new") - public Rectangle getDrawingRect(@NotNull final JTextComponent c) { - int w = borderSize; - return new Rectangle(w, w, c.getWidth() - 2 * w, c.getHeight() - 2 * w); + protected void paintBorderBackground(final Graphics2D g, final JTextComponent c) { + g.setColor(getBackgroundColor(c)); + Rectangle r = getDrawingRect(getComponent()); + int arc = getArcSize(c); + DarkUIUtil.fillRoundRect(g, r.x, r.y, r.width, r.height, arc); } protected static Icon getSearchIcon(final Component c) { @@ -193,20 +189,18 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh return isSearchField(c) && getSearchPopup((JComponent) c) != null; } - @Contract("null -> false") + public static boolean isSearchField(final Component c) { return c instanceof JTextField && "search".equals(((JTextField) c).getClientProperty("JTextField.variant")); } - protected void paintBorderBackground(@NotNull final Graphics2D g, @NotNull final JTextComponent c) { - g.setColor(getBackgroundColor(c)); - Rectangle r = getDrawingRect(getComponent()); - int arc = getArcSize(c); - DarkUIUtil.fillRoundRect(g, r.x, r.y, r.width, r.height, arc); + protected Color getBackgroundColor(final JTextComponent c) { + return c.isEnabled() && c.isEditable() ? background : inactiveBackground; } - protected Color getBackgroundColor(@NotNull final JTextComponent c) { - return c.isEnabled() && c.isEditable() ? background : inactiveBackground; + public Rectangle getDrawingRect(final JTextComponent c) { + int w = borderSize; + return new Rectangle(w, w, c.getWidth() - 2 * w, c.getHeight() - 2 * w); } protected int getArcSize(final Component c) { @@ -218,7 +212,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh : (alt ? searchArcSize : arcSize); } - protected void paintSearchField(@NotNull final Graphics2D g, @NotNull final JTextComponent c) { + protected void paintSearchField(final Graphics2D g, final JTextComponent c) { g.setColor(getBackgroundColor(c)); Rectangle r = getDrawingRect(getComponent()); int arc = getArcSize(c); diff --git a/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextPaneUI.java b/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextPaneUI.java index 7dab137a..f69b60c0 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextPaneUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextPaneUI.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.text; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.text.Element; @@ -38,8 +35,6 @@ import java.beans.PropertyChangeEvent; public class DarkTextPaneUI extends DarkEditorPaneUI { - @NotNull - @Contract("_ -> new") public static ComponentUI createUI(final JComponent c) { return new DarkTextPaneUI(); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/text/SelectLineAction.java b/src/main/java/com/github/weisj/darklaf/ui/text/SelectLineAction.java index ca210f7d..2f8f98b5 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/text/SelectLineAction.java +++ b/src/main/java/com/github/weisj/darklaf/ui/text/SelectLineAction.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.text; -import org.jetbrains.annotations.Contract; - import javax.swing.*; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultEditorKit; @@ -104,7 +102,7 @@ public class SelectLineAction extends TextAction { } - @Contract(pure = true) + private int getFirstNonWhitespacePos() { int offset = currentLine.offset; int end = offset + currentLine.count - 1; diff --git a/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarBorder.java b/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarBorder.java index f6969d69..835da724 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarBorder.java +++ b/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarBorder.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.ui.toolbar; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.border.AbstractBorder; import javax.swing.plaf.UIResource; @@ -46,7 +43,7 @@ public class DarkToolBarBorder extends AbstractBorder implements UIResource, Swi } - public void paintBorder(final Component c, @NotNull final Graphics g, + public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) { g.translate(x, y); @@ -68,7 +65,7 @@ public class DarkToolBarBorder extends AbstractBorder implements UIResource, Swi g.translate(-x, -y); } - @Contract("null -> false") + private boolean isFloatable(final Component c) { return c instanceof JToolBar && ((JToolBar) c).isFloatable(); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUI.java b/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUI.java index f691e3c2..f3e284f3 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUI.java @@ -24,9 +24,6 @@ package com.github.weisj.darklaf.ui.toolbar; import com.github.weisj.darklaf.decorators.MouseResponder; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -48,13 +45,12 @@ public class DarkToolBarUI extends DarkToolBarUIBridge { private Dimension horizontalDim = new Dimension(0, 0); private Timer timer = new Timer(5, e -> dragTo()); - @NotNull - @Contract(value = "_ -> new", pure = true) + public static ComponentUI createUI(final JComponent c) { return new DarkToolBarUI(); } - @Nullable + private static Robot createRobot() { try { return new Robot(); @@ -287,7 +283,7 @@ public class DarkToolBarUI extends DarkToolBarUIBridge { } @Override - protected void paintDragWindow(@NotNull final Graphics g) { + protected void paintDragWindow(final Graphics g) { g.setColor(dragWindow.getBackground()); int w = dragWindow.getWidth(); int h = dragWindow.getHeight(); @@ -299,7 +295,7 @@ public class DarkToolBarUI extends DarkToolBarUIBridge { g.fillRect(0, h - 1, w, 1); } - public void paint(@NotNull final Graphics g, @NotNull final JComponent c) { + public void paint(final Graphics g, final JComponent c) { g.setColor(background); g.fillRect(0, 0, c.getWidth(), c.getHeight()); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/toolbar/DropPreviewPanel.java b/src/main/java/com/github/weisj/darklaf/ui/toolbar/DropPreviewPanel.java index 30e0b02b..e3af54b1 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/toolbar/DropPreviewPanel.java +++ b/src/main/java/com/github/weisj/darklaf/ui/toolbar/DropPreviewPanel.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.toolbar; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; @@ -45,7 +43,7 @@ public class DropPreviewPanel extends JComponent { } @Override - public void paint(@NotNull final Graphics g) { + public void paint(final Graphics g) { g.setColor(getBackgroundColor()); g.fillRect(0, 0, getWidth(), getHeight()); } diff --git a/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java b/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java index 9be65f82..1d2a3bcf 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java @@ -28,7 +28,6 @@ import com.github.weisj.darklaf.components.border.BubbleBorder; import com.github.weisj.darklaf.components.border.DropShadowBorder; import com.github.weisj.darklaf.components.tooltip.ToolTipStyle; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -68,10 +67,10 @@ public class DarkTooltipBorder implements Border { height - ins.top - ins.bottom); } - protected boolean isPlain(@NotNull final Component c) { - if (!(c instanceof JComponent)) return false; - Object prop = ((JComponent) c).getClientProperty("JToolTip.style"); - return prop == ToolTipStyle.PLAIN || "plain".equals(prop); + public int getPointerOffset(final Component c, final Dimension dimension) { + if (isPlain(c)) return 0; + return bubbleBorder.getOffset(dimension.width - 2 * shadowBorder.getShadowSize(), dimension.height) + + shadowBorder.getShadowSize(); } private void adjustInsets(final Insets si) { @@ -165,10 +164,10 @@ public class DarkTooltipBorder implements Border { bubbleBorder.setPointerSize(height); } - public int getPointerOffset(final Component c, @NotNull final Dimension dimension) { - if (isPlain(c)) return 0; - return bubbleBorder.getOffset(dimension.width - 2 * shadowBorder.getShadowSize(), dimension.height) - + shadowBorder.getShadowSize(); + protected boolean isPlain(final Component c) { + if (!(c instanceof JComponent)) return false; + Object prop = ((JComponent) c).getClientProperty("JToolTip.style"); + return prop == ToolTipStyle.PLAIN || "plain".equals(prop); } public int getShadowSize(final Component c) { diff --git a/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java b/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java index 672cc2e2..1108ce01 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java @@ -25,8 +25,6 @@ package com.github.weisj.darklaf.ui.tooltip; import com.github.weisj.darklaf.components.alignment.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -51,7 +49,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe protected JToolTip toolTip; protected MouseListener mouseListener = new MouseAdapter() { @Override - public void mouseEntered(@NotNull final MouseEvent e) { + public void mouseEntered(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) return; /* * We redispatch the event to the ToolTipManager with a corrected location. @@ -71,7 +69,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe } @Override - public void mouseExited(@NotNull final MouseEvent e) { + public void mouseExited(final MouseEvent e) { boolean inside = isInside(e); if (!inside) { ToolTipManager.sharedInstance().mouseExited( @@ -83,7 +81,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe }; protected MouseListener exitListener = new MouseAdapter() { @Override - public void mouseExited(@NotNull final MouseEvent e) { + public void mouseExited(final MouseEvent e) { ToolTipManager.sharedInstance().mouseExited( new MouseEvent(toolTip.getComponent(), e.getID(), e.getWhen(), e.getModifiersEx(), Integer.MIN_VALUE, Integer.MIN_VALUE, e.getClickCount(), e.isPopupTrigger(), @@ -91,9 +89,8 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe } }; - @NotNull - @Contract("_ -> new") - public static ComponentUI createUI(@NotNull final JComponent c) { + + public static ComponentUI createUI(final JComponent c) { if (Boolean.TRUE.equals(c.getClientProperty("JComponent.plainTooltip"))) { return BasicToolTipUI.createUI(c); } else { @@ -101,13 +98,13 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe } } - protected boolean isInside(@NotNull final MouseEvent e) { + protected boolean isInside(final MouseEvent e) { Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), toolTip); return contains(toolTip, p.x, p.y); } @Override - public boolean contains(@NotNull final JComponent c, final int x, final int y) { + public boolean contains(final JComponent c, final int x, final int y) { Border b = c.getBorder(); if (b instanceof DarkTooltipBorder) { Area insideArea = ((DarkTooltipBorder) b).getBackgroundArea(toolTip, @@ -165,7 +162,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe } @Override - public void paint(@NotNull final Graphics g, @NotNull final JComponent c) { + public void paint(final Graphics g, final JComponent c) { if (((JToolTip) c).getTipText() == null) return; g.setColor(c.getBackground()); if (c.getBorder() instanceof DarkTooltipBorder) { @@ -175,7 +172,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe super.paint(g, c); } - public Dimension getPreferredSize(@NotNull final JComponent c) { + public Dimension getPreferredSize(final JComponent c) { Font font = c.getFont(); FontMetrics fm = c.getFontMetrics(font); Insets insets = c.getInsets(); @@ -216,7 +213,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe } @Override - public void propertyChange(@NotNull final PropertyChangeEvent evt) { + public void propertyChange(final PropertyChangeEvent evt) { String key = evt.getPropertyName(); if (evt.getSource() instanceof JToolTip) { JToolTip tooltip = (JToolTip) evt.getSource(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java b/src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java index 6b5b803c..30751dbd 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tree/DarkDefaultTreeEditor.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.ui.tree; import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.tree.DefaultTreeCellEditor; @@ -83,7 +82,7 @@ public class DarkDefaultTreeEditor extends DefaultTreeCellEditor { return comp; } - protected DarkTreeCellEditor getBooleanEditor(@NotNull final JTree table) { + protected DarkTreeCellEditor getBooleanEditor(final JTree table) { if ("radioButton".equals(table.getClientProperty("JTree.booleanRenderType"))) { return radioButtonEditor; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellBorder.java b/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellBorder.java index c8aeae26..722b4c33 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellBorder.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellBorder.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.ui.tree; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -44,7 +43,7 @@ public class DarkTreeCellBorder implements Border, UIResource { } @Override - public void paintBorder(final Component c, @NotNull final Graphics g, final int x, + public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { g.setColor(borderColor); DarkUIUtil.drawRect(g, 0, 0, width, height, 1); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java b/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java index 07efca53..0a0647ca 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellEditor.java @@ -25,7 +25,6 @@ package com.github.weisj.darklaf.ui.tree; import com.github.weisj.darklaf.components.SelectableTreeNode; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.PopupMenuEvent; @@ -57,7 +56,7 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi this((JToggleButton) checkBox); } - public DarkTreeCellEditor(@NotNull final JToggleButton toggleButton) { + public DarkTreeCellEditor(final JToggleButton toggleButton) { super(dummyCheckBox); editorComponent = toggleButton; delegate = new EditorDelegate() { @@ -101,7 +100,7 @@ public class DarkTreeCellEditor extends DefaultCellEditor implements TreeCellEdi setClickCountToStart(2); } - public DarkTreeCellEditor(@NotNull final JSpinner spinner) { + public DarkTreeCellEditor(final JSpinner spinner) { super(dummyCheckBox); editorComponent = spinner; spinner.putClientProperty("JSpinner.isTreeCellEditor", Boolean.TRUE); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java b/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java index 272815b4..3110b76b 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRenderer.java @@ -25,7 +25,6 @@ package com.github.weisj.darklaf.ui.tree; import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton; import com.github.weisj.darklaf.util.DarkUIUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; @@ -79,11 +78,11 @@ public class DarkTreeCellRenderer extends DefaultTreeCellRenderer implements Tre return val; } - protected static boolean isBooleanRenderingEnabled(@NotNull final JTree tree) { + protected static boolean isBooleanRenderingEnabled(final JTree tree) { return Boolean.TRUE.equals(tree.getClientProperty("JTree.renderBooleanAsCheckBox")); } - protected DarkCellRendererToggleButton getBooleanRenderer(@NotNull final JTree table) { + protected DarkCellRendererToggleButton getBooleanRenderer(final JTree table) { if ("radioButton".equals(table.getClientProperty("JTree.booleanRenderType"))) { return radioRenderer; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java b/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java index 9dacf592..b3a0d522 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.ui.tree; import com.github.weisj.darklaf.util.SystemInfo; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -75,7 +73,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { } } - private void handle(@NotNull final MouseEvent e) { + private void handle(final MouseEvent e) { final JTree tree = (JTree) e.getSource(); if (SwingUtilities.isLeftMouseButton(e) && !e.isPopupTrigger()) { // if we can't stop any ongoing editing, do nothing @@ -114,13 +112,12 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener { protected Icon collapsed; private boolean myOldRepaintAllRowValue; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTreeUI(); } - protected boolean isSelected(@NotNull final MouseEvent e) { + protected boolean isSelected(final MouseEvent e) { final JTree tree = (JTree) e.getSource(); final int selected = tree.getClosestRowForLocation(e.getX(), e.getY()); final int[] rows = tree.getSelectionRows(); diff --git a/src/main/java/com/github/weisj/darklaf/ui/tree/TreeCellEditorDelegate.java b/src/main/java/com/github/weisj/darklaf/ui/tree/TreeCellEditorDelegate.java index 63298364..96405305 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tree/TreeCellEditorDelegate.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tree/TreeCellEditorDelegate.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.tree; -import org.jetbrains.annotations.Contract; - import javax.swing.*; import javax.swing.event.CellEditorListener; import javax.swing.tree.TreeCellEditor; @@ -38,7 +36,7 @@ public class TreeCellEditorDelegate implements TreeCellEditor { private final TreeCellEditor editor; - @Contract(pure = true) + public TreeCellEditorDelegate(final TreeCellEditor editor) { this.editor = editor; } diff --git a/src/main/java/com/github/weisj/darklaf/ui/tree/TreeRendererComponent.java b/src/main/java/com/github/weisj/darklaf/ui/tree/TreeRendererComponent.java index d23a2a5b..cfb0ba3e 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tree/TreeRendererComponent.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tree/TreeRendererComponent.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.ui.tree; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; @@ -117,7 +115,7 @@ public class TreeRendererComponent extends Container { /** * Calculate the y location for the icon. */ - private int calculateIconY(@NotNull final Icon icon) { + private int calculateIconY(final Icon icon) { int iconHeight = icon.getIconHeight(); int textHeight = renderComponent.getFontMetrics(renderComponent.getFont()).getHeight(); int textY = iconHeight / 2 - textHeight / 2; diff --git a/src/main/java/com/github/weisj/darklaf/ui/tristate/DarkTristateCheckBoxUI.java b/src/main/java/com/github/weisj/darklaf/ui/tristate/DarkTristateCheckBoxUI.java index 47a35030..8694426c 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/tristate/DarkTristateCheckBoxUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/tristate/DarkTristateCheckBoxUI.java @@ -26,8 +26,6 @@ package com.github.weisj.darklaf.ui.tristate; import com.github.weisj.darklaf.components.tristate.TristateCheckBox; import com.github.weisj.darklaf.components.tristate.TristateState; import com.github.weisj.darklaf.ui.checkbox.DarkCheckBoxUI; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -41,8 +39,7 @@ public class DarkTristateCheckBoxUI extends DarkCheckBoxUI { private Icon checkBoxIndeterminateDisabledIcon; private Icon checkBoxIndeterminateFocusedIcon; - @NotNull - @Contract("_ -> new") + public static ComponentUI createUI(final JComponent c) { return new DarkTristateCheckBoxUI(); } @@ -56,7 +53,7 @@ public class DarkTristateCheckBoxUI extends DarkCheckBoxUI { } @Override - protected Icon getCheckIcon(@NotNull final AbstractButton b) { + protected Icon getCheckIcon(final AbstractButton b) { if (b instanceof TristateCheckBox) { TristateState state = ((TristateCheckBox) b).getState(); if (state == TristateState.INDETERMINATE) { diff --git a/src/main/java/com/github/weisj/darklaf/util/Animator.java b/src/main/java/com/github/weisj/darklaf/util/Animator.java index 40d32ac2..6af1db7b 100644 --- a/src/main/java/com/github/weisj/darklaf/util/Animator.java +++ b/src/main/java/com/github/weisj/darklaf/util/Animator.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -77,7 +74,7 @@ public abstract class Animator { startTime = -1; } - @NotNull + private static ScheduledExecutorService createScheduler() { ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, r -> { final Thread thread = new Thread(r, "Darcula Animations"); @@ -189,7 +186,7 @@ public abstract class Animator { return ticker != null; } - @Contract(pure = true) + public final boolean isForward() { return forward; } diff --git a/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java b/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java index faec5365..ae8bb6cc 100644 --- a/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java +++ b/src/main/java/com/github/weisj/darklaf/util/ColorUtil.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import java.awt.*; /** @@ -33,31 +30,28 @@ import java.awt.*; */ public final class ColorUtil { - @Contract(pure = true) + private ColorUtil() { } - @NotNull - @Contract("_, _ -> new") - public static Color shift(@NotNull final Color c, final double d) { + + public static Color shift(final Color c, final double d) { return new Color(shift(c.getRed(), d), shift(c.getGreen(), d), shift(c.getBlue(), d), c.getAlpha()); } - @Contract(pure = true) + private static int shift(final int colorComponent, final double d) { int n = (int) ((double) colorComponent * d); return n > 255 ? 255 : (Math.max(n, 0)); } - @NotNull - @Contract("_, _ -> new") + public static Color toAlpha(final Color color, final double alpha) { return toAlpha(color, (int) (alpha * 255)); } - @NotNull - @Contract("_, _ -> new") + public static Color toAlpha(final Color color, final int a) { Color c = color != null ? color : Color.black; return new Color(c.getRed(), c.getGreen(), c.getBlue(), Math.min(Math.max(0, a), 255)); @@ -71,8 +65,8 @@ public final class ColorUtil { } } - @NotNull - public static Color fromHex(@NotNull String str) { + + public static Color fromHex(String str) { if (str.startsWith("#")) { str = str.substring(1); } @@ -88,7 +82,7 @@ public final class ColorUtil { } } - @NotNull + public static Color removeAlpha(final Color color) { return toAlpha(color, 255); } diff --git a/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java b/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java index 4d0353b2..db7c8282 100644 --- a/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java +++ b/src/main/java/com/github/weisj/darklaf/util/DarkUIUtil.java @@ -25,9 +25,6 @@ package com.github.weisj.darklaf.util; import com.github.weisj.darklaf.decorators.CellRenderer; import com.github.weisj.darklaf.ui.popupmenu.DarkPopupMenuUI; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import sun.awt.SunToolkit; import javax.swing.*; @@ -78,7 +75,7 @@ public final class DarkUIUtil { doPaint(g, width, height, arc, bw); } - private static void doPaint(@NotNull final Graphics2D g, final int width, final int height, final float arc, + private static void doPaint(final Graphics2D g, final int width, final int height, final float arc, final float bw) { GraphicsContext context = GraphicsUtil.setupStrokePainting(g); @@ -125,13 +122,13 @@ public final class DarkUIUtil { config.restore(); } - public static void fillRoundRect(@NotNull final Graphics2D g, final float x, final float y, + public static void fillRoundRect(final Graphics2D g, final float x, final float y, final float width, final float height, final int arc) { g.fill(new RoundRectangle2D.Float(x, y, width, height, arc, arc)); } - @NotNull - public static Color blendColors(@NotNull final Color color1, @NotNull final Color color2, final double percent) { + + public static Color blendColors(final Color color1, final Color color2, final double percent) { if (percent == 1) return color1; if (percent == 0) return color2; double inverse_percent = 1.0 - percent; @@ -182,16 +179,15 @@ public final class DarkUIUtil { return ActionEvent.ALT_MASK; } - @Nullable - @Contract(pure = true) - public static Object getUIOfType(final ComponentUI ui, @NotNull final Class klass) { + + public static Object getUIOfType(final ComponentUI ui, final Class klass) { if (klass.isInstance(ui)) { return ui; } return null; } - public static void doNotCancelPopupSetup(@NotNull final JComponent component) { + public static void doNotCancelPopupSetup(final JComponent component) { component.putClientProperty("doNotCancelPopup", DarkPopupMenuUI.HIDE_POPUP_KEY); component.putClientProperty("doNotCancelOnScroll", Boolean.TRUE); } @@ -205,7 +201,7 @@ public final class DarkUIUtil { } @SuppressWarnings("unchecked") - @Nullable + public static T getParentOfType(final Class cls, final Component c) { for (Component eachParent = c; eachParent != null; eachParent = eachParent.getParent()) { if (cls.isAssignableFrom(eachParent.getClass())) { @@ -215,21 +211,20 @@ public final class DarkUIUtil { return null; } - @Contract("null -> null") - @Nullable - public static Window getWindow(@Nullable final Component component) { + + public static Window getWindow(final Component component) { if (component == null) { return null; } return component instanceof Window ? (Window) component : SwingUtilities.getWindowAncestor(component); } - public static boolean isTooltipShowing(@NotNull final JComponent component) { + public static boolean isTooltipShowing(final JComponent component) { AbstractAction hideTipAction = (AbstractAction) component.getActionMap().get("hideTip"); return hideTipAction.isEnabled(); } - @Nullable + public static MenuElement findEnabledChild(final MenuElement[] e, final MenuElement elem, final boolean forward) { for (int i = 0; i < e.length; i++) { if (e[i] == elem) { @@ -251,7 +246,7 @@ public final class DarkUIUtil { return result; } - @Nullable + private static MenuElement nextEnabledChild(final MenuElement[] e, final int fromIndex, final int toIndex) { for (int i = fromIndex; i <= toIndex; i++) { if (e[i] != null) { @@ -266,7 +261,7 @@ public final class DarkUIUtil { return null; } - @Nullable + private static MenuElement previousEnabledChild(final MenuElement[] e, final int fromIndex, final int toIndex) { for (int i = fromIndex; i >= toIndex; i--) { if (e[i] != null) { @@ -281,7 +276,7 @@ public final class DarkUIUtil { return null; } - public static void drawRect(@NotNull final Graphics g, final int x, final int y, + public static void drawRect(final Graphics g, final int x, final int y, final int width, final int height, final int thickness) { g.fillRect(x, y, width, thickness); g.fillRect(x, y + thickness, thickness, height - 2 * thickness); @@ -289,7 +284,7 @@ public final class DarkUIUtil { g.fillRect(x, y + height - thickness, width, thickness); } - public static boolean isOverText(@NotNull final MouseEvent e, final int index, final JList list) { + public static boolean isOverText(final MouseEvent e, final int index, final JList list) { Rectangle bounds = list.getCellBounds(index, index); if (!bounds.contains(e.getPoint())) return false; //noinspection unchecked @@ -314,7 +309,7 @@ public final class DarkUIUtil { return textRect.contains(p); } - public static boolean isOverText(@NotNull final MouseEvent e, final int row, final int column, + public static boolean isOverText(final MouseEvent e, final int row, final int column, final JTable table) { Rectangle bounds = table.getCellRect(row, column, false); if (!bounds.contains(e.getPoint())) return false; @@ -327,12 +322,12 @@ public final class DarkUIUtil { } } - public static boolean isMenuShortcutKeyDown(@NotNull final InputEvent event) { + public static boolean isMenuShortcutKeyDown(final InputEvent event) { return (event.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0; } @SuppressWarnings("SuspiciousNameCombination") - public static void rotateRectangle(@NotNull final Rectangle rect) { + public static void rotateRectangle(final Rectangle rect) { int tmp = rect.x; rect.x = rect.y; rect.y = tmp; @@ -342,7 +337,7 @@ public final class DarkUIUtil { } @SuppressWarnings("SuspiciousNameCombination") - public static void rotatePoint(@NotNull final Point p) { + public static void rotatePoint(final Point p) { int tmp = p.x; p.x = p.y; p.y = tmp; diff --git a/src/main/java/com/github/weisj/darklaf/util/GraphicsUtil.java b/src/main/java/com/github/weisj/darklaf/util/GraphicsUtil.java index 0e3bac3e..e00ddfd2 100644 --- a/src/main/java/com/github/weisj/darklaf/util/GraphicsUtil.java +++ b/src/main/java/com/github/weisj/darklaf/util/GraphicsUtil.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import java.awt.*; import java.util.Map; @@ -35,16 +32,16 @@ import java.util.Map; */ public final class GraphicsUtil { - @Contract(pure = true) + private GraphicsUtil() { } - @NotNull + public static GraphicsContext setupAntialiasing(final Graphics g2) { return setupAntialiasing(g2, true, false); } - @NotNull + public static GraphicsContext setupAntialiasing(final Graphics g2, final boolean enableAA, final boolean ignoreSystemSettings) { GraphicsContext config = new GraphicsContext(g2); @@ -64,7 +61,7 @@ public final class GraphicsUtil { return config; } - @NotNull + public static GraphicsContext setupAAPainting(final Graphics g) { GraphicsContext config = new GraphicsContext(g); Graphics2D g2 = (Graphics2D) g; @@ -73,7 +70,7 @@ public final class GraphicsUtil { return config; } - @NotNull + public static GraphicsContext paintWithAlpha(final Graphics g, final float alpha) { assert 0.0F <= alpha && alpha <= 1.0F : "alpha should be in range 0.0f .. 1.0f"; @@ -83,7 +80,7 @@ public final class GraphicsUtil { return config; } - @NotNull + public static GraphicsContext setupStrokePainting(final Graphics g) { Graphics2D g2 = (Graphics2D) g; GraphicsContext context = new GraphicsContext(g2); diff --git a/src/main/java/com/github/weisj/darklaf/util/ImageUtil.java b/src/main/java/com/github/weisj/darklaf/util/ImageUtil.java index b0d54c48..88f994b5 100644 --- a/src/main/java/com/github/weisj/darklaf/util/ImageUtil.java +++ b/src/main/java/com/github/weisj/darklaf/util/ImageUtil.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; @@ -35,7 +32,7 @@ import java.awt.image.BufferedImage; */ public final class ImageUtil { - @Contract(pure = true) + private ImageUtil() { } @@ -46,8 +43,8 @@ public final class ImageUtil { * @param bounds the bounds inside the component to capture. * @return image containing the captured area. */ - @NotNull - public static Image scaledImageFromComponent(@NotNull final Component c, @NotNull final Rectangle bounds) { + + public static Image scaledImageFromComponent(final Component c, final Rectangle bounds) { return scaledImageFromComponent(c, bounds, Scale.SCALE_X, Scale.SCALE_Y); } @@ -60,8 +57,8 @@ public final class ImageUtil { * @param scaley the y scale * @return image containing the captured area. */ - @NotNull - public static Image scaledImageFromComponent(@NotNull final Component c, @NotNull final Rectangle bounds, + + public static Image scaledImageFromComponent(final Component c, final Rectangle bounds, final double scalex, final double scaley) { BufferedImage image; boolean scale = scalex != 1.0 || scaley != 1.0; @@ -89,13 +86,13 @@ public final class ImageUtil { * @param bounds the bounds inside the component to capture. * @return image containing the captured area. */ - @NotNull - public static Image imageFromComponent(@NotNull final Component c, @NotNull final Rectangle bounds) { + + public static Image imageFromComponent(final Component c, final Rectangle bounds) { return scaledImageFromComponent(c, bounds, 1.0, 1.0); } - @NotNull - public static Icon cropIcon(@NotNull final Icon icon, int maxWidth, int maxHeight) { + + public static Icon cropIcon(final Icon icon, int maxWidth, int maxHeight) { if (icon.getIconHeight() <= maxHeight && icon.getIconWidth() <= maxWidth) { return icon; } @@ -138,8 +135,7 @@ public final class ImageUtil { } } - @NotNull - @Contract("null -> fail") + public static BufferedImage toBufferedImage(final Image image) { if (image == null) { throw new NullPointerException("Can't covert null image"); @@ -157,8 +153,7 @@ public final class ImageUtil { } } - @NotNull - @Contract("_, _, _ -> new") + public static BufferedImage createImage(final int width, final int height, final int type) { return new BufferedImage(Scale.scaleWidth(width), Scale.scaleHeight(height), type) { @Override diff --git a/src/main/java/com/github/weisj/darklaf/util/LazyActionMap.java b/src/main/java/com/github/weisj/darklaf/util/LazyActionMap.java index 94976e8a..054b8259 100644 --- a/src/main/java/com/github/weisj/darklaf/util/LazyActionMap.java +++ b/src/main/java/com/github/weisj/darklaf/util/LazyActionMap.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import javax.swing.plaf.ActionMapUIResource; import java.lang.reflect.InvocationTargetException; @@ -80,7 +78,7 @@ public class LazyActionMap extends ActionMapUIResource { * registered on. * @return the action map */ - @NotNull + public static ActionMap getActionMap(final Class loaderClass, final String defaultsKey) { ActionMap map = (ActionMap) UIManager.get(defaultsKey); diff --git a/src/main/java/com/github/weisj/darklaf/util/Pair.java b/src/main/java/com/github/weisj/darklaf/util/Pair.java index 4ca395a2..d4cec7c2 100644 --- a/src/main/java/com/github/weisj/darklaf/util/Pair.java +++ b/src/main/java/com/github/weisj/darklaf/util/Pair.java @@ -23,14 +23,12 @@ */ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.Contract; - public class Pair { private T first; private H second; - @Contract(pure = true) + public Pair(final T first, final H second) { this.first = first; this.second = second; diff --git a/src/main/java/com/github/weisj/darklaf/util/PropertyLoader.java b/src/main/java/com/github/weisj/darklaf/util/PropertyLoader.java index 7d8a59fa..899c44a0 100644 --- a/src/main/java/com/github/weisj/darklaf/util/PropertyLoader.java +++ b/src/main/java/com/github/weisj/darklaf/util/PropertyLoader.java @@ -26,9 +26,6 @@ package com.github.weisj.darklaf.util; import com.github.weisj.darklaf.icons.DarkUIAwareIcon; import com.github.weisj.darklaf.icons.EmptyIcon; import com.github.weisj.darklaf.icons.IconLoader; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.plaf.ColorUIResource; @@ -79,8 +76,8 @@ public final class PropertyLoader { objectsToLoad.clear(); } - @NotNull - public static Properties loadProperties(@NotNull final Class clazz, final String name, final String path) { + + public static Properties loadProperties(final Class clazz, final String name, final String path) { final Properties properties = new Properties(); try (InputStream stream = clazz.getResourceAsStream(path + name + ".properties")) { properties.load(stream); @@ -90,7 +87,7 @@ public final class PropertyLoader { return properties; } - public static void putProperties(@NotNull final Properties properties, final Properties accumulator, + public static void putProperties(final Properties properties, final Properties accumulator, final UIDefaults currentDefaults) { for (final String key : properties.stringPropertyNames()) { final String value = properties.getProperty(key); @@ -105,17 +102,17 @@ public final class PropertyLoader { } } - private static Object parseValue(@NotNull final String key, @NotNull final String value, + private static Object parseValue(final String key, final String value, final Map defaults) { return parseValue(key, value, false, defaults); } - private static String parseKey(@NotNull final String key) { + private static String parseKey(final String key) { return key.startsWith(REFERENCE_PREFIX) ? key.substring(REFERENCE_PREFIX.length()) : key; } - @Nullable - private static Object parseValue(@NotNull final String propertyKey, @NotNull final String value, + + private static Object parseValue(final String propertyKey, final String value, final boolean ignoreRequest, final Map defaults) { if ("null".equals(value)) { return null; @@ -172,7 +169,7 @@ public final class PropertyLoader { return value; } - @NotNull + private static Object parseInsets(final String value) { final List numbers = StringUtil.split(value, ","); return new InsetsUIResource( @@ -182,18 +179,17 @@ public final class PropertyLoader { Integer.parseInt(numbers.get(3))); } - @NotNull - @Contract("_ -> new") + private static Object parseFont(final String value) { try { final String[] decode = value.split("-"); return new FontUIResource(decode[0], Integer.parseInt(decode[1]), Integer.parseInt(decode[2])); - } catch (@NotNull final Exception e) { + } catch (final Exception e) { return new FontUIResource("Dialog", Font.PLAIN, 12); } } - private static Icon parseIcon(@NotNull final String value) { + private static Icon parseIcon(final String value) { String path = value; Dimension dim = new Dimension(16, 16); if (value.charAt(value.length() - 1) == ')') { @@ -234,26 +230,26 @@ public final class PropertyLoader { return ICON_LOADER.getIcon(path, dim.width, dim.height); } - @NotNull - private static DimensionUIResource parseSize(@NotNull final String value) { + + private static DimensionUIResource parseSize(final String value) { int[] dim = Arrays.stream(value.split(",", 2)).mapToInt(Integer::parseInt).toArray(); return new DimensionUIResource(dim[0], dim[1]); } - @Nullable - private static Integer getInteger(@NotNull final String value) { + + private static Integer getInteger(final String value) { try { return Integer.parseInt(value); - } catch (@NotNull final NumberFormatException ignored) { + } catch (final NumberFormatException ignored) { return null; } } - @Nullable + private static Object parseObject(final String value) { try { return Class.forName(value).getDeclaredConstructor().newInstance(); - } catch (@NotNull final Exception ignored) { } + } catch (final Exception ignored) { } return null; } @@ -265,13 +261,13 @@ public final class PropertyLoader { final String value; final String key; - @Contract(pure = true) + private ObjectRequest(final String key, final String value) { this.key = key; this.value = value; } - private void resolve(@NotNull final Map cache) { + private void resolve(final Map cache) { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); if (cache.containsKey(value)) { defaults.put(key, cache.get(value)); @@ -294,8 +290,7 @@ public final class PropertyLoader { } } - @NotNull - @Contract(pure = true) + @Override public String toString() { return "[" + key + "," + value + "]"; diff --git a/src/main/java/com/github/weisj/darklaf/util/ReflectionUtil.java b/src/main/java/com/github/weisj/darklaf/util/ReflectionUtil.java index 632c8b46..4e05519d 100644 --- a/src/main/java/com/github/weisj/darklaf/util/ReflectionUtil.java +++ b/src/main/java/com/github/weisj/darklaf/util/ReflectionUtil.java @@ -23,7 +23,6 @@ */ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.Nullable; import sun.misc.Unsafe; import java.lang.reflect.Field; @@ -36,7 +35,7 @@ public final class ReflectionUtil { * @param newLogger the new logger to use. * @return the logger that was used previously. */ - @Nullable + public static Object changeIllegalAccessLogger(final Object newLogger) { try { Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); diff --git a/src/main/java/com/github/weisj/darklaf/util/Scale.java b/src/main/java/com/github/weisj/darklaf/util/Scale.java index c721d493..d3eb7a3c 100644 --- a/src/main/java/com/github/weisj/darklaf/util/Scale.java +++ b/src/main/java/com/github/weisj/darklaf/util/Scale.java @@ -23,8 +23,6 @@ */ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.Contract; - import java.awt.*; import java.util.logging.Logger; @@ -43,47 +41,47 @@ public final class Scale { LOGGER.info("Using screen scaling SCALE_X=" + SCALE_X + ", SCALE_Y=" + SCALE_Y); } - @Contract(pure = true) + public static int scale(final int i) { return (int) (SCALE * i); } - @Contract(pure = true) + public static float scale(final float f) { return (float) (SCALE * f); } - @Contract(pure = true) + public static double scale(final double d) { return SCALE * d; } - @Contract(pure = true) + public static int scaleWidth(final int i) { return (int) (SCALE_X * i); } - @Contract(pure = true) + public static float scaleWidth(final float f) { return (float) (SCALE_X * f); } - @Contract(pure = true) + public static double scaleWidth(final double d) { return SCALE_X * d; } - @Contract(pure = true) + public static int scaleHeight(final int i) { return (int) (SCALE_Y * i); } - @Contract(pure = true) + public static float scaleHeight(final float f) { return (float) (SCALE_Y * f); } - @Contract(pure = true) + public static double scaleHeight(final double d) { return SCALE_Y * d; } diff --git a/src/main/java/com/github/weisj/darklaf/util/StringUtil.java b/src/main/java/com/github/weisj/darklaf/util/StringUtil.java index 413acced..2f1ad831 100644 --- a/src/main/java/com/github/weisj/darklaf/util/StringUtil.java +++ b/src/main/java/com/github/weisj/darklaf/util/StringUtil.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -36,17 +33,16 @@ import java.util.List; */ public final class StringUtil { - @Contract(pure = true) + private StringUtil() { } - @Contract("null -> null; !null -> !null") + public static String toUpperCase(final String a) { return a == null ? null : toUpperCase((CharSequence) a).toString(); } - @NotNull - @Contract("null -> fail") + public static CharSequence toUpperCase(final CharSequence s) { if (s == null) { throw new NullPointerException("CharSequence can't be null"); @@ -65,7 +61,7 @@ public final class StringUtil { return answer; } - @Contract(pure = true) + public static char toUpperCase(final char a) { if (a < 'a') { return a; @@ -82,7 +78,7 @@ public final class StringUtil { return split(s, separator, excludeSeparator, true); } - public static List split(final String s, @NotNull final String separator, + public static List split(final String s, final String separator, final boolean excludeSeparator, final boolean excludeEmptyStrings) { if (separator.isEmpty()) { return Collections.singletonList(s); @@ -111,7 +107,7 @@ public final class StringUtil { } } - public static int indexOfIgnoreCase(@NotNull final String where, final char what, int fromIndex) { + public static int indexOfIgnoreCase(final String where, final char what, int fromIndex) { int sourceCount = where.length(); if (fromIndex >= sourceCount) { return -1; @@ -134,7 +130,7 @@ public final class StringUtil { return a == b || toUpperCase(a) == toUpperCase(b) || toLowerCase(a) == toLowerCase(b); } - @Contract(pure = true) + public static char toLowerCase(final char a) { if (a >= 'A' && (a < 'a' || a > 'z')) { return a <= 'Z' ? (char) (a + 32) : Character.toLowerCase(a); @@ -244,8 +240,8 @@ public final class StringUtil { return s.trim().length() == 0; } - @NotNull - public static String repeat(@NotNull final String s, final int count) { + + public static String repeat(final String s, final int count) { if (count <= 0) return s; if (count == 1) return s; StringBuilder builder = new StringBuilder(s.length() * count); diff --git a/src/main/java/com/github/weisj/darklaf/util/SwingXUtilities.java b/src/main/java/com/github/weisj/darklaf/util/SwingXUtilities.java index e9f74cb5..f99ef014 100644 --- a/src/main/java/com/github/weisj/darklaf/util/SwingXUtilities.java +++ b/src/main/java/com/github/weisj/darklaf/util/SwingXUtilities.java @@ -24,7 +24,6 @@ package com.github.weisj.darklaf.util; import org.jdesktop.jxlayer.JXLayer; -import org.jetbrains.annotations.NotNull; import org.pbjar.jxlayer.plaf.ext.TransformUI; import javax.swing.*; @@ -33,7 +32,7 @@ import java.awt.geom.AffineTransform; public class SwingXUtilities { - @NotNull + public static Point convertPointToParent(final Component source, final Point p) { JXLayer layer = DarkUIUtil.getParentOfType(JXLayer.class, source); if (layer != null && layer.getUI() instanceof TransformUI) { diff --git a/src/main/java/com/github/weisj/darklaf/util/SystemInfo.java b/src/main/java/com/github/weisj/darklaf/util/SystemInfo.java index a36d0bc3..2d94d8de 100644 --- a/src/main/java/com/github/weisj/darklaf/util/SystemInfo.java +++ b/src/main/java/com/github/weisj/darklaf/util/SystemInfo.java @@ -24,8 +24,6 @@ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.Contract; - /** * @author Konstantin Bulenkov */ @@ -67,7 +65,7 @@ public class SystemInfo { isUndefined = !isX86 & !isX64; } - @Contract(pure = true) + public SystemInfo() { } diff --git a/src/main/java/com/github/weisj/darklaf/util/TimerUtil.java b/src/main/java/com/github/weisj/darklaf/util/TimerUtil.java index 4d7f0e71..76c3ccf9 100644 --- a/src/main/java/com/github/weisj/darklaf/util/TimerUtil.java +++ b/src/main/java/com/github/weisj/darklaf/util/TimerUtil.java @@ -23,9 +23,6 @@ */ package com.github.weisj.darklaf.util; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.event.ActionListener; @@ -33,10 +30,10 @@ import java.awt.event.ActionListener; * @author Jannis Weis */ public final class TimerUtil { - @Contract("_, _, _ -> new") - @NotNull - public static Timer createNamedTimer(@NotNull final String name, final int delay, - @NotNull final ActionListener listener) { + + + public static Timer createNamedTimer(final String name, final int delay, + final ActionListener listener) { return new Timer(delay, listener) { @Override public String toString() { @@ -45,9 +42,8 @@ public final class TimerUtil { }; } - @Contract("_, _ -> new") - @NotNull - public static Timer createNamedTimer(@NotNull final String name, final int delay) { + + public static Timer createNamedTimer(final String name, final int delay) { return new Timer(delay, null) { @Override public String toString() { diff --git a/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java b/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java index c8978781..baed7fba 100644 --- a/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java +++ b/src/main/java/javax/swing/text/DefaultHighlighterDark/DarkHighlightPainter.java @@ -27,8 +27,6 @@ import com.github.weisj.darklaf.color.ColorWrapper; import com.github.weisj.darklaf.ui.text.StyleConstantsEx; import com.github.weisj.darklaf.util.GraphicsContext; import com.github.weisj.darklaf.util.GraphicsUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import sun.swing.SwingUtilities2; import javax.swing.*; @@ -120,7 +118,7 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai * @param c the editor */ @Override - public void paint(final Graphics g, final int offs0, final int offs1, @NotNull final Shape bounds, + public void paint(final Graphics g, final int offs0, final int offs1, final Shape bounds, final JTextComponent c) { Rectangle alloc = bounds.getBounds(); Graphics2D g2d = (Graphics2D) g; @@ -188,7 +186,7 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai @Override public Shape paintLayer(final Graphics g, final int offs0, final int offs1, - final Shape bounds, final JTextComponent c, @NotNull final View view) { + final Shape bounds, final JTextComponent c, final View view) { color = (Color) view.getAttributes().getAttribute(StyleConstantsEx.SelectedForeground); if (color == null) { color = c.getSelectedTextColor(); @@ -229,17 +227,8 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai return dirtyShape; } - private void setupColor(final Graphics2D g2d, @NotNull final JTextComponent c) { - Paint paint = getPaint(); - if (paint == null) { - g2d.setColor(c.getSelectionColor()); - } else { - g2d.setPaint(paint); - } - } - protected Shape paintLayerImpl(final Graphics2D g2d, final int offs0, final int offs1, - @NotNull final JTextComponent c) throws BadLocationException { + final JTextComponent c) throws BadLocationException { Shape dirtyShape; Rectangle posStart = c.modelToView(c.getSelectionStart()); Rectangle posEnd = c.modelToView(c.getSelectionEnd()); @@ -325,7 +314,33 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai return dirtyShape; } - @NotNull + private Shape paintSelectionStart(final Graphics2D g2d, final Rectangle r, + final JTextComponent c, + final Rectangle posStart, + final Rectangle posOffs0, + final boolean endBeforeStart, final boolean isSecondLastLine, + final boolean extendToEnd) { + if (DEBUG_COLOR) g2d.setColor(Color.RED); + Insets margin = c.getMargin(); + boolean rounded = isRounded(c); + if (rounded && extendToEnd) r.width -= arcSize; + if (rounded) { + boolean roundLeftBottom = endBeforeStart && isSecondLastLine; + if (r.width < 2 * arcSize) r.width = 2 * arcSize; + paintRoundRect(g2d, r, arcSize, true, false, roundLeftBottom, false); + boolean drawCorner = posOffs0.equals(posStart) && !roundLeftBottom && r.x >= margin.left + arcSize; + if (drawCorner) { + paintStartArc(g2d, r); + r.x -= arcSize; + r.width += arcSize; + } + } else { + g2d.fillRect(r.x, r.y, r.width, r.height); + } + return r; + } + + private Shape paintMiddleSelection(final Graphics2D g, final Rectangle r, final JTextComponent c, final boolean toEndOfLine, final boolean toStartOfLine, final boolean isFirstLine, final boolean isLastLine, @@ -350,8 +365,8 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai /* * Selection is contained to one line. */ - @Contract("_, _, _, _, _ -> param3") - @NotNull + + private Shape paintSelection(final Graphics2D g2d, final JTextComponent c, final Rectangle r, final boolean selectionStart, final boolean selectionEnd) { if (DEBUG_COLOR) g2d.setColor(Color.BLUE); @@ -363,43 +378,8 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai return r; } - @Contract("_, _, _, _, _, _, _, _ -> param2") - @NotNull - private Shape paintSelectionStart(@NotNull final Graphics2D g2d, @NotNull final Rectangle r, - @NotNull final JTextComponent c, - @NotNull final Rectangle posStart, - final Rectangle posOffs0, - final boolean endBeforeStart, final boolean isSecondLastLine, - final boolean extendToEnd) { - if (DEBUG_COLOR) g2d.setColor(Color.RED); - Insets margin = c.getMargin(); - boolean rounded = isRounded(c); - if (rounded && extendToEnd) r.width -= arcSize; - if (rounded) { - boolean roundLeftBottom = endBeforeStart && isSecondLastLine; - if (r.width < 2 * arcSize) r.width = 2 * arcSize; - paintRoundRect(g2d, r, arcSize, true, false, roundLeftBottom, false); - boolean drawCorner = posOffs0.equals(posStart) && !roundLeftBottom && r.x >= margin.left + arcSize; - if (drawCorner) { - paintStartArc(g2d, r); - r.x -= arcSize; - r.width += arcSize; - } - } else { - g2d.fillRect(r.x, r.y, r.width, r.height); - } - return r; - } - - private boolean isRounded(final JTextComponent c) { - return !suppressRounded - && (roundedEdges || Boolean.TRUE.equals(c.getClientProperty("JTextComponent.roundedSelection"))); - } - - @Contract("_, _, _, _, _, _, _, _, _ -> param2") - @NotNull - private Shape paintSelectionEnd(@NotNull final Graphics2D g2d, @NotNull final Rectangle r, - @NotNull final JTextComponent c, final Rectangle posStart, + private Shape paintSelectionEnd(final Graphics2D g2d, final Rectangle r, + final JTextComponent c, final Rectangle posStart, final boolean isFirstLine, final boolean isSecondLine, final boolean extendToStart, final boolean extendToEnd, final boolean endBeforeStart) { @@ -427,7 +407,12 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai return r; } - private Shape paintExtension(final Graphics2D g2d, @NotNull final JTextComponent c, + private boolean isRounded(final JTextComponent c) { + return !suppressRounded + && (roundedEdges || Boolean.TRUE.equals(c.getClientProperty("JTextComponent.roundedSelection"))); + } + + private Shape paintExtension(final Graphics2D g2d, final JTextComponent c, final boolean isToEndOfLine, final boolean isToStartOfLine, final boolean isFirstLine, final boolean isLastLine, final boolean isSecondLine, final boolean isSecondLastLine, @@ -476,7 +461,7 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai return r; } - private void paintRoundRect(@NotNull final Graphics g, @NotNull final Rectangle r, final int arcSize, + private void paintRoundRect(final Graphics g, final Rectangle r, final int arcSize, final boolean leftTop, final boolean rightTop, final boolean leftBottom, final boolean rightBottom) { int aw = Math.min(arcSize, r.width); @@ -488,6 +473,19 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai if (!rightBottom) g.fillRect(r.x + r.width - aw, r.y + r.height - ah, aw, ah); } + private void paintStartArc(final Graphics2D g2d, final Rectangle r) { + if (DEBUG_COLOR) g2d.setColor(Color.PINK); + Area arc = new Area(new Rectangle2D.Double( + r.x - arcSize + 0.25, r.y + r.height - arcSize + 0.25, arcSize, arcSize)); + arc.subtract(new Area(new Arc2D.Double( + r.x - 2 * arcSize + 0.25, + r.y + r.height - 2 * arcSize + 0.25, 2 * arcSize, 2 * arcSize, + 0, -90, Arc2D.Double.PIE))); + g2d.fill(arc); + r.x -= arcSize; + r.width += arcSize; + } + private void paintRoundedLeftRight(final Graphics g, final boolean left, final boolean right, final Rectangle r) { if (right || left) { g.fillRoundRect(r.x, r.y, r.width, r.height, arcSize, arcSize); @@ -503,20 +501,7 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai } } - private void paintStartArc(@NotNull final Graphics2D g2d, @NotNull final Rectangle r) { - if (DEBUG_COLOR) g2d.setColor(Color.PINK); - Area arc = new Area(new Rectangle2D.Double( - r.x - arcSize + 0.25, r.y + r.height - arcSize + 0.25, arcSize, arcSize)); - arc.subtract(new Area(new Arc2D.Double( - r.x - 2 * arcSize + 0.25, - r.y + r.height - 2 * arcSize + 0.25, 2 * arcSize, 2 * arcSize, - 0, -90, Arc2D.Double.PIE))); - g2d.fill(arc); - r.x -= arcSize; - r.width += arcSize; - } - - private void paintEndArc(@NotNull final Graphics2D g2d, @NotNull final Rectangle r) { + private void paintEndArc(final Graphics2D g2d, final Rectangle r) { if (DEBUG_COLOR) g2d.setColor(Color.PINK); Area arc = new Area(new Rectangle2D.Double( r.x + r.width - 0.25, r.y - 0.25, arcSize, arcSize)); @@ -525,4 +510,13 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai r.y - 0.25, 2 * arcSize, 2 * arcSize, 90, 90, Arc2D.Double.PIE))); g2d.fill(arc); } + + private void setupColor(final Graphics2D g2d, final JTextComponent c) { + Paint paint = getPaint(); + if (paint == null) { + g2d.setColor(c.getSelectionColor()); + } else { + g2d.setPaint(paint); + } + } } diff --git a/src/main/java/org/pbjar/jxlayer/plaf/ext/MouseEventUI.java b/src/main/java/org/pbjar/jxlayer/plaf/ext/MouseEventUI.java index 989ddce3..1c7d187b 100644 --- a/src/main/java/org/pbjar/jxlayer/plaf/ext/MouseEventUI.java +++ b/src/main/java/org/pbjar/jxlayer/plaf/ext/MouseEventUI.java @@ -33,9 +33,6 @@ package org.pbjar.jxlayer.plaf.ext; import org.jdesktop.jxlayer.JXLayer; import org.jdesktop.jxlayer.plaf.AbstractLayerUI; import org.jdesktop.jxlayer.plaf.LayerUI; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.plaf.ComponentUI; @@ -69,10 +66,10 @@ public class MouseEventUI extends AbstractLayerUI { new JInternalFrame(); } - @Nullable + private Component lastEnteredTarget, lastPressedTarget; private boolean dispatchingMode = false; - @Nullable + private JXLayer installedLayer; /** @@ -82,7 +79,7 @@ public class MouseEventUI extends AbstractLayerUI { */ @SuppressWarnings("deprecation") @Override - public boolean contains(@NotNull final JComponent c, final int x, final int y) { + public boolean contains(final JComponent c, final int x, final int y) { return c.inside(x, y); } @@ -95,7 +92,7 @@ public class MouseEventUI extends AbstractLayerUI { */ @SuppressWarnings("unchecked") @Override - public void installUI(@NotNull final JComponent component) throws IllegalStateException { + public void installUI(final JComponent component) throws IllegalStateException { super.installUI(component); if (installedLayer != null) { throw new IllegalStateException(this.getClass().getName() @@ -108,7 +105,7 @@ public class MouseEventUI extends AbstractLayerUI { * Overridden to remove the installed {@link JXLayer}. */ @Override - public void uninstallUI(@NotNull final JComponent c) { + public void uninstallUI(final JComponent c) { installedLayer = null; super.uninstallUI(c); } @@ -128,7 +125,7 @@ public class MouseEventUI extends AbstractLayerUI { * components according to their bounds. */ @Override - public void eventDispatched(final AWTEvent event, @NotNull final JXLayer layer) { + public void eventDispatched(final AWTEvent event, final JXLayer layer) { if (event instanceof MouseEvent) { MouseEvent mouseEvent = (MouseEvent) event; if (!dispatchingMode) { @@ -161,8 +158,8 @@ public class MouseEventUI extends AbstractLayerUI { * registered. */ @Override - protected void processMouseWheelEvent(@NotNull final MouseWheelEvent event, - @NotNull final JXLayer jxlayer) { + protected void processMouseWheelEvent(final MouseWheelEvent event, + final JXLayer jxlayer) { /* * Only process an event if it is not already consumed. This may be the * case if this LayerUI is contained in a wrapped hierarchy. @@ -195,9 +192,9 @@ public class MouseEventUI extends AbstractLayerUI { } } - @NotNull - private Point calculateTargetPoint(@NotNull final JXLayer layer, - @NotNull final MouseEvent mouseEvent) { + + private Point calculateTargetPoint(final JXLayer layer, + final MouseEvent mouseEvent) { Point point = mouseEvent.getPoint(); SwingUtilities.convertPointToScreen(point, mouseEvent.getComponent()); SwingUtilities.convertPointFromScreen(point, layer); @@ -221,9 +218,9 @@ public class MouseEventUI extends AbstractLayerUI { // } } - @NotNull + private MouseWheelEvent createMouseWheelEvent( - @NotNull final MouseWheelEvent mouseWheelEvent, @NotNull final Point point, @NotNull final Component target) { + final MouseWheelEvent mouseWheelEvent, final Point point, final Component target) { return new MouseWheelEvent(target, // mouseWheelEvent.getID(), // mouseWheelEvent.getWhen(), // @@ -238,16 +235,15 @@ public class MouseEventUI extends AbstractLayerUI { ); } - private void dispatchMouseEvent(@Nullable final MouseEvent mouseEvent) { + private void dispatchMouseEvent(final MouseEvent mouseEvent) { if (mouseEvent != null) { Component target = mouseEvent.getComponent(); target.dispatchEvent(mouseEvent); } } - @Contract("null -> null") - @Nullable - private Component findWheelListenerComponent(@Nullable final Component target) { + + private Component findWheelListenerComponent(final Component target) { if (target == null) { return null; } else if (target.getMouseWheelListeners().length == 0) { @@ -257,8 +253,8 @@ public class MouseEventUI extends AbstractLayerUI { } } - private void generateEnterExitEvents(@NotNull final JXLayer layer, - @NotNull final MouseEvent originalEvent, final Component newTarget, @NotNull final Point realPoint) { + private void generateEnterExitEvents(final JXLayer layer, + final MouseEvent originalEvent, final Component newTarget, final Point realPoint) { if (lastEnteredTarget != newTarget) { dispatchMouseEvent(transformMouseEvent(layer, originalEvent, lastEnteredTarget, realPoint, MouseEvent.MOUSE_EXITED)); @@ -269,8 +265,8 @@ public class MouseEventUI extends AbstractLayerUI { } @SuppressWarnings("DuplicatedCode") - @Nullable - private Component getListeningComponent(@NotNull final MouseEvent event, @NotNull final Component component) { + + private Component getListeningComponent(final MouseEvent event, final Component component) { Component comp; switch (event.getID()) { case MouseEvent.MOUSE_CLICKED: @@ -293,8 +289,8 @@ public class MouseEventUI extends AbstractLayerUI { return comp; } - @Nullable - private Component getMouseListeningComponent(@NotNull final Component component) { + + private Component getMouseListeningComponent(final Component component) { if (component.getMouseListeners().length > 0) { return component; } else { @@ -308,8 +304,8 @@ public class MouseEventUI extends AbstractLayerUI { } @SuppressWarnings("Duplicates") - @Nullable - private Component getMouseMotionListeningComponent(@NotNull final Component component) { + + private Component getMouseMotionListeningComponent(final Component component) { /* * Mouse motion events may result in MOUSE_ENTERED and MOUSE_EXITED. * @@ -329,8 +325,8 @@ public class MouseEventUI extends AbstractLayerUI { } } - @Nullable - private Component getMouseWheelListeningComponent(@NotNull final Component component) { + + private Component getMouseWheelListeningComponent(final Component component) { if (component.getMouseWheelListeners().length > 0) { return component; } else { @@ -343,8 +339,8 @@ public class MouseEventUI extends AbstractLayerUI { } } - @Nullable - private Component getTarget(@NotNull final JXLayer layer, @NotNull final Point targetPoint) { + + private Component getTarget(final JXLayer layer, final Point targetPoint) { Component view = layer.getView(); if (view == null) { return null; @@ -357,8 +353,8 @@ public class MouseEventUI extends AbstractLayerUI { } @SuppressWarnings("Duplicates") - private void redispatch(@NotNull final MouseEvent originalEvent, - @NotNull final JXLayer layer) { + private void redispatch(final MouseEvent originalEvent, + final JXLayer layer) { if (layer.getView() != null) { if (originalEvent.getComponent() != layer.getGlassPane()) { originalEvent.consume(); @@ -407,23 +403,23 @@ public class MouseEventUI extends AbstractLayerUI { } } - private void redispatchMouseWheelEvent(@NotNull final MouseWheelEvent mouseWheelEvent, - final Component target, @NotNull final JXLayer layer) { + private void redispatchMouseWheelEvent(final MouseWheelEvent mouseWheelEvent, + final Component target, final JXLayer layer) { MouseWheelEvent newEvent = this.transformMouseWheelEvent( mouseWheelEvent, target, layer); processMouseWheelEvent(newEvent, layer); } - @Nullable - private MouseEvent transformMouseEvent(@NotNull final JXLayer layer, - @NotNull final MouseEvent mouseEvent, final Component target, @NotNull final Point realPoint) { + + private MouseEvent transformMouseEvent(final JXLayer layer, + final MouseEvent mouseEvent, final Component target, final Point realPoint) { return transformMouseEvent(layer, mouseEvent, target, realPoint, mouseEvent.getID()); } - @Nullable - private MouseEvent transformMouseEvent(@NotNull final JXLayer layer, - @NotNull final MouseEvent mouseEvent, @Nullable final Component target, @NotNull final Point targetPoint, final int id) { + + private MouseEvent transformMouseEvent(final JXLayer layer, + final MouseEvent mouseEvent, final Component target, final Point targetPoint, final int id) { if (target == null) { return null; } else { @@ -442,9 +438,9 @@ public class MouseEventUI extends AbstractLayerUI { } } - @NotNull + private MouseWheelEvent transformMouseWheelEvent( - @NotNull final MouseWheelEvent mouseWheelEvent, final Component t, + final MouseWheelEvent mouseWheelEvent, final Component t, final JXLayer layer) { Component target = t; if (target == null) { @@ -456,8 +452,8 @@ public class MouseEventUI extends AbstractLayerUI { point, target); } - @NotNull - private Point transformPoint(final JXLayer layer, @NotNull final Point point) { + + private Point transformPoint(final JXLayer layer, final Point point) { AffineTransform transform = this.getTransform(layer); if (transform != null) { try { @@ -469,7 +465,7 @@ public class MouseEventUI extends AbstractLayerUI { return point; } - @Nullable + protected JXLayer getInstalledLayer() { return installedLayer; } diff --git a/src/main/java/org/pbjar/jxlayer/plaf/ext/TransformUI.java b/src/main/java/org/pbjar/jxlayer/plaf/ext/TransformUI.java index 4c42d514..087ae9b2 100644 --- a/src/main/java/org/pbjar/jxlayer/plaf/ext/TransformUI.java +++ b/src/main/java/org/pbjar/jxlayer/plaf/ext/TransformUI.java @@ -36,9 +36,6 @@ import org.jdesktop.jxlayer.JXLayer; import org.jdesktop.jxlayer.plaf.AbstractBufferedLayerUI; import org.jdesktop.jxlayer.plaf.LayerUI; import org.jdesktop.swingx.ForwardingRepaintManager; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.pbjar.jxlayer.plaf.ext.transform.DefaultTransformModel; import org.pbjar.jxlayer.plaf.ext.transform.TransformLayout; import org.pbjar.jxlayer.plaf.ext.transform.TransformModel; @@ -156,20 +153,20 @@ public class TransformUI extends MouseEventUI { private final RepaintManagerProvider rpmProvider = new RepaintManagerProvider() { - @NotNull + @Override public Class getForwardingRepaintManagerClass() { return TransformRPMSwingX.class; } - @NotNull + @Override public Class getWrappedRepaintManagerClass() { return TransformRPMFallBack.class; } @Override - public boolean isAdequate(@NotNull final Class manager) { + public boolean isAdequate(final Class manager) { return manager.isAnnotationPresent(TransformRPMAnnotation.class); } }; @@ -178,7 +175,7 @@ public class TransformUI extends MouseEventUI { private JComponent view; private final PropertyChangeListener viewChangeListener = evt -> setView((JComponent) evt.getNewValue()); - @Nullable + private TransformModel transformModel; private LayoutManager originalLayout; @@ -240,7 +237,7 @@ public class TransformUI extends MouseEventUI { * * @param hints the new rendering hints */ - public void addRenderingHints(@NotNull final Map hints) { + public void addRenderingHints(final Map hints) { this.renderingHints.putAll(hints); } @@ -250,8 +247,8 @@ public class TransformUI extends MouseEventUI { * @return the {@link TransformModel} * @see #setModel(TransformModel) */ - @Contract(pure = true) - @Nullable + + public final TransformModel getModel() { return transformModel; } @@ -263,8 +260,8 @@ public class TransformUI extends MouseEventUI { * @throws NullPointerException if transformModel is {@code null} * @see #getModel() */ - @Contract("null -> fail") - public final void setModel(@Nullable final TransformModel transformModel) throws NullPointerException { + + public final void setModel(final TransformModel transformModel) throws NullPointerException { if (transformModel == null) { throw new NullPointerException("The TransformModel may not be null"); } @@ -290,7 +287,7 @@ public class TransformUI extends MouseEventUI { * @param layer the {@link JXLayer}. * @return a {@link AffineTransform} instance or {@code null} */ - @NotNull + public AffineTransform getPreferredTransform(final Dimension size, final JXLayer layer) { return this.transformModel != null ? this.transformModel.getPreferredTransform(size, layer) : new AffineTransform(); @@ -390,7 +387,7 @@ public class TransformUI extends MouseEventUI { * @see #uninstallUI(JComponent) */ @Override - public void installUI(@NotNull final JComponent component) { + public void installUI(final JComponent component) { super.installUI(component); JXLayer installedLayer = this.getInstalledLayer(); originalLayout = installedLayer.getLayout(); @@ -408,7 +405,7 @@ public class TransformUI extends MouseEventUI { * @param c the component. */ @Override - public void uninstallUI(@NotNull final JComponent c) { + public void uninstallUI(final JComponent c) { JXLayer installedLayer = this.getInstalledLayer(); Objects.requireNonNull(installedLayer) .removePropertyChangeListener(KEY_VIEW, this.viewChangeListener); @@ -437,7 +434,7 @@ public class TransformUI extends MouseEventUI { * * @param hints the new rendering hints or {@code null} to clear all rendering hints */ - public void setRenderingHints(@Nullable final Map hints) { + public void setRenderingHints(final Map hints) { this.renderingHints.clear(); if (hints != null) { this.renderingHints.putAll(hints); @@ -451,7 +448,7 @@ public class TransformUI extends MouseEventUI { * @param layer the layer * @return the argument rectangle if no {@link AffineTransform} is available, else a new rectangle */ - public final Rectangle transform(@NotNull final Rectangle rect, final JXLayer layer) { + public final Rectangle transform(final Rectangle rect, final JXLayer layer) { AffineTransform at = getTransform(layer); if (at == null) { return rect; @@ -475,7 +472,7 @@ public class TransformUI extends MouseEventUI { /* * Get the most suitable background color. */ - private Color getBackgroundColor(@NotNull final JXLayer layer) { + private Color getBackgroundColor(final JXLayer layer) { Container colorProvider = layer.getView() == null ? layer : layer.getView(); while (colorProvider != null && !colorProvider.isOpaque()) { colorProvider = colorProvider.getParent(); @@ -523,7 +520,7 @@ public class TransformUI extends MouseEventUI { * @see #paint(Graphics, JComponent) */ @Override - protected final void paintLayer(@NotNull final Graphics2D g2, @NotNull final JXLayer layer) { + protected final void paintLayer(final Graphics2D g2, final JXLayer layer) { JComponent view = layer.getView(); if (view != null) { if (view.getX() < 0 || view.getY() < 0) { @@ -546,7 +543,7 @@ public class TransformUI extends MouseEventUI { *

In {@code enabled} state this method is delegated to the {@link TransformModel} that has * been set. Otherwise {@code null} will be returned. */ - @NotNull + @Override protected final AffineTransform getTransform(final JXLayer layer) { return transformModel != null ? transformModel.getTransform(layer) @@ -561,7 +558,7 @@ public class TransformUI extends MouseEventUI { * @see #addRenderingHints(Map) * @see #addRenderingHint(RenderingHints.Key, Object) */ - @NotNull + @Override protected Map getRenderingHints(final JXLayer layer) { return renderingHints; @@ -593,7 +590,7 @@ public class TransformUI extends MouseEventUI { * current {@link RepaintManager}. */ @Override - public void addDirtyRegion(@NotNull final JComponent c, final int x, final int y, final int w, final int h) { + public void addDirtyRegion(final JComponent c, final int x, final int y, final int w, final int h) { if (c.isShowing()) { JXLayer layer = findJXLayer(c); TransformUI ui = (TransformUI) layer.getUI(); @@ -615,7 +612,7 @@ public class TransformUI extends MouseEventUI { * @param c a component * @return the ancestor {@link JXLayer} instance */ - @NotNull + @SuppressWarnings("unchecked") private JXLayer findJXLayer(final JComponent c) { JXLayer layer = (JXLayer) SwingUtilities.getAncestorOfClass(JXLayer.class, c); diff --git a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/DefaultLayerLayout.java b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/DefaultLayerLayout.java index 6720a543..28059359 100644 --- a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/DefaultLayerLayout.java +++ b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/DefaultLayerLayout.java @@ -31,7 +31,6 @@ package org.pbjar.jxlayer.plaf.ext.transform; */ import org.jdesktop.jxlayer.JXLayer; -import org.jetbrains.annotations.NotNull; import java.awt.*; import java.io.Serializable; @@ -57,7 +56,7 @@ public class DefaultLayerLayout implements LayoutManager, Serializable { /** * {@inheritDoc} */ - @NotNull + public Dimension preferredLayoutSize(final Container parent) { JXLayer layer = (JXLayer) parent; Insets insets = layer.getInsets(); @@ -76,7 +75,7 @@ public class DefaultLayerLayout implements LayoutManager, Serializable { /** * {@inheritDoc} */ - @NotNull + public Dimension minimumLayoutSize(final Container parent) { JXLayer layer = (JXLayer) parent; Insets insets = layer.getInsets(); diff --git a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/DefaultTransformModel.java b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/DefaultTransformModel.java index 54b2dae7..0524a1c0 100644 --- a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/DefaultTransformModel.java +++ b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/DefaultTransformModel.java @@ -28,9 +28,6 @@ package org.pbjar.jxlayer.plaf.ext.transform; */ import org.jdesktop.jxlayer.JXLayer; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -75,9 +72,9 @@ public class DefaultTransformModel implements TransformModel { listeners.put(listener, null); } - @NotNull + @Override - public AffineTransform getPreferredTransform(@Nullable final Dimension size, final JXLayer layer) { + public AffineTransform getPreferredTransform(final Dimension size, final JXLayer layer) { Point2D p = getRotationCenter(size); double centerX = p.getX(); double centerY = p.getY(); @@ -95,7 +92,7 @@ public class DefaultTransformModel implements TransformModel { * @param size the size. * @return center of rotation. */ - public Point2D getRotationCenter(@Nullable final Dimension size) { + public Point2D getRotationCenter(final Dimension size) { if (supplier != null) { return supplier.apply(size); } @@ -111,7 +108,7 @@ public class DefaultTransformModel implements TransformModel { * @param centerY a center Y * @return a new {@link AffineTransform} */ - @NotNull + protected AffineTransform transformNoScale(final double centerX, final double centerY) { AffineTransform at = new AffineTransform(); at.translate(centerX, centerY); @@ -132,9 +129,9 @@ public class DefaultTransformModel implements TransformModel { return (Double) getValue(Type.Rotation); } - @NotNull + @SuppressWarnings("unchecked") - protected T getValue(@NotNull final Type type) { + protected T getValue(final Type type) { return (T) values[type.ordinal()]; } @@ -180,15 +177,60 @@ public class DefaultTransformModel implements TransformModel { } /** - * Set a value and fire a PropertyChange. + * Return the currently active {@link AffineTransform}. Recalculate if needed. * - * @param type the value type - * @param newValue the new value + * @return the currently active {@link AffineTransform} */ - private void setValue(@NotNull final Type type, final Object newValue) { - Object oldValue = values[type.ordinal()]; - values[type.ordinal()] = newValue; - fireChangeEvent(oldValue, newValue); + + @Override + public AffineTransform getTransform(final JXLayer layer) { + JComponent view = layer == null ? null : layer.getView(); + /* + * Set the current actual program values in addition to the user options. + */ + setValue(Type.LayerWidth, layer == null ? 0 : layer.getWidth()); + setValue(Type.LayerHeight, layer == null ? 0 : layer.getHeight()); + setValue(Type.ViewWidth, view == null ? 0 : view.getWidth()); + setValue(Type.ViewHeight, view == null ? 0 : view.getHeight()); + /* + * If any change to previous values, recompute the transform. + */ + if (!Arrays.equals(prevValues, values) || !valid) { + System.arraycopy(values, 0, prevValues, 0, values.length); + transform.setToIdentity(); + if (view != null) { + Point2D p = getRotationCenter(layer == null ? null : layer.getSize()); + double centerX = p.getX(); + double centerY = p.getY(); + + AffineTransform nonScaledTransform = transformNoScale(centerX, centerY); + + double scaleX; + double scaleY; + if (getValue(Type.ScaleToPreferredSize)) { + scaleX = getValue(Type.PreferredScale); + scaleY = scaleX; + } else { + Area area = new Area(new Rectangle2D.Double(0, 0, view.getWidth(), view.getHeight())); + area.transform(nonScaledTransform); + Rectangle2D bounds = area.getBounds2D(); + scaleX = layer == null ? 0 : layer.getWidth() / bounds.getWidth(); + scaleY = layer == null ? 0 : layer.getHeight() / bounds.getHeight(); + + if (getValue(Type.PreserveAspectRatio)) { + scaleX = Math.min(scaleX, scaleY); + scaleY = scaleX; + } + } + + transform.translate(centerX, centerY); + transform.scale(getValue(Type.Mirror) ? -scaleX : scaleX, scaleY); + transform.translate(-centerX, -centerY); + transform.concatenate(nonScaledTransform); + } + } + valid = true; + return transform; } /** @@ -242,60 +284,15 @@ public class DefaultTransformModel implements TransformModel { } /** - * Return the currently active {@link AffineTransform}. Recalculate if needed. + * Set a value and fire a PropertyChange. * - * @return the currently active {@link AffineTransform} + * @param type the value type + * @param newValue the new value */ - @NotNull - @Override - public AffineTransform getTransform(@Nullable final JXLayer layer) { - JComponent view = layer == null ? null : layer.getView(); - /* - * Set the current actual program values in addition to the user options. - */ - setValue(Type.LayerWidth, layer == null ? 0 : layer.getWidth()); - setValue(Type.LayerHeight, layer == null ? 0 : layer.getHeight()); - setValue(Type.ViewWidth, view == null ? 0 : view.getWidth()); - setValue(Type.ViewHeight, view == null ? 0 : view.getHeight()); - /* - * If any change to previous values, recompute the transform. - */ - if (!Arrays.equals(prevValues, values) || !valid) { - System.arraycopy(values, 0, prevValues, 0, values.length); - transform.setToIdentity(); - if (view != null) { - Point2D p = getRotationCenter(layer == null ? null : layer.getSize()); - double centerX = p.getX(); - double centerY = p.getY(); - - AffineTransform nonScaledTransform = transformNoScale(centerX, centerY); - - double scaleX; - double scaleY; - if (getValue(Type.ScaleToPreferredSize)) { - scaleX = getValue(Type.PreferredScale); - scaleY = scaleX; - } else { - Area area = new Area(new Rectangle2D.Double(0, 0, view.getWidth(), view.getHeight())); - area.transform(nonScaledTransform); - Rectangle2D bounds = area.getBounds2D(); - scaleX = layer == null ? 0 : layer.getWidth() / bounds.getWidth(); - scaleY = layer == null ? 0 : layer.getHeight() / bounds.getHeight(); - - if (getValue(Type.PreserveAspectRatio)) { - scaleX = Math.min(scaleX, scaleY); - scaleY = scaleX; - } - } - - transform.translate(centerX, centerY); - transform.scale(getValue(Type.Mirror) ? -scaleX : scaleX, scaleY); - transform.translate(-centerX, -centerY); - transform.concatenate(nonScaledTransform); - } - } - valid = true; - return transform; + private void setValue(final Type type, final Object newValue) { + Object oldValue = values[type.ordinal()]; + values[type.ordinal()] = newValue; + fireChangeEvent(oldValue, newValue); } @Override @@ -319,7 +316,7 @@ public class DefaultTransformModel implements TransformModel { * @param oldValue an old value * @param newValue a new value */ - protected void fireChangeEvent(@NotNull final Object oldValue, final Object newValue) { + protected void fireChangeEvent(final Object oldValue, final Object newValue) { if (!oldValue.equals(newValue)) { ChangeEvent event = new ChangeEvent(this); for (ChangeListener listener : listeners.keySet()) { @@ -476,12 +473,12 @@ public class DefaultTransformModel implements TransformModel { private final Object defaultValue; - @Contract(pure = true) + Type(final Object defaultValue) { this.defaultValue = defaultValue; } - @NotNull + public static Object[] createArray() { Object[] array = new Object[values().length]; for (Type type : values()) { diff --git a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformLayout.java b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformLayout.java index f3ca20d0..763d2548 100644 --- a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformLayout.java +++ b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformLayout.java @@ -33,7 +33,6 @@ package org.pbjar.jxlayer.plaf.ext.transform; import org.jdesktop.jxlayer.JXLayer; import org.jdesktop.jxlayer.plaf.LayerUI; -import org.jetbrains.annotations.NotNull; import org.pbjar.jxlayer.plaf.ext.TransformUI; import javax.swing.*; @@ -74,7 +73,7 @@ public class TransformLayout extends DefaultLayerLayout { * Overridden to apply a preferred transform on the {@link Dimension} object returned from the super * implementation. */ - @NotNull + @Override public Dimension preferredLayoutSize(final Container parent) { return transform(parent, super.preferredLayoutSize(parent)); @@ -84,7 +83,7 @@ public class TransformLayout extends DefaultLayerLayout { * Overridden to apply a preferred transform on the {@link Dimension} object returned from the super * implementation. */ - @NotNull + @Override public Dimension minimumLayoutSize(final Container parent) { return transform(parent, super.minimumLayoutSize(parent)); @@ -120,9 +119,9 @@ public class TransformLayout extends DefaultLayerLayout { super.layoutContainer(parent); } - @NotNull + @SuppressWarnings("unchecked") - private Dimension transform(final Container parent, @NotNull final Dimension size) { + private Dimension transform(final Container parent, final Dimension size) { JXLayer layer = (JXLayer) parent; LayerUI ui = layer.getUI(); if (ui instanceof TransformUI) { diff --git a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformModel.java b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformModel.java index a67b419c..f5dc2cf1 100644 --- a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformModel.java +++ b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformModel.java @@ -32,7 +32,6 @@ package org.pbjar.jxlayer.plaf.ext.transform; import org.jdesktop.jxlayer.JXLayer; -import org.jetbrains.annotations.NotNull; import org.pbjar.jxlayer.plaf.ext.TransformUI; import javax.swing.*; @@ -67,7 +66,7 @@ public interface TransformModel { * @param layer the {@link JXLayer}. * @return a {@link AffineTransform} instance or {@code null} */ - @NotNull + AffineTransform getPreferredTransform(Dimension size, JXLayer layer); /** @@ -77,7 +76,7 @@ public interface TransformModel { * @param layer the {@link JXLayer} * @return a {@link AffineTransform} or {@code null} */ - @NotNull + AffineTransform getTransform(JXLayer layer); /** diff --git a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMFallBack.java b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMFallBack.java index 7b9a9983..c6f39873 100644 --- a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMFallBack.java +++ b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMFallBack.java @@ -32,7 +32,6 @@ package org.pbjar.jxlayer.plaf.ext.transform; import org.jdesktop.swingx.ForwardingRepaintManager; -import org.jetbrains.annotations.NotNull; import org.pbjar.jxlayer.repaint.RepaintManagerProvider; import org.pbjar.jxlayer.repaint.RepaintManagerUtils; import org.pbjar.jxlayer.repaint.WrappedRepaintManager; @@ -67,7 +66,7 @@ public class TransformRPMFallBack extends WrappedRepaintManager { * Delegates and then marks a JXLayer ancestor as dirty with the transformed rectangle. */ @Override - public void addDirtyRegion(@NotNull final JComponent c, final int x, final int y, final int w, final int h) { + public void addDirtyRegion(final JComponent c, final int x, final int y, final int w, final int h) { if (!TransformRPMImpl.addDirtyRegion(c, x, y, w, h, this)) { super.addDirtyRegion(c, x, y, w, h); } diff --git a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMImpl.java b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMImpl.java index 5166fa78..2ecad1ac 100644 --- a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMImpl.java +++ b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMImpl.java @@ -34,8 +34,6 @@ package org.pbjar.jxlayer.plaf.ext.transform; import com.github.weisj.darklaf.log.LogFormatter; import org.jdesktop.jxlayer.JXLayer; import org.jdesktop.jxlayer.plaf.LayerUI; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.pbjar.jxlayer.plaf.ext.TransformUI; import javax.swing.*; @@ -93,8 +91,8 @@ public final class TransformRPMImpl { * otherwise */ @SuppressWarnings("unchecked") - public static boolean addDirtyRegion(@NotNull final JComponent aComponent, final int x, final int y, - final int w, final int h, @NotNull final RepaintManager manager) { + public static boolean addDirtyRegion(final JComponent aComponent, final int x, final int y, + final int w, final int h, final RepaintManager manager) { if (aComponent.isShowing()) { JXLayer layer = findJXLayer(aComponent); if (layer != null) { @@ -178,7 +176,7 @@ public final class TransformRPMImpl { * @param aComponent some component * @return a {@link JXLayer} instance or {@code null} */ - @Nullable + private static JXLayer findJXLayer(final JComponent aComponent) { JXLayer layer = (JXLayer) SwingUtilities.getAncestorOfClass( diff --git a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMSwingX.java b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMSwingX.java index fff1b3e0..8bbb4865 100644 --- a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMSwingX.java +++ b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformRPMSwingX.java @@ -32,7 +32,6 @@ package org.pbjar.jxlayer.plaf.ext.transform; import org.jdesktop.swingx.ForwardingRepaintManager; -import org.jetbrains.annotations.NotNull; import org.pbjar.jxlayer.repaint.RepaintManagerProvider; import org.pbjar.jxlayer.repaint.RepaintManagerUtils; @@ -58,7 +57,7 @@ public class TransformRPMSwingX extends ForwardingRepaintManager { * * @param delegate the delegate {@link RepaintManager} */ - public TransformRPMSwingX(@NotNull final RepaintManager delegate) { + public TransformRPMSwingX(final RepaintManager delegate) { super(delegate); TransformRPMImpl.hackInitialization(delegate, this); } @@ -67,7 +66,7 @@ public class TransformRPMSwingX extends ForwardingRepaintManager { * Delegates and then marks a JXLayer ancestor as dirty with the transformed rectangle. */ @Override - public void addDirtyRegion(@NotNull final JComponent c, final int x, final int y, final int w, final int h) { + public void addDirtyRegion(final JComponent c, final int x, final int y, final int w, final int h) { if (!TransformRPMImpl.addDirtyRegion(c, x, y, w, h, this)) { super.addDirtyRegion(c, x, y, w, h); } diff --git a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformUtils.java b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformUtils.java index 9b6d227f..bff59ad3 100644 --- a/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformUtils.java +++ b/src/main/java/org/pbjar/jxlayer/plaf/ext/transform/TransformUtils.java @@ -32,8 +32,6 @@ package org.pbjar.jxlayer.plaf.ext.transform; import org.jdesktop.jxlayer.JXLayer; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import org.pbjar.jxlayer.plaf.ext.TransformUI; import javax.swing.*; @@ -47,7 +45,7 @@ import java.util.Map; */ public final class TransformUtils { - @Contract(pure = true) + private TransformUtils() { } @@ -57,7 +55,7 @@ public final class TransformUtils { * @param component the component. * @return the JXLayer. */ - @NotNull + public static JXLayer createTransformJXLayer(final JComponent component) { return createTransformJXLayer(component, 1.0, null); } @@ -70,7 +68,7 @@ public final class TransformUtils { * @param hints the rendering hints. * @return the JXLayer. */ - @NotNull + public static JXLayer createTransformJXLayer( final JComponent component, final double scale, final Map hints) { DefaultTransformModel model = new DefaultTransformModel(); @@ -86,8 +84,8 @@ public final class TransformUtils { * @param hints the rendering hints. * @return the JXLayer. */ - @Contract("_, _, _ -> new") - @NotNull + + public static JXLayer createTransformJXLayer( final JComponent component, final TransformModel model, final Map hints) { TransformUI ui = new TransformUI(model); @@ -102,7 +100,7 @@ public final class TransformUtils { * @param scale the scaling * @return the JXLayer. */ - @NotNull + public static JXLayer createTransformJXLayer(final JComponent component, final double scale) { return createTransformJXLayer(component, scale, null); } @@ -114,7 +112,7 @@ public final class TransformUtils { * @param model the transform model. * @return the JXLayer. */ - @NotNull + public static JXLayer createTransformJXLayer( final JComponent component, final TransformModel model) { return createTransformJXLayer(component, model, null); diff --git a/src/main/java/org/pbjar/jxlayer/repaint/RepaintManagerProvider.java b/src/main/java/org/pbjar/jxlayer/repaint/RepaintManagerProvider.java index 95194d71..bf44c99c 100644 --- a/src/main/java/org/pbjar/jxlayer/repaint/RepaintManagerProvider.java +++ b/src/main/java/org/pbjar/jxlayer/repaint/RepaintManagerProvider.java @@ -32,7 +32,6 @@ package org.pbjar.jxlayer.repaint; import org.jdesktop.swingx.ForwardingRepaintManager; -import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -51,7 +50,7 @@ public interface RepaintManagerProvider { * * @return a class object */ - @NotNull + Class getForwardingRepaintManagerClass(); /** @@ -62,7 +61,7 @@ public interface RepaintManagerProvider { * * @return a class object */ - @NotNull + Class getWrappedRepaintManagerClass(); /** diff --git a/src/main/java/org/pbjar/jxlayer/repaint/RepaintManagerUtils.java b/src/main/java/org/pbjar/jxlayer/repaint/RepaintManagerUtils.java index cfcdff4b..6449ff89 100644 --- a/src/main/java/org/pbjar/jxlayer/repaint/RepaintManagerUtils.java +++ b/src/main/java/org/pbjar/jxlayer/repaint/RepaintManagerUtils.java @@ -33,9 +33,6 @@ package org.pbjar.jxlayer.repaint; import com.github.weisj.darklaf.log.LogFormatter; import org.jdesktop.swingx.ForwardingRepaintManager; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -65,7 +62,7 @@ public final class RepaintManagerUtils { LOGGER.addHandler(handler); } - @Contract(pure = true) + private RepaintManagerUtils() { } @@ -75,8 +72,8 @@ public final class RepaintManagerUtils { * * @return an {@link Action} object */ - @Contract(" -> new") - @NotNull + + public static Action createRPDisplayAction() { return new DisplayAction(); } @@ -89,7 +86,7 @@ public final class RepaintManagerUtils { * @param provider the provider */ public static void ensureRepaintManagerSet( - final Component c, @NotNull final RepaintManagerProvider provider) { + final Component c, final RepaintManagerProvider provider) { ensureImpl(RepaintManager.currentManager(c), provider); } @@ -100,7 +97,7 @@ public final class RepaintManagerUtils { * @param provider the provider that provides for the type and implementation of a delegated RepaintManager */ private static void ensureImpl( - @NotNull final RepaintManager delegate, @NotNull final RepaintManagerProvider provider) { + final RepaintManager delegate, final RepaintManagerProvider provider) { /* * Setup a traversal variable. */ @@ -127,9 +124,9 @@ public final class RepaintManagerUtils { } } - @NotNull + private static RepaintManager createManager( - @NotNull final Class clazz, final RepaintManager delegate) { + final Class clazz, final RepaintManager delegate) { try { RepaintManager newManager = clazz.getConstructor(RepaintManager.class).newInstance(delegate); return newManager; @@ -146,7 +143,7 @@ public final class RepaintManagerUtils { * @param provider the provider */ public static void ensureRepaintManagerSet( - final JComponent c, @NotNull final RepaintManagerProvider provider) { + final JComponent c, final RepaintManagerProvider provider) { ensureImpl(RepaintManager.currentManager(c), provider); } @@ -175,7 +172,7 @@ public final class RepaintManagerUtils { } @Override - public void actionPerformed(@NotNull final ActionEvent e) { + public void actionPerformed(final ActionEvent e) { JComponent c = (JComponent) e.getSource(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); @@ -194,7 +191,7 @@ public final class RepaintManagerUtils { c, message, "The RepaintManager tree", JOptionPane.INFORMATION_MESSAGE); } - private void appendClass(@NotNull final PrintWriter writer, @NotNull final Object obj) { + private void appendClass(final PrintWriter writer, final Object obj) { Class clazz = obj.getClass(); String prefix = "Class: "; while (clazz != null) { @@ -204,9 +201,9 @@ public final class RepaintManagerUtils { } } - private void appendDelegates(@NotNull final PrintWriter writer, @NotNull final Object rp) { + private void appendDelegates(final PrintWriter writer, final Object rp) { appendClass(writer, rp); - @Nullable RepaintManager delegate; + RepaintManager delegate; if (rp instanceof WrappedRepaintManager) { delegate = ((WrappedRepaintManager) rp).getDelegateManager(); } else if (swingX) { diff --git a/src/main/java/org/pbjar/jxlayer/repaint/WrappedRepaintManager.java b/src/main/java/org/pbjar/jxlayer/repaint/WrappedRepaintManager.java index d1cd28ab..2a9cac86 100644 --- a/src/main/java/org/pbjar/jxlayer/repaint/WrappedRepaintManager.java +++ b/src/main/java/org/pbjar/jxlayer/repaint/WrappedRepaintManager.java @@ -32,9 +32,6 @@ package org.pbjar.jxlayer.repaint; import org.jdesktop.swingx.ForwardingRepaintManager; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.applet.Applet; @@ -59,7 +56,7 @@ public class WrappedRepaintManager extends RepaintManager { /** * The wrapped manager. */ - @NotNull + private final RepaintManager delegate; /** @@ -67,8 +64,8 @@ public class WrappedRepaintManager extends RepaintManager { * * @param delegate an existing RepaintManager */ - @Contract("null -> fail") - public WrappedRepaintManager(@Nullable final RepaintManager delegate) { + + public WrappedRepaintManager(final RepaintManager delegate) { if (delegate == null) { throw new NullPointerException(); } @@ -162,7 +159,7 @@ public class WrappedRepaintManager extends RepaintManager { * * @return the delegate */ - @Nullable + public RepaintManager getDelegateManager() { return delegate; } diff --git a/src/test/java/defaults/ChangeLookAndFeelAction.java b/src/test/java/defaults/ChangeLookAndFeelAction.java index 87718df2..3990f56a 100644 --- a/src/test/java/defaults/ChangeLookAndFeelAction.java +++ b/src/test/java/defaults/ChangeLookAndFeelAction.java @@ -1,7 +1,5 @@ package defaults; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.event.ActionEvent; @@ -20,7 +18,7 @@ final class ChangeLookAndFeelAction extends AbstractAction { putValue(Action.SHORT_DESCRIPTION, getValue(Action.NAME)); } - public void actionPerformed(@NotNull final ActionEvent e) { + public void actionPerformed(final ActionEvent e) { try { UIManager.setLookAndFeel(laf); defaults.resetComponents(); @@ -38,7 +36,7 @@ final class ChangeLookAndFeelAction extends AbstractAction { frame.setUndecorated(false); } frame.setVisible(true); - } catch (@NotNull final Exception ex) { + } catch (final Exception ex) { ex.printStackTrace(); } } diff --git a/src/test/java/defaults/SafeIcon.java b/src/test/java/defaults/SafeIcon.java index 4e81cc0c..bfe7b3c8 100644 --- a/src/test/java/defaults/SafeIcon.java +++ b/src/test/java/defaults/SafeIcon.java @@ -1,8 +1,5 @@ package defaults; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; @@ -27,13 +24,13 @@ final class SafeIcon implements Icon { private final Icon wrappee; private Icon standIn; - @Contract(pure = true) + SafeIcon(final Icon wrappee) { this.wrappee = wrappee; } @Override - public void paintIcon(final Component c, @NotNull final Graphics g, final int x, final int y) { + public void paintIcon(final Component c, final Graphics g, final int x, final int y) { if (standIn == this) { paintFallback(c, g, x, y); } else if (standIn != null) { @@ -41,7 +38,7 @@ final class SafeIcon implements Icon { } else { try { wrappee.paintIcon(c, g, x, y); - } catch (@NotNull final ClassCastException e) { + } catch (final ClassCastException e) { createStandIn(e); standIn.paintIcon(c, g, x, y); } @@ -59,34 +56,34 @@ final class SafeIcon implements Icon { } private void paintFallback( - final Component c, @NotNull final Graphics g, final int x, final int y) { + final Component c, final Graphics g, final int x, final int y) { g.drawRect(x, y, getIconWidth(), getIconHeight()); g.drawLine(x, y, x + getIconWidth(), y + getIconHeight()); g.drawLine(x + getIconWidth(), y, x, y + getIconHeight()); } - private void createStandIn(@NotNull final ClassCastException e) { + private void createStandIn(final ClassCastException e) { try { final Class clazz = getClass(e); final JComponent standInComponent = getSubstitute(clazz); standIn = createImageIcon(standInComponent); - } catch (@NotNull final Exception e1) { + } catch (final Exception e1) { // something went wrong - fallback to this painting standIn = this; } } - private Class getClass(@NotNull final ClassCastException e) throws ClassNotFoundException { + private Class getClass(final ClassCastException e) throws ClassNotFoundException { String className = e.getMessage(); className = className.substring(className.lastIndexOf(" ") + 1); return Class.forName(className); } - private JComponent getSubstitute(@NotNull final Class clazz) throws IllegalAccessException { + private JComponent getSubstitute(final Class clazz) throws IllegalAccessException { JComponent standInComponent = null; try { standInComponent = (JComponent) clazz.getDeclaredConstructor().newInstance(); - } catch (@NotNull final InstantiationException e) { + } catch (final InstantiationException e) { standInComponent = new AbstractButton() { }; ((AbstractButton) standInComponent).setModel(new DefaultButtonModel()); @@ -96,8 +93,7 @@ final class SafeIcon implements Icon { return standInComponent; } - @Contract("_ -> new") - @NotNull + private Icon createImageIcon(final JComponent standInComponent) { final BufferedImage image = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB); diff --git a/src/test/java/defaults/SampleRenderer.java b/src/test/java/defaults/SampleRenderer.java index b1541c86..481fc0e8 100644 --- a/src/test/java/defaults/SampleRenderer.java +++ b/src/test/java/defaults/SampleRenderer.java @@ -1,8 +1,6 @@ package defaults; import com.github.weisj.darklaf.ui.cell.DarkCellRendererToggleButton; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; @@ -23,8 +21,7 @@ final class SampleRenderer extends JLabel implements TableCellRenderer { setOpaque(true); } - @Contract("_, _, _, _, _, _ -> this") - @NotNull + public Component getTableCellRendererComponent( final JTable table, final Object sample, @@ -60,7 +57,7 @@ final class SampleRenderer extends JLabel implements TableCellRenderer { public void paint(final Graphics g) { try { super.paint(g); - } catch (@NotNull final Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } diff --git a/src/test/java/defaults/UIManagerDefaults.java b/src/test/java/defaults/UIManagerDefaults.java index 0777f14e..82c814e0 100644 --- a/src/test/java/defaults/UIManagerDefaults.java +++ b/src/test/java/defaults/UIManagerDefaults.java @@ -3,15 +3,13 @@ package defaults; * This programs uses the information found in the UIManager * to create a table of key/value pairs for each Swing component. */ + import com.github.weisj.darklaf.DarkLafInfo; import com.github.weisj.darklaf.LafManager; import com.github.weisj.darklaf.components.OverlayScrollPane; import com.github.weisj.darklaf.ui.table.DarkColorTableCellRendererEditor; import org.jdesktop.swingx.JXTaskPane; import org.jdesktop.swingx.JXTaskPaneContainer; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.Border; @@ -90,7 +88,7 @@ public class UIManagerDefaults implements ItemListener { /* * The content pane should be added to a high level container */ - @NotNull + public JComponent getContentPane() { return contentPane; } @@ -98,7 +96,7 @@ public class UIManagerDefaults implements ItemListener { /** * Create menu bar */ - @NotNull + private JMenuBar createMenuBar() { final JMenuBar menuBar = new JMenuBar(); menuBar.add(createFileMenu()); @@ -109,7 +107,7 @@ public class UIManagerDefaults implements ItemListener { /** * Create menu items for the Application menu */ - @NotNull + private JMenu createFileMenu() { final JMenu menu = new JMenu("Application"); menu.setMnemonic('A'); @@ -121,7 +119,7 @@ public class UIManagerDefaults implements ItemListener { /** * Create menu items for the Look & Feel menu */ - @NotNull + private JMenu createLAFMenu() { final ButtonGroup bg = new ButtonGroup(); final JMenu menu = new JMenu("Look & Feel"); @@ -146,7 +144,7 @@ public class UIManagerDefaults implements ItemListener { /* * This panel is added to the North of the content pane */ - @NotNull + private JComponent buildNorthComponent() { comboBox = new JComboBox() { @Override @@ -192,8 +190,8 @@ public class UIManagerDefaults implements ItemListener { /* * This panel is added to the Center of the content pane */ - @Contract(" -> new") - @NotNull + + private JComponent buildCenterComponent() { final DefaultTableModel model = new DefaultTableModel(COLUMN_NAMES, 0); table = new JTable(model); @@ -264,8 +262,8 @@ public class UIManagerDefaults implements ItemListener { /* * Parse the key to determine the item name to use */ - @Nullable - private String getItemName(@NotNull final String key, final Object value) { + + private String getItemName(final String key, final Object value) { // Seems like this is an old check required for JDK1.4.2 if (key.startsWith("class") || key.startsWith("javax")) { return null; @@ -277,7 +275,7 @@ public class UIManagerDefaults implements ItemListener { } } - private String getComponentName(@NotNull final String key, final Object value) { + private String getComponentName(final String key, final Object value) { // The key is of the form: // "componentName.componentProperty", or // "componentNameUI", or @@ -300,28 +298,7 @@ public class UIManagerDefaults implements ItemListener { return componentName; } - private int componentNameEndOffset(@NotNull final String key) { - // Handle Nimbus properties first - // "ComboBox.scrollPane", "Table.editor" and "Tree.cellEditor" - // have different format even within the Nimbus properties. - // (the component name is specified in quotes) - if (key.startsWith("\"")) { - return key.indexOf("\"", 1) + 1; - } - int pos = key.indexOf(":"); - if (pos != -1) { - return pos; - } - pos = key.indexOf("["); - if (pos != -1) { - return pos; - } - // Handle normal properties - return key.indexOf("."); - } - - @NotNull - private String getValueName(@NotNull final String key, final Object value) { + private String getValueName(final String key, final Object value) { if (value instanceof Icon) { return "Icon"; } else if (value instanceof Font) { @@ -353,10 +330,30 @@ public class UIManagerDefaults implements ItemListener { } } + private int componentNameEndOffset(final String key) { + // Handle Nimbus properties first + // "ComboBox.scrollPane", "Table.editor" and "Tree.cellEditor" + // have different format even within the Nimbus properties. + // (the component name is specified in quotes) + if (key.startsWith("\"")) { + return key.indexOf("\"", 1) + 1; + } + int pos = key.indexOf(":"); + if (pos != -1) { + return pos; + } + pos = key.indexOf("["); + if (pos != -1) { + return pos; + } + // Handle normal properties + return key.indexOf("."); + } + /* * Implement the ItemListener interface */ - public void itemStateChanged(@NotNull final ItemEvent e) { + public void itemStateChanged(final ItemEvent e) { final String itemName = (String) e.getItem(); changeTableModel(itemName); updateRowHeights(); @@ -414,7 +411,7 @@ public class UIManagerDefaults implements ItemListener { } table.setRowHeight(row, rowHeight); } - } catch (@NotNull final ClassCastException ignored) { + } catch (final ClassCastException ignored) { } } diff --git a/src/test/java/icon/AllIcons.java b/src/test/java/icon/AllIcons.java index 630ea1b1..53807731 100644 --- a/src/test/java/icon/AllIcons.java +++ b/src/test/java/icon/AllIcons.java @@ -30,7 +30,6 @@ import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.icons.ThemedSVGIcon; import com.github.weisj.darklaf.util.Pair; import com.kitfox.svg.app.beans.SVGIcon; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.ListDataListener; @@ -86,7 +85,7 @@ public class AllIcons { }); } - @NotNull + private static List> loadIcons() throws URISyntaxException { List> list = new ArrayList<>(); for (String folder : FOLDERS) { @@ -108,7 +107,7 @@ public class AllIcons { } private static File[] getResourceFolderFiles(final String folder, - @NotNull final Class clazz) throws URISyntaxException { + final Class clazz) throws URISyntaxException { URL url = clazz.getResource(folder); return new File(url.toURI()).listFiles(); } diff --git a/src/test/java/theme/MyCustomTheme.java b/src/test/java/theme/MyCustomTheme.java index a443ff03..b56c6885 100644 --- a/src/test/java/theme/MyCustomTheme.java +++ b/src/test/java/theme/MyCustomTheme.java @@ -25,7 +25,6 @@ package theme; import com.github.weisj.darklaf.theme.Theme; import com.github.weisj.darklaf.util.SystemInfo; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.util.Properties; @@ -33,7 +32,7 @@ import java.util.Properties; public class MyCustomTheme extends Theme { @Override - public void loadGlobals(@NotNull final Properties properties, final UIDefaults currentDefaults) { + public void loadGlobals(final Properties properties, final UIDefaults currentDefaults) { super.loadGlobals(properties, currentDefaults); /* * Properties in the globals file should have a 'globals.' to be applied globally. diff --git a/src/test/java/ui/SolidColorIcon.java b/src/test/java/ui/SolidColorIcon.java index 0cc417d3..ddb6fcce 100644 --- a/src/test/java/ui/SolidColorIcon.java +++ b/src/test/java/ui/SolidColorIcon.java @@ -23,8 +23,6 @@ */ package ui; -import org.jetbrains.annotations.NotNull; - import javax.swing.*; import java.awt.*; @@ -44,7 +42,7 @@ final class SolidColorIcon implements Icon { } @Override - public void paintIcon(final Component c, @NotNull final Graphics g, final int x, final int y) { + public void paintIcon(final Component c, final Graphics g, final int x, final int y) { g.setColor(color); g.fillRect(x, y, getIconWidth(), getIconHeight()); } diff --git a/src/test/java/ui/internalFrame/InternalFrameDemo.java b/src/test/java/ui/internalFrame/InternalFrameDemo.java index eb58d9df..e599817a 100644 --- a/src/test/java/ui/internalFrame/InternalFrameDemo.java +++ b/src/test/java/ui/internalFrame/InternalFrameDemo.java @@ -24,8 +24,6 @@ package ui.internalFrame; import com.github.weisj.darklaf.LafManager; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -64,7 +62,7 @@ public class InternalFrameDemo extends JFrame implements ActionListener { SwingUtilities.invokeLater(InternalFrameDemo::createAndShowGUI); } - @NotNull + private JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); @@ -118,7 +116,7 @@ public class InternalFrameDemo extends JFrame implements ActionListener { } //React to menu selections. - public void actionPerformed(@NotNull final ActionEvent e) { + public void actionPerformed(final ActionEvent e) { if ("new".equals(e.getActionCommand())) { createFrame(); } else { @@ -127,7 +125,7 @@ public class InternalFrameDemo extends JFrame implements ActionListener { } //Quit the application. - @Contract(" -> fail") + private void quit() { System.exit(0); } diff --git a/src/test/java/ui/tabFrame/TabFrameDemo.java b/src/test/java/ui/tabFrame/TabFrameDemo.java index 3cd338c5..e89b3821 100644 --- a/src/test/java/ui/tabFrame/TabFrameDemo.java +++ b/src/test/java/ui/tabFrame/TabFrameDemo.java @@ -31,7 +31,6 @@ import com.github.weisj.darklaf.components.text.NumberedTextComponent; import com.github.weisj.darklaf.components.text.NumberingPane; import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.util.StringUtil; -import org.jetbrains.annotations.NotNull; import ui.ComponentDemo; import ui.DemoResources; @@ -45,7 +44,7 @@ public class TabFrameDemo implements ComponentDemo { ComponentDemo.showDemo(new TabFrameDemo(), new Dimension(1000, 500)); } - @NotNull + private static Component createTextArea() { NumberedTextComponent numberPane = new NumberedTextComponent(new NonWrappingTextPane() {{ setText(StringUtil.repeat(DemoResources.LOREM_IPSUM, 10)); diff --git a/src/test/java/ui/toolBar/ToolBarDemo.java b/src/test/java/ui/toolBar/ToolBarDemo.java index 45e3a8c2..063be2f1 100644 --- a/src/test/java/ui/toolBar/ToolBarDemo.java +++ b/src/test/java/ui/toolBar/ToolBarDemo.java @@ -53,14 +53,13 @@ package ui.toolBar;/* */ /* - * toolBar.ToolBarDemo.java requires the following addditional files: + * toolBar.ToolBarDemo.java requires the following additional files: * images/Back24.gif * images/Forward24.gif * images/Up24.gif */ import com.github.weisj.darklaf.LafManager; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -93,7 +92,7 @@ public class ToolBarDemo extends JPanel implements ActionListener { add(scrollPane, BorderLayout.CENTER); } - private void addButtons(@NotNull final JToolBar toolBar) { + private void addButtons(final JToolBar toolBar) { JButton button; //first button @@ -112,7 +111,7 @@ public class ToolBarDemo extends JPanel implements ActionListener { toolBar.add(button); } - @NotNull + private JButton makeNavigationButton(final String imageName, final String actionCommand, final String toolTipText, @@ -163,7 +162,7 @@ public class ToolBarDemo extends JPanel implements ActionListener { frame.setVisible(true); } - public void actionPerformed(@NotNull final ActionEvent e) { + public void actionPerformed(final ActionEvent e) { String cmd = e.getActionCommand(); String description = null;