Java tutorial
/* * LumaQQ - Java QQ Client * * Copyright (C) 2004 luma <stubma@163.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package edu.tsinghua.lumaqq.ui.helper; import static edu.tsinghua.lumaqq.resource.Messages.*; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osgi.util.NLS; import edu.tsinghua.lumaqq.MessageQueue; import edu.tsinghua.lumaqq.models.Cluster; import edu.tsinghua.lumaqq.models.Model; import edu.tsinghua.lumaqq.models.ModelRegistry; import edu.tsinghua.lumaqq.models.Organization; import edu.tsinghua.lumaqq.models.User; import edu.tsinghua.lumaqq.qq.Util; import edu.tsinghua.lumaqq.qq.packets.InPacket; import edu.tsinghua.lumaqq.qq.packets.in.ReceiveIMPacket; import edu.tsinghua.lumaqq.record.RecordEntry; import edu.tsinghua.lumaqq.ui.BrowserShell; import edu.tsinghua.lumaqq.ui.CheckUpdateShell; import edu.tsinghua.lumaqq.ui.IPSeekerWindow; import edu.tsinghua.lumaqq.ui.InfoManagerWindow; import edu.tsinghua.lumaqq.ui.MainShell; import edu.tsinghua.lumaqq.ui.MemberEditShell; import edu.tsinghua.lumaqq.ui.ReceiveIMWindow; import edu.tsinghua.lumaqq.ui.ReceiveSystemMessageShell; import edu.tsinghua.lumaqq.ui.SMSWindow; import edu.tsinghua.lumaqq.ui.SendClusterIMWindow; import edu.tsinghua.lumaqq.ui.SendIMTabWindow; import edu.tsinghua.lumaqq.ui.SendIMWindow; import edu.tsinghua.lumaqq.ui.SystemMessageListWindow; import edu.tsinghua.lumaqq.ui.TempSessionIMWindow; import edu.tsinghua.lumaqq.ui.WeatherWindow; import edu.tsinghua.lumaqq.ui.config.cluster.ClusterInfoWindow; import edu.tsinghua.lumaqq.ui.config.face.FaceWindow; import edu.tsinghua.lumaqq.ui.config.sys.SystemOptionWindow; import edu.tsinghua.lumaqq.ui.config.user.UserInfoWindow; import edu.tsinghua.lumaqq.ui.wizard.WizardWindow; /** * ??? * * @author luma */ public class ShellLauncher { private MainShell main; public ShellLauncher(MainShell main) { this.main = main; } /** * ???? */ public void goAlumni() { openBrowserShell(url_alumni, "Search/Create Alumni", NLS.bind(message_box_manual_browse, url_alumni)); } /** * QQ */ public void goQQHome() { openBrowserShell( NLS.bind(url_qqhome, String.valueOf(main.getMyModel().qq), Util.convertByteToHexStringWithoutSpace(main.getClient().getUser().getClientKey())), "", message_box_please_set_browser); } /** * QQ */ public void goQQShowMall() { openBrowserShell( NLS.bind(url_qqshow_mall, String.valueOf(main.getMyModel().qq), Util.convertByteToHexStringWithoutSpace(main.getClient().getUser().getClientKey())), "", message_box_please_set_browser); } /** * */ public void goClusterCommunity() { openBrowserShell(url_cluster_community, "Group Community", NLS.bind(message_box_manual_browse, url_cluster_community)); } /** * ?QQ? */ public void goApply() { openBrowserShell(url_apply, "Apply Free QQ Number", NLS.bind(message_box_manual_browse, url_apply)); } /** * ? */ public void goChatroom() { openBrowserShell(url_chatroom, "QQ Chatroom", NLS.bind(message_box_manual_browse, url_chatroom)); } /** * QQ? */ public void goQQGame() { openBrowserShell(url_game, "QQ Game", NLS.bind(message_box_manual_browse, url_game)); } /** * LumaQQ */ public void goLumaQQ() { openBrowserShell(url_lumaqq, "LumaQQ HomePage", NLS.bind(message_box_manual_browse, url_lumaqq)); } /** * ?? * * @param categoryId * ID */ public void searchCluster(int categoryId) { String url = NLS.bind(url_search_cluster, String.valueOf(categoryId)); openBrowserShell(url, "Search Cluster By Category", NLS.bind(message_box_manual_browse, url)); } /** * ? * * @return * ? */ public WeatherWindow openWeatherWindow() { if (main.getShellRegistry().isWeatherWindowOpen()) { WeatherWindow w = main.getShellRegistry().getWeatherWindow(); w.setMinimized(false); w.setActive(); return w; } else { WeatherWindow w = ShellFactory.createWeatherWindow(main); w.open(); return w; } } /** * ? * * @param friend * @return */ public SMSWindow openSMSWindow(User friend) { if (main.getShellRegistry().hasSMSWindow(friend)) { SMSWindow w = main.getShellRegistry().getSMSWindow(friend); w.setMinimized(false); w.setActive(); return w; } else { SMSWindow w = ShellFactory.createSMSWindow(main, friend); w.open(); return w; } } /** * ? * * @param mobile * @return */ public SMSWindow openSMSWindow(String mobile) { if (main.getShellRegistry().hasSMSWindow(mobile)) { SMSWindow w = main.getShellRegistry().getSMSWindow(mobile); w.setMinimized(false); w.setActive(); return w; } else { SMSWindow w = ShellFactory.createSMSWindow(main, mobile); w.open(); return w; } } /** * ? */ public SMSWindow openSMSWindow() { if (main.getShellRegistry().hasSMSWindow()) { SMSWindow w = main.getShellRegistry().getSMSWindow(); w.setMinimized(false); w.setActive(); return w; } else { SMSWindow w = ShellFactory.createSMSWindow(main); w.open(); return w; } } /** * ?? */ public void openSystemMessageListWindow() { if (main.getShellRegistry().isSystemMessageListWindowOpened()) { SystemMessageListWindow smls = main.getShellRegistry().getSystemMessageListWindow(); smls.setMinimized(false); smls.setActive(); } else { SystemMessageListWindow smls = ShellFactory.createSystemMessageListWindow(main); main.getShellRegistry().registerSystemMessageListWindow(smls); smls.open(); } } /** * ?? * * @param startPage * */ public WizardWindow openSearchWizard() { if (main.getShellRegistry().isSearchWizardOpened()) { WizardWindow ss = main.getShellRegistry().getSearchWizard(); ss.setMinimized(false); ss.setActive(); return ss; } else { WizardWindow window = ShellFactory.createSearchWizard(main); main.getShellRegistry().registerSearchWizard(window); window.open(); return window; } } /** * ? */ public WizardWindow openClusterWizard() { if (main.getShellRegistry().isClusterWizardOpened()) { WizardWindow window = main.getShellRegistry().getClusterWizard(); window.setMinimized(false); window.setActive(); return window; } else { WizardWindow window = ShellFactory.createClusterWizard(main); main.getShellRegistry().registerClusterWizard(window); window.open(); return window; } } /** * ? * * @return * ? */ public SystemOptionWindow openSystemOptionWindow() { SystemOptionWindow sos = null; if (main.getShellRegistry().isSystemOptionWindowOpened()) { sos = main.getShellRegistry().getSystemOptionWindow(); sos.setMinimized(false); sos.setActive(); } else { sos = ShellFactory.createSystemOptionWindow(main); main.getShellRegistry().registerSystemOptionWindow(sos); sos.open(); } return sos; } /** * ? */ public void openCheckUpdateShell() { if (!main.getShellRegistry().isCheckUpdateShellOpened()) { CheckUpdateShell cus = ShellFactory.createCheckUpdateShell(main); main.getShellRegistry().registerCheckUpdateShell(cus); cus.open(); } } /** * /?? * * @param type * @param parentCluster * @param parentOrganization * @param model * @return */ public MemberEditShell openMemberEditShell(int type, Cluster parentCluster, Organization parentOrganization, Model model) { ShellRegistry shellRegistry = main.getShellRegistry(); if (model != null && shellRegistry.hasMemberEditShell(model)) { MemberEditShell shell = shellRegistry.getMemberEditShell(model); shell.setFocus(); shell.setActive(); return shell; } else { MemberEditShell shell = ShellFactory.createMemberEditShell(main, type, parentCluster, parentOrganization); if (model != null) shellRegistry.registerMemberEditShell(model, shell); if (type == MemberEditShell.TEMP_CLUSTER) shell.setCluster((Cluster) model); else shell.setOrganization((Organization) model); shell.open(); return shell; } } /** * ??? * * @param f * ?model */ public void openDeleteReceiveSystemMessageShell(User f) { ReceiveSystemMessageShell rsms = ShellFactory.createReceiveSystemMessageShell(main); rsms.setFriendModel(f); rsms.open(ReceiveSystemMessageShell.DELETE_MODE); } /** * ??? * * @param f * ?model */ public void openAddReceiveSystemMessageShell(User f) { ReceiveSystemMessageShell rsms = ShellFactory.createReceiveSystemMessageShell(main); rsms.setFriendModel(f); rsms.open(ReceiveSystemMessageShell.ADD_MODE); } /** * IP? */ public void openIPSeekerWindow() { IPSeekerWindow iss = ShellFactory.createIPSeekerWindow(main); iss.open(); } /** * ???? * * @param c * model */ public void openClusterIMWindow(Cluster c) { // ?? if (main.getOptionHelper().isUseTabIMWindow()) { openIMTabWindow(c); return; } ShellRegistry shellRegistry = main.getShellRegistry(); MessageQueue mq = main.getMessageQueue(); // ??? SendClusterIMWindow scms = null; if (shellRegistry.hasSendClusterIMWindow(c)) { scms = shellRegistry.getSendClusterIMWindow(c); scms.setMinimized(false); scms.setActive(); } else { scms = ShellFactory.createSendClusterIMWindow(main, c); shellRegistry.addSendClusterIMWindow(c, scms); scms.open(); } // ?0 c.messageCount = 0; BlindHelper blindHelper = main.getBlindHelper(); blindHelper.refreshModel(c); int clusterId = c.clusterId; if (mq.hasMessage(clusterId)) { while (mq.hasMessage(clusterId)) { // ? ReceiveIMPacket packet = (ReceiveIMPacket) mq.getMessage(clusterId); scms.appendMessage(c, packet.clusterIM, false); } blindHelper.getViewer(c).stopAnimation(c); switch (c.clusterType) { case SUBJECT: blindHelper.stopBlinkText(c.getParentCluster().getSubjectDummy()); blindHelper.getViewer(c).stopAnimation(c.getParentCluster()); break; case DIALOG: blindHelper.stopBlinkText(c.getParentCluster()); break; } // view part?? blindHelper.resetGroupImageEffect(main.getBlindHelper().getClusterGroup()); // ?? main.getUIHelper().resetTrayImageEffect(); } } /** * ???sender? * * @param sender * ??? */ public void openIMShell(int sender) { Cluster c = ModelRegistry.getCluster(sender); if (c == null) openNormalIMWindow(ModelRegistry.getUser(sender)); else openClusterIMWindow(c); } /** * ??? * * @param f */ public void openTempSessionIMWindow(int qq) { // User? User f = ModelRegistry.getUser(qq); boolean noUser = f == null; if (noUser) { f = new User(); f.qq = qq; f.nick = f.displayName = String.valueOf(qq); } // ??? ShellRegistry shellRegistry = main.getShellRegistry(); MessageQueue mq = main.getMessageQueue(); TempSessionIMWindow sms = null; if (shellRegistry.hasTempSessionIMWindow(f)) { sms = shellRegistry.getTempSessionIMWindow(f); sms.setMinimized(false); sms.setActive(); sms.setFocus(); } else { sms = ShellFactory.createTempSessionIMWindow(main, f); sms.open(); } // ??????????? if (mq.hasTempSessionMessage(f.qq)) { while (mq.hasTempSessionMessage(f.qq)) { // ? ReceiveIMPacket packet = (ReceiveIMPacket) mq.getTempSessionMessage(f.qq); sms.appendMessage(f, packet.tempSessionIM); } // ??? main.getBlindHelper().stopAnimation(f.group, f); f.hasMessage = false; // ?view part?? main.getBlindHelper().resetGroupImageEffect(f.group); // ?? main.getUIHelper().resetTrayImageEffect(); } // ??? if (noUser) main.getClient().getUserInfo(qq); } /** * ???? * * @param f * ?model * @return * ??SendMessageShell?ReceiveMessageShell */ public void openNormalIMWindow(User f) { // ?? if (main.getOptionHelper().isUseTabIMWindow()) { openIMTabWindow(f); return; } ShellRegistry shellRegistry = main.getShellRegistry(); MessageQueue mq = main.getMessageQueue(); // QQ? int qqNum = f.qq; // ????????? // ???????? // ????? // ?????? // ????????????? // ???????model if (f.talkMode) { // ????? SendIMWindow sms = null; if (shellRegistry.hasSendIMWindow(f)) { sms = shellRegistry.getSendIMWindow(f); sms.setMinimized(false); sms.setActive(); sms.setFocus(); } else { sms = ShellFactory.createSendIMWindow(main, f); sms.open(); } // ??????????? if (mq.hasMessage(qqNum)) { while (mq.hasMessage(qqNum)) { // ? ReceiveIMPacket packet = (ReceiveIMPacket) mq.getMessage(qqNum); sms.appendMessage(f, packet.normalIM, packet.normalHeader); } // ??? main.getBlindHelper().getViewer(f).stopAnimation(f); f.hasMessage = false; main.getBlindHelper().refreshGroup(f.group); // ?view part?? main.getBlindHelper().resetGroupImageEffect(f.group); // ?? main.getUIHelper().resetTrayImageEffect(); } } else { if (mq.hasMessage(qqNum)) { // ???? // ? ReceiveIMPacket packet = (ReceiveIMPacket) mq.getMessage(qqNum); // ????? if (!mq.hasMessage(qqNum)) { main.getBlindHelper().stopAnimation(f.group, f); f.hasMessage = false; main.getBlindHelper().refreshModel(f); } // ?view part?? main.getBlindHelper().resetGroupImageEffect(f.group); // ?? main.getUIHelper().resetTrayImageEffect(); // ???????? // ???? ReceiveIMWindow rms = null; if (shellRegistry.hasReceiveIMWindow(f)) { rms = shellRegistry.getReceiveIMWindow(f); rms.setMinimized(false); } else { // ?? rms = ShellFactory.createReceiveIMWindow(main, f); rms.open(); } rms.setMessage(packet); rms.setNextButtonEnabled(mq.hasMessage(qqNum)); rms.setActive(); } else { // ????? // ????????? SendIMWindow sms = null; if (shellRegistry.hasSendIMWindow(f)) { sms = shellRegistry.getSendIMWindow(f); sms.setMinimized(false); sms.setFocus(); } else { sms = ShellFactory.createSendIMWindow(main, f); sms.open(); } sms.setActive(); } } } /** * ? * * @param c * model * @return * ? */ public ClusterInfoWindow openClusterInfoWindow(Cluster c) { ShellRegistry shellRegistry = main.getShellRegistry(); if (shellRegistry.hasClusterInfoWindow(c)) { ClusterInfoWindow cis = shellRegistry.getClusterInfoWindow(c); cis.setMinimized(false); cis.setActive(); return cis; } else { ClusterInfoWindow cis = ShellFactory.createClusterInfoWindow(main, c); shellRegistry.addClusterInfoWindow(c, cis); cis.open(); return cis; } } /** * ?? * * @param url * URL * @param title * ? * @param errorString * ? */ public void openBrowserShell(String url, String title, String errorString) { // ????? String browser = main.getOptionHelper().getBrowser(); try { if (browser.equals("")) { MessageDialog dialog = new MessageDialog(main.getShell(), message_box_common_question_title, null, message_box_browser_not_set, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0); switch (dialog.open()) { case 0: main.getShellLauncher().openSystemOptionWindow().setCurrentPage(SystemOptionWindow.OTHER); break; case 1: BrowserShell bs = ShellFactory.createBrowserShell(main); bs.setUrl(url); bs.setTitle(title); bs.open(); break; } } else Runtime.getRuntime().exec(browser.replaceAll("\\[URL\\]", url)); } catch (Throwable t) { MessageDialog.openWarning(main.getShell(), message_box_common_warning_title, errorString); } } /** * ?? * * @param packet * ? */ public void openReceiveSystemMessageShell(InPacket packet) { // ???? if (!main.getMessageQueue().hasSystemMessage()) main.getUIHelper().stopBlinkSystemMessageIcon(); // tray icon?? main.getUIHelper().resetTrayImageEffect(); // ?? ReceiveSystemMessageShell rsms = ShellFactory.createReceiveSystemMessageShell(main); rsms.setSystemMessage(packet); rsms.open(); } /** * ?? * * @param entry * ? */ public void openReceiveSystemMessageShell(RecordEntry entry) { ReceiveSystemMessageShell rsms = ShellFactory.createReceiveSystemMessageShell(main); rsms.setSystemMessage(entry); rsms.open(); } /** * ?????friendmodel? * * @param f * ?model * @param style * ?? */ public UserInfoWindow openUserInfoWindow(User f, int style) { ShellRegistry shellRegistry = main.getShellRegistry(); // ?????? if (shellRegistry.hasUserInfoWindow(f)) { UserInfoWindow uiw = shellRegistry.getUserInfoWindow(f); uiw.setMinimized(false); uiw.setActive(); return uiw; } else { UserInfoWindow uiw = ShellFactory.createUserInfoWindow(main, f, style); shellRegistry.addUserInfoWindow(f, uiw); uiw.open(); return uiw; } } /** * ?? */ public void openFaceWindow() { ShellRegistry shellRegistry = main.getShellRegistry(); if (shellRegistry.isFaceWindowOpened()) { FaceWindow window = shellRegistry.getFaceWindow(); window.setMinimized(false); window.setActive(); } else { FaceWindow window = ShellFactory.createFaceWindow(main); shellRegistry.registerFaceWindow(window); window.open(); } } /** * ???? * * @param model * Model */ public SendIMTabWindow openIMTabWindow(Model model) { ShellRegistry shellRegistry = main.getShellRegistry(); SendIMTabWindow window = null; if (shellRegistry.isSendIMTabWindowOpened()) { window = shellRegistry.getSendIMTabWindow(); window.setMinimized(false); window.setActive(); } else { window = ShellFactory.createSendIMTabWindow(main); shellRegistry.registerSendIMTabWindow(window); window.open(); } window.addTabIM(model); window.activeContainer(model); // ??????????? MessageQueue mq = main.getMessageQueue(); if (model instanceof User) { User f = (User) model; if (mq.hasMessage(f.qq)) { while (mq.hasMessage(f.qq)) { // ? ReceiveIMPacket packet = (ReceiveIMPacket) mq.getMessage(f.qq); window.putMessage(model, packet); } // ??? main.getBlindHelper().getViewer(model).stopAnimation(model); f.hasMessage = false; main.getBlindHelper().refreshGroup(f.group); // ?view part?? main.getBlindHelper().resetGroupImageEffect(f.group); // ?? main.getUIHelper().resetTrayImageEffect(); } } else if (model instanceof Cluster) { BlindHelper blindHelper = main.getBlindHelper(); Cluster c = (Cluster) model; if (mq.hasMessage(c.clusterId)) { while (mq.hasMessage(c.clusterId)) { // ? ReceiveIMPacket packet = (ReceiveIMPacket) mq.getMessage(c.clusterId); window.putMessage(c, packet); } blindHelper.getViewer(c).stopAnimation(c); switch (c.clusterType) { case SUBJECT: blindHelper.stopBlinkText(c.getParentCluster().getSubjectDummy()); blindHelper.getViewer(c).stopAnimation(c.getParentCluster()); break; case DIALOG: blindHelper.stopBlinkText(c.getParentCluster()); break; } // view part?? blindHelper.resetGroupImageEffect(main.getBlindHelper().getClusterGroup()); // ?? main.getUIHelper().resetTrayImageEffect(); } } return window; } /** * ?? * * @return * ??? */ public InfoManagerWindow openInfoManagerWindow() { if (main.getShellRegistry().isInfoManagerWindowOpen()) { InfoManagerWindow w = main.getShellRegistry().getInfoManagerWindow(); w.setMinimized(false); w.setActive(); return w; } else { InfoManagerWindow w = ShellFactory.createInfoManagerWindow(main); main.getShellRegistry().registerInfoManagerWindow(w); w.open(); return w; } } /** * ?? * * @param main */ public void openLastLoginTipWindow(MainShell main) { ShellFactory.createLastLoginTipWindow(main).open(); } }