spark部分代碼分析,修改筆記

org.jivesoftware.resource  圖片聲音資料路徑



1.修改字體:各個界面類中改11為12  org.jivesoftware--Spark.java--installBaseUIProperties()--setApplicationFont(new Font("Dialog", Font.PLAIN, 12));


2.聊天窗口加“發送”按鈕:

org.jivesoftware.spark.ui--ChatRoom.java--ChatRoom()中加入如下代碼:

  button = new JButton();
        button.addActionListener(new ActionListener() {
         public void actionPerformed(final ActionEvent arg0) {
                  sendMessage();
                    getChatInputEditor().setText("");
                    getChatInputEditor().setCaretPosition(0);
       
         }
        });
        button.setBorder(new EmptyBorder(0,0,0,0));
       
        button.setText("發送");
        button.setBounds(115, 181, 106, 28);
找到init()方法,加入:
 bottomPanel.add(button, new GridBagConstraints(4, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
                GridBagConstraints.NONE, new Insets(0,0,5,10), 0, 0));


3.登錄界面修改

設置個人頭像位置路徑
/spark/src/java/org/jivesoftware/sparkimpl/profile/AvatarPanel.java

/spark/src/java/org/jivesoftware/spark/ui/status/StatusBar.java   
 imageLabel.setIcon(Default.getImageIcon(Default.MAIN_IMAGE)); //584行,修改主界面個人頭像為默認。    


登陸界面上部背景
LoginDialog.java
private final ImageIcon icons = Default.getImageIcon(Default.MAIN_IMAGE);

/spark/src/java/org/jivesoftware/resource/default.properties
default.properties--MAIN_IMAGE = images/spark.gif  //個人頭像修改

/spark/src/java/org/jivesoftware/spark/ui/status/StatusBar.java  536-596行

 mainPanel.add(imagePanel,
        new GridBagConstraints(0,0, 1, 1, 1.0, 0.0,
                     GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(40,0,40,0),24,24)); //登陸界面設置頭像大小為24x24,居中

mainPanel.add(loginPanel,
                   new GridBagConstraints(0, 2, 2, 1,
                           1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
                           new Insets(0, 0, 0, 0), 0,100));  //設置登陸框大小



//登陸界面加入狀態下拉列表
/spark/src/resources/i18n/spark_i18n_zh_CN.properties
status.online=在線   status.pending=掛起  status.on.phone=電話中   

org.jivesoftware.spark.ui.status //狀態欄包















4.個人信息
4.1
/spark/src/resources/i18n/spark_i18n_zh_CN.properties   tab.avatar 個性頭像
menuitem.edit.my.profile=編輯我的簡介 ...
menuitem.lookup.profile=查看簡介 ...
/spark/src/java/org/jivesoftware/sparkimpl/profile/VCardEditor.java 個人資料編輯對話框

