mirror of https://github.com/weisJ/darklaf.git
weisj
5 years ago
12 changed files with 166 additions and 3 deletions
@ -0,0 +1,58 @@
|
||||
/* |
||||
* MIT License |
||||
* |
||||
* Copyright (c) 2019 Jannis Weis |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
* of this software and associated documentation files (the "Software"), to deal |
||||
* in the Software without restriction, including without limitation the rights |
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
* copies of the Software, and to permit persons to whom the Software is |
||||
* furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included in all |
||||
* copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
* SOFTWARE. |
||||
*/ |
||||
package com.github.weisj.darklaf.components.border; |
||||
|
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.border.Border; |
||||
import java.util.Map; |
||||
import java.util.WeakHashMap; |
||||
|
||||
public final class DarkBorders { |
||||
|
||||
private static final WeakLineBorder KEY = new WeakLineBorder(0, 0, 0, 0); |
||||
private static Map<WeakLineBorder, WeakLineBorder> lineBorderMap = new WeakHashMap<>(); |
||||
|
||||
@NotNull |
||||
public static Border createLineBorder(final int top, final int left, final int bottom, final int right) { |
||||
WeakLineBorder border = null; |
||||
KEY.setInsets(top, left, bottom, right); |
||||
if (lineBorderMap.containsKey(KEY)) { |
||||
border = lineBorderMap.get(KEY); |
||||
} |
||||
if (border == null) { |
||||
border = new WeakLineBorder(top, left, bottom, right); |
||||
lineBorderMap.put(KEY, border); |
||||
} |
||||
border.setColor(UIManager.getColor("border")); |
||||
return border; |
||||
} |
||||
|
||||
public static void update() { |
||||
for (var border : lineBorderMap.values()) { |
||||
border.setColor(UIManager.getColor("border")); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,65 @@
|
||||
/* |
||||
* MIT License |
||||
* |
||||
* Copyright (c) 2019 Jannis Weis |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
* of this software and associated documentation files (the "Software"), to deal |
||||
* in the Software without restriction, including without limitation the rights |
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
* copies of the Software, and to permit persons to whom the Software is |
||||
* furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included in all |
||||
* copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
* SOFTWARE. |
||||
*/ |
||||
package com.github.weisj.darklaf.components.border; |
||||
|
||||
import org.jetbrains.annotations.Contract; |
||||
|
||||
class WeakLineBorder extends MutableLineBorder { |
||||
|
||||
private int left; |
||||
private int top; |
||||
private int bottom; |
||||
private int right; |
||||
|
||||
public WeakLineBorder(final int top, final int left, final int bottom, final int right) { |
||||
super(top, left, bottom, right, null); |
||||
this.top = top; |
||||
this.left = left; |
||||
this.bottom = bottom; |
||||
this.right = right; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int result = left; |
||||
result = 31 * result + top; |
||||
result = 31 * result + bottom; |
||||
result = 31 * result + right; |
||||
return result; |
||||
} |
||||
|
||||
@Contract(value = "null -> false", pure = true) |
||||
@Override |
||||
public boolean equals(final Object o) { |
||||
if (this == o) return true; |
||||
if (o == null || getClass() != o.getClass()) return false; |
||||
|
||||
WeakLineBorder that = (WeakLineBorder) o; |
||||
|
||||
if (left != that.left) return false; |
||||
if (top != that.top) return false; |
||||
if (bottom != that.bottom) return false; |
||||
return right == that.right; |
||||
} |
||||
} |
Loading…
Reference in new issue