• MessageTreePlugin.java
  1. final MessageTreeTab messageTreeTab = new MessageTreeTab();
  2. /**
  3. * Adds a tab to Spark
  4. */
  5. private void addTabToSpark(){
  6. // Get Workspace UI from SparkManager
  7. Workspace workspace = SparkManager.getWorkspace();
  8. // Retrieve the Tabbed Pane from the WorkspaceUI.
  9. SparkTabbedPane tabbedPane = workspace.getWorkspacePane();
  10. // Add own Tab.
  11. tabbedPane.addTab("消息", null,<SPAN style="COLOR: #ff0000">messageTreeTab</SPAN>);
  12. //messageTreeTab.invokeDialog();
  13. }
  • MessageTreeTab.java
  1. public class MessageTreeTab extends JPanel {
  2. private static final long serialVersionUID = -381458717030745122L;
  3. private JiveTreeNode msgType;
  4. private List<JiveTreeNode> groupNodes = new ArrayList<JiveTreeNode>();
  5. private MessageTree msgTree;
  6. private JiveTable messageType;
  7. public MessageTreeTab(){
  8. setLayout(new GridBagLayout());
  9. msgType = new JiveTreeNode("分类");
  10. msgTree = <SPAN style="COLOR: #ff0000">new MessageTree</SPAN>(msgType);
  11. msgTree.setPreferredSize(new Dimension(150, 400));
  12. String groupName = Res.getString("status.online");
  13. String[] headers = new String[]{"类型","时间","内容"};
  14. messageType = new JiveTable(headers, null);
  15. messageType.setPreferredSize(new Dimension(350, 400));
  16. final JScrollPane pane = new JScrollPane(messageType);
  17. pane.setBorder(BorderFactory.createTitledBorder(Res.getString("label.message").replace("&", "")));
  18. final JScrollPane treePane = new JScrollPane(msgTree);
  19. treePane.setBorder(BorderFactory.createTitledBorder(Res.getString("message.send.to.these.people")));
  20. //          treePane.getVerticalScrollBar().setBlockIncrement(200);
  21. //          treePane.getVerticalScrollBar().setUnitIncrement(20);
  22. // Add to UI
  23. add(treePane, new GridBagConstraints(0, 0, 1, 1, 0.5, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 0), 0, 0));
  24. add(pane, new GridBagConstraints(1, 0, 1, 3, 0.5, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 0, 2, 5), 0, 0));
  25. msgTree.expandTree();
  26. }
  27. /**
  28. * Displays the message tree dialog.
  29. */
  30. public void invokeDialog() {
  31. JiveTreeNode groupNode = new JiveTreeNode("通知类型1");
  32. groupNode.add( new JiveTreeNode("通知类型11"));
  33. groupNode.add(new JiveTreeNode("通知类型12"));
  34. groupNode.add(new JiveTreeNode("通知类型13"));
  35. groupNode.add(new JiveTreeNode("通知类型14"));
  36. groupNode.add(new JiveTreeNode("通知类型15"));
  37. JiveTreeNode groupNode2 = new JiveTreeNode("通知类型2");
  38. groupNode2.add( new JiveTreeNode("通知类型21"));
  39. groupNode2.add(new JiveTreeNode("通知类型22"));
  40. groupNode2.add(new JiveTreeNode("通知类型23"));
  41. groupNode2.add(new JiveTreeNode("通知类型24"));
  42. groupNode2.add(new JiveTreeNode("通知类型25"));
  43. msgType.add(groupNode);
  44. msgType.add(groupNode2);
  45. }
  46. }

  • MessageTree.java
  1. public class MessageTree extends JPanel {
  2. private static final long serialVersionUID = 5992552368286729600L;
  3. private Tree tree;
  4. public MessageTree(JiveTreeNode rootNode) {
  5. tree = new Tree(rootNode);
  6. tree.setCellRenderer(new DefaultTreeCellRenderer());
  7. tree.setRowHeight(18);
  8. tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  9. tree.setToggleClickCount(1000);
  10. tree.putClientProperty("JTree.lineStyle", "Angled");
  11. tree.addMouseListener(new NodeSelectionListener(tree));
  12. setLayout(new BorderLayout());
  13. add(tree);
  14. }
  15. class NodeSelectionListener extends MouseAdapter {
  16. JTree tree;
  17. NodeSelectionListener(JTree tree) {
  18. this.tree = tree;
  19. }
  20. public void mouseClicked(MouseEvent e) {
  21. int x = e.getX();
  22. int y = e.getY();
  23. int row = tree.getRowForLocation(x, y);
  24. TreePath path = tree.getPathForRow(row);
  25. if (path != null) {
  26. JiveTreeNode node = (JiveTreeNode)path.getLastPathComponent();
  27. if (!node.isLeaf()) {
  28. tree.expandPath(path);
  29. }
  30. else {
  31. tree.collapsePath(path);
  32. }
  33. ((DefaultTreeModel)tree.getModel()).nodeChanged(node);
  34. // I need revalidate if node is root.  but why?
  35. tree.revalidate();
  36. tree.repaint();
  37. }
  38. }
  39. }
  40. public JTree getTree() {
  41. return tree;
  42. }
  43. /**
  44. * Call to expand the entire tree.
  45. */
  46. public void expandTree() {
  47. for (int i = 0; i <= tree.getRowCount(); i++) {
  48. tree.expandPath(tree.getPathForRow(i));
  49. }
  50. }
  51. }
 

