⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 singlegrouptablemodel.java

📁 jxta官方例程
💻 JAVA
字号:
/** * Copyright (c) 2005 Frank Toennies * Redistributions in source code form must reproduce the above copyright and this condition. * The contents of this file are subject to the Sun Project JXTA License Version 1.1 (the "License"); * you may not use this file except in compliance with the License. * A copy of the License is available at http://www.jxta.org/jxta_license.html. * Please see the license information page for instructions on use of the license in source files. * * This software consists of voluntary contributions made by many individuals on behalf of Project JXTA. * For more information on Project JXTA, please see http://www.jxta.org. * */package net.jxta.myjxta.ui;import net.jxta.myjxta.presence.PeerEntry;import net.jxta.myjxta.presence.PresenceController;import net.jxta.myjxta.util.Group;import net.jxta.myjxta.util.JxtaNode;import net.jxta.myjxta.util.JxtaNodeListener;import net.jxta.myjxta.util.PeerNode;import javax.swing.table.DefaultTableModel;import javax.swing.table.TableModel;import java.util.Collections;import java.util.Iterator;import java.util.Vector;/** * @author Frank Toennies -- */public class SingleGroupTableModel extends DefaultTableModel        implements        TableModel, JxtaNodeListener {    Group m_group;    /**     * @param peerGroup     */    public SingleGroupTableModel(Group peerGroup) {        m_group = peerGroup;    }    public Group getGroup() {        return m_group;    }    public void addOrRefreshPeer(PeerNode peer) {        PeerEntry p = new PeerEntry(peer);        final Vector<PeerEntry> rows = getRows();		if (!rows.contains(p)) {            rows.add(p);            peer.addListener(this);        } else {            //m_rows.get(p)        }               fireTableDataChanged();    }    /* (non-Javadoc)    * @see javax.swing.table.TableModel#getRowCount()    */    public int getRowCount() {        if (getRows() != null) {            return getRows().size();        } else {            return 0;        }    }    /**     * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.     *     * @param columnIndex the column being queried     * @return the Object.class     */    public Class<PeerEntry> getColumnClass(int columnIndex) {        return PeerEntry.class;    }    /* (non-Javadoc)      * @see javax.swing.table.TableModel#getColumnCount()      */    public int getColumnCount() {        return 1;    }    /* (non-Javadoc)      * @see javax.swing.table.TableModel#getValueAt(int, int)      */    public Object getValueAt(int row, int column) {        if (row >= 0 && column >= 0) {        	Vector<PeerEntry> raw=getRows();        	Vector<PeerEntry> sorted=new Vector<PeerEntry>(raw);        	Collections.sort(sorted);            return sorted.get(row);        } else {            return null;        }    }    /* (non-Javadoc)    * @see javax.swing.table.TableModel#getColumnName(int)    */    public String getColumnName(int colNr) {        return null;//		return STRINGS.getString("label.pipe.name");    }    public PeerNode[] getAllPeerNodes() {        PeerNode result[] = new PeerNode[getRows().size()];        int i = 0;        for (Iterator<PeerEntry> iterator = getRows().iterator(); iterator.hasNext();) {            PeerEntry peerEntry = iterator.next();            result[i] = peerEntry.getNode();            i++;        }        return result;    }    public void shutdown() {        for (Iterator<PeerEntry> iterator = getRows().iterator(); iterator.hasNext();) {            PeerEntry peerEntry = iterator.next();            peerEntry.getNode().removeListener(this);        }    }    public void nodeChanged(JxtaNode node) {        fireTableDataChanged();    }    public Vector<PeerEntry> getRows() {        Group group = getGroup();        if (group == null)            return null;        return PresenceController.getController(group.getId()).getAllContacts();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -