From 223e15fcbb60acc554522f22739b0e88a7253dd4 Mon Sep 17 00:00:00 2001 From: kuangshuai Date: Tue, 19 Oct 2021 20:44:14 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-60942=20=E5=8A=A0=E8=BD=BD=E5=9B=BE?= =?UTF-8?q?=E8=A7=86=E8=A7=89=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/guide/base/GuideView.java | 5 +- .../guide/ui/GuideLoadingGlassPane.java | 19 ++-- .../mainframe/guide/ui/GuideLoadingPane.java | 98 +++++++++++++++++++ .../design/mainframe/guide/ui/ImagePanel.java | 28 ------ 4 files changed, 115 insertions(+), 35 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingPane.java delete mode 100644 designer-base/src/main/java/com/fr/design/mainframe/guide/ui/ImagePanel.java diff --git a/designer-base/src/main/java/com/fr/design/mainframe/guide/base/GuideView.java b/designer-base/src/main/java/com/fr/design/mainframe/guide/base/GuideView.java index 7e141d7d5..f8b93e34c 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/guide/base/GuideView.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/guide/base/GuideView.java @@ -40,7 +40,6 @@ public class GuideView extends JDialog { this.setSize(window.getSize()); this.setLayout(FRGUIPaneFactory.createBorderLayout()); setBg(); - this.setGlassPane(new GuideLoadingGlassPane()); DesignerContext.getDesignerFrame().addWindowListener(new WindowAdapter() { @Override @@ -106,12 +105,16 @@ public class GuideView extends JDialog { } public void showLoading() { + this.setGlassPane(GuideLoadingGlassPane.getInstance()); + GuideLoadingGlassPane.getInstance().startLoading(); updateGuideViewLocation(); this.setVisible(true); + this.invalidate(); this.getGlassPane().setVisible(true); } public void hideLoading() { + GuideLoadingGlassPane.getInstance().stopLoading(); this.getGlassPane().setVisible(false); repaint(); SwingUtilities.invokeLater(new Runnable() { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingGlassPane.java b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingGlassPane.java index 64017dfb7..47a10d0be 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingGlassPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingGlassPane.java @@ -9,11 +9,11 @@ import javax.swing.SwingConstants; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; +import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; public class GuideLoadingGlassPane extends JPanel { - private static final String loadingImagePath = "/com/fr/design/mainframe/guide/loading.gif"; private static GuideLoadingGlassPane loadingPane; public static GuideLoadingGlassPane getInstance() { @@ -32,16 +32,15 @@ public class GuideLoadingGlassPane extends JPanel { public void initComponent() { JPanel loadingView = FRGUIPaneFactory.createBorderLayout_S_Pane(); loadingView.setOpaque(false); - loadingView.setPreferredSize(new Dimension(130, 120)); + loadingView.setPreferredSize(new Dimension(150, 90)); JPanel imageContainer = FRGUIPaneFactory.createCenterFlowInnerContainer_S_Pane(); imageContainer.setOpaque(false); - ImagePanel imagePanel = new ImagePanel(loadingImagePath); - imagePanel.setOpaque(false); - imagePanel.setPreferredSize(new Dimension(84, 84)); - imageContainer.add(imagePanel); + + imageContainer.add(GuideLoadingPane.getInstance()); UILabel hintLabel = new UILabel(Toolkit.i18nText("Fine-Design_Guide_Loading_Wait")); + hintLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14)); hintLabel.setHorizontalAlignment(SwingConstants.CENTER); hintLabel.setForeground(Color.WHITE); @@ -50,4 +49,12 @@ public class GuideLoadingGlassPane extends JPanel { this.add(loadingView, new GridBagConstraints()); } + + public void startLoading() { + GuideLoadingPane.getInstance().start(); + } + + public void stopLoading() { + GuideLoadingPane.getInstance().stop(); + } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingPane.java b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingPane.java new file mode 100644 index 000000000..0a290c784 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingPane.java @@ -0,0 +1,98 @@ +package com.fr.design.mainframe.guide.ui; + +import javax.swing.JPanel; +import javax.swing.Timer; +import java.awt.AlphaComposite; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Point; +import java.awt.RenderingHints; +import java.awt.Stroke; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * Created by kerry on 2020-10-23 + */ +public class GuideLoadingPane extends JPanel { + private static final BasicStroke STROKE = new BasicStroke(4); + private static final int FPS = 30; + private static final int START_ANGLE = 90; + private static GuideLoadingPane imagePanel; + private Image image; + private int angle; + private Timer timer; + + public static GuideLoadingPane getInstance() { + if (imagePanel == null) { + imagePanel = new GuideLoadingPane(); + } + return imagePanel; + } + + public GuideLoadingPane() { + this.setOpaque(false); + this.setPreferredSize(new Dimension(50, 50)); + timer = new Timer(1000 / FPS, new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + repaint(); + angle -= 180 / FPS; // 5 degrees per 100 ms = 50 degrees/second + if (angle > -270) { + angle += 2 * 360; + } + } + }); + } + + public void start() { + angle = START_ANGLE; + timer.start(); + } + + public void stop() { + timer.stop(); + } + + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + Composite oldComposite = g2.getComposite(); + Stroke oldStroke = g2.getStroke(); + + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); + + int d = Math.min(getWidth(), getHeight()); + int r = d / 2; + Point circlePoint = new Point(getWidth() / 2, getHeight() / 2); + + g2.setColor(Color.WHITE); + g2.fillOval(circlePoint.x - r, circlePoint.y - r, d, d); + + g2.setColor(Color.BLACK); + int waitCircleD = d / 10; + int waitCircleR = waitCircleD / 2; + + g2.fillOval(circlePoint.x - r / 3 - waitCircleR, circlePoint.y - waitCircleR, waitCircleD, waitCircleD); + g2.fillOval(circlePoint.x - waitCircleR, circlePoint.y - waitCircleR, waitCircleD, waitCircleD); + g2.fillOval(circlePoint.x + r / 3 - waitCircleR, circlePoint.y - waitCircleR, waitCircleD, waitCircleD); + + + g2.setStroke(STROKE); + g2.setColor(Color.decode("#419BF9")); + + int lineWidth = (int) STROKE.getLineWidth(); + g2.drawArc(circlePoint.x - r + lineWidth / 2 , circlePoint.y - r + lineWidth / 2, d - lineWidth, d - lineWidth, angle, -90); + + g2.setStroke(oldStroke); + g2.setComposite(oldComposite); + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/ImagePanel.java b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/ImagePanel.java deleted file mode 100644 index deaf97417..000000000 --- a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/ImagePanel.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.fr.design.mainframe.guide.ui; - -import javax.swing.JPanel; -import java.awt.Graphics; -import java.awt.Image; -import java.awt.Toolkit; - -/** - * Created by kerry on 2020-10-23 - */ -public class ImagePanel extends JPanel { - - - private Image image; - - public ImagePanel(String imagePath) { - image = Toolkit.getDefaultToolkit().createImage(ImagePanel.class - .getResource(imagePath)); - } - - @Override - public void paintComponent(Graphics g) { - super.paintComponent(g); - if (image != null) { - g.drawImage(image, 0, 0, getWidth(), getHeight(), this); - } - } -}