/spark/src/java/org/jivesoftware/sparkimpl/profile/PersonalPanel.java 修改“個人資料”編輯對話框布局
 JLabel firstNameLabel = new JLabel();
          firstNameField = new JTextField();
          ResourceUtils.resLabel(firstNameLabel, firstNameField, Res.getString("label.first.name") + ":");
          add(firstNameLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
          add(firstNameField, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

/spark/src/java/org/jivesoftware/sparkimpl/profile/VCardEditor.java     修改“編輯我的簡介”對話框布局

label.job.title=(&J) 職務
修改對輸入內容持久化
/spark/src/java/org/jivesoftware/sparkimpl/profile/VCardEditor.java
private void fillUI(VCard vcard){
  personalPanel.setFirstName(vcard.getFirstName());
        personalPanel.setMiddleName(vcard.getMiddleName());
。。。}

  private void saveVCard() {
final VCard vcard = new VCard();
// Save personal info
vcard.setFirstName(personalPanel.getFirstName());
vcard.setLastName(personalPanel.getLastName());

。。。}



4.2加個性簽名
spark是沒有簽名功能的,為了滿足用戶的需求,需要加入簽名功能,今天搞了搞 。不是很完美,以后會慢慢的完善。 我的思路是 :利用vcard中的中間名,修改成簽名信息。

首先,要把布局修改下 workspace 中的buildlayout方法   statusbox.loadvcard 。在聲明statusbox時候,進行了statusbox界面加載。 進入org.jivesoftware.spark.ui.status.StatusBar  在 StatusBar的構造方法中 進行了如下修改

         add(statusPanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2,12, 0, 0), 0, 0));
        add(qianmingLabel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 7, 0, 0), 0, 0));
         add(commandPanel, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
  主要做的工作是 吧statuspanel移到了 nicknamelable位置,然后 把 nicknamelable加載到了statuspanel上

在statusbar中 要聲明

   private JLabel qianmingLabel = new JLabel();

添加兩個方法

   public void setQianMing(String qianming) {
        qianmingLabel.setText(qianming);
    }

    public JLabel getQianMingLabel() {
        return qianmingLabel;
    }

   String qianming=    SparkManager.getVCardManager().getVCard().getMiddleName();
     if(qianming!=null) setQianMing(qianming);

然后到statuspanel的構造方法內 進行如下修改

   add(nicknameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            add(iconLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            add(statusLabel, new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 0), 0, 0));

            statusLabel.setFont(new Font("宋體", Font.PLAIN, 11));
            statusLabel.setIcon(SparkRes.getImageIcon(SparkRes.DOWN_ARROW_IMAGE));
            statusLabel.setHorizontalTextPosition(JLabel.LEFT);
         // nicknameLabel.setToolTipText(SparkManager.getConnection().getUser());
          nicknameLabel.setFont(new Font("宋體", Font.BOLD, 12));
主要工作是把nicknamelabel 加到這個面板上。

接下來的工作就是要修改vcard了 把 中間名修改為狀態。首先,修改界面

先修改下i18  zh_CN 吧 label.middle.name 修改為 簽名信息

然后修改   把firstname  與 middlename進行位置調換

   // Handle First Name
        JLabel firstNameLabel = new JLabel();
        firstNameField = new JTextField();
        ResourceUtils.resLabel(firstNameLabel, firstNameField, Res.getString("label.first.name") + ":");

        add(firstNameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        add(firstNameField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

        // Handle Middle Name
        JLabel middleNameLabel = new JLabel();
        middleNameField = new JTextField();
        ResourceUtils.resLabel(middleNameLabel, middleNameField, Res.getString("label.middle.name") + ":");
        add(middleNameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        add(middleNameField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 

然后在 vcardeditor(org.jivesoftware.sparkimpl.profile )saveVCard() 方法 添加如下代碼

 

 vcard.setMiddleName(personalPanel.getMiddleName());
 SparkManager.getWorkspace().getStatusBar().getQianMingLabel().setText(personalPanel.getMiddleName()); //添加的代碼。 作用就是 當點擊保存的時候,進行statusbar簽名信息更新。

最好 還要修改contactitem  要進行監聽,設置簽名信息  ,當用戶修改簽名的時候也要對應的進行更新

setstatusText 這個方法已經修改成了進行簽名信息更新了 跟staus沒有任何關系了

    public void setStatusText(String status) {
        String qianming=   SparkManager.getVCardManager().getVCard(getJID()).getMiddleName();
   
        if(qianming==null||qianming.equals("")){qianming="";}
        getDescriptionLabel().setText(qianming);

//        if (ModelUtil.hasLength(status)) {
//            getDescriptionLabel().setText(" - " + status);
//        }
//        else {
//            getDescriptionLabel().setText("");
//        }
    }

 

最后 在contactitem進行處理,生成contactitem的時候,要進行簽名初始化;

 

 // 獲取簽名信息
    VCard vCard = SparkManager.getVCardManager().getVCard(fullyQualifiedJID);
    String qianming=vCard.getMiddleName();
    setStatusText(qianming);

5.設置面板。
樣式面板
/spark/src/java/org/jivesoftware/spark/ui/themes/ThemePanel.java
        add(emoticonCheckBox, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); //342行,改布局位置



6.個人簡介小窗口

/spark/src/java/org/jivesoftware/spark/ui/VCardViewer.java
204行:修改Email信息        final JLabel emailTimeLabel = new JLabel(Res.getString("label.email.address").replace("&", "") + ": ");
        add(emailTimeLabel, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 7, 2, 0), 0, 0));
        add(emailTime, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(-3,81, 2, 0), 0, 0));

230-258行:修改 部門、職務、電話、手機

7.查找搜索
/spark/src/java/org/jivesoftware/sparkimpl/search/users/SearchForm.java
311行:職務信息


8.主界面
/spark/src/java/org/jivesoftware/spark/ui/ContactInfoWindow.java




9.個人信息懸浮窗口
/spark/src/java/org/jivesoftware/spark/ui/ContactInfoWindow.java

添加郵箱信息:
417行:   
     emailAddress = vcard.getEmailHome();
         if (!ModelUtil.hasLength(emailAddress)) {
        emailAddress = Res.getString("label.na");
         }
         Color linkColor = new Color(49, 89, 151);
         final String unselectedText = "<html><body><font color=" + GraphicUtils.toHTMLColor(linkColor) + "><u>" + emailAddress + "</u></font></body></html>";
         final String hoverText = "<html><body><font color=red><u>" + emailAddress + "</u></font></body></html>";
         emailTime.setText(unselectedText);
        //鼠標事件監聽
         emailTime.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                startEmailClient(emailAddress);
            }

            public void mouseEntered(MouseEvent e) {
                emailTime.setText(hoverText);
                setCursor(LINK_CURSOR);

            }

            public void mouseExited(MouseEvent e) {
                setCursor(DEFAULT_CURSOR);
            }
        });
150行:
JLabel emailtext=new JLabel();
        emailtext.setText(Res.getString("label.email.address")+":");
        add(emailtext,new GridBagConstraints(0, 7, 4, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0,5, 2, 2), 0, 0));
        add(emailTime, new GridBagConstraints(0,7,4, 1, 1.5, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(-2,60, 2, 2), 0, 0));
        emailtext.setFont(new Font("Dialog", Font.PLAIN, 12));
        emailtext.setForeground(Color.gray);
460行:
設置窗體大小
        size.width = 300;
        size.height = 190;



10.主界面聯系人列表

/spark/src/java/org/jivesoftware/spark/ui/ContactItem.java
需要修改顯示聯系人姓名(現在顯示的是id)

資料卡中 nickname=生日,nickname可以取到,但在主窗口中取不到



11.搜索框
org.jivesoftware.spark.search/searchservice.java
93.97行,去掉鎖子圖標
//add(lockLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 15), 0, 0));


12."登陸設置"界面
/spark/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferencePanel.java
/spark/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreference.java








 本文由用戶 xilong008 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!