forked from fanruan/design
kuangshuai
3 years ago
4 changed files with 115 additions and 35 deletions
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue