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

📄 bsconfwindow.java

📁 一款即时通讯软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        topSplitPane.setResizeWeight(1);

        //*** button panel ***
        buttonPanel = new JPanel(new GridBagLayout());

        sendButton = new JButton();
        sendButton.setText("Send");
        sendButton.addActionListener(this);
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridy = 1;
        buttonPanel.add(sendButton, gridBagConstraints);

        /*urlButton = new JButton("URL");
        urlButton.addActionListener(this);
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridy = 2;
        buttonPanel.add(urlButton, gridBagConstraints);*/

        inviteButton = new JButton();
        inviteButton.setText("Invite");
        inviteButton.addActionListener(this);
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridy = 3;
        buttonPanel.add(inviteButton, gridBagConstraints);

        closeButton = new JButton();
        closeButton.setText("Close");
        closeButton.addActionListener(this);
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridy = 4;
        buttonPanel.add(closeButton, gridBagConstraints);

        writeScrollPane = new JScrollPane();
        writeTextArea = new JTextArea();
        writeTextArea.setLineWrap(true);
        writeTextArea.setWrapStyleWord(true);
        writeScrollPane.setBorder(new javax.swing.border.TitledBorder("Write"));
        writeScrollPane.setViewportView(writeTextArea);
        writeTextArea.addKeyListener(this);

        bottomPanel = new JPanel(new BorderLayout());
        bottomPanel.add(writeScrollPane, BorderLayout.CENTER);
        bottomPanel.add(buttonPanel, BorderLayout.EAST);

        mainSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, topSplitPane, bottomPanel);
        //mainSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, rosterTree.getScrollPane(), bottomPanel);
        mainSplitPane.setBorder(null);
        mainSplitPane.setDividerSize(8);
        mainSplitPane.setResizeWeight(1);

        JPanel checkBoxesPanel = new JPanel();
        Icon icon = new ImageIcon(ClassLoader.getSystemResource(!docked?
                                "images/dock.gif" : "images/float.gif"));
        dockButton = new JButton(icon);
        dockButton.setToolTipText(docked? "Float" : "Dock");
        dockButton.addActionListener(this);
        if (!OSVersion.isJava1Point4orHigher())
            dockButton.setEnabled(false);
        icon = new ImageIcon(ClassLoader.getSystemResource("images/bookmark.gif"));
        bookmarkButton = new JButton(icon);
        bookmarkButton.setToolTipText("Add bookmark");
        bookmarkButton.addActionListener(this);
        enterSendsCheckBox = new JCheckBox("Enter = Send", enterSends);
        enterSendsCheckBox.addActionListener(this);
        historyButton = new JButton("Load history");
        historyButton.addActionListener(this);
        checkBoxesPanel.add(enterSendsCheckBox);
        checkBoxesPanel.add(dockButton);
        checkBoxesPanel.add(bookmarkButton);
        checkBoxesPanel.add(historyButton);

        mainPanel.add(checkBoxesPanel, BorderLayout.NORTH);
        mainPanel.add(mainSplitPane, BorderLayout.CENTER);
        //add(rosterTree.getScrollPane(), BorderLayout.CENTER);

        setLayout(new BorderLayout());
        add(mainPanel, BorderLayout.CENTER);

        MouseAdapter ma = new MouseAdapter() {
            public void mouseClicked(MouseEvent mouseEvent) {
                if (newMsg) {
                    setNewMsg(false);
                    ((BSConfWinManager)winMan).updateNewMessageFlags(BSConfWindow.this, false);
                }
            }
        };
        addMouseListener(ma);
        writeTextArea.addMouseListener(ma);
        confTextPane.addMouseListener(ma);
        frame.addMouseListener(ma);
        frame.getContentPane().addMouseListener(ma);

        setNewMsg(newMsg);

    }

    /** Handles actions from GUI controls */
    public void actionPerformed(ActionEvent evt) {
        Object source = evt.getSource();
        // close
        if (source == closeButton) {
            close();
        }
        // send message
        else if (source == sendButton) {
            confBean.sendMessage(roomJID, writeTextArea.getText());
            writeTextArea.setText("");
        }
        // start countdown
        if (source == countdownButton) {
            startCountdown();
        }
        // invite into the room
        else if (source == inviteButton) {
            ((BSConfWinManager)winMan).composeInvitation(roomJID, null, null);
        }
        // send URL
        /*else if (source == urlButton) {
            BSSendURLDialog dlg = new BSSendURLDialog(docked? ((BSConfWinManager)winMan).mainFrame : frame);
            dlg.setVisible(true);
            if (dlg.desc != null && dlg.url != null)
                confBean.sendURLMessage(roomJID, dlg.desc + " :" + dlg.url, dlg.url, dlg.desc);
        }*/
        else if (evt.getSource() == historyButton) {
            loadHistory();
        }
        else if (evt.getSource() == enterSendsCheckBox) {
            enterSends = enterSendsCheckBox.isSelected();
        }
        else if (evt.getSource() == dockButton) {
            if (winMan != null) {
                winMan.setWindowDocked(this, !docked);
                Icon icon = new ImageIcon(ClassLoader.getSystemResource(!docked?
                                "images/dock.gif" : "images/float.gif"));
                dockButton.setIcon(icon);
                dockButton.setToolTipText(docked? "Float" : "Dock");
                winMan.selectWindow(this);
            }
        }
        else if (evt.getSource() == presenceChangesCheckBox) {
            presenceChanges = !presenceChanges;
        }
        else if (evt.getSource() == alertsCheckBox) {
            alerts = !alerts;
        }
        else if (evt.getSource() == pluginCheckBox) {
            boolean state = pluginCheckBox.isSelected();
            int lastLocation = roomSplitPane.getLastDividerLocation();
            roomSplitPane.setDividerLocation(state ? lastLocation : 0);
        }
        else if (evt.getSource() == videoButton) {
            if (videoBean != null)
            {
                videoBean.requestLaunch(this);
            }
        }
        else if (evt.getSource() == bookmarkButton) {
            if (winMan != null)
                ((BSConfWinManager)winMan).addBookmark(roomJID);
        }
        // countdowns
        else {
            int size = countdowns.size();
            for (int i=0; i<size; i++) {
                if (source == countdowns.elementAt(i)) {
                    BSCountdown c = (BSCountdown) source;
                    sendCountdownState(c);
                    if (c.getTimeLeft() == 0) {
                        countdowns.remove(c);
                        c.removeActionListener(this);
                    }
                    break;
                }
            }
        }
    }

    /** Sends message according to given countdown */
    protected void sendCountdownState(BSCountdown count) {
        if (count.getTimeLeft() == 0) {
            confBean.sendMessage(roomJID, "{" + count.getName() + ": GO!}");
        }
        else {
            int minLeft = count.getTimeLeft()/60;
            int secLeft = count.getTimeLeft() - 60 * minLeft;

            if (minLeft > 0) {
                String secStr = new String((secLeft < 10)? "0":"") +
                            Integer.toString(secLeft);
                confBean.sendMessage(roomJID, "{" + count.getName() + ": " +
                         Integer.toString(minLeft) + ":" + secStr +
                         ((minLeft == 1)? " minute" : " minutes") + "}");
            }
            else {
                confBean.sendMessage(roomJID, "{" + count.getName() + ": "
                          + Integer.toString(secLeft)
                          + ((secLeft == 1)? " second" : " seconds") + "}");
            }
        }
    }

    /** Returns JID of the room */
    public JID getRoomJID() {
        return roomJID;
    }


    /** Changes nickname */
    public void changeNick() {
        BSNameDialog dlg = new BSNameDialog(docked? ((BSConfWinManager)winMan).mainFrame : frame,
                                            "New nickname:", "");
        dlg.setVisible(true);
        if (dlg.name != null && !"".equals(dlg.name))
            confBean.changeNick(roomJID, dlg.name);
    }


    /** Starts countdown */
    public void startCountdown() {
        BSConfCountdownDialog dlg = new BSConfCountdownDialog(
                                            docked? ((BSConfWinManager)winMan).mainFrame : frame);
        dlg.setVisible(true);

        if (dlg.name != null) {

            BSCountdown c = new BSCountdown(dlg.name, dlg.minutes, dlg.seconds);
            c.addActionListener(this);
            countdowns.add(c);
            sendCountdownState(c);
            c.start();
        }
    }

    /** Loads message history */
    protected void loadHistory() {
        String history = History.getMessages(
               new JID(BSMainFrame.username, BSMainFrame.server, null), roomJID);
        if (history != null) {
            confTextPane.clear();
            confTextPane.append(history, BSAutoScrollTextPane.REGULAR_STYLE);
        }
    }

    /** Handles changes in state of presence combo box */
    public void itemStateChanged(ItemEvent itemEvent) {
        if (confBean == null || roomJID == null) return;

        if (itemEvent.getStateChange() == ItemEvent.SELECTED) {

            ItemSelectable is = itemEvent.getItemSelectable();
            /*if (is == showComboBox) {
                String showStr = ((ImageIcon)showComboBox.getSelectedItem()).getDescription();
                // sets attention to "none" when away or xa
                if (BSMainFrame.SHOW_AWAY_STR.equals(showStr) ||
                    BSMainFrame.SHOW_XA_STR.equals(showStr)) {
                    dontSendAttention = true;
                    attentionSlider.setValue(0);
                    dontSendAttention = false;
                }
                // sets attention to "some" when dnd
                else if (BSMainFrame.SHOW_DND_STR.equals(showStr)) {
                    dontSendAttention = true;
                    attentionSlider.setValue(1);
                    dontSendAttention = false;
                }
                // sets attention to "full" when online
                else if (BSMainFrame.SHOW_ONLINE_STR.equals(showStr) ||
                         BSMainFrame.SHOW_CHAT_STR.equals(showStr)) {
                    dontSendAttention = true;
                    attentionSlider.setValue(attentions.length-1);
                    dontSendAttention = false;
                }
            }*/
            // sends presence
            if (is == showComboBox || is == voteComboBox) {
                sendPresence();
            }
        }
    }

    /*protected void sendPresence() {

        String votingStr = (String) voteComboBox.getSelectedItem();
        if (NOT_VOTING_STR.equals(votingStr))
            votingStr = null;

        String attentionStr = attentions[(int)attentionSlider.getValue()];

        String statusStr = "Attention " + attentionStr;
        if (votingStr != null)
            statusStr = votingStr + ", " + statusStr;

        String presence = ((ImageIcon) showComboBox.getSelectedItem()).getDescription();

        if (BSMainFrame.SHOW_ONLINE_STR.equals(presence))
            confBean.sendPresence(new BSPresenceInfo(null, true, null, statusStr), roomJID);
        else if (BSMainFrame.SHOW_CHAT_STR.equals(presence))
              confBean.sendPresence(new BSPresenceInfo(null, true, BSPresenceInfo.SHOW_CHAT, statusStr), roomJID);
        else if (BSMainFrame.SHOW_AWAY_STR.equals(presence))
            confBean.sendPresence(new BSPresenceInfo(null, true, BSPresenceInfo.SHOW_AWAY, statusStr), roomJID);
        else if (BSMainFrame.SHOW_XA_STR.equals(presence))
            confBean.sendPresence(new BSPresenceInfo(null, true, BSPresenceInfo.SHOW_XA, statusStr), roomJID);
        else if (BSMainFrame.SHOW_DND_STR.equals(presence))
            confBean.sendPresence(new BSPresenceInfo(null, true, BSPresenceInfo.SHOW_DND, statusStr), roomJID);
    }*/

    protected void sendPresence() {

        String votingStr = (String) voteComboBox.getSelectedItem();
        if (NOT_VOTING_STR.equals(votingStr))
            votingStr = "";
        else
            votingStr = votingStr + ", ";

        String presence = ((ImageIcon) showComboBox.getSelectedItem()).getDescription();

⌨️ 快捷键说明

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