Skip to content

Commit c6b01cc

Browse files
committed
调整图片上传后第二次不刷新
1 parent 0fce7ae commit c6b01cc

File tree

16 files changed

+136
-75
lines changed

16 files changed

+136
-75
lines changed

conf/nbs.db

0 Bytes
Binary file not shown.

src/main/java/io/nbs/client/Launcher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void launch(){
9696
try{
9797
ipfs = new IPFS(cfgHelper.getIPFSAddress());
9898
boolean first = needInitConfig(ipfs);
99-
// first = true;
99+
//first = true;
100100
if(first){
101101
currentFrame = new InitialFrame(ipfs);
102102
}else {
@@ -156,6 +156,8 @@ private boolean needInitConfig(IPFS ipfs) throws IOException {
156156
currentPeer.setAvatar(avatar.toString());
157157
currentPeer.setAvatarSuffix(avatarSuffix.toString());
158158
}
159+
Object avatarName = cfg.get(ConfigurationHelper.JSON_AVATAR_NAME_KEY);
160+
if(avatarName!=null)currentPeer.setAvatarName((String)avatarName);
159161
return false;
160162
}else {
161163
return true;

src/main/java/io/nbs/client/adapter/ContactsItemAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ public AvatarViewHolder onCreateHeaderViewHolder(int viewType, int position) {
8282
public void onBindHeaderViewHolder(AvatarViewHolder viewHolder, int position) {
8383
ContactsAvatarViewHolder holder = (ContactsAvatarViewHolder) viewHolder;
8484
holder.setPreferredSize(new Dimension(100, 25));
85-
holder.setBackground(ColorCnst.ITEM_SELECTED_LIGHT);
86-
holder.setBorder(new NbsBorder(NbsBorder.BOTTOM));
85+
holder.setBackground(ColorCnst.CONTACTS_ITEM_GRAY_MAIN);//字母分类背景
86+
holder.setBorder(new NbsBorder(NbsBorder.BOTTOM,ColorCnst.CONTACTS_ITEM_LINE_GRAY));
8787
holder.setOpaque(true);
8888

8989
holder.letterLabel = new JLabel();
9090
holder.letterLabel.setText(holder.getLetter());
91-
holder.letterLabel.setForeground(ColorCnst.FONT_GRAY);
91+
holder.letterLabel.setForeground(ColorCnst.FONT_GRAY_DARKER);
9292

9393
holder.setLayout(new BorderLayout());
9494
holder.add(holder.letterLabel, BorderLayout.WEST);

src/main/java/io/nbs/client/cnsts/ColorCnst.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,23 @@ public class ColorCnst {
2020
public static Color WINDOW_BACKGROUND = new Color(238, 238, 238);
2121
public static final Color WINDOW_BACKGROUND_LIGHT = new Color(250, 250, 250);
2222

23-
public static Color SCROLL_BAR_TRACK_LIGHT = new Color(214, 214, 214);
23+
2424
public static Color FONT_WHITE = new Color(255, 255, 255);
2525
public static Color FONT_GRAY = new Color(152, 152, 152);
2626
public static Color FONT_GRAY_DARKER = new Color(152, 152, 152);
2727
public static Color DARKER = new Color(38, 41, 46);
2828
public static Color ITEM_SELECTED_DARK = new Color(57, 63, 68);
2929
public static Color ITEM_SELECTED = new Color(65, 71, 78);
30-
public static Color ITEM_SELECTED_LIGHT = new Color(228, 228, 228);
31-
public static Color LIGHT_GRAY = new Color(222, 222, 222);
30+
public static Color ITEM_SELECTED_LIGHT = new Color(168, 168, 168);
31+
public static Color LIGHT_GRAY = new Color(228, 228, 228);
3232
public static Color DIALOG_BORDER = new Color(204, 204, 204);
3333
public static Color PROGRESS_BAR_START = new Color(178, 226, 129);
3434
public static Color PROGRESS_BAR_END = new Color(133, 194, 97);
3535
public static Color MAIN_COLOR = new Color(54, 172, 72);
3636
public static Color MAIN_COLOR_DARKER = new Color(51, 154, 69);
3737
public static final Color SCROLL_BAR_THUMB = new Color(122, 122, 122);
3838
public static final Color SCROLL_BAR_TTRACK = new Color(175, 175, 175);
39+
public static Color SCROLL_BAR_TRACK_LIGHT = new Color(214, 214, 214);
3940

4041
public static final Color CONTACTS_ITEM_GRAY_MAIN = new Color(221, 221, 221);
4142
public static final Color CONTACTS_ITEM_LINE_GRAY = new Color(207, 207, 207);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.nbs.client.ui.components;
2+
3+
import javax.swing.*;
4+
import java.io.File;
5+
6+
/**
7+
* @Package : io.nbs.client.ui.components
8+
* @Description : <p></p>
9+
* @Author : lambor.c
10+
* @Date : 2018/7/2-13:51
11+
* Copyright (c) 2018, NBS , lambor.c<[email protected]>.
12+
* All rights reserved.
13+
*/
14+
public class EditableAvatarPanel extends JPanel {
15+
private static EditableAvatarPanel context;
16+
private static String text;
17+
18+
private NBSButton editorBTN;
19+
private File selectFile;
20+
21+
private int imageMaxW = 200;
22+
private int imageMaxH = 200;
23+
24+
25+
public static EditableAvatarPanel getContext() {
26+
return context;
27+
}
28+
29+
/**
30+
* 自适应图片
31+
*/
32+
class ImageAdjustLabel extends JLabel
33+
{
34+
35+
}
36+
}

src/main/java/io/nbs/client/ui/components/NbsListView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void setScrollHiddenOnMouseLeave(JComponent jComponent){
7979
scrollMouseListener = new MouseAdapter() {
8080
@Override
8181
public void mouseEntered(MouseEvent e) {
82-
setScrollBarColor(ColorCnst.SCROLL_BAR_THUMB,ColorCnst.WINDOW_BACKGROUND);
82+
setScrollBarColor(ColorCnst.SCROLL_BAR_THUMB,ColorCnst.SCROLL_BAR_TTRACK);
8383
getVerticalScrollBar().repaint();
8484
super.mouseEntered(e);
8585
}

src/main/java/io/nbs/client/ui/components/ScrollUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void setTrackColor(Color trackColor) {
5151
@Override
5252
protected void configureScrollBarColors() {
5353
//滑道
54-
setThumbBounds(0,0,3,10);
54+
setThumbBounds(0,0,2,5);
5555
}
5656

5757
/**
@@ -65,7 +65,7 @@ protected void configureScrollBarColors() {
6565
*/
6666
@Override
6767
public Dimension getPreferredSize(JComponent c) {
68-
c.setPreferredSize(new Dimension(7,0));
68+
c.setPreferredSize(new Dimension(5,0));
6969
return super.getPreferredSize(c);
7070
}
7171

src/main/java/io/nbs/client/ui/filters/ImageFileFilter.java

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.nbs.client.ui.filters;
2+
3+
import javax.swing.filechooser.FileFilter;
4+
import java.io.File;
5+
6+
/**
7+
* @Package : io.nbs.client.ui.filters
8+
* @Description : <p></p>
9+
* @Author : lambor.c
10+
* @Date : 2018/7/2-13:23
11+
* Copyright (c) 2018, NBS , lambor.c<[email protected]>.
12+
* All rights reserved.
13+
*/
14+
public class ImagesFiltFilter extends FileFilter {
15+
@Override
16+
public boolean accept(File f) {
17+
String name = f.getName();
18+
name = name.toLowerCase();
19+
return f.isDirectory()|| name.endsWith(".png")||name.endsWith("jpg")||name.endsWith("gif")||name.endsWith("jpeg");
20+
}
21+
22+
@Override
23+
public String getDescription() {
24+
return ".jpg,.jpeg,.gif,.png";
25+
}
26+
}

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.nbs.client.cnsts.ColorCnst;
1414
import io.nbs.client.cnsts.FontUtil;
1515
import io.nbs.client.cnsts.OSUtil;
16+
import io.nbs.client.ui.filters.ImagesFiltFilter;
1617
import io.nbs.commons.helper.AvatarImageHandler;
1718
import io.nbs.commons.helper.ConfigurationHelper;
1819
import io.nbs.sdk.beans.PeerInfo;
@@ -399,7 +400,10 @@ public void actionPerformed(ActionEvent e) {
399400
avatarLabel.addMouseListener(new AbstractMouseListener(){
400401
@Override
401402
public void mouseClicked(MouseEvent e) {
402-
uploadAvatar();
403+
boolean res = uploadAvatar();
404+
if(!res){
405+
406+
}
403407
super.mouseClicked(e);
404408
}
405409

@@ -535,13 +539,17 @@ private void initWorkDist(){
535539
* 64*64 .nbs/profile/avatars/thumbs/peerId
536540
* 40*40 .nbs/cache/avatars/thumbs/hash
537541
*/
538-
private void uploadAvatar(){
542+
private boolean uploadAvatar(){
539543
fileChooser = new JFileChooser();
540544
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
541545
fileChooser.showDialog(this,"选择图片");
542-
// fileChooser.setFileFilter(new ImageFileFilter());
546+
ImagesFiltFilter filtFilter = new ImagesFiltFilter();
547+
fileChooser.addChoosableFileFilter(filtFilter);
548+
fileChooser.setFileFilter(filtFilter);
549+
543550
File file = fileChooser.getSelectedFile();
544-
if(file!=null){
551+
if(file!=null)
552+
{
545553
String name = file.getName();//源文件名
546554
String avatarPeerName = tempInfo.getId() + name.substring(name.lastIndexOf("."));
547555
new Thread(()->{
@@ -550,8 +558,8 @@ private void uploadAvatar(){
550558
FileOutputStream fos = null;
551559
try {
552560
//上传前先压缩
553-
imageHandler.createdAvatar4Profile(file,avatarPeerName);
554-
File file128 = new File(AppGlobalCnst.consturactPath(AvatarImageHandler.getAvatarProfileHome(),avatarPeerName));
561+
imageHandler.createdAvatar4Profile(file,null);
562+
File file128 = new File(AppGlobalCnst.consturactPath(AvatarImageHandler.getAvatarProfileHome(),name));
555563
NamedStreamable.FileWrapper fileWrapper = new NamedStreamable.FileWrapper(file128);
556564

557565
nodes = ipfs.add(fileWrapper);
@@ -563,7 +571,7 @@ private void uploadAvatar(){
563571
String avatarFileName = fileHash+ name.substring(name.lastIndexOf("."));
564572
try {
565573
imageHandler.createContactsAvatar(file,avatarFileName);
566-
ImageIcon icon = new ImageIcon(AppGlobalCnst.consturactPath(AvatarImageHandler.getAvatarProfileHome(),avatarPeerName));
574+
ImageIcon icon = new ImageIcon(AppGlobalCnst.consturactPath(AvatarImageHandler.getAvatarProfileHome(),name));
567575
if(icon!=null){
568576
logger.info(fileHash);
569577
avatarLabel.setIcon(icon);
@@ -580,6 +588,10 @@ private void uploadAvatar(){
580588
statusPanel.setVisible(true);
581589
}
582590
}).start();
591+
return true;
592+
}else {
593+
JOptionPane.showMessageDialog(this,"请选择图片类型文件.");
594+
return false;
583595
}
584596
}
585597
}

0 commit comments

Comments
 (0)