From 1ddcc02f7e9efcbb36c924ba4057b6e1db132857 Mon Sep 17 00:00:00 2001 From: hades Date: Sat, 8 May 2021 16:05:04 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-51304=20=E4=BF=9D=E5=AD=98=E6=97=B6gif?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E4=B8=BA=E9=80=8F=E6=98=8E=E6=97=B6=20?= =?UTF-8?q?=E9=94=AF=E9=BD=BF=E5=A4=AA=E4=B8=A5=E9=87=8D=20=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E4=BB=A3=E7=A0=81=E6=9D=A5=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/DesktopCardPane.java | 2 + .../fr/design/mainframe/TransparentPane.java | 98 +++++++++++++++---- 2 files changed, 81 insertions(+), 19 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesktopCardPane.java b/designer-base/src/main/java/com/fr/design/mainframe/DesktopCardPane.java index a2cc6f806..22a10d3ba 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesktopCardPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesktopCardPane.java @@ -105,11 +105,13 @@ public class DesktopCardPane extends BasicPane implements TargetModifiedListener } public void showCover() { + transparentPane.start(); layeredPane.moveToFront(transparentPane); DesignerContext.getDesignerFrame().refreshUIToolBar(); } public void hideCover() { + transparentPane.stop(); layeredPane.moveToFront(component); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/TransparentPane.java b/designer-base/src/main/java/com/fr/design/mainframe/TransparentPane.java index 100ab04f6..8861a7591 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/TransparentPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/TransparentPane.java @@ -3,6 +3,7 @@ package com.fr.design.mainframe; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import java.awt.AlphaComposite; +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Component; import java.awt.Composite; @@ -11,23 +12,34 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.LayoutManager; +import java.awt.RenderingHints; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.ImageIcon; import javax.swing.JComponent; +import javax.swing.Timer; /** * @author hades * @version 10.0 * Created by hades on 2021/4/12 */ -public class TransparentPane extends JComponent { +public class TransparentPane extends JComponent implements ActionListener { - private static final ImageIcon LOADING_ICON = new ImageIcon(TransparentPane.class.getResource("/com/fr/web/images/loading-local.gif")); - - private UILabel loadingLabel; private UILabel label; private AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); + private volatile boolean mIsRunning; + private volatile boolean mIsFadingOut; + private Timer mTimer; + private int mAngle; + private int mFadeCount; + private int mFadeLimit = 15; + private int lines = 12; + private int maxAngle = 360; + private int angleAdd = 30; + private double prec = 0.56; public TransparentPane() { @@ -41,10 +53,7 @@ public class TransparentPane extends JComponent { setLayout(getCoverLayout()); setBackground(null); setOpaque(false); - - loadingLabel = new UILabel(LOADING_ICON); label = new UILabel(Toolkit.i18nText("Fine-Design_Saving_Template_Tip")); - add(loadingLabel); add(label); } @@ -69,16 +78,11 @@ public class TransparentPane extends JComponent { public void layoutContainer(Container parent) { int width = parent.getParent().getWidth(); int height = parent.getParent().getHeight(); - int loadingLabelWidth = loadingLabel.getPreferredSize().width; - int loadingLabelHeight = loadingLabel.getPreferredSize().height; - int buttonX = (width - loadingLabelWidth) / 2; - int buttonY = (height - loadingLabelHeight) / 2; int labelWidth = label.getPreferredSize().width; int labelHeight = label.getPreferredSize().height; int labelX = (width - labelWidth) / 2; - int labelY = (height - labelHeight) / 2 + loadingLabelHeight; + int labelY = (int) ((height - labelHeight) * prec); label.setBounds(labelX, labelY, labelWidth, labelHeight); - loadingLabel.setBounds(buttonX, buttonY, loadingLabelWidth, loadingLabelHeight); } @Override @@ -90,13 +94,69 @@ public class TransparentPane extends JComponent { @Override public void paint(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - Composite oldComposite = g2d.getComposite(); - g2d.setComposite(composite); - g2d.setColor(Color.BLACK); - g2d.fillRect(0, 0, getWidth(), getHeight()); - g2d.setComposite(oldComposite); + int w = this.getWidth(); + int h = this.getHeight(); super.paint(g); + if (!mIsRunning) { + return; + } + Graphics2D g2 = (Graphics2D) g.create(); + float fade = (float) mFadeCount / (float) mFadeLimit; + Composite urComposite = g2.getComposite(); + g2.setComposite(composite); + g2.fillRect(0, 0, w, h); + g2.setComposite(urComposite); + int s = Math.min(w, h) / 50; + int cx = w / 2; + int cy = h / 2; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setStroke(new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); + g2.setPaint(Color.BLACK); + g2.rotate(Math.PI * mAngle / 180, cx, cy); + for (int i = 0; i < lines; i++) { + float scale = (11.0f - (float) i) / 11.0f; + g2.drawLine(cx + s, cy, cx + s * 2, cy); + g2.rotate(-Math.PI / 6, cx, cy); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, scale * fade)); + } + g2.dispose(); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (mIsRunning) { + repaint(); + mAngle += angleAdd; + if (mAngle >= maxAngle) { + mAngle = 0; + } + if (mIsFadingOut) { + if (--mFadeCount == 0) { + mIsRunning = false; + mTimer.stop(); + } + } else if (mFadeCount < mFadeLimit) { + mFadeCount++; + } + } + } + + public void start() { + if (mIsRunning) { + return; + } + mIsRunning = true; + mIsFadingOut = false; + mFadeCount = 0; + int fps = 24; + int tick = 1000 / fps; + mTimer = new Timer(tick, this); + mTimer.start(); + } + + public void stop() { + mIsRunning = false; + mIsFadingOut = true; } }