Browse Source

Removed further dependency on DarculaLaf.

Fixed several code style issues.
pull/1/head
weisj 5 years ago
parent
commit
5e626206ea
  1. 5
      src/main/java/com/weis/darklaf/DarkLaf.java
  2. 75
      src/main/java/com/weis/darklaf/DarkMetalTheme.java
  3. 4
      src/main/java/com/weis/darklaf/LightLaf.java
  4. 8
      src/main/java/com/weis/darklaf/components/ColorPipetteBase.java
  5. 46
      src/main/java/com/weis/darklaf/components/ScrollPopupMenu.java
  6. 23
      src/main/java/com/weis/darklaf/components/border/DropShadowBorder.java
  7. 2
      src/main/java/com/weis/darklaf/icons/IconLoader.java
  8. 13
      src/main/java/com/weis/darklaf/platform/windows/JNIDecorations.java
  9. 3
      src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java
  10. 5
      src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java
  11. 3
      src/main/java/com/weis/darklaf/ui/checkbox/DarkCheckBoxBorder.java
  12. 2
      src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelImageProducer.java
  13. 2
      src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelPanel.java
  14. 2
      src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java
  15. 3
      src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java
  16. 2
      src/main/java/com/weis/darklaf/ui/menu/DarkPopupMenuUI.java
  17. 3
      src/main/java/com/weis/darklaf/ui/radiobutton/DarkRadioButtonBorder.java
  18. 4
      src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerBorder.java
  19. 3
      src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java
  20. 1
      src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java
  21. 100
      src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java
  22. 2
      src/main/java/com/weis/darklaf/ui/tabbedpane/TabbedPaneTransferHandler.java
  23. 3
      src/main/java/com/weis/darklaf/ui/table/DarkTableBorder.java
  24. 4
      src/main/java/com/weis/darklaf/ui/table/DarkTableCellRenderer.java
  25. 3
      src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderBorder.java
  26. 4
      src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUI.java
  27. 32
      src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUIBridge.java
  28. 6
      src/main/java/com/weis/darklaf/ui/table/DarkTableUIBridge.java
  29. 6
      src/main/java/com/weis/darklaf/ui/text/DarkEditorPaneUI.java
  30. 5
      src/main/java/com/weis/darklaf/ui/text/DarkTextAreaUI.java
  31. 10
      src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java
  32. 3
      src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java
  33. 2
      src/main/java/com/weis/darklaf/ui/text/SelectLineAction.java
  34. 4
      src/main/java/com/weis/darklaf/ui/text/SelectWordAction.java
  35. 7
      src/main/java/com/weis/darklaf/util/DarkUIUtil.java
  36. 6
      src/main/java/com/weis/darklaf/util/LafUtil.java
  37. 41
      src/main/java/com/weis/darklaf/util/StringUtil.java
  38. 137
      src/main/java/com/weis/darklaf/util/SystemInfo.java

5
src/main/java/com/weis/darklaf/DarkLaf.java

