Skip to content

Commit e5feeb2

Browse files
committed
Merge branch 'master' of github.com:W-B-S/nbs-client-test
2 parents 42b9f34 + dec103a commit e5feeb2

File tree

16 files changed

+566
-21
lines changed

16 files changed

+566
-21
lines changed

conf/nbs.db

0 Bytes
Binary file not shown.

src/main/java/io/ipfs/api/ResData.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public ResData(String message) {
2929
this.message = message;
3030
}
3131

32+
/**
33+
* 0 success
34+
* @return
35+
*/
3236
public int getCode() {
3337
return code;
3438
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ public static Launcher getContext() {
297297
}
298298

299299
public IPFS getIpfs() {
300+
if(ipfs ==null){
301+
String apiURL = ConfigurationHelper.getInstance().getIPFSAddress();
302+
try{
303+
ipfs = new IPFS(apiURL);
304+
}catch (RuntimeException e){
305+
logger.error("未能链接上IPFS服务,请检查服务是否已停止.");
306+
}
307+
}
300308
return ipfs;
301309
}
302310

@@ -377,4 +385,8 @@ public static void destoryIPFS(){
377385
public static boolean isIpfsRuning() {
378386
return ipfsRuning;
379387
}
388+
389+
public static String getSysUser(){
390+
return System.getProperty("user.name","");
391+
}
380392
}

src/main/java/io/nbs/client/listener/IPFSFileUploader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class IPFSFileUploader {
3939
private static Logger logger = LoggerFactory.getLogger(IPFSFileUploader.class);
4040
private static IPFS ipfs;
4141
private AttachmentInfoService service;
42-
public static int MAX_SIZE = 1000*1024*1024;
42+
public static long MAX_SIZE = 2000*1024*1024;
4343
private PeerInfo cureent;
4444
private MessagePanel messagePanel;
4545
private List<MessageItem> messageItems;
@@ -66,7 +66,7 @@ public MerkleNode addFileToIPFS(File file) throws FileTooLargeException {
6666
String name = file.getName();
6767
long size = file.length();
6868
if(size>MAX_SIZE){
69-
throw new FileTooLargeException("上传文件【"+name+"】超过"+DataSizeFormatUtil.formatDataSize((long)MAX_SIZE)+"限制.");
69+
throw new FileTooLargeException("上传文件【"+name+"】超过"+DataSizeFormatUtil.formatDataSize(MAX_SIZE)+"限制.");
7070
}
7171
try {
7272
NamedStreamable.FileWrapper fileWrapper = new NamedStreamable.FileWrapper(file);
@@ -86,7 +86,7 @@ public MerkleNode addByteFileToIPFS(File file) throws FileTooLargeException {
8686
String fname = file.getName();
8787
long size = file.length();
8888
if(size>MAX_SIZE){
89-
throw new FileTooLargeException("上传文件【"+fname+"】超过"+DataSizeFormatUtil.formatDataSize((long)MAX_SIZE)+"限制.");
89+
throw new FileTooLargeException("上传文件【"+fname+"】超过"+DataSizeFormatUtil.formatDataSize(MAX_SIZE)+"限制.");
9090
}
9191
int len = (int)size;
9292
byte[] lagerBytes = new byte[len];

src/main/java/io/nbs/client/ui/components/forms/LCFormLabel.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,16 @@ private void initComponents(){
4545
public void setVolumeText(String text){
4646
this.textArea.setText(text);
4747
}
48+
49+
public void setHorizontalAlignment(int horizontalAlignment){
50+
this.label.setHorizontalAlignment(horizontalAlignment);
51+
}
52+
53+
public JLabel getLabel() {
54+
return label;
55+
}
56+
57+
public LCJTextArea getTextArea() {
58+
return textArea;
59+
}
4860
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ private void initComponents(){
164164
@Override
165165
protected void paintComponent(Graphics g) {
166166
super.paintComponent(g);
167-
if(getIconImage()==null)
167+
/* if(getIconImage()==null)
168168
return;
169169
Image icon = getIconImage();
170170
ImageIcon imageIcon = new ImageIcon(icon);
171171
if(icon != null){
172172
g.drawImage(icon,0,0,getWidth(),getHeight(),imageIcon.getImageObserver());
173-
}
173+
}*/
174174
}
175175

176176
public void setIcon(ImageIcon icon){

src/main/java/io/nbs/client/ui/panels/im/IMFileActionListener.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import io.nbs.client.exceptions.FileTooLargeException;
88
import io.nbs.client.listener.IPFSFileUploader;
99
import io.nbs.client.ui.frames.MainFrame;
10+
import io.nbs.client.ui.panels.im.messages.MessageEditorPanel;
11+
import io.nbs.commons.helper.DateHelper;
1012
import io.nbs.commons.utils.DataSizeFormatUtil;
1113
import io.nbs.sdk.beans.PeerInfo;
1214
import io.nbs.sdk.prot.IPMParser;
@@ -18,6 +20,7 @@
1820
import java.awt.event.ActionEvent;
1921
import java.awt.event.ActionListener;
2022
import java.io.File;
23+
import java.util.concurrent.atomic.AtomicInteger;
2124

2225
/**
2326
* @Package : io.nbs.client.ui.panels.im
@@ -32,6 +35,9 @@ public class IMFileActionListener implements ActionListener {
3235

3336
private IPFSFileUploader fileUploader;
3437
private AttachmentInfoService attachmentInfoService;
38+
private MessageEditorPanel editorPanel;
39+
private AtomicInteger uploading = new AtomicInteger(0);
40+
private String upfileName = "";
3541

3642
private JFileChooser jFileChooser;
3743
public IMFileActionListener(IPFSFileUploader fileUploader, JFileChooser fileChooser, SqlSession sqlSession) {
@@ -40,23 +46,42 @@ public IMFileActionListener(IPFSFileUploader fileUploader, JFileChooser fileChoo
4046
attachmentInfoService = new AttachmentInfoService(sqlSession);
4147
}
4248

49+
public IMFileActionListener(IPFSFileUploader fileUploader, JFileChooser fileChooser, SqlSession sqlSession, MessageEditorPanel editorPanel) {
50+
this.editorPanel = editorPanel;
51+
this.fileUploader = fileUploader;
52+
this.jFileChooser = fileChooser;
53+
attachmentInfoService = new AttachmentInfoService(sqlSession);
54+
}
55+
4356
@Override
4457
public void actionPerformed(ActionEvent e) {
58+
if(uploading.intValue()==1){
59+
JOptionPane.showMessageDialog(MainFrame.getContext(),"正在上传文件["+upfileName+"],请稍后再传...");
60+
return;
61+
}
4562
this.jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
4663
this.jFileChooser.showDialog(Launcher.getContext().getCurrentFrame(),"选择");
4764
File selection = jFileChooser.getSelectedFile();
4865
if(selection==null)return;
49-
logger.info(selection.getAbsolutePath());
50-
66+
this.upfileName = selection.getName();
67+
logger.info("{}在{}分享了{}",MainFrame.getContext().getCurrentPeer().getNick(),DateHelper.currentTime(),selection.getAbsolutePath());
68+
if(selection.length()>200*1024*1024){
69+
//JOptionPane.showMessageDialog(MainFrame.getContext(),"成功加入分享任务,由于文件较大需要稍等一会儿返回唯一串码.");
70+
editorPanel.setTipLabel("正在上传["+selection.getName()+"]请稍后...",true);
71+
}
72+
uploading.set(1);
5173
new Thread(()->{
5274
try {
5375
MerkleNode node = fileUploader.addFileToIPFS(selection);
76+
logger.info("添加文件成功.{}",selection.getName());
77+
editorPanel.setTipLabel(null,false);
78+
uploading.set(0);
5479
new Thread(()->{
5580
saveUploadFileInfo2DB(node);
5681
}).start();
5782
} catch (FileTooLargeException e1) {
5883
logger.error("删除文件失败,{}-{}",e1.getMessage(),e1.getCause());
59-
JOptionPane.showMessageDialog(MainFrame.getContext(),"文件太大,最大只能上传["+DataSizeFormatUtil.formatDataSize((long)IPFSFileUploader.MAX_SIZE)+"]文件。");
84+
JOptionPane.showMessageDialog(MainFrame.getContext(),"文件太大,最大只能上传["+DataSizeFormatUtil.formatDataSize(IPFSFileUploader.MAX_SIZE)+"]文件。");
6085

6186
}
6287
}).start();

src/main/java/io/nbs/client/ui/panels/im/messages/MessageEditorPanel.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class MessageEditorPanel extends ParentAvailablePanel {
3939
*/
4040
private JPanel controlLabel;
4141

42+
private static MessageEditorPanel context;
43+
4244
private JLabel fileLabel;
4345
private JLabel expressionLabel;
4446
private JLabel cutLabel;
@@ -58,15 +60,17 @@ public class MessageEditorPanel extends ParentAvailablePanel {
5860

5961
private JFileChooser jFileChooser;
6062
private IMFileActionListener imFileActionListener;
63+
private JLabel msgTipLabel;
6164

6265
/**
6366
*
6467
* @param parent
6568
*/
6669
public MessageEditorPanel(JPanel parent, IPFSFileUploader uploader) {
6770
super(parent);
71+
context = this;
6872
jFileChooser = new JFileChooser();
69-
imFileActionListener = new IMFileActionListener(uploader,jFileChooser,Launcher.getSqlSession());
73+
imFileActionListener = new IMFileActionListener(uploader,jFileChooser,Launcher.getSqlSession(),context);
7074
initComponents();
7175
initView();
7276
setListeners();
@@ -128,6 +132,9 @@ private void initComponents(){
128132
cutTip
129133
);
130134

135+
msgTipLabel = new JLabel();
136+
137+
131138
textEditor = new NBSTextEditor();
132139
textEditor.setBackground(ColorCnst.WINDOW_BACKGROUND);
133140
textEditor.setFont(FontUtil.getDefaultFont(14));
@@ -155,11 +162,22 @@ private void initComponents(){
155162

156163
private void initView(){
157164
this.setLayout(new GridBagLayout());
165+
//提示
166+
msgTipLabel.setHorizontalAlignment(JLabel.RIGHT);
167+
msgTipLabel.setBackground(ColorCnst.WINDOW_BACKGROUND);
168+
msgTipLabel.setForeground(ColorCnst.RED);
169+
msgTipLabel.setVisible(false);
170+
171+
msgTipLabel.setFont(FontUtil.getDefaultFont(10));
172+
158173
controlLabel.add(expressionLabel);
159174
controlLabel.add(fileIcon);
175+
controlLabel.add(msgTipLabel);
160176
//隐藏截图
161177
//controlLabel.add(cutIcon);
162178

179+
180+
163181
add(controlLabel,new GBC(0,0).setFill(GBC.HORIZONTAL).setWeight(1,1));
164182
add(textScrollPane,new GBC(0,1).setFill(GBC.BOTH).setWeight(1,15));
165183
add(sendPanel,new GBC(0,2)
@@ -258,4 +276,10 @@ public NBSButton getSendButton() {
258276
}
259277

260278

279+
public void setTipLabel(String msg,boolean visabled){
280+
if(msg==null)msg="";
281+
this.msgTipLabel.setText(msg);
282+
this.msgTipLabel.setVisible(visabled);
283+
this.controlLabel.updateUI();
284+
}
261285
}

src/main/java/io/nbs/client/ui/panels/manage/MMBodyPanel.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ private void setListeners() {
106106
* @param who
107107
*/
108108
public void showPanel(MMNames who){
109+
if(who==MMNames.TIP){
110+
MMMonitPanel.setCtrlSign(true);
111+
}else {
112+
tipResultHashPanel.hideMMMonitor();
113+
MMMonitPanel.setCtrlSign(false);
114+
}
109115
cardLayout.show(cardPanel,who.name());
110116
}
111117

src/main/java/io/nbs/client/ui/panels/manage/MMSearcherPanel.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import io.nbs.client.ui.components.SearchTextField;
1919
import io.nbs.client.ui.components.common.DownLoadTipIconPanel;
2020
import io.nbs.client.ui.components.common.JCirclePanel;
21+
import io.nbs.client.ui.components.forms.LCFormLabel;
2122
import io.nbs.client.ui.frames.MainFrame;
2223
import io.nbs.client.ui.panels.ParentAvailablePanel;
2324
import io.nbs.client.ui.panels.manage.body.TipResultHashPanel;
2425
import io.nbs.client.vo.AttachmentDataDTO;
26+
import io.nbs.commons.helper.DateHelper;
2527
import io.nbs.commons.utils.ButtonIconUtil;
2628
import io.nbs.commons.utils.IconUtil;
2729
import io.nbs.sdk.page.PageModel;
@@ -176,22 +178,33 @@ private void searchHash(final String text){
176178
bodyPanel.showPanel(MMBodyPanel.MMNames.TIP);
177179
IPFS ipfs = Launcher.getContext().getIpfs();
178180
TipResultHashPanel tipResultHashPanel= MMBodyPanel.getContext().getTipResultHashPanel();
179-
tipResultHashPanel.clearVol();
180181
if(tipResultHashPanel.prevousHash().equals(text))return;
182+
tipResultHashPanel.clearVol();
181183
tipResultHashPanel.setHash(multihash.toBase58());
182184
new Thread(()->{
185+
if( tipResultHashPanel.getMonitPanel()!=null){
186+
tipResultHashPanel.getMonitPanel().stopMonitor();
187+
}
183188
Multihash multihash1= Multihash.fromBase58(text);
189+
long start = System.currentTimeMillis();
184190
try {
191+
tipResultHashPanel.searchingFromIntelnet();
185192
Object o =ipfs.object.stat(multihash1);
186193
String json = JSONParser.toString(o);
187194
BlockStat stat = JSON.parseObject(json,BlockStat.class);
188-
tipResultHashPanel.setBlkStat(stat,null);
195+
long usedsecd = System.currentTimeMillis()-start;
196+
logger.info("客户端IP{}用时{}ms",MainFrame.getContext().getCurrentPeer().getIp(),usedsecd);
197+
logger.info("TESTLOG:{}>>>查找文件:{},用时{}",Launcher.getSysUser(),text,DateHelper.calcUsedTime(usedsecd));
198+
tipResultHashPanel.setBlkStat(stat,null,usedsecd);
189199
} catch (IOException e) {
190200
e.printStackTrace();
191201
logger.error(e.getMessage());
192202
String error = "没有在NBS网络世界查到你要的数据["+multihash1.toBase58()+"]";
193-
tipResultHashPanel.setBlkStat(null,error);
203+
long usedsecd = System.currentTimeMillis()-start;
204+
logger.info("TESTLOG:{}>>>查找文件:{}没有查到,用时{}",Launcher.getSysUser(),text,DateHelper.calcUsedTime(usedsecd));
205+
tipResultHashPanel.setBlkStat(null,error,usedsecd);
194206
}
207+
tipResultHashPanel.setPreousHash(text);
195208
}).start();
196209
}else {
197210
bodyPanel.showPanel(MMBodyPanel.MMNames.LISTF);

0 commit comments

Comments
 (0)