66
77import UI .templete .WihteBackJPanel ;
88import com .alibaba .fastjson .JSON ;
9+ import com .nbs .ipfs .IPFSHelper ;
910import com .nbs .tools .PropertyUtil ;
1011import com .nbs .tools .StringHelper ;
1112import org .apache .commons .lang3 .StringUtils ;
1516import javax .swing .*;
1617import javax .swing .table .AbstractTableModel ;
1718import java .awt .*;
19+ import java .awt .event .ActionEvent ;
20+ import java .awt .event .MouseAdapter ;
21+ import java .awt .event .MouseEvent ;
1822import java .io .File ;
1923import java .io .IOException ;
2024import java .util .Map ;
@@ -31,8 +35,6 @@ public class StatusPanel extends JPanel {
3135 private static final long serialVersionUID = 1L ;
3236 private static final Logger logger = LoggerFactory .getLogger (StatusPanel .class );
3337
34- public static boolean isRunning = false ;
35-
3638 public static final String AVATAR_IMAGE_PATH = ConstantsUI .PROFILE_ROOT +"avatars" +File .separator ;
3739
3840
@@ -101,19 +103,18 @@ private JPanel getCenterPanel(){
101103 JPanel cell11 = new WihteBackJPanel ();
102104 cell11 .setLayout (new FlowLayout (FlowLayout .LEFT ,ConstantsUI .MAIN_H_GAP ,5 ));
103105
104- String peerId = "" ;
105- try {
106- if (AppMainWindow .SERVER_STAT ){
107- Map m =AppMainWindow .ipfs .id ();
108- if (m .containsKey ("ID" ))peerId = (String ) m .get ("ID" );
109- AppMainWindow .PEER_ID = peerId ;
110- }
111- } catch (IOException e ) {
112- e .printStackTrace ();
113- }
114- String nickVal = PropertyUtil .getProperty ("nbs.ui.panel.status.default-nickname" );
106+ //头像
107+ String nickVal = StringUtils .isBlank (AppMainWindow .PROFILE_NICKNAME ) ?
108+ PropertyUtil .getProperty ("nbs.ui.panel.status.default-nickname" ) : AppMainWindow .PROFILE_NICKNAME ;
115109 ImageIcon icon = new ImageIcon (AVATAR_IMAGE_PATH + PropertyUtil .getProperty ("nbs.ui.panel.status.default-avatar" ));
116110 AvatarIconButton avatar = new AvatarIconButton (icon ,nickVal );
111+ //
112+ avatar .addActionListener (new AbstractAction () {
113+ @ Override
114+ public void actionPerformed (ActionEvent e ) {
115+ JOptionPane .showMessageDialog (AppMainWindow .frame ,"暂时不能设置头像" );
116+ }
117+ });
117118 cell11 .add (avatar );
118119
119120 firstRow .add (cell11 );
@@ -125,19 +126,38 @@ private JPanel getCenterPanel(){
125126 WihteBackJPanel peerInfo = new WihteBackJPanel ();
126127 peerInfo .setLayout (new GridLayout (2 ,1 ));
127128 //
128- JLabel nickname = new ContentJLabel (nickVal );
129- nickname .setFont (ConstantsUI .FONT_LABEL );
130- peerInfo .add (nickname );
131129
132- JLabel peerIDLabel = new ContentJLabel (PropertyUtil .getProperty ("nbs.ui.panel.status.label.peer-id" ,"PeerID:" )+peerId );
130+ JLabel nickLabel = new ContentJLabel (AppMainWindow .PROFILE_NICKNAME );
131+ nickLabel .setFont (ConstantsUI .FONT_LABEL );
132+ nickLabel .addMouseListener (new MouseAdapter () {
133+ @ Override
134+ public void mouseClicked (MouseEvent e ) {
135+ String newNick = JOptionPane .showInputDialog (AppMainWindow .frame ,"昵称" ,nickLabel .getText ());
136+ if (StringUtils .isNotBlank (newNick .trim ())&&newNick .trim ().length ()<=40 ){
137+ try {
138+ String res = IPFSHelper .getInstance ().updateNick (newNick );
139+ if (res !=null )AppMainWindow .PROFILE_NICKNAME = res ;
140+ nickLabel .setText (res );
141+ nickLabel .updateUI ();
142+ } catch (IOException e1 ) {
143+ e1 .printStackTrace ();
144+ JOptionPane .showMessageDialog (AppMainWindow .frame ,"修改失败." );
145+ }
146+ }
147+ super .mouseClicked (e );
148+ }
149+ });
150+ peerInfo .add (nickLabel );
151+
152+ JLabel peerIDLabel = new ContentJLabel (PropertyUtil .getProperty ("nbs.ui.panel.status.label.peer-id" ,"PeerID:" )+AppMainWindow .PEER_ID );
133153 peerIDLabel .setFont (ConstantsUI .FONT_NORMAL );
134154 peerInfo .add (peerIDLabel );
135155 cell11 .add (peerInfo ,BorderLayout .CENTER );
136156
137157 /**
138158 * Peer 详细信息
139159 */
140- JScrollPane scrollPane = new JScrollPane (getPeerIdInfo (peerId ),JScrollPane .VERTICAL_SCROLLBAR_AS_NEEDED ,JScrollPane .HORIZONTAL_SCROLLBAR_AS_NEEDED );
160+ JScrollPane scrollPane = new JScrollPane (getPeerIdInfo (AppMainWindow . PEER_ID ),JScrollPane .VERTICAL_SCROLLBAR_AS_NEEDED ,JScrollPane .HORIZONTAL_SCROLLBAR_AS_NEEDED );
141161 //scrollPane.setLayout(new BorderLayout());
142162 scrollPane .setBackground (ConstantsUI .MAIN_BACK_COLOR );
143163 scrollPane .setSize (ConstantsUI .MAIN_WINDOW_WIDTH -85 ,ConstantsUI .MAIN_WINDOW_HEIGHT -136 );
0 commit comments