Compare commits

...

4 Commits

Author SHA1 Message Date
Guus der Kinderen
7705a3e72c SPARK-2372: Async chat leave
The ‘leave chat’ event can be executed asynchronously, so that the UI isn’t needlessly waiting for things.
2025-10-10 14:19:00 +02:00
Guus der Kinderen
8313e43eb4 SPARK-2360: Isolate bugs, log improvements
There is a slew of minor issues, such as operating on non-existing images, that throw unchecked exceptions and break the application badly.

To isolate these occurrences, exception handling can be put in place, with some logging being generated. That won’t solve the underlying issue, but it should limit the impact of these issues.
2025-10-10 12:34:32 +02:00
Guus der Kinderen
05b8e82499 Addressing review feedback 2025-10-10 12:34:04 +02:00
Guus der Kinderen
0734d54743 SPARK-2356: Guard against missing resources
When a resource is missing, Spark should log and return null, rather than throw an unchecked exception.
2025-10-10 12:34:04 +02:00
25 changed files with 379 additions and 283 deletions

View File

@ -15,6 +15,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 java.io.IOException; import java.io.IOException;
@ -55,9 +57,19 @@ public class ConfigurationRes {
} }
public static ImageIcon getImageIcon(String imageName) { public static ImageIcon getImageIcon(String imageName) {
final String iconURI = getString(imageName); try {
final URL imageURL = cl.getResource(iconURI); final String iconURI = getString(imageName);
return new ImageIcon(imageURL); final URL imageURL = cl.getResource(iconURI);
if (imageURL != null) {
return new ImageIcon(imageURL);
} else {
Log.warning(imageName + " not found.");
}
}
catch (Exception e) {
Log.warning("Unable to load image " + imageName, e);
}
return null;
} }
public static URL getURL(String propertyName) { public static URL getURL(String propertyName) {

View File

@ -208,8 +208,8 @@ public class Default {
cache.put(imageName, icon); cache.put(imageName, icon);
return icon; return icon;
} }
catch (Exception ex) { catch (Exception e) {
Log.debug(imageName + " not found."); Log.warning(imageName + " not found.", e);
} }
return null; return null;
} }

View File

@ -15,6 +15,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 java.io.IOException; import java.io.IOException;
@ -52,9 +54,19 @@ public class SoundsRes {
} }
public static ImageIcon getImageIcon(String imageName) { public static ImageIcon getImageIcon(String imageName) {
final String iconURI = getString(imageName); try {
final URL imageURL = cl.getResource(iconURI); final String iconURI = getString(imageName);
return new ImageIcon(imageURL); final URL imageURL = cl.getResource(iconURI);
if (imageURL != null) {
return new ImageIcon(imageURL);
} else {
Log.warning(imageName + " not found.");
}
}
catch (Exception e) {
Log.warning("Unable to load image " + imageName, e);
}
return null;
} }
public static URL getURL(String propertyName) { public static URL getURL(String propertyName) {

View File

@ -353,10 +353,16 @@ public class SparkRes {
public static ImageIcon getImageIcon(String imageName) { public static ImageIcon getImageIcon(String imageName) {
try { try {
final URL imageURL = getURL(imageName); final String iconURI = getString(imageName);
return new ImageIcon(imageURL); final URL imageURL = cl.getResource(iconURI);
} catch (Exception ex) { if (imageURL != null) {
Log.error(imageName + " not found."); return new ImageIcon(imageURL);
} else {
Log.warning(imageName + " not found.");
}
}
catch (Exception e) {
Log.warning("Unable to load image " + imageName, e);
} }
return null; return null;
} }

View File

@ -303,8 +303,8 @@ public class ContactInfoWindow extends JPanel {
} }
avatarLabel.setBorder(BorderFactory.createLineBorder(Color.lightGray, 1, true)); avatarLabel.setBorder(BorderFactory.createLineBorder(Color.lightGray, 1, true));
} }
catch (MalformedURLException e) { catch (Exception e) {
Log.error(e); Log.warning("Unable to update avatar in contact info window", e);
} }
// Get VCard from memory (if available) // Get VCard from memory (if available)

View File

@ -601,8 +601,8 @@ public class ContactItem extends JPanel {
setSideIcon(icon); setSideIcon(icon);
} }
} }
} catch (MalformedURLException e) { } catch (Exception e) {
Log.error(e); Log.warning("Unable to update avatar in side icon", e);
} }
} }

View File

