Fixes an issue with missing or corrupt images which could cause the whole user interface of the application or parts of it to not appear at all.

cusax-fix 4989
Lyubomir Marinov 12 years ago
parent a2ac6e081c
commit 5ddf339060

@ -471,19 +471,26 @@ private void loadTooltip(final ExtendedTooltip tip)
protocolContact = i.next();
// Set the first found status message.
if (statusMessage == null
&& protocolContact.getStatusMessage() != null
&& protocolContact.getStatusMessage().length() > 0)
if (statusMessage == null)
{
statusMessage = protocolContact.getStatusMessage();
if ((statusMessage != null) && (statusMessage.length() == 0))
statusMessage = null;
}
if(ConfigurationUtils.isHideAccountStatusSelectorsEnabled())
break;
ImageIcon protocolStatusIcon
= ImageLoader.getIndexedProtocolIcon(
ImageUtils.getBytesInImage(
protocolContact.getPresenceStatus().getStatusIcon()),
protocolContact.getProtocolProvider());
= getContactPresenceStatusIcon(protocolContact);
if (protocolStatusIcon != null)
{
protocolStatusIcon
= ImageLoader.getIndexedProtocolIcon(
protocolStatusIcon.getImage(),
protocolContact.getProtocolProvider());
}
String contactAddress = protocolContact.getAddress();
//String statusMessage = protocolContact.getStatusMessage();
@ -682,14 +689,13 @@ public MetaContactDetail(Contact contact)
{
super( contact.getAddress(),
contact.getDisplayName(),
new ImageIcon(contact.getPresenceStatus().getStatusIcon()),
getContactPresenceStatusIcon(contact),
contact);
this.contact = contact;
ProtocolProviderService parentProvider
= contact.getProtocolProvider();
Iterator<Class<? extends OperationSet>> opSetClasses
= parentProvider.getSupportedOperationSetClasses().iterator();
@ -736,4 +742,11 @@ public Collection<SIPCommButton> getContactCustomActionButtons()
{
return MetaContactListSource.getContactCustomActionButtons(this);
}
private static ImageIcon getContactPresenceStatusIcon(Contact contact)
{
byte[] bytes = contact.getPresenceStatus().getStatusIcon();
return (bytes == null) ? null : new ImageIcon(bytes);
}
}

