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

📄 collaborationpanel.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        //sessionTableModel.removeTableModelListener(this);        for (int i = 0; i < sessionTableModel.getRowCount(); i++) {            String n = (String) sessionTableModel.getValueAt(i, mailColumn);            if (mail.equals(n)) {                sessionTableModel.setValueAt("true", i, controlColumn);                controllingParticipantMail = mail;            } else {                sessionTableModel.setValueAt("false", i, controlColumn);            }        }        //sessionTableModel.addTableModelListener(this);    }    /**     * Returns the email address of the participant that currently has control.     * @return the email address of the participant that has control or null     */    public String getControllingParticipant() {        return controllingParticipantMail;    }    /**     * A preliminary implementation for the use of Locales.     */    public void updateLocale() {        sessionNameLabel.setText(ElanLocale.getString(                "P2P.CollaborationPanel.Label.Session"));        chairNameLabel.setText(ElanLocale.getString(                "P2P.CollaborationPanel.Label.Chair"));        docNameLabel.setText(ElanLocale.getString(                "P2P.CollaborationPanel.Label.Document"));        sessionValueLabel.setText("");        chairValueLabel.setText("");        docValueLabel.setText("");        sessionTableModel.setColumnIdentifiers(new String[] {                ElanLocale.getString("P2P.CollaborationPanel.Header.Control"),                ElanLocale.getString(                    "P2P.CollaborationPanel.Header.Participant"),                ElanLocale.getString("P2P.CollaborationPanel.Header.Mail")            });        byeButton.setText(ElanLocale.getString(                "P2P.CollaborationPanel.Button.Bye"));        requestControlButton.setText(ElanLocale.getString(                "P2P.CollaborationPanel.Button.Control"));    }    /**     * Implement ActionListener. Handles button presses etc.     *     * @param event the ActionEvent     *     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)     */    public void actionPerformed(ActionEvent event) {        if (event.getActionCommand().equals("bye")) {            logOff();        } else if (event.getActionCommand().equals("control")) {            requestControl();        }    }    /**     * Performs a check on a change of the table model.     * @param tme the tablemodelevent     * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)     */    public void tableChanged(TableModelEvent tme) {        if (tme.getType() == TableModelEvent.UPDATE) {            String oldControllingPartMail = controllingParticipantMail;            sessionTableModel.removeTableModelListener(this);            int row = tme.getFirstRow();            int column = tme.getColumn(); //should be the "Control" column            // check if the row was already the controller row            TableModel tm = (TableModel) tme.getSource();            for (int i = 0; i < tm.getRowCount(); i++) {                if (i != row) {                    tm.setValueAt("false", i, column);                } else {                    int mailColumn = sessionTableModel.findColumn(ElanLocale.getString(                                "P2P.CollaborationPanel.Header.Mail"));                    controllingParticipantMail = (String) tm.getValueAt(i,                            mailColumn);                    if (!controllingParticipantMail.equals(                                oldControllingPartMail)) {                        // notify group                        // elanP2P.setControllingParticipant(controllingParticipant);                        logger.info("Setting controlling participant to: " +                            controllingParticipantMail);                    }                }            }            sessionTableModel.addTableModelListener(this);        }    }    /**     * A temporary main method for testing purposes.     *     * @param args args     */    public static void main(String[] args) {        final CollaborationPanel cp = new CollaborationPanel();        // temp, show in separate frame        showFrame(cp);        populate(cp);    }    private static void showFrame(CollaborationPanel cp) {        JFrame frame = new JFrame("Collaboration");        frame.getContentPane().add(cp);        frame.setSize(400, 300);        frame.addWindowListener(new WindowAdapter() {                public void windowClosed(WindowEvent we) {                    System.exit(0);                }            });        frame.setVisible(true);    }    private static void populate(final CollaborationPanel cp) {        new Thread(new Runnable() {                public void run() {                    try {                        Thread.sleep(3000);                    } catch (InterruptedException ie) {                    }                    cp.setSessionName("Test session");                    cp.setChairName("Kofi Annan");                    cp.setSharedDocumentName("test document");                    //		cp.addParticipant("hopi", "hopi@hetnet.nl");                    //		cp.addParticipant("solana", "solana@webos.es");                    //		cp.addParticipant("lubbi", "lubbi@demon.nl");                    //		cp.setControllingParticipant("solana@webos.es");                    //		cp.setLocalParticipantName("hopi");                    //		cp.setLocalParticipantMail("hopi@hetnet.nl");                    try {                        Thread.sleep(3000);                    } catch (InterruptedException ie) {                    }                    //cp.removeParticipant("solana@webos.es");                }            }).start();    }    //********************************************************    // internal classes    //********************************************************    class CollaborativeTableModel extends DefaultTableModel {        /**         * Returns true for the "Control" column, false for the other columns.         *          * @param   row       the row whose value is to be queried          * @param   column    the column whose value is to be queried         * @return  true true for the "Control" column, false otherwise         * @see #setValueAt         */        public boolean isCellEditable(int row, int column) {            /*            String head = getColumnName(column);            if (head != null && head.equals(ElanLocale.getString("P2P.CollaborationPanel.Header.Control"))) {                return true;            }            */            return false;        }    }    /**     * A table cell editor that uses a JRadioButton as the editor component.     * @author Han Sloetjes     */    class RadioButtonCellEditor extends AbstractCellEditor        implements TableCellEditor, ActionListener, Serializable {        private JRadioButton radioButton;        /**         * No-arg constructor.         */        RadioButtonCellEditor() {            radioButton = new JRadioButton();            radioButton.addActionListener(this);        }        /**         * Returns the JRadioButton editor component.         * @param table the enclosing table         * @param value the current value         * @param isSelected the selected state of the table cell         * @param row the rowindex         * @param column the column index         * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int)         */        public Component getTableCellEditorComponent(JTable table,            Object value, boolean isSelected, int row, int column) {            setValue(value);            if (isSelected) {                radioButton.setBackground(table.getSelectionBackground());            } else {                radioButton.setBackground(table.getBackground());            }            radioButton.setHorizontalAlignment(SwingConstants.CENTER);            return radioButton;        }        /**         * Sets the selected state of the radiobutton.         * @param value a Boolean or String         */        private void setValue(Object value) {            boolean selected = false;            if (value instanceof Boolean) {                selected = ((Boolean) value).booleanValue();            } else if (value instanceof String) {                selected = ((String) value).equalsIgnoreCase("true");            }            radioButton.setSelected(selected);        }        /**         * Called when the editing has been canceled.         * @see javax.swing.CellEditor#cancelCellEditing()         */        public void cancelCellEditing() {            fireEditingCanceled();        }        /**         * Called when the editing has been stopped. Always returns true         * because the new value is always accepted without validation.         * @see javax.swing.CellEditor#stopCellEditing()         */        public boolean stopCellEditing() {            fireEditingStopped();            return true;        }        /**         * Returns the current value of the radio button.         * @return true if the radiobutton is selected, false otherwise         * @see javax.swing.CellEditor#getCellEditorValue()         */        public Object getCellEditorValue() {            return new Boolean(radioButton.isSelected());        }        /**         * Returns true.         * @return always returns true         * @see javax.swing.CellEditor#isCellEditable(java.util.EventObject)         */        public boolean isCellEditable(EventObject anEvent) {            return true;        }        /**         * Returns false.         * @param anEvent the event         * @return always returns false         * @see javax.swing.CellEditor#shouldSelectCell(java.util.EventObject)         */        public boolean shouldSelectCell(EventObject anEvent) {            return false;        }        /**         * Implement ActionListener by firing editingStopped         * @param ae the actionevent         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)         */        public void actionPerformed(ActionEvent ae) {            if (!radioButton.isSelected()) {                radioButton.setSelected(true);            } else {                // apparently a change in the participant that has control occurred                //System.out.println("control change");            }            RadioButtonCellEditor.this.stopCellEditing();        }    }    /**     * A table cell renderer that uses a JRadioButton to render boolean values.     * @author Han Sloetjes     */    class RadioButtonTableCellRenderer extends JRadioButton        implements TableCellRenderer, Serializable {        /**         * Creates a new RadioButtonTableCellRenderer instance         */        RadioButtonTableCellRenderer() {            super();            setOpaque(true);        }        /**         * Returns a radio button for the specified cell to render         * the boolean value.         * @param table the enclosing table         * @param value the current value         * @param isSelected the selected state of the table cell         * @param row the rowindex         * @param column the column index         * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)         */        public Component getTableCellRendererComponent(JTable table,            Object value, boolean isSelected, boolean hasFocus, int row,            int column) {            if (isSelected) {                super.setBackground(table.getSelectionBackground());            } else {                super.setBackground(table.getBackground());            }            setValue(value);            setHorizontalAlignment(SwingConstants.CENTER);            return this;        }        /**         * Overridden for performance reasons.         */        public void validate() {        }        /**         * Overridden for performance reasons.         */        public void revalidate() {        }        /**         * Overridden for performance reasons.         */        public void repaint(long tm, int x, int y, int width, int height) {        }        /**         * Overridden for performance reasons.         */        public void repaint(Rectangle r) {        }        /**         * Sets the <code>Boolean</code> value for the cell being rendered to         * <code>value</code>.         *         * @param value  the Boolean value for this cell; if value is         *        <code>null</code> it sets the value to <code>false</code>         * @see JRadioButton#setSelected         */        protected void setValue(Object value) {            boolean selected = false;            if (value instanceof Boolean) {                selected = ((Boolean) value).booleanValue();            } else if (value instanceof String) {                selected = ((String) value).equalsIgnoreCase("true");            }            super.setSelected(selected);        }    }}

⌨️ 快捷键说明

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