@ -77,12 +77,15 @@ public class VCardPanel extends JPanel {
add(avatarImage, new GridBagConstraints(0, 0, 1, 3, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 0), 0, 0)); add(avatarImage, new GridBagConstraints(0, 0, 1, 3, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 0), 0, 0));
buildAvatarHover(); buildAvatarHover();
Image aImage = SparkRes.getImageIcon(SparkRes.BLANK_24x24).getImage(); try {
aImage = aImage.getScaledInstance(-1, 64, Image.SCALE_SMOOTH); Image aImage = SparkRes.getImageIcon(SparkRes.BLANK_24x24).getImage();
ImageIcon ico = new ImageIcon(aImage); aImage = aImage.getScaledInstance(-1, 64, Image.SCALE_SMOOTH);
ImageIcon ico = new ImageIcon(aImage);
avatarImage.setIcon(ico);
avatarImage.setIcon(ico);
} catch (Exception e) {
Log.error("Unable to process image in vcard!", e);
}
VCard vcard = SparkManager.getVCardManager().getVCard(jid); VCard vcard = SparkManager.getVCardManager().getVCard(jid);
@ -105,7 +108,7 @@ public class VCardPanel extends JPanel {
icon = new ImageIcon(newImage); icon = new ImageIcon(newImage);
} }
catch (Exception e) { catch (Exception e) {
Log.error(e); Log.error("Unable to fetch image in vcard!", e);
} }
} }
else { else {
@ -153,7 +156,7 @@ public class VCardPanel extends JPanel {
icon = new ImageIcon(newImage); icon = new ImageIcon(newImage);
} catch (Exception e1) { } catch (Exception e1) {
Log.error(e1); Log.error("Unable to process vcard avatar", e1);
} }
} else { } else {

View File

@ -75,58 +75,61 @@ public class VCardViewer extends JPanel {
avatarImage = new JLabel(); avatarImage = new JLabel();
add(avatarImage, new GridBagConstraints(0, 0, 1, 3, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 0), 0, 0)); add(avatarImage, new GridBagConstraints(0, 0, 1, 3, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 0), 0, 0));
try {
Image aImage = SparkRes.getImageIcon(SparkRes.BLANK_24x24).getImage();
aImage = aImage.getScaledInstance(-1, 64, Image.SCALE_SMOOTH);
ImageIcon ico = new ImageIcon(aImage);
Image aImage = SparkRes.getImageIcon(SparkRes.BLANK_24x24).getImage(); avatarImage.setIcon(ico);
aImage = aImage.getScaledInstance(-1, 64, Image.SCALE_SMOOTH);
ImageIcon ico = new ImageIcon(aImage);
avatarImage.setIcon(ico); final SwingWorker vcardLoader = new SwingWorker()
{
VCard vcard = null;
final SwingWorker vcardLoader = new SwingWorker() { @Override
VCard vcard = null; public Object construct()
{
@Override vcard = SparkManager.getVCardManager().getVCard(jid);
public Object construct() { return vcard;
vcard = SparkManager.getVCardManager().getVCard(jid);
return vcard;
}
@Override
public void finished() {
if (vcard == null) {
// Do nothing.
return;
} }
ImageIcon icon = null; @Override
public void finished()
byte[] bytes = vcard.getAvatar(); {
if (bytes != null && bytes.length > 0) { if (vcard == null) {
try { // Do nothing.
icon = new ImageIcon(bytes); return;
Image aImage = icon.getImage();
aImage = aImage.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
icon = new ImageIcon(aImage);
} }
catch (Exception e) {
Log.error(e); ImageIcon icon = null;
byte[] bytes = vcard.getAvatar();
if (bytes != null && bytes.length > 0) {
try {
icon = new ImageIcon(bytes);
Image aImage = icon.getImage();
aImage = aImage.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
icon = new ImageIcon(aImage);
} catch (Exception e) {
Log.warning("Unable to get scaled avatar from vcard.", e);
}
} else {
icon = SparkRes.getImageIcon(SparkRes.DEFAULT_AVATAR_32x32_IMAGE);
} }
}
else {
icon = SparkRes.getImageIcon(SparkRes.DEFAULT_AVATAR_32x32_IMAGE);
}
if (icon != null && icon.getIconWidth() > 0) { if (icon != null && icon.getIconWidth() > 0) {
avatarImage.setIcon(icon); avatarImage.setIcon(icon);
avatarImage.setBorder(BorderFactory.createLineBorder(Color.lightGray, 1, true)); avatarImage.setBorder(BorderFactory.createLineBorder(Color.lightGray, 1, true));
}
vcard.setJabberId(jid);
buildUI(vcard);
} }
};
vcard.setJabberId(jid); vcardLoader.start();
buildUI(vcard); } catch (Exception e) {
} Log.warning("Unable to get avatar from vcard.", e);
}; }
vcardLoader.start();
} }
private void buildUI(final VCard vcard) { private void buildUI(final VCard vcard) {

View File

@ -920,18 +920,29 @@ public class ConferenceRoomBrowser extends JPanel implements ActionListener,
} }
if (isbookmark && ispassword) { if (isbookmark && ispassword) {
Image img = ImageCombiner.combine(bookmarkicon, passwordicon); try {
iconLabel.setIcon(new ImageIcon(img)); Image img = ImageCombiner.combine(bookmarkicon, passwordicon);
if (img != null) {
iconLabel.setIcon(new ImageIcon(img));
}
} catch (Exception e) {
Log.warning("Unable to set icon for bookmarked & password-protected room " + jid, e);
}
} else if (isbookmark) { } else if (isbookmark) {
iconLabel.setIcon(bookmarkicon); iconLabel.setIcon(bookmarkicon);
} else if (ispassword) { } else if (ispassword) {
Image img = ImageCombiner.returnTransparentImage( try {
passwordicon.getIconWidth(), passwordicon.getIconHeight()); if (passwordicon != null) {
Image img = ImageCombiner.returnTransparentImage(
Image combined = ImageCombiner.combine(new ImageIcon(img), passwordicon.getIconWidth(), passwordicon.getIconHeight());
passwordicon); Image combined = ImageCombiner.combine(new ImageIcon(img), passwordicon);
if (combined != null) {
iconLabel.setIcon(new ImageIcon(combined)); iconLabel.setIcon(new ImageIcon(combined));
}
}
} catch (Exception e) {
Log.warning("Unable to set icon for password-protected room " + jid, e);
}
} }
String occupants = Integer.toString(numberOfOccupants); String occupants = Integer.toString(numberOfOccupants);
@ -939,7 +950,7 @@ public class ConferenceRoomBrowser extends JPanel implements ActionListener,
occupants = "n/a"; occupants = "n/a";
} }
return new Object[] { iconLabel, roomName.toString(), jid.getLocalpart().toString(), occupants }; return new Object[] { iconLabel, roomName == null ? jid.getLocalpart().toString() : roomName.toString(), jid.getLocalpart().toString(), occupants };
} }
@Override @Override

