Skip to content

Commit

Permalink
Merge pull request #3 from DJ-Raven/fix-push-popup
Browse files Browse the repository at this point in the history
Drawer support dynamic submenu
  • Loading branch information
DJ-Raven committed Jan 7, 2024
2 parents 2d08f97 + 0ecaa43 commit 20679e9
Show file tree
Hide file tree
Showing 20 changed files with 485 additions and 234 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>raven.popup</groupId>
<artifactId>swing-glasspane-popup</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public int getDrawerWidth() {
}

public void build(DrawerPanel drawerPanel) {

}

public void rebuildMenu() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/raven/drawer/component/menu/MenuEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface MenuEvent {

public void selected(MenuAction action, int index, int subIndex);
public void selected(MenuAction action, int[] index);
}
5 changes: 1 addition & 4 deletions src/main/java/raven/drawer/component/menu/MenuLayout.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package raven.drawer.component.menu;

import com.formdev.flatlaf.util.UIScale;
import raven.drawer.DrawerOption;

import java.awt.*;

public class MenuLayout implements LayoutManager {
Expand All @@ -19,7 +16,7 @@ public void removeLayoutComponent(Component comp) {
public Dimension preferredLayoutSize(Container parent) {
synchronized (parent.getTreeLock()) {
Insets insets = parent.getInsets();
// use parent width to avoid the issues right-to-left scroll pane
// Use parent width to avoid the issues right-to-left scroll pane
int width = parent.getParent().getWidth();
int height = insets.top + insets.bottom;
int count = parent.getComponentCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public MenuValidation(boolean keepMenuValidationIndex, boolean removeLabelWhenEm
this.removeLabelWhenEmptyMenu = removeLabelWhenEmptyMenu;
}

public boolean menuValidation(int index, int subIndex) {
public boolean menuValidation(int[] index) {
return true;
}

Expand Down
201 changes: 136 additions & 65 deletions src/main/java/raven/drawer/component/menu/SimpleMenu.java

Large diffs are not rendered by default.

16 changes: 6 additions & 10 deletions src/main/java/raven/drawer/component/menu/SimpleMenuOption.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package raven.drawer.component.menu;

import com.formdev.flatlaf.extras.FlatSVGIcon;
import raven.drawer.component.menu.data.MenuItem;

import javax.swing.*;
import java.util.ArrayList;
Expand All @@ -11,23 +12,18 @@ 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;
protected MenuItem menus[];
protected float iconScale[] = {1f};

protected String baseIconPath;
protected boolean menuItemAutoSelect = true;

public SimpleMenuOption setMenus(String menus[][]) {
public SimpleMenuOption setMenus(MenuItem menus[]) {
this.menus = menus;
return this;
}

public SimpleMenuOption setIcons(String icons[]) {
this.icons = icons;
return this;
}

public SimpleMenuOption setIconScale(float iconScale) {
public SimpleMenuOption setIconScale(float... iconScale) {
this.iconScale = iconScale;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ 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 styleMenuItem(JButton menu, int[] index) {
}

public void styleLabel(JLabel label) {
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/raven/drawer/component/menu/data/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package raven.drawer.component.menu.data;

import java.util.ArrayList;
import java.util.List;

public class Item implements MenuItem {

public String getName() {
return name;
}

public String getIcon() {
return icon;
}

public List<Item> getSubMenu() {
return subMenu;
}

private final String name;
private String icon;
private List<Item> subMenu;

public Item(String name) {
this.name = name;
}

public Item(String name, String icon) {
this.name = name;
this.icon = icon;
}

public Item subMenu(Item item) {
addSubMenu(item);
return this;
}

public Item subMenu(String name) {
addSubMenu(new Item(name));
return this;
}

private void addSubMenu(Item item) {
if (subMenu == null) {
subMenu = new ArrayList<>();
}
subMenu.add(item);
}

public boolean isSubmenuAble() {
return subMenu != null;
}

@Override
public boolean isMenu() {
return true;
}

public static class Label implements MenuItem {

public String getName() {
return name;
}

private String name;

public Label(String name) {
this.name = name;
}

@Override
public boolean isMenu() {
return false;
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/raven/drawer/component/menu/data/MenuItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package raven.drawer.component.menu.data;

public interface MenuItem {

boolean isMenu();
}
3 changes: 2 additions & 1 deletion src/main/java/raven/popup/DefaultOption.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package raven.popup;

import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.util.UIScale;

import java.awt.*;

Expand Down Expand Up @@ -37,7 +38,7 @@ public boolean blockBackground() {

@Override
public Color background() {
return FlatLaf.isLafDark()?new Color(50, 50, 50):new Color(20, 20, 20);
return FlatLaf.isLafDark() ? new Color(50, 50, 50) : new Color(20, 20, 20);
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/raven/popup/GlassPanePopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class GlassPanePopup {

private static GlassPanePopup instance;
private JFrame mainFrame;
protected WindowSnapshots windowSnapshots;
protected JLayeredPane layerPane;
protected Container contentPane;
Expand Down Expand Up @@ -50,6 +51,7 @@ private void updateLayout() {

public static void install(JFrame frame) {
instance = new GlassPanePopup();
instance.mainFrame = frame;
instance.windowSnapshots = new WindowSnapshots(frame);
instance.contentPane = frame.getContentPane();
frame.setGlassPane(instance.layerPane);
Expand Down Expand Up @@ -197,6 +199,14 @@ public static int getPopupCount() {
return instance.layerPane.getComponentCount();
}

public static JFrame getMainFrame() {
return instance.mainFrame;
}

public static boolean isInit() {
return !(instance == null || instance.mainFrame == null);
}

protected synchronized void removePopup(Component popup) {
layerPane.remove(popup);
if (layerPane.getComponentCount() == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/raven/popup/GlassPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void end() {
}
}
});
animator.setInterpolator(CubicBezierEasing.EASE_IN_OUT);
animator.setInterpolator(CubicBezierEasing.EASE);
}

public void setShowPopup(boolean show) {
Expand Down
Loading

0 comments on commit 20679e9

Please sign in to comment.