@ -409,20 +409,30 @@ private static boolean isAutoAnswerEnabled(
* @return the image.
*/
private static Image getIconForProvider(
ProtocolProviderService providerService, Image customProviderImage,
ImageObserver imageObserver)
ProtocolProviderService providerService,
Image customProviderImage,
ImageObserver imageObserver)
{
Image left = null;
if(isAutoAnswerEnabled(providerService))
left = ImageLoader.getImage(ImageLoader.AUTO_ANSWER_CHECK);
Image left
= isAutoAnswerEnabled(providerService)
? ImageLoader.getImage(ImageLoader.AUTO_ANSWER_CHECK)
: null;
if(customProviderImage == null)
customProviderImage = ImageUtils.getBytesInImage(
providerService.getProtocolIcon().getIcon(
ProtocolIcon.ICON_SIZE_16x16));
{
byte[] bytes
= providerService.getProtocolIcon().getIcon(
ProtocolIcon.ICON_SIZE_16x16);
if (bytes != null)
customProviderImage = ImageUtils.getBytesInImage(bytes);
}
return ImageUtils.getComposedImage(
left, customProviderImage, imageObserver);
return
ImageUtils.getComposedImage(
left,
customProviderImage,
imageObserver);
}
/**
@ -526,7 +536,10 @@ private AutoAnswerMenuItem(ProtocolProviderService provider,
Image onlineImage,
SIPCommMenu parentMenu)
{
super(displayName, new ImageIcon(onlineImage));
super(
displayName,
(onlineImage == null) ? null : new ImageIcon(onlineImage));
this.providerService = provider;
this.parentMenu = parentMenu;

@ -106,10 +106,11 @@ public PresenceStatusMenu(ProtocolProviderService protocolProvider)
while (statusIterator.hasNext())
{
PresenceStatus status = statusIterator.next();
byte[] statusIcon = status.getStatusIcon();
this.addItem(
addItem(
status.getStatusName(),
new ImageIcon(status.getStatusIcon()),
(statusIcon == null) ? null : new ImageIcon(statusIcon),
this);
}
@ -133,12 +134,13 @@ public PresenceStatusMenu(ProtocolProviderService protocolProvider)
public void addItem(String text, Icon icon, ActionListener actionListener)
{
JCheckBoxMenuItem item = new JCheckBoxMenuItem(text, icon);
item.setName(text);
group.add(item);
item.addActionListener(actionListener);
this.add(item);
add(item);
}
/**

@ -46,11 +46,12 @@ public class SimpleStatusMenu
*/
public SimpleStatusMenu(ProtocolProviderService protocolProvider)
{
this(protocolProvider,
protocolProvider.getAccountID().getDisplayName(),
ImageUtils.getBytesInImage(
protocolProvider.getProtocolIcon().getIcon(
ProtocolIcon.ICON_SIZE_16x16)));
this(
protocolProvider,
protocolProvider.getAccountID().getDisplayName(),
getProtocolImage(
protocolProvider,
ProtocolIcon.ICON_SIZE_16x16));
}
/**
@ -64,27 +65,34 @@ private SimpleStatusMenu(ProtocolProviderService protocolProvider,
String displayName,
Image onlineImage)
{
super(displayName, new ImageIcon(onlineImage), protocolProvider);
super(
displayName,
(onlineImage == null) ? null : new ImageIcon(onlineImage),
protocolProvider);
this.setToolTipText("<html><b>" + displayName
+ "</b><br>Offline</html>");
setToolTipText("<html><b>" + displayName + "</b><br>Offline</html>");
JLabel titleLabel = new JLabel(displayName);
titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD));
this.add(titleLabel);
this.addSeparator();
add(titleLabel);
addSeparator();
onlineItem = createMenuItem(
"service.gui.ONLINE",
getIcon(),
GlobalStatusEnum.ONLINE_STATUS);
offlineItem = createMenuItem(
"service.gui.OFFLINE",
new ImageIcon(LightGrayFilter.createDisabledImage(onlineImage)),
GlobalStatusEnum.OFFLINE_STATUS);
offlineItem
= createMenuItem(
"service.gui.OFFLINE",
(onlineImage == null)
? null
: new ImageIcon(
LightGrayFilter.createDisabledImage(
onlineImage)),
GlobalStatusEnum.OFFLINE_STATUS);
group.add(onlineItem);
group.add(offlineItem);
@ -96,16 +104,18 @@ private SimpleStatusMenu(ProtocolProviderService protocolProvider,
}
private JCheckBoxMenuItem createMenuItem(
String textKey, Icon icon, String name)
String textKey,
Icon icon,
String name)
{
JCheckBoxMenuItem menuItem =
new JCheckBoxMenuItem(
GuiActivator.getResources().getI18NString(textKey),
icon);
JCheckBoxMenuItem menuItem
= new JCheckBoxMenuItem(
GuiActivator.getResources().getI18NString(textKey),
icon);
menuItem.setName(name);
menuItem.addActionListener(this);
this.add(menuItem);
add(menuItem);
return menuItem;
}
@ -161,18 +171,29 @@ public void updateStatus(PresenceStatus presenceStatus)
public void loadSkin()
{
super.loadSkin();
setIcon(new ImageIcon(ImageUtils.getBytesInImage(
protocolProvider.getProtocolIcon().getIcon(
ProtocolIcon.ICON_SIZE_16x16))));
if(onlineItem != null)
Image image
= getProtocolImage(protocolProvider, ProtocolIcon.ICON_SIZE_16x16);
if (image != null)
setIcon(new ImageIcon(image));
if (onlineItem != null)
onlineItem.setIcon(getIcon());
if(offlineItem != null)
if ((offlineItem != null) && (image != null))
{
offlineItem.setIcon(
new ImageIcon(LightGrayFilter.createDisabledImage(
ImageUtils.getBytesInImage(
protocolProvider.getProtocolIcon().getIcon(
ProtocolIcon.ICON_SIZE_16x16)))));
new ImageIcon(LightGrayFilter.createDisabledImage(image)));
}
}
private static Image getProtocolImage(
ProtocolProviderService pps,
String iconSize)
{
byte[] bytes = pps.getProtocolIcon().getIcon(iconSize);
return (bytes == null) ? null : ImageUtils.getBytesInImage(bytes);
}
}

@ -1535,16 +1535,13 @@ public static String getImageUri(ImageID imageID)
*/
public static ImageIcon getAccountStatusImage(ProtocolProviderService pps)
{
ImageIcon statusIcon;
OperationSetPresence presence
= pps.getOperationSet(OperationSetPresence.class);
byte[] protocolStatusIcon
= (presence == null)
? null
: presence.getPresenceStatus().getStatusIcon();
Image statusImage;
byte[] protocolStatusIcon = null;
if(presence != null)
protocolStatusIcon = presence.getPresenceStatus().getStatusIcon();
if (presence != null && protocolStatusIcon != null)
{
@ -1552,21 +1549,22 @@ public static ImageIcon getAccountStatusImage(ProtocolProviderService pps)
}
else
{
statusImage
= ImageUtils.getBytesInImage(pps.getProtocolIcon().getIcon(
ProtocolIcon.ICON_SIZE_16x16));
byte[] bytes
= pps.getProtocolIcon().getIcon(ProtocolIcon.ICON_SIZE_16x16);
if (!pps.isRegistered())
statusImage
= (bytes == null) ? null : ImageUtils.getBytesInImage(bytes);
if (!pps.isRegistered() && (statusImage != null))
{
statusImage
= LightGrayFilter.createDisabledImage(statusImage);
}
}
statusIcon = new ImageIcon(
getIndexedProtocolImage(statusImage, pps));
return statusIcon;
return
(statusImage == null)
? null
: new ImageIcon(getIndexedProtocolImage(statusImage, pps));
}
/**

@ -177,49 +177,50 @@ private void changeStatus(String statusName)
public void updateStatus(PresenceStatus presenceStatus)
{
String presenceStatusName = presenceStatus.getStatusName();
if (logger.isTraceEnabled())
logger.trace("Systray update status for provider: "
+ provider.getAccountID().getAccountAddress()
+ ". The new status will be: " + presenceStatus.getStatusName());
{
logger.trace(
"Systray update status for provider: "
+ provider.getAccountID().getAccountAddress()
+ ". The new status will be: "
+ presenceStatusName);
}
if (menu instanceof AbstractButton)
((AbstractButton) menu).setIcon(new ImageIcon(presenceStatus
.getStatusIcon()));
{
byte[] bytes = presenceStatus.getStatusIcon();
if (bytes != null)
((AbstractButton) menu).setIcon(new ImageIcon());
}
if(menu instanceof Menu)
{
Menu theMenu = (Menu) menu;
for(int i =0; i < theMenu.getItemCount(); i++)
for(int i = 0, count = theMenu.getItemCount(); i < count; i++)
{
MenuItem item = theMenu.getItem(i);
if(item instanceof CheckboxMenuItem)
{
if(item.getLabel().equals(presenceStatus.getStatusName()))
{
((CheckboxMenuItem)item).setState(true);
}
else
{
((CheckboxMenuItem)item).setState(false);
}
((CheckboxMenuItem) item).setState(
item.getLabel().equals(presenceStatusName));
}
}
}
else if(menu instanceof JMenu)
{
JMenu theMenu = (JMenu) menu;
for(int i =0; i < theMenu.getItemCount(); i++)
for(int i = 0, count = theMenu.getItemCount(); i < count; i++)
{
JMenuItem item = theMenu.getItem(i);
if(item instanceof JCheckBoxMenuItem)
{
if(item.getText().equals(presenceStatus.getStatusName()))
item.setSelected(true);
else
item.setSelected(false);
}
item.setSelected(item.getText().equals(presenceStatusName));
}
}
}

@ -146,12 +146,9 @@ public void setTitle(String titleText)
* @param icon the icon to show
* @param text the name to show
*/
public void addLine(Icon icon,
String text)
public void addLine(Icon icon, String text)
{
JLabel lineLabel = new JLabel( text,
icon,
JLabel.LEFT);
JLabel lineLabel = new JLabel(text, icon, JLabel.LEFT);
linesPanel.add(lineLabel);

@ -503,9 +503,7 @@ public static Image getBytesInImage(byte[] imageBytes)
Image image = null;
try
{
image = ImageIO.read(
new ByteArrayInputStream(imageBytes));
image = ImageIO.read(new ByteArrayInputStream(imageBytes));
}
catch (Exception e)
{
@ -523,48 +521,51 @@ public static Image getBytesInImage(byte[] imageBytes)
* @return the composed image.
*/
public static Image getComposedImage(
Image leftImage, Image rightImage,
ImageObserver imageObserver)
Image leftImage, Image rightImage,
ImageObserver imageObserver)
{
int height = 0;
if(leftImage == null && rightImage == null)
return null;
if(leftImage != null && rightImage != null)
height = Math.max(leftImage.getHeight(imageObserver),
rightImage.getHeight(imageObserver));
else if(leftImage == null)
height = rightImage.getHeight(imageObserver);
else
height = leftImage.getHeight(imageObserver);
int height;
int leftWidth;
int width;
int width = 0;
int leftWidth = 0;
if(leftImage != null && rightImage != null)
if (leftImage == null)
{
leftWidth = leftImage.getWidth(imageObserver);
width = leftWidth +
rightImage.getWidth(imageObserver);
if (rightImage == null)
{
return null;
}
else
{
height = rightImage.getHeight(imageObserver);
leftWidth = rightImage.getWidth(imageObserver);
width = leftWidth * 2;
}
}
else if(leftImage == null)
else if (rightImage == null)
{
leftWidth = rightImage.getWidth(imageObserver);
width = leftWidth*2;
height = leftImage.getHeight(imageObserver);
leftWidth = leftImage.getWidth(imageObserver);
width = leftWidth * 2;
}
else
{
height
= Math.max(
leftImage.getHeight(imageObserver),
rightImage.getHeight(imageObserver));
leftWidth = leftImage.getWidth(imageObserver);
width = leftWidth*2;
width = leftWidth + rightImage.getWidth(imageObserver);
}
BufferedImage buffImage =
new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
BufferedImage buffImage
= new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) buffImage.getGraphics();
AntialiasingManager.activateAntialiasing(g);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
if(leftImage != null)
if (leftImage != null)
g.drawImage(leftImage, 0, 0, null);
if(rightImage != null)
if (rightImage != null)
g.drawImage(rightImage, leftWidth + 1, 0, null);
return buffImage;

Loading…
Cancel
Save