View File

@ -46,6 +46,7 @@ import org.jivesoftware.spark.ui.conferences.ConferenceUtils;
import org.jivesoftware.spark.ui.conferences.DataFormDialog; import org.jivesoftware.spark.ui.conferences.DataFormDialog;
import org.jivesoftware.spark.ui.conferences.GroupChatParticipantList; import org.jivesoftware.spark.ui.conferences.GroupChatParticipantList;
import org.jivesoftware.spark.util.ModelUtil; import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.UIComponentRegistry; import org.jivesoftware.spark.util.UIComponentRegistry;
import org.jivesoftware.spark.util.log.Log; import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences; import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
@ -543,14 +544,13 @@ public class GroupChatRoom extends ChatRoom
// Update Room Notice To Inform Agent that he has left the chat. // Update Room Notice To Inform Agent that he has left the chat.
getTranscriptWindow().insertNotificationMessage( Res.getString( "message.user.left.room", getNickname() ), ChatManager.NOTIFICATION_COLOR ); getTranscriptWindow().insertNotificationMessage( Res.getString( "message.user.left.room", getNickname() ), ChatManager.NOTIFICATION_COLOR );
try SwingUtilities.invokeLater(() -> {
{ try {
chat.leave(); chat.leave();
} } catch ( Exception e ) {
catch ( Exception e ) Log.error( "Closing Group Chat Room error.", e );
{ }
Log.error( "Closing Group Chat Room error.", e ); });
}
// Set window as greyed out. // Set window as greyed out.
getTranscriptWindow().showWindowDisabled(); getTranscriptWindow().showWindowDisabled();

View File

