private void browseItem(DiscoverItems.Item discoveredItem) { addAddress(discoveredItem.getEntityID()); browsePanel.removeAll(); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con); DiscoverItems result; try { result = discoManager.discoverItems(discoveredItem.getEntityID()); } catch (XMPPException e) { browsePanel.invalidate(); browsePanel.validate(); browsePanel.repaint(); return; } Iterator<DiscoverItems.Item> discoverItems = result.getItems(); List<Entity> list = new ArrayList<Entity>(); while (discoverItems.hasNext()) { DiscoverItems.Item item = discoverItems.next(); Entity entity = new Entity(item); browsePanel.add(entity); list.add(entity); } GraphicUtils.makeSameSize((JComponent[]) list.toArray(new JComponent[list.size()])); browsePanel.invalidate(); browsePanel.validate(); browsePanel.repaint(); }
/** Displays the Spark error log. */ private void showErrorLog() { final File logDir = new File(Spark.getLogDirectory(), "errors.log"); // Read file and show final String errorLogs = URLFileSystem.getContents(logDir); final JFrame frame = new JFrame(Res.getString("title.client.logs")); frame.setLayout(new BorderLayout()); frame.setIconImage(SparkManager.getApplicationImage().getImage()); final JTextPane pane = new JTextPane(); pane.setBackground(Color.white); pane.setFont(new Font("Dialog", Font.PLAIN, 12)); pane.setEditable(false); pane.setText(errorLogs); frame.add(new JScrollPane(pane), BorderLayout.CENTER); final JButton copyButton = new JButton(Res.getString("button.copy.to.clipboard")); frame.add(copyButton, BorderLayout.SOUTH); copyButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { SparkManager.setClipboard(errorLogs); copyButton.setEnabled(false); } }); frame.pack(); frame.setSize(600, 400); GraphicUtils.centerWindowOnScreen(frame); frame.setVisible(true); }
public String getToolTipText(MouseEvent e) { int r = rowAtPoint(e.getPoint()); int c = columnAtPoint(e.getPoint()); Object value; try { value = getValueAt(r, c); } catch (Exception e1) { // If we encounter a row that should not actually exist and therefore // has a null value. Just return an empty string for the tooltip. return ""; } String tooltipValue = null; if (value instanceof JLabel) { tooltipValue = ((JLabel) value).getToolTipText(); } if (value instanceof JLabel && tooltipValue == null) { tooltipValue = ((JLabel) value).getText(); } else if (value != null && tooltipValue == null) { tooltipValue = value.toString(); } else if (tooltipValue == null) { tooltipValue = ""; } return GraphicUtils.createToolTip(tooltipValue); }
/** Update avatar icon. */ public void updateAvatarInSideIcon() { try { final URL url = getAvatarURL(); if (url != null) { if (!avatarsShowing) { setSideIcon(null); } else { ImageIcon icon = new ImageIcon(url); icon = GraphicUtils.scale(icon, iconSize, iconSize); setSideIcon(icon); } } } catch (MalformedURLException e) { Log.error(e); } }
/** * Builds the UI based on a VCard. * * @param vcard the vcard used to build the UI. */ private void buildUI(VCard vcard) { personalPanel.setFirstName(vcard.getFirstName()); personalPanel.setMiddleName(vcard.getMiddleName()); personalPanel.setLastName(vcard.getLastName()); personalPanel.setEmailAddress(vcard.getEmailHome()); personalPanel.setNickname(vcard.getNickName()); personalPanel.setJID(vcard.getJabberId()); businessPanel.setCompany(vcard.getOrganization()); businessPanel.setDepartment(vcard.getOrganizationUnit()); businessPanel.setStreetAddress(vcard.getAddressFieldWork("STREET")); businessPanel.setCity(vcard.getAddressFieldWork("LOCALITY")); businessPanel.setState(vcard.getAddressFieldWork("REGION")); businessPanel.setZipCode(vcard.getAddressFieldWork("PCODE")); businessPanel.setCountry(vcard.getAddressFieldWork("CTRY")); businessPanel.setJobTitle(vcard.getField("TITLE")); businessPanel.setPhone(vcard.getPhoneWork("VOICE")); businessPanel.setFax(vcard.getPhoneWork("FAX")); businessPanel.setPager(vcard.getPhoneWork("PAGER")); businessPanel.setMobile(vcard.getPhoneWork("CELL")); businessPanel.setWebPage(vcard.getField("URL")); // Load Home Info homePanel.setStreetAddress(vcard.getAddressFieldHome("STREET")); homePanel.setCity(vcard.getAddressFieldHome("LOCALITY")); homePanel.setState(vcard.getAddressFieldHome("REGION")); homePanel.setZipCode(vcard.getAddressFieldHome("PCODE")); homePanel.setCountry(vcard.getAddressFieldHome("CTRY")); homePanel.setPhone(vcard.getPhoneHome("VOICE")); homePanel.setFax(vcard.getPhoneHome("FAX")); homePanel.setPager(vcard.getPhoneHome("PAGER")); homePanel.setMobile(vcard.getPhoneHome("CELL")); // Set avatar byte[] bytes = vcard.getAvatar(); if (bytes != null && bytes.length > 0) { ImageIcon icon = new ImageIcon(bytes); avatarPanel.setAvatar(icon); avatarPanel.setAvatarBytes(bytes); if (avatarLabel != null) { icon = GraphicUtils.scaleImageIcon(icon, 48, 48); avatarLabel.setIcon(icon); } } }
/** * Constructs the UI for the MainWindow. The MainWindow UI is the container for the entire Spark * application. * * @param title the title of the frame. * @param icon the icon used in the frame. */ private MainWindow(String title, ImageIcon icon) { // Initialize and dock the menus buildMenu(); // Add Workspace Container getContentPane().setLayout(new BorderLayout()); LayoutSettings settings = LayoutSettingsManager.getLayoutSettings(); if (settings.getMainWindowX() == 0 && settings.getMainWindowY() == 0) { // Use default settings. setSize(300, 500); GraphicUtils.centerWindowOnScreen(this); } else { setBounds( settings.getMainWindowX(), settings.getMainWindowY(), settings.getMainWindowWidth(), settings.getMainWindowHeight()); } // Add menubar this.setJMenuBar(mainWindowBar); this.getContentPane().add(topToolbar, BorderLayout.NORTH); setTitle(title); setIconImage(icon.getImage()); // Setup WindowListener to be the proxy to the actual window listener // which cannot normally be used outside of the Window component because // of protected access. addWindowListener( new WindowAdapter() { /** * This event fires when the window has become active. * * @param e WindowEvent is not used. */ public void windowActivated(WindowEvent e) { fireWindowActivated(); } /** Invoked when a window is de-activated. */ public void windowDeactivated(WindowEvent e) {} /** * This event fires whenever a user minimizes the window from the toolbar. * * @param e WindowEvent is not used. */ public void windowIconified(WindowEvent e) {} /** * This event fires when the application is closing. This allows Plugins to do any * persistence or other work before exiting. * * @param e WindowEvent is never used. */ public void windowClosing(WindowEvent e) { saveLayout(); setVisible(false); } }); this.addWindowFocusListener(new MainWindowFocusListener()); }
/** Saves the VCard. */ private void saveVCard() { final VCard vcard = new VCard(); // Save personal info vcard.setFirstName(personalPanel.getFirstName()); vcard.setLastName(personalPanel.getLastName()); vcard.setMiddleName(personalPanel.getMiddleName()); vcard.setEmailHome(personalPanel.getEmailAddress()); vcard.setNickName(personalPanel.getNickname()); // Save business info vcard.setOrganization(businessPanel.getCompany()); vcard.setAddressFieldWork("STREET", businessPanel.getStreetAddress()); vcard.setAddressFieldWork("LOCALITY", businessPanel.getCity()); vcard.setAddressFieldWork("REGION", businessPanel.getState()); vcard.setAddressFieldWork("PCODE", businessPanel.getZipCode()); vcard.setAddressFieldWork("CTRY", businessPanel.getCountry()); vcard.setField("TITLE", businessPanel.getJobTitle()); vcard.setOrganizationUnit(businessPanel.getDepartment()); vcard.setPhoneWork("VOICE", businessPanel.getPhone()); vcard.setPhoneWork("FAX", businessPanel.getFax()); vcard.setPhoneWork("PAGER", businessPanel.getPager()); vcard.setPhoneWork("CELL", businessPanel.getMobile()); vcard.setField("URL", businessPanel.getWebPage()); // Save Home Info vcard.setAddressFieldHome("STREET", homePanel.getStreetAddress()); vcard.setAddressFieldHome("LOCALITY", homePanel.getCity()); vcard.setAddressFieldHome("REGION", homePanel.getState()); vcard.setAddressFieldHome("PCODE", homePanel.getZipCode()); vcard.setAddressFieldHome("CTRY", homePanel.getCountry()); vcard.setPhoneHome("VOICE", homePanel.getPhone()); vcard.setPhoneHome("FAX", homePanel.getFax()); vcard.setPhoneHome("PAGER", homePanel.getPager()); vcard.setPhoneHome("CELL", homePanel.getMobile()); // Save Avatar final File avatarFile = avatarPanel.getAvatarFile(); byte[] avatarBytes = avatarPanel.getAvatarBytes(); if (avatarFile != null) { try { // Make it 48x48 ImageIcon icon = new ImageIcon(avatarFile.toURI().toURL()); Image image = icon.getImage(); image = image.getScaledInstance(-1, 48, Image.SCALE_SMOOTH); avatarBytes = GraphicUtils.getBytesFromImage(image); } catch (MalformedURLException e) { Log.error("Unable to set avatar.", e); } } // If avatar bytes, persist as vcard. if (avatarBytes != null) { vcard.setAvatar(avatarBytes); } try { final VCardManager vcardManager = SparkManager.getVCardManager(); vcardManager.setPersonalVCard(vcard); vcard.save(SparkManager.getConnection()); // Notify users. if (avatarFile != null || avatarBytes != null) { Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence(); Presence newPresence = new Presence( presence.getType(), presence.getStatus(), presence.getPriority(), presence.getMode()); // Change my own presence SparkManager.getSessionManager().changePresence(newPresence); // Chnage avatar in status bar. StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); statusBar.setAvatar(new ImageIcon(vcard.getAvatar())); } else { String firstName = vcard.getFirstName(); String lastName = vcard.getLastName(); StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) { statusBar.setNickname(firstName + " " + lastName); } else if (ModelUtil.hasLength(firstName)) { statusBar.setNickname(firstName); } statusBar.setAvatar(null); } // Notify listenres SparkManager.getVCardManager().notifyVCardListeners(); } catch (XMPPException e) { Log.error(e); JOptionPane.showMessageDialog( SparkManager.getMainWindow(), Res.getString("message.vcard.not.supported"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE); } }