Skip to content

Commit c205f30

Browse files
committed
修改Mac下初始化头像BUG
1 parent 14ae977 commit c205f30

File tree

11 files changed

+370
-10
lines changed

11 files changed

+370
-10
lines changed

conf/nbs.db

0 Bytes
Binary file not shown.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.nbs.client.ui.components.common;
2+
3+
import io.nbs.client.cnsts.ColorCnst;
4+
import io.nbs.client.cnsts.FontUtil;
5+
import io.nbs.client.ui.components.GBC;
6+
import io.nbs.commons.utils.IconUtil;
7+
import net.miginfocom.swing.MigLayout;
8+
9+
import javax.swing.*;
10+
import java.awt.*;
11+
12+
/**
13+
* @Package : io.nbs.client.ui.components.common
14+
* @Description : <p></p>
15+
* @Author : lambor.c
16+
* @Date : 2018/7/17-10:23
17+
* Copyright (c) 2018, NBS , lambor.c<[email protected]>.
18+
* All rights reserved.
19+
*/
20+
public class DownLoadTipIconPanel extends JPanel {
21+
private JCirclePanel circlePanel;
22+
private JLabel textLabel;
23+
public DownLoadTipIconPanel(JCirclePanel circlePanel) {
24+
initComponents(circlePanel);
25+
initView();
26+
}
27+
28+
private void initComponents(JCirclePanel circlePanel){
29+
textLabel = new JLabel("Download Task:");
30+
textLabel.setHorizontalAlignment(JLabel.RIGHT);
31+
textLabel.setFont(FontUtil.getDefaultFont(16));
32+
textLabel.setForeground(ColorCnst.FONT_ABOUT_TITLE_BLUE);
33+
textLabel.setOpaque(false);
34+
this.circlePanel = circlePanel;
35+
36+
}
37+
38+
private void initView(){
39+
setLayout(new FlowLayout(FlowLayout.RIGHT,0,2));
40+
this.add(textLabel);
41+
this.add(circlePanel);
42+
}
43+
44+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package io.nbs.client.ui.components.common;
2+
3+
import io.nbs.client.cnsts.FontUtil;
4+
5+
import javax.swing.*;
6+
import java.awt.*;
7+
8+
/**
9+
* @Package : io.nbs.client.ui.components.common
10+
* @Description : <p></p>
11+
* @Author : lambor.c
12+
* @Date : 2018/7/17-13:12
13+
* Copyright (c) 2018, NBS , lambor.c<[email protected]>.
14+
* All rights reserved.
15+
*/
16+
public class JCirclePanel extends JPanel {
17+
private int r = 10;
18+
public final static Color DEF_COLOR = new Color(255,102,99);
19+
private Color color;
20+
private JLabel tip;
21+
22+
private int num = 0;
23+
24+
public JCirclePanel(int r, Color color) {
25+
this.r = r;
26+
this.color = color;
27+
initComponents();
28+
}
29+
30+
public JCirclePanel(int r) {
31+
this(r,DEF_COLOR);
32+
}
33+
34+
private void initComponents(){
35+
this.setLayout(new BorderLayout());
36+
37+
tip = new JLabel("3");
38+
tip.setFont(FontUtil.getDefaultFont(10,Font.BOLD));
39+
tip.setForeground(Color.WHITE);
40+
tip.setOpaque(false);
41+
tip.setHorizontalAlignment(JLabel.CENTER);
42+
this.add(tip,BorderLayout.CENTER);
43+
}
44+
45+
@Override
46+
public void paintComponent(Graphics g){
47+
g.setColor(this.color);
48+
int w = this.getWidth();
49+
int h = this.getHeight();
50+
g.fillOval(w/2-r,h/2-r,2*r,2*r);
51+
}
52+
53+
public int getR() {
54+
return r;
55+
}
56+
57+
public void setR(int r) {
58+
this.r = r;
59+
this.repaint();
60+
}
61+
62+
public Color getColor() {
63+
return color;
64+
}
65+
66+
public void setColor(Color color) {
67+
this.color = color;
68+
this.repaint();
69+
}
70+
71+
public int getNum() {
72+
return num;
73+
}
74+
75+
public void setNum(int num) {
76+
this.num = num;
77+
this.setVisible(true);
78+
this.setToolTipText("有"+num+"个文件正在下载.");
79+
this.repaint();
80+
}
81+
82+
83+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package io.nbs.client.ui.components.common;
2+
3+
import io.nbs.client.cnsts.ColorCnst;
4+
import io.nbs.client.cnsts.FontUtil;
5+
6+
import javax.swing.*;
7+
import java.awt.*;
8+
import java.awt.image.BufferedImage;
9+
10+
/**
11+
* @Package : io.nbs.client.ui.components.common
12+
* @Description : <p></p>
13+
* @Author : lambor.c
14+
* @Date : 2018/7/17-10:45
15+
* Copyright (c) 2018, NBS , lambor.c<[email protected]>.
16+
* All rights reserved.
17+
*/
18+
public class JImageBGPanel extends JPanel {
19+
private static final long serialVersionUID = 5456195237081251666L;
20+
/**
21+
* 居中
22+
*/
23+
public static final int CENTER = 0;
24+
/**
25+
* 平铺
26+
*/
27+
public static final int TILED = 1;
28+
/**
29+
* 拉伸
30+
*/
31+
public static final int SCALED = 2;
32+
33+
private int backgroundMode = 0;
34+
35+
private Image backgroundImage;
36+
37+
private JLabel text;
38+
39+
public JImageBGPanel() {
40+
this(null,0);
41+
}
42+
43+
/**
44+
*
45+
* @param backgroundImage
46+
* @param backgroundMode
47+
*/
48+
public JImageBGPanel(Image backgroundImage,int backgroundMode) {
49+
super();
50+
this.backgroundMode = backgroundMode;
51+
this.backgroundImage = backgroundImage;
52+
}
53+
54+
public JImageBGPanel(Image backgroundImage) {
55+
this(backgroundImage,0);
56+
}
57+
58+
public Image getBackgroundImage() {
59+
return backgroundImage;
60+
}
61+
62+
public void setBackgroundImage(Image backgroundImage) {
63+
this.backgroundImage = backgroundImage;
64+
this.repaint();
65+
}
66+
67+
private void initComponets(){
68+
text = new JLabel("5");
69+
text.setOpaque(true);
70+
text.setForeground(ColorCnst.FONT_WHITE);
71+
text.setFont(FontUtil.getDefaultFont(10));
72+
text.setHorizontalAlignment(JLabel.CENTER);
73+
}
74+
75+
public void setText(String textTip) {
76+
if(this.text!=null){
77+
this.text.setText(textTip);
78+
this.updateUI();
79+
}
80+
}
81+
82+
public int getBackgroundMode() {
83+
return backgroundMode;
84+
}
85+
86+
public void setBackgroundMode(int backgroundMode) {
87+
switch (backgroundMode){
88+
case 0:
89+
case 1:
90+
case 2:
91+
this.backgroundMode = backgroundMode;
92+
this.repaint();
93+
break;
94+
default:
95+
break;
96+
}
97+
98+
}
99+
100+
@Override
101+
protected void paintComponent(Graphics g) {
102+
super.paintComponent(g);
103+
if(backgroundImage!=null){
104+
int compWidth = this.getWidth();
105+
int compHeight = this.getHeight();
106+
int imgWidth = backgroundImage.getWidth(this);
107+
int imgHeight = backgroundImage.getHeight(this);
108+
109+
switch (this.backgroundMode){
110+
case 0 :
111+
{
112+
//float oScale = imgWidth*1.0F/imgWidth;
113+
// int nImageW = imgWidth,nImageH = imgHeight;
114+
BufferedImage bufImage = new BufferedImage(compWidth,compHeight,BufferedImage.TYPE_INT_RGB);
115+
Graphics2D g2d = bufImage.createGraphics();
116+
int x = (compWidth-imgWidth)/2;
117+
int y = (compHeight-imgHeight)/2;
118+
119+
g2d.drawImage(backgroundImage,x,y,null);
120+
121+
g2d.dispose();
122+
123+
g.drawImage(bufImage,0,0,null);
124+
break;
125+
}
126+
case 1:
127+
{
128+
for(int ix=0;ix<compWidth;ix += imgWidth){
129+
for(int iy=0;iy<compHeight;iy += imgHeight){
130+
g.drawImage(backgroundImage,ix,iy,this);
131+
}
132+
}
133+
break;
134+
}
135+
case 2:
136+
{
137+
g.drawImage(backgroundImage,0,0,compWidth,compHeight,this);
138+
break;
139+
}
140+
default:
141+
break;
142+
}
143+
}
144+
}
145+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package io.nbs.client.ui.components.common;
2+
3+
import javax.swing.border.Border;
4+
import java.awt.*;
5+
6+
/**
7+
* @Package : io.nbs.client.ui.components.common
8+
* @Description : <p></p>
9+
* @Author : lambor.c
10+
* @Date : 2018/7/17-13:13
11+
* Copyright (c) 2018, NBS , lambor.c<[email protected]>.
12+
* All rights reserved.
13+
*/
14+
public class JRoundBorder implements Border {
15+
private Color color;
16+
17+
18+
public JRoundBorder(Color color) {
19+
this.color = color;
20+
}
21+
22+
public JRoundBorder() {
23+
initColor();
24+
}
25+
26+
27+
28+
private void initColor(){
29+
this.color = new Color(255,102,99);
30+
}
31+
32+
33+
@Override
34+
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
35+
g.setColor(color);
36+
int cW = 0,cH=0;
37+
if(c!=null){
38+
cW = c.getWidth();
39+
cH = c.getHeight();
40+
}
41+
int arcWidth = cW/2;
42+
int arcHeight = cH/2;
43+
g.drawRoundRect(0,0,cW,cH,arcWidth,arcHeight);
44+
45+
}
46+
47+
@Override
48+
public Insets getBorderInsets(Component c) {
49+
return new Insets(0,0,0,0);
50+
}
51+
52+
@Override
53+
public boolean isBorderOpaque() {
54+
return false;
55+
}
56+
}

src/main/java/io/nbs/client/ui/frames/InitialFrame.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,17 @@ private void initComponents(){
163163
JPanel editLeft = new JPanel(){
164164
@Override
165165
protected void paintComponent(Graphics g) {
166+
super.paintComponent(g);
167+
if(getIconImage()==null)
168+
return;
166169
Image icon = getIconImage();
167170
ImageIcon imageIcon = new ImageIcon(icon);
168171
if(icon != null){
169172
g.drawImage(icon,0,0,getWidth(),getHeight(),imageIcon.getImageObserver());
170173
}
171-
super.paintComponent(g);
174+
}
175+
176+
public void setIcon(ImageIcon icon){
172177

173178
}
174179
};

src/main/java/io/nbs/client/ui/panels/TitlePanel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package io.nbs.client.ui.panels;
22

33
import io.nbs.client.Launcher;
4-
import io.nbs.client.listener.AbstractMouseListener;
54
import io.nbs.client.cnsts.ColorCnst;
5+
import io.nbs.client.listener.AbstractMouseListener;
6+
67
import io.nbs.client.cnsts.FontUtil;
78
import io.nbs.client.cnsts.OSUtil;
89
import io.nbs.client.ui.components.GBC;
910
import io.nbs.client.ui.frames.MainFrame;
1011

12+
1113
import javax.swing.*;
1214
import java.awt.*;
1315
import java.awt.event.*;

0 commit comments

Comments
 (0)