📄 groupchatbookmarks.java
字号:
/** * Makes sure all of the required information to save a bookmark is filled * in * * @return true if the information is completely filled out */ private boolean checkData() { if (roomBox.getText().equals("") || serverBox.getText().equals("") || nickBox.getText().equals("")) { Standard.warningMessage(this, resources .getString("groupChatBookmarksDialogTitle"), resources .getString("enterAllFields")); return false; } return true; } /** * Deletes a bookmark from disk * * @author Adam Olsen * @version 1.0 */ class DeleteListener implements ActionListener { public void actionPerformed(ActionEvent e) { int result = JOptionPane.showConfirmDialog(thisPointer, resources .getString("sureDelete"), resources .getString("deleteBookmark"), JOptionPane.YES_NO_OPTION); if (result != 0) return; ListModel model = bookMarkList.getModel(); Bookmark.Conference c = (Bookmark.Conference)model.getElementAt(bookMarkList .getSelectedIndex()); bookmark.removeConference(c); loadBookmarks(); validate(); new Thread(new SaveBookmark()).start(); } } /** * Shows a menu on the bookmark items allowing you to delete one of them * * @author Adam Olsen * @version 1.0 */ class RightClickListener extends MouseAdapter { public void mousePressed(MouseEvent e) { checkPop(e); } public void mouseReleased(MouseEvent e) { checkPop(e); } public void mouseClicked(MouseEvent e) { checkPop(e); } public void checkPop(MouseEvent e) { if (e.isPopupTrigger()) { int index = bookMarkList.locationToIndex(new Point(e.getX(), e .getY())); bookMarkList.setSelectedIndex(index); deleteMenu.show(e.getComponent(), e.getX(), e.getY()); } else { loadBookmark(); if (e.getClickCount() >= 2) openHandler(); } } } /** * Opens a bookmark and fills out the fields with it's information */ private void loadBookmark() { ListModel model = bookMarkList.getModel(); Bookmark.Conference c = (Bookmark.Conference)model.getElementAt(bookMarkList.getSelectedIndex()); String jid = c.getJid(); int b = jid.indexOf("@"); roomBox.setText(jid.substring(0,b)); serverBox.setText(jid.substring(b+1)); nickBox.setText(c.getNick()); passBox.setText(c.getPassword()); auto.setSelected(c.getAutojoin()); } /** * Opens a connection to a groupchat room */ private void openHandler() { if (!checkData()) return; if (BuddyList.getInstance().getTabFrame() != null && BuddyList.getInstance().getTabFrame().isRoomOpen( roomBox.getText() + "@" + serverBox.getText())) { Standard.warningMessage(this, resources.getString("openBookmark"), resources.getString("alreadyInRoom")); return; } ChatRoomPanel window = new ChatRoomPanel(roomBox.getText() + "@" + serverBox.getText(), nickBox.getText(), new String(passBox .getPassword())); window.startChat(); dispose(); } /** * Loads all the bookmarks and puts them in the list of bookmarks */ private void loadBookmarks() { wait.setVisible(false); bookmarks.clear(); if( bookmark != null ) { Iterator i = bookmark.getConferences(); while( i.hasNext() ) { bookmarks.add(i.next()); } } bookMarkList.setListData(bookmarks.toArray()); bookMarkList.validate(); } class CollectBookmarks implements Runnable { private boolean autojoin = false; public CollectBookmarks( boolean autojoin ) { this.autojoin = autojoin; if( !autojoin ) wait.setVisible(true); } public void run() { try { pDataManager = new PrivateDataManager(BuddyList.getInstance().getConnection()); bookmark = (Bookmark)pDataManager.getPrivateData("storage", "storage:bookmarks"); if( !Settings.getInstance().getBoolean( "jbotherMucAdded" ) ) { String user = BuddyList.getInstance().getConnection().getUser(); int b = user.indexOf("@"); user = user.substring( 0, b ); bookmark.addConference("jbother", "jbother@conference.jabber.ccc.de", user, "", false ); pDataManager.setPrivateData(bookmark); Settings.getInstance().setBoolean( "jbotherMucAdded", true ); } } catch( Exception ex ) { com.valhalla.Logger.logException(ex); } SwingUtilities.invokeLater( new Runnable() { public void run() { if( !autojoin ) { loadBookmarks(); } else performAutoJoin(); } } ); } } private void performAutoJoin() { if( bookmark == null ) return; Iterator i = bookmark.getConferences(); while(i.hasNext()) { Bookmark.Conference c=(Bookmark.Conference)i.next(); if (c.getAutojoin()) { ChatRoomPanel window = new ChatRoomPanel(c.getJid(), c.getNick(), c.getPassword()); window.startChat(); } } } public void autoJoin() { new Thread(new CollectBookmarks(true)).start(); } /** * Creates a MJTextField with a label * * @param label * the name of the the label * @param box * the MJTextField */ private void createInputBox(String label, Container box) { JLabel labelBox = new JLabel(label + " "); c.gridy = row++; c.gridx = 0; grid.setConstraints(labelBox, c); inputPanel.add(labelBox); c.gridx = 1; grid.setConstraints(box, c); inputPanel.add(box); }}/** * Displays the different group chat bookmarks * * @author Adam Olsen * @version 1.0 */class ListRenderer extends JLabel implements ListCellRenderer { public ListRenderer() { setOpaque(true); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Bookmark.Conference c = (Bookmark.Conference)value; setText(c.getName()); setBackground(isSelected ? list.getSelectionBackground() : list .getBackground()); setForeground(isSelected ? list.getSelectionForeground() : list .getForeground()); list.validate(); return this; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -