mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
Refactoring work.
git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@8450 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
@ -12,14 +12,15 @@ package org.jivesoftware.resource;
|
|||||||
|
|
||||||
import org.jivesoftware.spark.util.log.Log;
|
import org.jivesoftware.spark.util.log.Log;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.PropertyResourceBundle;
|
import java.util.PropertyResourceBundle;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
|
|
||||||
public class Default {
|
public class Default {
|
||||||
private static PropertyResourceBundle prb;
|
private static PropertyResourceBundle prb;
|
||||||
|
|
||||||
@ -103,4 +104,18 @@ public class Default {
|
|||||||
return cl.getResource(getString(propertyName));
|
return cl.getResource(getString(propertyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static final URL getURLWithoutException(String propertyName) {
|
||||||
|
// Otherwise, load and add to cache.
|
||||||
|
try {
|
||||||
|
final String iconURI = getString(propertyName);
|
||||||
|
final URL imageURL = cl.getResource(iconURI);
|
||||||
|
return imageURL;
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Log.debug(propertyName + " not found.");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
package org.jivesoftware.resource;
|
package org.jivesoftware.resource;
|
||||||
|
|
||||||
|
import org.jivesoftware.spark.util.log.Log;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JEditorPane;
|
import javax.swing.JEditorPane;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
@ -347,4 +349,17 @@ public class SparkRes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final URL getURLWithoutException(String propertyName) {
|
||||||
|
// Otherwise, load and add to cache.
|
||||||
|
try {
|
||||||
|
final String iconURI = getString(propertyName);
|
||||||
|
final URL imageURL = cl.getResource(iconURI);
|
||||||
|
return imageURL;
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Log.debug(propertyName + " not found.");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -10,7 +10,10 @@
|
|||||||
|
|
||||||
package org.jivesoftware.spark;
|
package org.jivesoftware.spark;
|
||||||
|
|
||||||
|
import org.jivesoftware.spark.component.browser.BrowserViewer;
|
||||||
|
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementations of this interface define alert mechanisms based on the Operating System
|
* Implementations of this interface define alert mechanisms based on the Operating System
|
||||||
@ -41,6 +44,30 @@ public interface Alerter {
|
|||||||
*/
|
*/
|
||||||
void stopFlashing(Window window);
|
void stopFlashing(Window window);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup system tray.
|
||||||
|
*/
|
||||||
|
void setupSystemTray();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start Idle Process.
|
||||||
|
*/
|
||||||
|
void startIdleProcess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Browser to use for this platform.
|
||||||
|
*
|
||||||
|
* @return the <code>BrowserViewer</code> to use.
|
||||||
|
*/
|
||||||
|
BrowserViewer getBrowser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instructs Spark to open up a file.
|
||||||
|
*
|
||||||
|
* @param file the file or directory to open.
|
||||||
|
*/
|
||||||
|
void openFile(File file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if this <code>Alerter</code> should handle the alert request.
|
* Return true if this <code>Alerter</code> should handle the alert request.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -206,9 +206,6 @@ public final class SessionManager implements ConnectionListener {
|
|||||||
// Send Presence Packet
|
// Send Presence Packet
|
||||||
SparkManager.getConnection().sendPacket(presence);
|
SparkManager.getConnection().sendPacket(presence);
|
||||||
|
|
||||||
// Update Tray Icon
|
|
||||||
SparkManager.getNotificationsEngine().changePresence(presence);
|
|
||||||
|
|
||||||
// Fire Presence Listeners
|
// Fire Presence Listeners
|
||||||
final Iterator presenceListeners = new ArrayList(this.presenceListeners).iterator();
|
final Iterator presenceListeners = new ArrayList(this.presenceListeners).iterator();
|
||||||
while (presenceListeners.hasNext()) {
|
while (presenceListeners.hasNext()) {
|
||||||
@ -269,7 +266,9 @@ public final class SessionManager implements ConnectionListener {
|
|||||||
* @throws Exception thrown is an error occurs loading native library.
|
* @throws Exception thrown is an error occurs loading native library.
|
||||||
*/
|
*/
|
||||||
private void setIdleListener() throws Exception {
|
private void setIdleListener() throws Exception {
|
||||||
|
if(true){
|
||||||
|
return;
|
||||||
|
}
|
||||||
final Timer timer = new Timer();
|
final Timer timer = new Timer();
|
||||||
|
|
||||||
timer.scheduleAtFixedRate(new TimerTask() {
|
timer.scheduleAtFixedRate(new TimerTask() {
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import org.jivesoftware.resource.SparkRes;
|
|||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smackx.MessageEventManager;
|
import org.jivesoftware.smackx.MessageEventManager;
|
||||||
import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
||||||
import org.jivesoftware.spark.component.Notifications;
|
|
||||||
import org.jivesoftware.spark.filetransfer.SparkTransferManager;
|
import org.jivesoftware.spark.filetransfer.SparkTransferManager;
|
||||||
import org.jivesoftware.spark.preference.PreferenceManager;
|
import org.jivesoftware.spark.preference.PreferenceManager;
|
||||||
import org.jivesoftware.spark.search.SearchManager;
|
import org.jivesoftware.spark.search.SearchManager;
|
||||||
@ -91,7 +90,6 @@ public final class SparkManager {
|
|||||||
private static MessageEventManager messageEventManager;
|
private static MessageEventManager messageEventManager;
|
||||||
private static UserManager userManager;
|
private static UserManager userManager;
|
||||||
private static ChatManager chatManager;
|
private static ChatManager chatManager;
|
||||||
private static Notifications notifications;
|
|
||||||
private static VCardManager vcardManager;
|
private static VCardManager vcardManager;
|
||||||
private static AlertManager alertManager;
|
private static AlertManager alertManager;
|
||||||
|
|
||||||
@ -219,21 +217,6 @@ public final class SparkManager {
|
|||||||
return Workspace.getInstance();
|
return Workspace.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the Notification System to handle general notification in either
|
|
||||||
* the system tray or "toaster" popups. You could use the notification engine
|
|
||||||
* to alert users to incoming messages, new emails, or forum posts.
|
|
||||||
*
|
|
||||||
* @return the Notification system.
|
|
||||||
*/
|
|
||||||
public static Notifications getNotificationsEngine() {
|
|
||||||
if (notifications == null) {
|
|
||||||
notifications = new Notifications();
|
|
||||||
}
|
|
||||||
return notifications;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the <code>MessageEventManager</code> used in Spark. The MessageEventManager is responsible
|
* Returns the <code>MessageEventManager</code> used in Spark. The MessageEventManager is responsible
|
||||||
* for XMPP specific operations such as notifying users that you have received their message or
|
* for XMPP specific operations such as notifying users that you have received their message or
|
||||||
|
|||||||
@ -187,9 +187,6 @@ public class Workspace extends JPanel implements PacketListener {
|
|||||||
public void buildLayout() {
|
public void buildLayout() {
|
||||||
new Enterprise();
|
new Enterprise();
|
||||||
|
|
||||||
// Initilaize tray
|
|
||||||
SparkManager.getNotificationsEngine();
|
|
||||||
|
|
||||||
// Initialize Contact List
|
// Initialize Contact List
|
||||||
contactList = new ContactList();
|
contactList = new ContactList();
|
||||||
conferences = new ConferenceServices();
|
conferences = new ConferenceServices();
|
||||||
|
|||||||
@ -1,378 +0,0 @@
|
|||||||
/**
|
|
||||||
* $Revision: $
|
|
||||||
* $Date: $
|
|
||||||
*
|
|
||||||
* Copyright (C) 2006 Jive Software. All rights reserved.
|
|
||||||
*
|
|
||||||
* This software is published under the terms of the GNU Lesser Public License (LGPL),
|
|
||||||
* a copy of which is included in this distribution.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jivesoftware.spark.component;
|
|
||||||
|
|
||||||
import org.jdesktop.jdic.tray.SystemTray;
|
|
||||||
import org.jdesktop.jdic.tray.TrayIcon;
|
|
||||||
import org.jivesoftware.MainWindow;
|
|
||||||
import org.jivesoftware.MainWindowListener;
|
|
||||||
import org.jivesoftware.Spark;
|
|
||||||
import org.jivesoftware.resource.Default;
|
|
||||||
import org.jivesoftware.resource.Res;
|
|
||||||
import org.jivesoftware.resource.SparkRes;
|
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
|
||||||
import org.jivesoftware.spark.SparkManager;
|
|
||||||
import org.jivesoftware.spark.Workspace;
|
|
||||||
import org.jivesoftware.spark.ui.PresenceListener;
|
|
||||||
import org.jivesoftware.spark.ui.status.StatusBar;
|
|
||||||
import org.jivesoftware.spark.ui.status.StatusItem;
|
|
||||||
import org.jivesoftware.spark.util.log.Log;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.Frame;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.awt.Insets;
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.Toolkit;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
|
||||||
import javax.swing.Action;
|
|
||||||
import javax.swing.BorderFactory;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JMenu;
|
|
||||||
import javax.swing.JMenuItem;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JPopupMenu;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles tray icon operations inside of Spark. Use to display incoming chat requests, incoming messages
|
|
||||||
* and general notifications.
|
|
||||||
*/
|
|
||||||
public final class Notifications implements ActionListener, MainWindowListener {
|
|
||||||
private ImageIcon availableIcon;
|
|
||||||
private ImageIcon unavaliableIcon;
|
|
||||||
private ImageIcon busyIcon;
|
|
||||||
private TrayIcon trayIcon;
|
|
||||||
private JPopupMenu notificationDialog;
|
|
||||||
private WrappedLabel messageLabel = new WrappedLabel();
|
|
||||||
|
|
||||||
|
|
||||||
private final JMenuItem openMenu = new JMenuItem(Res.getString("menuitem.open"));
|
|
||||||
private final JMenuItem hideMenu = new JMenuItem(Res.getString("menuitem.hide"));
|
|
||||||
private final JMenuItem exitMenu = new JMenuItem(Res.getString("menuitem.exit"));
|
|
||||||
|
|
||||||
// Define DND MenuItems
|
|
||||||
private final JMenu statusMenu = new JMenu(Res.getString("menuitem.status"));
|
|
||||||
|
|
||||||
private boolean isDisposed;
|
|
||||||
private ImageTitlePanel headerLabel = new ImageTitlePanel();
|
|
||||||
|
|
||||||
private JFrame hideWindow = null;
|
|
||||||
|
|
||||||
private long madeVisibleTime = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance of notifications.
|
|
||||||
*/
|
|
||||||
public Notifications() {
|
|
||||||
// Tray only works in windows.
|
|
||||||
if (Spark.isMac()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SystemTray tray = null;
|
|
||||||
try {
|
|
||||||
tray = SystemTray.getDefaultSystemTray();
|
|
||||||
}
|
|
||||||
catch (Throwable e) {
|
|
||||||
Log.error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
setupNotificationDialog();
|
|
||||||
|
|
||||||
// Handle tray image.
|
|
||||||
final ImageIcon trayImage = Default.getImageIcon(Default.TRAY_IMAGE);
|
|
||||||
if (trayImage != null) {
|
|
||||||
availableIcon = trayImage;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
availableIcon = SparkRes.getImageIcon(SparkRes.TRAY_IMAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unavaliableIcon = SparkRes.getImageIcon(SparkRes.MESSAGE_AWAY);
|
|
||||||
busyIcon = SparkRes.getImageIcon(SparkRes.MESSAGE_DND);
|
|
||||||
trayIcon = new TrayIcon(availableIcon);
|
|
||||||
trayIcon.setToolTip(Default.getString(Default.APPLICATION_NAME)); // NORES
|
|
||||||
|
|
||||||
JPopupMenu popupMenu = new JPopupMenu(Res.getString("title.tray.information"));
|
|
||||||
|
|
||||||
// Add DND Menus
|
|
||||||
addStatusMenuItems();
|
|
||||||
|
|
||||||
// Add Open Menu
|
|
||||||
openMenu.setFont(new Font("Dialog", Font.BOLD, 11));
|
|
||||||
popupMenu.add(openMenu);
|
|
||||||
|
|
||||||
// Add Hide Menu
|
|
||||||
popupMenu.add(hideMenu);
|
|
||||||
popupMenu.addSeparator();
|
|
||||||
// Add Spark Home Menu
|
|
||||||
|
|
||||||
popupMenu.add(statusMenu);
|
|
||||||
|
|
||||||
// Add Listeners
|
|
||||||
openMenu.addActionListener(this);
|
|
||||||
hideMenu.addActionListener(this);
|
|
||||||
|
|
||||||
|
|
||||||
Action logoutAction = new AbstractAction() {
|
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
|
||||||
SparkManager.getMainWindow().logout(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
logoutAction.putValue(Action.NAME, Res.getString("menuitem.logout.no.status"));
|
|
||||||
|
|
||||||
if (Spark.isWindows()) {
|
|
||||||
popupMenu.add(logoutAction);
|
|
||||||
}
|
|
||||||
// Add Exit Menu
|
|
||||||
popupMenu.add(exitMenu);
|
|
||||||
exitMenu.addActionListener(this);
|
|
||||||
|
|
||||||
SparkManager.getMainWindow().addMainWindowListener(this);
|
|
||||||
|
|
||||||
trayIcon.setPopupMenu(popupMenu);
|
|
||||||
trayIcon.addActionListener(this);
|
|
||||||
|
|
||||||
if (tray != null) {
|
|
||||||
tray.addTrayIcon(trayIcon);
|
|
||||||
}
|
|
||||||
SparkManager.getSessionManager().addPresenceListener(new PresenceListener() {
|
|
||||||
public void presenceChanged(Presence presence) {
|
|
||||||
changePresence(presence);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Change the presence of the tray.
|
|
||||||
*
|
|
||||||
* @param presence the new presence.
|
|
||||||
*/
|
|
||||||
public void changePresence(Presence presence) {
|
|
||||||
if (Spark.isMac()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (presence.getMode() == Presence.Mode.available || presence.getMode() == Presence.Mode.chat) {
|
|
||||||
trayIcon.setIcon(availableIcon);
|
|
||||||
}
|
|
||||||
else if (presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa) {
|
|
||||||
trayIcon.setIcon(unavaliableIcon);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
trayIcon.setIcon(busyIcon);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get Status Text
|
|
||||||
if (presence.isAvailable()) {
|
|
||||||
String status = presence.getStatus();
|
|
||||||
trayIcon.setToolTip(Default.getString(Default.APPLICATION_NAME) + "\n" + status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notify agent that there is a new incoming chat request.
|
|
||||||
*/
|
|
||||||
public final void showIncomingRequest() {
|
|
||||||
// Make sure we only show when minimized or not in focus
|
|
||||||
if (SparkManager.getMainWindow().isInFocus()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
displayBubble("Incoming Request", "You have a new incoming chat request.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the icon from flashing.
|
|
||||||
*/
|
|
||||||
public void stopFlashing() {
|
|
||||||
Workspace workspace = SparkManager.getWorkspace();
|
|
||||||
|
|
||||||
StatusBar statusBox = workspace.getStatusBar();
|
|
||||||
Presence presence = statusBox.getPresence();
|
|
||||||
|
|
||||||
changePresence(presence);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Object o = e.getSource();
|
|
||||||
if (!(o instanceof JMenuItem)) {
|
|
||||||
MainWindow window = SparkManager.getMainWindow();
|
|
||||||
/*
|
|
||||||
if (window.isVisible() && window.getState() == Frame.NORMAL) {
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
if (now - madeVisibleTime > 1000) {
|
|
||||||
window.setVisible(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
madeVisibleTime = System.currentTimeMillis();
|
|
||||||
*/
|
|
||||||
showMainWindow();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final JMenuItem item = (JMenuItem)e.getSource();
|
|
||||||
if (item == openMenu) {
|
|
||||||
showMainWindow();
|
|
||||||
}
|
|
||||||
else if (item == hideMenu) {
|
|
||||||
SparkManager.getMainWindow().setVisible(false);
|
|
||||||
hideMenu.setEnabled(false);
|
|
||||||
}
|
|
||||||
else if (item == exitMenu) {
|
|
||||||
isDisposed = true;
|
|
||||||
SparkManager.getMainWindow().shutdown();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
final String status = item.getText();
|
|
||||||
|
|
||||||
// Change Status
|
|
||||||
Workspace workspace = SparkManager.getWorkspace();
|
|
||||||
StatusItem statusItem = workspace.getStatusBar().getStatusItem(status);
|
|
||||||
if (statusItem != null) {
|
|
||||||
SparkManager.getSessionManager().changePresence(statusItem.getPresence());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Brings the <code>MainWindow</code> to the front.
|
|
||||||
*/
|
|
||||||
private void showMainWindow() {
|
|
||||||
if (hideWindow != null) {
|
|
||||||
hideWindow.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
SparkManager.getMainWindow().setState(Frame.NORMAL);
|
|
||||||
SparkManager.getMainWindow().setVisible(true);
|
|
||||||
|
|
||||||
notificationDialog.setVisible(false);
|
|
||||||
|
|
||||||
hideMenu.setEnabled(true);
|
|
||||||
|
|
||||||
SparkManager.getMainWindow().toFront();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add all Registered DND's to MenuItems.
|
|
||||||
*/
|
|
||||||
private void addStatusMenuItems() {
|
|
||||||
Workspace workspace = SparkManager.getWorkspace();
|
|
||||||
StatusBar statusBar = workspace.getStatusBar();
|
|
||||||
|
|
||||||
Iterator iter = statusBar.getStatusList().iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
StatusItem item = (StatusItem)iter.next();
|
|
||||||
final JMenuItem menuItem = new JMenuItem(item.getText(), item.getIcon());
|
|
||||||
menuItem.addActionListener(this);
|
|
||||||
statusMenu.add(menuItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mainWindowActivated() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mainWindowDeactivated() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup notification dialog.
|
|
||||||
*/
|
|
||||||
private void setupNotificationDialog() {
|
|
||||||
notificationDialog = new JPopupMenu();
|
|
||||||
notificationDialog.setFocusable(false);
|
|
||||||
notificationDialog.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
||||||
|
|
||||||
Point newLoc = new Point((int)screenSize.getWidth() - 200, (int)screenSize.getHeight() - 150);
|
|
||||||
|
|
||||||
JPanel mainPanel = new JPanel();
|
|
||||||
mainPanel.setBackground(Color.white);
|
|
||||||
mainPanel.setLayout(new GridBagLayout());
|
|
||||||
mainPanel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
|
|
||||||
|
|
||||||
// Add Header Label
|
|
||||||
mainPanel.add(headerLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
|
|
||||||
|
|
||||||
// Add Message Label
|
|
||||||
final JScrollPane messageScroller = new JScrollPane(messageLabel);
|
|
||||||
mainPanel.add(messageScroller, new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
|
|
||||||
messageScroller.setBackground(Color.white);
|
|
||||||
messageScroller.setForeground(Color.white);
|
|
||||||
messageLabel.setBackground(Color.white);
|
|
||||||
messageScroller.getViewport().setBackground(Color.white);
|
|
||||||
|
|
||||||
// JButton okButton = new JButton("Ok");
|
|
||||||
mainPanel.setPreferredSize(new Dimension(200, 150));
|
|
||||||
|
|
||||||
headerLabel.setTitle("Spark"); // NORES
|
|
||||||
headerLabel.setTitleFont(new Font("Dialog", Font.BOLD, 10));
|
|
||||||
|
|
||||||
messageLabel.setFont(new Font("Dialog", Font.PLAIN, 11));
|
|
||||||
|
|
||||||
notificationDialog.add(mainPanel, BorderLayout.CENTER);
|
|
||||||
notificationDialog.pack();
|
|
||||||
notificationDialog.setPreferredSize(new Dimension(200, 150));
|
|
||||||
notificationDialog.setLocation(newLoc);
|
|
||||||
messageLabel.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
notificationDialog.setVisible(false);
|
|
||||||
showMainWindow();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mainPanel.addMouseListener(new MouseAdapter() {
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
notificationDialog.setVisible(false);
|
|
||||||
showMainWindow();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows notification dialog for incoming messages.
|
|
||||||
*
|
|
||||||
* @param title who the body is from.
|
|
||||||
* @param body the body of the body.
|
|
||||||
*/
|
|
||||||
public void displayBubble(String title, String body) {
|
|
||||||
// Tray only works in windows and mac.
|
|
||||||
if (!Spark.isWindows()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// trayIcon.displayMessage(title, body, TrayIcon.INFO_MESSAGE_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user