@ -1,10 +1,9 @@
package com.weis.darklaf;
import com.bulenkov.darcula.DarculaMetalTheme;
import com.bulenkov.iconloader.util.SystemInfo;
import com.weis.darklaf.platform.windows.JNIDecorations;
import com.weis.darklaf.ui.menu.DarkPopupMenuUI;
import com.weis.darklaf.util.LafUtil;
import com.weis.darklaf.util.SystemInfo;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import sun.awt.AppContext;
@ -45,7 +44,7 @@ public class DarkLaf extends BasicLookAndFeel {
try {
if (SystemInfo.isWindows || SystemInfo.isLinux) {
base = new MetalLookAndFeel();
MetalLookAndFeel.setCurrentTheme(new DarculaMetalTheme());
MetalLookAndFeel.setCurrentTheme(new DarkMetalTheme());
} else {
final String name = UIManager.getSystemLookAndFeelClassName();
base = (BasicLookAndFeel) Class.forName(name).getDeclaredConstructor().newInstance();

75
src/main/java/com/weis/darklaf/DarkMetalTheme.java

@ -0,0 +1,75 @@
package com.weis.darklaf;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.DefaultMetalTheme;
import java.awt.*;
public class DarkMetalTheme extends DefaultMetalTheme {
private final ColorUIResource myControlHighlightColor = new ColorUIResource(108, 111, 113);
private final ColorUIResource myControlDarkShadowColor = new ColorUIResource(39, 42, 44);
private final ColorUIResource myControlColor = new ColorUIResource(3948353);
private static final ColorUIResource white = new ColorUIResource(128, 128, 128);
private static final ColorUIResource darkBlue = new ColorUIResource(0, 44, 63);
private static final ColorUIResource lightGray = new ColorUIResource(109, 109, 109);
private final ColorUIResource mySeparatorForeground = new ColorUIResource(53, 56, 58);
public static final ColorUIResource primary1 = new ColorUIResource(53, 56, 58);
private static final ColorUIResource primary2 = new ColorUIResource(50, 66, 114);
private static final ColorUIResource primary3 = new ColorUIResource(53, 69, 91);
public String getName() {
return "Darcula theme";
}
public ColorUIResource getControl() {
return this.myControlColor;
}
public ColorUIResource getControlHighlight() {
return this.myControlHighlightColor;
}
public ColorUIResource getControlDarkShadow() {
return this.myControlDarkShadowColor;
}
public ColorUIResource getSeparatorBackground() {
return this.getControl();
}
public ColorUIResource getSeparatorForeground() {
return this.mySeparatorForeground;
}
public ColorUIResource getMenuBackground() {
return lightGray;
}
public ColorUIResource getMenuSelectedBackground() {
return darkBlue;
}
public ColorUIResource getMenuSelectedForeground() {
return white;
}
public ColorUIResource getAcceleratorSelectedForeground() {
return white;
}
public ColorUIResource getFocusColor() {
return new ColorUIResource(Color.black);
}
protected ColorUIResource getPrimary1() {
return primary1;
}
protected ColorUIResource getPrimary2() {
return primary2;
}
protected ColorUIResource getPrimary3() {
return primary3;
}
}

4
src/main/java/com/weis/darklaf/LightLaf.java

@ -1,6 +1,7 @@
package com.weis.darklaf;
import com.bulenkov.iconloader.util.SystemInfo;
import com.weis.darklaf.util.SystemInfo;
import org.jetbrains.annotations.NotNull;
import javax.swing.plaf.metal.MetalLookAndFeel;
@ -19,7 +20,6 @@ public class LightLaf extends DarkLaf {
* Create new light Darcula LaF.
*/
public LightLaf() {
super();
if (SystemInfo.isWindows || SystemInfo.isLinux) {
MetalLookAndFeel.setCurrentTheme(new LightMetalTheme());
}

8
src/main/java/com/weis/darklaf/components/ColorPipetteBase.java

@ -1,6 +1,6 @@
package com.weis.darklaf.components;
import com.bulenkov.iconloader.util.SystemInfo;
import com.weis.darklaf.ui.colorchooser.ColorListener;
import com.weis.darklaf.ui.colorchooser.ColorPipette;
import com.weis.darklaf.util.DarkUIUtil;
@ -226,12 +226,6 @@ public abstract class ColorPipetteBase implements ColorPipette, AWTEventListener
setCursor(blankCursor);
}
@NotNull
@Override
public Cursor getCursor() {
return super.getCursor();
}
@Override
protected JRootPane createRootPane() {
return new JRootPane() {

46
src/main/java/com/weis/darklaf/components/ScrollPopupMenu.java

@ -11,29 +11,6 @@ import java.awt.*;
public class ScrollPopupMenu extends JPopupMenu {
private final MenuKeyListener menuKeyListener = new MenuKeyListener() {
@Override
public void menuKeyTyped(final MenuKeyEvent e) {
}
@Override
public void menuKeyPressed(final MenuKeyEvent e) {
SwingUtilities.invokeLater(() -> {
var path = e.getMenuSelectionManager().getSelectedPath();
if (path.length == 0) {
return;
}
var bounds = path[path.length - 1].getComponent().getBounds();
var r = SwingUtilities.convertRectangle(ScrollPopupMenu.this, bounds, scrollPane);
scrollPane.getViewport().scrollRectToVisible(r);
});
}
@Override
public void menuKeyReleased(final MenuKeyEvent e) {
}
};
private int maxHeight;
private final JPanel contentPane;
private final JScrollPane scrollPane;
@ -49,6 +26,29 @@ public class ScrollPopupMenu extends JPopupMenu {
contentPane.add(overlayScrollPane, BorderLayout.CENTER);
contentPane.setBorder(getBorder());
setDoubleBuffered(true);
MenuKeyListener menuKeyListener = new MenuKeyListener() {
@Override
public void menuKeyTyped(final MenuKeyEvent e) {
}
@Override
public void menuKeyPressed(final MenuKeyEvent e) {
SwingUtilities.invokeLater(() -> {
var path = e.getMenuSelectionManager().getSelectedPath();
if (path.length == 0) {
return;
}
var bounds = path[path.length - 1].getComponent().getBounds();
var r = SwingUtilities.convertRectangle(ScrollPopupMenu.this, bounds, scrollPane);
scrollPane.getViewport().scrollRectToVisible(r);
});
}
@Override
public void menuKeyReleased(final MenuKeyEvent e) {
}
};
addMenuKeyListener(menuKeyListener);
}

23
src/main/java/com/weis/darklaf/components/border/DropShadowBorder.java

@ -46,7 +46,7 @@ public class DropShadowBorder implements Border, Serializable {
}
private static final Map<Double, Map<Position, BufferedImage>> CACHE
= new HashMap<Double, Map<Position, BufferedImage>>();
= new HashMap<>();
private Color shadowColor;
@ -146,9 +146,9 @@ public class DropShadowBorder implements Border, Serializable {
topLeftShadowPoint = new Point();
if (showLeftShadow && !showTopShadow) {
topLeftShadowPoint.setLocation(x, y + shadowOffset);
} else if (showLeftShadow && showTopShadow) {
} else if (showLeftShadow) {
topLeftShadowPoint.setLocation(x, y);
} else if (!showLeftShadow && showTopShadow) {
} else {
topLeftShadowPoint.setLocation(x + shadowSize, y);
}
}
@ -158,9 +158,9 @@ public class DropShadowBorder implements Border, Serializable {
bottomLeftShadowPoint = new Point();
if (showLeftShadow && !showBottomShadow) {
bottomLeftShadowPoint.setLocation(x, y + height - shadowSize - shadowSize);
} else if (showLeftShadow && showBottomShadow) {
} else if (showLeftShadow) {
bottomLeftShadowPoint.setLocation(x, y + height - shadowSize);
} else if (!showLeftShadow && showBottomShadow) {
} else {
bottomLeftShadowPoint.setLocation(x + shadowSize, y + height - shadowSize);
}
}
@ -170,9 +170,9 @@ public class DropShadowBorder implements Border, Serializable {
bottomRightShadowPoint = new Point();
if (showRightShadow && !showBottomShadow) {
bottomRightShadowPoint.setLocation(x + width - shadowSize, y + height - shadowSize - shadowSize);
} else if (showRightShadow && showBottomShadow) {
} else if (showRightShadow) {
bottomRightShadowPoint.setLocation(x + width - shadowSize, y + height - shadowSize);
} else if (!showRightShadow && showBottomShadow) {
} else {
bottomRightShadowPoint.setLocation(x + width - shadowSize - shadowSize, y + height - shadowSize);
}
}
@ -182,9 +182,9 @@ public class DropShadowBorder implements Border, Serializable {
topRightShadowPoint = new Point();
if (showRightShadow && !showTopShadow) {
topRightShadowPoint.setLocation(x + width - shadowSize, y + shadowOffset);
} else if (showRightShadow && showTopShadow) {
} else if (showRightShadow) {
topRightShadowPoint.setLocation(x + width - shadowSize, y);
} else if (!showRightShadow && showTopShadow) {
} else {
topRightShadowPoint.setLocation(x + width - shadowSize - shadowSize, y);
}
}
@ -256,11 +256,12 @@ public class DropShadowBorder implements Border, Serializable {
}
}
@SuppressWarnings("SuspiciousNameCombination")
@NotNull
private Map<Position, BufferedImage> getImages(Graphics2D g2) {
//first, check to see if an image for this size has already been rendered
//if so, use the cache. Else, draw and save
Map<Position, BufferedImage> images = CACHE.get(shadowSize + (shadowColor.hashCode() * .3) + (shadowOpacity * .12));//TODO do a real hash
Map<Position, BufferedImage> images = CACHE.get(shadowSize + (shadowColor.hashCode() * .3) + (shadowOpacity * .12));//(TUDU) do a real hash
if (images == null) {
images = new HashMap<>();
@ -344,7 +345,7 @@ public class DropShadowBorder implements Border, Serializable {
image.flush();
CACHE.put(shadowSize + (shadowColor.hashCode() * .3) + (shadowOpacity * .12),
images); //TODO do a real hash
images); //TUDU do a real hash
}
return images;
}

2
src/main/java/com/weis/darklaf/icons/IconLoader.java

@ -93,7 +93,7 @@ public final class IconLoader {
}
public static final class IconKey {
String path;
final String path;
int w;
int h;

13
src/main/java/com/weis/darklaf/platform/windows/JNIDecorations.java

@ -1,10 +1,10 @@
package com.weis.darklaf.platform.windows;
import com.bulenkov.iconloader.util.SystemInfo;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.weis.darklaf.DarkLaf;
import com.weis.darklaf.platform.NativeUtil;
import com.weis.darklaf.util.SystemInfo;
import org.jetbrains.annotations.Contract;
import java.awt.*;
@ -35,8 +35,6 @@ public class JNIDecorations {
}
private static final Logger LOGGER = Logger.getLogger(JNIDecorations.class.getName());
private static final String X86 = "32";
private static final String X64 = "64";
private static boolean supported;
private static boolean loaded;
@ -63,13 +61,14 @@ public class JNIDecorations {
}
if (loaded) return true;
try {
String model = System.getProperty("sun.arch.data.model");
if (X86.equals(model)) {
if (SystemInfo.isX86) {
NativeUtil.loadLibraryFromJar("/library/x86/jniplatform.dll");
} else if (X64.equals(model)) {
} else if (SystemInfo.isX64) {
NativeUtil.loadLibraryFromJar("/library/x64/jniplatform.dll");
} else {
LOGGER.warning("Could not determine jre model '" + model + "'. Decorations will be disabled");
LOGGER.warning("Could not determine jre model '"
+ SystemInfo.jreArchitecture
+ "'. Decorations will be disabled");
return false;
}
loaded = true;

3
src/main/java/com/weis/darklaf/ui/button/DarkButtonBorder.java

@ -1,6 +1,5 @@
package com.weis.darklaf.ui.button;
import com.bulenkov.darcula.ui.DarculaButtonPainter;
import com.weis.darklaf.util.DarkUIUtil;
import com.weis.darklaf.util.GraphicsContext;
import org.jetbrains.annotations.Contract;
@ -15,8 +14,6 @@ import java.awt.geom.Area;
import java.awt.geom.RoundRectangle2D;
/**
* Custom adaption of {@link DarculaButtonPainter}.
*
* @author Jannis Weis
* @since 2019
*/

5
src/main/java/com/weis/darklaf/ui/button/DarkButtonUI.java

@ -1,9 +1,8 @@
package com.weis.darklaf.ui.button;
import com.bulenkov.darcula.ui.DarculaButtonUI;
import com.bulenkov.iconloader.util.SystemInfo;
import com.weis.darklaf.util.GraphicsContext;
import com.weis.darklaf.util.GraphicsUtil;
import com.weis.darklaf.util.SystemInfo;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import sun.swing.SwingUtilities2;
@ -19,8 +18,6 @@ import java.awt.*;
import java.awt.geom.RoundRectangle2D;
/**
* Custom adaption of {@link DarculaButtonUI}.
*
* @author Jannis Weis
* @since 2019
*/

3
src/main/java/com/weis/darklaf/ui/checkbox/DarkCheckBoxBorder.java

@ -1,7 +1,8 @@
package com.weis.darklaf.ui.checkbox;
import com.bulenkov.iconloader.util.SystemInfo;
import com.weis.darklaf.util.DarkUIUtil;
import com.weis.darklaf.util.SystemInfo;
import javax.swing.border.Border;
import javax.swing.plaf.InsetsUIResource;

2
src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelImageProducer.java

@ -9,7 +9,7 @@ public class ColorWheelImageProducer extends MemoryImageSource {
private final int[] myPixels;
private final int myWidth;
private final int myHeight;
private float myBrightness = 1f;
private float myBrightness;
private float[] myHues;
private float[] mySat;

2
src/main/java/com/weis/darklaf/ui/colorchooser/ColorWheelPanel.java

@ -9,7 +9,6 @@ import java.awt.*;
public class ColorWheelPanel extends JPanel {
private final ColorWheel myColorWheel;
private final SlideComponent myBrightnessComponent;
private final boolean opacityInPercent;
private SlideComponent myOpacityComponent = null;
private boolean enableOpacity;
@ -19,7 +18,6 @@ public class ColorWheelPanel extends JPanel {
setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
this.enableOpacity = enableOpacity;
this.opacityInPercent = opacityInPercent;
myColorWheel = new ColorWheel();
add(myColorWheel, BorderLayout.CENTER);

2
src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserPanel.java

@ -11,8 +11,6 @@ import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
public class DarkColorChooserPanel extends AbstractColorChooserPanel implements ColorListener {

3
src/main/java/com/weis/darklaf/ui/colorchooser/DarkColorChooserUI.java

@ -13,9 +13,6 @@ import javax.swing.event.AncestorListener;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicColorChooserUI;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.beans.PropertyChangeListener;
public class DarkColorChooserUI extends BasicColorChooserUI {

2
src/main/java/com/weis/darklaf/ui/menu/DarkPopupMenuUI.java

@ -85,7 +85,7 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI {
MenuSelectionManager msm = MenuSelectionManager.defaultManager();
MenuElement[] p = msm.getSelectedPath();
List<JPopupMenu> list = new ArrayList<JPopupMenu>(p.length);
List<JPopupMenu> list = new ArrayList<>(p.length);
for (MenuElement element : p) {
if (element instanceof JPopupMenu) {
list.add((JPopupMenu) element);

3
src/main/java/com/weis/darklaf/ui/radiobutton/DarkRadioButtonBorder.java

@ -1,7 +1,8 @@
package com.weis.darklaf.ui.radiobutton;
import com.bulenkov.iconloader.util.SystemInfo;
import com.weis.darklaf.util.DarkUIUtil;
import com.weis.darklaf.util.SystemInfo;
import javax.swing.border.Border;
import javax.swing.plaf.InsetsUIResource;

4
src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerBorder.java

@ -14,8 +14,8 @@ import java.awt.*;
public class DarkSpinnerBorder implements Border, UIResource {
public static int BORDER_SIZE = DarkTextBorder.BORDER_SIZE;
public static int ARC_SIZE = DarkTextFieldUI.SEARCH_ARC_SIZE;
public static final int BORDER_SIZE = DarkTextBorder.BORDER_SIZE;
public static final int ARC_SIZE = DarkTextFieldUI.SEARCH_ARC_SIZE;
@Override
public void paintBorder(@NotNull final Component c, final Graphics g2,

3
src/main/java/com/weis/darklaf/ui/spinner/DarkSpinnerUI.java

@ -31,7 +31,6 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
private Component component;
private JComponent editor;
private Color compColor;
private JButton nextButton;
private JButton prevButton;
private final FocusListener focusListener = new FocusAdapter() {
@ -128,7 +127,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements PropertyChangeListe
@Override
protected Component createNextButton() {
nextButton = createArrow(SwingConstants.NORTH);
JButton nextButton = createArrow(SwingConstants.NORTH);
nextButton.setName("Spinner.nextButton");
nextButton.setBorder(new EmptyBorder(1, 1, 1, 1));
installNextButtonListeners(nextButton);

1
src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java

@ -941,6 +941,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
}
@SuppressWarnings("SuspiciousNameCombination")
@Override
protected void calculateTabRects(final int tabPlacement, final int tabCount) {
FontMetrics metrics = getFontMetrics();

100
src/main/java/com/weis/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java

@ -35,6 +35,7 @@ import java.awt.event.MouseMotionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Hashtable;
import java.util.Objects;
import java.util.Vector;
/**
@ -196,8 +197,8 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
// Private instance data
protected Insets currentPadInsets = new Insets(0, 0, 0, 0);
protected Insets currentTabAreaInsets = new Insets(0, 0, 0, 0);
protected final Insets currentPadInsets = new Insets(0, 0, 0, 0);
protected final Insets currentTabAreaInsets = new Insets(0, 0, 0, 0);
protected Component visibleComponent;
// PENDING(api): See comment for ContainerHandler
@ -220,7 +221,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
* A rectangle used for general layout calculations in order
* to avoid constructing many new Rectangles on the fly.
*/
protected transient Rectangle calcRect = new Rectangle(0, 0, 0, 0);
protected final transient Rectangle calcRect = new Rectangle(0, 0, 0, 0);
/**
* Tab that has focus.
@ -644,6 +645,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
/**
* Adds the specified mnemonic at the specified index.
*/
@SuppressWarnings("MagicConstant")
protected void addMnemonic(final int index, final int mnemonic) {
if (mnemonicToIndexMap == null) {
initMnemonics();
@ -653,14 +655,14 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
mnemonicInputMap.put(KeyStroke.getKeyStroke(mnemonic, InputEvent.ALT_GRAPH_DOWN_MASK
| DarkUIUtil.getFocusAcceleratorKeyMask()),
"setSelectedIndex");
mnemonicToIndexMap.put(Integer.valueOf(mnemonic), Integer.valueOf(index));
mnemonicToIndexMap.put(mnemonic, index);
}
/**
* Installs the state needed for mnemonics.
*/
protected void initMnemonics() {
mnemonicToIndexMap = new Hashtable<Integer, Integer>();
mnemonicToIndexMap = new Hashtable<>();
mnemonicInputMap = new ComponentInputMapUIResource(tabPane);
mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(tabPane,
JComponent.WHEN_IN_FOCUSED_WINDOW));
@ -733,16 +735,14 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
Insets tabAreaInsets = getTabAreaInsets(placement);
switch (placement) {
case JTabbedPane.TOP:
case JTabbedPane.LEFT:
case JTabbedPane.RIGHT:
baseline += insets.top + tabAreaInsets.top;
return baseline;
case JTabbedPane.BOTTOM:
baseline = height - insets.bottom -
tabAreaInsets.bottom - maxTabHeight + baseline;
return baseline;
case JTabbedPane.LEFT:
case JTabbedPane.RIGHT:
baseline += insets.top + tabAreaInsets.top;
return baseline;
}
}
return -1;
@ -1025,8 +1025,8 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
* subtracting xCropLen[i] from (tab.y + tab.height) and adding yCropLen[i]
* to (tab.x).
*/
protected static int[] xCropLen = {1, 1, 0, 0, 1, 1, 2, 2};
protected static int[] yCropLen = {0, 3, 3, 6, 6, 9, 9, 12};
protected static final int[] xCropLen = {1, 1, 0, 0, 1, 1, 2, 2};
protected static final int[] yCropLen = {0, 3, 3, 6, 6, 9, 9, 12};
protected static final int CROP_SEGMENT = 12;
protected static Polygon createCroppedTabShape(final int tabPlacement, final Rectangle tabRect, final int cropline) {
@ -2511,7 +2511,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
*/
protected int getPreviousTabIndex(final int base) {
int tabIndex = (base - 1 >= 0 ? base - 1 : tabPane.getTabCount() - 1);
return (tabIndex >= 0 ? tabIndex : 0);
return (Math.max(tabIndex, 0));
}
/**
@ -2570,7 +2570,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
*/
protected int getPreviousTabRun(final int baseRun) {
int runIndex = (baseRun - 1 >= 0 ? baseRun - 1 : runCount - 1);
return (runIndex >= 0 ? runIndex : 0);
return (Math.max(runIndex, 0));
}
/**
@ -2590,6 +2590,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
* @param targetInsets the target insets
* @param targetPlacement the target placement
*/
@SuppressWarnings("SuspiciousNameCombination")
protected static void rotateInsets(final Insets topInsets, final Insets targetInsets, final int targetPlacement) {
switch (targetPlacement) {
@ -2658,37 +2659,37 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
if (ui == null) {
return;
}
if (key == NEXT) {
if (Objects.equals(key, NEXT)) {
ui.navigateSelectedTab(SwingConstants.NEXT);
} else if (key == PREVIOUS) {
} else if (Objects.equals(key, PREVIOUS)) {
ui.navigateSelectedTab(SwingConstants.PREVIOUS);
} else if (key == RIGHT) {
} else if (Objects.equals(key, RIGHT)) {
ui.navigateSelectedTab(SwingConstants.EAST);
} else if (key == LEFT) {
} else if (Objects.equals(key, LEFT)) {
ui.navigateSelectedTab(SwingConstants.WEST);
} else if (key == UP) {
} else if (Objects.equals(key, UP)) {
ui.navigateSelectedTab(SwingConstants.NORTH);
} else if (key == DOWN) {
} else if (Objects.equals(key, DOWN)) {
ui.navigateSelectedTab(SwingConstants.SOUTH);
} else if (key == PAGE_UP) {
} else if (Objects.equals(key, PAGE_UP)) {
int tabPlacement = pane.getTabPlacement();
if (tabPlacement == TOP || tabPlacement == BOTTOM) {
ui.navigateSelectedTab(SwingConstants.WEST);
} else {
ui.navigateSelectedTab(SwingConstants.NORTH);
}
} else if (key == PAGE_DOWN) {
} else if (Objects.equals(key, PAGE_DOWN)) {
int tabPlacement = pane.getTabPlacement();
if (tabPlacement == TOP || tabPlacement == BOTTOM) {
ui.navigateSelectedTab(SwingConstants.EAST);
} else {
ui.navigateSelectedTab(SwingConstants.SOUTH);
}
} else if (key == REQUEST_FOCUS) {
} else if (Objects.equals(key, REQUEST_FOCUS)) {
pane.requestFocus();
} else if (key == REQUEST_FOCUS_FOR_VISIBLE) {
} else if (Objects.equals(key, REQUEST_FOCUS_FOR_VISIBLE)) {
ui.requestFocusForVisibleComponent();
} else if (key == SET_SELECTED) {
} else if (Objects.equals(key, SET_SELECTED)) {
String command = e.getActionCommand();
if (command != null && command.length() > 0) {
@ -2696,21 +2697,21 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
if (mnemonic >= 'a' && mnemonic <= 'z') {
mnemonic -= ('a' - 'A');
}
Integer index = ui.mnemonicToIndexMap.get(Integer.valueOf(mnemonic));
if (index != null && pane.isEnabledAt(index.intValue())) {
pane.setSelectedIndex(index.intValue());
Integer index = ui.mnemonicToIndexMap.get(mnemonic);
if (index != null && pane.isEnabledAt(index)) {
pane.setSelectedIndex(index);
}
}
} else if (key == SELECT_FOCUSED) {
} else if (Objects.equals(key, SELECT_FOCUSED)) {
int focusIndex = ui.getFocusIndex();
if (focusIndex != -1) {
pane.setSelectedIndex(focusIndex);
}
} else if (key == SCROLL_FORWARD) {
} else if (Objects.equals(key, SCROLL_FORWARD)) {
if (ui.scrollableTabLayoutEnabled()) {
ui.tabScroller.scrollForward(pane.getTabPlacement());
}
} else if (key == SCROLL_BACKWARD) {
} else if (Objects.equals(key, SCROLL_BACKWARD)) {
if (ui.scrollableTabLayoutEnabled()) {
ui.tabScroller.scrollBackward(pane.getTabPlacement());
}
@ -3228,9 +3229,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
protected void rotateTabRuns(final int tabPlacement, final int selectedRun) {
for (int i = 0; i < selectedRun; i++) {
int save = tabRuns[0];
for (int j = 1; j < runCount; j++) {
tabRuns[j - 1] = tabRuns[j];
}
if (runCount - 1 >= 0) System.arraycopy(tabRuns, 1, tabRuns, 0, runCount - 1);
tabRuns[runCount - 1] = save;
}
}
@ -3577,8 +3576,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
} else if (tabScroller != null &&
(child == tabScroller.scrollForwardButton ||
child == tabScroller.scrollBackwardButton)) {
Component scrollbutton = child;
Dimension bsize = scrollbutton.getPreferredSize();
Dimension bsize = child.getPreferredSize();
int bx = 0;
int by = 0;
int bw = bsize.width;
@ -3764,10 +3762,10 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
public ScrollableTabPanel tabPanel;
public JButton scrollForwardButton;
public JButton scrollBackwardButton;
public CroppedEdge croppedEdge;
public final CroppedEdge croppedEdge;
public int leadingTabIndex;
protected Point tabViewPosition = new Point(0, 0);
protected final Point tabViewPosition = new Point(0, 0);
ScrollableTabSupport(final int tabPlacement) {
viewport = new ScrollableTabViewport();
@ -4012,7 +4010,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
}
@SuppressWarnings("serial") // Superclass is not serializable across versions
protected class ScrollableTabButton extends BasicArrowButton implements UIResource,
protected static class ScrollableTabButton extends BasicArrowButton implements UIResource,
SwingConstants {
public ScrollableTabButton(final int direction) {
super(direction,
@ -4036,36 +4034,36 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
JTabbedPane pane = (JTabbedPane) e.getSource();
String name = e.getPropertyName();
boolean isScrollLayout = scrollableTabLayoutEnabled();
if (name == "mnemonicAt") {
if (Objects.equals(name, "mnemonicAt")) {
updateMnemonics();
pane.repaint();
} else if (name == "displayedMnemonicIndexAt") {
} else if (Objects.equals(name, "displayedMnemonicIndexAt")) {
pane.repaint();
} else if (name == "indexForTitle") {
} else if (Objects.equals(name, "indexForTitle")) {
calculatedBaseline = false;
Integer index = (Integer) e.getNewValue();
updateHtmlViews(index, false);
} else if (name == "tabLayoutPolicy") {
} else if (Objects.equals(name, "tabLayoutPolicy")) {
DarkTabbedPaneUIBridge.this.uninstallUI(pane);
DarkTabbedPaneUIBridge.this.installUI(pane);
calculatedBaseline = false;
} else if (name == "tabPlacement") {
} else if (Objects.equals(name, "tabPlacement")) {
if (scrollableTabLayoutEnabled()) {
tabScroller.createButtons();
}
calculatedBaseline = false;
} else if (name == "opaque" && isScrollLayout) {
boolean newVal = ((Boolean) e.getNewValue()).booleanValue();
} else if (Objects.equals(name, "opaque") && isScrollLayout) {
boolean newVal = (Boolean) e.getNewValue();
tabScroller.tabPanel.setOpaque(newVal);
tabScroller.viewport.setOpaque(newVal);
} else if (name == "background" && isScrollLayout) {
} else if (Objects.equals(name, "background") && isScrollLayout) {
Color newVal = (Color) e.getNewValue();
tabScroller.tabPanel.setBackground(newVal);
tabScroller.viewport.setBackground(newVal);
Color newColor = selectedColor == null ? newVal : selectedColor;
tabScroller.scrollForwardButton.setBackground(newColor);
tabScroller.scrollBackwardButton.setBackground(newColor);
} else if (name == "indexForTabComponent") {
} else if (Objects.equals(name, "indexForTabComponent")) {
if (tabContainer != null) {
tabContainer.removeUnusedTabComponents();
}
@ -4081,10 +4079,10 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
tabPane.revalidate();
tabPane.repaint();
calculatedBaseline = false;
} else if (name == "indexForNullComponent") {
} else if (Objects.equals(name, "indexForNullComponent")) {
isRunsDirty = true;
updateHtmlViews((Integer) e.getNewValue(), true);
} else if (name == "font" || SwingUtilities2.isScaleChanged(e)) {
} else if (Objects.equals(name, "font") || SwingUtilities2.isScaleChanged(e)) {
calculatedBaseline = false;
}
}
@ -4252,7 +4250,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
Integer indexObj =
(Integer) tp.getClientProperty("__index_to_remove__");
if (indexObj != null) {
int index = indexObj.intValue();
int index = indexObj;
if (htmlViews != null && htmlViews.size() > index) {
htmlViews.removeElementAt(index);
}
@ -4326,7 +4324,7 @@ public class DarkTabbedPaneUIBridge extends TabbedPaneUI implements SwingConstan
}
protected Vector<View> createHTMLVector() {
Vector<View> htmlViews = new Vector<View>();
Vector<View> htmlViews = new Vector<>();
int count = tabPane.getTabCount();
if (count > 0) {
for (int i = 0; i < count; i++) {

2
src/main/java/com/weis/darklaf/ui/tabbedpane/TabbedPaneTransferHandler.java

@ -274,6 +274,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa
}
dropRect.y = destRect.y + destRect.height - dropRect.height;
} else if (placement == LEFT || placement == RIGHT) {
//Todo
}
}
}
@ -525,6 +526,7 @@ public class TabbedPaneTransferHandler extends TransferHandler implements DropTa
return new Rectangle(transferData.tabBounds);
}
@NotNull
@Override
public Object getTransferData(final DataFlavor flavor) throws UnsupportedFlavorException {
if (!isDataFlavorSupported(flavor)) {

3
src/main/java/com/weis/darklaf/ui/table/DarkTableBorder.java

@ -1,6 +1,7 @@
package com.weis.darklaf.ui.table;
import com.weis.darklaf.components.border.MutableLineBorder;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.plaf.UIResource;
@ -13,7 +14,7 @@ public class DarkTableBorder extends MutableLineBorder implements UIResource {
}
@Override
public void paintBorder(final Component c, final Graphics g, final int x, final int y,
public void paintBorder(final Component c, @NotNull final Graphics g, final int x, final int y,
final int width, final int height) {
setColor(getBorderColor());
super.paintBorder(c, g, x, y, width, height);

4
src/main/java/com/weis/darklaf/ui/table/DarkTableCellRenderer.java

@ -48,11 +48,11 @@ public class DarkTableCellRenderer extends DefaultTableCellRenderer {
if (!isSelected) {
if (row % 2 == 1) {
component.setBackground(alternativeRowColor);
setDefaultCellRenderWithAllType(table, value, isSelected, hasFocus, row, column,
setDefaultCellRenderWithAllType(table, value, false, hasFocus, row, column,
alternativeRowColor);
} else {
component.setBackground(normalColor);
setDefaultCellRenderWithAllType(table, value, isSelected, hasFocus, row, column, normalColor);
setDefaultCellRenderWithAllType(table, value, false, hasFocus, row, column, normalColor);
}
component.setForeground(table.getSelectionForeground());
}

3
src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderBorder.java

@ -1,6 +1,7 @@
package com.weis.darklaf.ui.table;
import com.weis.darklaf.components.border.MutableLineBorder;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.plaf.UIResource;
@ -13,7 +14,7 @@ public class DarkTableHeaderBorder extends MutableLineBorder implements UIResour
}
@Override
public void paintBorder(final Component c, final Graphics g, final int x, final int y,
public void paintBorder(final Component c, @NotNull final Graphics g, final int x, final int y,
final int width, final int height) {
setColor(getBorderColor());
super.paintBorder(c, g, x, y, width, height);

4
src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUI.java

@ -1,6 +1,6 @@
package com.weis.darklaf.ui.table;
import com.bulenkov.iconloader.util.GraphicsConfig;
import com.weis.darklaf.util.GraphicsContext;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@ -50,7 +50,7 @@ public class DarkTableHeaderUI extends DarkTableHeaderUIBridge {
@Override
public void paint(final Graphics g2, final @NotNull JComponent c) {
final Graphics2D g = (Graphics2D) g2;
final GraphicsConfig config = new GraphicsConfig(g);
final GraphicsContext config = new GraphicsContext(g);
int h = c.getHeight();
int w = c.getWidth();

32
src/main/java/com/weis/darklaf/ui/table/DarkTableHeaderUIBridge.java

@ -19,15 +19,16 @@ import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import java.util.Objects;
public class DarkTableHeaderUIBridge extends BasicTableHeaderUI {
protected static Cursor resizeCursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
protected static final Cursor resizeCursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
//
// Instance Variables
//
protected static FocusListener focusListener = new FocusListener() {
protected static final FocusListener focusListener = new FocusListener() {
public void focusGained(@NotNull final FocusEvent e) {
repaintHeader(e.getSource());
}
@ -242,7 +243,6 @@ public class DarkTableHeaderUIBridge extends BasicTableHeaderUI {
if (doScroll) {
scrollToColumn(newColIndex);
}
return;
}
/**
@ -585,16 +585,16 @@ public class DarkTableHeaderUIBridge extends BasicTableHeaderUI {
DarkTableHeaderUIBridge ui =
(DarkTableHeaderUIBridge) DarkUIUtil.getUIOfType(th.getUI(), DarkTableHeaderUIBridge.class);
if (ui != null) {
if (key == MOVE_COLUMN_LEFT) {
if (Objects.equals(key, MOVE_COLUMN_LEFT)) {
return th.getReorderingAllowed()
&& maybeMoveColumn(true, th, ui, false);
} else if (key == MOVE_COLUMN_RIGHT) {
} else if (Objects.equals(key, MOVE_COLUMN_RIGHT)) {
return th.getReorderingAllowed()
&& maybeMoveColumn(false, th, ui, false);
} else if (key == RESIZE_LEFT ||
key == RESIZE_RIGHT) {
} else if (Objects.equals(key, RESIZE_LEFT) ||
Objects.equals(key, RESIZE_RIGHT)) {
return canResize(cm.getColumn(ui.getSelectedColumnIndex()), th);
} else if (key == FOCUS_TABLE) {
} else if (Objects.equals(key, FOCUS_TABLE)) {
return (th.getTable() != null);
}
}
@ -611,7 +611,7 @@ public class DarkTableHeaderUIBridge extends BasicTableHeaderUI {
}
String name = getName();
if (TOGGLE_SORT_ORDER == name) {
if (Objects.equals(TOGGLE_SORT_ORDER, name)) {
JTable table = th.getTable();
RowSorter<?> sorter = table == null ? null : table.getRowSorter();
if (sorter != null) {
@ -620,27 +620,27 @@ public class DarkTableHeaderUIBridge extends BasicTableHeaderUI {
columnIndex);
sorter.toggleSortOrder(columnIndex);
}
} else if (SELECT_COLUMN_TO_LEFT == name) {
} else if (Objects.equals(SELECT_COLUMN_TO_LEFT, name)) {
if (th.getComponentOrientation().isLeftToRight()) {
ui.selectPreviousColumn(true);
} else {
ui.selectNextColumn(true);
}
} else if (SELECT_COLUMN_TO_RIGHT == name) {
} else if (Objects.equals(SELECT_COLUMN_TO_RIGHT, name)) {
if (th.getComponentOrientation().isLeftToRight()) {
ui.selectNextColumn(true);
} else {
ui.selectPreviousColumn(true);
}
} else if (MOVE_COLUMN_LEFT == name) {
} else if (Objects.equals(MOVE_COLUMN_LEFT, name)) {
moveColumn(true, th, ui);
} else if (MOVE_COLUMN_RIGHT == name) {
} else if (Objects.equals(MOVE_COLUMN_RIGHT, name)) {
moveColumn(false, th, ui);
} else if (RESIZE_LEFT == name) {
} else if (Objects.equals(RESIZE_LEFT, name)) {
resize(true, th, ui);
} else if (RESIZE_RIGHT == name) {
} else if (Objects.equals(RESIZE_RIGHT, name)) {
resize(false, th, ui);
} else if (FOCUS_TABLE == name) {
} else if (Objects.equals(FOCUS_TABLE, name)) {
JTable table = th.getTable();
if (table != null) {
table.requestFocusInWindow();

6
src/main/java/com/weis/darklaf/ui/table/DarkTableUIBridge.java

@ -23,8 +23,8 @@ public class DarkTableUIBridge extends BasicTableUI {
}
protected static int getAdjustedLead(final JTable table, final boolean row) {
return row ? getAdjustedLead(table, row, table.getSelectionModel())
: getAdjustedLead(table, row, table.getColumnModel().getSelectionModel());
return row ? getAdjustedLead(table, true, table.getSelectionModel())
: getAdjustedLead(table, false, table.getColumnModel().getSelectionModel());
}
/**
@ -233,7 +233,7 @@ public class DarkTableUIBridge extends BasicTableUI {
protected Rectangle extendRect(final Rectangle rect, final boolean horizontal) {
if (rect == null) {
return rect;
return null;
}
if (horizontal) {

6
src/main/java/com/weis/darklaf/ui/text/DarkEditorPaneUI.java

@ -173,16 +173,14 @@ public class DarkEditorPaneUI extends DarkTextUI {
void removeActions(final ActionMap map, final Action[] actions) {
int n = actions.length;
for (int i = 0; i < n; i++) {
Action a = actions[i];
for (Action a : actions) {
map.remove(a.getValue(Action.NAME));
}
}
void addActions(final ActionMap map, final Action[] actions) {
int n = actions.length;
for (int i = 0; i < n; i++) {
Action a = actions[i];
for (Action a : actions) {
map.put(a.getValue(Action.NAME), a);
}
}

5
src/main/java/com/weis/darklaf/ui/text/DarkTextAreaUI.java

@ -46,11 +46,6 @@ public class DarkTextAreaUI extends DarkTextUI {
return "TextArea";
}
protected void installDefaults() {
super.installDefaults();
//the fix for 4785160 is undone
}
/**
* This method gets called when a bound property is changed
* on the associated JTextComponent. This is a hook

10
src/main/java/com/weis/darklaf/ui/text/DarkTextBorder.java

@ -1,12 +1,13 @@
package com.weis.darklaf.ui.text;
import com.bulenkov.darcula.ui.DarculaTextBorder;
import com.weis.darklaf.util.DarkUIUtil;
import com.weis.darklaf.util.GraphicsContext;
import com.weis.darklaf.util.GraphicsUtil;
import org.jetbrains.annotations.Contract;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.UIResource;
import java.awt.*;
/**
@ -15,7 +16,7 @@ import java.awt.*;
* @author Jannis Weis
* @since 2019
*/
public class DarkTextBorder extends DarculaTextBorder {
public class DarkTextBorder implements Border, UIResource {
public final static int BORDER_SIZE = 2;
public final static int PADDING = 4;
@ -77,4 +78,9 @@ public class DarkTextBorder extends DarculaTextBorder {
}
return insets;
}
@Override
public boolean isBorderOpaque() {
return false;
}
}

3
src/main/java/com/weis/darklaf/ui/text/DarkTextFieldUI.java

@ -1,6 +1,5 @@
package com.weis.darklaf.ui.text;
import com.bulenkov.darcula.ui.DarculaTextBorder;
import com.weis.darklaf.decorators.MouseClickListener;
import com.weis.darklaf.decorators.MouseMovementListener;
import com.weis.darklaf.decorators.PopupMenuAdapter;
@ -134,7 +133,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
Border border = c.getBorder();
if (isSearchField(c)) {
paintSearchField(g, c);
} else if (border instanceof DarculaTextBorder) {
} else if (border instanceof DarkTextBorder) {
paintBorderBackground(g, c);
} else {
super.paintBackground(g);

2
src/main/java/com/weis/darklaf/ui/text/SelectLineAction.java

@ -39,7 +39,7 @@ public class SelectLineAction extends TextAction {
@Override
public void actionPerformed(final ActionEvent e) {
int newPos = 0;
int newPos;
try {
var textArea = getTextComponent(e);
int caretPosition = textArea.getCaretPosition();

4
src/main/java/com/weis/darklaf/ui/text/SelectWordAction.java

@ -10,8 +10,8 @@ import java.awt.event.ActionEvent;
public class SelectWordAction extends TextAction {
protected Action start;
protected Action end;
protected final Action start;
protected final Action end;
public SelectWordAction() {
super(DefaultEditorKit.selectWordAction);

7
src/main/java/com/weis/darklaf/util/DarkUIUtil.java

@ -1,8 +1,5 @@
package com.weis.darklaf.util;
import com.bulenkov.iconloader.util.ColorUtil;
import com.bulenkov.iconloader.util.DoubleColor;
import com.bulenkov.iconloader.util.Gray;
import com.weis.darklaf.decorators.CellRenderer;
import com.weis.darklaf.ui.menu.DarkPopupMenuUI;
import org.jetbrains.annotations.Contract;
@ -181,8 +178,8 @@ public final class DarkUIUtil {
}
public static Color getTreeUnfocusedSelectionBackground() {
Color background = getTreeTextBackground();
return ColorUtil.isDark(background) ? new DoubleColor(Gray._30, new Color(13, 41, 62)) : Gray._212;
// Color background = getTreeTextBackground();
return new Color(13, 41, 62);
}
public static Color getTreeTextBackground() {

6
src/main/java/com/weis/darklaf/util/LafUtil.java

@ -1,8 +1,5 @@
package com.weis.darklaf.util;
import com.bulenkov.iconloader.util.ColorUtil;
import com.bulenkov.iconloader.util.StringUtil;
import com.bulenkov.iconloader.util.SystemInfo;
import com.weis.darklaf.DarkLaf;
import com.weis.darklaf.icons.EmptyIcon;
import com.weis.darklaf.icons.IconLoader;
@ -170,11 +167,8 @@ public final class LafUtil {
private static final class LoadError {
private final String message;
@Contract(pure = true)
private LoadError(final String message) {
this.message = message;
}
}

41
src/main/java/com/weis/darklaf/util/StringUtil.java

@ -1,6 +1,11 @@
package com.weis.darklaf.util;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public final class StringUtil {
@ -53,4 +58,40 @@ public final class StringUtil {
return a;
}
}
public static List<String> split(String s, String separator) {
return split(s, separator, true);
}
public static List<String> split(String s, String separator, boolean excludeSeparator) {
return split(s, separator, excludeSeparator, true);
}
public static List<String> split(String s, @NotNull String separator, boolean excludeSeparator, boolean excludeEmptyStrings) {
if (separator.isEmpty()) {
return Collections.singletonList(s);
} else {
List<String> result = new ArrayList<>();
int pos = 0;
while(true) {
int index = s.indexOf(separator, pos);
if (index == -1) {
if (pos < s.length() || !excludeEmptyStrings && pos == s.length()) {
result.add(s.substring(pos, s.length()));
}
return result;
}
int nextPos = index + separator.length();
String token = s.substring(pos, excludeSeparator ? index : nextPos);
if (!token.isEmpty() || !excludeEmptyStrings) {
result.add(token);
}
pos = nextPos;
}
}
}
}

137
src/main/java/com/weis/darklaf/util/SystemInfo.java

@ -0,0 +1,137 @@
package com.weis.darklaf.util;
import org.jetbrains.annotations.Contract;
/**
* @author Konstantin Bulenkov
*/
public class SystemInfo {
public static final String X86 = "32";
public static final String X64 = "64";
public static final String OS_NAME = System.getProperty("os.name");
public static final String OS_VERSION = System.getProperty("os.version").toLowerCase();
public static final String JAVA_VERSION = System.getProperty("java.version");
public static final String JAVA_RUNTIME_VERSION = System.getProperty("java.runtime.version");
protected static final String _OS_NAME;
public static final boolean isWindows;
public static final boolean isOS2;
public static final boolean isMac;
public static final boolean isLinux;
public static final boolean isUnix;
public static final boolean isFileSystemCaseSensitive;
public static final boolean isMacOSLion;
public static final boolean isAppleJvm;
public static final boolean isOracleJvm;
public static final boolean isSunJvm;
public static final String jreArchitecture = System.getProperty("sun.arch.data.model");
public static final boolean isX86;
public static final boolean isX64;
public static final boolean isUndefined;
@Contract(pure = true)
public SystemInfo() {
}
public static boolean isOsVersionAtLeast(String version) {
return compareVersionNumbers(OS_VERSION, version) >= 0;
}
private static boolean isTiger() {
return isMac && !OS_VERSION.startsWith("10.0")
&& !OS_VERSION.startsWith("10.1")
&& !OS_VERSION.startsWith("10.2")
&& !OS_VERSION.startsWith("10.3");
}
private static boolean isLeopard() {
return isMac && isTiger() && !OS_VERSION.startsWith("10.4");
}
private static boolean isSnowLeopard() {
return isMac && isLeopard() && !OS_VERSION.startsWith("10.5");
}
private static boolean isLion() {
return isMac && isSnowLeopard() && !OS_VERSION.startsWith("10.6");
}
private static boolean isMountainLion() {
return isMac && isLion() && !OS_VERSION.startsWith("10.7");
}
public static int compareVersionNumbers(String v1, String v2) {
if (v1 == null && v2 == null) {
return 0;
} else if (v1 == null) {
return -1;
} else if (v2 == null) {
return 1;
} else {
String[] part1 = v1.split("[.\\_-]");
String[] part2 = v2.split("[._\\-]");
int idx;
for(idx = 0; idx < part1.length && idx < part2.length; ++idx) {
String p1 = part1[idx];
String p2 = part2[idx];
int cmp;
if (p1.matches("\\d+") && p2.matches("\\d+")) {
cmp = (Integer.valueOf(p1)).compareTo(Integer.valueOf(p2));
} else {
cmp = part1[idx].compareTo(part2[idx]);
}
if (cmp != 0) {
return cmp;
}
}
if (part1.length == part2.length) {
return 0;
} else {
return part1.length > idx ? 1 : -1;
}
}
}
public static boolean isJavaVersionAtLeast(String v) {
return com.bulenkov.iconloader.util.StringUtil.compareVersionNumbers(JAVA_RUNTIME_VERSION, v) >= 0;
}
private static boolean isOracleJvm() {
String vendor = getJavaVmVendor();
return vendor != null && com.bulenkov.iconloader.util.StringUtil.containsIgnoreCase(vendor, "Oracle");
}
private static boolean isSunJvm() {
String vendor = getJavaVmVendor();
return vendor != null && com.bulenkov.iconloader.util.StringUtil.containsIgnoreCase(vendor, "Sun") && com.bulenkov.iconloader.util.StringUtil.containsIgnoreCase(vendor, "Microsystems");
}
private static boolean isAppleJvm() {
String vendor = getJavaVmVendor();
return vendor != null && com.bulenkov.iconloader.util.StringUtil.containsIgnoreCase(vendor, "Apple");
}
public static String getJavaVmVendor() {
return System.getProperty("java.vm.vendor");
}
static {
_OS_NAME = OS_NAME.toLowerCase();
isWindows = _OS_NAME.startsWith("windows");
isOS2 = _OS_NAME.startsWith("os/2") || _OS_NAME.startsWith("os2");
isMac = _OS_NAME.startsWith("mac");
isLinux = _OS_NAME.startsWith("linux");
isUnix = !isWindows && !isOS2;
isFileSystemCaseSensitive = isUnix && !isMac;
isMacOSLion = isLion();
isAppleJvm = isAppleJvm();
isOracleJvm = isOracleJvm();
isSunJvm = isSunJvm();
isX64 = X64.equals(jreArchitecture);
isX86 = X86.equals(jreArchitecture);
isUndefined = !isX86 & !isX64;
}
}
Loading…
Cancel
Save