Skip to content

Commit d992405

Browse files
committed
增加联系人框
1 parent 5826300 commit d992405

File tree

14 files changed

+210
-23
lines changed

14 files changed

+210
-23
lines changed

config/zh-cn.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ nbs.ui.btn.about.title=\u5173\u4E8E
1616
nbs.ui.panel.status.label=PEER INFO
1717
nbs.ui.panel.about.label=About NBS Chain
1818
nbs.ui.panel.file.label=NBS FILE DATA
19-
nbs.ui.panel.im.label=\u70B9\u5BF9\u70B9\u804A\u5929
19+
nbs.ui.panel.im.label=\u5F53\u524D\u804A\u5929\uFF1A
2020
nbs.ui.panel.setting.label=\u914D\u7F6E
2121

2222
### panel label

src/main/java/UI/AppMainWindow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ private void loadEnv(){
190190
logger.info(k+"="+v);
191191
}
192192
logger.info("ENV ============================<<");
193-
NBS_FILES_ROOT_PATH = ConfigHelper.CURRENT_DIR + ConfigHelper.getNbsFilesRoot();
194-
NBS_FILES_IPFS_ROOT = NBS_FILES_ROOT_PATH + File.separator +"ipfs";
193+
NBS_FILES_ROOT_PATH = ConfigHelper.CURRENT_DIR +File.separator+ ConfigHelper.getNbsFilesRoot()+File.separator;
194+
NBS_FILES_IPFS_ROOT = NBS_FILES_ROOT_PATH +"ipfs" + File.separator;
195195
File ipfsDir = new File(NBS_FILES_IPFS_ROOT);
196196
if(ipfsDir.isDirectory()&& !ipfsDir.exists()){
197197
ipfsDir.mkdirs();

src/main/java/UI/ConstantsUI.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class ConstantsUI {
5050
*/
5151
public final static String CURRENT_DIR = System.getProperty("user.dir");
5252

53-
public final static String IPFS_PATH = CURRENT_DIR + File.separator + ".nbs_local"+ File.separator;
5453

5554
public final static String PROFILE_ROOT = CURRENT_DIR + File.separator + "profile"+ File.separator;
5655

src/main/java/UI/common/ToolbarStatsPanel.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package UI.common;
22

33
import UI.ConstantsUI;
4+
import com.nbs.entity.ContactsItem;
45
import com.nbs.tools.PropertyUtil;
56
import org.apache.commons.lang3.StringUtils;
67

@@ -18,15 +19,20 @@
1819
public class ToolbarStatsPanel extends JPanel {
1920

2021
private final JLabel titleLabel = new JLabel();
22+
private final JLabel contactsToLabel = new JLabel();
2123
public ToolbarStatsPanel(String key){
2224
titleLabel.setFont(ConstantsUI.FONT_TITLE);
2325
titleLabel.setForeground(ConstantsUI.PANEL_TITILE_COLOR);
26+
contactsToLabel.setFont(ConstantsUI.FONT_LABEL);
27+
contactsToLabel.setForeground(ConstantsUI.PANEL_TITILE_COLOR);
28+
contactsToLabel.setHorizontalAlignment(JLabel.HORIZONTAL);
2429
if(StringUtils.isNoneBlank(key)&& null != PropertyUtil.getProperty(key)){
2530
titleLabel.setText(PropertyUtil.getProperty(key));
2631
}
2732
this.setBackground(ConstantsUI.MAIN_BACK_COLOR);
28-
this.setLayout(new FlowLayout(FlowLayout.LEFT,ConstantsUI.MAIN_H_GAP,5));
33+
this.setLayout(new FlowLayout(FlowLayout.LEFT,4,5));
2934
this.add(titleLabel);
35+
this.add(contactsToLabel);
3036
}
3137

3238
/**
@@ -39,4 +45,14 @@ public void setTitle(String title){
3945
this.updateUI();
4046
}
4147

48+
/**
49+
*
50+
* @param contents
51+
*/
52+
public void resetContacts(String contents){
53+
if(StringUtils.isBlank(contents))contents = "";
54+
contactsToLabel.setText(contents);
55+
contactsToLabel.updateUI();
56+
contactsToLabel.validate();
57+
}
4258
}

src/main/java/UI/panel/im/IMPanel.java

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import UI.common.NBSAbstractPanel;
77
import UI.common.ToolbarStatsPanel;
88
import UI.templete.WihteBackJPanel;
9+
import com.nbs.entity.ContactsItem;
910
import com.nbs.entity.PeerInfoBase;
1011
import com.nbs.tools.DateHelper;
1112
import com.nbs.ui.components.ColorCnst;
@@ -28,17 +29,24 @@
2829
public class IMPanel extends NBSAbstractPanel {
2930
private static final long serialVersionUID = 1L;
3031
public static final String PKUI_PANEL_IM_LABEL = "nbs.ui.panel.im.label";
32+
private static IMPanel context;
3133

3234
/**
3335
* 在线peers
3436
*/
35-
private static JPanel peersJPanel;
36-
3737
private static JPanel peerList;
38+
/**
39+
* 左侧IM peers
40+
*/
41+
private ImLeftPanel leftPanel;
3842

3943
private static JScrollPane scrollPane;
4044

4145
private static JTextArea imMSGShow = new JTextArea();
46+
/**
47+
* 顶部显示
48+
*/
49+
private static ToolbarStatsPanel toolbarStatsPanel = new ToolbarStatsPanel(PKUI_PANEL_IM_LABEL);;
4250
/**
4351
*
4452
*/
@@ -47,6 +55,10 @@ public class IMPanel extends NBSAbstractPanel {
4755
private static JTextArea inputArea = new JTextArea();
4856

4957
private PeerInfoBase currentContactPeer = null;
58+
/**
59+
*
60+
*/
61+
private static ContactsItem CURRENT_TO_CONTACTS_ITEM = null;
5062

5163

5264

@@ -64,6 +76,7 @@ public class IMPanel extends NBSAbstractPanel {
6476

6577
public IMPanel(boolean isDoubleBuffered) {
6678
super(isDoubleBuffered);
79+
context = this;
6780
}
6881

6982
@Override
@@ -73,13 +86,11 @@ protected void init() {
7386

7487
@Override
7588
protected void addComponent() {
76-
ToolbarStatsPanel toolbarStatsPanel = new ToolbarStatsPanel(PKUI_PANEL_IM_LABEL);
7789
this.add(toolbarStatsPanel,BorderLayout.NORTH);
7890
/**
7991
*
8092
*/
8193
this.add(getCenterPanel(),BorderLayout.CENTER);
82-
8394
}
8495

8596

@@ -97,13 +108,18 @@ private JPanel getCenterPanel(){
97108
WihteBackJPanel centerPanel = new WihteBackJPanel();
98109
centerPanel.setLayout(new BorderLayout());
99110

111+
/**
112+
*
113+
*/
100114
peerList = new JPanel();
101-
peerList.setBackground(new Color(221,221,221));
102-
Dimension leftDimsnsion = new Dimension(245,ConstantsUI.MAIN_WINDOW_HEIGHT);
115+
Dimension leftDimsnsion = new Dimension(260,ConstantsUI.MAIN_WINDOW_HEIGHT);
103116
peerList.setPreferredSize(leftDimsnsion);
104117
peerList.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
105118

106-
centerPanel.add(peerList,BorderLayout.WEST);
119+
leftPanel = new ImLeftPanel();
120+
leftPanel.setPreferredSize(leftDimsnsion);
121+
122+
centerPanel.add(leftPanel,BorderLayout.WEST);
107123

108124
/**
109125
* 聊天主窗口
@@ -246,10 +262,28 @@ private void sendMsg(){
246262
} catch (Exception e) {
247263
e.printStackTrace();
248264
}
265+
}
249266

267+
public static void setCurrentToPeer(ContactsItem item){
268+
CURRENT_TO_CONTACTS_ITEM = item;
269+
}
250270

271+
/**
272+
* 切换聊天peer
273+
*/
274+
public void contactsItemChanged(ContactsItem item){
275+
//TODO
276+
CURRENT_TO_CONTACTS_ITEM = item;
277+
if(item==null)return;
278+
toolbarStatsPanel.resetContacts(item.getName());
251279

280+
}
252281

253-
282+
/**
283+
*
284+
* @return
285+
*/
286+
public static IMPanel getContext() {
287+
return context;
254288
}
255289
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package UI.panel.im;
2+
3+
import com.nbs.ui.components.ColorCnst;
4+
import com.nbs.ui.components.GBC;
5+
import com.nbs.ui.panels.ListPanel;
6+
import com.nbs.ui.panels.SearchPanel;
7+
8+
import javax.swing.*;
9+
import java.awt.*;
10+
11+
/**
12+
* @Package : UI.panel.im
13+
* @Description : <p></p>
14+
* @Author : lambor.c
15+
* @Date : 2018/6/24-10:36
16+
* Copyright (c) 2018, NBS , lambor.c<[email protected]>.
17+
* All rights reserved.
18+
*/
19+
public class ImLeftPanel extends JPanel {
20+
21+
private SearchPanel searchPanel;
22+
23+
/**
24+
* contact list or other
25+
*/
26+
private ListPanel listPanel;
27+
28+
public ImLeftPanel() {
29+
initComponents();
30+
initView();
31+
}
32+
33+
private void initComponents(){
34+
35+
searchPanel = new SearchPanel(this);
36+
37+
listPanel = new ListPanel(this);
38+
listPanel.setBackground(ColorCnst.FONT_GRAY);
39+
}
40+
41+
private void initView(){
42+
this.setBackground(ColorCnst.FONT_GRAY);
43+
this.setLayout(new GridBagLayout());
44+
45+
//add(searchPanel,new GBC(0,0).setFill(GBC.BOTH).setAnchor(GBC.CENTER).setWeight(1,7));
46+
add(listPanel,new GBC(0,1).setAnchor(GBC.CENTER).setFill(GBC.BOTH).setWeight(1,2));
47+
}
48+
49+
public ListPanel getListPanel() {
50+
return listPanel;
51+
}
52+
}

src/main/java/com/nbs/tools/ConfigHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ConfigHelper {
2828
* 系统当前路径
2929
*/
3030
public final static String CURRENT_DIR = System.getProperty("user.dir");
31-
private static final String CONF_ROOT = CURRENT_DIR + File.separator+"config" + File.separator;
31+
public static final String CONF_ROOT = CURRENT_DIR + File.separator+"config" + File.separator;
3232
private static final String CONF_FILE = "nbs-conf.properties";
3333
public static final String PK_SERVER_STATS = "ipfs.server.stats";
3434
public static final String PK_CFG_IPFS_ADDR = "nbs.server.address";

src/main/java/com/nbs/tools/PropertyUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
public class PropertyUtil {
2020

21+
22+
2123
/**
2224
* @Date : 2018/6/13 15:49
2325
* @Author : lanbery
@@ -30,8 +32,9 @@ public class PropertyUtil {
3032
public static String getProperty(String key){
3133
Properties props = new Properties();
3234
try{
35+
3336
InputStream in = new BufferedInputStream(
34-
new FileInputStream(CnstTools.PROPS_ROOT_PATH+"zh-cn.properties"));
37+
new FileInputStream(ConfigHelper.CONF_ROOT+"zh-cn.properties"));
3538
props.load(in);
3639
String v = props.getProperty(key);
3740
return v;

src/main/java/com/nbs/ui/adapter/ContactsItemAdapter.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.nbs.ui.adapter;
22

3+
import UI.AppMainWindow;
4+
import UI.panel.im.IMPanel;
35
import com.nbs.entity.ContactsItem;
46
import com.nbs.ui.AvatarViewHolder;
57
import com.nbs.ui.ContactsItemViewHolder;
@@ -34,6 +36,10 @@ public class ContactsItemAdapter extends BaseAdapter<ContactsItemViewHolder> {
3436
*/
3537
private ContactsItemViewHolder selectedViewHolder;
3638

39+
/**
40+
*
41+
* @param contactsItems
42+
*/
3743
public ContactsItemAdapter(List<ContactsItem> contactsItems) {
3844
this.contactsItems = contactsItems;
3945
if(contactsItems != null){
@@ -66,6 +72,11 @@ public AvatarViewHolder onCreateHeaderViewHolder(int viewType, int position) {
6672
return null;
6773
}
6874

75+
/**
76+
*
77+
* @param viewHolder
78+
* @param position
79+
*/
6980
@Override
7081
public void onBindHeaderViewHolder(AvatarViewHolder viewHolder, int position) {
7182
ContactsAvatarViewHolder holder = (ContactsAvatarViewHolder) viewHolder;
@@ -82,14 +93,19 @@ public void onBindHeaderViewHolder(AvatarViewHolder viewHolder, int position) {
8293
holder.add(holder.letterLabel, BorderLayout.WEST);
8394
}
8495

96+
/**
97+
*
98+
* @param viewHolder
99+
* @param position
100+
*/
85101
@Override
86102
public void onBindViewHolder(ContactsItemViewHolder viewHolder, int position) {
87103
viewHolders.add(position, viewHolder);
88104
ContactsItem item = contactsItems.get(position);
89105

90106
ImageIcon icon = new ImageIcon();
91107
icon.setImage(AvatarUtil.createOrLoadUserAvatar(item.getName())
92-
.getScaledInstance(30, 30, Image.SCALE_SMOOTH));
108+
.getScaledInstance(32, 32, Image.SCALE_SMOOTH));
93109
viewHolder.avatar.setIcon(icon);
94110

95111
viewHolder.roomName.setText(item.getName());
@@ -99,6 +115,10 @@ public void onBindViewHolder(ContactsItemViewHolder viewHolder, int position) {
99115
@Override
100116
public void mouseClicked(MouseEvent e)
101117
{
118+
//JOptionPane.showMessageDialog(AppMainWindow.frame,item.getName());
119+
System.out.println(this.getClass().getName()+">>>>>>>>>>>>"+item.getName());
120+
IMPanel.getContext().contactsItemChanged(item);
121+
102122
//TODO 右侧聊天面板加载切换
103123
/* RightPanel.getContext().getUserInfoPanel().setUsername(item.getName());
104124
RightPanel.getContext().showPanel(RightPanel.USER_INFO);

src/main/java/com/nbs/ui/components/NbsListView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ public void mouseReleased(MouseEvent e) {
171171
super.mouseReleased(e);
172172
}
173173

174+
175+
174176
@Override
175177
public void mouseWheelMoved(MouseWheelEvent e) {
176178
if(System.currentTimeMillis()-lastWeelTime <1000){

0 commit comments

Comments
 (0)