Browse Source

REPORT-51304 保存时gif背景为透明时 锯齿太严重 通过代码来绘制

feature/10.0
hades 4 years ago
parent
commit
1ddcc02f7e
  1. 2
      designer-base/src/main/java/com/fr/design/mainframe/DesktopCardPane.java
  2. 98
      designer-base/src/main/java/com/fr/design/mainframe/TransparentPane.java

2
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() { public void showCover() {
transparentPane.start();
layeredPane.moveToFront(transparentPane); layeredPane.moveToFront(transparentPane);
DesignerContext.getDesignerFrame().refreshUIToolBar(); DesignerContext.getDesignerFrame().refreshUIToolBar();
} }
public void hideCover() { public void hideCover() {
transparentPane.stop();
layeredPane.moveToFront(component); layeredPane.moveToFront(component);
} }

98
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.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import java.awt.AlphaComposite; import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Composite; import java.awt.Composite;
@ -11,23 +12,34 @@ import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.LayoutManager; 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.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.Timer;
/** /**
* @author hades * @author hades
* @version 10.0 * @version 10.0
* Created by hades on 2021/4/12 * 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 UILabel label;
private AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); 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() { public TransparentPane() {
@ -41,10 +53,7 @@ public class TransparentPane extends JComponent {
setLayout(getCoverLayout()); setLayout(getCoverLayout());
setBackground(null); setBackground(null);
setOpaque(false); setOpaque(false);
loadingLabel = new UILabel(LOADING_ICON);
label = new UILabel(Toolkit.i18nText("Fine-Design_Saving_Template_Tip")); label = new UILabel(Toolkit.i18nText("Fine-Design_Saving_Template_Tip"));
add(loadingLabel);
add(label); add(label);
} }
@ -69,16 +78,11 @@ public class TransparentPane extends JComponent {
public void layoutContainer(Container parent) { public void layoutContainer(Container parent) {
int width = parent.getParent().getWidth(); int width = parent.getParent().getWidth();
int height = parent.getParent().getHeight(); 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 labelWidth = label.getPreferredSize().width;
int labelHeight = label.getPreferredSize().height; int labelHeight = label.getPreferredSize().height;
int labelX = (width - labelWidth) / 2; int labelX = (width - labelWidth) / 2;
int labelY = (height - labelHeight) / 2 + loadingLabelHeight; int labelY = (int) ((height - labelHeight) * prec);
label.setBounds(labelX, labelY, labelWidth, labelHeight); label.setBounds(labelX, labelY, labelWidth, labelHeight);
loadingLabel.setBounds(buttonX, buttonY, loadingLabelWidth, loadingLabelHeight);
} }
@Override @Override
@ -90,13 +94,69 @@ public class TransparentPane extends JComponent {
@Override @Override
public void paint(Graphics g) { public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g; int w = this.getWidth();
Composite oldComposite = g2d.getComposite(); int h = this.getHeight();
g2d.setComposite(composite);
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setComposite(oldComposite);
super.paint(g); 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;
} }
} }

Loading…
Cancel
Save