From 3b402dc50d2433d98fd8d555b62a71e8c1600d4e Mon Sep 17 00:00:00 2001 From: raven Date: Tue, 14 Nov 2023 18:53:31 +0700 Subject: [PATCH 01/13] add alerts --- .idea/workspace.xml | 47 ++++--- .../java/raven/alerts/ShapeGenerator.java | 41 ++++++ src/main/java/raven/alerts/SimpleAlerts.java | 127 ++++++++++++++++++ src/test/java/test/DemoAlerts.java | 36 +++++ 4 files changed, 235 insertions(+), 16 deletions(-) create mode 100644 src/main/java/raven/alerts/ShapeGenerator.java create mode 100644 src/main/java/raven/alerts/SimpleAlerts.java create mode 100644 src/test/java/test/DemoAlerts.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 67b7b31..251d3d4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,8 +6,6 @@ - - - { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "WebServerToolWindowFactoryState": "false", + "jdk.selected.JAVA_MODULE": "1.8", + "last_opened_file_path": "D:/Raven/youtube/glasspane popup/swing glasspane popup/swing-glasspane-popup/src/test/resources/image", + "project.structure.last.edited": "Modules", + "project.structure.proportion": "0.15", + "project.structure.side.proportion": "0.3586207", + "settings.editor.selected.configurable": "MavenSettings" } -}]]> +} + + + - + + + + diff --git a/src/main/java/raven/alerts/ShapeGenerator.java b/src/main/java/raven/alerts/ShapeGenerator.java new file mode 100644 index 0000000..8c72686 --- /dev/null +++ b/src/main/java/raven/alerts/ShapeGenerator.java @@ -0,0 +1,41 @@ +package raven.alerts; + +import java.awt.*; +import java.awt.geom.Ellipse2D; + +public class ShapeGenerator { + + protected static Shape randomShape(int v) { + int width = 10; + int height = 10; + switch (v) { + case 0: + return createRandomCircle(width, height); + case 1: + return createRandomRectangle(width, height); + default: + return createRandomPolygon(width, height); + } + } + + private static Shape createRandomCircle(int width, int height) { + int diameter = Math.min(width, height); + int x = (width - diameter) / 2; + int y = (height - diameter) / 2; + return new Ellipse2D.Double(x, y, diameter, diameter); + } + + private static Shape createRandomRectangle(int width, int height) { + int rectWidth = width / 2; + int rectHeight = height / 2; + int x = (width - rectWidth) / 2; + int y = (height - rectHeight) / 2; + return new Rectangle(x, y, rectWidth, rectHeight); + } + + private static Shape createRandomPolygon(int width, int height) { + int[] xPoints = {width / 4, width / 2, (3 * width) / 4}; + int[] yPoints = {height / 4, (3 * height) / 4, height / 2}; + return new Polygon(xPoints, yPoints, 3); + } +} \ No newline at end of file diff --git a/src/main/java/raven/alerts/SimpleAlerts.java b/src/main/java/raven/alerts/SimpleAlerts.java new file mode 100644 index 0000000..1aab77c --- /dev/null +++ b/src/main/java/raven/alerts/SimpleAlerts.java @@ -0,0 +1,127 @@ +package raven.alerts; + +import com.formdev.flatlaf.ui.FlatUIUtils; +import com.formdev.flatlaf.util.Animator; +import com.formdev.flatlaf.util.CubicBezierEasing; +import com.formdev.flatlaf.util.UIScale; +import net.miginfocom.swing.MigLayout; +import raven.popup.component.GlassPaneChild; + +import javax.swing.*; +import java.awt.*; +import java.awt.geom.AffineTransform; +import java.util.Random; + +public class SimpleAlerts extends GlassPaneChild { + + public SimpleAlerts() { + init(); + } + + private void init() { + setLayout(new MigLayout("wrap,fillx,insets 15 0 15 0", "[fill,400]")); + add(new PanelEffect()); + } + + @Override + public int getRoundBorder() { + return 20; + } + + protected class PanelEffect extends JPanel { + + private Effect effects[]; + private float animate; + private Animator animator; + + protected void start() { + if (animator == null) { + animator = new Animator(2000, new Animator.TimingTarget() { + @Override + public void timingEvent(float v) { + animate = v; + repaint(); + } + }); + animator.setInterpolator(CubicBezierEasing.EASE); + } + if (animator.isRunning()) { + animator.stop(); + } + animator.start(); + } + + private void createEffect() { + effects = new Effect[30]; + for (int i = 0; i < effects.length; i++) { + effects[i] = new Effect(); + } + start(); + } + + + public PanelEffect() { + setLayout(new MigLayout("height 300")); + JButton cmd = new JButton("Test"); + cmd.addActionListener(e -> { + createEffect(); + }); + add(cmd); + } + + @Override + protected void paintChildren(Graphics g) { + if (effects != null && effects.length > 0) { + Graphics2D g2 = (Graphics2D) g.create(); + float s = UIScale.getUserScaleFactor(); + + FlatUIUtils.setRenderingHints(g2); + int width = getWidth(); + int height = getHeight(); + int x = width / 2; + int y = height / 2; + float size = Math.min(width, height) / 2; + + float l = size * animate; + float remove = 0.7f; + g2.translate(x, y); g2.scale(s, s); + for (int i = 0; i < effects.length; i++) { + Effect effect = effects[i]; + double sp = effect.speed * 0.05f; + double xx = Math.cos(Math.toRadians(effect.direction)) * l * sp; + double yy = Math.sin(Math.toRadians(effect.direction)) * l * sp; + AffineTransform oldTran = g2.getTransform(); + g2.translate(xx, yy); + g2.rotate(Math.toRadians(animate * 360), 5, 5); + g2.setColor(effect.color); + if (animate >= remove) { + float f = (animate - remove) / (1f - remove); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f - f)); + } + g2.fill(effect.shape); + g2.setTransform(oldTran); + } + g2.dispose(); + } + super.paintChildren(g); + } + } + + protected class Effect { + + protected Shape shape; + protected Color color; + protected float direction; + protected float speed; + + public Effect() { + Random random = new Random(); + color = effectColors[random.nextInt(effectColors.length)]; + shape = ShapeGenerator.randomShape(random.nextInt(3)); + direction = random.nextInt(360); + speed = random.nextInt(25)+5; + } + } + + protected static final Color effectColors[] = {Color.decode("#8DBF13"), Color.decode("#13BF86"), Color.decode("#134FBF"), Color.decode("#C144D5"), Color.decode("#D58844"), Color.decode("#D54B44")}; +} diff --git a/src/test/java/test/DemoAlerts.java b/src/test/java/test/DemoAlerts.java new file mode 100644 index 0000000..95aa955 --- /dev/null +++ b/src/test/java/test/DemoAlerts.java @@ -0,0 +1,36 @@ +package test; + +import com.formdev.flatlaf.FlatLaf; +import com.formdev.flatlaf.fonts.roboto.FlatRobotoFont; +import com.formdev.flatlaf.themes.FlatMacDarkLaf; +import net.miginfocom.swing.MigLayout; +import raven.alerts.SimpleAlerts; +import raven.drawer.Drawer; +import raven.popup.GlassPanePopup; + +import javax.swing.*; +import java.awt.*; + +public class DemoAlerts extends JFrame { + + public DemoAlerts() { + GlassPanePopup.install(this); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(new Dimension(1366, 768)); + setLocationRelativeTo(null); + setLayout(new MigLayout("")); + JButton cmd = new JButton("Show Drawer"); + cmd.addActionListener(e -> { + GlassPanePopup.showPopup(new SimpleAlerts()); + }); + add(cmd); + } + + public static void main(String[] args) { + FlatRobotoFont.install(); + FlatLaf.registerCustomDefaultsSource("themes"); + UIManager.put("defaultFont", new Font(FlatRobotoFont.FAMILY, Font.PLAIN, 13)); + FlatMacDarkLaf.setup(); + EventQueue.invokeLater(() -> new DemoAlerts().setVisible(true)); + } +} From f94a48ec674a6f6e798cffd36c77b65bb8f763b1 Mon Sep 17 00:00:00 2001 From: raven Date: Tue, 14 Nov 2023 20:36:38 +0700 Subject: [PATCH 02/13] add alerts --- .idea/workspace.xml | 29 ++++--- src/main/java/raven/alerts/SimpleAlerts.java | 87 ++++++++++++++++--- .../resources/raven/alerts/icon/error.svg | 24 +++++ .../resources/raven/alerts/icon/question.svg | 36 ++++++++ .../resources/raven/alerts/icon/success.svg | 23 +++++ src/test/java/test/DemoAlerts.java | 3 +- 6 files changed, 178 insertions(+), 24 deletions(-) create mode 100644 src/main/resources/raven/alerts/icon/error.svg create mode 100644 src/main/resources/raven/alerts/icon/question.svg create mode 100644 src/main/resources/raven/alerts/icon/success.svg diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 251d3d4..fbe7500 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,6 +6,8 @@ + + - { - "keyToString": { - "RunOnceActivity.OpenProjectViewOnStart": "true", - "RunOnceActivity.ShowReadmeOnStart": "true", - "SHARE_PROJECT_CONFIGURATION_FILES": "true", - "WebServerToolWindowFactoryState": "false", - "jdk.selected.JAVA_MODULE": "1.8", - "last_opened_file_path": "D:/Raven/youtube/glasspane popup/swing glasspane popup/swing-glasspane-popup/src/test/resources/image", - "project.structure.last.edited": "Modules", - "project.structure.proportion": "0.15", - "project.structure.side.proportion": "0.3586207", - "settings.editor.selected.configurable": "MavenSettings" + +}]]> + diff --git a/src/main/java/raven/alerts/SimpleAlerts.java b/src/main/java/raven/alerts/SimpleAlerts.java index 1aab77c..86513ef 100644 --- a/src/main/java/raven/alerts/SimpleAlerts.java +++ b/src/main/java/raven/alerts/SimpleAlerts.java @@ -1,13 +1,19 @@ package raven.alerts; +import com.formdev.flatlaf.FlatClientProperties; +import com.formdev.flatlaf.extras.FlatSVGIcon; import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.util.Animator; import com.formdev.flatlaf.util.CubicBezierEasing; import com.formdev.flatlaf.util.UIScale; import net.miginfocom.swing.MigLayout; +import raven.popup.GlassPanePopup; import raven.popup.component.GlassPaneChild; import javax.swing.*; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; import java.awt.*; import java.awt.geom.AffineTransform; import java.util.Random; @@ -20,7 +26,9 @@ public SimpleAlerts() { private void init() { setLayout(new MigLayout("wrap,fillx,insets 15 0 15 0", "[fill,400]")); - add(new PanelEffect()); + String title = "Data Save Successful"; + String message = "Great news! Your data has been securely saved. It's all set and ready for your use whenever you need it. If you have any questions, just let us know!"; + add(new PanelEffect(title, message)); } @Override @@ -34,6 +42,10 @@ protected class PanelEffect extends JPanel { private float animate; private Animator animator; + private JLabel labelIcon; + private JLabel labelTitle; + private JTextPane textPane; + protected void start() { if (animator == null) { animator = new Animator(2000, new Animator.TimingTarget() { @@ -60,13 +72,61 @@ private void createEffect() { } - public PanelEffect() { - setLayout(new MigLayout("height 300")); - JButton cmd = new JButton("Test"); + public PanelEffect(String title, String message) { + setLayout(new MigLayout("fillx,wrap,insets 0,center", "[fill,center]", "[]10[][][]20[]20")); + labelIcon = new JLabel(new FlatSVGIcon("raven/alerts/icon/success.svg", 4f)); + labelTitle = new JLabel(title, JLabel.CENTER); + textPane = new JTextPane(); + textPane.setOpaque(false); + StyledDocument doc = textPane.getStyledDocument(); + SimpleAttributeSet center = new SimpleAttributeSet(); + StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); + doc.setParagraphAttributes(0, doc.getLength(), center, false); + textPane.setEditable(false); + textPane.setText(message); + textPane.putClientProperty(FlatClientProperties.STYLE, "" + + "border:5,25,5,25"); + labelTitle.putClientProperty(FlatClientProperties.STYLE, "" + + "font:bold +5;" + + "foreground:#61BE79"); + JPanel panelTitle = new JPanel(new MigLayout("insets 2 25 2 25,fill")); + panelTitle.setOpaque(false); + panelTitle.add(createCloseButton(), "trailing"); + add(panelTitle); + add(labelIcon); + add(labelTitle); + add(textPane); + createButton(); + } + + protected Component createCloseButton() { + JButton cmdClose = new JButton(new FlatSVGIcon("raven/popup/icon/close.svg", 0.8f)); + cmdClose.putClientProperty(FlatClientProperties.STYLE, "" + + "arc:999;" + + "borderWidth:0;" + + "focusWidth:0;" + + "innerFocusWidth:0;" + + "background:null"); + cmdClose.addActionListener(e -> GlassPanePopup.closePopup(SimpleAlerts.this)); + return cmdClose; + } + + protected void createButton() { + JButton cmd = new JButton("OK"); cmd.addActionListener(e -> { createEffect(); }); - add(cmd); + cmd.putClientProperty(FlatClientProperties.STYLE, "" + + "borderWidth:0;" + + "focusWidth:0;" + + "innerFocusWidth:0;" + + "arc:10;" + + "font:bold +2;" + + "margin:5,50,5,50;" + + "background:#61BE79;" + + "foreground:#F0F0F0;" + + "arc:999"); + add(cmd, "grow 0"); } @Override @@ -78,13 +138,14 @@ protected void paintChildren(Graphics g) { FlatUIUtils.setRenderingHints(g2); int width = getWidth(); int height = getHeight(); - int x = width / 2; - int y = height / 2; + int x = labelIcon.getX() + labelIcon.getWidth() / 2; + int y = labelIcon.getY() + labelIcon.getHeight() / 2; float size = Math.min(width, height) / 2; float l = size * animate; float remove = 0.7f; - g2.translate(x, y); g2.scale(s, s); + g2.translate(x, y); + g2.scale(s, s); for (int i = 0; i < effects.length; i++) { Effect effect = effects[i]; double sp = effect.speed * 0.05f; @@ -119,9 +180,15 @@ public Effect() { color = effectColors[random.nextInt(effectColors.length)]; shape = ShapeGenerator.randomShape(random.nextInt(3)); direction = random.nextInt(360); - speed = random.nextInt(25)+5; + speed = random.nextInt(25) + 5; } } - protected static final Color effectColors[] = {Color.decode("#8DBF13"), Color.decode("#13BF86"), Color.decode("#134FBF"), Color.decode("#C144D5"), Color.decode("#D58844"), Color.decode("#D54B44")}; + protected static final Color effectColors[] = { + Color.decode("#8DBF13"), Color.decode("#13BF86"), + Color.decode("#FF5733"), Color.decode("#E6A801"), + Color.decode("#FFC300"), Color.decode("#FF5733"), + Color.decode("#C70039"), Color.decode("#900C3F"), + Color.decode("#581845"), Color.decode("#4A235A") + }; } diff --git a/src/main/resources/raven/alerts/icon/error.svg b/src/main/resources/raven/alerts/icon/error.svg new file mode 100644 index 0000000..a207467 --- /dev/null +++ b/src/main/resources/raven/alerts/icon/error.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/raven/alerts/icon/question.svg b/src/main/resources/raven/alerts/icon/question.svg new file mode 100644 index 0000000..ba83784 --- /dev/null +++ b/src/main/resources/raven/alerts/icon/question.svg @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/raven/alerts/icon/success.svg b/src/main/resources/raven/alerts/icon/success.svg new file mode 100644 index 0000000..e8946ea --- /dev/null +++ b/src/main/resources/raven/alerts/icon/success.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/test/DemoAlerts.java b/src/test/java/test/DemoAlerts.java index 95aa955..0616a70 100644 --- a/src/test/java/test/DemoAlerts.java +++ b/src/test/java/test/DemoAlerts.java @@ -3,6 +3,7 @@ import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.fonts.roboto.FlatRobotoFont; import com.formdev.flatlaf.themes.FlatMacDarkLaf; +import com.formdev.flatlaf.themes.FlatMacLightLaf; import net.miginfocom.swing.MigLayout; import raven.alerts.SimpleAlerts; import raven.drawer.Drawer; @@ -30,7 +31,7 @@ public static void main(String[] args) { FlatRobotoFont.install(); FlatLaf.registerCustomDefaultsSource("themes"); UIManager.put("defaultFont", new Font(FlatRobotoFont.FAMILY, Font.PLAIN, 13)); - FlatMacDarkLaf.setup(); + FlatMacLightLaf.setup(); EventQueue.invokeLater(() -> new DemoAlerts().setVisible(true)); } } From ef77cd97970f1441bac3a5e7c75ae9a71cbc987d Mon Sep 17 00:00:00 2001 From: laing raven Date: Tue, 14 Nov 2023 22:29:57 +0700 Subject: [PATCH 03/13] update --- .idea/workspace.xml | 5 +- src/main/java/raven/alerts/SimpleAlerts.java | 55 ++++++++++++++------ src/main/java/raven/popup/DefaultOption.java | 4 +- src/test/java/test/DemoAlerts.java | 4 +- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fbe7500..ebe705e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,6 +7,7 @@ + + @@ -139,6 +141,7 @@ + diff --git a/src/main/java/raven/alerts/SimpleAlerts.java b/src/main/java/raven/alerts/SimpleAlerts.java index 86513ef..58c4e30 100644 --- a/src/main/java/raven/alerts/SimpleAlerts.java +++ b/src/main/java/raven/alerts/SimpleAlerts.java @@ -20,15 +20,20 @@ public class SimpleAlerts extends GlassPaneChild { - public SimpleAlerts() { + private final AlertsType type; + private final String title; + private final String message; + + public SimpleAlerts(AlertsType type, String title, String message) { + this.type = type; + this.title = title; + this.message = message; init(); } private void init() { setLayout(new MigLayout("wrap,fillx,insets 15 0 15 0", "[fill,400]")); - String title = "Data Save Successful"; - String message = "Great news! Your data has been securely saved. It's all set and ready for your use whenever you need it. If you have any questions, just let us know!"; - add(new PanelEffect(title, message)); + add(new PanelEffect(type, title, message)); } @Override @@ -72,9 +77,9 @@ private void createEffect() { } - public PanelEffect(String title, String message) { + public PanelEffect(AlertsType type, String title, String message) { setLayout(new MigLayout("fillx,wrap,insets 0,center", "[fill,center]", "[]10[][][]20[]20")); - labelIcon = new JLabel(new FlatSVGIcon("raven/alerts/icon/success.svg", 4f)); + labelIcon = new JLabel(new FlatSVGIcon("raven/alerts/icon/" + type.name + ".svg", 4f)); labelTitle = new JLabel(title, JLabel.CENTER); textPane = new JTextPane(); textPane.setOpaque(false); @@ -85,10 +90,12 @@ public PanelEffect(String title, String message) { textPane.setEditable(false); textPane.setText(message); textPane.putClientProperty(FlatClientProperties.STYLE, "" + - "border:5,25,5,25"); + "border:5,25,5,25;" + + "[light]foreground:lighten(@foreground,30%);" + + "[dark]foreground:darken(@foreground,30%)"); labelTitle.putClientProperty(FlatClientProperties.STYLE, "" + "font:bold +5;" + - "foreground:#61BE79"); + "foreground:" + type.color); JPanel panelTitle = new JPanel(new MigLayout("insets 2 25 2 25,fill")); panelTitle.setOpaque(false); panelTitle.add(createCloseButton(), "trailing"); @@ -121,9 +128,9 @@ protected void createButton() { "focusWidth:0;" + "innerFocusWidth:0;" + "arc:10;" + - "font:bold +2;" + + "font:+1;" + "margin:5,50,5,50;" + - "background:#61BE79;" + + "background:" + type.color + ";" + "foreground:#F0F0F0;" + "arc:999"); add(cmd, "grow 0"); @@ -185,10 +192,28 @@ public Effect() { } protected static final Color effectColors[] = { - Color.decode("#8DBF13"), Color.decode("#13BF86"), - Color.decode("#FF5733"), Color.decode("#E6A801"), - Color.decode("#FFC300"), Color.decode("#FF5733"), - Color.decode("#C70039"), Color.decode("#900C3F"), - Color.decode("#581845"), Color.decode("#4A235A") + Color.decode("#f43f5e"), Color.decode("#6366f1"), + Color.decode("#ec4899"), Color.decode("#3b82f6"), + Color.decode("#d946ef"), Color.decode("#0ea5e9"), + Color.decode("#a855f7"), Color.decode("#06b6d4"), + Color.decode("#8b5cf6"), Color.decode("#14b8a6"), + Color.decode("#10b981"), Color.decode("#22c55e"), + Color.decode("#84cc16"), Color.decode("#eab308"), + Color.decode("#f59e0b"), Color.decode("#f97316"), + Color.decode("#ef4444"), Color.decode("#78716c"), + Color.decode("#737373"), Color.decode("#71717a"), + Color.decode("#6b7280"), Color.decode("#64748b") }; + + public enum AlertsType { + SUCCESS("success", "#4FC671"), ERROR("error", "#E15D5D"), WARNING("warning", "#E1BB5D"); + + protected String name; + private String color; + + private AlertsType(String name, String color) { + this.name = name; + this.color = color; + } + } } diff --git a/src/main/java/raven/popup/DefaultOption.java b/src/main/java/raven/popup/DefaultOption.java index a7bfcfb..353b350 100644 --- a/src/main/java/raven/popup/DefaultOption.java +++ b/src/main/java/raven/popup/DefaultOption.java @@ -1,5 +1,7 @@ package raven.popup; +import com.formdev.flatlaf.FlatLaf; + import java.awt.*; public class DefaultOption implements Option { @@ -35,7 +37,7 @@ public boolean blockBackground() { @Override public Color background() { - return new Color(20, 20, 20); + return FlatLaf.isLafDark()?new Color(50, 50, 50):new Color(20, 20, 20); } @Override diff --git a/src/test/java/test/DemoAlerts.java b/src/test/java/test/DemoAlerts.java index 0616a70..0d48590 100644 --- a/src/test/java/test/DemoAlerts.java +++ b/src/test/java/test/DemoAlerts.java @@ -22,7 +22,9 @@ public DemoAlerts() { setLayout(new MigLayout("")); JButton cmd = new JButton("Show Drawer"); cmd.addActionListener(e -> { - GlassPanePopup.showPopup(new SimpleAlerts()); + String title = "Data Save Successful"; + String message = "Great news! Your data has been securely saved. It's all set and ready for your use whenever you need it. If you have any questions, just let us know!"; + GlassPanePopup.showPopup(new SimpleAlerts(SimpleAlerts.AlertsType.SUCCESS, title, message)); }); add(cmd); } From 694b102872058f51093794ac345fb723772066a9 Mon Sep 17 00:00:00 2001 From: raven Date: Wed, 15 Nov 2023 16:48:54 +0700 Subject: [PATCH 04/13] update --- .idea/workspace.xml | 6 +- src/main/java/raven/alerts/AlertsOption.java | 27 +++++++ src/main/java/raven/alerts/SimpleAlerts.java | 56 ++++++++------- src/main/java/raven/swing/AnimateIcon.java | 71 +++++++++++++++++++ .../resources/raven/alerts/icon/warning.svg | 31 ++++++++ 5 files changed, 162 insertions(+), 29 deletions(-) create mode 100644 src/main/java/raven/alerts/AlertsOption.java create mode 100644 src/main/java/raven/swing/AnimateIcon.java create mode 100644 src/main/resources/raven/alerts/icon/warning.svg diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ebe705e..13ec192 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,8 +7,6 @@ - - - + diff --git a/src/main/java/raven/alerts/AlertsOption.java b/src/main/java/raven/alerts/AlertsOption.java new file mode 100644 index 0000000..d1008d6 --- /dev/null +++ b/src/main/java/raven/alerts/AlertsOption.java @@ -0,0 +1,27 @@ +package raven.alerts; + +import raven.swing.AnimateIcon; + +import javax.swing.*; +import java.awt.*; + +public class AlertsOption { + + protected Icon icon; + protected Color baseColor; + + public AlertsOption(Icon icon, Color baseColor) { + this.icon = icon; + this.baseColor = baseColor; + } + + protected static AlertsOption getAlertsOption(SimpleAlerts.AlertsType type) { + if (type == SimpleAlerts.AlertsType.SUCCESS) { + return new AlertsOption(new AnimateIcon("raven/alerts/icon/success.svg", 4f), Color.decode("#10b981")); + } else if (type == SimpleAlerts.AlertsType.WARNING) { + return new AlertsOption(new AnimateIcon("raven/alerts/icon/warning.svg", 4f), Color.decode("#f59e0b")); + } else { + return new AlertsOption(new AnimateIcon("raven/alerts/icon/error.svg", 4f), Color.decode("#ef4444")); + } + } +} diff --git a/src/main/java/raven/alerts/SimpleAlerts.java b/src/main/java/raven/alerts/SimpleAlerts.java index 58c4e30..8d074ef 100644 --- a/src/main/java/raven/alerts/SimpleAlerts.java +++ b/src/main/java/raven/alerts/SimpleAlerts.java @@ -9,6 +9,7 @@ import net.miginfocom.swing.MigLayout; import raven.popup.GlassPanePopup; import raven.popup.component.GlassPaneChild; +import raven.swing.AnimateIcon; import javax.swing.*; import javax.swing.text.SimpleAttributeSet; @@ -20,20 +21,24 @@ public class SimpleAlerts extends GlassPaneChild { - private final AlertsType type; private final String title; private final String message; public SimpleAlerts(AlertsType type, String title, String message) { - this.type = type; this.title = title; this.message = message; - init(); + init(AlertsOption.getAlertsOption(type)); } - private void init() { + public SimpleAlerts(AlertsOption option, String title, String message) { + this.title = title; + this.message = message; + init(option); + } + + private void init(AlertsOption option) { setLayout(new MigLayout("wrap,fillx,insets 15 0 15 0", "[fill,400]")); - add(new PanelEffect(type, title, message)); + add(new PanelEffect(option, title, message)); } @Override @@ -43,6 +48,7 @@ public int getRoundBorder() { protected class PanelEffect extends JPanel { + private AlertsOption option; private Effect effects[]; private float animate; private Animator animator; @@ -50,6 +56,7 @@ protected class PanelEffect extends JPanel { private JLabel labelIcon; private JLabel labelTitle; private JTextPane textPane; + private AnimateIcon animateIcon; protected void start() { if (animator == null) { @@ -57,7 +64,11 @@ protected void start() { @Override public void timingEvent(float v) { animate = v; - repaint(); + if (animateIcon == null) { + repaint(); + } else { + animateIcon.setAnimate(animate); + } } }); animator.setInterpolator(CubicBezierEasing.EASE); @@ -77,9 +88,13 @@ private void createEffect() { } - public PanelEffect(AlertsType type, String title, String message) { - setLayout(new MigLayout("fillx,wrap,insets 0,center", "[fill,center]", "[]10[][][]20[]20")); - labelIcon = new JLabel(new FlatSVGIcon("raven/alerts/icon/" + type.name + ".svg", 4f)); + public PanelEffect(AlertsOption option, String title, String message) { + this.option = option; + setLayout(new MigLayout("debug,fillx,wrap,insets 0,center", "[fill,center]", "0[]3[]10[]20[]20")); + if (option.icon instanceof AnimateIcon) { + animateIcon = (AnimateIcon) option.icon; + } + labelIcon = new JLabel(option.icon); labelTitle = new JLabel(title, JLabel.CENTER); textPane = new JTextPane(); textPane.setOpaque(false); @@ -89,17 +104,16 @@ public PanelEffect(AlertsType type, String title, String message) { doc.setParagraphAttributes(0, doc.getLength(), center, false); textPane.setEditable(false); textPane.setText(message); + labelIcon.putClientProperty(FlatClientProperties.STYLE, "" + + "border:20,5,10,5"); textPane.putClientProperty(FlatClientProperties.STYLE, "" + "border:5,25,5,25;" + "[light]foreground:lighten(@foreground,30%);" + "[dark]foreground:darken(@foreground,30%)"); labelTitle.putClientProperty(FlatClientProperties.STYLE, "" + - "font:bold +5;" + - "foreground:" + type.color); - JPanel panelTitle = new JPanel(new MigLayout("insets 2 25 2 25,fill")); - panelTitle.setOpaque(false); - panelTitle.add(createCloseButton(), "trailing"); - add(panelTitle); + "font:bold +5"); + labelTitle.setForeground(option.baseColor); + add(createCloseButton(), "pos visual.x2-pref-25 2"); add(labelIcon); add(labelTitle); add(textPane); @@ -120,6 +134,7 @@ protected Component createCloseButton() { protected void createButton() { JButton cmd = new JButton("OK"); + cmd.setBackground(option.baseColor); cmd.addActionListener(e -> { createEffect(); }); @@ -130,7 +145,6 @@ protected void createButton() { "arc:10;" + "font:+1;" + "margin:5,50,5,50;" + - "background:" + type.color + ";" + "foreground:#F0F0F0;" + "arc:999"); add(cmd, "grow 0"); @@ -206,14 +220,6 @@ public Effect() { }; public enum AlertsType { - SUCCESS("success", "#4FC671"), ERROR("error", "#E15D5D"), WARNING("warning", "#E1BB5D"); - - protected String name; - private String color; - - private AlertsType(String name, String color) { - this.name = name; - this.color = color; - } + SUCCESS, ERROR, WARNING } } diff --git a/src/main/java/raven/swing/AnimateIcon.java b/src/main/java/raven/swing/AnimateIcon.java new file mode 100644 index 0000000..7739fcd --- /dev/null +++ b/src/main/java/raven/swing/AnimateIcon.java @@ -0,0 +1,71 @@ +package raven.swing; + +import com.formdev.flatlaf.extras.FlatSVGIcon; +import com.formdev.flatlaf.util.Animator; + +import java.awt.*; +import java.awt.geom.AffineTransform; + +public class AnimateIcon extends FlatSVGIcon { + + private Component component; + + private Animator animator; + private float animate; + + public AnimateIcon(String name, float scale) { + super(name, scale); + } + + @Override + public void paintIcon(Component c, Graphics g, int x, int y) { + if (c != component) { + component = c; + } + if (animate > 0) { + Graphics2D g2 = (Graphics2D) g; + AffineTransform tran = g2.getTransform(); + float scale = 1 + animate * 0.5f; + float rotate = animate * -0.5f; + int centerX = x + getIconWidth() / 2; + int centerY = y + getIconHeight() / 2; + g2.translate(centerX, centerY); + g2.rotate(rotate); + g2.scale(scale, scale); + g2.translate(-centerX, -centerY); + super.paintIcon(c, g, x, y); + g2.setTransform(tran); + } else { + super.paintIcon(c, g, x, y); + } + } + + public void setAnimate(float f) { + float v; + if (f < 0.5f) { + v = f * 2; + } else { + v = 2 - (f * 2); + } + this.animate = v; + if (component != null) { + component.repaint(); + } + } + + public boolean animate() { + boolean act = false; + if (component != null) { + if (animator == null) { + animator = new Animator(350, (float f) -> { + setAnimate(f); + }); + } + if (!animator.isRunning()) { + animator.start(); + act = true; + } + } + return act; + } +} diff --git a/src/main/resources/raven/alerts/icon/warning.svg b/src/main/resources/raven/alerts/icon/warning.svg new file mode 100644 index 0000000..4cb5824 --- /dev/null +++ b/src/main/resources/raven/alerts/icon/warning.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 1b39959b6cea37e1eb6b455722b1c7f99b41c980 Mon Sep 17 00:00:00 2001 From: raven Date: Wed, 15 Nov 2023 20:51:31 +0700 Subject: [PATCH 05/13] fixed animation and scale --- .idea/workspace.xml | 27 ++++++++-------- src/main/java/raven/alerts/SimpleAlerts.java | 34 ++++++++++++++------ src/test/java/test/DemoAlerts.java | 4 +-- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 13ec192..ca9929c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,6 +7,7 @@ + - { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "WebServerToolWindowFactoryState": "false", + "jdk.selected.JAVA_MODULE": "1.8", + "last_opened_file_path": "D:/Raven/swing-glasspane-popup/src/main/resources/raven/alerts/icon", + "project.structure.last.edited": "Modules", + "project.structure.proportion": "0.15", + "project.structure.side.proportion": "0.3586207", + "settings.editor.selected.configurable": "MavenSettings" } -}]]> +} diff --git a/src/main/java/raven/alerts/SimpleAlerts.java b/src/main/java/raven/alerts/SimpleAlerts.java index 8d074ef..935d197 100644 --- a/src/main/java/raven/alerts/SimpleAlerts.java +++ b/src/main/java/raven/alerts/SimpleAlerts.java @@ -64,11 +64,10 @@ protected void start() { @Override public void timingEvent(float v) { animate = v; - if (animateIcon == null) { - repaint(); - } else { - animateIcon.setAnimate(animate); + if (animateIcon != null) { + animateIcon.setAnimate(easeOutBounce(v)); } + repaint(); } }); animator.setInterpolator(CubicBezierEasing.EASE); @@ -79,6 +78,22 @@ public void timingEvent(float v) { animator.start(); } + private float easeOutBounce(float x) { + double n1 = 7.5625f; + double d1 = 2.75f; + double v; + if (x < 1 / d1) { + v = n1 * x * x; + } else if (x < 2 / d1) { + v = n1 * (x -= 1.5 / d1) * x + 0.75f; + } else if (x < 2.5 / d1) { + v = n1 * (x -= 2.25 / d1) * x + 0.9375f; + } else { + v = n1 * (x -= 2.625 / d1) * x + 0.984375f; + } + return (float) v; + } + private void createEffect() { effects = new Effect[30]; for (int i = 0; i < effects.length; i++) { @@ -90,7 +105,7 @@ private void createEffect() { public PanelEffect(AlertsOption option, String title, String message) { this.option = option; - setLayout(new MigLayout("debug,fillx,wrap,insets 0,center", "[fill,center]", "0[]3[]10[]20[]20")); + setLayout(new MigLayout("fillx,wrap,insets 0", "[fill,center]", "0[]3[]10[]20[]20")); if (option.icon instanceof AnimateIcon) { animateIcon = (AnimateIcon) option.icon; } @@ -105,7 +120,7 @@ public PanelEffect(AlertsOption option, String title, String message) { textPane.setEditable(false); textPane.setText(message); labelIcon.putClientProperty(FlatClientProperties.STYLE, "" + - "border:20,5,10,5"); + "border:25,5,10,5"); textPane.putClientProperty(FlatClientProperties.STYLE, "" + "border:5,25,5,25;" + "[light]foreground:lighten(@foreground,30%);" + @@ -113,7 +128,7 @@ public PanelEffect(AlertsOption option, String title, String message) { labelTitle.putClientProperty(FlatClientProperties.STYLE, "" + "font:bold +5"); labelTitle.setForeground(option.baseColor); - add(createCloseButton(), "pos visual.x2-pref-25 2"); + add(createCloseButton(), "pos 100%-pref-25 2"); add(labelIcon); add(labelTitle); add(textPane); @@ -166,7 +181,7 @@ protected void paintChildren(Graphics g) { float l = size * animate; float remove = 0.7f; g2.translate(x, y); - g2.scale(s, s); + for (int i = 0; i < effects.length; i++) { Effect effect = effects[i]; double sp = effect.speed * 0.05f; @@ -174,11 +189,12 @@ protected void paintChildren(Graphics g) { double yy = Math.sin(Math.toRadians(effect.direction)) * l * sp; AffineTransform oldTran = g2.getTransform(); g2.translate(xx, yy); + g2.scale(s, s); g2.rotate(Math.toRadians(animate * 360), 5, 5); g2.setColor(effect.color); if (animate >= remove) { float f = (animate - remove) / (1f - remove); - g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f - f)); + // g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f - f)); } g2.fill(effect.shape); g2.setTransform(oldTran); diff --git a/src/test/java/test/DemoAlerts.java b/src/test/java/test/DemoAlerts.java index 0d48590..e951500 100644 --- a/src/test/java/test/DemoAlerts.java +++ b/src/test/java/test/DemoAlerts.java @@ -2,11 +2,9 @@ import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.fonts.roboto.FlatRobotoFont; -import com.formdev.flatlaf.themes.FlatMacDarkLaf; import com.formdev.flatlaf.themes.FlatMacLightLaf; import net.miginfocom.swing.MigLayout; import raven.alerts.SimpleAlerts; -import raven.drawer.Drawer; import raven.popup.GlassPanePopup; import javax.swing.*; @@ -24,7 +22,7 @@ public DemoAlerts() { cmd.addActionListener(e -> { String title = "Data Save Successful"; String message = "Great news! Your data has been securely saved. It's all set and ready for your use whenever you need it. If you have any questions, just let us know!"; - GlassPanePopup.showPopup(new SimpleAlerts(SimpleAlerts.AlertsType.SUCCESS, title, message)); + GlassPanePopup.showPopup(new SimpleAlerts(SimpleAlerts.AlertsType.WARNING, title, message)); }); add(cmd); } From cbdd921228a47c330da34a1586e2c9331f19eb89 Mon Sep 17 00:00:00 2001 From: laing raven Date: Wed, 15 Nov 2023 22:04:25 +0700 Subject: [PATCH 06/13] update --- .idea/workspace.xml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ebe705e..ee2cbd2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,12 +4,7 @@ - - - - - - + From 6139a5499d47ce502aa0675b7fff3d4fe45386d6 Mon Sep 17 00:00:00 2001 From: laing raven Date: Thu, 16 Nov 2023 19:49:17 +0700 Subject: [PATCH 07/13] update alert --- .idea/workspace.xml | 33 +++++++++---------- src/main/java/raven/alerts/AlertsOption.java | 14 ++++---- src/main/java/raven/alerts/MessageAlerts.java | 32 ++++++++++++++++++ src/main/java/raven/alerts/SimpleAlerts.java | 21 ++++-------- .../raven/alerts/effect/disclaimer.svg | 3 ++ .../resources/raven/alerts/effect/mark.svg | 3 ++ .../resources/raven/alerts/effect/query.svg | 3 ++ .../resources/raven/alerts/effect/warning.svg | 3 ++ src/test/java/test/DemoAlerts.java | 4 +-- 9 files changed, 74 insertions(+), 42 deletions(-) create mode 100644 src/main/java/raven/alerts/MessageAlerts.java create mode 100644 src/main/resources/raven/alerts/effect/disclaimer.svg create mode 100644 src/main/resources/raven/alerts/effect/mark.svg create mode 100644 src/main/resources/raven/alerts/effect/query.svg create mode 100644 src/main/resources/raven/alerts/effect/warning.svg diff --git a/.idea/workspace.xml b/.idea/workspace.xml index bc3f73c..955c061 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,13 +5,9 @@ - - + - - - - { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "WebServerToolWindowFactoryState": "false", + "jdk.selected.JAVA_MODULE": "1.8", + "last_opened_file_path": "D:/Raven/youtube/glasspane popup/swing glasspane popup/swing-glasspane-popup/src/main/resources/raven/alerts/effect", + "project.structure.last.edited": "Modules", + "project.structure.proportion": "0.15", + "project.structure.side.proportion": "0.3586207", + "settings.editor.selected.configurable": "MavenSettings" } -}]]> +} @@ -146,6 +142,7 @@ + diff --git a/src/main/java/raven/alerts/AlertsOption.java b/src/main/java/raven/alerts/AlertsOption.java index db1e23e..63f73f4 100644 --- a/src/main/java/raven/alerts/AlertsOption.java +++ b/src/main/java/raven/alerts/AlertsOption.java @@ -41,8 +41,8 @@ public AlertsOption setEffectLoop(boolean effectLoop) { return this; } - protected static AlertsOption getAlertsOption(SimpleAlerts.AlertsType type) { - if (type == SimpleAlerts.AlertsType.SUCCESS) { + protected static AlertsOption getAlertsOption(MessageAlerts.MessageType messageType) { + if (messageType == MessageAlerts.MessageType.SUCCESS) { Icon effects[] = new Icon[]{ new FlatSVGIcon("raven/alerts/effect/check.svg"), new FlatSVGIcon("raven/alerts/effect/star.svg"), @@ -51,12 +51,12 @@ protected static AlertsOption getAlertsOption(SimpleAlerts.AlertsType type) { }; return getDefaultOption("raven/alerts/icon/success.svg", "#10b981") .setRandomEffect(effects); - } else if (type == SimpleAlerts.AlertsType.WARNING) { + } else if (messageType == MessageAlerts.MessageType.WARNING) { Icon effects[] = new Icon[]{ - new FlatSVGIcon("raven/alerts/effect/check.svg"), - new FlatSVGIcon("raven/alerts/effect/star.svg"), - new FlatSVGIcon("raven/alerts/effect/firework.svg"), - new FlatSVGIcon("raven/alerts/effect/balloon.svg") + new FlatSVGIcon("raven/alerts/effect/disclaimer.svg"), + new FlatSVGIcon("raven/alerts/effect/warning.svg"), + new FlatSVGIcon("raven/alerts/effect/query.svg"), + new FlatSVGIcon("raven/alerts/effect/mark.svg") }; return getDefaultOption("raven/alerts/icon/warning.svg", "#f59e0b") .setRandomEffect(effects); diff --git a/src/main/java/raven/alerts/MessageAlerts.java b/src/main/java/raven/alerts/MessageAlerts.java new file mode 100644 index 0000000..0fa685e --- /dev/null +++ b/src/main/java/raven/alerts/MessageAlerts.java @@ -0,0 +1,32 @@ +package raven.alerts; + +import raven.popup.GlassPanePopup; + +public class MessageAlerts { + + private static MessageAlerts instance; + + public static MessageAlerts getInstance() { + if (instance == null) { + instance = new MessageAlerts(); + } + return instance; + } + + private MessageAlerts() { + } + + public void showMessage(String title, String message) { + + } + + public void showMessage(String title, String message, MessageType messageType) { + + GlassPanePopup.showPopup(new SimpleAlerts(AlertsOption.getAlertsOption(messageType), title, message)); + } + + + public enum MessageType { + SUCCESS, ERROR, WARNING + } +} diff --git a/src/main/java/raven/alerts/SimpleAlerts.java b/src/main/java/raven/alerts/SimpleAlerts.java index ddc9d7a..fbd223a 100644 --- a/src/main/java/raven/alerts/SimpleAlerts.java +++ b/src/main/java/raven/alerts/SimpleAlerts.java @@ -25,12 +25,6 @@ public class SimpleAlerts extends GlassPaneChild { private final String message; private PanelEffect panelEffect; - public SimpleAlerts(AlertsType type, String title, String message) { - this.title = title; - this.message = message; - init(AlertsOption.getAlertsOption(type)); - } - public SimpleAlerts(AlertsOption option, String title, String message) { this.title = title; this.message = message; @@ -81,7 +75,7 @@ public void timingEvent(float v) { public void end() { if (option.effectLoop && isShowing()) { SwingUtilities.invokeLater(() -> { - animator.start(); + createEffect(); }); } } @@ -202,7 +196,7 @@ protected void paintChildren(Graphics g) { double xx = Math.cos(Math.toRadians(effect.direction)) * l * sp; double yy = Math.sin(Math.toRadians(effect.direction)) * l * sp; AffineTransform oldTran = g2.getTransform(); - Icon icon = effect.effect; + Icon icon = option.randomEffect[effect.effectIndex]; int iw = icon.getIconWidth() / 2; int ih = icon.getIconHeight() / 2; xx -= iw; @@ -219,7 +213,8 @@ protected void paintChildren(Graphics g) { g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, option.effectAlpha - f)); } } - effect.effect.paintIcon(null, new GraphicsColorFilter(g2, effect.color), 0, 0); + + icon.paintIcon(null, new GraphicsColorFilter(g2, effect.color), 0, 0); g2.setTransform(oldTran); } g2.dispose(); @@ -230,7 +225,7 @@ protected void paintChildren(Graphics g) { protected class Effect { - protected Icon effect; + protected int effectIndex; protected Color color; protected float direction; protected float speed; @@ -239,7 +234,7 @@ public Effect(Icon[] randomEffect) { Random random = new Random(); color = effectColors[random.nextInt(effectColors.length)]; if (randomEffect != null && randomEffect.length > 0) { - effect = randomEffect[random.nextInt(randomEffect.length)]; + effectIndex = random.nextInt(randomEffect.length); } direction = random.nextInt(360); speed = random.nextInt(25) + 5; @@ -279,8 +274,4 @@ public void setPaint(Paint paint) { super.setPaint(color); } } - - public enum AlertsType { - SUCCESS, ERROR, WARNING - } } diff --git a/src/main/resources/raven/alerts/effect/disclaimer.svg b/src/main/resources/raven/alerts/effect/disclaimer.svg new file mode 100644 index 0000000..a79c0b0 --- /dev/null +++ b/src/main/resources/raven/alerts/effect/disclaimer.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/main/resources/raven/alerts/effect/mark.svg b/src/main/resources/raven/alerts/effect/mark.svg new file mode 100644 index 0000000..f7ad079 --- /dev/null +++ b/src/main/resources/raven/alerts/effect/mark.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/main/resources/raven/alerts/effect/query.svg b/src/main/resources/raven/alerts/effect/query.svg new file mode 100644 index 0000000..9396385 --- /dev/null +++ b/src/main/resources/raven/alerts/effect/query.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/main/resources/raven/alerts/effect/warning.svg b/src/main/resources/raven/alerts/effect/warning.svg new file mode 100644 index 0000000..1b98693 --- /dev/null +++ b/src/main/resources/raven/alerts/effect/warning.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/test/java/test/DemoAlerts.java b/src/test/java/test/DemoAlerts.java index b0fc6b1..0678ef6 100644 --- a/src/test/java/test/DemoAlerts.java +++ b/src/test/java/test/DemoAlerts.java @@ -3,8 +3,8 @@ import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.fonts.roboto.FlatRobotoFont; import com.formdev.flatlaf.themes.FlatMacDarkLaf; -import com.formdev.flatlaf.themes.FlatMacLightLaf; import net.miginfocom.swing.MigLayout; +import raven.alerts.MessageAlerts; import raven.alerts.SimpleAlerts; import raven.popup.GlassPanePopup; @@ -23,7 +23,7 @@ public DemoAlerts() { cmd.addActionListener(e -> { String title = "Data Save Successful"; String message = "Great news! Your data has been securely saved. It's all set and ready for your use whenever you need it. If you have any questions, just let us know!"; - GlassPanePopup.showPopup(new SimpleAlerts(SimpleAlerts.AlertsType.SUCCESS, title, message)); + MessageAlerts.getInstance().showMessage(title,message, MessageAlerts.MessageType.SUCCESS); }); add(cmd); } From b367b3e0331c33ab3c02aa4f426a027727530567 Mon Sep 17 00:00:00 2001 From: laing raven Date: Fri, 17 Nov 2023 02:08:02 +0700 Subject: [PATCH 08/13] update alert --- .idea/workspace.xml | 49 +++++++--- src/main/java/raven/alerts/AlertsOption.java | 82 ++++++++++------ src/main/java/raven/alerts/MessageAlerts.java | 42 ++++++++- src/main/java/raven/alerts/SimpleAlerts.java | 94 ++++++------------- src/main/java/raven/swing/AnimateIcon.java | 59 +++++++++--- .../swing/animator/EasingInterpolator.java | 30 ++++++ .../java/raven/swing/animator/Evaluator.java | 6 ++ .../raven/swing/animator/EvaluatorFloat.java | 9 ++ .../java/raven/swing/animator/KeyFrames.java | 31 ++++++ src/test/java/test/DemoAlerts.java | 7 +- src/test/resources/themes/FlatLaf.properties | 2 + 11 files changed, 286 insertions(+), 125 deletions(-) create mode 100644 src/main/java/raven/swing/animator/EasingInterpolator.java create mode 100644 src/main/java/raven/swing/animator/Evaluator.java create mode 100644 src/main/java/raven/swing/animator/EvaluatorFloat.java create mode 100644 src/main/java/raven/swing/animator/KeyFrames.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 955c061..1a8fdcc 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,8 +7,11 @@ + + +