Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DJ-Raven committed Dec 3, 2023
2 parents 49c15b2 + b7c1215 commit 9801b44
Show file tree
Hide file tree
Showing 17 changed files with 290 additions and 53 deletions.
23 changes: 1 addition & 22 deletions src/main/java/raven/drawer/component/DrawerPanel.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package raven.drawer.component;

import com.formdev.flatlaf.FlatClientProperties;
import net.miginfocom.swing.MigLayout;
import raven.popup.component.GlassPaneChild;

import javax.swing.*;
import java.awt.*;

public class DrawerPanel extends GlassPaneChild {

private final DrawerBuilder drawerBuilder;
Expand All @@ -28,7 +24,7 @@ private void init() {
}
if (drawerBuilder.getMenu() != null) {
layoutRow += "[fill]";
add(createScroll(drawerBuilder.getMenu()));
add(drawerBuilder.getMenu());
}
if (drawerBuilder.getFooter() != null) {
layoutRow += "[grow 0]";
Expand All @@ -37,23 +33,6 @@ private void init() {
setLayout(new MigLayout("wrap,insets 0,fill", "fill", layoutRow));
}

protected JScrollPane createScroll(Component component) {
JScrollPane scroll = new JScrollPane(component);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll.putClientProperty(FlatClientProperties.STYLE, "" +
"background:null");
scroll.getVerticalScrollBar().setUnitIncrement(10);
scroll.getHorizontalScrollBar().setUnitIncrement(10);
scroll.getVerticalScrollBar().putClientProperty(FlatClientProperties.STYLE, "" +
"width:9;" +
"trackArc:999;" +
"thumbInsets:0,3,0,3;" +
"trackInsets:0,3,0,3;" +
"background:null");
scroll.setBorder(BorderFactory.createEmptyBorder());
return scroll;
}

public DrawerBuilder getDrawerBuilder() {
return drawerBuilder;
}
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/raven/drawer/component/SimpleDrawerBuilder.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package raven.drawer.component;

import com.formdev.flatlaf.FlatClientProperties;
import raven.drawer.component.footer.SimpleFooter;
import raven.drawer.component.footer.SimpleFooterData;
import raven.drawer.component.header.SimpleHeader;
import raven.drawer.component.header.SimpleHeaderData;
import raven.drawer.component.menu.SimpleMenu;
import raven.drawer.component.menu.SimpleMenuOption;
import raven.utils.FlatLafStyleUtils;

import javax.swing.*;
import java.awt.*;
Expand All @@ -14,17 +16,42 @@ public abstract class SimpleDrawerBuilder implements DrawerBuilder {

protected SimpleHeader header;
protected JSeparator headerSeparator;
protected JScrollPane menuScroll;
protected SimpleMenu menu;
protected SimpleFooter footer;


public SimpleDrawerBuilder() {
header = new SimpleHeader(getSimpleHeaderData());
headerSeparator = new JSeparator();
menu = new SimpleMenu(getSimpleMenuOption());
SimpleMenuOption simpleMenuOption = getSimpleMenuOption();
menu = new SimpleMenu(simpleMenuOption);
menuScroll = createScroll(menu);
footer = new SimpleFooter(getSimpleFooterData());
}

protected JScrollPane createScroll(JComponent component) {
JScrollPane scroll = new JScrollPane(component);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
String background = FlatLafStyleUtils.getStyleValue(component, "background", "null");
scroll.putClientProperty(FlatClientProperties.STYLE, "" +
"background:" + background);
scroll.getVerticalScrollBar().setUnitIncrement(10);
scroll.getHorizontalScrollBar().setUnitIncrement(10);
scroll.getVerticalScrollBar().putClientProperty(FlatClientProperties.STYLE, "" +
"width:9;" +
"trackArc:999;" +
"thumbInsets:0,3,0,3;" +
"trackInsets:0,3,0,3;" +
"background:" + background);
if (!background.equals("null")) {
FlatLafStyleUtils.appendStyleIfAbsent(scroll.getVerticalScrollBar(), "" +
"track:" + background);
}
scroll.setBorder(BorderFactory.createEmptyBorder());
return scroll;
}

@Override
public Component getHeader() {
return header;
Expand All @@ -37,7 +64,7 @@ public Component getHeaderSeparator() {

@Override
public Component getMenu() {
return menu;
return menuScroll;
}

@Override
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/raven/drawer/component/footer/SimpleFooter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package raven.drawer.component.footer;

import com.formdev.flatlaf.FlatClientProperties;
import net.miginfocom.swing.MigLayout;
import raven.utils.FlatLafStyleUtils;

import javax.swing.*;

Expand All @@ -16,14 +16,22 @@ public SimpleFooter(SimpleFooterData simpleFooterData) {

private void init() {
setLayout(new MigLayout("wrap,insets 5 20 10 20,fill,gap 3"));
putClientProperty(FlatClientProperties.STYLE, "" +
"background:null");
labelTitle = new JLabel(simpleFooterData.title);
labelDescription = new JLabel(simpleFooterData.description);
labelDescription.putClientProperty(FlatClientProperties.STYLE, "" +

if (simpleFooterData.simpleFooterStyle != null) {
simpleFooterData.simpleFooterStyle.styleFooter(this);
simpleFooterData.simpleFooterStyle.styleTitle(labelTitle);
simpleFooterData.simpleFooterStyle.styleDescription(labelDescription);
}

FlatLafStyleUtils.appendStyleIfAbsent(this, "" +
"background:null");
FlatLafStyleUtils.appendStyleIfAbsent(labelDescription, "" +
"font:-1;" +
"[light]foreground:lighten(@foreground,30%);" +
"[dark]foreground:darken(@foreground,30%)");

add(labelTitle);
add(labelDescription);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class SimpleFooterData {

protected String title;
protected String description;
protected SimpleFooterStyle simpleFooterStyle;

public SimpleFooterData setTitle(String title) {
this.title = title;
Expand All @@ -14,4 +15,9 @@ public SimpleFooterData setDescription(String description) {
this.description = description;
return this;
}

public SimpleFooterData setFooterStyle(SimpleFooterStyle simpleFooterStyle) {
this.simpleFooterStyle = simpleFooterStyle;
return this;
}
}
15 changes: 15 additions & 0 deletions src/main/java/raven/drawer/component/footer/SimpleFooterStyle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package raven.drawer.component.footer;

import javax.swing.*;

public abstract class SimpleFooterStyle {

public void styleFooter(JComponent component) {
}

public void styleTitle(JLabel label) {
}

public void styleDescription(JLabel label) {
}
}
19 changes: 13 additions & 6 deletions src/main/java/raven/drawer/component/header/SimpleHeader.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package raven.drawer.component.header;

import com.formdev.flatlaf.FlatClientProperties;
import net.miginfocom.swing.MigLayout;
import raven.utils.FlatLafStyleUtils;

import javax.swing.*;

Expand All @@ -16,14 +16,21 @@ public SimpleHeader(SimpleHeaderData simpleHeaderData) {

private void init() {
setLayout(new MigLayout("wrap,insets 10 20 5 20,fill,gap 3"));
putClientProperty(FlatClientProperties.STYLE, "" +
"background:null");
profile = new JLabel(simpleHeaderData.icon);
profile.putClientProperty(FlatClientProperties.STYLE, "" +
"background:$Component.borderColor");
labelTitle = new JLabel(simpleHeaderData.title);
labelDescription = new JLabel(simpleHeaderData.description);
labelDescription.putClientProperty(FlatClientProperties.STYLE, "" +

if (simpleHeaderData.simpleHeaderStyle != null) {
simpleHeaderData.simpleHeaderStyle.styleHeader(this);
simpleHeaderData.simpleHeaderStyle.styleProfile(profile);
simpleHeaderData.simpleHeaderStyle.styleTitle(labelTitle);
simpleHeaderData.simpleHeaderStyle.styleDescription(labelDescription);
}
FlatLafStyleUtils.appendStyleIfAbsent(this, "" +
"background:null");
FlatLafStyleUtils.appendStyleIfAbsent(profile, "" +
"background:$Component.borderColor");
FlatLafStyleUtils.appendStyleIfAbsent(labelDescription, "" +
"font:-1;" +
"[light]foreground:lighten(@foreground,30%);" +
"[dark]foreground:darken(@foreground,30%)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class SimpleHeaderData {
protected String title;
protected String description;

protected SimpleHeaderStyle simpleHeaderStyle;

public SimpleHeaderData setIcon(Icon icon) {
this.icon = icon;
return this;
Expand All @@ -22,4 +24,9 @@ public SimpleHeaderData setDescription(String description) {
this.description = description;
return this;
}

public SimpleHeaderData setHeaderStyle(SimpleHeaderStyle simpleHeaderStyle) {
this.simpleHeaderStyle = simpleHeaderStyle;
return this;
}
}
18 changes: 18 additions & 0 deletions src/main/java/raven/drawer/component/header/SimpleHeaderStyle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package raven.drawer.component.header;

import javax.swing.*;

public abstract class SimpleHeaderStyle {

public void styleHeader(JComponent component) {
}

public void styleProfile(JLabel label) {
}

public void styleTitle(JLabel label) {
}

public void styleDescription(JLabel label) {
}
}
31 changes: 24 additions & 7 deletions src/main/java/raven/drawer/component/menu/SimpleMenu.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package raven.drawer.component.menu;

import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.ColorFunctions;
import com.formdev.flatlaf.util.UIScale;
import raven.utils.FlatLafStyleUtils;

import javax.swing.*;
import java.awt.*;
Expand All @@ -26,6 +26,9 @@ public void rebuildMenu() {

private void init() {
setLayout(new MenuLayout());
if (simpleMenuOption.simpleMenuStyle != null) {
simpleMenuOption.simpleMenuStyle.styleMenu(this);
}
buildMenu();
}

Expand Down Expand Up @@ -83,14 +86,17 @@ protected JButton createMenuItem(String name, int index) {
}
}
button.setHorizontalAlignment(JButton.LEADING);
button.putClientProperty(FlatClientProperties.STYLE, "" +
if (simpleMenuOption.simpleMenuStyle != null) {
simpleMenuOption.simpleMenuStyle.styleMenuItem(button, index);
}
FlatLafStyleUtils.appendStyleIfAbsent(button, "" +
"arc:0;" +
"margin:6,20,6,20;" +
"borderWidth:0;" +
"focusWidth:0;" +
"innerFocusWidth:0;" +
"background:null;" +
"iconTextGap:5");
"iconTextGap:5;");
return button;
}

Expand Down Expand Up @@ -158,7 +164,10 @@ protected boolean checkLabelValidation(int labelIndex, int menuIndex) {

protected Component createLabel(String name) {
JLabel label = new JLabel(name);
label.putClientProperty(FlatClientProperties.STYLE, "" +
if (simpleMenuOption.simpleMenuStyle != null) {
simpleMenuOption.simpleMenuStyle.styleLabel(label);
}
FlatLafStyleUtils.appendStyleIfAbsent(label, "" +
"border:8,10,8,10;" +
"[light]foreground:lighten($Label.foreground,30%);" +
"[dark]foreground:darken($Label.foreground,30%)");
Expand Down Expand Up @@ -231,8 +240,15 @@ private void createMainMenuEvent(JButton button) {
protected JButton createSubMenuItem(String name, int index, int gap) {
JButton button = new JButton(name);
button.setHorizontalAlignment(JButton.LEADING);
button.putClientProperty(FlatClientProperties.STYLE, "" +
"border:7," + (gap + 25) + ",7,20;" +
if (simpleMenuOption.simpleMenuStyle != null) {
simpleMenuOption.simpleMenuStyle.styleSubMenuItem(button, this.index, index);
}
FlatLafStyleUtils.appendStyleIfAbsent(button, "" +
"arc:0;" +
"margin:7," + (gap + 25) + ",7," + (gap + 25) + ";" +
"borderWidth:0;" +
"focusWidth:0;" +
"innerFocusWidth:0;" +
"background:null");
return button;
}
Expand All @@ -242,6 +258,7 @@ protected void paintChildren(Graphics g) {
super.paintChildren(g);
if (getComponentCount() > 0) {
boolean ltr = getComponentOrientation().isLeftToRight();
Color foreground = getComponent(0).getForeground();
int menuHeight = getComponent(0).getHeight();
int width = getWidth();
int height = getHeight();
Expand All @@ -261,7 +278,7 @@ protected void paintChildren(Graphics g) {
int y = com.getY() + (com.getHeight() / 2);
p.append(createCurve(round, x, y, ltr), false);
}
Color color = FlatLaf.isLafDark() ? ColorFunctions.darken(getForeground(), 0.6f) : ColorFunctions.lighten(getForeground(), 0.6f);
Color color = ColorFunctions.mix(getBackground(), foreground, 0.7f);
g2.setColor(color);
g2.setStroke(new BasicStroke(UIScale.scale(1f)));
g2.draw(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class SimpleMenuOption {

protected List<MenuEvent> events = new ArrayList<>();
protected MenuValidation menuValidation = new MenuValidation();
protected SimpleMenuStyle simpleMenuStyle;
protected String menus[][];
protected String icons[];
protected float iconScale = 1f;
Expand Down Expand Up @@ -46,6 +47,11 @@ public SimpleMenuOption setMenuValidation(MenuValidation menuValidation) {
return this;
}

public SimpleMenuOption setMenuStyle(SimpleMenuStyle simpleMenuStyle) {
this.simpleMenuStyle = simpleMenuStyle;
return this;
}

public SimpleMenuOption addMenuEvent(MenuEvent event) {
events.add(event);
return this;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/raven/drawer/component/menu/SimpleMenuStyle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package raven.drawer.component.menu;

import javax.swing.*;

public abstract class SimpleMenuStyle {

public void styleMenu(JComponent component) {
}

public void styleMenuItem(JButton menu, int index) {
}

public void styleSubMenuItem(JButton subMenu, int index, int subIndex) {
}

public void styleLabel(JLabel label) {
}
}
Loading

0 comments on commit 9801b44

Please sign in to comment.