Browse Source
* commit '12b5356c1251bf34a439930e50777d71532aea8d': 国际化 rt REPORT-8813 设计器启动增加加载工程的loadingmaster
zack
7 years ago
11 changed files with 355 additions and 27 deletions
@ -0,0 +1,83 @@
|
||||
package com.fr.design.gui.iprogressbar; |
||||
|
||||
import com.fr.design.utils.ThemeUtils; |
||||
|
||||
import javax.swing.LookAndFeel; |
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.RenderingHints; |
||||
import java.awt.geom.RoundRectangle2D; |
||||
|
||||
/** |
||||
* 新进度条UI(暂时只处理了非模糊场景) |
||||
* Created by zack on 2018/6/21. |
||||
*/ |
||||
public class ModernUIProgressBarUI extends UIProgressBarUI { |
||||
// draw determinate
|
||||
@Override |
||||
protected void drawXpHorzProgress(Graphics g, int x, int y, |
||||
int w, int h, int amountFull) { |
||||
Graphics2D g2d = (Graphics2D) g; |
||||
g2d.translate(x, y); |
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
||||
if (!progressBar.isOpaque()) { |
||||
//绘制进度条背板
|
||||
g2d.setColor(progressBar.getBackground()); |
||||
RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, w, h, 10, 10); |
||||
g2d.fill(roundedRectangle); |
||||
} |
||||
//
|
||||
g2d.setColor(progressBar.getForeground()); |
||||
int mx = 0; |
||||
while (mx < amountFull) { |
||||
RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, amountFull, h, 10, 10); |
||||
g2d.fill(roundedRectangle); |
||||
mx += 8; |
||||
} |
||||
g2d.translate(-x, -y); |
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
||||
} |
||||
|
||||
|
||||
// draw determinate
|
||||
@Override |
||||
protected void drawXpVertProgress(Graphics g, int x, int y, |
||||
int w, int h, int amountFull) { |
||||
Graphics2D g2d = (Graphics2D) g; |
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
||||
g2d.translate(x, y); |
||||
// paint the track
|
||||
if (!progressBar.isOpaque()) { |
||||
g.setColor(progressBar.getBackground()); |
||||
RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, w, h, 10, 10); |
||||
g2d.fill(roundedRectangle); |
||||
} |
||||
// paints bottom to top...
|
||||
int my = 0; |
||||
while (my < amountFull) { |
||||
RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, w, amountFull, 10, 10); |
||||
g2d.fill(roundedRectangle); |
||||
my += 8; |
||||
} |
||||
g.translate(-x, -y); |
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
||||
} |
||||
|
||||
@Override |
||||
protected Color getSelectionForeground() { |
||||
return ThemeUtils.PROCESS_SELECTED_FORECOLOR; |
||||
} |
||||
|
||||
@Override |
||||
protected Color getSelectionBackground() { |
||||
return ThemeUtils.PROCESS_SELECTED_BACKCOLOR; |
||||
} |
||||
|
||||
@Override |
||||
protected void installDefaults() { |
||||
LookAndFeel.installBorder(progressBar, "ProgressBar.border"); |
||||
LookAndFeel.installColorsAndFont(progressBar, |
||||
"ProgressBar.modern.background", "ProgressBar.modern.foreground", "ProgressBar.font"); |
||||
} |
||||
} |
@ -0,0 +1,80 @@
|
||||
package com.fr.design.gui.iprogressbar; |
||||
|
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.dialog.UIDialog; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.general.FRFont; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.JDialog; |
||||
import javax.swing.JLabel; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JProgressBar; |
||||
import javax.swing.plaf.ColorUIResource; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Dimension; |
||||
import java.awt.Frame; |
||||
|
||||
/** |
||||
* 加载进度弹窗 |
||||
*/ |
||||
public class ProgressDialog extends UIDialog { |
||||
private JProgressBar progressBar; |
||||
private JDialog centerDialog; |
||||
private JLabel text; |
||||
|
||||
public ProgressDialog(Frame parent) { |
||||
super(parent); |
||||
setUndecorated(true); |
||||
setSize(parent.getSize()); |
||||
setLocationRelativeTo(null); |
||||
setOpacity(0.5f); |
||||
initComponent(); |
||||
} |
||||
|
||||
private void initComponent() { |
||||
|
||||
centerDialog = new JDialog(this); |
||||
centerDialog.setSize(new Dimension(482, 124)); |
||||
centerDialog.setUndecorated(true); |
||||
GUICoreUtils.centerWindow(centerDialog); |
||||
JPanel panel = new JPanel(); |
||||
panel.setBorder(new UIProgressBorder(3, UIConstants.DEFAULT_BG_RULER, 14, 46, 47, 37, 47)); |
||||
panel.setLayout(new BorderLayout(4, 15)); |
||||
progressBar = new JProgressBar(); |
||||
progressBar.setUI(new ModernUIProgressBarUI()); |
||||
progressBar.setBorderPainted(false); |
||||
progressBar.setOpaque(false); |
||||
progressBar.setBorder(null); |
||||
panel.add(progressBar, BorderLayout.CENTER); |
||||
text = new UILabel(Inter.getLocText("Fine-Designer_Loading_Project"), JLabel.CENTER); |
||||
FRFont font = FRFont.getInstance().applySize(14).applyForeground(new ColorUIResource(333334)); |
||||
text.setFont(font); |
||||
panel.add(text, BorderLayout.SOUTH); |
||||
centerDialog.getContentPane().add(panel); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void checkValid() throws Exception { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void setVisible(boolean b) { |
||||
super.setVisible(b); |
||||
centerDialog.setVisible(b); |
||||
centerDialog.setResizable(false); |
||||
} |
||||
|
||||
public void setProgressValue(int value) { |
||||
progressBar.setValue(value); |
||||
} |
||||
|
||||
@Override |
||||
public void dispose() { |
||||
centerDialog.dispose(); |
||||
super.dispose(); |
||||
} |
||||
} |
@ -0,0 +1,93 @@
|
||||
package com.fr.design.gui.iprogressbar; |
||||
|
||||
import com.fr.design.border.UIRoundedBorder; |
||||
|
||||
import java.awt.AlphaComposite; |
||||
import java.awt.BasicStroke; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Insets; |
||||
import java.awt.RenderingHints; |
||||
import java.awt.geom.RoundRectangle2D; |
||||
|
||||
/** |
||||
* 进度条带阴影的边框 |
||||
*/ |
||||
public class UIProgressBorder extends UIRoundedBorder { |
||||
private int left; |
||||
private int right; |
||||
private int top; |
||||
private int bottom; |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
public UIProgressBorder(Color color) { |
||||
super(color); |
||||
} |
||||
|
||||
public UIProgressBorder(Color color, int thickness) { |
||||
super(color, thickness); |
||||
} |
||||
|
||||
public UIProgressBorder(Color color, int thickness, int roundedCorners) { |
||||
super(color, thickness, roundedCorners); |
||||
} |
||||
|
||||
public UIProgressBorder(int lineStyle, Color color, int roundedCorners) { |
||||
super(lineStyle, color, roundedCorners); |
||||
} |
||||
|
||||
public UIProgressBorder(int lineStyle, Color color, int roundedCorners, int top, int left, int bottom, int right) { |
||||
super(lineStyle, color, roundedCorners); |
||||
this.top = top; |
||||
this.right = right; |
||||
this.bottom = bottom; |
||||
this.left = left; |
||||
} |
||||
|
||||
@Override |
||||
public Insets getBorderInsets(Component c) { |
||||
Insets insets = new Insets(top, left, bottom, right); |
||||
return insets; |
||||
} |
||||
|
||||
@Override |
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
||||
Color oldColor = g.getColor(); |
||||
|
||||
Graphics2D g2d = (Graphics2D) g; |
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
||||
g2d.setColor(getLineColor()); |
||||
g2d.fill(new RoundRectangle2D.Double(x, y, width, height, 0, 0)); |
||||
g2d.setColor(oldColor); |
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
||||
paintBorderShadow(g2d, 7, x, y, width, height); |
||||
|
||||
g2d.setColor(oldColor); |
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1f)); |
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
||||
} |
||||
|
||||
private void paintBorderShadow(Graphics2D g2, int shadowWidth, int x, int y, int width, int height) { |
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
||||
shadowWidth = Math.max(shadowWidth, 2); |
||||
int sw = shadowWidth; |
||||
for (int i = sw; i > 0; i--) { |
||||
float pct = (float) (sw - i) / (sw - 1); |
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.01f * i)); |
||||
g2.setColor(getMixedColor(Color.LIGHT_GRAY, 1.0f - pct, Color.WHITE, pct)); |
||||
g2.setStroke(new BasicStroke(i)); |
||||
g2.draw(new RoundRectangle2D.Double(x, y, width, height, getRoundedCorner(), getRoundedCorner())); |
||||
} |
||||
} |
||||
|
||||
private static Color getMixedColor(Color c1, float pct1, Color c2, float pct2) { |
||||
float[] clr1 = c1.getComponents(null); |
||||
float[] clr2 = c2.getComponents(null); |
||||
for (int i = 0; i < clr1.length; i++) { |
||||
clr1[i] = (clr1[i] * pct1) + (clr2[i] * pct2); |
||||
} |
||||
return new Color(clr1[0], clr1[1], clr1[2], clr1[3]); |
||||
} |
||||
} |
Loading…
Reference in new issue