@ -345,12 +345,16 @@ public class CustomMessages {
// Add Types // Add Types
for (StatusItem statusItem : statusBar.getStatusList()) { for (StatusItem statusItem : statusBar.getStatusList()) {
if (!PresenceManager.isOnPhone(statusItem.getPresence())) { if (!PresenceManager.isOnPhone(statusItem.getPresence())) {
ImageIcon icon = (ImageIcon) statusItem.getIcon(); try {
ImageIcon icon = (ImageIcon) statusItem.getIcon();
ImageIcon newIcon = new ImageIcon(icon.getImage()); ImageIcon newIcon = new ImageIcon(icon.getImage());
newIcon.setDescription(statusItem.getText()); newIcon.setDescription(statusItem.getText());
typeBox.addItem(newIcon); typeBox.addItem(newIcon);
} catch (Exception e) {
Log.warning("Unable to update icon on custom status bar", e);
}
} }
} }

View File

@ -165,19 +165,23 @@ public class StatusBar extends JPanel implements VCardListener {
} }
public void setAvatar(Icon icon) { public void setAvatar(Icon icon) {
if (icon == null) { try {
imageLabel.setIcon(null); if (icon == null) {
} else { imageLabel.setIcon(null);
Image image = ImageCombiner.iconToImage(icon);
if (icon.getIconHeight() > 64 || icon.getIconWidth() > 64) {
imageLabel.setIcon(new ImageIcon(image.getScaledInstance(-1, 64, Image.SCALE_SMOOTH)));
} else { } else {
imageLabel.setIcon(icon); Image image = ImageCombiner.iconToImage(icon);
if (icon.getIconHeight() > 64 || icon.getIconWidth() > 64) {
imageLabel.setIcon(new ImageIcon(image.getScaledInstance(-1, 64, Image.SCALE_SMOOTH)));
} else {
imageLabel.setIcon(icon);
}
} }
imageLabel.setBorder(null);
revalidate();
allowProfileEditing();
} catch (Exception e) {
Log.warning("Unable to set avatar", e);
} }
imageLabel.setBorder(null);
revalidate();
allowProfileEditing();
} }
public CommandPanel getCommandPanel() { public CommandPanel getCommandPanel() {
@ -506,7 +510,7 @@ public class StatusBar extends JPanel implements VCardListener {
imageLabel.validate(); imageLabel.validate();
imageLabel.repaint(); imageLabel.repaint();
} catch (Exception e) { } catch (Exception e) {
// no issue Log.warning("Unable to update vcard viewer with avatar data", e);
} }
} else { } else {
imageLabel.setIcon(null); imageLabel.setIcon(null);

View File

@ -692,50 +692,48 @@ public final class GraphicUtils {
* @return byte[] * @return byte[]
*/ */
public static byte[] getBytesFromImage(File file) { public static byte[] getBytesFromImage(File file) {
FileInputStream fileInputStream = null; try (FileInputStream fileInputStream = new FileInputStream(file)) {
try {
fileInputStream = new FileInputStream(file);
byte[] data = new byte[(int) file.length()]; byte[] data = new byte[(int) file.length()];
fileInputStream.read(data); fileInputStream.read(data);
fileInputStream.close();
return data; return data;
} catch (IOException e) { } catch (Exception e) {
if (fileInputStream != null) { Log.warning("Unable to read image", e);
try {
fileInputStream.close();
} catch (IOException e1) {
Log.error(e1);
}
}
return null; return null;
} }
} }
/** /**
* Returns a scaled down image if the height or width is smaller than the image size. * Returns a scaled down image if the height or width is smaller than the
* image size.
* *
* @param icon the image icon. * @param icon
* @param newHeight the preferred height. * the image icon.
* @param newWidth the preferred width. * @param newHeight
* the preferred height.
* @param newWidth
* the preferred width.
* @return the icon. * @return the icon.
*/ */
public static ImageIcon scaleImageIcon(ImageIcon icon, int newHeight, int newWidth) { public static ImageIcon scaleImageIcon(ImageIcon icon, int newHeight, int newWidth)
int height = icon.getIconHeight(); {
int width = icon.getIconWidth(); try {
boolean resize = false; Image img = icon.getImage();
if (height > newHeight) { int height = icon.getIconHeight();
height = newHeight; int width = icon.getIconWidth();
resize = true;
if (height > newHeight) {
height = newHeight;
}
if (width > newWidth) {
width = newWidth;
}
img = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
return new ImageIcon(img);
} catch (Exception e) {
Log.warning("Unable to scale image", e);
return null;
} }
if (width > newWidth) {
width = newWidth;
resize = true;
}
if (!resize) {
return icon;
}
Image img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
return new ImageIcon(img);
} }
/** /**
@ -750,38 +748,44 @@ public final class GraphicUtils {
* the preferred width. * the preferred width.
* @return the icon. * @return the icon.
*/ */
public static ImageIcon scale(ImageIcon icon, int newHeight, int newWidth) { public static ImageIcon scale(ImageIcon icon, int newHeight, int newWidth)
Image img = icon.getImage(); {
int height = icon.getIconHeight(); try {
int width = icon.getIconWidth(); Image img = icon.getImage();
boolean scaleHeight = height * newWidth > width * newHeight; int height = icon.getIconHeight();
if (height > newHeight) { int width = icon.getIconWidth();
// Too tall boolean scaleHeight = height * newWidth > width * newHeight;
if (width <= newWidth || scaleHeight) { if (height > newHeight) {
// Width is okay or height is limiting factor due to aspect // Too tall
// ratio if (width <= newWidth || scaleHeight) {
height = newHeight; // Width is okay or height is limiting factor due to aspect
width = -1; // ratio
} else { height = newHeight;
// Width is limiting factor due to aspect ratio width = -1;
height = -1; } else {
width = newWidth; // Width is limiting factor due to aspect ratio
} height = -1;
} else if (width > newWidth) { width = newWidth;
// Too wide and height is okay }
height = -1; } else if (width > newWidth) {
width = newWidth; // Too wide and height is okay
} else if (scaleHeight) { height = -1;
// Height is limiting factor due to aspect ratio width = newWidth;
height = newHeight; } else if (scaleHeight) {
width = -1; // Height is limiting factor due to aspect ratio
} else { height = newHeight;
// Width is limiting factor due to aspect ratio width = -1;
height = -1; } else {
width = newWidth; // Width is limiting factor due to aspect ratio
} height = -1;
img = img.getScaledInstance(width, height, Image.SCALE_SMOOTH); width = newWidth;
return new ImageIcon(img); }
img = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
return new ImageIcon(img);
} catch (Exception e) {
Log.warning("Unable to scale image", e);
return null;
}
} }
/** /**
@ -796,7 +800,7 @@ public final class GraphicUtils {
try { try {
return new JFileChooser().getIcon(file); return new JFileChooser().getIcon(file);
} catch (Exception e) { } catch (Exception e) {
Log.debug("unable to get icon"); Log.warning("unable to get icon", e);
} }
return SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32); return SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32);
@ -833,27 +837,32 @@ public final class GraphicUtils {
* @return * @return
*/ */
public static ImageIcon fitToSquare(ImageIcon icon, int newSize) { public static ImageIcon fitToSquare(ImageIcon icon, int newSize) {
if (newSize <= 0) { try {
return icon; if (newSize <= 0) {
} return icon;
}
final int oldWidth = icon.getIconWidth(); final int oldWidth = icon.getIconWidth();
final int oldHeight = icon.getIconHeight(); final int oldHeight = icon.getIconHeight();
int newWidth; int newWidth;
int newHeight; int newHeight;
if (oldHeight >= oldWidth) { if (oldHeight >= oldWidth) {
newWidth = (int) ((float) oldWidth * newSize / oldHeight); newWidth = (int) ((float) oldWidth * newSize / oldHeight);
newHeight = newSize; newHeight = newSize;
} else { } else {
newWidth = newSize; newWidth = newSize;
newHeight = (int) ((float) oldHeight * newSize / oldWidth); newHeight = (int) ((float) oldHeight * newSize / oldWidth);
} }
final Image img = icon.getImage().getScaledInstance(newWidth, final Image img = icon.getImage().getScaledInstance(newWidth,
newHeight, Image.SCALE_SMOOTH); newHeight, Image.SCALE_SMOOTH);
return new ImageIcon(img); return new ImageIcon(img);
} catch (Exception e) {
Log.warning("Unable to fit image to square", e);
return null;
}
} }
// public static void centerWindowOnScreen(Runnable runnable) { // public static void centerWindowOnScreen(Runnable runnable) {

View File

@ -15,6 +15,8 @@
*/ */
package org.jivesoftware.spark.util; package org.jivesoftware.spark.util;
import org.jivesoftware.spark.util.log.Log;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration; import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice; import java.awt.GraphicsDevice;
@ -34,7 +36,6 @@ import javax.swing.JComponent;
*/ */
public class ImageCombiner { public class ImageCombiner {
/** /**
* Combines two images into one * Combines two images into one
* *
@ -59,30 +60,34 @@ public class ImageCombiner {
* @return combined Image * @return combined Image
*/ */
public static Image combine(ImageIcon image1, ImageIcon image2) { public static Image combine(ImageIcon image1, ImageIcon image2) {
try {
ImageObserver comp = new JComponent()
{
private static final long serialVersionUID = 1L;
};
ImageObserver comp = new JComponent() { int w = image1.getIconWidth() + image2.getIconWidth();
private static final long serialVersionUID = 1L; int h = Math.max(image1.getIconHeight(), image2.getIconHeight());
};
int w = image1.getIconWidth() + image2.getIconWidth(); BufferedImage image = new BufferedImage(w, h,
int h = Math.max(image1.getIconHeight(), image2.getIconHeight()); BufferedImage.TYPE_INT_ARGB);
BufferedImage image = new BufferedImage(w, h, Graphics2D g2 = image.createGraphics();
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics(); g2.drawImage(image1.getImage(), 0, 0, comp);
g2.drawImage(image2.getImage(), image1.getIconWidth(), 0, comp);
g2.dispose();
g2.drawImage(image1.getImage(), 0, 0, comp); return image;
g2.drawImage(image2.getImage(), image1.getIconWidth(), 0, comp); } catch (Exception e) {
g2.dispose(); Log.warning("Unable to combine two images", e);
return null;
return image; }
} }
public static Image returnTransparentImage(int w, int h) { public static Image returnTransparentImage(int w, int h) {
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
} }
/** /**
* Creates an Image from the specified Icon * Creates an Image from the specified Icon
@ -107,5 +112,4 @@ public class ImageCombiner {
return image; return image;
} }
} }
} }

View File

@ -136,16 +136,15 @@ public abstract class SwingWorker {
Runnable doConstruct = () -> { Runnable doConstruct = () -> {
try { try {
setValue(construct()); setValue(construct());
} }
catch ( Exception e ) { catch (Exception e) {
Log.error( e ); Log.error("SwingWorker exception while async constructing value", e);
} }
finally { finally {
threadVar.clear(); threadVar.clear();
} }
SwingUtilities.invokeLater(this::finished); SwingUtilities.invokeLater(this::finished);
}; };
Thread t = new Thread(doConstruct); Thread t = new Thread(doConstruct);

View File

@ -16,6 +16,7 @@
package org.jivesoftware.fastpath.resources; package org.jivesoftware.fastpath.resources;
import org.jivesoftware.fastpath.FastpathPlugin; import org.jivesoftware.fastpath.FastpathPlugin;
import org.jivesoftware.spark.util.log.Log;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JEditorPane; import javax.swing.JEditorPane;
@ -265,10 +266,14 @@ public class FastpathRes {
try { try {
final String iconURI = getString(imageName); final String iconURI = getString(imageName);
final URL imageURL = cl.getResource(iconURI); final URL imageURL = cl.getResource(iconURI);
return new ImageIcon(imageURL); if (imageURL != null) {
return new ImageIcon(imageURL);
} else {
Log.warning(imageName + " not found.");
}
} }
catch (Exception ex) { catch (Exception e) {
System.out.println(imageName + " not found."); Log.warning("Unable to load image " + imageName, e);
} }
return null; return null;
} }

View File

@ -207,7 +207,7 @@ public class IncomingCallUI extends JPanel {
avatarLabel.repaint(); avatarLabel.repaint();
} }
catch (Exception e) { catch (Exception e) {
// no issue Log.warning("Unable to generate image from avatar", e);
} }
} }

View File

@ -20,6 +20,8 @@ import java.util.PropertyResourceBundle;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.net.URL; import java.net.URL;
import org.jivesoftware.spark.util.log.Log;
/** /**
* Use for Phone Res Internationalization. * Use for Phone Res Internationalization.
* *
@ -46,10 +48,14 @@ public class JinglePhoneRes {
try { try {
final String iconURI = JinglePhoneRes.getString(imageName); final String iconURI = JinglePhoneRes.getString(imageName);
final URL imageURL = JinglePhoneRes.cl.getResource(iconURI); final URL imageURL = JinglePhoneRes.cl.getResource(iconURI);
return new ImageIcon(imageURL); if (imageURL != null) {
return new ImageIcon(imageURL);
} else {
Log.warning(imageName + " not found.");
}
} }
catch (Exception ex) { catch (Exception e) {
System.out.println(imageName + " not found."); Log.warning("Unable to load image " + imageName, e);
} }
return null; return null;
} }
@ -57,6 +63,4 @@ public class JinglePhoneRes {
public static final URL getURL(String propertyName) { public static final URL getURL(String propertyName) {
return JinglePhoneRes.cl.getResource(JinglePhoneRes.getString(propertyName)); return JinglePhoneRes.cl.getResource(JinglePhoneRes.getString(propertyName));
} }
} }

View File

@ -52,8 +52,8 @@ public class SparkMeetPlugin implements Plugin, ChatRoomListener, GlobalMessageL
private org.jivesoftware.spark.ChatManager chatManager; private org.jivesoftware.spark.ChatManager chatManager;
private final File pluginsettings = new File( Spark.getLogDirectory().getParentFile() + System.getProperty("file.separator") + "ofmeet.properties"); private final File pluginsettings = new File( Spark.getLogDirectory().getParentFile() + System.getProperty("file.separator") + "ofmeet.properties");
private final Map<String, ChatRoomDecorator> decorators = new HashMap<>(); private final Map<String, ChatRoomDecorator> decorators = new HashMap<>();
private String electronExePath = null; private String electronExePath = null;
private String electronHomePath = null; private String electronHomePath = null;
private XProcess electronThread = null; private XProcess electronThread = null;
@ -61,7 +61,7 @@ public class SparkMeetPlugin implements Plugin, ChatRoomListener, GlobalMessageL
public void initialize() public void initialize()
{ {
ProviderManager.addIQProvider("query", QueryRequest.NAMESPACE, new QueryRequest.Provider()); ProviderManager.addIQProvider("query", QueryRequest.NAMESPACE, new QueryRequest.Provider());
checkNatives(); checkNatives();
chatManager = SparkManager.getChatManager(); chatManager = SparkManager.getChatManager();
@ -72,7 +72,7 @@ public class SparkMeetPlugin implements Plugin, ChatRoomListener, GlobalMessageL
if (pluginsettings.exists()) if (pluginsettings.exists())
{ {
Log.warning("ofmeet-info: Properties-file does exist= " + pluginsettings.getPath()); Log.debug("ofmeet-info: Properties-file does exist= " + pluginsettings.getPath());
try { try {
props.load(new FileInputStream(pluginsettings)); props.load(new FileInputStream(pluginsettings));
@ -144,12 +144,12 @@ public class SparkMeetPlugin implements Plugin, ChatRoomListener, GlobalMessageL
QueryRequest response = (QueryRequest) result; QueryRequest response = (QueryRequest) result;
Log.debug("SparkMeet response: url=" + response.url); Log.debug("SparkMeet response: url=" + response.url);
if (response.url != null) serverUrl = response.url + "/"; if (response.url != null) serverUrl = response.url + "/";
} catch (Exception e) { } catch (Exception e) {
Log.error("Unable to get meet url from server for app type " + app); Log.error("Unable to get meet url from server for app type " + app);
} }
return serverUrl; return serverUrl;
} }
public void commit(String url) { public void commit(String url) {
@ -170,7 +170,7 @@ public class SparkMeetPlugin implements Plugin, ChatRoomListener, GlobalMessageL
{ {
Log.debug("shutdown"); Log.debug("shutdown");
chatManager.removeChatRoomListener(this); chatManager.removeChatRoomListener(this);
ProviderManager.removeIQProvider("query", QueryRequest.NAMESPACE); ProviderManager.removeIQProvider("query", QueryRequest.NAMESPACE);
if (electronThread != null) electronThread.destory(); if (electronThread != null) electronThread.destory();
electronThread = null; electronThread = null;
@ -439,7 +439,7 @@ public class SparkMeetPlugin implements Plugin, ChatRoomListener, GlobalMessageL
Log.debug("Native lib folder created and natives extracted"); Log.debug("Native lib folder created and natives extracted");
} }
else { else {
Log.warning("Native lib folder already exist."); Log.debug("Native lib folder already exist.");
} }

View File

@ -45,9 +45,19 @@ public class OTRResources {
* @return * @return
*/ */
public static ImageIcon getIcon(String fileName) { public static ImageIcon getIcon(String fileName) {
final ClassLoader cl = OTRResources.class.getClassLoader(); try {
ImageIcon icon = new ImageIcon(cl.getResource(fileName)); final ClassLoader cl = OTRResources.class.getClassLoader();
return icon; final URL imageURL = cl.getResource(fileName);
if (imageURL != null) {
return new ImageIcon(imageURL);
} else {
Log.warning(imageName + " not found.");
}
}
catch (Exception e) {
Log.warning("Unable to load image " + imageName, e);
}
return null;
} }
/** /**

View File

@ -1,6 +1,7 @@
package org.jivesoftware.game.reversi; package org.jivesoftware.game.reversi;
import org.jivesoftware.resource.UTF8Control; import org.jivesoftware.resource.UTF8Control;
import org.jivesoftware.spark.util.log.Log;
import java.net.URL; import java.net.URL;
import java.util.PropertyResourceBundle; import java.util.PropertyResourceBundle;
@ -9,47 +10,48 @@ import java.util.ResourceBundle;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
public class ReversiRes { public class ReversiRes {
private static PropertyResourceBundle prb; private static PropertyResourceBundle prb;
public static final String REVERSI_ICON = "REVERSI_ICON"; public static final String REVERSI_ICON = "REVERSI_ICON";
public static final String REVERSI_BOARD="REVERSI_BOARD"; public static final String REVERSI_BOARD="REVERSI_BOARD";
public static final String REVERSI_SCORE_WHITE="REVERSI_SCORE_WHITE"; public static final String REVERSI_SCORE_WHITE="REVERSI_SCORE_WHITE";
public static final String REVERSI_SCORE_BLACK="REVERSI_SCORE_BLACK"; public static final String REVERSI_SCORE_BLACK="REVERSI_SCORE_BLACK";
public static final String REVERSI_LABEL_BLACK="REVERSI_LABEL_BLACK"; public static final String REVERSI_LABEL_BLACK="REVERSI_LABEL_BLACK";
public static final String REVERSI_LABEL_WHITE="REVERSI_LABEL_WHITE"; public static final String REVERSI_LABEL_WHITE="REVERSI_LABEL_WHITE";
public static final String REVERSI_RESIGN="REVERSI_RESIGN"; public static final String REVERSI_RESIGN="REVERSI_RESIGN";
public static final String REVERSI_YOU="REVERSI_YOU"; public static final String REVERSI_YOU="REVERSI_YOU";
public static final String REVERSI_THEM="REVERSI_THEM"; public static final String REVERSI_THEM="REVERSI_THEM";
private ReversiRes() {
} private ReversiRes() {
private static final ClassLoader cl = ReversiRes.class.getClassLoader(); }
static { private static final ClassLoader cl = ReversiRes.class.getClassLoader();
ReversiRes.prb = (PropertyResourceBundle) ResourceBundle.getBundle("reversi", new UTF8Control());
}
public static String getString(String propertyName) {
return ReversiRes.prb.getString(propertyName);
}
public static ImageIcon getImageIcon(String imageName) { static {
try { ReversiRes.prb = (PropertyResourceBundle) ResourceBundle.getBundle("reversi", new UTF8Control());
final String iconURI = ReversiRes.getString(imageName); }
final URL imageURL = ReversiRes.cl.getResource(iconURI);
return new ImageIcon(imageURL);
}
catch (Exception ex) {
System.out.println(imageName + " not found.");
}
return null;
}
public static URL getURL(String propertyName) { public static String getString(String propertyName) {
return ReversiRes.cl.getResource(ReversiRes.getString(propertyName)); return ReversiRes.prb.getString(propertyName);
} }
public static ImageIcon getImageIcon(String imageName) {
try {
final String iconURI = ReversiRes.getString(imageName);
final URL imageURL = ReversiRes.cl.getResource(iconURI);
if (imageURL != null) {
return new ImageIcon(imageURL);
} else {
Log.warning(imageName + " not found.");
}
}
catch (Exception e) {
Log.warning("Unable to load image " + imageName, e);
}
return null;
}
public static URL getURL(String propertyName) {
return ReversiRes.cl.getResource(ReversiRes.getString(propertyName));
}
} }

View File

@ -643,13 +643,17 @@ public class SparkToaster {
} }
public void setIcon(Icon icon) { public void setIcon(Icon icon) {
if (icon.getIconHeight() > 64 || icon.getIconWidth() > 64) { try {
Image image = ImageCombiner.iconToImage(icon); if (icon.getIconHeight() > 64 || icon.getIconWidth() > 64) {
label.setIcon(new ImageIcon(image.getScaledInstance(-1, 64, Image image = ImageCombiner.iconToImage(icon);
Image.SCALE_SMOOTH))); label.setIcon(new ImageIcon(image.getScaledInstance(-1, 64,
} else { Image.SCALE_SMOOTH)));
label.setIcon(icon); } else{
} label.setIcon(icon);
}
} catch (Exception e) {
Log.warning("Unable to set icon in toaster", e);
}
} }
public RolloverButton getCloseButton() { public RolloverButton getCloseButton() {

View File

@ -58,8 +58,8 @@ public class PhoneRes {
final URL imageURL = cl.getResource(iconURI); final URL imageURL = cl.getResource(iconURI);
return new ImageIcon(imageURL); return new ImageIcon(imageURL);
} }
catch (Exception ex) { catch (Throwable t) {
System.out.println(imageName + " not found."); Log.warn(imageName + " not found.", t);
} }
return null; return null;
} }
@ -69,14 +69,18 @@ public class PhoneRes {
} }
public static final Image getImage(String imageName) { public static final Image getImage(String imageName) {
try { try {
final String iconURI = getString(imageName); final String iconURI = getString(imageName);
final URL imageURL = cl.getResource(iconURI); final URL imageURL = cl.getResource(iconURI);
return new ImageIcon(imageURL).getImage(); if (imageURL != null) {
} return new ImageIcon(imageURL);
catch (Exception ex) { } else {
Log.error(imageName + " not found."); Log.warning(imageName + " not found.");
} }
return null; }
} catch (Exception e) {
} Log.warning("Unable to load image " + imageName, e);
}
return null;
}
}

View File

@ -221,7 +221,7 @@ public class IncomingCallUI extends JPanel {
avatarLabel.repaint(); avatarLabel.repaint();
} }
catch (Exception e) { catch (Exception e) {
// no issue Log.warning("Unable to generate image from avatar", e);
} }
} }

View File

@ -204,7 +204,7 @@ public class OutgoingCallUI extends JPanel {
avatarLabel.repaint(); avatarLabel.repaint();
} }
catch (Exception e) { catch (Exception e) {
// no issue Log.warning("Unable to generate image from avatar", e);
} }
} }