Color bug fixes
This commit is contained in:
7
.idea/discord.xml
generated
Normal file
7
.idea/discord.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="ASK" />
|
||||||
|
<option name="description" value="" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,45 +1,75 @@
|
|||||||
// Source - https://stackoverflow.com/a/3634480
|
|
||||||
// Posted by Lalchand, modified by community. See post 'Timeline' for change history
|
|
||||||
// Retrieved 2026-02-08, License - CC BY-SA 3.0
|
|
||||||
|
|
||||||
package org.openautonomousconnection.oacswing.border;
|
package org.openautonomousconnection.oacswing.border;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import javax.swing.border.AbstractBorder;
|
import javax.swing.border.AbstractBorder;
|
||||||
import javax.swing.border.Border;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
@Getter
|
/**
|
||||||
public class RoundedBorder extends AbstractBorder {
|
* A rounded border that does NOT affect layout (zero insets).
|
||||||
|
* Use this for root/content panes where layout must not shift.
|
||||||
|
*/
|
||||||
|
public final class RoundedBorder extends AbstractBorder {
|
||||||
|
|
||||||
private int radius;
|
private final int radius;
|
||||||
private Color color;
|
private final int strokeWidth;
|
||||||
|
private final Color color;
|
||||||
|
|
||||||
public RoundedBorder(int radius, Color color) {
|
/**
|
||||||
|
* Creates an overlay rounded border.
|
||||||
|
*
|
||||||
|
* @param radius corner radius in pixels (must be >= 0)
|
||||||
|
* @param strokeWidth stroke width in pixels (must be >= 1)
|
||||||
|
* @param color border color (not null)
|
||||||
|
*/
|
||||||
|
public RoundedBorder(int radius, int strokeWidth, Color color) {
|
||||||
|
if (radius < 0) throw new IllegalArgumentException("radius must be >= 0");
|
||||||
|
if (strokeWidth < 1) throw new IllegalArgumentException("strokeWidth must be >= 1");
|
||||||
|
if (color == null) throw new IllegalArgumentException("color must not be null");
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
|
this.strokeWidth = strokeWidth;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Insets getBorderInsets(Component c) {
|
||||||
|
return new Insets(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Insets getBorderInsets(Component c, Insets insets) {
|
public Insets getBorderInsets(Component c, Insets insets) {
|
||||||
insets.left = insets.top = insets.right = insets.bottom = 18;
|
insets.top = 0;
|
||||||
|
insets.left = 0;
|
||||||
|
insets.bottom = 0;
|
||||||
|
insets.right = 0;
|
||||||
return insets;
|
return insets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isBorderOpaque() {
|
public boolean isBorderOpaque() {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||||
|
Graphics2D g2 = (Graphics2D) g.create();
|
||||||
|
try {
|
||||||
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
g2.setColor(color);
|
||||||
|
g2.setStroke(new BasicStroke(strokeWidth));
|
||||||
|
|
||||||
public void paintBorder( Component c, Graphics g, int x, int y,
|
int offset = strokeWidth / 2;
|
||||||
int width, int height) {
|
int w = width - strokeWidth;
|
||||||
int w = width;
|
int h = height - strokeWidth;
|
||||||
int h = height;
|
|
||||||
|
|
||||||
g.translate(x, y);
|
g2.drawRoundRect(
|
||||||
g.setColor( c.getBackground().darker() );
|
x + offset,
|
||||||
g.drawRoundRect( 0, 0, w-2, h-2, 8, 8 );
|
y + offset,
|
||||||
g.translate(-x, -y);
|
w - 1,
|
||||||
|
h - 1,
|
||||||
|
radius * 2,
|
||||||
|
radius * 2
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
g2.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,121 +1,132 @@
|
|||||||
/* Author: Maple
|
|
||||||
* Feb. 2 2026
|
|
||||||
* */
|
|
||||||
|
|
||||||
package org.openautonomousconnection.oacswing.component;
|
package org.openautonomousconnection.oacswing.component;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.openautonomousconnection.oacswing.component.design.Design;
|
|
||||||
import org.openautonomousconnection.oacswing.component.design.OACColor;
|
import org.openautonomousconnection.oacswing.component.design.OACColor;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.plaf.basic.BasicButtonUI;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import java.beans.ConstructorProperties;
|
import java.beans.ConstructorProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rounded Swing button with proper hover, pressed and disabled color handling.
|
||||||
|
*/
|
||||||
public class OACButton extends JButton implements OACPressable {
|
public class OACButton extends JButton implements OACPressable {
|
||||||
@Getter @Setter
|
|
||||||
protected Color pressColor = null;
|
|
||||||
|
|
||||||
protected Color previousColor = null;
|
@Getter @Setter
|
||||||
|
private Color pressedColor;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
|
private Color hoveredColor;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
|
private Color disabledColor;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
|
private int cornerRadius = 10;
|
||||||
|
|
||||||
|
private boolean hovered = false;
|
||||||
|
private boolean pressed = false;
|
||||||
|
|
||||||
public OACButton() {
|
public OACButton() {
|
||||||
super(null, null);
|
super(null, null);
|
||||||
|
|
||||||
this.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OACButton(Icon icon) {
|
public OACButton(Icon icon) {
|
||||||
super(null, icon);
|
super(null, icon);
|
||||||
|
|
||||||
this.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConstructorProperties({"text"})
|
@ConstructorProperties({"text"})
|
||||||
public OACButton(String text) {
|
public OACButton(String text) {
|
||||||
super(text, null);
|
super(text, null);
|
||||||
|
|
||||||
this.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OACButton(Action a) {
|
public OACButton(Action a) {
|
||||||
super(a);
|
super(a);
|
||||||
|
|
||||||
this.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OACButton(String text, Icon icon) {
|
public OACButton(String text, Icon icon) {
|
||||||
super(text, icon);
|
super(text, icon);
|
||||||
|
|
||||||
this.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void init() {
|
|
||||||
this.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mousePressed(MouseEvent e) {
|
|
||||||
previousColor = getBackground();
|
|
||||||
|
|
||||||
if(pressColor != null)
|
|
||||||
setBackground(pressColor);
|
|
||||||
|
|
||||||
super.mousePressed(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void init() {
|
||||||
setBackground(previousColor);
|
Color original = getBackground();
|
||||||
|
|
||||||
super.mouseReleased(e);
|
if (!isEnabled() && getDisabledColor() != null) {
|
||||||
|
setBackground(getDisabledColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseEntered(MouseEvent e) {
|
public void mouseEntered(MouseEvent e) {
|
||||||
//TODO: Hover
|
hovered = true;
|
||||||
|
|
||||||
super.mouseEntered(e);
|
if (!isEnabled() && getDisabledColor() != null) {
|
||||||
|
setBackground(getDisabledColor());
|
||||||
|
} else setBackground(getHoveredColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent e) {
|
public void mouseExited(MouseEvent e) {
|
||||||
//TODO: Hover
|
hovered = false;
|
||||||
|
pressed = false;
|
||||||
super.mouseExited(e);
|
if (!isEnabled() && getDisabledColor() != null) {
|
||||||
|
setBackground(getDisabledColor());
|
||||||
|
} else setBackground(original);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
pressed = true;
|
||||||
|
if (!isEnabled() && getDisabledColor() != null) {
|
||||||
|
setBackground(getDisabledColor());
|
||||||
|
} else setBackground(getPressedColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
pressed = false;
|
||||||
|
if (!isEnabled() && getDisabledColor() != null) {
|
||||||
|
setBackground(getDisabledColor());
|
||||||
|
} else setBackground(original);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component add(Component comp) {
|
public Component add(Component comp) {
|
||||||
this.initOther(comp);
|
initOther(comp);
|
||||||
return super.add(comp);
|
return super.add(comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component add(Component comp, int index) {
|
public Component add(Component comp, int index) {
|
||||||
this.initOther(comp);
|
initOther(comp);
|
||||||
return super.add(comp, index);
|
return super.add(comp, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(@NonNull Component comp, Object constraints) {
|
public void add(@NonNull Component comp, Object constraints) {
|
||||||
this.initOther(comp);
|
initOther(comp);
|
||||||
super.add(comp, constraints);
|
super.add(comp, constraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component add(String name, Component comp) {
|
public Component add(String name, Component comp) {
|
||||||
this.initOther(comp);
|
initOther(comp);
|
||||||
return super.add(name, comp);
|
return super.add(name, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Component comp, Object constraints, int index) {
|
public void add(Component comp, Object constraints, int index) {
|
||||||
this.initOther(comp);
|
initOther(comp);
|
||||||
super.add(comp, constraints, index);
|
super.add(comp, constraints, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ public interface OACComponent {
|
|||||||
// this.setBackground(design.getElements().get(this.getClass()).getColor());
|
// this.setBackground(design.getElements().get(this.getClass()).getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBackground(Color color);
|
default void init() {}
|
||||||
|
|
||||||
default void initOther(Component comp) {
|
default void initOther(Component comp) {
|
||||||
if(comp instanceof OACComponent component)
|
if(comp instanceof OACComponent component)
|
||||||
|
|||||||
@@ -6,7 +6,12 @@ import java.awt.*;
|
|||||||
|
|
||||||
public interface OACPressable extends OACComponent {
|
public interface OACPressable extends OACComponent {
|
||||||
|
|
||||||
Color getPressColor();
|
Color getPressedColor();
|
||||||
|
void setPressedColor(Color color);
|
||||||
|
|
||||||
void setPressColor(Color color);
|
Color getHoveredColor();
|
||||||
|
void setHoveredColor(Color color);
|
||||||
|
|
||||||
|
Color getDisabledColor();
|
||||||
|
void setDisabledColor(Color color);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
package org.openautonomousconnection.oacswing.component.design;
|
package org.openautonomousconnection.oacswing.component.design;
|
||||||
|
|
||||||
public record DesignFlags(OACColor background, OACColor foreground, OACColor pressed, OACColor hovered, boolean hasBorder) {
|
public record DesignFlags(OACColor background, OACColor foreground, OACColor pressed, OACColor hovered, OACColor disabled, boolean hasBorder) {
|
||||||
public DesignFlags(OACColor background) {
|
public DesignFlags(OACColor background) {
|
||||||
this(background, null, null, null, false);
|
this(background, null, null, null, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DesignFlags(OACColor background, OACColor foreground) {
|
public DesignFlags(OACColor background, OACColor foreground) {
|
||||||
this(background, foreground, null, null, false);
|
this(background, foreground, null, null, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DesignFlags(OACColor background, boolean hasBorder) {
|
public DesignFlags(OACColor background, boolean hasBorder) {
|
||||||
this(background, null, null, null, hasBorder);
|
this(background, null, null, null, null, hasBorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DesignFlags(OACColor background, OACColor foreground, boolean hasBorder) {
|
public DesignFlags(OACColor background, OACColor foreground, boolean hasBorder) {
|
||||||
this(background, foreground, null, null, hasBorder);
|
this(background, foreground, null, null, null, hasBorder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public class DesignManager {
|
|||||||
|
|
||||||
OACColor hovered = designFlags.hovered();
|
OACColor hovered = designFlags.hovered();
|
||||||
OACColor pressed = designFlags.pressed();
|
OACColor pressed = designFlags.pressed();
|
||||||
|
OACColor disabled = designFlags.disabled();
|
||||||
|
|
||||||
boolean hasBorder = designFlags.hasBorder();
|
boolean hasBorder = designFlags.hasBorder();
|
||||||
|
|
||||||
@@ -57,21 +58,24 @@ public class DesignManager {
|
|||||||
if(backgroundColour == null)
|
if(backgroundColour == null)
|
||||||
throw new NullPointerException("Background color cannot be null; please exclude the component from your design instead");
|
throw new NullPointerException("Background color cannot be null; please exclude the component from your design instead");
|
||||||
|
|
||||||
component.setBackground(backgroundColour.getColor());
|
|
||||||
|
|
||||||
if (component instanceof OACPressable pressable) {
|
if (component instanceof OACPressable pressable) {
|
||||||
// TODO: if(hovered != null)
|
if (hovered != null) pressable.setHoveredColor(hovered.getColor());
|
||||||
|
if (pressed != null) pressable.setPressedColor(pressed.getColor());
|
||||||
if(pressed != null)
|
if (disabled != null) pressable.setDisabledColor(disabled.getColor());
|
||||||
pressable.setPressColor(pressed.getColor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component instanceof JComponent jComponent) {
|
if (component instanceof JComponent jComponent) {
|
||||||
if(foregroundColour != null)
|
jComponent.setBackground(backgroundColour.getColor());
|
||||||
jComponent.setForeground(foregroundColour.getColor());
|
|
||||||
|
|
||||||
if (hasBorder)
|
if (foregroundColour != null) {
|
||||||
jComponent.setBorder(BorderFactory.createCompoundBorder(border, jComponent.getBorder()));
|
jComponent.setForeground(foregroundColour.getColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasBorder) {
|
||||||
|
jComponent.setBorder(new RoundedBorder(12, 1, OACColor.DARK_BORDERS.getColor()));
|
||||||
|
}
|
||||||
|
|
||||||
|
component.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +115,7 @@ public class DesignManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Design.DARK.getElements().put(OACButton.class, new DesignFlags(OACColor.DARK_BUTTON, OACColor.DARK_TEXT, OACColor.DARK_BUTTON_HOVER, OACColor.DARK_BUTTON_HOVER, true));
|
Design.DARK.getElements().put(OACButton.class, new DesignFlags(OACColor.DARK_BUTTON, OACColor.DARK_TEXT, OACColor.DARK_BUTTON_HOVER, OACColor.DARK_BUTTON_HOVER, OACColor.DARK_INACTIVE_BUTTON, true));
|
||||||
Design.DARK.getElements().put(OACCheckBox.class, new DesignFlags(OACColor.DARK_INPUT_FIELD));
|
Design.DARK.getElements().put(OACCheckBox.class, new DesignFlags(OACColor.DARK_INPUT_FIELD));
|
||||||
Design.DARK.getElements().put(OACCheckBoxMenuItem.class, new DesignFlags(OACColor.DARK_ITEM));
|
Design.DARK.getElements().put(OACCheckBoxMenuItem.class, new DesignFlags(OACColor.DARK_ITEM));
|
||||||
Design.DARK.getElements().put(OACColorChooser.class, new DesignFlags(OACColor.DARK_SECTION));
|
Design.DARK.getElements().put(OACColorChooser.class, new DesignFlags(OACColor.DARK_SECTION));
|
||||||
@@ -131,7 +135,7 @@ public class DesignManager {
|
|||||||
Design.DARK.getElements().put(OACRadioButton.class, new DesignFlags(OACColor.DARK_BUTTON));
|
Design.DARK.getElements().put(OACRadioButton.class, new DesignFlags(OACColor.DARK_BUTTON));
|
||||||
Design.DARK.getElements().put(OACTitleBar.class, new DesignFlags(OACColor.DARK_SECTION));
|
Design.DARK.getElements().put(OACTitleBar.class, new DesignFlags(OACColor.DARK_SECTION));
|
||||||
|
|
||||||
Design.DARK.border = new RoundedBorder(10, OACColor.DARK_BORDERS.getColor());
|
Design.DARK.border = new RoundedBorder(10, 1, OACColor.DARK_BORDERS.getColor());
|
||||||
|
|
||||||
//Design.DARK.border = new BevelBorder(BevelBorder.LOWERED, OACColor.DARK_BORDERS.getColor(), OACColor.DARK_SHADOW.getColor());
|
//Design.DARK.border = new BevelBorder(BevelBorder.LOWERED, OACColor.DARK_BORDERS.getColor(), OACColor.DARK_SHADOW.getColor());
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ public enum OACColor {
|
|||||||
DARK_INPUT_BUTTON_HOVER(Color.decode("#1c2140")),
|
DARK_INPUT_BUTTON_HOVER(Color.decode("#1c2140")),
|
||||||
DARK_ITEM(Color.decode("#d7dbe5")),
|
DARK_ITEM(Color.decode("#d7dbe5")),
|
||||||
DARK_BORDERS(Color.decode("#2a2f42")),
|
DARK_BORDERS(Color.decode("#2a2f42")),
|
||||||
DARK_BUTTON(Color.decode("#3b5bdb")),
|
DARK_BUTTON_HOVER(Color.decode("#3b5bdb")),
|
||||||
DARK_INACTIVE_BUTTON(Color.decode("#151a2b")),
|
DARK_INACTIVE_BUTTON(Color.decode("#151a2b")),
|
||||||
DARK_BUTTON_HOVER(Color.decode("#151a2b")),
|
DARK_BUTTON(Color.decode("#151a2b")),
|
||||||
DARK_TEXT(Color.decode("#cfd3dc")),
|
DARK_TEXT(Color.decode("#cfd3dc")),
|
||||||
DARK_SUBTITLE(Color.decode("#9aa0aa")),
|
DARK_SUBTITLE(Color.decode("#9aa0aa")),
|
||||||
DARK_LINK(Color.decode("#b4c6ff")),
|
DARK_LINK(Color.decode("#b4c6ff")),
|
||||||
|
|||||||
Reference in New Issue
Block a user