效果图:

【基于spark IM 的二次开发笔记】第二天 树形结构的更多相关文章

  1. 【基于spark IM 的二次开发笔记】第一天 各种配置

    [基于spark IM 的二次开发笔记]第一天 各种配置 http://juforg.iteye.com/blog/1870487 http://www.igniterealtime.org/down ...

  2. 提供基于Lesktop的IM二次开发,联系QQ:87172811

    提供基于Lesktop的IM二次开发,联系QQ:87172811

  3. phpcms二次开发笔记

    phpcms二次开发笔记 --soulsjie 以下载的全新的phpcms搭建一个新的站点为例,讲解如何利用phpcms进行二次开发 一.下载和安装phpcms http://www.phpcms.c ...

  4. 研究QGIS二次开发笔记(一)

    为了在QT程序中嵌入一个地图,最终选择了QGIS来干这件事.选型阶段真是呵呵.我折腾的是QGIS2.4.0. 首先,到官方网站下载安装QGIS.如果你跟我一样懒的话,可能希望下载一个已经编译好的win ...

  5. RTX二次开发笔记2

    问题一:关于DLL文件的引用 在安装文件夹内 APIObject.dll==>RTXSAPI.dll 服务器API接口 RTXCAPI.DLL ==> 客户端API接口 问题二:RTX二次 ...

  6. 基于leveldb,levigo做二次开发

    Leveldb是一个C++库,它有提供标准的C接口,头文件在include/leveldb/c.h中 levigo是leveldb 的一个go wrapper,它主要基于Leveldb中inlude/ ...

  7. OTRS 二次开发笔记

    公司使用otrs系统处理业务工单,各种事件流.因为是开源免费系统,因此需要在上面做一些功能补充或定制的二次开发. otrs是什么? OTRS 是一个功能强大的工单系统.完美适用于服务台(Help De ...

  8. (dede)织梦系统二次开发笔记

    (dede)织梦系统二次开发记录 --soulsjie 一.模板常用文件说明 模板文件都在文件夹templets下,我们以默认模板(default)为例,对模板文件结构进行分析: 首页模板文件目录 \ ...

  9. 派胜OA二次开发笔记(1)重写主界面

    最近从派胜OA 2018 升级到 2019,为了二次开发方便,索性花了两天,反向分析 PaiOA 2019 主界面程序,重写大部分代码,方便对菜单权限进行控制. 主界面/core/index.aspx ...

随机推荐

  1. Dynamic Programming: From novice to advanced

    作者:Dumitru 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg An impo ...

  2. (转)IOS学习笔记-2015-03-29 int、long、long long取值范围

    unsigned - - unsigned - - unsigned __int64的最大值: __int64的最小值:- unsigned __int64的最大值:  

  3. nginx 502

    查过网上的资源,基本都是认为是php线程打开文件句柄受限导致的错误.具体的解决的办法如下:   1.提升服务器的文件句柄打开打开 /etc/security/limits.conf : (增加) * ...

  4. 【Android】Sqlite3命令详解

    Sqlite3常用命令 Sqlite3命令有"."符合作为前缀. 基本操作 1.创建或者打开数据库 sqlite3 xxx.db 如果xxx.db存在则打开如果没有则新建此时执行创 ...

  5. Python3 基础

    Hello world 在文本编辑器中,键入python执行代码,保存文件为hello.py print('hello, world') 注意print前面不要有任何空格.然后,选择一个目录,例如C: ...

  6. 移动端REM布局方案

    引用http://www.w3cplus.com/mobile/lib-flexible-for-html5-layout.html的方案 下载地址https://github.com/hupan50 ...

  7. linux命令之chown命令

    发布:JB01   来源:脚本学堂     [大 中 小] 本文介绍下,linux系统中用于文件与目录权限管理的命令 chown命令的用法,chown将指定文件的拥有者改为指定的用户或组.有需要的朋友 ...

  8. 给destoon商城的列表中和首页添加购物车功能

    如何给destoon商城的列表中和首页添加购物车功能? 目前加入购物车的功能只存在商城的详细页面里,有时候我们需要批量购买的时候,希望在列表页就能够使用这个加入购物车的功能. 修改步骤见下: 例如在商 ...

  9. node论坛练手

    当时学node,自己写了个论坛练手,现在看还是有很多问题,有时间好好改改 https://github.com/hitbs228/countdown

  10. 腾讯面试题 腾讯面试题:给40亿个不重复的unsigned int的整数,没排过序的,然后再给一个数,如何快速判断这个数是否在那40亿个数当中?

    腾讯面试题:给40亿个不重复的unsigned int的整数,没排过序的,然后再给一个数,如何快速判断这个数是否在那40亿个数当中?  这个题目已经有一段时间了,但是腾讯现在还在用来面试.腾讯第一次面 ...