diff options
Diffstat (limited to 'src')
230 files changed, 6276 insertions, 2350 deletions
diff --git a/src/net/java/sip/communicator/impl/audionotifier/SCAudioClipImpl.java b/src/net/java/sip/communicator/impl/audionotifier/SCAudioClipImpl.java index cc0121c..a5b85cb 100644 --- a/src/net/java/sip/communicator/impl/audionotifier/SCAudioClipImpl.java +++ b/src/net/java/sip/communicator/impl/audionotifier/SCAudioClipImpl.java @@ -51,10 +51,10 @@ public class SCAudioClipImpl implements SCAudioClip InputStream inputstream; try { inputstream = url.openStream(); - this.createAppletAudioClip(inputstream); + this.createAppletAudioClip(inputstream); } catch (IOException e) - { + { e.printStackTrace(); } diff --git a/src/net/java/sip/communicator/impl/configuration/ConfigurationServiceImpl.java b/src/net/java/sip/communicator/impl/configuration/ConfigurationServiceImpl.java index e742284..c3a1861 100644 --- a/src/net/java/sip/communicator/impl/configuration/ConfigurationServiceImpl.java +++ b/src/net/java/sip/communicator/impl/configuration/ConfigurationServiceImpl.java @@ -325,7 +325,12 @@ public class ConfigurationServiceImpl while(keys.hasNext()) { String key = (String)keys.next(); - String keyPrefix = key.substring(0, key.lastIndexOf('.')); + int ix = key.lastIndexOf('.'); + + if(ix == -1) + continue; + + String keyPrefix = key.substring(0, ix); if(exactPrefixMatch) { diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java index aece132..eb4ac67 100644 --- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java +++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java @@ -18,6 +18,7 @@ import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.msghistory.*; import net.java.sip.communicator.service.notification.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.service.systray.*; import net.java.sip.communicator.util.*; @@ -52,6 +53,8 @@ public class GuiActivator implements BundleActivator private static NotificationService notificationService; private static SystrayService systrayService; + + private static ResourceManagementService resourcesService; private static Map providerFactoriesMap = new Hashtable(); @@ -305,6 +308,23 @@ public class GuiActivator implements BundleActivator return systrayService; } + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService) bundleContext + .getService(serviceReference); + } + + return resourcesService; + } + /** * Returns the <tt>NotificationService</tt> obtained from the bundle context. * diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java index d1b700c..22026d2 100644 --- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java @@ -600,8 +600,8 @@ public class UIServiceImpl // Check the isLookAndFeelDecorated property and set the appropriate // default decoration. boolean isDecorated - = new Boolean(ApplicationProperties - .getProperty("isLookAndFeelDecorated")).booleanValue(); + = new Boolean(GuiActivator.getResources(). + getSettingsString("isLookAndFeelDecorated")).booleanValue(); if (isDecorated) { diff --git a/src/net/java/sip/communicator/impl/gui/i18n/Messages.java b/src/net/java/sip/communicator/impl/gui/i18n/Messages.java index 7099e34..fa7469b 100644 --- a/src/net/java/sip/communicator/impl/gui/i18n/Messages.java +++ b/src/net/java/sip/communicator/impl/gui/i18n/Messages.java @@ -9,17 +9,13 @@ package net.java.sip.communicator.impl.gui.i18n; import java.text.*; import java.util.*; +import net.java.sip.communicator.impl.gui.GuiActivator; /** * The Messages class manages the access to the internationalization * properties files. * @author Yana Stamcheva */ public class Messages { - private static final String BUNDLE_NAME - = "resources.languages.impl.gui.resources"; - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - .getBundle(BUNDLE_NAME); /** * Returns an internationalized string corresponding to the given key. @@ -32,18 +28,12 @@ public class Messages { String resourceString; try { - resourceString = RESOURCE_BUNDLE.getString(key); + resourceString = GuiActivator.getResources().getI18NString(key); - int mnemonicIndex = resourceString.indexOf('&'); + char mnemonicIndex = GuiActivator.getResources().getI18nMnemonic(key); - if(mnemonicIndex > -1) { - i18nString.setMnemonic(resourceString.charAt(mnemonicIndex + 1)); - - String firstPart = resourceString.substring(0, mnemonicIndex); - String secondPart = resourceString.substring(mnemonicIndex + 1); - - resourceString = firstPart.concat(secondPart); - } + if(mnemonicIndex > -1) + i18nString.setMnemonic(mnemonicIndex); i18nString.setText(resourceString); @@ -71,21 +61,15 @@ public class Messages { String resourceString; try { - resourceString = RESOURCE_BUNDLE.getString(key); + resourceString = GuiActivator.getResources().getI18NString(key); + + char mnemonicIndex = GuiActivator.getResources().getI18nMnemonic(key); resourceString = MessageFormat.format( resourceString, (Object[]) params); - int mnemonicIndex = resourceString.indexOf('&'); - - if(mnemonicIndex > -1) { - i18nString.setMnemonic(resourceString.charAt(mnemonicIndex + 1)); - - String firstPart = resourceString.substring(0, mnemonicIndex); - String secondPart = resourceString.substring(mnemonicIndex + 1); - - resourceString = firstPart.concat(secondPart); - } + if(mnemonicIndex > -1) + i18nString.setMnemonic(mnemonicIndex); i18nString.setText(resourceString); diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommChatSelectorMenuUI.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommChatSelectorMenuUI.java index 59230e3..a7cd049 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommChatSelectorMenuUI.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommChatSelectorMenuUI.java @@ -12,6 +12,7 @@ import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.utils.*; /** @@ -57,8 +58,8 @@ public class SIPCommChatSelectorMenuUI super.paintBackground(g, menuItem, bgColor); boolean isToolBarExtended - = new Boolean(ApplicationProperties - .getProperty("isToolBarExteneded")).booleanValue(); + = new Boolean(GuiActivator.getResources(). + getSettingsString("isToolBarExteneded")).booleanValue(); if (!isToolBarExtended) { diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommDefaultTheme.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommDefaultTheme.java index eb7aad5..651d04a 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommDefaultTheme.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommDefaultTheme.java @@ -14,6 +14,7 @@ import javax.swing.plaf.*; import javax.swing.plaf.metal.*; import javax.swing.text.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.utils.*; /** @@ -30,7 +31,8 @@ public class SIPCommDefaultTheme * thumb shadow, tabbed pane focus, toolbar docking foreground */ private static final ColorUIResource PRIMARY_CONTROL_DARK_SHADOW = - new ColorUIResource(ColorProperties.getColor("primaryControlDarkShadow")); + new ColorUIResource(GuiActivator.getResources(). + getColor("primaryControlDarkShadow")); /** * Used for desktop color, menu selected background, focus color, slider @@ -38,17 +40,20 @@ public class SIPCommDefaultTheme * scroll bar thumb */ private static final ColorUIResource PRIMARY_CONTROL_SHADOW = - new ColorUIResource(ColorProperties.getColor("primaryControlShadow")); + new ColorUIResource(GuiActivator.getResources(). + getColor("primaryControlShadow")); /** * Used for progress bar border, tooltip border inactive, tooltip foreground * inactive, scroll bar dark shadow. */ private static final ColorUIResource CONTROL_DARK_SHADOW = - new ColorUIResource(ColorProperties.getColor("controlDarkShadow")); + new ColorUIResource(GuiActivator.getResources(). + getColor("controlDarkShadow")); private static final ColorUIResource CONTROL_SHADOW = - new ColorUIResource(ColorProperties.getColor("controlShadow")); + new ColorUIResource(GuiActivator.getResources(). + getColor("controlShadow")); /** * Used for window title inactive background, menu background, tooltip @@ -56,7 +61,8 @@ public class SIPCommDefaultTheme * scroll bar background, tabbed pane tab area background. */ private static final ColorUIResource CONTROL_COLOR = - new ColorUIResource(ColorProperties.getColor("controlColor")); + new ColorUIResource(GuiActivator.getResources(). + getColor("controlColor")); /** * Used for text hightlight color, window title background, scroll bar thumb @@ -64,64 +70,76 @@ public class SIPCommDefaultTheme * ToolBar.floatingForeground */ private static final ColorUIResource PRIMARY_CONTROL_COLOR - = new ColorUIResource(ColorProperties.getColor("primaryControlColor")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("primaryControlColor")); // Used to paint a gradient for a check box or a radio button. private static final ColorUIResource BUTTON_GRADIENT_DARK_COLOR - = new ColorUIResource(ColorProperties.getColor("buttonGradientDark")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("buttonGradientDark")); private static final ColorUIResource BUTTON_GRADIENT_LIGHT_COLOR - = new ColorUIResource(ColorProperties.getColor("buttonGradientLight")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("buttonGradientLight")); private static final ColorUIResource SLIDER_GRADIENT_DARK_COLOR - = new ColorUIResource(ColorProperties.getColor("sliderGradientDark")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("sliderGradientDark")); private static final ColorUIResource SLIDER_GRADIENT_LIGHT_COLOR - = new ColorUIResource(ColorProperties.getColor("sliderGradientLight")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("sliderGradientLight")); private static final ColorUIResource SELECTION_FOREGROUND - = new ColorUIResource(ColorProperties.getColor("selectionForeground")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("selectionForeground")); private static final ColorUIResource SELECTION_BACKGROUND - = new ColorUIResource(ColorProperties.getColor("selectionBackground")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("selectionBackground")); private static final ColorUIResource SPLIT_PANE_DEVIDER_FOCUS_COLOR - = new ColorUIResource(ColorProperties + = new ColorUIResource(GuiActivator.getResources() .getColor("splitPaneDeviderFocused")); private static final ColorUIResource TABBED_PANE_HIGHLIGHT_COLOR - = new ColorUIResource(ColorProperties + = new ColorUIResource(GuiActivator.getResources() .getColor("tabbedPaneBorderHighlight")); private static final ColorUIResource TABLE_GRID_COLOR - = new ColorUIResource(ColorProperties.getColor("tableGrid")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("tableGrid")); private static final ColorUIResource SCROLL_BAR_TRACK_HIGHLIGHT - = new ColorUIResource(ColorProperties + = new ColorUIResource(GuiActivator.getResources() .getColor("scrollBarTrackHighlight")); private static final ColorUIResource SCROLL_BAR_DARK_SHADOW - = new ColorUIResource(ColorProperties.getColor("scrollBarDarkShadow")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("scrollBarDarkShadow")); private static final ColorUIResource DESKTOP_BACKGROUND_COLOR - = new ColorUIResource(ColorProperties.getColor("desktopBackgroundColor")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("desktopBackgroundColor")); private static final ColorUIResource CONTROL_TEXT_COLOR - = new ColorUIResource(ColorProperties.getColor("textColor")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("textColor")); private static final ColorUIResource INACTIVE_CONTROL_TEXT_COLOR - = new ColorUIResource(ColorProperties.getColor("inactiveTextColor")); + = new ColorUIResource(GuiActivator.getResources(). + getColor("inactiveTextColor")); private static final ColorUIResource MENU_DISABLED_FOREGROUND - = new ColorUIResource(ColorProperties + = new ColorUIResource(GuiActivator.getResources() .getColor("menuDisabledForeground")); private static final ColorUIResource TAB_TITLE_HIGHLIGHT - = new ColorUIResource(ColorProperties + = new ColorUIResource(GuiActivator.getResources() .getColor("tabTitleHighlight")); private static final ColorUIResource TAB_TITLE - = new ColorUIResource(ColorProperties + = new ColorUIResource(GuiActivator.getResources() .getColor("tabTitle")); private static final FontUIResource BASIC_FONT diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTabbedPaneEnhancedUI.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTabbedPaneEnhancedUI.java index 132f2f3..47bcf55 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTabbedPaneEnhancedUI.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTabbedPaneEnhancedUI.java @@ -19,6 +19,7 @@ import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import javax.swing.text.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.utils.*; /** @@ -33,7 +34,8 @@ public class SIPCommTabbedPaneEnhancedUI extends SIPCommTabbedPaneUI { private static final Color whiteColor = Color.white; private static final int TAB_OVERLAP - = new Integer(LookAndFeelProperties.getProperty("tabOverlap")).intValue(); + = new Integer(GuiActivator.getResources(). + getSettingsString("tabOverlap")).intValue(); private static final int PREFERRED_WIDTH = 150; diff --git a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java index 91246ba..a80c982 100755 --- a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java +++ b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java @@ -99,8 +99,8 @@ public class MainFrame tabbedPane = new MainTabbedPane(this); String isToolbarExtendedString - = ApplicationProperties.getProperty( - "isToolBarExteneded"); + = GuiActivator.getResources(). + getSettingsString("isToolBarExteneded"); boolean isToolBarExtended = new Boolean(isToolbarExtendedString).booleanValue(); @@ -120,7 +120,7 @@ public class MainFrame this.initTitleFont(); String applicationName - = ApplicationProperties.getProperty( + = GuiActivator.getResources().getSettingsString( "applicationName"); this.setTitle(applicationName); @@ -170,8 +170,8 @@ public class MainFrame */ private void initBounds() { - int width = SizeProperties.getSize("mainWindowWidth"); - int height = SizeProperties.getSize("mainWindowHeight"); + int width = GuiActivator.getResources().getSettingsInt("mainWindowWidth"); + int height = GuiActivator.getResources().getSettingsInt("mainWindowHeight"); this.setSize(width, height); @@ -187,11 +187,11 @@ public class MainFrame JComponent layeredPane = this.getLayeredPane(); String fontName - = ApplicationProperties.getProperty( + = GuiActivator.getResources().getSettingsString( "fontName"); String titleFontSize - = ApplicationProperties.getProperty( + = GuiActivator.getResources().getSettingsString( "titleFontSize"); Font font = new Font( fontName, @@ -1327,8 +1327,8 @@ public class MainFrame */ public LogoBar() { - int width = SizeProperties.getSize("logoBarWidth"); - int height = SizeProperties.getSize("logoBarHeight"); + int width = GuiActivator.getResources().getSettingsInt("logoBarWidth"); + int height = GuiActivator.getResources().getSettingsInt("logoBarHeight"); this.setMinimumSize(new Dimension(width, height)); this.setPreferredSize(new Dimension(width, height)); @@ -1348,7 +1348,7 @@ public class MainFrame = ImageLoader.getImage(ImageLoader.WINDOW_TITLE_BAR); g.setColor(new Color( - ColorProperties.getColor("logoBarBackground"))); + GuiActivator.getResources().getColor("logoBarBackground"))); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.drawImage(backgroundImage, 0, 0, null); diff --git a/src/net/java/sip/communicator/impl/gui/main/account/AccountRegFirstPage.java b/src/net/java/sip/communicator/impl/gui/main/account/AccountRegFirstPage.java index 12a96af..8c1f747 100644 --- a/src/net/java/sip/communicator/impl/gui/main/account/AccountRegFirstPage.java +++ b/src/net/java/sip/communicator/impl/gui/main/account/AccountRegFirstPage.java @@ -16,6 +16,7 @@ import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.customcontrols.*; import net.java.sip.communicator.impl.gui.i18n.*; import net.java.sip.communicator.impl.gui.utils.*; @@ -94,7 +95,8 @@ public class AccountRegFirstPage extends JPanel this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // check for preferred wizard - String prefWName = LoginProperties.getProperty("preferredAccountWizard"); + String prefWName = GuiActivator.getResources(). + getSettingsString("preferredAccountWizard"); if(prefWName != null && prefWName.length() > 0) preferredWizardName = prefWName; } diff --git a/src/net/java/sip/communicator/impl/gui/main/account/NewAccountDialog.java b/src/net/java/sip/communicator/impl/gui/main/account/NewAccountDialog.java index 70492cf..13f533e 100644 --- a/src/net/java/sip/communicator/impl/gui/main/account/NewAccountDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/account/NewAccountDialog.java @@ -96,7 +96,8 @@ public class NewAccountDialog private void initNetworkList() { // check for preferred wizard - String prefWName = LoginProperties.getProperty("preferredAccountWizard"); + String prefWName = GuiActivator.getResources(). + getSettingsString("preferredAccountWizard"); if(prefWName != null && prefWName.length() > 0) preferredWizardName = prefWName; diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallListPanel.java b/src/net/java/sip/communicator/impl/gui/main/call/CallListPanel.java index c26b7a1..c8f2972 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallListPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallListPanel.java @@ -435,7 +435,7 @@ public class CallListPanel super.paintComponent(g); g.setColor(new Color( - ColorProperties.getColor("contactListBackground"))); + GuiActivator.getResources().getColor("contactListBackground"))); // paint the background with the choosen color g.fillRect(0, 0, getWidth(), getHeight()); diff --git a/src/net/java/sip/communicator/impl/gui/main/call/DialPanel.java b/src/net/java/sip/communicator/impl/gui/main/call/DialPanel.java index e46ea93..d7cf7e0 100755 --- a/src/net/java/sip/communicator/impl/gui/main/call/DialPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/DialPanel.java @@ -72,9 +72,11 @@ public class DialPanel private DialButton diezButton = new DialButton( ImageLoader.getImage(ImageLoader.DIEZ_DIAL_BUTTON)); - private int hgap = SizeProperties.getSize("dialPadHorizontalGap"); + private int hgap = GuiActivator.getResources(). + getSettingsInt("dialPadHorizontalGap"); - private int vgap = SizeProperties.getSize("dialPadVerticalGap"); + private int vgap = GuiActivator.getResources(). + getSettingsInt("dialPadVerticalGap"); private JPanel dialPadPanel = new JPanel(new GridLayout(4, 3, hgap, vgap)); @@ -97,8 +99,8 @@ public class DialPanel this.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); - int width = SizeProperties.getSize("dialPadWidth"); - int height = SizeProperties.getSize("dialPadHeight"); + int width = GuiActivator.getResources().getSettingsInt("dialPadWidth"); + int height = GuiActivator.getResources().getSettingsInt("dialPadHeight"); this.dialPadPanel.setPreferredSize(new Dimension(width, height)); @@ -421,7 +423,7 @@ public class DialPanel super.paintComponent(g); g.setColor(new Color( - ColorProperties.getColor("contactListBackground"))); + GuiActivator.getResources().getColor("contactListBackground"))); // paint the background with the chosen color g.fillRect(0, 0, getWidth(), getHeight()); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java index 9f4ee5a..9bbe043 100755 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java @@ -1170,7 +1170,7 @@ public class ChatConversationPanel super.paintComponent(g); g.setColor(new Color( - ColorProperties.getColor("contactListBackground"))); + GuiActivator.getResources().getColor("contactListBackground"))); // paint the background with the choosen color g.fillRect(0, 0, getWidth(), getHeight()); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java index 14c8dc9..bc50006 100755 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java @@ -795,8 +795,8 @@ public class ChatWindow */ public LogoBar() { - int width = SizeProperties.getSize("logoBarWidth"); - int height = SizeProperties.getSize("logoBarHeight"); + int width = GuiActivator.getResources().getSettingsInt("logoBarWidth"); + int height = GuiActivator.getResources().getSettingsInt("logoBarHeight"); this.setMinimumSize(new Dimension(width, height)); this.setPreferredSize(new Dimension(width, height)); @@ -816,7 +816,7 @@ public class ChatWindow = ImageLoader.getImage(ImageLoader.WINDOW_TITLE_BAR); g.setColor(new Color( - ColorProperties.getColor("logoBarBackground"))); + GuiActivator.getResources().getColor("logoBarBackground"))); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.drawImage(backgroundImage, 0, 0, null); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/MenusPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/MenusPanel.java index e2ea81e..270a4d1 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/MenusPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/MenusPanel.java @@ -11,6 +11,7 @@ import java.awt.*; import javax.swing.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.main.chat.menus.*; import net.java.sip.communicator.impl.gui.main.chat.toolBars.*; import net.java.sip.communicator.impl.gui.utils.*; @@ -42,8 +43,8 @@ public class MenusPanel this.parentWindow = parentWindow; boolean isToolBarExtended - = new Boolean(ApplicationProperties - .getProperty("isToolBarExteneded")).booleanValue(); + = new Boolean(GuiActivator.getResources(). + getSettingsString("isToolBarExteneded")).booleanValue(); if (isToolBarExtended) mainToolBar = new ExtendedMainToolBar(this.parentWindow); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/SmiliesSelectorBox.java b/src/net/java/sip/communicator/impl/gui/main/chat/SmiliesSelectorBox.java index 751c2ec..c930aa7 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/SmiliesSelectorBox.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/SmiliesSelectorBox.java @@ -14,6 +14,7 @@ import java.awt.event.*; import javax.swing.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.customcontrols.*; import net.java.sip.communicator.impl.gui.lookandfeel.*; import net.java.sip.communicator.impl.gui.utils.*; @@ -38,10 +39,10 @@ public class SmiliesSelectorBox extends JMenuBar private SIPCommMenu selectorBox = new SIPCommMenu(); private static int BUTTON_HEIGHT - = SizeProperties.getSize("mainToolbarButtonHeight"); + = GuiActivator.getResources().getSettingsInt("mainToolbarButtonHeight"); private static int BUTTON_WIDTH - = SizeProperties.getSize("mainToolbarButtonWidth"); + = GuiActivator.getResources().getSettingsInt("mainToolbarButtonWidth"); private SelectorBoxRolloverListener rolloverListener = new SelectorBoxRolloverListener(); @@ -173,7 +174,8 @@ public class SmiliesSelectorBox extends JMenuBar this.selectorBox.setVerticalTextPosition(SwingConstants.BOTTOM); this.selectorBox.setHorizontalTextPosition(SwingConstants.CENTER); this.selectorBox.setForeground( - new Color(ColorProperties.getColor("chatMenuForeground"))); + new Color(GuiActivator.getResources(). + getColor("chatMenuForeground"))); } /** diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/SmiliesSelectorBox.java.orig b/src/net/java/sip/communicator/impl/gui/main/chat/SmiliesSelectorBox.java.orig new file mode 100644 index 0000000..751c2ec --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/main/chat/SmiliesSelectorBox.java.orig @@ -0,0 +1,210 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ + +package net.java.sip.communicator.impl.gui.main.chat; + +import java.util.*; + +import java.awt.*; +import java.awt.event.*; + +import javax.swing.*; + +import net.java.sip.communicator.impl.gui.customcontrols.*; +import net.java.sip.communicator.impl.gui.lookandfeel.*; +import net.java.sip.communicator.impl.gui.utils.*; + +/** + * The <tt>SmiliesSelectorBox</tt> is the component where user could choose + * a smiley icon to send. + * + * @author Yana Stamcheva + */ +public class SmiliesSelectorBox extends JMenuBar + implements ActionListener +{ + private ChatWindow chatWindow; + + private ArrayList imageList; + + private int gridRowCount = 0; + + private int gridColCount = 0; + + private SIPCommMenu selectorBox = new SIPCommMenu(); + + private static int BUTTON_HEIGHT + = SizeProperties.getSize("mainToolbarButtonHeight"); + + private static int BUTTON_WIDTH + = SizeProperties.getSize("mainToolbarButtonWidth"); + + private SelectorBoxRolloverListener rolloverListener + = new SelectorBoxRolloverListener(); + + /** + * Creates an instance of this <tt>SmiliesSelectorBox</tt> and initializes + * the panel with the smiley icons given by the incoming imageList. + * + * @param imageList The pack of smiley icons. + */ + public SmiliesSelectorBox(ArrayList imageList, ChatWindow chatWindow) + { + this.imageList = imageList; + + this.chatWindow = chatWindow; + + this.selectorBox.setUI(new SIPCommChatSelectorMenuUI()); + + this.setOpaque(false); + this.selectorBox.setOpaque(false); + this.setPreferredSize( + new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); + + //Should explicitly remove any border in order to align correctly the + //icon. + this.selectorBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + + this.selectorBox.setIcon(new ImageIcon(ImageLoader + .getImage(ImageLoader.SMILIES_ICON))); + + this.calculateGridDimensions(imageList.size()); + + this.selectorBox.getPopupMenu().setLayout(new GridLayout( + this.gridRowCount, this.gridColCount, 5, 5)); + + for (int i = 0; i < imageList.size(); i++) { + + Smiley smiley = (Smiley) this.imageList.get(i); + + ImageIcon imageIcon + = new ImageIcon(ImageLoader.getImage(smiley.getImageID())); + + JMenuItem smileyItem = new JMenuItem (imageIcon); + +// smileyItem.setPreferredSize( +// new Dimension( imageIcon.getIconWidth(), +// imageIcon.getIconHeight())); + +// smileyItem.setMargin(new Insets(2, 2, 2, 2)); + + smileyItem.setToolTipText(smiley.getSmileyStrings()[0]); + + smileyItem.addActionListener(this); + + this.selectorBox.add(smileyItem); + } + + this.add(selectorBox); + } + + /** + * In order to have a popup which is at the form closest to sqware. + * @param itemsCount the count of items that will be laied out. + */ + private void calculateGridDimensions(int itemsCount) { + + this.gridRowCount = (int) Math.round(Math.sqrt(itemsCount)); + + this.gridColCount = (int) Math.round(itemsCount / gridRowCount); + } + + /** + * Opens the smilies selector box. + */ + public void open() + { + this.selectorBox.doClick(); + } + + /** + * Returns TRUE if the selector box is opened, otherwise returns FALSE. + * @return TRUE if the selector box is opened, otherwise returns FALSE + */ + public boolean isMenuSelected() + { + if(selectorBox.isPopupMenuVisible()) + return true; + + return false; + } + + /** + * Writes the symbol corresponding to a choosen smiley icon to the write + * message area at the end of the current text. + */ + public void actionPerformed(ActionEvent e) + { + JMenuItem smileyItem = (JMenuItem) e.getSource(); + String buttonText = smileyItem.getToolTipText(); + + for (int i = 0; i < this.imageList.size(); i++) { + + Smiley smiley = (Smiley) this.imageList.get(i); + + if (buttonText.equals(smiley.getSmileyStrings()[0])) { + + ChatPanel chatPanel = this.chatWindow + .getCurrentChatPanel(); + + chatPanel.addTextInWriteArea( + smiley.getSmileyStrings()[0] + " "); + + chatPanel.requestFocusInWriteArea(); + } + } + } + + /** + * Sets the given text to this smiley selector box. The given text will be + * position by default on the bottom of the icon. + * + * @param text the text to be added to this selector box. + */ + public void setText(String text) + { + this.selectorBox.setText(text); + + this.selectorBox.setFont(getFont().deriveFont(Font.BOLD, 10f)); + this.selectorBox.setVerticalTextPosition(SwingConstants.BOTTOM); + this.selectorBox.setHorizontalTextPosition(SwingConstants.CENTER); + this.selectorBox.setForeground( + new Color(ColorProperties.getColor("chatMenuForeground"))); + } + + /** + * Enables or disabled the roll-over effect, when user moves the mouse over + * this smilies selector box. + * + * @param isRollover <code>true</code> to enable the roll-over, + * <code>false</code> - otherwise. + */ + public void setRollover(boolean isRollover) + { + if(isRollover) + selectorBox.addMouseListener(rolloverListener); + else + selectorBox.removeMouseListener(rolloverListener); + } + + /** + * Handles <tt>MouseEvent</tt>s and changes the state of the contained + * selector box in order to make a roll-over effect. + */ + private class SelectorBoxRolloverListener extends MouseAdapter + { + public void mouseEntered(MouseEvent e) + { + selectorBox.setMouseOver(true); + } + + public void mouseExited(MouseEvent e) + { + selectorBox.setMouseOver(false); + } + } +} diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/menus/EditMenu.java b/src/net/java/sip/communicator/impl/gui/main/chat/menus/EditMenu.java index c9ec512..8a2768b 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/menus/EditMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/menus/EditMenu.java @@ -12,6 +12,7 @@ import java.awt.event.*; import javax.swing.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.customcontrols.*; import net.java.sip.communicator.impl.gui.i18n.*; import net.java.sip.communicator.impl.gui.main.chat.*; @@ -57,7 +58,7 @@ public class EditMenu extends SIPCommMenu this.chatWindow = chatWindow; this.setForeground(new Color( - ColorProperties.getColor("chatMenuForeground"))); + GuiActivator.getResources().getColor("chatMenuForeground"))); this.cutMenuItem.setName("cut"); this.copyMenuItem.setName("copy"); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/menus/FileMenu.java b/src/net/java/sip/communicator/impl/gui/main/chat/menus/FileMenu.java index ab109cb..4c658a1 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/menus/FileMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/menus/FileMenu.java @@ -12,6 +12,7 @@ import java.awt.event.*; import javax.swing.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.customcontrols.*; import net.java.sip.communicator.impl.gui.i18n.*; import net.java.sip.communicator.impl.gui.main.chat.*; @@ -56,7 +57,7 @@ public class FileMenu extends SIPCommMenu this.parentWindow = parentWindow; this.setForeground(new Color( - ColorProperties.getColor("chatMenuForeground"))); + GuiActivator.getResources().getColor("chatMenuForeground"))); this.add(saveMenuItem); this.add(printMenuItem); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/menus/HelpMenu.java b/src/net/java/sip/communicator/impl/gui/main/chat/menus/HelpMenu.java index eb836d6..d1b2aa0 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/menus/HelpMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/menus/HelpMenu.java @@ -51,7 +51,7 @@ public class HelpMenu this.chatWindow = chatWindow; this.setForeground(new Color( - ColorProperties.getColor("chatMenuForeground"))); + GuiActivator.getResources().getColor("chatMenuForeground"))); this.setMnemonic(Messages.getI18NString("help").getMnemonic()); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/ExtendedMainToolBar.java b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/ExtendedMainToolBar.java index 789807d..72303f4 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/ExtendedMainToolBar.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/ExtendedMainToolBar.java @@ -88,10 +88,10 @@ public class ExtendedMainToolBar ImageLoader.getImage(ImageLoader.FONT_ICON)); private static int DEFAULT_BUTTON_HEIGHT - = SizeProperties.getSize("mainToolbarButtonHeight"); + = GuiActivator.getResources().getSettingsInt("mainToolbarButtonHeight"); private static int DEFAULT_BUTTON_WIDTH - = SizeProperties.getSize("mainToolbarButtonWidth"); + = GuiActivator.getResources().getSettingsInt("mainToolbarButtonWidth"); private SmiliesSelectorBox smiliesBox; @@ -432,7 +432,7 @@ public class ExtendedMainToolBar this.setFont(getFont().deriveFont(Font.BOLD, 10f)); this.setForeground(new Color( - ColorProperties.getColor("toolBarForeground"))); + GuiActivator.getResources().getColor("toolBarForeground"))); this.setVerticalTextPosition(SwingConstants.BOTTOM); this.setHorizontalTextPosition(SwingConstants.CENTER); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java index dd025f6..76d4514 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java @@ -79,10 +79,10 @@ public class MainToolBar .getImage(ImageLoader.FONT_ICON)); private static int BUTTON_HEIGHT - = SizeProperties.getSize("mainToolbarButtonHeight"); + = GuiActivator.getResources().getSettingsInt("mainToolbarButtonHeight"); private static int BUTTON_WIDTH - = SizeProperties.getSize("mainToolbarButtonWidth"); + = GuiActivator.getResources().getSettingsInt("mainToolbarButtonWidth"); private SmiliesSelectorBox smiliesBox; diff --git a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomsListPanel.java b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomsListPanel.java index 3e77fcd..6e4185a 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomsListPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomsListPanel.java @@ -12,6 +12,7 @@ import java.awt.image.*; import javax.swing.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.main.*; import net.java.sip.communicator.impl.gui.main.chat.*; import net.java.sip.communicator.impl.gui.main.chat.conference.*; @@ -139,7 +140,7 @@ public class ChatRoomsListPanel super.paintComponent(g); g.setColor(new Color( - ColorProperties.getColor("contactListBackground"))); + GuiActivator.getResources().getColor("contactListBackground"))); // paint the background with the choosen color g.fillRect(0, 0, getWidth(), getHeight()); diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java index 4ba0da4..bbf0e20 100755 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java @@ -15,6 +15,7 @@ import java.util.*; import javax.swing.*; import javax.swing.Timer; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.i18n.*; import net.java.sip.communicator.impl.gui.main.*; import net.java.sip.communicator.impl.gui.main.chat.*; @@ -641,7 +642,7 @@ public class ContactListPanel super.paintComponent(g); g.setColor(new Color( - ColorProperties.getColor("contactListBackground"))); + GuiActivator.getResources().getColor("contactListBackground"))); // paint the background with the choosen color g.fillRect(0, 0, getWidth(), getHeight()); diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java.orig b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java.orig new file mode 100644 index 0000000..047332f --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java.orig @@ -0,0 +1,668 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ + +package net.java.sip.communicator.impl.gui.main.contactlist; + +import java.awt.*; +import java.awt.event.*; +import java.awt.image.*; +import java.util.*; + +import javax.swing.*; +import javax.swing.Timer; + +import net.java.sip.communicator.impl.gui.i18n.*; +import net.java.sip.communicator.impl.gui.main.*; +import net.java.sip.communicator.impl.gui.main.chat.*; +import net.java.sip.communicator.impl.gui.utils.*; +import net.java.sip.communicator.service.contacteventhandler.*; +import net.java.sip.communicator.service.contactlist.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.protocol.event.*; +import net.java.sip.communicator.util.*; + +/** + * The contactlist panel not only contains the contact list but it has the role + * of a message dispatcher. It process all sent and received messages as well as + * all typing notifications. Here are managed all contact list mouse events. + * + * @author Yana Stamcheva + */ +public class ContactListPanel + extends JScrollPane + implements MessageListener, + TypingNotificationsListener, + ContactListListener +{ + private MainFrame mainFrame; + + private ContactList contactList; + + private JPanel treePanel = new JPanel(new BorderLayout()); + + private TypingTimer typingTimer = new TypingTimer(); + + private CommonRightButtonMenu commonRightButtonMenu; + + private Logger logger = Logger.getLogger(ContactListPanel.class); + + private ChatWindowManager chatWindowManager; + + /** + * Creates the contactlist scroll panel defining the parent frame. + * + * @param mainFrame The parent frame. + */ + public ContactListPanel(MainFrame mainFrame) { + + this.mainFrame = mainFrame; + + this.chatWindowManager = mainFrame.getChatWindowManager(); + + this.treePanel.setOpaque(false); + + this.setViewport(new ScrollPaneBackground()); + + this.getViewport().setView(treePanel); + + this.setHorizontalScrollBarPolicy( + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + + this.getVerticalScrollBar().setUnitIncrement(30); + + this.setPreferredSize(new Dimension(200, 450)); + this.setMinimumSize(new Dimension(80, 200)); + + } + + /** + * Initializes the contact list. + * + * @param contactListService The MetaContactListService which will be used + * for a contact list data model. + */ + public void initList(MetaContactListService contactListService) + { + this.contactList = new ContactList(mainFrame); + + this.contactList.addContactListListener(this); + this.treePanel.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) + { + + if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { + commonRightButtonMenu = new CommonRightButtonMenu(mainFrame); + + commonRightButtonMenu.setInvoker(treePanel); + + commonRightButtonMenu.setLocation(e.getX() + + mainFrame.getX() + 5, e.getY() + mainFrame.getY() + + 105); + + commonRightButtonMenu.setVisible(true); + } + } + }); + + this.treePanel.add(contactList, BorderLayout.NORTH); + + this.treePanel.setBackground(Color.WHITE); + this.contactList.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + + this.getActionMap().put("runChat", new ContactListPanelEnterAction()); + + InputMap imap = this.getInputMap( + JComponent.WHEN_IN_FOCUSED_WINDOW); + + imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "runChat"); + } + + /** + * Returns the contact list. + * + * @return the contact list + */ + public ContactList getContactList() + { + return this.contactList; + } + + /** + * Implements the ContactListListener.contactSelected method. + */ + public void contactClicked(ContactListEvent evt) + { + MetaContact metaContact = evt.getSourceContact(); + + // Searching for the right proto contact to use as default for the + // chat conversation. + Contact defaultContact = metaContact.getDefaultContact(); + + ProtocolProviderService defaultProvider + = defaultContact.getProtocolProvider(); + + OperationSetBasicInstantMessaging + defaultIM = (OperationSetBasicInstantMessaging) + defaultProvider.getOperationSet( + OperationSetBasicInstantMessaging.class); + + ProtocolProviderService protoContactProvider; + OperationSetBasicInstantMessaging protoContactIM; + + if (defaultContact.getPresenceStatus().getStatus() < 1 + && (!defaultIM.isOfflineMessagingSupported() + || !defaultProvider.isRegistered())) + { + Iterator<Contact> protoContacts = metaContact.getContacts(); + + while(protoContacts.hasNext()) + { + Contact contact = protoContacts.next(); + + protoContactProvider = contact.getProtocolProvider(); + + protoContactIM = (OperationSetBasicInstantMessaging) + protoContactProvider.getOperationSet( + OperationSetBasicInstantMessaging.class); + + if(protoContactIM.isOfflineMessagingSupported() + && protoContactProvider.isRegistered()) + { + defaultContact = contact; + } + } + } + + ContactEventHandler contactHandler = mainFrame + .getContactHandler(defaultContact.getProtocolProvider()); + + contactHandler.contactClicked(defaultContact, evt.getClickCount()); + } + + /** + * Implements the ContactListListener.groupSelected method. + */ + public void groupSelected(ContactListEvent evt) + {} + + /** + * Implements the ContactListListener.protocolContactSelected method. + */ + public void protocolContactClicked(ContactListEvent evt) + { + Contact protoContact = evt.getSourceProtoContact(); + + ContactEventHandler contactHandler = mainFrame + .getContactHandler(protoContact.getProtocolProvider()); + + contactHandler.contactClicked(protoContact, evt.getClickCount()); + } + + /** + * Runs the chat window for the specified contact. We examine different + * cases here, depending on the chat window mode. + * + * In mode "Open messages in new window" a new window is opened for the + * given <tt>MetaContact</tt> if there's no opened window for it, + * otherwise the existing chat window is made visible and focused. + * + * In mode "Group messages in one chat window" a JTabbedPane is used to show + * chats for different contacts in ona window. A new tab is opened for the + * given <tt>MetaContact</tt> if there's no opened tab for it, otherwise + * the existing chat tab is selected and focused. + * + * @author Yana Stamcheva + */ + public class RunMessageWindow implements Runnable + { + private MetaContact metaContact; + + private Contact protocolContact; + + private boolean isSmsSelected = false; + + /** + * Creates an instance of <tt>RunMessageWindow</tt> by specifying the + * + * @param metaContact the meta contact to which we will talk. + */ + public RunMessageWindow(MetaContact metaContact) + { + this.metaContact = metaContact; + } + + /** + * Creates a chat window + * + * @param metaContact + * @param protocolContact + */ + public RunMessageWindow(MetaContact metaContact, + Contact protocolContact) + { + this.metaContact = metaContact; + this.protocolContact = protocolContact; + } + + /** + * Creates a chat window + * + * @param metaContact + * @param protocolContact + * @param isSmsSelected + */ + public RunMessageWindow(MetaContact metaContact, + Contact protocolContact, boolean isSmsSelected) + { + this.metaContact = metaContact; + this.protocolContact = protocolContact; + this.isSmsSelected = isSmsSelected; + } + + /** + * Opens a chat window + */ + public void run() + { + MetaContactChatPanel chatPanel; + + if(protocolContact != null) + chatPanel = chatWindowManager + .getContactChat(metaContact, protocolContact); + else + chatPanel = chatWindowManager.getContactChat(metaContact); + + chatPanel.setSmsSelected(isSmsSelected); + + chatWindowManager.openChat(chatPanel, true); + } + } + + /** + * When a message is received determines whether to open a new chat window + * or chat window tab, or to indicate that a message is received from a + * contact which already has an open chat. When the chat is found checks if + * in mode "Auto popup enabled" and if this is the case shows the message in + * the appropriate chat panel. + * + * @param evt the event containing details on the received message + */ + public void messageReceived(MessageReceivedEvent evt) + { + logger.trace("MESSAGE RECEIVED from contact: " + + evt.getSourceContact().getAddress()); + + Contact protocolContact = evt.getSourceContact(); + Date date = evt.getTimestamp(); + Message message = evt.getSourceMessage(); + int eventType = evt.getEventType(); + + MetaContact metaContact = mainFrame.getContactList() + .findMetaContactByContact(protocolContact); + + if(metaContact != null) + { + // Show an envelope on the sender contact in the contact list and + // in the systray. + ContactListModel clistModel + = (ContactListModel) contactList.getModel(); + + clistModel.addActiveContact(metaContact); + contactList.refreshContact(metaContact); + + // Obtain the corresponding chat panel. + final MetaContactChatPanel chatPanel + = chatWindowManager.getContactChat( metaContact, + protocolContact, + message.getMessageUID()); + + // Distinguish the message type, depending on the type of event that + // we have received. + String messageType = null; + + if(eventType == MessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED) + { + messageType = Constants.INCOMING_MESSAGE; + } + else if(eventType == MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED) + { + messageType = Constants.SYSTEM_MESSAGE; + } + else if(eventType == MessageReceivedEvent.SMS_MESSAGE_RECEIVED) + { + messageType = Constants.SMS_MESSAGE; + } + + chatPanel.processMessage(protocolContact.getDisplayName(), date, + messageType, message.getContent(), + message.getContentType()); + + // A bug Fix for Previous/Next buttons . + // Must update buttons state after message is processed + // otherwise states are not proper + chatPanel.getChatWindow().getMainToolBar(). + changeHistoryButtonsState(chatPanel); + + // Opens the chat panel with the new message in the UI thread. + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + chatWindowManager.openChat(chatPanel, false); + } + }); + + // Fire notification + String title = Messages.getI18NString("msgReceived", + new String[]{evt.getSourceContact().getDisplayName()}).getText(); + + NotificationManager.fireChatNotification( + protocolContact, + NotificationManager.INCOMING_MESSAGE, + title, + message.getContent()); + + chatPanel.treatReceivedMessage(protocolContact); + } + else + { + logger.trace("MetaContact not found for protocol contact: " + + protocolContact + "."); + } + } + + /** + * When a sent message is delivered shows it in the chat conversation panel. + * + * @param evt the event containing details on the message delivery + */ + public void messageDelivered(MessageDeliveredEvent evt) + { + Contact contact = evt.getDestinationContact(); + + MetaContact metaContact = mainFrame.getContactList() + .findMetaContactByContact(contact); + + logger.trace("MESSAGE DELIVERED to contact: " + + evt.getDestinationContact().getAddress()); + + Message msg = evt.getSourceMessage(); + + MetaContactChatPanel chatPanel = null; + + if(chatWindowManager.isChatOpenedForContact(metaContact)) + chatPanel = chatWindowManager.getContactChat(metaContact); + + if (chatPanel != null) + { + ProtocolProviderService protocolProvider = evt + .getDestinationContact().getProtocolProvider(); + + logger.trace("MESSAGE DELIVERED: process message to chat for contact: " + + evt.getDestinationContact().getAddress()); + + chatPanel.processMessage(this.mainFrame + .getAccount(protocolProvider), evt.getTimestamp(), + Constants.OUTGOING_MESSAGE, msg.getContent(), + msg.getContentType()); + } + } + + /** + * Shows a warning message to the user when message delivery has failed. + * + * @param evt the event containing details on the message delivery failure + */ + public void messageDeliveryFailed(MessageDeliveryFailedEvent evt) + { + logger.error(evt.getReason()); + + String errorMsg = null; + + Message sourceMessage = (Message) evt.getSource(); + + Contact sourceContact = evt.getDestinationContact(); + + MetaContact metaContact = mainFrame.getContactList() + .findMetaContactByContact(sourceContact); + + if (evt.getErrorCode() + == MessageDeliveryFailedEvent.OFFLINE_MESSAGES_NOT_SUPPORTED) { + + errorMsg = Messages.getI18NString( + "msgDeliveryOfflineNotSupported").getText(); + } + else if (evt.getErrorCode() + == MessageDeliveryFailedEvent.NETWORK_FAILURE) { + + errorMsg = Messages.getI18NString("msgNotDelivered").getText(); + } + else if (evt.getErrorCode() + == MessageDeliveryFailedEvent.PROVIDER_NOT_REGISTERED) { + + errorMsg = Messages.getI18NString( + "msgSendConnectionProblem").getText(); + } + else if (evt.getErrorCode() + == MessageDeliveryFailedEvent.INTERNAL_ERROR) { + + errorMsg = Messages.getI18NString( + "msgDeliveryInternalError").getText(); + } + else { + errorMsg = Messages.getI18NString( + "msgDeliveryFailedUnknownError").getText(); + } + + MetaContactChatPanel chatPanel = chatWindowManager + .getContactChat(metaContact, sourceContact); + + chatPanel.processMessage( + metaContact.getDisplayName(), + new Date(System.currentTimeMillis()), + Constants.OUTGOING_MESSAGE, + sourceMessage.getContent(), + sourceMessage.getContentType()); + + chatPanel.processMessage( + metaContact.getDisplayName(), + new Date(System.currentTimeMillis()), + Constants.ERROR_MESSAGE, + errorMsg, + "text"); + + chatWindowManager.openChat(chatPanel, false); + } + + /** + * Informs the user what is the typing state of his chat contacts. + * + * @param evt the event containing details on the typing notification + */ + public void typingNotificationReceifed(TypingNotificationEvent evt) + { + if (typingTimer.isRunning()) + typingTimer.stop(); + + String notificationMsg = ""; + + String contactName = this.mainFrame.getContactList() + .findMetaContactByContact(evt.getSourceContact()) + .getDisplayName() + + " "; + + if (contactName.equals("")) { + contactName = Messages.getI18NString("unknown").getText() + " "; + } + + int typingState = evt.getTypingState(); + MetaContact metaContact = mainFrame.getContactList() + .findMetaContactByContact(evt.getSourceContact()); + + if (typingState == OperationSetTypingNotifications.STATE_TYPING) + { + notificationMsg + = Messages.getI18NString("contactTyping", + new String[]{contactName}).getText(); + + typingTimer.setMetaContact(metaContact); + typingTimer.start(); + } + else if (typingState == OperationSetTypingNotifications.STATE_PAUSED) + { + notificationMsg = Messages.getI18NString("contactPausedTyping", + new String[]{contactName}).getText(); + typingTimer.setMetaContact(metaContact); + typingTimer.start(); + } + else if (typingState == OperationSetTypingNotifications.STATE_STOPPED) + { + notificationMsg = ""; + } + else if (typingState == OperationSetTypingNotifications.STATE_STALE) + { + notificationMsg + = Messages.getI18NString("contactTypingStateStale").getText(); + } + else if (typingState == OperationSetTypingNotifications.STATE_UNKNOWN) + { + // TODO: Implement state unknown + } + this.setChatNotificationMsg(metaContact, notificationMsg); + } + + /** + * Sets the typing notification message at the appropriate chat. + * + * @param metaContact The meta contact. + * @param notificationMsg The typing notification message. + */ + public void setChatNotificationMsg(MetaContact metaContact, + String notificationMsg) + { + if(chatWindowManager.isChatOpenedForContact(metaContact)) + chatWindowManager.getContactChat(metaContact) + .setStatusMessage(notificationMsg); + } + + /** + * Returns the right button menu of the contact list. + * @return the right button menu of the contact list + */ + public CommonRightButtonMenu getCommonRightButtonMenu() + { + return commonRightButtonMenu; + } + + /** + * The TypingTimer is started after a PAUSED typing notification is + * received. It waits 5 seconds and if no other typing event occurs removes + * the PAUSED message from the chat status panel. + */ + private class TypingTimer extends Timer + { + + private MetaContact metaContact; + + public TypingTimer() { + // Set delay + super(5 * 1000, null); + + this.addActionListener(new TimerActionListener()); + } + + private class TimerActionListener implements ActionListener + { + public void actionPerformed(ActionEvent e) + { + setChatNotificationMsg(metaContact, ""); + } + } + + private void setMetaContact(MetaContact metaContact) + { + this.metaContact = metaContact; + } + } + + /** + * Opens chat window when the selected value is a MetaContact and opens a + * group when the selected value is a MetaContactGroup. + */ + private class ContactListPanelEnterAction extends AbstractAction + { + public void actionPerformed(ActionEvent e) + { + Object selectedValue = contactList.getSelectedValue(); + + if (selectedValue instanceof MetaContact) { + MetaContact contact = (MetaContact) selectedValue; + + SwingUtilities.invokeLater(new RunMessageWindow(contact)); + } + else if (selectedValue instanceof MetaContactGroup) { + MetaContactGroup group = (MetaContactGroup) selectedValue; + + ContactListModel model + = (ContactListModel) contactList.getModel(); + + if (model.isGroupClosed(group)) { + model.openGroup(group); + } + } + } + } + + private class ScrollPaneBackground extends JViewport + { + BufferedImage bgImage; + + TexturePaint texture; + + public ScrollPaneBackground() + { + bgImage = ImageLoader.getImage(ImageLoader.MAIN_WINDOW_BACKGROUND); +// Rectangle rect +// = new Rectangle(0, 0, +// bgImage.getWidth(null), +// bgImage.getHeight(null)); + +// texture = new TexturePaint(bgImage, rect); + } + + public void paintComponent(Graphics g) + { + // do the superclass behavior first + super.paintComponent(g); + + g.setColor(new Color( + ColorProperties.getColor("contactListBackground"))); + + // paint the background with the choosen color + g.fillRect(0, 0, getWidth(), getHeight()); + + // paint the image + if (bgImage != null) + { + Graphics2D g2 = (Graphics2D) g; + +// g2.setPaint(texture); + + g2.drawImage(bgImage, + this.getWidth() - bgImage.getWidth(), + this.getHeight() - bgImage.getHeight(), + this); + } + } + + public void setView(JComponent view) + { + view.setOpaque(false); + super.setView(view); + } + } +} diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/ExtendedQuickMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/ExtendedQuickMenu.java index d9afd03..dc8bbf3 100644 --- a/src/net/java/sip/communicator/impl/gui/main/menus/ExtendedQuickMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/ExtendedQuickMenu.java @@ -72,10 +72,10 @@ public class ExtendedQuickMenu ImageLoader.getImage(ImageLoader.QUICK_MENU_SOUND_ON_ICON)); private static int DEFAULT_BUTTON_HEIGHT - = SizeProperties.getSize("mainToolbarButtonHeight"); + = GuiActivator.getResources().getSettingsInt("mainToolbarButtonHeight"); private static int DEFAULT_BUTTON_WIDTH - = SizeProperties.getSize("mainToolbarButtonWidth"); + = GuiActivator.getResources().getSettingsInt("mainToolbarButtonWidth"); private ExportedWindow configDialog; @@ -509,7 +509,7 @@ public class ExtendedQuickMenu this.setFont(getFont().deriveFont(Font.BOLD, 10f)); this.setForeground(new Color( - ColorProperties.getColor("toolBarForeground"))); + GuiActivator.getResources().getColor("toolBarForeground"))); this.setVerticalTextPosition(SwingConstants.BOTTOM); this.setHorizontalTextPosition(SwingConstants.CENTER); diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/FileMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/FileMenu.java index d22ffaf..a6bb1b9 100644 --- a/src/net/java/sip/communicator/impl/gui/main/menus/FileMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/FileMenu.java @@ -89,7 +89,7 @@ public class FileMenu super(Messages.getI18NString("file").getText()); this.setForeground( - new Color(ColorProperties.getColor("mainMenuForeground"))); + new Color(GuiActivator.getResources().getColor("mainMenuForeground"))); this.parentWindow = parentWindow; diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/HelpMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/HelpMenu.java index 80a2f0d..d248a45 100644 --- a/src/net/java/sip/communicator/impl/gui/main/menus/HelpMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/HelpMenu.java @@ -52,7 +52,8 @@ public class HelpMenu this.setMnemonic(Messages.getI18NString("help").getMnemonic()); this.setForeground( - new Color(ColorProperties.getColor("mainMenuForeground"))); + new Color(GuiActivator.getResources(). + getColor("mainMenuForeground"))); this.initPluginComponents(); } diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/QuickMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/QuickMenu.java index 608c462..74c05a8 100755 --- a/src/net/java/sip/communicator/impl/gui/main/menus/QuickMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/QuickMenu.java @@ -68,10 +68,10 @@ public class QuickMenu ImageLoader.QUICK_MENU_SOUND_ON_ICON))); private static int BUTTON_HEIGHT - = SizeProperties.getSize("mainToolbarButtonHeight"); + = GuiActivator.getResources().getSettingsInt("mainToolbarButtonHeight"); private static int BUTTON_WIDTH - = SizeProperties.getSize("mainToolbarButtonWidth"); + = GuiActivator.getResources().getSettingsInt("mainToolbarButtonWidth"); private ExportedWindow configDialog; diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java index 1ac5ed2..11f90f6 100644 --- a/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java @@ -55,7 +55,8 @@ public class ToolsMenu super(Messages.getI18NString("tools").getText()); this.setForeground( - new Color(ColorProperties.getColor("mainMenuForeground"))); + new Color(GuiActivator.getResources(). + getColor("mainMenuForeground"))); this.parentWindow = parentWindow; diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/ViewMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/ViewMenu.java index 15b80c5..2904343 100644 --- a/src/net/java/sip/communicator/impl/gui/main/menus/ViewMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/ViewMenu.java @@ -54,7 +54,8 @@ public class ViewMenu super(Messages.getI18NString("view").getText()); this.setForeground( - new Color(ColorProperties.getColor("mainMenuForeground"))); + new Color(GuiActivator.getResources(). + getColor("mainMenuForeground"))); this.mainFrame = mainFrame; diff --git a/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf b/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf index dd7f624..dd2fd58 100644 --- a/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf +++ b/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf @@ -7,6 +7,7 @@ Export-Package: net.java.sip.communicator.service.gui, net.java.sip.communicator.service.gui.event Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/impl/gui/utils/ApplicationProperties.java b/src/net/java/sip/communicator/impl/gui/utils/ApplicationProperties.java index dc5e5fb..e69de29 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ApplicationProperties.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ApplicationProperties.java @@ -1,57 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.gui.utils; - -import java.util.*; - -import net.java.sip.communicator.util.*; - -/** - * Accesses all application properties saved in the application.properties file. - * - * @author Yana Stamcheva - */ -public class ApplicationProperties -{ - /** - * Logger for this class. - */ - private static Logger log = Logger.getLogger(ApplicationProperties.class); - - /** - * Name of the bundle where we will search for color resources. - */ - private static final String BUNDLE_NAME - = "resources.application"; - - /** - * Bundle which handle access to localized resources. - */ - private static final ResourceBundle PROPERTIES_BUNDLE = ResourceBundle - .getBundle( BUNDLE_NAME); - - /** - * Returns the application property corresponding to the given key. - * - * @param key The key of the string. - * - * @return the application property corresponding to the given key - */ - public static String getProperty(String key) - { - try - { - return PROPERTIES_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - log.error("Missing property.", e); - - return ""; - } - } -} diff --git a/src/net/java/sip/communicator/impl/gui/utils/ColorProperties.java b/src/net/java/sip/communicator/impl/gui/utils/ColorProperties.java index 7b92d47..e69de29 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ColorProperties.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ColorProperties.java @@ -1,80 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.gui.utils; - -import java.util.*; - -import net.java.sip.communicator.util.*; - -/** - * Accesses the color resources saved in the colorResources.properties file. - * - * @author Yana Stamcheva - */ -public class ColorProperties -{ - /** - * Logger for this class. - */ - private static Logger log = Logger.getLogger(ColorProperties.class); - - /** - * Name of the bundle where we will search for color resources. - */ - private static final String BUNDLE_NAME - = "resources.colors.colorResources"; - - /** - * Bundle which handle access to localized resources. - */ - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - .getBundle( BUNDLE_NAME, - Locale.getDefault(), - ColorProperties.class.getClassLoader()); - - /** - * Returns an int RGB color corresponding to the given key. - * - * @param key The key of the string. - * - * @return An internationalized string corresponding to the given key. - */ - public static int getColor(String key) - { - try - { - return Integer.parseInt(RESOURCE_BUNDLE.getString(key), 16); - } - catch (MissingResourceException e) - { - log.error("Missing color resource.", e); - - return 0xFFFFFF; - } - } - - /** - * Returns an int RGB color corresponding to the given key. - * - * @param key The key of the string. - * - * @return An internationalized string corresponding to the given key. - */ - public static String getColorString(String key) - { - try - { - return RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - log.error("Missing color resource.", e); - - return "0xFFFFFF"; - } - } -} diff --git a/src/net/java/sip/communicator/impl/gui/utils/Constants.java b/src/net/java/sip/communicator/impl/gui/utils/Constants.java index aa3e637..880d4b0 100755 --- a/src/net/java/sip/communicator/impl/gui/utils/Constants.java +++ b/src/net/java/sip/communicator/impl/gui/utils/Constants.java @@ -15,6 +15,7 @@ import java.util.*; import javax.swing.text.html.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; @@ -138,48 +139,55 @@ public class Constants * record. */ public static final Color HISTORY_IN_CALL_COLOR - = new Color(ColorProperties.getColor("historyIncomingCallBackground")); + = new Color(GuiActivator.getResources(). + getColor("historyIncomingCallBackground")); /** * The color used to paint the background of an outgoing call history * record. */ public static final Color HISTORY_OUT_CALL_COLOR - = new Color(ColorProperties.getColor("historyOutgoingCallBackground")); + = new Color(GuiActivator.getResources(). + getColor("historyOutgoingCallBackground")); /** * The end color used to paint a gradient selected background of some * components. */ public static final Color SELECTED_COLOR - = new Color(ColorProperties.getColor("listSelectionColor")); + = new Color(GuiActivator.getResources(). + getColor("listSelectionColor")); /** * The start color used to paint a gradient mouse over background of some * components. */ public static final Color GRADIENT_DARK_COLOR - = new Color(ColorProperties.getColor("gradientDarkColor")); + = new Color(GuiActivator.getResources(). + getColor("gradientDarkColor")); /** * The end color used to paint a gradient mouse over background of some * components. */ public static final Color GRADIENT_LIGHT_COLOR - = new Color(ColorProperties.getColor("gradientLightColor")); + = new Color(GuiActivator.getResources(). + getColor("gradientLightColor")); /** * A color between blue and gray used to paint some borders. */ public static final Color BORDER_COLOR - = new Color(ColorProperties.getColor("borderColor")); + = new Color(GuiActivator.getResources(). + getColor("borderColor")); /** * A color between blue and gray (darker than the other one), used to paint * some borders. */ public static final Color LIST_SELECTION_BORDER_COLOR - = new Color(ColorProperties.getColor("listSelectionBorderColor")); + = new Color(GuiActivator.getResources(). + getColor("listSelectionBorderColor")); /* * ====================================================================== diff --git a/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java b/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java index 25d1e20..5bcdacb 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java @@ -10,11 +10,13 @@ package net.java.sip.communicator.impl.gui.utils; import java.awt.*; import java.awt.image.*; import java.io.*; +import java.net.*; import java.util.*; import javax.imageio.*; import javax.imageio.stream.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.util.*; /** @@ -1067,15 +1069,14 @@ public class ImageLoader { } else { - String path = Images.getString(imageID.getId()); + URL path = GuiActivator.getResources().getImageURL(imageID.getId()); if (path == null) return null; try { - image = ImageIO.read(ImageLoader.class.getClassLoader() - .getResource(path)); + image = ImageIO.read(path); loadedImages.put(imageID, image); } @@ -1093,16 +1094,22 @@ public class ImageLoader { * @param imageID The identifier of the image. * @return The image for the given identifier. */ - public static byte[] getImageInBytes(ImageID imageID) { - byte[] image = new byte[100000]; + public static byte[] getImageInBytes(ImageID imageID) + { + InputStream in = GuiActivator.getResources(). + getImageInputStream(imageID.getId()); - String path = Images.getString(imageID.getId()); - try { - Images.class.getClassLoader() - .getResourceAsStream(path).read(image); + if (in == null) + return null; + byte[] image = null; + try + { + image = new byte[in.available()]; - } catch (IOException e) { - log.error("Failed to load image:" + path, e); + in.read(image); + } catch (IOException e) + { + log.error("Failed to load image:" + imageID.getId(), e); } return image; @@ -1191,22 +1198,29 @@ public class ImageLoader { * The image wich path to return. * @return The path string of an already loaded image, otherwise null. */ - public static String getImagePath(Image image) { - - String path = null; - + public static String getImagePath(Image image) + { Iterator i = ImageLoader.loadedImages.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); - if (entry.getValue().equals(image)) { + if (entry.getValue().equals(image)) + { String imageID = ((ImageID) entry.getKey()).getId(); - path = Images.getString(imageID); + try + { + return GuiActivator.getResources(). + getImageURL(imageID).toURI().toString(); + } + catch(URISyntaxException ex) + { + log.error("Failed to create path for image " + imageID); + } } } - return path; + return null; } } diff --git a/src/net/java/sip/communicator/impl/gui/utils/Images.java b/src/net/java/sip/communicator/impl/gui/utils/Images.java index a11db2e..e69de29 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/Images.java +++ b/src/net/java/sip/communicator/impl/gui/utils/Images.java @@ -1,50 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ - -package net.java.sip.communicator.impl.gui.utils; - -import java.util.*; -import net.java.sip.communicator.util.*; - -/** - * Manages the access to the properties file containing all image paths. - * - * @author Yana Stamcheva - */ -public class Images -{ - private static final Logger logger - = Logger.getLogger(Images.class); - - private static final String BUNDLE_NAME - = "net.java.sip.communicator.impl.gui.utils.images"; - - private static final ResourceBundle RESOURCE_BUNDLE - = ResourceBundle.getBundle(BUNDLE_NAME); - - private Images() { - } - - /** - * Returns an image path corresponding to the given image key. - * @param key The key of the image. - * @return An image path corresponding to the given image key. - */ - public static String getString(String key) - { - try - { - return RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException exc) - { - logger.warn("Failed to find image for path " + key, exc); - } - - return null; - } -} diff --git a/src/net/java/sip/communicator/impl/gui/utils/LoginProperties.java b/src/net/java/sip/communicator/impl/gui/utils/LoginProperties.java index 8c93a9a..e69de29 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/LoginProperties.java +++ b/src/net/java/sip/communicator/impl/gui/utils/LoginProperties.java @@ -1,57 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.gui.utils; - -import java.util.*; - -import net.java.sip.communicator.util.*; - -/** - * Accesses all login properties saved in the login.properties file. - * - * @author Yana Stamcheva - */ -public class LoginProperties -{ - /** - * Logger for this class. - */ - private static Logger log = Logger.getLogger(ColorProperties.class); - - /** - * Name of the bundle where we will search for color resources. - */ - private static final String BUNDLE_NAME - = "resources.login"; - - /** - * Bundle which handle access to localized resources. - */ - private static final ResourceBundle PROPERTIES_BUNDLE = ResourceBundle - .getBundle( BUNDLE_NAME); - - /** - * Returns the application property corresponding to the given key. - * - * @param key The key of the string. - * - * @return the application property corresponding to the given key - */ - public static String getProperty(String key) - { - try - { - return PROPERTIES_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - log.error("Missing property.", e); - - return ""; - } - } -} diff --git a/src/net/java/sip/communicator/impl/gui/utils/LookAndFeelProperties.java b/src/net/java/sip/communicator/impl/gui/utils/LookAndFeelProperties.java index c5a9016..e69de29 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/LookAndFeelProperties.java +++ b/src/net/java/sip/communicator/impl/gui/utils/LookAndFeelProperties.java @@ -1,57 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.gui.utils; - -import java.util.*; - -import net.java.sip.communicator.util.*; - -/** - * Accesses all Look&Feel properties saved in the lookandfeel.properties file. - * - * @author Yana Stamcheva - */ -public class LookAndFeelProperties -{ - /** - * Logger for this class. - */ - private static Logger log = Logger.getLogger(LookAndFeelProperties.class); - - /** - * Name of the bundle where we will search for look and feel resources. - */ - private static final String BUNDLE_NAME - = "resources.lookandfeel"; - - /** - * Bundle which handle access to look and feel resources. - */ - private static final ResourceBundle PROPERTIES_BUNDLE = ResourceBundle - .getBundle( BUNDLE_NAME); - - /** - * Returns the look and feel property corresponding to the given key. - * - * @param key The key of the string. - * - * @return the look and feel property corresponding to the given key - */ - public static String getProperty(String key) - { - try - { - return PROPERTIES_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - log.error("Missing property.", e); - - return ""; - } - } -}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/gui/utils/SizeProperties.java b/src/net/java/sip/communicator/impl/gui/utils/SizeProperties.java index 491ec72..e69de29 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/SizeProperties.java +++ b/src/net/java/sip/communicator/impl/gui/utils/SizeProperties.java @@ -1,60 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.gui.utils; - -import java.util.*; - -import net.java.sip.communicator.util.*; - -/** - * Manages the access to the size properties contained in the size.properties - * file in the resource folder. - * - * @author Yana Stamcheva - */ -public class SizeProperties -{ - /** - * Logger for this class. - */ - private static Logger log = Logger.getLogger(SizeProperties.class); - - /** - * Name of the bundle where we will search for size properties. - */ - private static final String BUNDLE_NAME - = "resources.size.size"; - - /** - * Bundle which handles access to the size properties. - */ - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - .getBundle( BUNDLE_NAME, - Locale.getDefault(), - SizeProperties.class.getClassLoader()); - - /** - * Returns the size corresponding to the given key. - * - * @param key The key of the string. - * - * @return the size corresponding to the given key - */ - public static int getSize(String key) - { - try - { - return Integer.parseInt(RESOURCE_BUNDLE.getString(key)); - } - catch (MissingResourceException e) - { - log.error("Missing size resource.", e); - - return 0; - } - } -} diff --git a/src/net/java/sip/communicator/impl/gui/utils/Smiley.java b/src/net/java/sip/communicator/impl/gui/utils/Smiley.java index 5f9441d..1c47048 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/Smiley.java +++ b/src/net/java/sip/communicator/impl/gui/utils/Smiley.java @@ -7,6 +7,8 @@ package net.java.sip.communicator.impl.gui.utils; +import java.net.*; +import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.utils.ImageLoader.*; /** @@ -76,7 +78,14 @@ public class Smiley { * Returns the path of the image corresponding to this smily. * @return the path of the image corresponding to this smily. */ - public String getImagePath() { - return Images.getString(this.getImageID().getId()); + public String getImagePath() + { + URL url = GuiActivator.getResources(). + getImageURL(this.getImageID().getId()); + + if(url == null) + return null; + + return url.toString(); } } diff --git a/src/net/java/sip/communicator/impl/gui/utils/SoundProperties.java b/src/net/java/sip/communicator/impl/gui/utils/SoundProperties.java index 073f355..b8fc967 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/SoundProperties.java +++ b/src/net/java/sip/communicator/impl/gui/utils/SoundProperties.java @@ -67,9 +67,6 @@ public class SoundProperties private static final String BUNDLE_NAME = "net.java.sip.communicator.impl.gui.utils.sounds"; - private static final ResourceBundle RESOURCE_BUNDLE - = ResourceBundle.getBundle(BUNDLE_NAME); - private SoundProperties() { } } diff --git a/src/net/java/sip/communicator/impl/protocol/dict/DictActivator.java b/src/net/java/sip/communicator/impl/protocol/dict/DictActivator.java index 962c798..7050052 100644 --- a/src/net/java/sip/communicator/impl/protocol/dict/DictActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/dict/DictActivator.java @@ -26,7 +26,7 @@ public class DictActivator /** * The currently valid bundle context. */ - private static BundleContext bundleContext = null; + static BundleContext bundleContext = null; private ServiceRegistration dictPpFactoryServReg = null; private static ProtocolProviderFactoryDictImpl diff --git a/src/net/java/sip/communicator/impl/protocol/dict/DictStatusEnum.java b/src/net/java/sip/communicator/impl/protocol/dict/DictStatusEnum.java index 9259dda..2e7144c 100644 --- a/src/net/java/sip/communicator/impl/protocol/dict/DictStatusEnum.java +++ b/src/net/java/sip/communicator/impl/protocol/dict/DictStatusEnum.java @@ -86,7 +86,8 @@ public class DictStatusEnum */ public static byte[] loadIcon(String imagePath) { - InputStream is = DictStatusEnum.class.getClassLoader().getResourceAsStream(imagePath); + InputStream is = + ProtocolIconDictImpl.getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try diff --git a/src/net/java/sip/communicator/impl/protocol/dict/ProtocolIconDictImpl.java b/src/net/java/sip/communicator/impl/protocol/dict/ProtocolIconDictImpl.java index d783476..51d315b 100644 --- a/src/net/java/sip/communicator/impl/protocol/dict/ProtocolIconDictImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/dict/ProtocolIconDictImpl.java @@ -10,8 +10,11 @@ import java.io.*; import java.util.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * Reperesents the Dict protocol icon. Implements the <tt>ProtocolIcon</tt> * interface in order to provide a dict logo image in two different sizes. @@ -24,6 +27,8 @@ public class ProtocolIconDictImpl { private static Logger logger = Logger.getLogger(ProtocolIconDictImpl.class); + private static ResourceManagementService resourcesService; + /** * A hash table containing the protocol icon in different sizes. */ @@ -83,8 +88,7 @@ public class ProtocolIconDictImpl * @return The image for the given identifier. */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconDictImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try { @@ -95,4 +99,21 @@ public class ProtocolIconDictImpl } return icon; } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = DictActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService)DictActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/dict/dict.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/dict/dict.provider.manifest.mf index ff0b0d2..b2e050c 100644 --- a/src/net/java/sip/communicator/impl/protocol/dict/dict.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/dict/dict.provider.manifest.mf @@ -6,6 +6,7 @@ Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.service.contactlist, net.java.sip.communicator.service.configuration, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.util, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/impl/protocol/gibberish/GibberishActivator.java b/src/net/java/sip/communicator/impl/protocol/gibberish/GibberishActivator.java index b353774..3fd95dd 100644 --- a/src/net/java/sip/communicator/impl/protocol/gibberish/GibberishActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/gibberish/GibberishActivator.java @@ -38,7 +38,7 @@ public class GibberishActivator /** * The currently valid bundle context. */ - private static BundleContext bundleContext = null; + static BundleContext bundleContext = null; /** diff --git a/src/net/java/sip/communicator/impl/protocol/gibberish/GibberishStatusEnum.java b/src/net/java/sip/communicator/impl/protocol/gibberish/GibberishStatusEnum.java index 153a043..00aa715 100644 --- a/src/net/java/sip/communicator/impl/protocol/gibberish/GibberishStatusEnum.java +++ b/src/net/java/sip/communicator/impl/protocol/gibberish/GibberishStatusEnum.java @@ -154,20 +154,7 @@ public class GibberishStatusEnum */ public static byte[] loadIcon(String imagePath) { - InputStream is = GibberishStatusEnum.class.getClassLoader() - .getResourceAsStream(imagePath); - - byte[] icon = null; - try - { - icon = new byte[is.available()]; - is.read(icon); - } - catch (IOException exc) - { - logger.error("Failed to load icon: " + imagePath, exc); - } - return icon; + return ProtocolIconGibberishImpl.loadIcon(imagePath); } } diff --git a/src/net/java/sip/communicator/impl/protocol/gibberish/ProtocolIconGibberishImpl.java b/src/net/java/sip/communicator/impl/protocol/gibberish/ProtocolIconGibberishImpl.java index 39e057d..0e0fed0 100644 --- a/src/net/java/sip/communicator/impl/protocol/gibberish/ProtocolIconGibberishImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/gibberish/ProtocolIconGibberishImpl.java @@ -6,19 +6,16 @@ */ package net.java.sip.communicator.impl.protocol.gibberish; -import java.awt.image.*; import java.io.*; -import java.net.*; import java.util.*; -import javax.imageio.*; -import javax.imageio.stream.*; - -import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.impl.gui.utils.ImageLoader.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * Reperesents the Gibberish protocol icon. Implements the <tt>ProtocolIcon</tt> * interface in order to provide a gibberish logo image in two different sizes. @@ -31,6 +28,8 @@ public class ProtocolIconGibberishImpl private static Logger logger = Logger.getLogger(ProtocolIconGibberishImpl.class); + private static ResourceManagementService resourcesService; + /** * A hash table containing the protocol icon in different sizes. */ @@ -85,8 +84,7 @@ public class ProtocolIconGibberishImpl * @return The image for the given identifier. */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconGibberishImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try { @@ -97,4 +95,21 @@ public class ProtocolIconGibberishImpl } return icon; } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = GibberishActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService)GibberishActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/gibberish/gibberish.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/gibberish/gibberish.provider.manifest.mf index 86b00cb..4bb0210 100644 --- a/src/net/java/sip/communicator/impl/protocol/gibberish/gibberish.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/gibberish/gibberish.provider.manifest.mf @@ -4,6 +4,7 @@ Bundle-Description: A bundle providing support for the Gibberish protocol. Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.util, diff --git a/src/net/java/sip/communicator/impl/protocol/icq/AimStatusEnum.java b/src/net/java/sip/communicator/impl/protocol/icq/AimStatusEnum.java new file mode 100644 index 0000000..ca92400 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/icq/AimStatusEnum.java @@ -0,0 +1,99 @@ +package net.java.sip.communicator.impl.protocol.icq; + +import java.io.*; +import java.util.*; + +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.*; + +/** + * An enumeration containing all status instances that MUST be supported by + * an implementation of the AIM (Oscar) protocol. Implementations may + * support other forms of PresenceStatus but they MUST ALL support those + * enumerated here. + * <p> + * For testing purposes, this class also provides a <tt>List</tt> containing + * all of the status fields. + * + * @author Emil Ivov + */ +public class AimStatusEnum + extends PresenceStatus +{ + + private static Logger logger = Logger.getLogger(AimStatusEnum.class); + + /** + * The Online AIM status. Indicate that the user is able and willing to + * communicate. + */ + public static final AimStatusEnum ONLINE + = new AimStatusEnum(65, "Online", + loadIcon("resources/images/protocol/aim/aim16x16-online.png")); + + /** + * The Invisible AIM status. Indicates that the user has connectivity even + * though it may appear otherwise to others, to whom she would appear to be + * offline. + */ + public static final AimStatusEnum INVISIBLE + = new AimStatusEnum(45, "Invisible", + loadIcon("resources/images/protocol/aim/aim16x16-invisible.png")); + + /** + * The Away AIM status. Indicates that the user has connectivity but might + * not be able to immediately act upon initiation of communication. + */ + public static final AimStatusEnum AWAY + = new AimStatusEnum(40, "Away", + loadIcon("resources/images/protocol/aim/aim16x16-away.png")); + + /** + * The Offline AIM status. Indicates the user does not seem to be connected + * to the AIM network or at least does not want us to know she is + */ + public static final AimStatusEnum OFFLINE + = new AimStatusEnum(0, "Offline", + loadIcon("resources/images/protocol/aim/aim16x16-offline.png")); + + /** + * The minimal set of states that any AIM implementation must support. + */ + public static final ArrayList aimStatusSet =new ArrayList(); + static{ + aimStatusSet.add(ONLINE); + aimStatusSet.add(INVISIBLE); + aimStatusSet.add(AWAY); + aimStatusSet.add(OFFLINE); + } + + /** + * Creates a status with the specified connectivity coeff, name and icon. + * @param status the connectivity coefficient for the specified status + * @param statusName String + * @param statusIcon the icon associated with this status + */ + protected AimStatusEnum(int status, String statusName, byte[] statusIcon) + { + super(status, statusName, statusIcon); + } + + /** + * Loads an image from a given image path. + * @param imagePath The identifier of the image. + * @return The image for the given identifier. + */ + public static byte[] loadIcon(String imagePath) { + InputStream is = AimStatusEnum.class.getClassLoader() + .getResourceAsStream(imagePath); + + byte[] icon = null; + try { + icon = new byte[is.available()]; + is.read(icon); + } catch (IOException e) { + logger.error("Failed to load icon: " + imagePath, e); + } + return icon; + } +} diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ContactIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ContactIcqImpl.java index a8d7d3f..11a990b 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ContactIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ContactIcqImpl.java @@ -4,7 +4,6 @@ import java.util.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.icqconstants.*; -import net.java.sip.communicator.service.protocol.aimconstants.*; import net.kano.joustsim.oscar.oscar.service.ssi.*; /** diff --git a/src/net/java/sip/communicator/impl/protocol/icq/IcqActivator.java b/src/net/java/sip/communicator/impl/protocol/icq/IcqActivator.java index 255ebeb..5ecfa38 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/IcqActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/IcqActivator.java @@ -17,7 +17,7 @@ public class IcqActivator { private ServiceRegistration icqPpFactoryServReg = null; private ServiceRegistration aimPpFactoryServReg = null; - private static BundleContext bundleContext = null; + static BundleContext bundleContext = null; private static ConfigurationService configurationService = null; private static ProtocolProviderFactoryIcqImpl icqProviderFactory = null; diff --git a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java index d58fe3a..bbd7a79 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java @@ -20,7 +20,6 @@ import net.kano.joscar.snaccmd.icq.*; import net.kano.joustsim.*; import net.kano.joustsim.oscar.oscar.service.icbm.*; import net.java.sip.communicator.service.protocol.icqconstants.*; -import net.java.sip.communicator.service.protocol.aimconstants.*; /** * A straightforward implementation of the basic instant messaging operation diff --git a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java index 7c63a7a..d11ec29 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java @@ -12,7 +12,6 @@ import java.util.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.event.*; import net.java.sip.communicator.service.protocol.icqconstants.*; -import net.java.sip.communicator.service.protocol.aimconstants.*; import net.java.sip.communicator.service.protocol.AuthorizationResponse.*; import net.java.sip.communicator.util.*; import net.kano.joscar.*; diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolIconAimImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolIconAimImpl.java index 0c56539..5a7b61c 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolIconAimImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolIconAimImpl.java @@ -10,7 +10,9 @@ import java.io.*; import java.util.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; /** * Reperesents the Aim protocol icon. Implements the <tt>ProtocolIcon</tt> @@ -23,6 +25,8 @@ public class ProtocolIconAimImpl { private static Logger logger = Logger.getLogger(ProtocolIconAimImpl.class); + private static ResourceManagementService resourcesService; + /** * A hash table containing the protocol icon in different sizes. */ @@ -78,8 +82,7 @@ public class ProtocolIconAimImpl */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconAimImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try { @@ -90,4 +93,21 @@ public class ProtocolIconAimImpl } return icon; } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = IcqActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService)IcqActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolIconIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolIconIcqImpl.java index d75a75a..2ed212d 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolIconIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolIconIcqImpl.java @@ -10,7 +10,9 @@ import java.io.*; import java.util.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; /** * Reperesents the Icq protocol icon. Implements the <tt>ProtocolIcon</tt> @@ -23,6 +25,8 @@ public class ProtocolIconIcqImpl { private static Logger logger = Logger.getLogger(ProtocolIconIcqImpl.class); + private static ResourceManagementService resourcesService; + /** * A hash table containing the protocol icon in different sizes. */ @@ -78,8 +82,7 @@ public class ProtocolIconIcqImpl */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconIcqImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try { @@ -90,4 +93,21 @@ public class ProtocolIconIcqImpl } return icon; } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = IcqActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService)IcqActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/icq/icq.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/icq/icq.provider.manifest.mf index 36574bf..a0fda28 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/icq.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/icq/icq.provider.manifest.mf @@ -7,6 +7,7 @@ Import-Package: org.osgi.framework, javax.net, sun.misc, net.java.sip.communicator.service.configuration, + net.java.sip.communicator.service.resources, net.java.sip.communicator.util, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/impl/protocol/irc/ProtocolIconIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/ProtocolIconIrcImpl.java index bd753df..e653a66 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/ProtocolIconIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/ProtocolIconIrcImpl.java @@ -10,8 +10,11 @@ import java.io.*; import java.util.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * Represents the IRC protocol icon. Implements the <tt>ProtocolIcon</tt> * interface in order to provide an IRC icon image in two different sizes. @@ -24,6 +27,8 @@ public class ProtocolIconIrcImpl { private static Logger logger = Logger.getLogger(ProtocolIconIrcImpl.class); + private static ResourceManagementService resourcesService; + /** * A hash table containing the protocol icon in different sizes. */ @@ -79,8 +84,7 @@ public class ProtocolIconIrcImpl */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconIrcImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try { @@ -91,4 +95,21 @@ public class ProtocolIconIrcImpl } return icon; } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = IrcActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService)IrcActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } }
\ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf index 7a1bf0b..b11d55b 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/irc/irc.provider.manifest.mf @@ -6,6 +6,7 @@ Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, + net.java.sip.communicator.service.resources, net.java.sip.communicator.util, net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.protocol.event
\ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/JabberActivator.java b/src/net/java/sip/communicator/impl/protocol/jabber/JabberActivator.java index f4cff4d..5e318e6 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/JabberActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/JabberActivator.java @@ -31,7 +31,7 @@ public class JabberActivator /** * Bundle context from OSGi. */ - private static BundleContext bundleContext = null; + static BundleContext bundleContext = null; /** * Configuration service. diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolIconJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolIconJabberImpl.java index 5480b3f..d9e17d2 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolIconJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolIconJabberImpl.java @@ -10,9 +10,11 @@ import java.io.*; import java.util.*; import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.jabberconstants.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * Reperesents the Jabber protocol icon. Implements the <tt>ProtocolIcon</tt> * interface in order to provide a jabber icon image in two different sizes. @@ -30,6 +32,8 @@ public class ProtocolIconJabberImpl */ private final String iconPath; + private static ResourceManagementService resourcesService; + /** * A hash table containing the protocol icon in different sizes. */ @@ -93,9 +97,33 @@ public class ProtocolIconJabberImpl * @param imagePath The identifier of the image. * @return The image for the given identifier. */ - public static byte[] loadIcon(String imagePath) + public static byte[] loadIcon(String imagePath) { + InputStream is = getResources().getImageInputStreamForPath(imagePath); + + byte[] icon = null; + try { + icon = new byte[is.available()]; + is.read(icon); + } catch (IOException e) { + logger.error("Failed to load icon: " + imagePath, e); + } + return icon; + } + + public static ResourceManagementService getResources() { - return JabberStatusEnum.loadIcon(imagePath, - ProtocolIconJabberImpl.class); - } + if (resourcesService == null) + { + ServiceReference serviceReference = JabberActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService)JabberActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/jabber.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/jabber/jabber.provider.manifest.mf index 18388ff..780867b 100755 --- a/src/net/java/sip/communicator/impl/protocol/jabber/jabber.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/jabber/jabber.provider.manifest.mf @@ -19,6 +19,7 @@ Import-Package: org.osgi.framework, org.jivesoftware.smackx.jingle.packet, org.jivesoftware.smackx.jingle.provider, net.java.sip.communicator.service.configuration, + net.java.sip.communicator.service.resources, net.java.sip.communicator.util, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/impl/protocol/msn/MsnActivator.java b/src/net/java/sip/communicator/impl/protocol/msn/MsnActivator.java index fc144a0..7dbb079 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/MsnActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/MsnActivator.java @@ -11,6 +11,7 @@ import java.util.*; import org.osgi.framework.*; import net.java.sip.communicator.service.configuration.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; /** * Loads the MSN provider factory and registers it with service in the OSGI @@ -26,6 +27,8 @@ public class MsnActivator private static ConfigurationService configurationService = null; private static ProtocolProviderFactoryMsnImpl msnProviderFactory = null; + + private static ResourceManagementService resourcesService; /** * Called when this bundle is started so the Framework can perform the @@ -112,4 +115,21 @@ public class MsnActivator msnProviderFactory.stop(); msnPpFactoryServReg.unregister(); } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService) bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java index 284a16f..bf07574 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java @@ -349,7 +349,8 @@ public class OperationSetBasicInstantMessagingMsnImpl } Message newMailMessage = new MessageMsnImpl( - MessageFormat.format(Resources.getString("newMail"), + MessageFormat.format( + MsnActivator.getResources().getI18NString("newMail"), new Object[]{message.getFrom(), message.getFromAddr(), subject}), diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ProtocolIconMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ProtocolIconMsnImpl.java index fbeabc1..a6f6826 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/ProtocolIconMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/ProtocolIconMsnImpl.java @@ -77,8 +77,8 @@ public class ProtocolIconMsnImpl * @return The image for the given identifier. */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconMsnImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = + MsnActivator.getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try { diff --git a/src/net/java/sip/communicator/impl/protocol/msn/Resources.java b/src/net/java/sip/communicator/impl/protocol/msn/Resources.java deleted file mode 100644 index 7077827..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/Resources.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ - -package net.java.sip.communicator.impl.protocol.msn; - -import java.io.*; -import java.util.*; - -import net.java.sip.communicator.util.*; - -/** - * The Resources class manages the access to the internationalization - * properties files. - * - * @author Yana Stamcheva - */ -public class Resources -{ - - /** - * Logger for this class. - */ - private static Logger log = Logger.getLogger(Resources.class); - - /** - * Name of the bundle were we will search for localized string. - */ - private static final String BUNDLE_NAME - = "net.java.sip.communicator.impl.protocol.msn.resources"; - - /** - * Bundle which handle access to localized resources. - */ - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - .getBundle(BUNDLE_NAME); - - /** - * Returns an internationalized string corresponding to the given key. - * - * @param key The key of the string. - * - * @return An internationalized string corresponding to the given key. - */ - public static String getString(String key) - { - try - { - return RESOURCE_BUNDLE.getString(key); - - } - catch (MissingResourceException e) { - - return '!' + key + '!'; - } - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/msn.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/msn/msn.provider.manifest.mf index 7eecccd..75d1cd6 100755 --- a/src/net/java/sip/communicator/impl/protocol/msn/msn.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/msn/msn.provider.manifest.mf @@ -12,6 +12,7 @@ Import-Package: org.osgi.framework, org.xml.sax, sun.security.action, net.java.sip.communicator.service.configuration, + net.java.sip.communicator.service.resources, net.java.sip.communicator.util, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/impl/protocol/msn/resources.properties b/src/net/java/sip/communicator/impl/protocol/msn/resources.properties deleted file mode 100644 index fe2231a..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/resources.properties +++ /dev/null @@ -1 +0,0 @@ -newMail=You have one new Mail from {0} ({1}) with subject: {2} diff --git a/src/net/java/sip/communicator/impl/protocol/rss/ProtocolIconRssImpl.java b/src/net/java/sip/communicator/impl/protocol/rss/ProtocolIconRssImpl.java index 2133dbd..a08551f 100644 --- a/src/net/java/sip/communicator/impl/protocol/rss/ProtocolIconRssImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/rss/ProtocolIconRssImpl.java @@ -6,18 +6,14 @@ */ package net.java.sip.communicator.impl.protocol.rss; -import java.awt.image.*; import java.io.*; -import java.net.*; import java.util.*; -import javax.imageio.*; -import javax.imageio.stream.*; - -import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.impl.gui.utils.ImageLoader.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.ServiceReference; /** * Reperesents the Rss protocol icon. Implements the <tt>ProtocolIcon</tt> @@ -31,6 +27,8 @@ public class ProtocolIconRssImpl private static Logger logger = Logger.getLogger(ProtocolIconRssImpl.class); + private static ResourceManagementService resourcesService; + /** * A hash table containing the protocol icon in different sizes. */ @@ -87,8 +85,7 @@ public class ProtocolIconRssImpl */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconRssImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try { @@ -99,4 +96,21 @@ public class ProtocolIconRssImpl } return icon; } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = RssActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService)RssActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/rss/RssActivator.java b/src/net/java/sip/communicator/impl/protocol/rss/RssActivator.java index 2c9a391..77b1bcf 100644 --- a/src/net/java/sip/communicator/impl/protocol/rss/RssActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/rss/RssActivator.java @@ -39,7 +39,7 @@ public class RssActivator /** * The currently valid bundle context. */ - private static BundleContext bundleContext = null; + static BundleContext bundleContext = null; /** diff --git a/src/net/java/sip/communicator/impl/protocol/rss/RssStatusEnum.java b/src/net/java/sip/communicator/impl/protocol/rss/RssStatusEnum.java index 263241a..e374345 100644 --- a/src/net/java/sip/communicator/impl/protocol/rss/RssStatusEnum.java +++ b/src/net/java/sip/communicator/impl/protocol/rss/RssStatusEnum.java @@ -85,20 +85,7 @@ public class RssStatusEnum */ public static byte[] loadIcon(String imagePath) { - InputStream is = RssStatusEnum.class.getClassLoader() - .getResourceAsStream(imagePath); - - byte[] icon = null; - try - { - icon = new byte[is.available()]; - is.read(icon); - } - catch (IOException exc) - { - logger.error("Failed to load icon: " + imagePath, exc); - } - return icon; + return ProtocolIconRssImpl.loadIcon(imagePath); } } diff --git a/src/net/java/sip/communicator/impl/protocol/rss/rss.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/rss/rss.provider.manifest.mf index e1c5bf6..baebfc5 100644 --- a/src/net/java/sip/communicator/impl/protocol/rss/rss.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/rss/rss.provider.manifest.mf @@ -11,6 +11,7 @@ Import-Package: org.osgi.framework, javax.xml.parsers, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, + net.java.sip.communicator.service.resources, net.java.sip.communicator.util, net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.protocol.event, diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetSmsMessagingSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetSmsMessagingSipImpl.java new file mode 100644 index 0000000..bafffc7 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetSmsMessagingSipImpl.java @@ -0,0 +1,728 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.sip; + +import java.io.*; +import java.net.*; +import java.text.*; +import java.util.*; +import javax.sip.*; +import javax.sip.address.*; +import javax.sip.header.*; +import javax.sip.message.*; + +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.protocol.Message; +import net.java.sip.communicator.service.protocol.event.*; +import net.java.sip.communicator.util.*; + +/** + * A straightforward implementation of the basic instant messaging operation + * set. + * + * @author Benoit Pradelle + */ +public class OperationSetSmsMessagingSipImpl + implements OperationSetSmsMessaging, SipMessageProcessor +{ + private static final Logger logger = + Logger.getLogger(OperationSetBasicInstantMessagingSipImpl.class); + + /** + * A list of listeners registered for message events. + */ + private Vector messageListeners = new Vector(); + + /** + * The provider that created us. + */ + private ProtocolProviderServiceSipImpl sipProvider = null; + + /** + * A reference to the persistent presence operation set that we use + * to match incoming messages to <tt>Contact</tt>s and vice versa. + */ + private OperationSetPresenceSipImpl opSetPersPresence = null; + + /** + * A reference to the persistent presence operation set that we use + * to match incoming messages to <tt>Contact</tt>s and vice versa. + */ + private OperationSetBasicInstantMessagingSipImpl opSetBasicIm = null; + + private static final String SMS_OUTGOING_MESSAGE_HEADER = "P-Send-SMS"; + private static final String[] SMS_OUTGOING_MESSAGE_HEADER_VALUES = + new String[]{"simple", "confirmation-request", "premium"}; + private static final String SMS_OUTGOING_DEFAULT_MESSAGE_HEADER_VALUE = + SMS_OUTGOING_MESSAGE_HEADER_VALUES[0]; + private static final String SMS_RECEIVED_MESSAGE_HEADER = "P-Received-SMS"; + + /** + * Creates an instance of this operation set. + * @param provider a ref to the <tt>ProtocolProviderServiceImpl</tt> + * that created us and that we'll use for retrieving the underlying aim + * connection. + */ + OperationSetSmsMessagingSipImpl( + ProtocolProviderServiceSipImpl provider, + OperationSetBasicInstantMessagingSipImpl opSetBasicIm) + { + this.sipProvider = provider; + + provider.addRegistrationStateChangeListener(new + RegistrationStateListener()); + this.opSetBasicIm = opSetBasicIm; + opSetBasicIm.addMessageProcessor(this); + } + + /** + * Registers a MessageListener with this operation set so that it gets + * notifications of successful message delivery, failure or reception of + * incoming messages.. + * + * @param listener the <tt>MessageListener</tt> to register. + */ + public void addMessageListener(MessageListener listener) + { + synchronized (this.messageListeners) + { + if (!this.messageListeners.contains(listener)) + { + this.messageListeners.add(listener); + } + } + } + + /** + * Unregisters <tt>listener</tt> so that it won't receive any further + * notifications upon successful message delivery, failure or reception of + * incoming messages.. + * + * @param listener the <tt>MessageListener</tt> to unregister. + */ + public void removeMessageListener(MessageListener listener) + { + synchronized (this.messageListeners) + { + this.messageListeners.remove(listener); + } + } + + /** + * Create a Message instance for sending arbitrary MIME-encoding content. + * + * @param content content value + * @param contentType the MIME-type for <tt>content</tt> + * @param contentEncoding encoding used for <tt>content</tt> + * @return the newly created message. + */ + public Message createMessage(byte[] content, String contentType, + String contentEncoding) + { + return opSetBasicIm.createMessage( + content, contentType, contentEncoding, null); + } + + /** + * Create a Message instance for sending a simple text messages with + * default (text/plain) content type and encoding. + * + * @param messageText the string content of the message. + * @return Message the newly created message + */ + public Message createMessage(String messageText) + { + return opSetBasicIm.createMessage(messageText); + } + + /** + * Determines whether the protocol supports the supplied content type + * + * @param contentType the type we want to check + * @return <tt>true</tt> if the protocol supports it and + * <tt>false</tt> otherwise. + */ + public boolean isContentTypeSupported(String contentType) + { + if(contentType.equals(DEFAULT_MIME_TYPE)) + return true; + else + return false; + } + + /** + * Sends the <tt>message</tt> to the destination indicated by the + * <tt>to</tt> contact. + * + * @param to the destination to send <tt>message</tt> to + * @param message the <tt>Message</tt> to send. + * @throws java.lang.IllegalStateException if the underlying stack is + * not registered and initialized. + * @throws java.lang.IllegalArgumentException if <tt>to</tt> is not an + * instance of ContactImpl. + */ + public void sendSmsMessage(String to, Message message) + throws IllegalStateException, IllegalArgumentException + { + ContactSipImpl volatileContact = + (ContactSipImpl)opSetPersPresence.findContactByID(to); + + // check if contact already exist + if(volatileContact == null) + volatileContact = opSetPersPresence.createVolatileContact(to); + + sendSmsMessage(volatileContact, message); + } + + /** + * Sends the <tt>message</tt> to the destination indicated by the + * <tt>to</tt> contact. + * + * @param to the <tt>Contact</tt> to send <tt>message</tt> to + * @param message the <tt>Message</tt> to send. + * @throws java.lang.IllegalStateException if the underlying stack is + * not registered and initialized. + * @throws java.lang.IllegalArgumentException if <tt>to</tt> is not an + * instance of ContactImpl. + */ + public void sendSmsMessage(Contact to, Message message) + throws IllegalStateException, IllegalArgumentException + { + if (! (to instanceof ContactSipImpl)) + throw new IllegalArgumentException( + "The specified contact is not a Sip contact." + + to); + + assertConnected(); + + // create the message + Request mes; + try + { + mes = opSetBasicIm.createMessage(to, message); + } + catch (OperationFailedException ex) + { + logger.error( + "Failed to create the message." + , ex); + + MessageDeliveryFailedEvent evt = + new MessageDeliveryFailedEvent( + message, + to, + MessageDeliveryFailedEvent.INTERNAL_ERROR, + new Date()); + fireMessageEvent(evt); + return; + } + + Header smsHeader = null; + try + { + smsHeader = this.sipProvider.getHeaderFactory() + .createHeader(SMS_OUTGOING_MESSAGE_HEADER, + SMS_OUTGOING_DEFAULT_MESSAGE_HEADER_VALUE); + } + catch (ParseException exc) + { + //shouldn't happen + logger.error( + "An unexpected error occurred while" + + "constructing the SmsHeadder", exc); + + MessageDeliveryFailedEvent evt = + new MessageDeliveryFailedEvent( + message, + to, + MessageDeliveryFailedEvent.INTERNAL_ERROR, + new Date()); + fireMessageEvent(evt); + return; + } + + mes.addHeader(smsHeader); + + try + { + opSetBasicIm.sendRequestMessage(mes, to, message); + } + catch(TransactionUnavailableException ex) + { + logger.error( + "Failed to create messageTransaction.\n" + + "This is most probably a network connection error." + , ex); + + MessageDeliveryFailedEvent evt = + new MessageDeliveryFailedEvent( + message, + to, + MessageDeliveryFailedEvent.NETWORK_FAILURE, + new Date()); + fireMessageEvent(evt); + return; + } + catch(SipException ex) + { + logger.error( + "Failed to send the message." + , ex); + + MessageDeliveryFailedEvent evt = + new MessageDeliveryFailedEvent( + message, + to, + MessageDeliveryFailedEvent.INTERNAL_ERROR, + new Date()); + fireMessageEvent(evt); + return; + } + } + + /** + * Utility method throwing an exception if the stack is not properly + * initialized. + * @throws java.lang.IllegalStateException if the underlying stack is + * not registered and initialized. + */ + private void assertConnected() + throws IllegalStateException + { + if (this.sipProvider == null) + throw new IllegalStateException( + "The provider must be non-null and signed on the " + + "service before being able to communicate."); + if (!this.sipProvider.isRegistered()) + throw new IllegalStateException( + "The provider must be signed on the service before " + + "being able to communicate."); + } + + /** + * Our listener that will tell us when we're registered to + */ + private class RegistrationStateListener + implements RegistrationStateChangeListener + { + /** + * The method is called by a ProtocolProvider implementation whenever + * a change in the registration state of the corresponding provider had + * occurred. + * @param evt ProviderStatusChangeEvent the event describing the status + * change. + */ + public void registrationStateChanged(RegistrationStateChangeEvent evt) + { + logger.debug("The provider changed state from: " + + evt.getOldState() + + " to: " + evt.getNewState()); + + if (evt.getNewState() == RegistrationState.REGISTERED) + { + opSetPersPresence = (OperationSetPresenceSipImpl) + sipProvider.getSupportedOperationSets() + .get(OperationSetPersistentPresence.class.getName()); + } + } + } + + /** + * Delivers the specified event to all registered message listeners. + * @param evt the <tt>EventObject</tt> that we'd like delivered to all + * registered message listeners. + */ + private void fireMessageEvent(EventObject evt) + { + Iterator listeners = null; + synchronized (this.messageListeners) + { + listeners = new ArrayList(this.messageListeners).iterator(); + } + + while (listeners.hasNext()) + { + MessageListener listener + = (MessageListener) listeners.next(); + + if (evt instanceof MessageDeliveredEvent) + { + listener.messageDelivered( (MessageDeliveredEvent) evt); + } + else if (evt instanceof MessageReceivedEvent) + { + listener.messageReceived( (MessageReceivedEvent) evt); + } + else if (evt instanceof MessageDeliveryFailedEvent) + { + listener.messageDeliveryFailed( + (MessageDeliveryFailedEvent) evt); + } + } + } + + /** + * Process the incoming sip messages + * @param requestEvent the incoming event holding the message + * @return whether this message needs further processing(true) or no(false) + */ + public boolean processMessage(RequestEvent requestEvent) + { + // get the content + String content = null; + + try + { + Request req = requestEvent.getRequest(); + + // ignore messages which are not sms and continue processing + if(req.getHeader(SMS_RECEIVED_MESSAGE_HEADER) == null) + return true; + + content = new String(req.getRawContent(), getCharset(req)); + } + catch (UnsupportedEncodingException ex) + { + logger.debug("failed to convert the message charset"); + content = new String(requestEvent.getRequest().getRawContent()); + } + + // who sent this request ? + FromHeader fromHeader = (FromHeader) + requestEvent.getRequest().getHeader(FromHeader.NAME); + + if (fromHeader == null) + { + logger.error("received a request without a from header"); + // no further processing + return false; + } + + Contact from = resolveContact( + fromHeader.getAddress().getURI().toString()); + Message newMessage = createMessage(content); + + if (from == null) { + logger.debug("received a message from an unknown contact: " + + fromHeader.getAddress().getURI().toString()); + //create the volatile contact + from = opSetPersPresence + .createVolatileContact(fromHeader.getAddress().getURI() + .toString().substring(4)); + } + + // answer ok + try + { + Response ok = sipProvider.getMessageFactory() + .createResponse(Response.OK, requestEvent.getRequest()); + SipProvider jainSipProvider = (SipProvider) requestEvent. + getSource(); + jainSipProvider.getNewServerTransaction( + requestEvent.getRequest()).sendResponse(ok); + } + catch (ParseException exc) + { + logger.error("failed to build the response", exc); + } + catch (SipException exc) + { + logger.error("failed to send the response : " + + exc.getMessage(), + exc); + } + catch (InvalidArgumentException exc) + { + logger.debug("Invalid argument for createResponse : " + + exc.getMessage(), + exc); + } + + // fire an event + MessageReceivedEvent msgReceivedEvt + = new MessageReceivedEvent( + newMessage, from, new Date(), + MessageReceivedEvent.SMS_MESSAGE_RECEIVED); + fireMessageEvent(msgReceivedEvt); + + // no further processing + return false; + } + + /** + * Process the responses of sent messages + * @param responseEvent the incoming event holding the response + * @return whether this message needs further processing(true) or no(false) + */ + public boolean processResponse(ResponseEvent responseEvent, Map sentMsg) + { + Request req = responseEvent.getClientTransaction().getRequest(); + + // ignore messages which are not sms and continue processing + if(req.getHeader(SMS_OUTGOING_MESSAGE_HEADER) == null) + return true; + + int status = responseEvent.getResponse().getStatusCode(); + + // content of the response + String content = null; + + try + { + content = new String(req.getRawContent(), getCharset(req)); + } + catch (UnsupportedEncodingException exc) + { + logger.debug("failed to convert the message charset", exc); + content = new String(req.getRawContent()); + } + + // to who did we send the original message ? + ToHeader toHeader = (ToHeader) + req.getHeader(ToHeader.NAME); + + if (toHeader == null) + { + // should never happen + logger.error("send a request without a to header"); + return false; + } + + Contact to = resolveContact(toHeader.getAddress() + .getURI().toString()); + + if (to == null) { + logger.error( + "Error received a response from an unknown contact : " + + toHeader.getAddress().getURI().toString() + " : " + + responseEvent.getResponse().getReasonPhrase()); + + // error for delivering the message + MessageDeliveryFailedEvent evt = + new MessageDeliveryFailedEvent( + // we don't know what message it concerns + createMessage(content), + to, + MessageDeliveryFailedEvent.INTERNAL_ERROR, + new Date()); + fireMessageEvent(evt); + + return false; + } + + // we retrieve the original message + String key = ((CallIdHeader)req.getHeader(CallIdHeader.NAME)) + .getCallId(); + + Message newMessage = (Message) sentMsg.get(key); + + if (newMessage == null) { + // should never happen + logger.error("Couldn't find the message sent"); + + // error for delivering the message + MessageDeliveryFailedEvent evt = + new MessageDeliveryFailedEvent( + // we don't know what message it is + createMessage(content), + to, + MessageDeliveryFailedEvent.INTERNAL_ERROR, + new Date()); + fireMessageEvent(evt); + + return false; + } + + // status 401/407 = proxy authentification + if (status >= 400 && status != 401 && status != 407) + { + logger.info( + "Error received from the network : " + + responseEvent.getResponse().getReasonPhrase()); + + // error for delivering the message + MessageDeliveryFailedEvent evt = + new MessageDeliveryFailedEvent( + newMessage, + to, + MessageDeliveryFailedEvent.NETWORK_FAILURE, + new Date(), + responseEvent.getResponse().getReasonPhrase()); + fireMessageEvent(evt); + sentMsg.remove(key); + + return false; + } + else if (status == 401 || status == 407) + { + return true; + } + else if (status >= 200) + { + logger.debug( + "Ack received from the network : " + + responseEvent.getResponse().getReasonPhrase()); + + // we delivered the message + MessageDeliveredEvent msgDeliveredEvt + = new MessageDeliveredEvent( + newMessage, to, new Date()); + + fireMessageEvent(msgDeliveredEvt); + + // we don't need this message anymore + sentMsg.remove(key); + + return false; + } + + return false; + } + + public boolean processTimeout(TimeoutEvent timeoutEvent, Map sentMessages) + { + // this is normaly handled by the SIP stack + logger.error("Timeout event thrown : " + timeoutEvent.toString()); + + if (timeoutEvent.isServerTransaction()) + { + logger.warn("The sender has probably not received our OK"); + return false; + } + + Request req = timeoutEvent.getClientTransaction().getRequest(); + + // ignore messages which are not sms and continue processing + if(req.getHeader(SMS_OUTGOING_MESSAGE_HEADER) == null) + return true; + + // get the content + String content = null; + try + { + content = new String(req.getRawContent(), getCharset(req)); + } + catch (UnsupportedEncodingException ex) + { + logger.warn("failed to convert the message charset", ex); + content = new String(req.getRawContent()); + } + + // to who this request has been sent ? + ToHeader toHeader = (ToHeader) req.getHeader(ToHeader.NAME); + + if (toHeader == null) + { + logger.error("received a request without a to header"); + return false; + } + + Contact to = resolveContact( + toHeader.getAddress().getURI().toString()); + + Message failedMessage = null; + + if (to == null) { + logger.error( + "timeout on a message sent to an unknown contact : " + + toHeader.getAddress().getURI().toString()); + + //we don't know what message it concerns, so create a new + //one + failedMessage = createMessage(content); + } + else + { + // try to retrieve the original message + String key = ((CallIdHeader)req.getHeader(CallIdHeader.NAME)) + .getCallId(); + failedMessage = (Message) sentMessages.get(key); + + if (failedMessage == null) + { + // should never happen + logger.error("Couldn't find the sent message."); + + // we don't know what the message is so create a new one + //based on the content of the failed request. + failedMessage = createMessage(content); + } + } + + // error for delivering the message + MessageDeliveryFailedEvent evt = + new MessageDeliveryFailedEvent( + // we don't know what message it concerns + failedMessage, + to, + MessageDeliveryFailedEvent.INTERNAL_ERROR, + new Date()); + fireMessageEvent(evt); + + return false; + } + + /** + * Try to find a charset in a MESSAGE request for the + * text content. If no charset is defined, the default charset + * for text messages is returned. + * + * @param req the MESSAGE request in which to look for a charset + * @return defined charset in the request or DEFAULT_MIME_ENCODING + * if no charset is specified + */ + private String getCharset(Request req) + { + String charset = null; + Header contentTypeHeader = req.getHeader(ContentTypeHeader.NAME); + if (contentTypeHeader instanceof ContentTypeHeader) + charset = ((ContentTypeHeader) contentTypeHeader) + .getParameter("charset"); + if (charset == null) + charset = DEFAULT_MIME_ENCODING; + return charset; + } + + /** + * Try to find a contact registered using a string to identify him. + * + * @param contactID A string with which the contact may have + * been registered + * @return A valid contact if it has been found, null otherwise + */ + private Contact resolveContact(String contactID) { + Contact res = opSetPersPresence.findContactByID(contactID); + + if (res == null) { + // we try to resolve the conflict by removing "sip:" from the id + if (contactID.startsWith("sip:")) { + res = opSetPersPresence.findContactByID( + contactID.substring(4)); + } + + if (res == null) { + // we try to remove the part after the '@' + if (contactID.indexOf('@') > -1) { + res = opSetPersPresence.findContactByID( + contactID.substring(0, + contactID.indexOf('@'))); + + if (res == null) { + // try the same thing without sip: + if (contactID.startsWith("sip:")) { + res = opSetPersPresence.findContactByID( + contactID.substring(4, + contactID.indexOf('@'))); + } + } + } + } + } + + return res; + } +} diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolIconSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolIconSipImpl.java index 8084b1a..96c0031 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolIconSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolIconSipImpl.java @@ -10,8 +10,11 @@ import java.io.*; import java.util.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * Represents the Sip protocol icon. Implements the <tt>ProtocolIcon</tt> * interface in order to provide an sip icon image in two different sizes. @@ -29,6 +32,8 @@ public class ProtocolIconSipImpl * A hash table containing the protocol icon in different sizes. */ private Hashtable iconsTable = new Hashtable(); + + private static ResourceManagementService resourcesService; /** * Creates an instance of this class by passing to it the path, where all @@ -101,8 +106,7 @@ public class ProtocolIconSipImpl */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconSipImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try @@ -116,4 +120,21 @@ public class ProtocolIconSipImpl } return icon; } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = SipActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService)SipActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipActivator.java b/src/net/java/sip/communicator/impl/protocol/sip/SipActivator.java index 4452bdc..192536a 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/SipActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipActivator.java @@ -26,7 +26,7 @@ public class SipActivator private Logger logger = Logger.getLogger(SipActivator.class.getName()); private ServiceRegistration sipPpFactoryServReg = null; - private static BundleContext bundleContext = null; + static BundleContext bundleContext = null; private static ConfigurationService configurationService = null; private static NetworkAddressManagerService networkAddressManagerService = null; diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipStatusEnum.java b/src/net/java/sip/communicator/impl/protocol/sip/SipStatusEnum.java index db5b549..13ffece 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/SipStatusEnum.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipStatusEnum.java @@ -187,20 +187,7 @@ public class SipStatusEnum */ public static byte[] loadIcon(String imagePath) { - InputStream is = SipStatusEnum.class.getClassLoader() - .getResourceAsStream(imagePath); - - byte[] icon = null; - try - { - icon = new byte[is.available()]; - is.read(icon); - } - catch (IOException exc) - { - logger.error("Failed to load icon: " + imagePath, exc); - } - return icon; + return ProtocolIconSipImpl.loadIcon(imagePath); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/sip/sip.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/sip/sip.provider.manifest.mf index a2ef9a4..8408124 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/sip.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/sip/sip.provider.manifest.mf @@ -9,6 +9,7 @@ Import-Package: org.osgi.framework, net.java.sip.communicator.util, net.java.sip.communicator.util.xml, net.java.sip.communicator.service.configuration.event, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.protocol.event, net.java.sip.communicator.service.netaddr, diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/ContactSSHImpl.java b/src/net/java/sip/communicator/impl/protocol/ssh/ContactSSHImpl.java index a4859ac..55d5f73 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/ContactSSHImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/ssh/ContactSSHImpl.java @@ -33,8 +33,8 @@ public class ContactSSHImpl /** * This acts as a seperator between details stored in persistent data */ - private final String detailsSeperator = Resources - .getString("detailsSeperator"); + private final String detailsSeperator = + Resources.getString("detailsSeperator"); /** * The identifier for SSH Stack diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/ProtocolIconSSHImpl.java b/src/net/java/sip/communicator/impl/protocol/ssh/ProtocolIconSSHImpl.java index 4be9e27..5dca388 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/ProtocolIconSSHImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/ssh/ProtocolIconSSHImpl.java @@ -87,8 +87,8 @@ public class ProtocolIconSSHImpl */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconSSHImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = + SSHActivator.getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try { diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/ProtocolProviderServiceSSHImpl.java b/src/net/java/sip/communicator/impl/protocol/ssh/ProtocolProviderServiceSSHImpl.java index 428ffc9..08eb57b 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/ProtocolProviderServiceSSHImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/ssh/ProtocolProviderServiceSSHImpl.java @@ -49,7 +49,8 @@ public class ProtocolProviderServiceSSHImpl * The test command given after each command to determine the reply length * of the command */ - private final String testCommand = Resources.getString("testCommand"); + private final String testCommand = + Resources.getString("testCommand"); /** * A reference to the protocol provider of UIService diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/Resources.java b/src/net/java/sip/communicator/impl/protocol/ssh/Resources.java index 6209e5e..59a29ae 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/Resources.java +++ b/src/net/java/sip/communicator/impl/protocol/ssh/Resources.java @@ -13,7 +13,6 @@ package net.java.sip.communicator.impl.protocol.ssh; import java.io.*; -import java.util.*; import net.java.sip.communicator.util.*; @@ -25,13 +24,7 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - private static final String BUNDLE_NAME - = "net.java.sip.communicator.impl.protocol.ssh.resources"; - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - .getBundle(BUNDLE_NAME); - - public static ImageID SSH_LOGO = new ImageID("protocolIcon"); + public static ImageID SSH_LOGO = new ImageID("protocolIconSsh"); /** * Returns an string corresponding to the given key. @@ -42,15 +35,7 @@ public class Resources */ public static String getString(String key) { - try - { - return RESOURCE_BUNDLE.getString(key); - - } - catch (MissingResourceException exc) - { - return '!' + key + '!'; - } + return SSHActivator.getResources().getI18NString(key); } /** @@ -60,15 +45,12 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image= null; + byte[] image = null; InputStream inputStream; - - String path = Resources.getString(imageID.getId()); - try { - inputStream = Resources.class.getClassLoader() - .getResourceAsStream(path); + inputStream = + SSHActivator.getResources().getImageInputStream(imageID.getId()); image = new byte[inputStream.available()]; @@ -76,7 +58,7 @@ public class Resources } catch (IOException exc) { - log.error("Failed to load image:" + path, exc); + log.error("Failed to load image:" + imageID.getId(), exc); } return image; diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/SSHActivator.java b/src/net/java/sip/communicator/impl/protocol/ssh/SSHActivator.java index 31c89f0..7981779 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/SSHActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/ssh/SSHActivator.java @@ -17,6 +17,7 @@ import java.util.*; import org.osgi.framework.*; import net.java.sip.communicator.util.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; /** * Loads the SSH provider factory and registers its services in the OSGI @@ -47,6 +48,7 @@ public class SSHActivator */ private static BundleContext bundleContext = null; + private static ResourceManagementService resourcesService; /** * Called when this bundle is started. In here we'll export the @@ -121,4 +123,21 @@ public class SSHActivator sshPpFactoryServReg.unregister(); logger.info("SSH protocol implementation [STOPPED]."); } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService) bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/SSHStatusEnum.java b/src/net/java/sip/communicator/impl/protocol/ssh/SSHStatusEnum.java index bccb8f2..d346f2b 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/SSHStatusEnum.java +++ b/src/net/java/sip/communicator/impl/protocol/ssh/SSHStatusEnum.java @@ -135,20 +135,7 @@ public class SSHStatusEnum */ public static byte[] loadIcon(String imagePath) { - InputStream is = SSHStatusEnum.class.getClassLoader() - .getResourceAsStream(imagePath); - - byte[] icon = null; - try - { - icon = new byte[is.available()]; - is.read(icon); - } - catch (IOException exc) - { - logger.error("Failed to load icon: " + imagePath, exc); - } - return icon; + return ProtocolIconSSHImpl.loadIcon(imagePath); } } diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/resources.properties b/src/net/java/sip/communicator/impl/protocol/ssh/resources.properties deleted file mode 100644 index ed39a76..0000000 --- a/src/net/java/sip/communicator/impl/protocol/ssh/resources.properties +++ /dev/null @@ -1,4 +0,0 @@ -#Contact Details Seperator(must not be part of contact data stored as persistent
-# data)
-detailsSeperator=~
-protocolIcon=resources/images/protocol/ssh/ssh-online.png
diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/ssh.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/ssh/ssh.provider.manifest.mf index 75af2d0..c77a0e9 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/ssh.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/ssh/ssh.provider.manifest.mf @@ -12,6 +12,7 @@ Import-Package: org.osgi.framework, javax.crypto.interfaces, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, + net.java.sip.communicator.service.resources, net.java.sip.communicator.util, net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.protocol.event, diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java index dc48fc7..631eec8 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java @@ -436,10 +436,12 @@ public class OperationSetBasicInstantMessagingYahooImpl + yahooMailLogon + "\">" + yahooMailLogon + "</a>"; - String newMail = "<b>" + Resources.getString("newMail") + " : </b> " + String newMail = "<b>" + + YahooActivator.getResources().getI18NString("newMail") + " : </b> " + ev.getSubject(); - newMail += "\n<br /><b>" + Resources.getString("from") + " : </b> " + newMail += "\n<br /><b>" + + YahooActivator.getResources().getI18NString("from") + " : </b> " + ev.getFrom() + " <" + ev.getEmailAddress() + ">"; newMail += "\n<br /> " + yahooMailLogon; diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolIconYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolIconYahooImpl.java index c90e660..c1b8573 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolIconYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolIconYahooImpl.java @@ -77,8 +77,8 @@ public class ProtocolIconYahooImpl * @return The image for the given identifier. */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconYahooImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = + YahooActivator.getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try { diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/Resources.java b/src/net/java/sip/communicator/impl/protocol/yahoo/Resources.java deleted file mode 100644 index b62f025..0000000 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/Resources.java +++ /dev/null @@ -1,60 +0,0 @@ -/*
- * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package net.java.sip.communicator.impl.protocol.yahoo;
-
-import java.io.*;
-import java.util.*;
-
-import net.java.sip.communicator.util.*;
-
-/**
- * The Resources class manages the access to the internationalization
- * properties files.
- *
- * @author Yana Stamcheva
- */
-public class Resources
-{
-
- /**
- * Logger for this class.
- */
- private static Logger log = Logger.getLogger(Resources.class);
-
- /**
- * Name of the bundle were we will search for localized string.
- */
- private static final String BUNDLE_NAME
- = "net.java.sip.communicator.impl.protocol.yahoo.resources";
-
- /**
- * Bundle which handle access to localized resources.
- */
- private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
- .getBundle(BUNDLE_NAME);
-
- /**
- * Returns an internationalized string corresponding to the given key.
- *
- * @param key The key of the string.
- *
- * @return An internationalized string corresponding to the given key.
- */
- public static String getString(String key)
- {
- try
- {
- return RESOURCE_BUNDLE.getString(key);
-
- }
- catch (MissingResourceException e) {
-
- return '!' + key + '!';
- }
- }
-}
diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/YahooActivator.java b/src/net/java/sip/communicator/impl/protocol/yahoo/YahooActivator.java index 2874504..8dbe58b 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/YahooActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/YahooActivator.java @@ -11,6 +11,7 @@ import java.util.*; import org.osgi.framework.*; import net.java.sip.communicator.service.configuration.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; /** * Loads the Yahoo provider factory and registers it with service in the OSGI @@ -26,6 +27,8 @@ public class YahooActivator private static ConfigurationService configurationService = null; private static ProtocolProviderFactoryYahooImpl yahooProviderFactory = null; + + private static ResourceManagementService resourcesService; /** * Called when this bundle is started so the Framework can perform the @@ -112,4 +115,21 @@ public class YahooActivator yahooProviderFactory.stop(); yahooPpFactoryServReg.unregister(); } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService) bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/resources.properties b/src/net/java/sip/communicator/impl/protocol/yahoo/resources.properties deleted file mode 100644 index 6797533..0000000 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/resources.properties +++ /dev/null @@ -1,2 +0,0 @@ -newMail=New mail, subject -from=From diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/yahoo.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/yahoo/yahoo.provider.manifest.mf index 453478b..d956708 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/yahoo.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/yahoo.provider.manifest.mf @@ -13,6 +13,7 @@ Import-Package: org.osgi.framework, org.xml.sax, sun.security.action, net.java.sip.communicator.service.configuration, + net.java.sip.communicator.service.resources, net.java.sip.communicator.util, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/impl/protocol/zeroconf/ProtocolIconZeroconfImpl.java b/src/net/java/sip/communicator/impl/protocol/zeroconf/ProtocolIconZeroconfImpl.java index 33a5ca8..87b6dbc 100644 --- a/src/net/java/sip/communicator/impl/protocol/zeroconf/ProtocolIconZeroconfImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/zeroconf/ProtocolIconZeroconfImpl.java @@ -10,8 +10,11 @@ import java.io.*; import java.util.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * Reperesents the zeroconf protocol icon. Implements the <tt>ProtocolIcon</tt> * interface in order to provide a zeroconf logo image in two different sizes. @@ -25,6 +28,8 @@ public class ProtocolIconZeroconfImpl private static Logger logger = Logger.getLogger(ProtocolIconZeroconfImpl.class); + private static ResourceManagementService resourcesService; + /** * A hash table containing the protocol icon in different sizes. */ @@ -84,8 +89,7 @@ public class ProtocolIconZeroconfImpl */ public static byte[] loadIcon(String imagePath) { - InputStream is = ProtocolIconZeroconfImpl.class - .getClassLoader().getResourceAsStream(imagePath); + InputStream is = getResources().getImageInputStreamForPath(imagePath); byte[] icon = null; try @@ -99,4 +103,21 @@ public class ProtocolIconZeroconfImpl } return icon; } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = ZeroconfActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService)ZeroconfActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/impl/protocol/zeroconf/ZeroconfActivator.java b/src/net/java/sip/communicator/impl/protocol/zeroconf/ZeroconfActivator.java index e25ba29..8de1830 100644 --- a/src/net/java/sip/communicator/impl/protocol/zeroconf/ZeroconfActivator.java +++ b/src/net/java/sip/communicator/impl/protocol/zeroconf/ZeroconfActivator.java @@ -39,7 +39,7 @@ public class ZeroconfActivator /** * The currently valid bundle context. */ - private static BundleContext bundleContext = null; + static BundleContext bundleContext = null; /** diff --git a/src/net/java/sip/communicator/impl/protocol/zeroconf/ZeroconfStatusEnum.java b/src/net/java/sip/communicator/impl/protocol/zeroconf/ZeroconfStatusEnum.java index 35e7f12..a35b784 100644 --- a/src/net/java/sip/communicator/impl/protocol/zeroconf/ZeroconfStatusEnum.java +++ b/src/net/java/sip/communicator/impl/protocol/zeroconf/ZeroconfStatusEnum.java @@ -130,20 +130,7 @@ public class ZeroconfStatusEnum */ public static byte[] loadIcon(String imagePath) { - InputStream is = ZeroconfStatusEnum.class.getClassLoader() - .getResourceAsStream(imagePath); - - byte[] icon = null; - try - { - icon = new byte[is.available()]; - is.read(icon); - } - catch (IOException exc) - { - logger.error("Failed to load icon: " + imagePath, exc); - } - return icon; + return ProtocolIconZeroconfImpl.loadIcon(imagePath); } } diff --git a/src/net/java/sip/communicator/impl/protocol/zeroconf/zeroconf.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/zeroconf/zeroconf.provider.manifest.mf index 305ce56..d256c49 100644 --- a/src/net/java/sip/communicator/impl/protocol/zeroconf/zeroconf.provider.manifest.mf +++ b/src/net/java/sip/communicator/impl/protocol/zeroconf/zeroconf.provider.manifest.mf @@ -6,6 +6,7 @@ Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, + net.java.sip.communicator.service.resources, net.java.sip.communicator.util, net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.protocol.event
\ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/resources/ResourceManagementActivator.java b/src/net/java/sip/communicator/impl/resources/ResourceManagementActivator.java new file mode 100644 index 0000000..3069076 --- /dev/null +++ b/src/net/java/sip/communicator/impl/resources/ResourceManagementActivator.java @@ -0,0 +1,45 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.resources; + +import net.java.sip.communicator.service.resources.*; + +import net.java.sip.communicator.util.Logger; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +/** + * + * @author damencho + */ +public class ResourceManagementActivator + implements BundleActivator +{ + + private Logger logger = + Logger.getLogger(ResourceManagementActivator.class); + static BundleContext bundleContext; + + public void start(BundleContext bc) throws Exception + { + bundleContext = bc; + + ResourceManagementServiceImpl resPackImpl = + new ResourceManagementServiceImpl(); + + bundleContext.registerService( ResourceManagementService.class.getName(), + resPackImpl, + null); + + logger.info("Default resources ... [REGISTERED]"); + } + + public void stop(BundleContext bc) throws Exception + { + + } +} diff --git a/src/net/java/sip/communicator/impl/resources/ResourceManagementServiceImpl.java b/src/net/java/sip/communicator/impl/resources/ResourceManagementServiceImpl.java new file mode 100644 index 0000000..2713546 --- /dev/null +++ b/src/net/java/sip/communicator/impl/resources/ResourceManagementServiceImpl.java @@ -0,0 +1,594 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.resources; + +import java.io.*; +import java.net.*; +import java.text.MessageFormat; +import java.util.*; + +import net.java.sip.communicator.service.resources.*; +import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + +/** + * + * @author Damian Minkov + */ +public class ResourceManagementServiceImpl + implements ResourceManagementService, + ServiceListener +{ + private static Logger logger = + Logger.getLogger(ResourceManagementServiceImpl.class); + + private ResourceBundle colorResourceBundle; + private ResourcePack colorPack = null; + + private ResourceBundle imageResourceBundle; + private ResourcePack imagePack = null; + + private LanguagePack languagePack = null; + + private ResourceBundle settingsResourceBundle; + private ResourcePack settingsPack = null; + + private ResourceBundle soundResourceBundle; + private ResourcePack soundPack = null; + + ResourceManagementServiceImpl() + { + ResourceManagementActivator.bundleContext.addServiceListener(this); + + colorPack = + registerDefaultPack(ColorPack.class.getName(), + ColorPack.RESOURCE_NAME_DEFAULT_VALUE); + + if (colorPack != null) + colorResourceBundle = getResourceBundle(colorPack); + + imagePack = + registerDefaultPack(ImagePack.class.getName(), + ImagePack.RESOURCE_NAME_DEFAULT_VALUE); + + if (imagePack != null) + imageResourceBundle = getResourceBundle(imagePack); + + languagePack = + (LanguagePack) registerDefaultPack(LanguagePack.class.getName(), + LanguagePack.RESOURCE_NAME_DEFAULT_VALUE); + + settingsPack = + registerDefaultPack(SettingsPack.class.getName(), + SettingsPack.RESOURCE_NAME_DEFAULT_VALUE); + + if (settingsPack != null) + settingsResourceBundle = getResourceBundle(settingsPack); + + soundPack = + registerDefaultPack(SoundPack.class.getName(), + SoundPack.RESOURCE_NAME_DEFAULT_VALUE); + + if (soundPack != null) + soundResourceBundle = getResourceBundle(soundPack); + } + + private ResourcePack registerDefaultPack( String className, + String typeName) + { + ServiceReference[] serRefs = null; + + String osgiFilter = + "(" + ResourcePack.RESOURCE_NAME + "=" + typeName + ")"; + + try + { + serRefs = ResourceManagementActivator + .bundleContext.getServiceReferences( + className, + osgiFilter); + } + catch (InvalidSyntaxException exc) + { + logger.error("Could not obtain resource packs reference.", exc); + } + + if (serRefs != null) + { + for (int i = 0; i < serRefs.length; i++) + { + ResourcePack rp = + (ResourcePack) ResourceManagementActivator.bundleContext. + getService(serRefs[i]); + + return rp; + } + } + + return null; + } + + private ResourceBundle getResourceBundle(ResourcePack resourcePack) + { + String baseName = resourcePack.getResourcePackBaseName(); + + return ResourceBundle.getBundle( + baseName, + Locale.getDefault(), + resourcePack.getClass().getClassLoader()); + } + + private ResourceBundle getResourceBundle(ResourcePack resourcePack, Locale l) + { + String baseName = resourcePack.getResourcePackBaseName(); + + return ResourceBundle.getBundle( + baseName, + l, + resourcePack.getClass().getClassLoader()); + } + + private String findString(String key, ResourceBundle resourceBundle) + { + try + { + String value = resourceBundle.getString(key); + if (value != null) + { + return value; + } + } + catch (MissingResourceException e) + { + logger.error("Missing resource.", e); + } + + // nothing found + return null; + } + + public void serviceChanged(ServiceEvent event) + { + Object sService = ResourceManagementActivator.bundleContext.getService( + event.getServiceReference()); + + if (!(sService instanceof ResourcePack)) + { + return; + } + + ResourcePack resource = (ResourcePack) sService; + + if (event.getType() == ServiceEvent.REGISTERED) + { + logger.info("Resource registered " + resource); + + String resourceBaseName = resource.getResourcePackBaseName(); + + ResourceBundle resourceBundle = ResourceBundle.getBundle( + resourceBaseName, + Locale.getDefault(), + resource.getClass().getClassLoader()); + + if(resource instanceof ColorPack && colorPack == null) + { + colorPack = resource; + colorResourceBundle = resourceBundle; + } + else if(resource instanceof ImagePack && imagePack == null) + { + imagePack = resource; + imageResourceBundle = resourceBundle; + } + else if(resource instanceof LanguagePack && languagePack == null) + { + languagePack = (LanguagePack) resource; + } + else if(resource instanceof SettingsPack && settingsPack == null) + { + settingsPack = resource; + settingsResourceBundle = resourceBundle; + } + else if(resource instanceof SoundPack && soundPack == null) + { + soundPack = resource; + soundResourceBundle = resourceBundle; + } + } + else if (event.getType() == ServiceEvent.UNREGISTERING) + { + if(resource instanceof ColorPack + && colorPack.equals(resource)) + { + colorPack = null; + colorResourceBundle = null; + } + else if(resource instanceof ImagePack + && imagePack.equals(resource)) + { + imagePack = null; + imageResourceBundle = null; + } + else if(resource instanceof LanguagePack + && languagePack.equals(resource)) + { + languagePack = null; + } + else if(resource instanceof SettingsPack + && settingsPack.equals(resource)) + { + settingsPack = null; + settingsResourceBundle = null; + } + else if(resource instanceof SoundPack + && soundPack.equals(resource)) + { + soundPack = null; + soundResourceBundle = null; + } + } + } + + // Color pack methods + public int getColor(String key) + { + String res = findString(key, colorResourceBundle); + + if(res == null) + { + logger.error("Missing color resource for key: " + key); + + return 0xFFFFFF; + } + else + return Integer.parseInt(res, 16); + } + + public String getColorString(String key) + { + String res = findString(key, colorResourceBundle); + + if(res == null) + { + logger.error("Missing color resource for key: " + key); + + return "0xFFFFFF"; + } + else + return res; + } + + // Image pack methods + /** + * Loads a stream from a given identifier. + * + * @param streamKey The identifier of the stream. + * @return The stream for the given identifier. + */ + public InputStream getImageInputStreamForPath(String path) + { + return imagePack.getClass().getClassLoader().getResourceAsStream(path); + } + /** + * Loads a stream from a given identifier. + * + * @param streamKey The identifier of the stream. + * @return The stream for the given identifier. + */ + public InputStream getImageInputStream(String streamKey) + { + String path = findString(streamKey, imageResourceBundle); + + if (path == null || path.length() == 0) + { + logger.warn("Missing resource for key: " + streamKey); + return null; + } + + return getImageInputStreamForPath(path); + } + + /** + * Loads an url from a given identifier. + * + * @param urlKey The identifier of the url. + * @return The url for the given identifier. + */ + public URL getImageURL(String urlKey) + { + String path = findString(urlKey, imageResourceBundle); + + if (path == null || path.length() == 0) + { + logger.warn("Missing resource for key: " + urlKey + + " / " + imageResourceBundle); + return null; + } + return getImageURLForPath(path); + } + + public URL getImageURLForPath(String path) + { + return imagePack.getClass().getClassLoader().getResource(path); + } + + // Language pack methods + /** + * Returns an internationalized string corresponding to the given key. + * + * @param key The key of the string. + * @return An internationalized string corresponding to the given key. + */ + public String getI18NString(String key) + { + return getI18NString(key, Locale.getDefault()); + } + + /** + * Returns an internationalized string corresponding to the given key. + * + * @param key The key of the string. + * @param l The locale. + * @return An internationalized string corresponding to the given key and + * given locale. + */ + public String getI18NString(String key, Locale l) + { + ResourceBundle resourceBundle + = getResourceBundle(languagePack, l); + + String resourceString = findString(key, resourceBundle); + + if (resourceString == null) + { + logger.warn("Missing resource for key: " + key); + return '!' + key + '!'; + } + + int mnemonicIndex = resourceString.indexOf('&'); + + if (mnemonicIndex > -1) + { + String firstPart = resourceString.substring(0, mnemonicIndex); + String secondPart = resourceString.substring(mnemonicIndex + 1); + + resourceString = firstPart.concat(secondPart); + } + + return resourceString; + } + + /** + * Returns an internationalized string corresponding to the given key. + * + * @param key The key of the string. + * @return An internationalized string corresponding to the given key. + */ + public String getI18NString(String key, String[] params) + { + return getI18NString(key, params, Locale.getDefault()); + } + + /** + * Returns an internationalized string corresponding to the given key. + * + * @param key The key of the string. + * @param l The locale. + * @return An internationalized string corresponding to the given key. + */ + public String getI18NString(String key, String[] params, Locale l) + { + ResourceBundle resourceBundle + = getResourceBundle(languagePack, l); + + String resourceString = findString(key, resourceBundle); + + if (resourceString == null) + { + logger.warn("Missing resource for key: " + key); + return '!' + key + '!'; + } + + int mnemonicIndex = resourceString.indexOf('&'); + + if (mnemonicIndex > -1) + { + String firstPart = resourceString.substring(0, mnemonicIndex); + String secondPart = resourceString.substring(mnemonicIndex + 1); + + resourceString = firstPart.concat(secondPart); + } + + resourceString = MessageFormat.format(resourceString, (Object[])params); + + return resourceString; + } + + /** + * Returns an internationalized string corresponding to the given key. + * + * @param key The key of the string. + * @return An internationalized string corresponding to the given key. + */ + public char getI18nMnemonic(String key) + { + return getI18nMnemonic(key, Locale.getDefault()); + } + + /** + * Returns an internationalized string corresponding to the given key. + * + * @param key The key of the string. + * @return An internationalized string corresponding to the given key. + */ + public char getI18nMnemonic(String key, Locale l) + { + ResourceBundle resourceBundle + = getResourceBundle(languagePack, l); + + String resourceString = findString(key, resourceBundle); + + if (resourceString == null) + { + logger.warn("Missing resource for key: " + key); + return 0; + } + + int mnemonicIndex = resourceString.indexOf('&'); + + if (mnemonicIndex > -1) + { + return resourceString.charAt(mnemonicIndex + 1); + } + + return 0; + } + + // Settings pack methods + public String getSettingsString(String key) + { + return findString(key, settingsResourceBundle); + } + + public int getSettingsInt(String key) + { + String resourceString = findString(key, settingsResourceBundle); + + if (resourceString == null) + { + logger.warn("Missing resource for key: " + key); + return 0; + } + + return Integer.parseInt(resourceString); + } + + /** + * Loads an url from a given identifier. + * + * @param urlKey The identifier of the url. + * @return The url for the given identifier. + */ + public URL getSettingsURL(String urlKey) + { + String path = findString(urlKey, settingsResourceBundle); + + if (path == null || path.length() == 0) + { + logger.warn("Missing resource for key: " + urlKey); + return null; + } + return settingsPack.getClass().getClassLoader().getResource(path); + } + /** + * Loads a stream from a given identifier. + * + * @param streamKey The identifier of the stream. + * @return The stream for the given identifier. + */ + public InputStream getSettingsInputStream(String streamKey) + { + String path = findString(streamKey, settingsResourceBundle); + + if (path == null || path.length() == 0) + { + logger.warn("Missing resource for key: " + streamKey); + return null; + } + + return settingsPack.getClass().getClassLoader().getResourceAsStream(path); + } + + + // Sound pack methods + public URL getSoundURL(String urlKey) + { + String path = findString(urlKey, soundResourceBundle); + + if (path == null || path.length() == 0) + { + logger.warn("Missing resource for key: " + urlKey); + return null; + } + return getSoundURLForPath(path); + } + + public URL getSoundURLForPath(String path) + { + return soundPack.getClass().getClassLoader().getResource(path); + } + + public Iterator getCurrentColors() + { + Enumeration colorKeys = colorResourceBundle.getKeys(); + + List colorList = new ArrayList(); + while (colorKeys.hasMoreElements()) + { + colorList.add(colorKeys.nextElement()); + } + + return colorList.iterator(); + } + + public Iterator getCurrentImages() + { + Enumeration imageKeys = imageResourceBundle.getKeys(); + + List imageList = new ArrayList(); + while (imageKeys.hasMoreElements()) + { + imageList.add(imageKeys.nextElement()); + } + + return imageList.iterator(); + } + + public Iterator getCurrentSettings() + { + Enumeration settingKeys = settingsResourceBundle.getKeys(); + + List settingList = new ArrayList(); + while (settingKeys.hasMoreElements()) + { + settingList.add(settingKeys.nextElement()); + } + + return settingList.iterator(); + } + + public Iterator getCurrentSounds() + { + Enumeration soundKeys = soundResourceBundle.getKeys(); + + List soundList = new ArrayList(); + while (soundKeys.hasMoreElements()) + { + soundList.add(soundKeys.nextElement()); + } + + return soundList.iterator(); + } + + public Iterator getAvailableLocales() + { + return languagePack.getAvailableLocales(); + } + + public Iterator getI18nStringsByLocale(Locale l) + { + Enumeration languageKeys = getResourceBundle(languagePack, l).getKeys(); + + List languageList = new ArrayList(); + while (languageKeys.hasMoreElements()) + { + languageList.add(languageKeys.nextElement()); + } + + return languageList.iterator(); + } +} diff --git a/src/net/java/sip/communicator/impl/resources/resourcemanagement.manifest.mf b/src/net/java/sip/communicator/impl/resources/resourcemanagement.manifest.mf new file mode 100644 index 0000000..be777e9 --- /dev/null +++ b/src/net/java/sip/communicator/impl/resources/resourcemanagement.manifest.mf @@ -0,0 +1,10 @@ +Bundle-Activator: net.java.sip.communicator.impl.resources.ResourceManagementActivator +Bundle-Name: Resource Management Service +Bundle-Description: The plugin managing images and languages resource packs. +Bundle-Vendor: sip-communicator.org +Bundle-Version: 0.0.1 +Export-Package: net.java.sip.communicator.service.resources +Import-Package: org.osgi.framework, + net.java.sip.communicator.util, + net.java.sip.communicator.service.configuration, + net.java.sip.communicator.service.configuration.event diff --git a/src/net/java/sip/communicator/impl/systray/Resources.java b/src/net/java/sip/communicator/impl/systray/Resources.java index 4dd570b..d92bcd4 100644 --- a/src/net/java/sip/communicator/impl/systray/Resources.java +++ b/src/net/java/sip/communicator/impl/systray/Resources.java @@ -15,7 +15,10 @@ import java.util.*; import javax.imageio.*; import javax.swing.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; + +import org.osgi.framework.*; /** * The Messages class manages the access to the internationalization * properties files. @@ -23,22 +26,11 @@ import net.java.sip.communicator.util.*; * @author Nicolas Chamouard */ public class Resources -{ - +{ private static Logger log = Logger.getLogger(Resources.class); - private static final String BUNDLE_NAME - = "resources.languages.impl.systray.resources"; - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - .getBundle(BUNDLE_NAME); - - private static final String APPLICATION_RESUORCE_LOCATION - = "resources.application"; - - private static final ResourceBundle applicationBundle - = ResourceBundle.getBundle(APPLICATION_RESUORCE_LOCATION); - + private static ResourceManagementService resourcesService; + /** * Returns an internationalized string corresponding to the given key. * @@ -47,26 +39,7 @@ public class Resources */ public static String getString(String key) { - try - { - String resourceString = RESOURCE_BUNDLE.getString(key); - - int mnemonicIndex = resourceString.indexOf('&'); - - if(mnemonicIndex > -1) - { - String firstPart = resourceString.substring(0, mnemonicIndex); - String secondPart = resourceString.substring(mnemonicIndex + 1); - - resourceString = firstPart.concat(secondPart); - } - - return resourceString; - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -77,21 +50,7 @@ public class Resources */ public static char getMnemonic(String key) { - try - { - String resourceString = RESOURCE_BUNDLE.getString(key); - - int mnemonicIndex = resourceString.indexOf('&'); - - if(mnemonicIndex > -1) - return resourceString.charAt(mnemonicIndex + 1); - } - catch (MissingResourceException e) - { - return 0; - } - - return 0; + return getResources().getI18nMnemonic(key); } /** @@ -104,21 +63,19 @@ public class Resources { BufferedImage image = null; - String path = Resources.getString(imageID); + InputStream in = + getResources().getImageInputStream(imageID); - if(path == null || path.length() == 0) + if(in == null) return null; try { - image = - ImageIO.read(Resources.class.getClassLoader() - .getResourceAsStream(path)); - + image = ImageIO.read(in); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return new ImageIcon(image); @@ -132,13 +89,7 @@ public class Resources */ public static URL getImageURL(String imageID) { - String path = Resources.getString(imageID); - - if(path == null || path.length() == 0) - return null; - - return Resources.class.getClassLoader() - .getResource(path); + return getResources().getImageURL(imageID); } /** @@ -149,13 +100,24 @@ public class Resources */ public static String getApplicationString(String key) { - try - { - return applicationBundle.getString(key); - } - catch (MissingResourceException e) + return getResources().getSettingsString(key); + } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) { - return '!' + key + '!'; + ServiceReference serviceReference = SystrayActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)SystrayActivator.bundleContext + .getService(serviceReference); } + + return resourcesService; } } diff --git a/src/net/java/sip/communicator/impl/systray/systray.manifest.mf b/src/net/java/sip/communicator/impl/systray/systray.manifest.mf index b863eef..2693328 100644 --- a/src/net/java/sip/communicator/impl/systray/systray.manifest.mf +++ b/src/net/java/sip/communicator/impl/systray/systray.manifest.mf @@ -11,6 +11,7 @@ Import-Package: org.osgi.framework, com.apple.cocoa.foundation,
net.java.sip.communicator.util,
net.java.sip.communicator.service.configuration,
+ net.java.sip.communicator.service.resources,
net.java.sip.communicator.service.protocol,
net.java.sip.communicator.service.protocol.event,
net.java.sip.communicator.service.gui,
diff --git a/src/net/java/sip/communicator/impl/version/VersionActivator.java b/src/net/java/sip/communicator/impl/version/VersionActivator.java index 647a841..e365e83 100644 --- a/src/net/java/sip/communicator/impl/version/VersionActivator.java +++ b/src/net/java/sip/communicator/impl/version/VersionActivator.java @@ -24,7 +24,7 @@ public class VersionActivator private Logger logger = Logger.getLogger(VersionActivator.class.getName()); private ServiceRegistration versionServReg = null; - private static BundleContext bundleContext = null; + static BundleContext bundleContext = null; private static ConfigurationService configurationService = null; /** diff --git a/src/net/java/sip/communicator/impl/version/VersionImpl.java b/src/net/java/sip/communicator/impl/version/VersionImpl.java index e5c95b7..de66f1d 100644 --- a/src/net/java/sip/communicator/impl/version/VersionImpl.java +++ b/src/net/java/sip/communicator/impl/version/VersionImpl.java @@ -9,6 +9,8 @@ package net.java.sip.communicator.impl.version; import java.util.*; import net.java.sip.communicator.service.version.*; +import net.java.sip.communicator.service.resources.*; +import org.osgi.framework.ServiceReference; /** * A static implementation of the Version interface. @@ -75,6 +77,8 @@ public class VersionImpl * SIP Communicator. */ public static final VersionImpl CURRENT_VERSION = new VersionImpl(); + + private static ResourceManagementService resourcesService; /** * Returns the version major of the current SIP Communicator version. In an @@ -296,9 +300,22 @@ public class VersionImpl { try { + if (resourcesService == null) + { + ServiceReference serviceReference = VersionActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)VersionActivator.bundleContext + .getService(serviceReference); + } + applicationName = - ResourceBundle.getBundle("resources.application"). - getString("applicationName"); + resourcesService.getSettingsString("applicationName"); + } catch (Exception e) { // if resource bundle is not found or the key is missing diff --git a/src/net/java/sip/communicator/impl/version/version.impl.manifest.mf b/src/net/java/sip/communicator/impl/version/version.impl.manifest.mf index 7b7d255..6f22d2a 100755 --- a/src/net/java/sip/communicator/impl/version/version.impl.manifest.mf +++ b/src/net/java/sip/communicator/impl/version/version.impl.manifest.mf @@ -6,6 +6,7 @@ Bundle-Version: 0.0.1 System-Bundle: yes Import-Package: org.osgi.framework, net.java.sip.communicator.service.configuration, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.util, net.java.sip.communicator.service.version diff --git a/src/net/java/sip/communicator/plugin/accountinfo/AccountDetailsPanel.java b/src/net/java/sip/communicator/plugin/accountinfo/AccountDetailsPanel.java index fe504d1..12597f8 100644 --- a/src/net/java/sip/communicator/plugin/accountinfo/AccountDetailsPanel.java +++ b/src/net/java/sip/communicator/plugin/accountinfo/AccountDetailsPanel.java @@ -144,7 +144,7 @@ public class AccountDetailsPanel changeAvatarButton.addActionListener(new ChangeAvatarActionListener());
- avatarLabel.setIcon(Resources.getImage("defaultPersonIcon"));
+ avatarLabel.setIcon(Resources.getImage("accountInfoDefaultPersonIcon"));
changeButtonPanel.add(changeAvatarButton);
diff --git a/src/net/java/sip/communicator/plugin/accountinfo/AccountInfoForm.java b/src/net/java/sip/communicator/plugin/accountinfo/AccountInfoForm.java index dbd6c78..50e25e4 100644 --- a/src/net/java/sip/communicator/plugin/accountinfo/AccountInfoForm.java +++ b/src/net/java/sip/communicator/plugin/accountinfo/AccountInfoForm.java @@ -114,7 +114,7 @@ public class AccountInfoForm */
public byte[] getIcon()
{
- return Resources.getImageInBytes("infoIcon");
+ return Resources.getImageInBytes("accountInfoIcon");
}
/**
diff --git a/src/net/java/sip/communicator/plugin/accountinfo/Resources.java b/src/net/java/sip/communicator/plugin/accountinfo/Resources.java index 1f45e84..2828c14 100644 --- a/src/net/java/sip/communicator/plugin/accountinfo/Resources.java +++ b/src/net/java/sip/communicator/plugin/accountinfo/Resources.java @@ -14,7 +14,10 @@ import java.util.*; import javax.imageio.*;
import javax.swing.*;
+import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
+
+import org.osgi.framework.*;
/**
* The <tt>Resources</tt> class manages the access to the internationalization
* properties files and the image resources used in this plugin.
@@ -25,31 +28,7 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class);
- /**
- * The name of the resource, where internationalization strings for this
- * plugin are stored.
- */
- private static final String STRING_RESOURCE_NAME
- = "resources.languages.plugin.accountinfo.resources";
-
- /**
- * The name of the resource, where paths to images used in this bundle are
- * stored.
- */
- private static final String IMAGE_RESOURCE_NAME
- = "net.java.sip.communicator.plugin.accountinfo.resources";
-
- /**
- * The string resource bundle.
- */
- private static final ResourceBundle STRING_RESOURCE_BUNDLE
- = ResourceBundle.getBundle(STRING_RESOURCE_NAME);
-
- /**
- * The image resource bundle.
- */
- private static final ResourceBundle IMAGE_RESOURCE_BUNDLE
- = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME);
+ private static ResourceManagementService resourcesService;
/**
* Returns an internationalized string corresponding to the given key.
@@ -58,14 +37,7 @@ public class Resources { */
public static String getString(String key)
{
- try
- {
- return STRING_RESOURCE_BUNDLE.getString(key);
- }
- catch (MissingResourceException e)
- {
- return '!' + key + '!';
- }
+ return getResources().getI18NString(key);
}
/**
@@ -77,15 +49,19 @@ public class Resources { {
BufferedImage image = null;
- String path = IMAGE_RESOURCE_BUNDLE.getString(imageID);
+ InputStream in =
+ getResources().getImageInputStream(imageID);
+
+ if(in == null)
+ return null;
+
try
{
- image = ImageIO.read(Resources.class.getClassLoader()
- .getResourceAsStream(path));
+ image = ImageIO.read(in);
}
catch (IOException e)
{
- log.error("Failed to load image:" + path, e);
+ log.error("Failed to load image:" + imageID, e);
}
return new ImageIcon(image);
@@ -98,21 +74,42 @@ public class Resources { */
public static byte[] getImageInBytes(String imageID)
{
- byte[] image = new byte[100000];
-
- String path = IMAGE_RESOURCE_BUNDLE.getString(imageID);
+ InputStream in =
+ getResources().getImageInputStream(imageID);
+
+ if(in == null)
+ return null;
+
+ byte[] image = null;
try
{
- Resources.class.getClassLoader()
- .getResourceAsStream(path).read(image);
-
+ image = new byte[in.available()];
+ in.read(image);
}
catch (IOException e)
{
- log.error("Failed to load image:" + path, e);
+ log.error("Failed to load image:" + imageID, e);
}
return image;
}
+
+ public static ResourceManagementService getResources()
+ {
+ if (resourcesService == null)
+ {
+ ServiceReference serviceReference = AccountInfoActivator.bundleContext
+ .getServiceReference(ResourceManagementService.class.getName());
+
+ if(serviceReference == null)
+ return null;
+
+ resourcesService =
+ (ResourceManagementService)AccountInfoActivator.bundleContext
+ .getService(serviceReference);
+ }
+
+ return resourcesService;
+ }
}
diff --git a/src/net/java/sip/communicator/plugin/accountinfo/accountinfo.manifest.mf b/src/net/java/sip/communicator/plugin/accountinfo/accountinfo.manifest.mf index a53defa..28359d7 100644 --- a/src/net/java/sip/communicator/plugin/accountinfo/accountinfo.manifest.mf +++ b/src/net/java/sip/communicator/plugin/accountinfo/accountinfo.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1
Import-Package: org.osgi.framework,
net.java.sip.communicator.util,
+ net.java.sip.communicator.service.resources,
net.java.sip.communicator.service.contactlist,
net.java.sip.communicator.service.contactlist.event,
net.java.sip.communicator.service.gui,
diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccountRegistrationWizard.java index c48fa66..b14d7ca 100644 --- a/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/AimAccountRegistrationWizard.java @@ -71,7 +71,7 @@ public class AimAccountRegistrationWizard */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameAim"); } /** @@ -81,7 +81,7 @@ public class AimAccountRegistrationWizard */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionAim"); } /** diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/aimaccregwizz/FirstWizardPage.java index 7b530e1..fb4637c 100644 --- a/src/net/java/sip/communicator/plugin/aimaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/FirstWizardPage.java @@ -69,7 +69,7 @@ public class FirstWizardPage private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); private JTextArea registerArea = - new JTextArea(Resources.getString("registerNewAccountText")); + new JTextArea(Resources.getString("aimRegisterNewAccountText")); private JButton registerButton = new JButton(Resources.getString("registerNewAccount")); diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/aimaccregwizz/Resources.java index 37a4d7c..1f82730 100644 --- a/src/net/java/sip/communicator/plugin/aimaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/Resources.java @@ -10,7 +10,11 @@ package net.java.sip.communicator.plugin.aimaccregwizz; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; + +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -21,41 +25,17 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.aimaccregwizz.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.aimaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); + private static ResourceManagementService resourcesService; /** * A constant pointing to the Aim protocol logo image. */ - public static ImageID AIM_LOGO = new ImageID("protocolIcon"); + public static ImageID AIM_LOGO = new ImageID("protocolIconAim"); /** * A constant pointing to the Aim protocol wizard page image. */ - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageAim"); /** * Returns an internationalized string corresponding to the given key. @@ -64,15 +44,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -82,19 +54,22 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; - - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); - + image = new byte[in.available()]; + in.read(image); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return image; @@ -117,4 +92,22 @@ public class Resources return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = AimAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)AimAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/aimaccregwizz/aimaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/aimaccregwizz/aimaccregwizz.manifest.mf index 4da5f84..013edda 100644 --- a/src/net/java/sip/communicator/plugin/aimaccregwizz/aimaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/aimaccregwizz/aimaccregwizz.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/plugin/branding/AboutWindow.java b/src/net/java/sip/communicator/plugin/branding/AboutWindow.java index 7a68ac0..875380e 100644 --- a/src/net/java/sip/communicator/plugin/branding/AboutWindow.java +++ b/src/net/java/sip/communicator/plugin/branding/AboutWindow.java @@ -22,19 +22,20 @@ public class AboutWindow extends JDialog implements HyperlinkListener, private WindowBackground mainPanel = new WindowBackground();
private JLabel titleLabel = new JLabel(
- BrandingResources.getApplicationString("applicationName"));
+ BrandingActivator.getResources().getSettingsString("applicationName"));
private JLabel versionLabel = new JLabel(" "
+ System.getProperty("sip-communicator.version"));
private JTextArea logoArea = new JTextArea(
- Resources.getString("logoMessage"));
+ BrandingActivator.getResources().getI18NString("logoMessage"));
private StyledHTMLEditorPane rightsArea = new StyledHTMLEditorPane();
private StyledHTMLEditorPane licenseArea = new StyledHTMLEditorPane();
- private JButton okButton = new JButton(Resources.getString("ok"));
+ private JButton okButton = new JButton(
+ BrandingActivator.getResources().getI18NString("ok"));
private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
@@ -44,9 +45,10 @@ public class AboutWindow extends JDialog implements HyperlinkListener, {
super(owner);
- this.setTitle( Resources.getString("aboutWindowTitle",
- new String[]{BrandingResources
- .getApplicationString("applicationName")}));
+ this.setTitle(
+ BrandingActivator.getResources().getI18NString("aboutWindowTitle",
+ new String[]{BrandingActivator.getResources().
+ getSettingsString("applicationName")}));
this.setModal(false);
@@ -66,8 +68,8 @@ public class AboutWindow extends JDialog implements HyperlinkListener, this.versionLabel.setForeground(Constants.TITLE_COLOR);
this.versionLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);
- int logoAreaFontSize = new Integer(
- BrandingResources.getApplicationString("aboutLogoFontSize")).intValue();
+ int logoAreaFontSize = BrandingActivator.getResources().
+ getSettingsInt("aboutLogoFontSize");
this.logoArea.setFont(
Constants.FONT.deriveFont(Font.BOLD, logoAreaFontSize));
@@ -83,7 +85,8 @@ public class AboutWindow extends JDialog implements HyperlinkListener, this.rightsArea.setContentType("text/html");
- this.rightsArea.appendToEnd(Resources.getString("copyright",
+ this.rightsArea.appendToEnd(BrandingActivator.getResources().
+ getI18NString("copyright",
new String[]{Constants.TEXT_COLOR}));
this.rightsArea.setPreferredSize(new Dimension(50, 20));
@@ -95,7 +98,8 @@ public class AboutWindow extends JDialog implements HyperlinkListener, this.rightsArea.addHyperlinkListener(this);
this.licenseArea.setContentType("text/html");
- this.licenseArea.appendToEnd(Resources.getString("license",
+ this.licenseArea.appendToEnd(BrandingActivator.getResources().
+ getI18NString("license",
new String[]{Constants.TEXT_COLOR}));
this.licenseArea.setPreferredSize(new Dimension(50, 20));
@@ -114,7 +118,8 @@ public class AboutWindow extends JDialog implements HyperlinkListener, this.getRootPane().setDefaultButton(okButton);
- this.okButton.setMnemonic(Resources.getString("ok").charAt(0));
+ this.okButton.setMnemonic(BrandingActivator.getResources().
+ getI18nMnemonic("ok"));
this.okButton.addActionListener(this);
@@ -151,9 +156,8 @@ public class AboutWindow extends JDialog implements HyperlinkListener, {
try
{
- bgImage = ImageIO.read(WindowBackground.class.getClassLoader()
- .getResource(BrandingResources
- .getResourceString("aboutWindowBg")));
+ bgImage = ImageIO.read(BrandingActivator.getResources().
+ getImageURL("aboutWindowBg"));
}
catch (IOException e)
{
diff --git a/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java b/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java index ab0f0c2..0cae435 100644 --- a/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java +++ b/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java @@ -17,7 +17,8 @@ public class AboutWindowPluginComponent implements PluginComponent { private JMenuItem aboutMenuItem - = new JMenuItem(Resources.getString("aboutMenuEntry")); + = new JMenuItem(BrandingActivator.getResources(). + getI18NString("aboutMenuEntry")); private Container container; @@ -52,7 +53,7 @@ public class AboutWindowPluginComponent public String getName() { - return Resources.getString("aboutMenuEntry"); + return BrandingActivator.getResources().getI18NString("aboutMenuEntry"); } public void setCurrentContact(MetaContact metaContact) diff --git a/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java b/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java index e48864b..578faa2 100644 --- a/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java +++ b/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java @@ -6,11 +6,9 @@ */ package net.java.sip.communicator.plugin.branding; -import java.awt.event.*; import java.util.*; -import javax.swing.*; - +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.util.*; @@ -25,6 +23,8 @@ public class BrandingActivator private WelcomeWindow welcomeWindow; private static BundleContext bundleContext; + + private static ResourceManagementService resourcesService; public void start(BundleContext bc) throws Exception { @@ -107,4 +107,20 @@ public class BrandingActivator return bundleContext; } + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService) bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/branding/BrandingResources.java b/src/net/java/sip/communicator/plugin/branding/BrandingResources.java index 3940911..e69de29 100644 --- a/src/net/java/sip/communicator/plugin/branding/BrandingResources.java +++ b/src/net/java/sip/communicator/plugin/branding/BrandingResources.java @@ -1,67 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.plugin.branding; - -import java.text.*; -import java.util.*; - -/** - * The BrandingResources class manages the access to the - * brandingResources.properties file. - * - * @author Yana Stamcheva - */ -public class BrandingResources -{ - private static final String RESOUCRE_LOCATION - = "net.java.sip.communicator.plugin.branding.brandingResources"; - - private static final ResourceBundle resourceBundle - = ResourceBundle.getBundle(RESOUCRE_LOCATION); - - private static final String APPLICATION_RESUORCE_LOCATION - = "resources.application"; - - private static final ResourceBundle applicationBundle - = ResourceBundle.getBundle(APPLICATION_RESUORCE_LOCATION); - - /** - * Returns the resource string corresponding to the given key. - * - * @param key The key of the string. - * @return the resource string corresponding to the given key - */ - public static String getResourceString(String key) - { - try - { - return resourceBundle.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } - } - - /** - * Returns the application property string corresponding to the given key. - * - * @param key The key of the string. - * @return the application property string corresponding to the given key - */ - public static String getApplicationString(String key) - { - try - { - return applicationBundle.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } - } -}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/branding/Constants.java b/src/net/java/sip/communicator/plugin/branding/Constants.java index 6b7d2e4..861e67e 100644 --- a/src/net/java/sip/communicator/plugin/branding/Constants.java +++ b/src/net/java/sip/communicator/plugin/branding/Constants.java @@ -30,14 +30,14 @@ public class Constants * Dark blue color used in the about window and the splash screen.
*/
public static final Color TITLE_COLOR
- = new Color(Integer.parseInt(
- Resources.getColor("splashScreenTitleColor"), 16));
+ = new Color(
+ BrandingActivator.getResources().getColor("splashScreenTitleColor"));
/**
* Text color used in the about window and the splash screen.
*/
public static final String TEXT_COLOR
- = Resources.getColor("splashScreenTextColor");
+ = BrandingActivator.getResources().getColorString("splashScreenTextColor");
/*
@@ -50,10 +50,9 @@ public class Constants * The default <tt>Font</tt> object used through this ui implementation.
*/
public static final Font FONT
- = new Font( BrandingResources.getApplicationString("fontName"),
+ = new Font( BrandingActivator.getResources().getSettingsString("fontName"),
Font.PLAIN,
- new Integer(BrandingResources.getApplicationString("fontSize"))
- .intValue());
+ BrandingActivator.getResources().getSettingsInt("fontSize"));
/**
* Temporary method to load the css style used in the chat window.
@@ -62,9 +61,8 @@ public class Constants */
public static void loadSimpleStyle(StyleSheet style)
{
- InputStream is = Constants.class.getClassLoader()
- .getResourceAsStream(
- BrandingResources.getResourceString("textStyle"));
+ InputStream is = BrandingActivator.getResources().
+ getSettingsInputStream("textStyle");
Reader r = new BufferedReader(new InputStreamReader(is));
try
diff --git a/src/net/java/sip/communicator/plugin/branding/Resources.java b/src/net/java/sip/communicator/plugin/branding/Resources.java deleted file mode 100644 index da0d2ba..0000000 --- a/src/net/java/sip/communicator/plugin/branding/Resources.java +++ /dev/null @@ -1,105 +0,0 @@ -/*
- * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.plugin.branding;
-
-import java.text.*;
-import java.util.*;
-
-import net.java.sip.communicator.util.*;
-
-/**
- * The Messages class manages the access to the internationalization properties
- * files.
- *
- * @author Yana Stamcheva
- */
-public class Resources
-{
- private static Logger log = Logger.getLogger(Resources.class);
-
- private static final String RESOURCE_LOCATION
- = "resources.languages.plugin.branding.resources";
-
- private static final ResourceBundle resourceBundle
- = ResourceBundle.getBundle(RESOURCE_LOCATION);
-
- private static final String COLOR_BUNDLE_NAME
- = "resources.colors.colorResources";
-
- private static final ResourceBundle COLOR_RESOURCE_BUNDLE
- = ResourceBundle.getBundle(COLOR_BUNDLE_NAME);
-
- /**
- * Returns an internationalized string corresponding to the given key.
- *
- * @param key The key of the string.
- * @return An internationalized string corresponding to the given key.
- */
- public static String getString(String key)
- {
- try
- {
- return resourceBundle.getString(key);
- }
- catch (MissingResourceException e)
- {
- return '!' + key + '!';
- }
- }
-
- /**
- * Returns an internationalized string corresponding to the given key,
- * by replacing all occurences of '?' with the given string param.
- * @param key The key of the string.
- * @param params the params, that should replace {1}, {2}, etc. in the
- * string given by the key parameter
- * @return An internationalized string corresponding to the given key,
- * by replacing all occurences of {#number} with the given string param.
- */
- public static String getString(String key, String[] params)
- {
- String resourceString;
-
- try
- {
- resourceString = resourceBundle.getString(key);
-
- resourceString = MessageFormat.format(
- resourceString, (Object[]) params);
-
- }
- catch (MissingResourceException e)
- {
- log.error("Missing string resource.", e);
-
- resourceString = '!' + key + '!';
- }
-
- return resourceString;
- }
-
- /**
- * Returns an int RGB color corresponding to the given key.
- *
- * @param key The key of the string.
- *
- * @return an int RGB color corresponding to the given key.
- */
- public static String getColor(String key)
- {
- try
- {
- return COLOR_RESOURCE_BUNDLE.getString(key);
- }
- catch (MissingResourceException e)
- {
- log.error("Missing color resource.", e);
-
- return "FFFFFF";
- }
- }
-}
diff --git a/src/net/java/sip/communicator/plugin/branding/WelcomeWindow.java b/src/net/java/sip/communicator/plugin/branding/WelcomeWindow.java index c923e99..ba990a9 100644 --- a/src/net/java/sip/communicator/plugin/branding/WelcomeWindow.java +++ b/src/net/java/sip/communicator/plugin/branding/WelcomeWindow.java @@ -12,13 +12,13 @@ public class WelcomeWindow extends JDialog private WindowBackground mainPanel = new WindowBackground(); private JLabel titleLabel - = new JLabel(BrandingResources.getApplicationString("applicationName")); + = new JLabel(BrandingActivator.getResources().getSettingsString("applicationName")); private JLabel versionLabel = new JLabel(" " + System.getProperty("sip-communicator.version")); - private JTextArea logoArea = new JTextArea(Resources - .getString("logoMessage")); + private JTextArea logoArea = new JTextArea( + BrandingActivator.getResources().getI18NString("logoMessage")); private StyledHTMLEditorPane rightsArea = new StyledHTMLEditorPane(); @@ -29,13 +29,14 @@ public class WelcomeWindow extends JDialog private JPanel loadingPanel = new JPanel(new BorderLayout()); private JLabel loadingLabel = new JLabel( - Resources.getString("loading") + ": "); + BrandingActivator.getResources().getI18NString("loading") + ": "); private JLabel bundleLabel = new JLabel(); public WelcomeWindow() { - this.setTitle(BrandingResources.getApplicationString("applicationName")); + this.setTitle( + BrandingActivator.getResources().getSettingsString("applicationName")); this.setModal(false); this.setUndecorated(true); @@ -56,9 +57,8 @@ public class WelcomeWindow extends JDialog this.versionLabel.setForeground(Constants.TITLE_COLOR); this.versionLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); - int logoAreaFontSize = new Integer( - BrandingResources.getApplicationString("aboutLogoFontSize")) - .intValue(); + int logoAreaFontSize = BrandingActivator.getResources(). + getSettingsInt("aboutLogoFontSize"); this.logoArea.setFont( Constants.FONT.deriveFont(Font.BOLD, logoAreaFontSize)); @@ -72,11 +72,12 @@ public class WelcomeWindow extends JDialog this.logoArea.setBorder(BorderFactory.createEmptyBorder(20, 190, 0, 0)); this.rightsArea.setContentType("text/html"); - this.rightsArea.appendToEnd(Resources.getString("welcomeMessage", + this.rightsArea.appendToEnd(BrandingActivator.getResources().getI18NString( + "welcomeMessage", new String[]{ Constants.TEXT_COLOR, - BrandingResources.getApplicationString("applicationName"), - BrandingResources.getApplicationString("applicationWebSite") + BrandingActivator.getResources().getSettingsString("applicationName"), + BrandingActivator.getResources().getSettingsString("applicationWebSite") })); this.rightsArea.setPreferredSize(new Dimension(50, 50)); @@ -87,7 +88,8 @@ public class WelcomeWindow extends JDialog this.rightsArea.setAlignmentX(Component.RIGHT_ALIGNMENT); this.licenseArea.setContentType("text/html"); - this.licenseArea.appendToEnd(Resources.getString("license", + this.licenseArea.appendToEnd(BrandingActivator.getResources().getI18NString( + "license", new String[] { Constants.TEXT_COLOR @@ -186,9 +188,8 @@ public class WelcomeWindow extends JDialog try { - bgImage = ImageIO.read(WindowBackground.class.getClassLoader() - .getResource( - BrandingResources.getResourceString("splashScreenBg"))); + bgImage = ImageIO.read( + BrandingActivator.getResources().getImageURL("splashScreenBg")); } catch (IOException e) { diff --git a/src/net/java/sip/communicator/plugin/branding/branding.manifest.mf b/src/net/java/sip/communicator/plugin/branding/branding.manifest.mf index 4a6a2bc..9042c9c 100755 --- a/src/net/java/sip/communicator/plugin/branding/branding.manifest.mf +++ b/src/net/java/sip/communicator/plugin/branding/branding.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.service.browserlauncher, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.gui, net.java.sip.communicator.service.gui.event, net.java.sip.communicator.util, diff --git a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java index 2d758f8..2b50db6 100644 --- a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java +++ b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java @@ -20,7 +20,7 @@ public class ContactInfoActivator implements BundleActivator private static BrowserLauncherService browserLauncherService;
- private static BundleContext bundleContext;
+ static BundleContext bundleContext;
/**
* Starts this bundle.
diff --git a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoDetailsPanel.java b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoDetailsPanel.java index 17294d2..2b7252e 100644 --- a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoDetailsPanel.java +++ b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoDetailsPanel.java @@ -98,13 +98,13 @@ public class ContactInfoDetailsPanel JScrollPane extendedScrollPane = new JScrollPane(extendedPanel);
this.tabbedPane.addTab(Resources.getString("summary"), icon,
- summaryPanel, Resources.getString("summaryDesc")
+ summaryPanel, Resources.getString("contactSummaryDesc")
+ contact.getDisplayName());
this.tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
this.tabbedPane.addTab(Resources.getString("extended"), icon,
- extendedScrollPane, Resources.getString("extendedDesc")
+ extendedScrollPane, Resources.getString("contactExtendedDesc")
+ contact.getDisplayName());
this.tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
@@ -126,7 +126,7 @@ public class ContactInfoDetailsPanel private JPanel createUnsupportedPanel()
{
JTextArea unsupportedTextArea =
- new JTextArea(Resources.getString("notSupported"));
+ new JTextArea(Resources.getString("contactInfoNotSupported"));
unsupportedTextArea.setEditable(false);
unsupportedTextArea.setLineWrap(true);
@@ -169,7 +169,7 @@ public class ContactInfoDetailsPanel if (bytes != null)
avatarImage = new ImageIcon(bytes);
else
- avatarImage = Resources.getImage("defaultPersonIcon");
+ avatarImage = Resources.getImage("contactInfoDefaultPersonIcon");
ImageIcon scaledImage =
new ImageIcon(avatarImage.getImage().getScaledInstance(105, 130,
diff --git a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoDialog.java b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoDialog.java index c4ea25a..7e828a9 100644 --- a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoDialog.java +++ b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoDialog.java @@ -52,11 +52,11 @@ public class ContactInfoDialog */
public ContactInfoDialog(MetaContact metaContact)
{
- super(Resources.getString("contactInfo"));
+ super(Resources.getString("contactDetails"));
this.metaContact = metaContact;
- this.setTitle(Resources.getString("contactInfo")
+ this.setTitle(Resources.getString("contactDetails")
+ ": "
+ metaContact.getDisplayName());
diff --git a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoMenuItem.java b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoMenuItem.java index c612bf8..dce3bfb 100644 --- a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoMenuItem.java +++ b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoMenuItem.java @@ -25,7 +25,7 @@ public class ContactInfoMenuItem {
private JMenuItem menuItem
= new JMenuItem(Resources.getString("contactInfo"),
- Resources.getImage("infoIcon"));
+ Resources.getImage("contactInfoIcon"));
private MetaContact metaContact;
diff --git a/src/net/java/sip/communicator/plugin/contactinfo/Resources.java b/src/net/java/sip/communicator/plugin/contactinfo/Resources.java index 77fda90..5f72602 100644 --- a/src/net/java/sip/communicator/plugin/contactinfo/Resources.java +++ b/src/net/java/sip/communicator/plugin/contactinfo/Resources.java @@ -14,8 +14,11 @@ import java.util.*; import javax.imageio.*;
import javax.swing.*;
+import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
+import org.osgi.framework.*;
+
/**
* The <tt>Resources</tt> class manages the access to the internationalization
* properties files and the image resources used in this plugin.
@@ -26,31 +29,7 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class);
- /**
- * The name of the resource, where internationalization strings for this
- * plugin are stored.
- */
- private static final String STRING_RESOURCE_NAME
- = "resources.languages.plugin.contactinfo.resources";
-
- /**
- * The name of the resource, where paths to images used in this bundle are
- * stored.
- */
- private static final String IMAGE_RESOURCE_NAME
- = "net.java.sip.communicator.plugin.contactinfo.resources";
-
- /**
- * The string resource bundle.
- */
- private static final ResourceBundle STRING_RESOURCE_BUNDLE
- = ResourceBundle.getBundle(STRING_RESOURCE_NAME);
-
- /**
- * The image resource bundle.
- */
- private static final ResourceBundle IMAGE_RESOURCE_BUNDLE
- = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME);
+ private static ResourceManagementService resourcesService;
/**
* Returns an internationalized string corresponding to the given key.
@@ -59,15 +38,7 @@ public class Resources { */
public static String getString(String key)
{
- try
- {
- return STRING_RESOURCE_BUNDLE.getString(key);
-
- }
- catch (MissingResourceException e)
- {
- return '!' + key + '!';
- }
+ return getResources().getI18NString(key);
}
/**
@@ -79,18 +50,39 @@ public class Resources { {
BufferedImage image = null;
- String path = IMAGE_RESOURCE_BUNDLE.getString(imageID);
-
+ InputStream in =
+ getResources().getImageInputStream(imageID);
+
+ if(in == null)
+ return null;
+
try
{
- image = ImageIO.read(Resources.class.getClassLoader()
- .getResourceAsStream(path));
+ image = ImageIO.read(in);
}
catch (IOException e)
{
- log.error("Failed to load image:" + path, e);
+ log.error("Failed to load image:" + imageID, e);
}
return new ImageIcon(image);
}
+
+ public static ResourceManagementService getResources()
+ {
+ if (resourcesService == null)
+ {
+ ServiceReference serviceReference = ContactInfoActivator.bundleContext
+ .getServiceReference(ResourceManagementService.class.getName());
+
+ if(serviceReference == null)
+ return null;
+
+ resourcesService =
+ (ResourceManagementService)ContactInfoActivator.bundleContext
+ .getService(serviceReference);
+ }
+
+ return resourcesService;
+ }
}
diff --git a/src/net/java/sip/communicator/plugin/contactinfo/contactinfo.manifest.mf b/src/net/java/sip/communicator/plugin/contactinfo/contactinfo.manifest.mf index 530dcec..2fdc1e8 100644 --- a/src/net/java/sip/communicator/plugin/contactinfo/contactinfo.manifest.mf +++ b/src/net/java/sip/communicator/plugin/contactinfo/contactinfo.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1
Import-Package: org.osgi.framework,
net.java.sip.communicator.util,
+ net.java.sip.communicator.service.resources,
net.java.sip.communicator.service.contactlist,
net.java.sip.communicator.service.contactlist.event,
net.java.sip.communicator.service.gui,
diff --git a/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultColorPackImpl.java b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultColorPackImpl.java new file mode 100644 index 0000000..5c4ac6e --- /dev/null +++ b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultColorPackImpl.java @@ -0,0 +1,33 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.defaultresourcepack; + +import net.java.sip.communicator.service.resources.*; + +/** + * + * @author Damian Minkov + */ +public class DefaultColorPackImpl + implements ColorPack +{ + + public String getResourcePackBaseName() + { + return "resources.colors.colorResources"; + } + + public String getName() + { + return "Default Color Resources"; + } + + public String getDescription() + { + return "Provide SIP Communicator default Color resource pack."; + } +} diff --git a/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultImagePackImpl.java b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultImagePackImpl.java new file mode 100644 index 0000000..b8b9779 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultImagePackImpl.java @@ -0,0 +1,33 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.defaultresourcepack; + +import net.java.sip.communicator.service.resources.*; + +/** + * + * @author Damian Minkov + */ +public class DefaultImagePackImpl + implements ImagePack +{ + + public String getResourcePackBaseName() + { + return "resources.images.images"; + } + + public String getName() + { + return "Default Image Resources"; + } + + public String getDescription() + { + return "Provide SIP Communicator default Image resource pack."; + } +} diff --git a/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultLanguagePackImpl.java b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultLanguagePackImpl.java new file mode 100644 index 0000000..e9dc7f0 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultLanguagePackImpl.java @@ -0,0 +1,100 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.defaultresourcepack; + +import java.io.*; +import java.net.*; +import java.util.*; +import java.util.jar.*; + +import net.java.sip.communicator.service.resources.*; +import net.java.sip.communicator.util.*; + +/** + * + * @author Damian Minkov + */ +public class DefaultLanguagePackImpl + implements LanguagePack +{ + private Logger logger = Logger.getLogger(DefaultLanguagePackImpl.class); + + private ArrayList localeList = new ArrayList(); + + public DefaultLanguagePackImpl() + { + try + { + JarFile jf = new JarFile(getJarfileName()); + + Enumeration resources = jf.entries(); + while (resources.hasMoreElements()) + { + JarEntry je = (JarEntry) resources.nextElement(); + + Locale locale; + String entryName = je.getName(); + if (entryName.matches("resources/languages/.*\\.properties")) + { + int localeIndex = entryName.indexOf('_'); + + if (localeIndex == -1) + locale = new Locale("EN"); + else + { + String localeName = + entryName.substring(localeIndex + 1, + entryName.indexOf('.')); + + locale = new Locale(localeName); + } + + localeList.add(locale); + } + } + } + catch (java.io.IOException e) + { + logger.error("Cannot load locales.", e); + } + } + + public String getResourcePackBaseName() + { + return "resources.languages.resources"; + } + + public Iterator getAvailableLocales() + { + return localeList.iterator(); + } + + public String getName() + { + return "Default Language Resources"; + } + + public String getDescription() + { + return "Provide SIP Communicator default Language resource pack."; + } + + private String getJarfileName() + { + // Get the location of the jar file and the jar file name + java.net.URL outputURL = + DefaultLanguagePackImpl.class.getProtectionDomain().getCodeSource() + .getLocation(); + + String outputString = outputURL.toString(); + + String[] parseString; + parseString = outputString.split("file:"); + + String jarFilename = parseString[1]; + return jarFilename; + } +} diff --git a/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultResourcePackActivator.java b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultResourcePackActivator.java new file mode 100644 index 0000000..bc06e4b --- /dev/null +++ b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultResourcePackActivator.java @@ -0,0 +1,94 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.defaultresourcepack; + +import java.util.Hashtable; +import net.java.sip.communicator.service.resources.*; + +import net.java.sip.communicator.util.Logger; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +/** + * + * @author damencho + */ +public class DefaultResourcePackActivator + implements BundleActivator +{ + + private Logger logger = + Logger.getLogger(DefaultResourcePackActivator.class); + private static BundleContext bundleContext; + + public void start(BundleContext bc) throws Exception + { + bundleContext = bc; + + DefaultColorPackImpl colPackImpl = + new DefaultColorPackImpl(); + + Hashtable props = new Hashtable(); + props.put(ColorPack.RESOURCE_NAME, + ColorPack.RESOURCE_NAME_DEFAULT_VALUE); + + bundleContext.registerService( ColorPack.class.getName(), + colPackImpl, + props); + + DefaultImagePackImpl imgPackImpl = + new DefaultImagePackImpl(); + + Hashtable imgProps = new Hashtable(); + imgProps.put(ImagePack.RESOURCE_NAME, + ImagePack.RESOURCE_NAME_DEFAULT_VALUE); + + bundleContext.registerService( ImagePack.class.getName(), + imgPackImpl, + imgProps); + + DefaultLanguagePackImpl langPackImpl = + new DefaultLanguagePackImpl(); + + Hashtable langProps = new Hashtable(); + langProps.put(LanguagePack.RESOURCE_NAME, + LanguagePack.RESOURCE_NAME_DEFAULT_VALUE); + + bundleContext.registerService( LanguagePack.class.getName(), + langPackImpl, + langProps); + + DefaultSettingsPackImpl setPackImpl = + new DefaultSettingsPackImpl(); + + Hashtable setProps = new Hashtable(); + langProps.put(SettingsPack.RESOURCE_NAME, + SettingsPack.RESOURCE_NAME_DEFAULT_VALUE); + + bundleContext.registerService( SettingsPack.class.getName(), + setPackImpl, + setProps); + + DefaultSoundPackImpl sndPackImpl = + new DefaultSoundPackImpl(); + + Hashtable sndProps = new Hashtable(); + langProps.put(SoundPack.RESOURCE_NAME, + SoundPack.RESOURCE_NAME_DEFAULT_VALUE); + + bundleContext.registerService( SoundPack.class.getName(), + sndPackImpl, + sndProps); + + logger.info("Default resources ... [REGISTERED]"); + } + + public void stop(BundleContext bc) throws Exception + { + + } +} diff --git a/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultSettingsPackImpl.java b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultSettingsPackImpl.java new file mode 100644 index 0000000..6ec12df --- /dev/null +++ b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultSettingsPackImpl.java @@ -0,0 +1,33 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.defaultresourcepack; + +import net.java.sip.communicator.service.resources.*; + +/** + * + * @author Damian Minkov + */ +public class DefaultSettingsPackImpl + implements SettingsPack +{ + + public String getResourcePackBaseName() + { + return "resources.config.defaults"; + } + + public String getName() + { + return "Default Settings Resources"; + } + + public String getDescription() + { + return "Provide SIP Communicator default Settings resource pack."; + } +} diff --git a/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultSoundPackImpl.java b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultSoundPackImpl.java new file mode 100644 index 0000000..82e10ed --- /dev/null +++ b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultSoundPackImpl.java @@ -0,0 +1,33 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.defaultresourcepack; + +import net.java.sip.communicator.service.resources.*; + +/** + * + * @author Damian Minkov + */ +public class DefaultSoundPackImpl + implements SoundPack +{ + + public String getResourcePackBaseName() + { + return "resources.sounds.sounds"; + } + + public String getName() + { + return "Default Sounds Resources"; + } + + public String getDescription() + { + return "Provide SIP Communicator default Sounds resource pack."; + } +} diff --git a/src/net/java/sip/communicator/plugin/defaultresourcepack/defaultresourcepack.manifest.mf b/src/net/java/sip/communicator/plugin/defaultresourcepack/defaultresourcepack.manifest.mf new file mode 100644 index 0000000..182caf1 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/defaultresourcepack/defaultresourcepack.manifest.mf @@ -0,0 +1,8 @@ +Bundle-Activator: net.java.sip.communicator.plugin.defaultresourcepack.DefaultResourcePackActivator +Bundle-Name: Default Resource Pack +Bundle-Description: The plugin offering default images and languages. +Bundle-Vendor: sip-communicator.org +Bundle-Version: 0.0.1 +Import-Package: org.osgi.framework, + net.java.sip.communicator.util, + net.java.sip.communicator.service.resources diff --git a/src/net/java/sip/communicator/plugin/dictaccregwizz/DictAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/dictaccregwizz/DictAccountRegistrationWizard.java index 7fa4f61..1d48b41 100644 --- a/src/net/java/sip/communicator/plugin/dictaccregwizz/DictAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/dictaccregwizz/DictAccountRegistrationWizard.java @@ -86,7 +86,7 @@ public class DictAccountRegistrationWizard */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameDict"); } /** @@ -96,7 +96,7 @@ public class DictAccountRegistrationWizard */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionDict"); } /** diff --git a/src/net/java/sip/communicator/plugin/dictaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/dictaccregwizz/Resources.java index 4266c2c..348f0f6 100644 --- a/src/net/java/sip/communicator/plugin/dictaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/dictaccregwizz/Resources.java @@ -10,8 +10,11 @@ package net.java.sip.communicator.plugin.dictaccregwizz; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -23,35 +26,11 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.dictaccregwizz.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.dictaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); + private static ResourceManagementService resourcesService; - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); + public static ImageID DICT_LOGO = new ImageID("protocolIconDict"); - public static ImageID DICT_LOGO = new ImageID("protocolIcon"); - - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageDict"); /** * Returns an internationalized string corresponding to the given key. @@ -61,15 +40,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } - //return '!' + key + '!'; + return getResources().getI18NString(key); } /** @@ -79,20 +50,24 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; - - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); + InputStream in = + getResources().getImageInputStream(imageID.getId()); + if(in == null) + return null; + + byte[] image = null; + try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + image = new byte[in.available()]; + in.read(image); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } - + return image; } @@ -113,4 +88,22 @@ public class Resources return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = DictAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)DictAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/dictaccregwizz/dictaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/dictaccregwizz/dictaccregwizz.manifest.mf index 4dcab77..c1c4169 100644 --- a/src/net/java/sip/communicator/plugin/dictaccregwizz/dictaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/dictaccregwizz/dictaccregwizz.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/ExtendedCallHistorySearchActivator.java b/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/ExtendedCallHistorySearchActivator.java index 9dd5efa..9847c8f 100644 --- a/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/ExtendedCallHistorySearchActivator.java +++ b/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/ExtendedCallHistorySearchActivator.java @@ -26,7 +26,7 @@ public class ExtendedCallHistorySearchActivator private Logger logger = Logger.getLogger(ExtendedCallHistorySearchActivator.class); - private static BundleContext context; + static BundleContext context; public void start(BundleContext bc) throws Exception { diff --git a/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/Resources.java b/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/Resources.java index e5c61a9..876a378 100644 --- a/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/Resources.java +++ b/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/Resources.java @@ -14,8 +14,11 @@ import java.util.*; import javax.imageio.*; import javax.swing.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files, image resources and color resources used in this plugin. @@ -26,37 +29,7 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.extendedcallhistorysearch.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.extendedcallhistorysearch.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); - - private static final String COLOR_BUNDLE_NAME - = "resources.colors.colorResources"; - - private static final ResourceBundle COLOR_RESOURCE_BUNDLE - = ResourceBundle.getBundle(COLOR_BUNDLE_NAME); + private static ResourceManagementService resourcesService; /** * Returns an internationalized string corresponding to the given key. @@ -65,28 +38,7 @@ public class Resources { */ public static String getString(String key) { - String resourceString; - - try - { - resourceString = STRING_RESOURCE_BUNDLE.getString(key); - - int mnemonicIndex = resourceString.indexOf('&'); - - if(mnemonicIndex > -1) - { - String firstPart = resourceString.substring(0, mnemonicIndex); - String secondPart = resourceString.substring(mnemonicIndex + 1); - - resourceString = firstPart.concat(secondPart); - } - } - catch (MissingResourceException e) - { - resourceString = '!' + key + '!'; - } - - return resourceString; + return getResources().getI18NString(key); } /** @@ -99,17 +51,19 @@ public class Resources { { BufferedImage image = null; - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID); - + InputStream in = + getResources().getImageInputStream(imageID); + + if(in == null) + return null; + try { - image = ImageIO.read(Resources.class.getClassLoader() - .getResourceAsStream(path)); - + image = ImageIO.read(in); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return new ImageIcon(image); @@ -123,23 +77,7 @@ public class Resources { */ public static char getMnemonic(String key) { - String resourceString; - try - { - resourceString = STRING_RESOURCE_BUNDLE.getString(key); - - int mnemonicIndex = resourceString.indexOf('&'); - - if(mnemonicIndex > -1) - { - return resourceString.charAt(mnemonicIndex + 1); - } - } - catch (MissingResourceException e) - { - return '!'; - } - return '!'; + return getResources().getI18nMnemonic(key); } /** @@ -151,15 +89,24 @@ public class Resources { */ public static int getColor(String key) { - try + return getResources().getColor(key); + } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) { - return Integer.parseInt(COLOR_RESOURCE_BUNDLE.getString(key), 16); + ServiceReference serviceReference = ExtendedCallHistorySearchActivator.context + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)ExtendedCallHistorySearchActivator.context + .getService(serviceReference); } - catch (MissingResourceException e) - { - log.error("Missing color resource.", e); - return 0xFFFFFF; - } + return resourcesService; } } diff --git a/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/extendedcallhistorysearch.manifest.mf b/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/extendedcallhistorysearch.manifest.mf index b73a13f..df4af89 100644 --- a/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/extendedcallhistorysearch.manifest.mf +++ b/src/net/java/sip/communicator/plugin/extendedcallhistorysearch/extendedcallhistorysearch.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.contactlist, net.java.sip.communicator.service.contactlist.event, net.java.sip.communicator.service.gui, diff --git a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationForm.java b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationForm.java index e325fd9..613f85c 100644 --- a/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationForm.java +++ b/src/net/java/sip/communicator/plugin/generalconfig/GeneralConfigurationForm.java @@ -265,7 +265,7 @@ public class GeneralConfigurationForm public byte[] getIcon() { - return Resources.getImage("pluginIcon"); + return Resources.getImage("pluginIconGeneralConfig"); } public String getTitle() diff --git a/src/net/java/sip/communicator/plugin/generalconfig/Resources.java b/src/net/java/sip/communicator/plugin/generalconfig/Resources.java index aab180e..6804cdc 100644 --- a/src/net/java/sip/communicator/plugin/generalconfig/Resources.java +++ b/src/net/java/sip/communicator/plugin/generalconfig/Resources.java @@ -10,8 +10,11 @@ package net.java.sip.communicator.plugin.generalconfig; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -22,44 +25,7 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.generalconfig.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.generalconfig.resources"; - - /** - * The name of the resource, where application properties are - * stored. - */ - private static final String APPLICATION_RESUORCE_LOCATION - = "resources.application"; - - /** - * The application resource bundle. - */ - private static final ResourceBundle APPLICATION_RESOURCE_BUNDLE - = ResourceBundle.getBundle(APPLICATION_RESUORCE_LOCATION); - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); + private static ResourceManagementService resourcesService; /** * Returns an internationalized string corresponding to the given key. @@ -68,14 +34,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -85,14 +44,7 @@ public class Resources */ public static String getApplicationString(String key) { - try - { - return APPLICATION_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getSettingsString(key); } /** @@ -102,19 +54,42 @@ public class Resources */ public static byte[] getImage(String imageId) { - byte[] image = new byte[100000]; + InputStream in = + getResources().getImageInputStream(imageId); + + if(in == null) + return null; + + byte[] image = null; - String path = IMAGE_RESOURCE_BUNDLE.getString(imageId); try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + image = new byte[in.available()]; + in.read(image); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageId, e); } return image; } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = GeneralConfigPluginActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)GeneralConfigPluginActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/generalconfig/generalconfig.manifest.mf b/src/net/java/sip/communicator/plugin/generalconfig/generalconfig.manifest.mf index 44332fd..1dc25ed 100644 --- a/src/net/java/sip/communicator/plugin/generalconfig/generalconfig.manifest.mf +++ b/src/net/java/sip/communicator/plugin/generalconfig/generalconfig.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.contactlist, net.java.sip.communicator.service.contactlist.event, net.java.sip.communicator.service.gui, diff --git a/src/net/java/sip/communicator/plugin/gibberishaccregwizz/GibberishAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/gibberishaccregwizz/GibberishAccountRegistrationWizard.java index 7ca29ee..54d0424 100644 --- a/src/net/java/sip/communicator/plugin/gibberishaccregwizz/GibberishAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/gibberishaccregwizz/GibberishAccountRegistrationWizard.java @@ -86,7 +86,7 @@ public class GibberishAccountRegistrationWizard */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameGibberish"); } /** @@ -96,7 +96,7 @@ public class GibberishAccountRegistrationWizard */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionGibberish"); } /** diff --git a/src/net/java/sip/communicator/plugin/gibberishaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/gibberishaccregwizz/Resources.java index 0010823..afe720b 100644 --- a/src/net/java/sip/communicator/plugin/gibberishaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/gibberishaccregwizz/Resources.java @@ -8,10 +8,12 @@ package net.java.sip.communicator.plugin.gibberishaccregwizz; import java.io.*; -import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -23,41 +25,17 @@ public class Resources private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.gibberishaccregwizz.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.gibberishaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); + private static ResourceManagementService resourcesService; /** * A constant pointing to the Gibberish protocol logo icon. */ - public static ImageID GIBBERISH_LOGO = new ImageID("protocolIcon"); + public static ImageID GIBBERISH_LOGO = new ImageID("protocolIconGibberish"); /** * A constant pointing to the Gibberish protocol wizard page image. */ - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageGibberish"); /** * Returns an internationalized string corresponding to the given key. @@ -67,14 +45,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException exc) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -85,18 +56,22 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; - - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + image = new byte[in.available()]; + in.read(image); } - catch (IOException exc) + catch (IOException e) { - log.error("Failed to load image:" + path, exc); + log.error("Failed to load image:" + imageID, e); } return image; @@ -119,5 +94,22 @@ public class Resources return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = GibberishAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)GibberishAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/gibberishaccregwizz/gibberishaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/gibberishaccregwizz/gibberishaccregwizz.manifest.mf index 13505e1..06d5959 100644 --- a/src/net/java/sip/communicator/plugin/gibberishaccregwizz/gibberishaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/gibberishaccregwizz/gibberishaccregwizz.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/FirstWizardPage.java index 776b02e..f0b3309 100644 --- a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/FirstWizardPage.java @@ -41,7 +41,7 @@ public class FirstWizardPage private JPanel valuesPanel = new JPanel();
- private JLabel userIDLabel = new JLabel(Resources.getString("username"));
+ private JLabel userIDLabel = new JLabel(Resources.getString("gtalkUsername"));
private JLabel passLabel = new JLabel(Resources.getString("password"));
@@ -95,7 +95,7 @@ public class FirstWizardPage private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
private JTextArea registerArea = new JTextArea(Resources
- .getString("registerNewAccountText"));
+ .getString("gtalkRegisterNewAccountText"));
private JButton registerButton = new JButton(Resources
.getString("registerNewAccount"));
diff --git a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/GoogleTalkAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/GoogleTalkAccountRegistrationWizard.java index ff106a3..fab7a41 100644 --- a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/GoogleTalkAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/GoogleTalkAccountRegistrationWizard.java @@ -116,7 +116,7 @@ public class GoogleTalkAccountRegistrationWizard {
Hashtable summaryTable = new Hashtable();
- summaryTable.put( Resources.getString("username"),
+ summaryTable.put( Resources.getString("gtalkUsername"),
registration.getUserID());
summaryTable.put( Resources.getString("rememberPassword"),
diff --git a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/Resources.java index 889d62f..9e10d2a 100644 --- a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/Resources.java @@ -9,6 +9,9 @@ import java.io.*; import java.util.*;
import net.java.sip.communicator.util.*;
+import net.java.sip.communicator.service.resources.*;
+
+import org.osgi.framework.*;
/**
* The <tt>Resources</tt> class manages the access to the internationalization
@@ -20,32 +23,8 @@ public class Resources {
private static Logger log = Logger.getLogger(Resources.class);
- /**
- * The name of the resource, where internationalization strings for this
- * plugin are stored.
- */
- private static final String STRING_RESOURCE_NAME =
- "resources.languages.plugin.googletalkaccregwizz.resources";
-
- /**
- * The name of the resource, where paths to images used in this bundle are
- * stored.
- */
- private static final String RESOURCE_NAME =
- "net.java.sip.communicator.plugin.googletalkaccregwizz.resources";
-
- /**
- * The string resource bundle.
- */
- private static final ResourceBundle STRING_RESOURCE_BUNDLE =
- ResourceBundle.getBundle(STRING_RESOURCE_NAME);
-
- /**
- * The image resource bundle.
- */
- private static final ResourceBundle RESOURCE_BUNDLE =
- ResourceBundle.getBundle(RESOURCE_NAME);
-
+ private static ResourceManagementService resourcesService;
+
/**
* A constant pointing to the Google Talk protocol logo image.
*/
@@ -64,27 +43,7 @@ public class Resources */
public static String getString(String key)
{
- String resourceString;
- try
- {
- resourceString = STRING_RESOURCE_BUNDLE.getString(key);
-
- int mnemonicIndex = resourceString.indexOf('&');
-
- if (mnemonicIndex > -1)
- {
- String firstPart = resourceString.substring(0, mnemonicIndex);
- String secondPart = resourceString.substring(mnemonicIndex + 1);
-
- resourceString = firstPart.concat(secondPart);
- }
- }
- catch (MissingResourceException e)
- {
- resourceString = '!' + key + '!';
- }
-
- return resourceString;
+ return getResources().getI18NString(key);
}
/**
@@ -95,26 +54,7 @@ public class Resources */
public static char getMnemonic(String key)
{
- String resourceString;
-
- try
- {
- resourceString = STRING_RESOURCE_BUNDLE.getString(key);
-
- int mnemonicIndex = resourceString.indexOf('&');
-
- if (mnemonicIndex > -1)
- {
- return resourceString.charAt(mnemonicIndex + 1);
- }
-
- }
- catch (MissingResourceException e)
- {
- return '!';
- }
-
- return '!';
+ return getResources().getI18nMnemonic(key);
}
/**
@@ -125,18 +65,22 @@ public class Resources */
public static byte[] getImage(ImageID imageID)
{
- byte[] image = new byte[100000];
-
- String path = RESOURCE_BUNDLE.getString(imageID.getId());
+ InputStream in =
+ getResources().getImageInputStream(imageID.getId());
+
+ if(in == null)
+ return null;
+
+ byte[] image = null;
try
{
- Resources.class.getClassLoader().getResourceAsStream(path).read(
- image);
+ image = new byte[in.available()];
+ in.read(image);
}
catch (IOException e)
{
- log.error("Failed to load image:" + path, e);
+ log.error("Failed to load image:" + imageID, e);
}
return image;
@@ -151,14 +95,7 @@ public class Resources */
public static String getProperty(String key)
{
- try
- {
- return RESOURCE_BUNDLE.getString(key);
- }
- catch (MissingResourceException e)
- {
- return '!' + key + '!';
- }
+ return getResources().getI18NString(key);
}
/**
@@ -178,4 +115,22 @@ public class Resources return id;
}
}
+
+ public static ResourceManagementService getResources()
+ {
+ if (resourcesService == null)
+ {
+ ServiceReference serviceReference = GoogleTalkAccRegWizzActivator.bundleContext
+ .getServiceReference(ResourceManagementService.class.getName());
+
+ if(serviceReference == null)
+ return null;
+
+ resourcesService =
+ (ResourceManagementService)GoogleTalkAccRegWizzActivator.bundleContext
+ .getService(serviceReference);
+ }
+
+ return resourcesService;
+ }
}
diff --git a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/googletalkaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/googletalkaccregwizz.manifest.mf index 6266fce..4b4936f 100644 --- a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/googletalkaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/googletalkaccregwizz.manifest.mf @@ -6,6 +6,7 @@ Bundle-Version: 0.0.1 Import-Package: org.osgi.framework,
net.java.sip.communicator.util,
net.java.sip.communicator.service.configuration,
+ net.java.sip.communicator.service.resources,
net.java.sip.communicator.service.configuration.event,
net.java.sip.communicator.service.protocol,
net.java.sip.communicator.service.protocol.icqconstants,
diff --git a/src/net/java/sip/communicator/plugin/guicustomization/ButtonTableCellRenderer.java b/src/net/java/sip/communicator/plugin/guicustomization/ButtonTableCellRenderer.java new file mode 100644 index 0000000..0bccc08 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/ButtonTableCellRenderer.java @@ -0,0 +1,46 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.guicustomization; + +import java.awt.*; +import javax.swing.*; +import javax.swing.table.*; + +/** + * Custom <tt>TableCellRenderer</tt> that renders + * <tt>ProtocolProviderService</tt> objects, <tt>MetaContactGroup</tt> + * objects and JLabels. + * + * @author Yana Stamcheva + */ +public class ButtonTableCellRenderer + extends JPanel + implements TableCellRenderer +{ + public ButtonTableCellRenderer() + { + super(new FlowLayout(FlowLayout.CENTER)); + + this.setOpaque(true); + } + + public Component getTableCellRendererComponent( JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) + { + this.removeAll(); + + if(value instanceof JButton) + { + this.add((JButton) value); + } + + return this; + } +}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/guicustomization/ButtonTableEditor.java b/src/net/java/sip/communicator/plugin/guicustomization/ButtonTableEditor.java new file mode 100644 index 0000000..c8b793f --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/ButtonTableEditor.java @@ -0,0 +1,58 @@ +package net.java.sip.communicator.plugin.guicustomization; + +import java.awt.*; + +import javax.swing.*; + +/** + * @version 1.0 11/09/98 + */ +public class ButtonTableEditor + extends DefaultCellEditor +{ + private JButton button; + + private JPanel buttonPanel; + + private boolean isPushed; + + public ButtonTableEditor() + { + super(new JCheckBox()); + } + + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, int row, int column) + { + isPushed = true; + if (value instanceof JButton) + { + this.button = (JButton) value; + + buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); + + buttonPanel.add(button); + + return buttonPanel; + } + + return null; + } + + public Object getCellEditorValue() + { + isPushed = false; + return button; + } + + public boolean stopCellEditing() + { + isPushed = false; + return super.stopCellEditing(); + } + + protected void fireEditingStopped() + { + super.fireEditingStopped(); + } +}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/guicustomization/ColorsPanel.java b/src/net/java/sip/communicator/plugin/guicustomization/ColorsPanel.java new file mode 100644 index 0000000..ce3853f --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/ColorsPanel.java @@ -0,0 +1,105 @@ +package net.java.sip.communicator.plugin.guicustomization; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; + +import javax.swing.*; +import javax.swing.table.*; + +public class ColorsPanel + extends JScrollPane +{ + private JTable colorsTable = new JTable(); + + private CustomTableModel colorsTableModel = new CustomTableModel(); + + public ColorsPanel() + { + this.getViewport().add(colorsTable); + + colorsTable.setModel(colorsTableModel); + colorsTableModel.addColumn("Description"); + colorsTableModel.addColumn("Color"); + colorsTableModel.addColumn("Change color"); + + colorsTable.getColumnModel().getColumn(1).setCellRenderer( + new LabelTableCellRenderer()); + + TableColumn buttonColumn + = colorsTable.getColumnModel().getColumn(2); + + buttonColumn.setCellRenderer(new ButtonTableCellRenderer()); + buttonColumn.setCellEditor(new ButtonTableEditor()); + + this.initColorTable(); + } + + private void initColorTable() + { + Iterator colorKeys + = GuiCustomizationActivator.getResources() + .getCurrentColors(); + + while (colorKeys.hasNext()) + { + String key = (String) colorKeys.next(); + final Color color = new Color( + GuiCustomizationActivator.getResources().getColor(key)); + + final JLabel colorLabel = new JLabel(); + colorLabel.setBackground(color); + + JButton colorChooserButton = new JButton(); + colorChooserButton.setAction( + new ChooseColorAction(color, colorLabel)); + + colorsTableModel.addRow(new Object[]{ key, + colorLabel, + colorChooserButton}); + colorChooserButton.setText("Choose a colour"); + + int rowHeight = 40; + colorsTable.setRowHeight( colorsTableModel.getRowCount() - 1, + rowHeight ); + } + } + + private class ChooseColorAction extends AbstractAction + { + private Color defaultColor; + private JLabel colorLabel; + + public ChooseColorAction(Color defaultColor, JLabel colorLabel) + { + this.defaultColor = defaultColor; + this.colorLabel = colorLabel; + } + public void actionPerformed(ActionEvent evt) + { + Color newColor + = JColorChooser.showDialog( new JColorChooser(), + "Choose a colour", + defaultColor); + + colorLabel.setBackground(newColor); + } + } + + Hashtable<String, String> getColors() + { + Hashtable res = new Hashtable(); + int rows = colorsTableModel.getRowCount(); + for (int i = 0; i < rows; i++) + { + String key = (String)colorsTableModel.getValueAt(i, 0); + JLabel colorLabel = (JLabel)colorsTableModel.getValueAt(i, 1); + + res.put( + key, + Integer.toHexString(colorLabel.getBackground().getRGB()).substring(2)); + } + + return res; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/CustomTableModel.java b/src/net/java/sip/communicator/plugin/guicustomization/CustomTableModel.java new file mode 100644 index 0000000..f969415 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/CustomTableModel.java @@ -0,0 +1,18 @@ +package net.java.sip.communicator.plugin.guicustomization; + +import javax.swing.*; +import javax.swing.table.*; + +public class CustomTableModel + extends DefaultTableModel +{ + public boolean isCellEditable(int row, int column) + { + Object o = getValueAt(row, column); + + if (column == 0 || o instanceof JLabel) + return false; + + return true; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/CustomizationWindow.java b/src/net/java/sip/communicator/plugin/guicustomization/CustomizationWindow.java new file mode 100644 index 0000000..8290fa8 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/CustomizationWindow.java @@ -0,0 +1,349 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. See terms of license at gnu.org. + */ +/* + * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI + * Builder, which is free for non-commercial use. If Jigloo is being used + * commercially (ie, by a corporation, company or business for any purpose + * whatever) then you should purchase a license for each developer using Jigloo. + * Please visit www.cloudgarden.com for details. Use of Jigloo implies + * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN + * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR + * ANY CORPORATE OR COMMERCIAL PURPOSE. + */ +package net.java.sip.communicator.plugin.guicustomization; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.net.URL; +import java.util.*; +import java.util.jar.*; +import java.util.zip.*; +import javax.swing.*; + +import net.java.sip.communicator.plugin.guicustomization.resourcepack.*; +import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + +public class CustomizationWindow + extends JFrame +{ + private JTabbedPane tabbedPane; + + private ImagesPanel imagesPanel; + + private SoundsPanel soundsPanel; + + private ColorsPanel colorsPanel; + + private I18nStringsPanel stringsPanel; + + private SettingsPanel settingsPanel; + + private Logger logger = Logger.getLogger(CustomizationWindow.class); + + private JButton saveProjectButton = new JButton("Create Skin"); + + private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + + private final String srcPackagePath = + "/net/java/sip/communicator/plugin/guicustomization/resourcepack"; + private final String manifestFileName = "customresourcepack.manifest.mf"; + + private final String[] customClassFiles = new String[]{ + "CustomColorPackImpl", + "CustomImagePackImpl", + "CustomLanguagePackImpl", + "CustomResourcePackActivator", + "CustomSettingsPackImpl", + "CustomSoundPackImpl" + }; + + private final String dstPackagePath = + "net/java/sip/communicator/plugin/guicustomization/resourcepack"; + + public CustomizationWindow() + { + super("SIP Communicator Branding Studio"); + + this.initGUI(); + } + + private void initGUI() + { + this.imagesPanel = new ImagesPanel(this); + this.colorsPanel = new ColorsPanel(); + this.soundsPanel = new SoundsPanel(this); + this.stringsPanel = new I18nStringsPanel(); + this.settingsPanel = new SettingsPanel(); + + this.tabbedPane = new JTabbedPane(); + this.getContentPane().add(tabbedPane, BorderLayout.CENTER); + this.getContentPane().add(buttonPanel, BorderLayout.SOUTH); + + this.tabbedPane.addTab("Images", imagesPanel); + this.tabbedPane.addTab("Colors", colorsPanel); + this.tabbedPane.addTab("Sounds", soundsPanel); + this.tabbedPane.addTab("Strings", stringsPanel); + this.tabbedPane.addTab("Settings", settingsPanel); + + this.buttonPanel.add(saveProjectButton); + + this.saveProjectButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent arg0) + { + //TODO: Implement jar creation here. + performSaveProject(); + } + }); + + this.setSize(570, 337); + } + + private void performSaveProject() + { + try + { + File file = null; + + JFileChooser fileChooser = new JFileChooser(); + + fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + fileChooser.setDialogTitle("Select Destination"); + fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); + + int result + = fileChooser.showOpenDialog(CustomizationWindow.this); + + if (result == JFileChooser.APPROVE_OPTION) + { + file = fileChooser.getSelectedFile(); + file = new File(file, "customresources.jar"); + } + else + return; + + + InputStream manifestIs = + CustomizationWindow.class. + getResource(srcPackagePath + "/" + manifestFileName). + openStream(); + + JarOutputStream outFile = + new JarOutputStream( + new FileOutputStream(file), + new Manifest(manifestIs)); + + for (int i = 0; i < customClassFiles.length; i++) + { + String cf = customClassFiles[i]; + + InputStream clIs = + CustomizationWindow.class. + getResourceAsStream(srcPackagePath + "/" + cf + ".class"); + byte[] bs = new byte[clIs.available()]; + clIs.read(bs); + clIs.close(); + + addNewZipEntry(dstPackagePath + "/" + cf + ".class", outFile, bs); + } + + saveColorPack(outFile); + saveImagePack(outFile); + saveLanguagePack(outFile); + saveSettingsPack(outFile); + saveSoundsPack(outFile); + + outFile.flush(); + outFile.close(); + manifestIs.close(); + } + catch (Exception e) + { + + logger.error("",e); + } + } + + private void saveColorPack(JarOutputStream outFile) + throws Exception + { + String resources = + new CustomColorPackImpl().getResourcePackBaseName(); + + Properties props = new Properties(); + + Hashtable h = colorsPanel.getColors(); + Iterator<String> iter = h.keySet().iterator(); + while (iter.hasNext()) + { + String k = iter.next(); + props.put(k, h.get(k)); + } + + ByteArrayOutputStream outB = new ByteArrayOutputStream(); + props.store(outB, "Custom Color resources"); + + addNewZipEntry(resources.replaceAll("\\.", "/") + ".properties", + outFile, outB.toByteArray()); + } + + private void saveImagePack(JarOutputStream outFile) + throws Exception + { + String resources = + new CustomImagePackImpl().getResourcePackBaseName(); + + Properties props = new Properties(); + String imagePathPrefix = "resources/images/"; + int imageName = 0; + + Hashtable<String, byte[]> h = imagesPanel.getImages(); + Iterator<String> iter = h.keySet().iterator(); + while (iter.hasNext()) + { + String k = iter.next(); + String fileName = imagePathPrefix + String.valueOf(imageName++) + ".png"; + byte[] bs = h.get(k); + + if(bs.length > 0) + { + props.put(k, fileName); + + addNewZipEntry(fileName, + outFile, bs); + } + else + props.put(k, ""); + } + ByteArrayOutputStream outB = new ByteArrayOutputStream(); + props.store(outB, "Custom Color resources"); + + addNewZipEntry(resources.replaceAll("\\.", "/") + ".properties", + outFile, outB.toByteArray()); + } + + private void saveLanguagePack(JarOutputStream outFile) + throws Exception + { + String resources = + new CustomLanguagePackImpl().getResourcePackBaseName(); + + Hashtable languages = stringsPanel.getLanguages(); + Iterator<String> iter = languages.keySet().iterator(); + while (iter.hasNext()) + { + String l = iter.next(); + Properties props = new Properties(); + + Hashtable<String,String> strings = (Hashtable<String,String>)languages.get(l); + + Iterator<String> stringsIter = strings.keySet().iterator(); + while (stringsIter.hasNext()) + { + String k = stringsIter.next(); + String v = strings.get(k); + + props.put(k, v); + } + + String filename = null; + if(l.equals("en")) + filename = + resources.replaceAll("\\.", "/") + ".properties"; + else + filename = + resources.replaceAll("\\.", "/") + "_" + l + ".properties"; + + ByteArrayOutputStream outB = new ByteArrayOutputStream(); + props.store(outB, "Custom Color resources"); + + addNewZipEntry(filename, + outFile, outB.toByteArray()); + } + } + + private void saveSettingsPack(JarOutputStream outFile) + throws Exception + { + String resources = + new CustomSettingsPackImpl().getResourcePackBaseName(); + + Properties props = new Properties(); + + Hashtable h = settingsPanel.getSettings(); + Iterator<String> iter = h.keySet().iterator(); + while (iter.hasNext()) + { + String k = iter.next(); + props.put(k, h.get(k)); + } + + ByteArrayOutputStream outB = new ByteArrayOutputStream(); + props.store(outB, "Custom Color resources"); + + addNewZipEntry(resources.replaceAll("\\.", "/") + ".properties", + outFile, outB.toByteArray()); + + // fix for missing styles, must also add the styles css + String entryName = + GuiCustomizationActivator.getResources().getSettingsString("textStyle"); + InputStream in = + GuiCustomizationActivator.getResources().getSettingsInputStream("textStyle"); + byte[] bs = new byte[in.available()]; + in.read(bs); + in.close(); + + addNewZipEntry(entryName, outFile, bs); + } + + private void saveSoundsPack(JarOutputStream outFile) + throws Exception + { + String resources = + new CustomSoundPackImpl().getResourcePackBaseName(); + + Properties props = new Properties(); + + String sndPathPrefix = "resources/sounds/"; + int sndName = 0; + + Hashtable<String,URL> h = soundsPanel.getSounds(); + Iterator<String> iter = h.keySet().iterator(); + while (iter.hasNext()) + { + String k = iter.next(); + URL u = h.get(k); + + String fileName = sndPathPrefix + String.valueOf(sndName++); + + props.put(k, fileName); + + InputStream in = u.openStream(); + byte[] bs = new byte[in.available()]; + in.read(bs); + + addNewZipEntry(fileName, + outFile, bs); + } + + ByteArrayOutputStream outB = new ByteArrayOutputStream(); + props.store(outB, "Custom Color resources"); + + addNewZipEntry(resources.replaceAll("\\.", "/") + ".properties", + outFile, outB.toByteArray()); + } + + private void addNewZipEntry(String name, JarOutputStream outFile, byte[] data) + throws Exception + { + ZipEntry z = new ZipEntry(name); + outFile.putNextEntry(z); + outFile.write(data); + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/GuiCustomizationActivator.java b/src/net/java/sip/communicator/plugin/guicustomization/GuiCustomizationActivator.java new file mode 100644 index 0000000..ef73f11 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/GuiCustomizationActivator.java @@ -0,0 +1,54 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.guicustomization; + +import net.java.sip.communicator.service.resources.*; +import net.java.sip.communicator.util.*; + +import org.osgi.framework.*; + +public class GuiCustomizationActivator implements BundleActivator +{ + private Logger logger = Logger.getLogger(GuiCustomizationActivator.class); + + static BundleContext bundleContext; + + private static ResourceManagementService resourceService; + + public void start(BundleContext bc) throws Exception + { + bundleContext = bc; + +// CustomizationWindow customizationWindow +// = new CustomizationWindow(); +// +// customizationWindow.pack(); +// customizationWindow.setSize(600, 500); +// customizationWindow.setVisible(true); + } + + public void stop(BundleContext bc) throws Exception + { + } + + public static ResourceManagementService getResources() + { + if (resourceService == null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourceService = (ResourceManagementService) bundleContext + .getService(serviceReference); + } + + return resourceService; + } +}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/guicustomization/I18nStringsPanel.java b/src/net/java/sip/communicator/plugin/guicustomization/I18nStringsPanel.java new file mode 100644 index 0000000..fa76a47 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/I18nStringsPanel.java @@ -0,0 +1,228 @@ +package net.java.sip.communicator.plugin.guicustomization; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; + +import javax.swing.*; +import javax.swing.event.*; + +import net.java.sip.communicator.service.resources.*; + +public class I18nStringsPanel + extends JPanel +{ + private JScrollPane tablePane = new JScrollPane(); + + private JScrollPane languageListPane = new JScrollPane(); + + private JTable stringsTable = new JTable(); + + private JList languageList = new JList(); + + private DefaultListModel languageListModel = new DefaultListModel(); + + private JButton addLanguageButton = new JButton("Add new language"); + + private JPanel leftPanel = new JPanel(new BorderLayout()); + + private Hashtable languagesTable = new Hashtable(); + + public I18nStringsPanel() + { + super(new BorderLayout()); + + this.add(tablePane, BorderLayout.CENTER); + this.add(leftPanel, BorderLayout.WEST); + + leftPanel.add(languageListPane, BorderLayout.CENTER); + leftPanel.add(addLanguageButton, BorderLayout.NORTH); + + languageListPane.getViewport().add(languageList); + languageList.setModel(languageListModel); + languageList + .addListSelectionListener(new LanguageListSelectionListener()); + + addLanguageButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent arg0) + { + NewLanguageDialog dialog = new NewLanguageDialog(); + + dialog.pack(); + dialog.setLocation( + (Toolkit.getDefaultToolkit().getScreenSize().width + - dialog.getWidth()) / 2, + (Toolkit.getDefaultToolkit().getScreenSize().height + - dialog.getHeight()) / 2); + dialog.setVisible(true); + } + }); + + tablePane.getViewport().add(stringsTable); + + stringsTable.setShowGrid(true); + stringsTable.setGridColor(Color.GRAY); + + this.initLocalesList(); + this.languageList.setSelectedIndex(0); + } + + private void initLocalesList() + { + ResourceManagementService resourceService + = GuiCustomizationActivator.getResources(); + + Iterator locales = resourceService.getAvailableLocales(); + + Locale locale; + CustomTableModel stringsTableModel; + + while(locales.hasNext()) + { + locale = (Locale) locales.next(); + + languageListModel.addElement(locale.getLanguage()); + + stringsTableModel = new CustomTableModel(); + + stringsTableModel.addColumn("Key"); + stringsTableModel.addColumn("Text"); + + this.initStringsTable(stringsTableModel, locale); + + languagesTable.put( locale.getLanguage(), + stringsTableModel); + } + } + + private void initStringsTable(CustomTableModel tableModel, Locale l) + { + Iterator stringKeys = GuiCustomizationActivator + .getResources().getI18nStringsByLocale(l); + + while (stringKeys.hasNext()) + { + String key = (String) stringKeys.next(); + String value + = GuiCustomizationActivator.getResources() + .getI18NString(key, l); + + tableModel.addRow(new Object[]{ key, value}); + } + } + + private class LanguageListSelectionListener implements ListSelectionListener + { + public void valueChanged(ListSelectionEvent e) + { + if (!e.getValueIsAdjusting()) + { + CustomTableModel newModel + = (CustomTableModel) languagesTable + .get(languageList.getSelectedValue()); + + stringsTable.setModel(newModel); + stringsTable.getColumnModel().getColumn(1) + .setCellRenderer(new TextAreaCellRenderer()); + stringsTable.repaint(); + } + } + } + + private class NewLanguageDialog + extends JDialog + implements ActionListener + { + private JPanel mainPanel = new JPanel(new BorderLayout(5, 5)); + + private JLabel enterLocaleLabel = new JLabel("Enter new locale: "); + + private JComboBox localeBox + = new JComboBox(Locale.getAvailableLocales()); + + private JButton okButton = new JButton("Ok"); + + private JButton cancelButton = new JButton("Cancel"); + + private JPanel buttonPanel + = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + + public NewLanguageDialog() + { + this.getContentPane().add(mainPanel); + + this.mainPanel.add(enterLocaleLabel, BorderLayout.WEST); + this.mainPanel.add(localeBox, BorderLayout.CENTER); + this.mainPanel.add(buttonPanel, BorderLayout.SOUTH); + + this.buttonPanel.add(okButton); + this.buttonPanel.add(cancelButton); + + this.okButton.addActionListener(this); + this.cancelButton.addActionListener(this); + + this.mainPanel.setBorder( + BorderFactory.createEmptyBorder(15, 15, 15, 15)); + this.mainPanel.setPreferredSize(new Dimension(210, 120)); + + this.getRootPane().setDefaultButton(okButton); + } + + public void actionPerformed(ActionEvent evt) + { + JButton button = (JButton) evt.getSource(); + + if (button.equals(okButton)) + { + Locale locale = (Locale)localeBox.getSelectedItem(); + + languageListModel.addElement(locale); + + CustomTableModel stringsTableModel = new CustomTableModel(); + + stringsTableModel.addColumn("Key"); + stringsTableModel.addColumn("Text"); + + initStringsTable(stringsTableModel, locale); + + languagesTable.put( locale, + stringsTableModel); + + this.dispose(); + } + else if (button.equals(cancelButton)) + { + this.dispose(); + } + } + } + + Hashtable<String, Hashtable<String, String>> getLanguages() + { + Hashtable res = new Hashtable(); + Enumeration e = languageListModel.elements(); + while (e.hasMoreElements()) + { + String locale = (String)e.nextElement(); + + CustomTableModel model = + (CustomTableModel)languagesTable.get(locale); + + Hashtable strings = new Hashtable(); + + int rows = model.getRowCount(); + for (int i = 0; i < rows; i++) + { + String key = (String)model.getValueAt(i, 0); + String val = (String)model.getValueAt(i, 1); + + strings.put(key, val); + } + + res.put(locale, strings); + } + + return res; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/ImagesPanel.java b/src/net/java/sip/communicator/plugin/guicustomization/ImagesPanel.java new file mode 100644 index 0000000..4bba1c7 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/ImagesPanel.java @@ -0,0 +1,282 @@ +package net.java.sip.communicator.plugin.guicustomization; + +import java.awt.*; +import java.awt.event.*; +import java.awt.image.*; +import java.io.*; +import java.util.*; + +import javax.imageio.*; +import javax.swing.*; +import javax.swing.table.*; + +import net.java.sip.communicator.util.*; + +public class ImagesPanel + extends JScrollPane +{ + private Logger logger = Logger.getLogger(ImagesPanel.class); + + private CustomTableModel imagesTableModel = new CustomTableModel(); + + private JTable imagesTable = new JTable(); + + private JFrame parentWindow; + + public ImagesPanel(JFrame parentWindow) + { + this.parentWindow = parentWindow; + + this.getViewport().add(imagesTable); + + imagesTableModel.addColumn("File path"); + imagesTableModel.addColumn("Image size"); + imagesTableModel.addColumn("Image"); + imagesTableModel.addColumn("Change image"); + + imagesTable.setModel(imagesTableModel); + + TableColumn sizeColumn + = imagesTable.getColumnModel().getColumn(1); + + sizeColumn.setCellRenderer( + new LabelTableCellRenderer()); + sizeColumn.setMaxWidth(100); + + imagesTable.getColumnModel().getColumn(2).setCellRenderer( + new LabelTableCellRenderer()); + + TableColumn buttonColumn + = imagesTable.getColumnModel().getColumn(3); + buttonColumn.setCellRenderer(new ButtonTableCellRenderer()); + buttonColumn.setCellEditor(new ButtonTableEditor()); + + this.initImageTable(); + } + + private void initImageTable() + { + Iterator imageKeys + = GuiCustomizationActivator.getResources() + .getCurrentImages(); + + // we set an initial row height, to fit the button. + int rowHeight = 40; + + while (imageKeys.hasNext()) + { + String key = (String) imageKeys.next(); + ImageIcon image = getImage(key); + final JLabel imageLabel = new JLabel(); + JLabel imageSizeLabel = new JLabel(); + int currentImageWidth = 0; + int currentImageHeight = 0; + + if (image != null) + { + imageLabel.setIcon(image); + currentImageWidth = image.getImage().getWidth(null); + currentImageHeight = image.getImage().getHeight(null); + + imageSizeLabel + .setText(currentImageWidth + "x" + currentImageHeight); + + images.put(key, getImageBytes(key)); + } + + JButton fileChooserButton = new JButton(); + + fileChooserButton.setAction( + new ChangeImageAction( key, + imageLabel, + imageSizeLabel, + currentImageWidth, + currentImageHeight)); + + imagesTableModel.addRow(new Object[]{ key, + imageSizeLabel, + imageLabel, + fileChooserButton}); + + fileChooserButton.setText("Change image"); + + if (image != null && rowHeight < image.getIconHeight()) + { + imagesTable.setRowHeight( imagesTableModel.getRowCount() - 1, + image.getIconHeight() ); + } + else + { + imagesTable.setRowHeight( imagesTableModel.getRowCount() - 1, + rowHeight ); + } + } + } + + + /** + * Loads an image from a given image identifier. + * + * @param imageID The identifier of the image. + * @return The image for the given identifier. + */ + private ImageIcon getImage(String imageID) + { + BufferedImage image = null; + + InputStream in = + GuiCustomizationActivator.getResources() + .getImageInputStream(imageID); + + if(in == null) + return null; + + try + { + image = ImageIO.read(in); + } + catch (IOException e) + { + logger.error("Failed to load image:" + imageID, e); + } + + return new ImageIcon(image); + } + + /** + * Loads an image from a given image identifier. + * + * @param imageID The identifier of the image. + * @return The image for the given identifier. + */ + private byte[] getImageBytes(String imageID) + { + InputStream in = + GuiCustomizationActivator.getResources() + .getImageInputStream(imageID); + + if(in == null) + return null; + + try + { + byte[] bs = new byte[in.available()]; + in.read(bs); + + return bs; + } + catch (IOException e) + { + logger.error("Failed to load image:" + imageID, e); + } + + return null; + } + + private class ChangeImageAction extends AbstractAction + { + private JLabel imageLabel; + private JLabel imageSizeLabel; + private int imageWidth; + private int imageHeight; + private String key; + + public ChangeImageAction( String key, + JLabel imageLabel, + JLabel imageSizeLabel, + int imageWidth, + int imageHeight) + { + this.key = key; + this.imageLabel = imageLabel; + this.imageSizeLabel = imageSizeLabel; + this.imageWidth = imageWidth; + this.imageHeight = imageHeight; + } + + public void actionPerformed(ActionEvent evt) + { + JFileChooser fileChooser + = new JFileChooser(); + + int result + = fileChooser.showOpenDialog(parentWindow); + + if (result == JFileChooser.APPROVE_OPTION) + { + File newImageFile = fileChooser.getSelectedFile(); + ImageIcon newImageIcon = new ImageIcon(newImageFile.getPath()); + + try + { + FileInputStream in = new FileInputStream(newImageFile); + byte[] bs = new byte[in.available()]; + in.read(bs); + in.close(); + + images.put(key, bs); + } + catch (Exception e) + { + e.printStackTrace(); + } + + imageLabel.setIcon(newImageIcon); + + if (newImageIcon.getIconWidth() > imageWidth + || newImageIcon.getIconHeight() > imageHeight) + { + imageSizeLabel.setBackground(Color.RED); + } + } + } + } + +// public static byte[] convertImage(Image img) +// { +// try +// { +// int[] pix = new int[img.getWidth(null) * img.getHeight(null)]; +// PixelGrabber pg = +// new PixelGrabber(img, 0, 0, img.getWidth(null), +// img.getHeight(null), pix, 0, img.getWidth(null)); +// pg.grabPixels(); +// +// byte[] pixels = new byte[img.getWidth(null) * img.getHeight(null)]; +// +// for (int j = 0; j < pix.length; j++) +// pixels[j] = new Integer(pix[j]).byteValue(); +// +// return pixels; +// } +// catch (InterruptedException e) +// { +// e.printStackTrace(); +// } +// return null; +// } + + Hashtable<String, byte[]> images = new Hashtable<String, byte[]>(); + + Hashtable<String, byte[]> getImages() + { + return images; +// Hashtable res = new Hashtable(); +// int rows = imagesTableModel.getRowCount(); +// for (int i = 0; i < rows; i++) +// { +// String key = (String)imagesTableModel.getValueAt(i, 0); +// JLabel imageLabel = (JLabel)imagesTableModel.getValueAt(i, 2); +// +// Icon icon = imageLabel.getIcon(); +// if(icon != null && icon instanceof ImageIcon) +// res.put( +// key, +// convertImage(((ImageIcon)icon).getImage())); +// else +// res.put(key,new byte[0]); +// } +// +// return res; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/LabelTableCellRenderer.java b/src/net/java/sip/communicator/plugin/guicustomization/LabelTableCellRenderer.java new file mode 100644 index 0000000..302192f --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/LabelTableCellRenderer.java @@ -0,0 +1,43 @@ +package net.java.sip.communicator.plugin.guicustomization; + +import java.awt.*; + +import javax.swing.*; +import javax.swing.table.*; + +public class LabelTableCellRenderer + extends JLabel + implements TableCellRenderer +{ + public LabelTableCellRenderer() + { + this.setOpaque(true); + } + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) + { + if (isSelected) + { + setBackground(table.getSelectionBackground()); + setForeground(table.getSelectionForeground()); + } + else + { + setBackground(table.getBackground()); + setForeground(table.getForeground()); + } + + if (value instanceof JLabel) + { + JLabel labelValue = (JLabel) value; + this.setText(labelValue.getText()); + this.setIcon(labelValue.getIcon()); + this.setBackground(labelValue.getBackground()); + } + + setEnabled(table.isEnabled()); + setFont(table.getFont()); + + return this; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/SettingsPanel.java b/src/net/java/sip/communicator/plugin/guicustomization/SettingsPanel.java new file mode 100644 index 0000000..59a25b3 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/SettingsPanel.java @@ -0,0 +1,62 @@ +package net.java.sip.communicator.plugin.guicustomization; + +import java.awt.*; +import java.util.*; + +import javax.swing.*; + +public class SettingsPanel + extends JScrollPane +{ + private JTable settingsTable = new JTable(); + + private CustomTableModel settingsTableModel = new CustomTableModel(); + + public SettingsPanel() + { + this.getViewport().add(settingsTable); + + settingsTable.setModel(settingsTableModel); + settingsTableModel.addColumn("Key"); + settingsTableModel.addColumn("Text"); + + settingsTable.getColumnModel().getColumn(1) + .setCellRenderer(new TextAreaCellRenderer()); + settingsTable.setShowGrid(true); + settingsTable.setGridColor(Color.GRAY); + this.initSettingTable(); + } + + private void initSettingTable() + { + Iterator settingKeys + = GuiCustomizationActivator.getResources() + .getCurrentSettings(); + + while (settingKeys.hasNext()) + { + String key = (String) settingKeys.next(); + String value + = GuiCustomizationActivator.getResources() + .getSettingsString(key); + + settingsTableModel.addRow(new Object[]{ key, + value}); + } + } + + Hashtable<String, String> getSettings() + { + Hashtable res = new Hashtable(); + int rows = settingsTableModel.getRowCount(); + for (int i = 0; i < rows; i++) + { + String key = (String)settingsTableModel.getValueAt(i, 0); + String value = (String)settingsTableModel.getValueAt(i, 1); + + res.put(key, value); + } + + return res; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/SoundsPanel.java b/src/net/java/sip/communicator/plugin/guicustomization/SoundsPanel.java new file mode 100644 index 0000000..7522016 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/SoundsPanel.java @@ -0,0 +1,239 @@ +package net.java.sip.communicator.plugin.guicustomization; + +import java.applet.*; +import java.awt.event.*; +import java.io.*; +import java.lang.reflect.*; +import java.net.*; +import java.security.*; +import java.util.*; + +import javax.swing.*; +import javax.swing.table.*; + +import net.java.sip.communicator.plugin.guicustomization.CustomizationWindow.*; +import net.java.sip.communicator.util.*; + +public class SoundsPanel + extends JScrollPane +{ + private Logger logger = Logger.getLogger(SoundsPanel.class); + + private JTable soundsTable = new JTable(); + + private CustomTableModel soundsTableModel = new CustomTableModel(); + + private static Constructor acConstructor = null; + + private JFrame parentWindow; + + public SoundsPanel(JFrame parentWindow) + { + this.parentWindow = parentWindow; + + this.getViewport().add(soundsTable); + + soundsTable.setModel(soundsTableModel); + soundsTableModel.addColumn("Description"); + soundsTableModel.addColumn("File path"); + soundsTableModel.addColumn("Change sound"); + + TableColumn buttonColumn1 + = soundsTable.getColumnModel().getColumn(1); + + buttonColumn1.setCellRenderer(new ButtonTableCellRenderer()); + buttonColumn1.setCellEditor(new ButtonTableEditor()); + buttonColumn1.setWidth(40); + + TableColumn buttonColumn2 + = soundsTable.getColumnModel().getColumn(2); + + buttonColumn2.setCellRenderer(new ButtonTableCellRenderer()); + buttonColumn2.setCellEditor(new ButtonTableEditor()); + buttonColumn2.setWidth(40); + + this.initSoundTable(); + } + + private void initSoundTable() + { + Iterator soundKeys + = GuiCustomizationActivator.getResources() + .getCurrentSounds(); + + int rowHeight = 40; + while (soundKeys.hasNext()) + { + String key = (String) soundKeys.next(); + URL soundURL + = GuiCustomizationActivator.getResources().getSoundURL(key); + + PlaySoundButton playSoundButton = new PlaySoundButton(soundURL); + playSoundButton.setAction(new PlaySoundAction()); + + JButton fileChooserButton = new JButton(); + fileChooserButton.setAction(new ChangeSoundAction(playSoundButton)); + + soundsTableModel.addRow(new Object[]{ key, + playSoundButton, + fileChooserButton}); + playSoundButton.setText("Play!"); + fileChooserButton.setText("Choose sound"); + + soundsTable.setRowHeight( soundsTableModel.getRowCount() - 1, + rowHeight ); + } + } + + + private class ChangeSoundAction extends AbstractAction + { + private PlaySoundButton playSoundButton; + + public ChangeSoundAction(PlaySoundButton button) + { + this.playSoundButton = button; + } + + public void actionPerformed(ActionEvent evt) + { + JFileChooser fileChooser + = new JFileChooser(); + + int result + = fileChooser.showOpenDialog(parentWindow); + + if (result == JFileChooser.APPROVE_OPTION) + { + File newSoundFile = fileChooser.getSelectedFile(); + try + { + playSoundButton + .setSoundURL(newSoundFile.toURL()); + } + catch (MalformedURLException e) + { + logger.error("Faile to create sound file.", e); + } + } + } + } + + private class PlaySoundAction extends AbstractAction + { + public void actionPerformed(ActionEvent evt) + { + PlaySoundButton button = (PlaySoundButton) evt.getSource(); + AudioClip ac; + try + { + ac = createAppletAudioClip(button.getSoundURL().openStream()); + + ac.play(); + } + catch (IOException e) + { + logger.error("Failed to open sound file.", e); + } + } + } + + private class PlaySoundButton extends JButton + { + private URL soundURL; + + public PlaySoundButton(URL soundURL) + { + this.soundURL = soundURL; + } + + public URL getSoundURL() + { + return soundURL; + } + + public void setSoundURL(URL url) + { + this.soundURL = url; + } + } + + /** + * Creates an AppletAudioClip. + * + * @param inputstream the audio input stream + * @throws IOException + */ + private AudioClip createAppletAudioClip(InputStream inputstream) + throws IOException + { + if(acConstructor == null) + { + try + { + acConstructor = (Constructor) AccessController + .doPrivileged(new PrivilegedExceptionAction() + { + public Object run() + throws NoSuchMethodException, + SecurityException, + ClassNotFoundException + { + + Class class1 = null; + try + { + class1 = Class.forName( + "com.sun.media.sound.JavaSoundAudioClip", + true, ClassLoader.getSystemClassLoader()); + } + catch(ClassNotFoundException ex) + { + class1 = Class.forName( + "sun.audio.SunAudioClip", true, null); + } + Class aclass[] = new Class[1]; + aclass[0] = Class.forName("java.io.InputStream"); + return class1.getConstructor(aclass); + } + }); + } + catch(PrivilegedActionException privilegedactionexception) + { + throw new IOException("Failed to get AudioClip constructor: " + + privilegedactionexception.getException()); + } + } + try + { + Object aobj[] = { + inputstream + }; + + return (AudioClip)acConstructor.newInstance(aobj); + } + catch(Exception exception) + { + throw new IOException("Failed to construct the AudioClip: " + + exception); + } + } + + Hashtable<String, URL> getSounds() + { + Hashtable res = new Hashtable(); + int rows = soundsTableModel.getRowCount(); + for (int i = 0; i < rows; i++) + { + String key = (String)soundsTableModel.getValueAt(i, 0); + PlaySoundButton sndButton = + (PlaySoundButton)soundsTableModel.getValueAt(i, 1); + + res.put( + key, + sndButton.getSoundURL()); + } + + return res; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/TextAreaCellRenderer.java b/src/net/java/sip/communicator/plugin/guicustomization/TextAreaCellRenderer.java new file mode 100644 index 0000000..fadaac0 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/TextAreaCellRenderer.java @@ -0,0 +1,32 @@ +package net.java.sip.communicator.plugin.guicustomization; + +import java.awt.*; + +import javax.swing.*; +import javax.swing.table.*; + +public class TextAreaCellRenderer + extends JTextArea + implements TableCellRenderer +{ + public TextAreaCellRenderer() + { + setLineWrap(true); + setWrapStyleWord(true); + } + + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) + { + String stringValue = (String) value; + + setText(stringValue); + setSize(table.getColumnModel().getColumn(column).getWidth(), + getPreferredSize().height); + if (table.getRowHeight(row) != getPreferredSize().height) + { + table.setRowHeight(row, getPreferredSize().height); + } + return this; + } +}
\ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/guicustomization/guicustomization.manifest.mf b/src/net/java/sip/communicator/plugin/guicustomization/guicustomization.manifest.mf new file mode 100644 index 0000000..64e320a --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/guicustomization.manifest.mf @@ -0,0 +1,14 @@ +Bundle-Activator: net.java.sip.communicator.plugin.guicustomization.GuiCustomizationActivator +Bundle-Name: Gui Customization Activator +Bundle-Description: The plugin offering gui customization interface. +Bundle-Vendor: sip-communicator.org +Bundle-Version: 0.0.1 +Import-Package: org.osgi.framework, + net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, + javax.swing, + javax.swing.event, + javax.swing.table, + javax.swing.text, + javax.swing.text.html, + javax.imageio
\ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomColorPackImpl.java b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomColorPackImpl.java new file mode 100644 index 0000000..11fedce --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomColorPackImpl.java @@ -0,0 +1,33 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.guicustomization.resourcepack; + +import net.java.sip.communicator.service.resources.*; + +/** + * + * @author Damian Minkov + */ +public class CustomColorPackImpl + implements ColorPack +{ + + public String getResourcePackBaseName() + { + return "resources.colors.colorResources"; + } + + public String getName() + { + return "Color Resources"; + } + + public String getDescription() + { + return "Provide SIP Communicator Color resource pack."; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomImagePackImpl.java b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomImagePackImpl.java new file mode 100644 index 0000000..2d384a0 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomImagePackImpl.java @@ -0,0 +1,33 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.guicustomization.resourcepack; + +import net.java.sip.communicator.service.resources.*; + +/** + * + * @author Damian Minkov + */ +public class CustomImagePackImpl + implements ImagePack +{ + + public String getResourcePackBaseName() + { + return "resources.images.images"; + } + + public String getName() + { + return "Image Resources"; + } + + public String getDescription() + { + return "Provide SIP Communicator Image resource pack."; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomLanguagePackImpl.java b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomLanguagePackImpl.java new file mode 100644 index 0000000..1531f9e --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomLanguagePackImpl.java @@ -0,0 +1,97 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.guicustomization.resourcepack; + +import java.util.*; + +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import net.java.sip.communicator.service.resources.*; + +/** + * + * @author Damian Minkov + */ +public class CustomLanguagePackImpl + implements LanguagePack +{ + private ArrayList localeList = new ArrayList(); + + public CustomLanguagePackImpl() + { + try + { + JarFile jf = new JarFile(getJarfileName()); + + Enumeration resources = jf.entries(); + while (resources.hasMoreElements()) + { + JarEntry je = (JarEntry) resources.nextElement(); + + Locale locale; + String entryName = je.getName(); + if (entryName.matches("resources/languages/.*\\.properties")) + { + int localeIndex = entryName.indexOf('_'); + + if (localeIndex == -1) + locale = new Locale("EN"); + else + { + String localeName = + entryName.substring(localeIndex + 1, + entryName.indexOf('.')); + + locale = new Locale(localeName); + } + + localeList.add(locale); + } + } + } + catch (java.io.IOException e) + { +// logger.error("Cannot load locales.", e); + } + } + + public String getResourcePackBaseName() + { + return "resources.languages.resources"; + } + + public String getName() + { + return "Language Resources"; + } + + public String getDescription() + { + return "Provide SIP Communicator Language resource pack."; + } + + public Iterator getAvailableLocales() + { + return localeList.iterator(); + } + + private String getJarfileName() + { + // Get the location of the jar file and the jar file name + java.net.URL outputURL = + CustomLanguagePackImpl.class.getProtectionDomain().getCodeSource() + .getLocation(); + + String outputString = outputURL.toString(); + + String[] parseString; + parseString = outputString.split("file:"); + + String jarFilename = parseString[1]; + return jarFilename; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomResourcePackActivator.java b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomResourcePackActivator.java new file mode 100644 index 0000000..95d0105 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomResourcePackActivator.java @@ -0,0 +1,103 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.guicustomization.resourcepack; + +import java.util.*; +import org.osgi.framework.*; +import org.osgi.service.startlevel.*; + +import net.java.sip.communicator.service.resources.*; +import net.java.sip.communicator.util.*; + +/** + * + * @author damencho + */ +public class CustomResourcePackActivator + implements BundleActivator +{ + + private Logger logger = + Logger.getLogger(CustomResourcePackActivator.class); + + private static BundleContext bundleContext; + + public void start(BundleContext bc) throws Exception + { + bundleContext = bc; + + ServiceReference serviceReference = bundleContext + .getServiceReference(StartLevel.class.getName()); + + StartLevel startLevelService = (StartLevel) bundleContext + .getService(serviceReference); + + startLevelService.setBundleStartLevel(bc.getBundle(), 39); + + CustomColorPackImpl colPackImpl = + new CustomColorPackImpl(); + + Hashtable props = new Hashtable(); + props.put(ColorPack.RESOURCE_NAME, + ColorPack.RESOURCE_NAME_DEFAULT_VALUE); + + bundleContext.registerService( ColorPack.class.getName(), + colPackImpl, + props); + + CustomImagePackImpl imgPackImpl = + new CustomImagePackImpl(); + + Hashtable imgProps = new Hashtable(); + imgProps.put(ImagePack.RESOURCE_NAME, + ImagePack.RESOURCE_NAME_DEFAULT_VALUE); + + bundleContext.registerService( ImagePack.class.getName(), + imgPackImpl, + imgProps); + + CustomLanguagePackImpl langPackImpl = + new CustomLanguagePackImpl(); + + Hashtable langProps = new Hashtable(); + langProps.put(LanguagePack.RESOURCE_NAME, + LanguagePack.RESOURCE_NAME_DEFAULT_VALUE); + + bundleContext.registerService( LanguagePack.class.getName(), + langPackImpl, + langProps); + + CustomSettingsPackImpl setPackImpl = + new CustomSettingsPackImpl(); + + Hashtable setProps = new Hashtable(); + langProps.put(SettingsPack.RESOURCE_NAME, + SettingsPack.RESOURCE_NAME_DEFAULT_VALUE); + + bundleContext.registerService( SettingsPack.class.getName(), + setPackImpl, + setProps); + + CustomSoundPackImpl sndPackImpl = + new CustomSoundPackImpl(); + + Hashtable sndProps = new Hashtable(); + langProps.put(SoundPack.RESOURCE_NAME, + SoundPack.RESOURCE_NAME_DEFAULT_VALUE); + + bundleContext.registerService( SoundPack.class.getName(), + sndPackImpl, + sndProps); + + logger.info("Custom resources ... [REGISTERED]"); + } + + public void stop(BundleContext bc) throws Exception + { + + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomSettingsPackImpl.java b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomSettingsPackImpl.java new file mode 100644 index 0000000..6deac80 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomSettingsPackImpl.java @@ -0,0 +1,33 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.guicustomization.resourcepack; + +import net.java.sip.communicator.service.resources.*; + +/** + * + * @author Damian Minkov + */ +public class CustomSettingsPackImpl + implements SettingsPack +{ + + public String getResourcePackBaseName() + { + return "resources.config.defaults"; + } + + public String getName() + { + return "Settings Resources"; + } + + public String getDescription() + { + return "Provide SIP Communicator Settings resource pack."; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomSoundPackImpl.java b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomSoundPackImpl.java new file mode 100644 index 0000000..2a9c7a6 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/CustomSoundPackImpl.java @@ -0,0 +1,33 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.guicustomization.resourcepack; + +import net.java.sip.communicator.service.resources.*; + +/** + * + * @author Damian Minkov + */ +public class CustomSoundPackImpl + implements SoundPack +{ + + public String getResourcePackBaseName() + { + return "resources.sounds"; + } + + public String getName() + { + return "Sounds Resources"; + } + + public String getDescription() + { + return "Provide SIP Communicator Sounds resource pack."; + } +} diff --git a/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/customresourcepack.manifest.mf b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/customresourcepack.manifest.mf new file mode 100644 index 0000000..ea6a54b --- /dev/null +++ b/src/net/java/sip/communicator/plugin/guicustomization/resourcepack/customresourcepack.manifest.mf @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-Activator: net.java.sip.communicator.plugin.guicustomization.resourcepack.CustomResourcePackActivator +Bundle-Name: Custom Resource Pack +Bundle-Description: The plugin offering custom images and languages. +Bundle-Vendor: sip-communicator.org +Bundle-Version: 0.0.1 +Import-Package: org.osgi.framework, + org.osgi.service.startlevel, + net.java.sip.communicator.util, + net.java.sip.communicator.service.resources diff --git a/src/net/java/sip/communicator/plugin/icqaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/icqaccregwizz/FirstWizardPage.java index 5c412d6..b8d851f 100644 --- a/src/net/java/sip/communicator/plugin/icqaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/icqaccregwizz/FirstWizardPage.java @@ -68,7 +68,7 @@ public class FirstWizardPage private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); private JTextArea registerArea = - new JTextArea(Resources.getString("registerNewAccountText")); + new JTextArea(Resources.getString("icqRegisterNewAccountText")); private JButton registerButton = new JButton(Resources.getString("registerNewAccount")); diff --git a/src/net/java/sip/communicator/plugin/icqaccregwizz/IcqAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/icqaccregwizz/IcqAccountRegistrationWizard.java index 1975a1a..b4051b4 100644 --- a/src/net/java/sip/communicator/plugin/icqaccregwizz/IcqAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/icqaccregwizz/IcqAccountRegistrationWizard.java @@ -71,7 +71,7 @@ public class IcqAccountRegistrationWizard */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameIcq"); } /** @@ -81,7 +81,7 @@ public class IcqAccountRegistrationWizard */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionIcq"); } /** diff --git a/src/net/java/sip/communicator/plugin/icqaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/icqaccregwizz/Resources.java index dfe50fd..c87677d 100644 --- a/src/net/java/sip/communicator/plugin/icqaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/icqaccregwizz/Resources.java @@ -10,8 +10,11 @@ package net.java.sip.communicator.plugin.icqaccregwizz; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -22,35 +25,11 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.icqaccregwizz.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.icqaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); + private static ResourceManagementService resourcesService; - public static ImageID ICQ_LOGO = new ImageID("protocolIcon"); + public static ImageID ICQ_LOGO = new ImageID("protocolIconIcq"); - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageIcq"); /** * Returns an internationalized string corresponding to the given key. @@ -60,14 +39,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -77,18 +49,22 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; - - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + image = new byte[in.available()]; + in.read(image); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return image; @@ -111,4 +87,22 @@ public class Resources return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = IcqAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)IcqAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/icqaccregwizz/icqaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/icqaccregwizz/icqaccregwizz.manifest.mf index 853ea55..94bd8a9 100644 --- a/src/net/java/sip/communicator/plugin/icqaccregwizz/icqaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/icqaccregwizz/icqaccregwizz.manifest.mf @@ -7,6 +7,7 @@ Import-Package: org.osgi.framework, net.java.sip.communicator.util, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.protocol.icqconstants, net.java.sip.communicator.service.protocol.event, diff --git a/src/net/java/sip/communicator/plugin/ircaccregwizz/IrcAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/ircaccregwizz/IrcAccountRegistrationWizard.java index fb64551..17bdd67 100644 --- a/src/net/java/sip/communicator/plugin/ircaccregwizz/IrcAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/ircaccregwizz/IrcAccountRegistrationWizard.java @@ -83,7 +83,7 @@ public class IrcAccountRegistrationWizard */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameIrc"); } /** @@ -93,7 +93,7 @@ public class IrcAccountRegistrationWizard */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionIrc"); } /** diff --git a/src/net/java/sip/communicator/plugin/ircaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/ircaccregwizz/Resources.java index 927c00a..703f268 100644 --- a/src/net/java/sip/communicator/plugin/ircaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/ircaccregwizz/Resources.java @@ -10,9 +10,11 @@ package net.java.sip.communicator.plugin.ircaccregwizz; import java.io.*; import java.util.*; -import net.java.sip.communicator.plugin.aimaccregwizz.Resources.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The Messages class manages the access to the internationalization * properties files. @@ -24,41 +26,17 @@ public class Resources private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.ircaccregwizz.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.ircaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); - + private static ResourceManagementService resourcesService; + /** * A constant pointing to the IRC protocol logo image. */ - public static ImageID IRC_LOGO = new ImageID("protocolIcon"); + public static ImageID IRC_LOGO = new ImageID("protocolIconIrc"); /** * A constant pointing to the IRC protocol wizard page image. */ - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageIrc"); /** * Returns an internationalized string corresponding to the given key. @@ -67,14 +45,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException exc) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -84,18 +55,22 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; - - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + image = new byte[in.available()]; + in.read(image); } - catch (IOException exc) + catch (IOException e) { - log.error("Failed to load image:" + path, exc); + log.error("Failed to load image:" + imageID, e); } return image; @@ -118,4 +93,22 @@ public class Resources return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = IrcAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)IrcAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/ircaccregwizz/ircaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/ircaccregwizz/ircaccregwizz.manifest.mf index 31f8be7..9149518 100644 --- a/src/net/java/sip/communicator/plugin/ircaccregwizz/ircaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/ircaccregwizz/ircaccregwizz.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationWizard.java index f5c67d6..7e9a0a9 100644 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationWizard.java @@ -82,7 +82,7 @@ public class JabberAccountRegistrationWizard */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameJabber"); } /** @@ -92,7 +92,7 @@ public class JabberAccountRegistrationWizard */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionJabber"); } /** diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberServerChooserDialog.java b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberServerChooserDialog.java index 22be4ec..ced5ee4 100644 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberServerChooserDialog.java +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberServerChooserDialog.java @@ -309,10 +309,7 @@ public class JabberServerChooserDialog // Create the builder and parse the file serverComments = factory.newDocumentBuilder() - .parse( - JabberServerChooserDialog.class.getClassLoader() - .getResourceAsStream( - Resources.getProperty("commentsFile"))); + .parse(Resources.getPropertyInputStream("commentsFile")); } catch (SAXException e) { diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/jabberaccregwizz/Resources.java index 56c74a1..6dc5ab8 100644 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/Resources.java @@ -8,10 +8,14 @@ package net.java.sip.communicator.plugin.jabberaccregwizz; import java.io.*; +import java.net.URL; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -22,41 +26,17 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.jabberaccregwizz.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String RESOURCE_NAME - = "net.java.sip.communicator.plugin.jabberaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle RESOURCE_BUNDLE - = ResourceBundle.getBundle(RESOURCE_NAME); - + private static ResourceManagementService resourcesService; + /** * A constant pointing to the Jabber protocol logo image. */ - public static ImageID PROTOCOL_ICON = new ImageID("protocolIcon"); + public static ImageID PROTOCOL_ICON = new ImageID("protocolIconJabber"); /** * A constant pointing to the Aim protocol wizard page image. */ - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageJabber"); /** * Returns an internationalized string corresponding to the given key. @@ -66,27 +46,7 @@ public class Resources */ public static String getString(String key) { - String resourceString; - try - { - resourceString = STRING_RESOURCE_BUNDLE.getString(key); - - int mnemonicIndex = resourceString.indexOf('&'); - - if(mnemonicIndex > -1) - { - String firstPart = resourceString.substring(0, mnemonicIndex); - String secondPart = resourceString.substring(mnemonicIndex + 1); - - resourceString = firstPart.concat(secondPart); - } - } - catch (MissingResourceException e) - { - resourceString = '!' + key + '!'; - } - - return resourceString; + return getResources().getI18NString(key); } /** @@ -97,26 +57,7 @@ public class Resources */ public static char getMnemonic(String key) { - String resourceString; - - try - { - resourceString = STRING_RESOURCE_BUNDLE.getString(key); - - int mnemonicIndex = resourceString.indexOf('&'); - - if(mnemonicIndex > -1) - { - return resourceString.charAt(mnemonicIndex + 1); - } - - } - catch (MissingResourceException e) - { - return '!'; - } - - return '!'; + return getResources().getI18nMnemonic(key); } /** @@ -127,18 +68,22 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; - - String path = RESOURCE_BUNDLE.getString(imageID.getId()); + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + image = new byte[in.available()]; + in.read(image); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return image; @@ -151,16 +96,9 @@ public class Resources * @param key the key of the resource to search for * @return the resource for the given key */ - public static String getProperty(String key) + public static InputStream getPropertyInputStream(String key) { - try - { - return RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getSettingsInputStream(key); } /** @@ -180,4 +118,22 @@ public class Resources return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = JabberAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)JabberAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/jabberaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/jabberaccregwizz/jabberaccregwizz.manifest.mf index 3e4ba6e..bcc9cb4 100755 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/jabberaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/jabberaccregwizz.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/resources.properties b/src/net/java/sip/communicator/plugin/jabberaccregwizz/resources.properties deleted file mode 100755 index b76d798..0000000 --- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/resources.properties +++ /dev/null @@ -1,4 +0,0 @@ -commentsFile=net/java/sip/communicator/plugin/jabberaccregwizz/resources/servercomments.xml - -protocolIcon=resources/images/protocol/jabber/status16x16-online.png -pageImage=resources/images/protocol/jabber/logo48x48.png diff --git a/src/net/java/sip/communicator/plugin/mailbox/MailboxActivator.java b/src/net/java/sip/communicator/plugin/mailbox/MailboxActivator.java index 17e3d08..12a9ab1 100644 --- a/src/net/java/sip/communicator/plugin/mailbox/MailboxActivator.java +++ b/src/net/java/sip/communicator/plugin/mailbox/MailboxActivator.java @@ -12,6 +12,7 @@ import net.java.sip.communicator.service.fileaccess.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.util.*; import net.java.sip.communicator.service.media.MediaService; +import net.java.sip.communicator.service.resources.*; /** * Activates the Mailbox plug-in. @@ -57,6 +58,8 @@ public class MailboxActivator * is currently registered with the bundle context. */ private static UIService uiService = null; + + private static ResourceManagementService resourcesService; /** * Starts this bundle and adds the <tt>MailboxConfigurationForm</tt> @@ -145,22 +148,39 @@ public class MailboxActivator } /** - * Returns a reference to a MediaService implementation currently registered - * in the bundle context or null if no such implementation was found. - * - * @return a reference to a MediaService implementation currently registered - * in the bundle context or null if no such implementation was found. - */ - public static MediaService getMediaService() + * Returns a reference to a MediaService implementation currently registered + * in the bundle context or null if no such implementation was found. + * + * @return a reference to a MediaService implementation currently registered + * in the bundle context or null if no such implementation was found. + */ + public static MediaService getMediaService() + { + if(mediaService == null) + { + ServiceReference mediaServiceReference + = bundleContext.getServiceReference( + MediaService.class.getName()); + mediaService = (MediaService)bundleContext + .getService(mediaServiceReference); + } + return mediaService; + } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) { - if(mediaService == null) - { - ServiceReference mediaServiceReference - = bundleContext.getServiceReference( - MediaService.class.getName()); - mediaService = (MediaService)bundleContext - .getService(mediaServiceReference); - } - return mediaService; + ServiceReference serviceReference = bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService) bundleContext + .getService(serviceReference); + } + + return resourcesService; } } diff --git a/src/net/java/sip/communicator/plugin/mailbox/Resources.java b/src/net/java/sip/communicator/plugin/mailbox/Resources.java index e6de03f..ef56e24 100644 --- a/src/net/java/sip/communicator/plugin/mailbox/Resources.java +++ b/src/net/java/sip/communicator/plugin/mailbox/Resources.java @@ -26,33 +26,6 @@ public class Resources private static Logger logger = Logger.getLogger(Resources.class); /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.mailbox.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.mailbox.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); - - - /** * Returns an internationalized string corresponding to the given key. * * @param key The key of the string. @@ -60,14 +33,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return MailboxActivator.getResources().getI18NString(key); } /** @@ -78,22 +44,22 @@ public class Resources */ public static byte[] getImageInBytes(String imageID) { - byte[] image = new byte[100000]; - - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID); - - logger.debug("Loading imageID=" + imageID + " from path=" + path); + logger.debug("Loading imageID=" + imageID); try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + InputStream in = + MailboxActivator.getResources().getImageInputStream(imageID); + byte[] image = new byte[in.available()]; + in.read(image); + + return image; } catch (IOException e) { - logger.error("Failed to load image:" + path, e); + logger.error("Failed to load image:" + imageID, e); } - return image; + return null; } }
\ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/msnaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/msnaccregwizz/FirstWizardPage.java index a4e17bd..b221dbd 100644 --- a/src/net/java/sip/communicator/plugin/msnaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/msnaccregwizz/FirstWizardPage.java @@ -116,7 +116,7 @@ public class FirstWizardPage uinPassPanel.add(rememberPassBox, BorderLayout.SOUTH); uinPassPanel.setBorder(BorderFactory.createTitledBorder(Resources - .getString("uinAndPassword"))); + .getString("msnUinAndPassword"))); mainPanel.add(uinPassPanel); this.add(mainPanel, BorderLayout.NORTH); diff --git a/src/net/java/sip/communicator/plugin/msnaccregwizz/MsnAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/msnaccregwizz/MsnAccountRegistrationWizard.java index 596ebf4..27f977d 100644 --- a/src/net/java/sip/communicator/plugin/msnaccregwizz/MsnAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/msnaccregwizz/MsnAccountRegistrationWizard.java @@ -79,7 +79,7 @@ public class MsnAccountRegistrationWizard */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameMsn"); } /** @@ -91,7 +91,7 @@ public class MsnAccountRegistrationWizard */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionMsn"); } /** diff --git a/src/net/java/sip/communicator/plugin/msnaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/msnaccregwizz/Resources.java index 4ce8fc4..3beb785 100644 --- a/src/net/java/sip/communicator/plugin/msnaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/msnaccregwizz/Resources.java @@ -10,8 +10,11 @@ package net.java.sip.communicator.plugin.msnaccregwizz; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -22,41 +25,17 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.msnaccregwizz.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.msnaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); + private static ResourceManagementService resourcesService; /** * A constant pointing to the MSN protocol logo image. */ - public static ImageID MSN_LOGO = new ImageID("protocolIcon"); + public static ImageID MSN_LOGO = new ImageID("protocolIconMsn"); /** * A constant pointing to the Aim protocol wizard page image. */ - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageMsn"); /** * Returns an internationalized string corresponding to the given key. @@ -66,14 +45,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -84,19 +56,22 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; - - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); - + image = new byte[in.available()]; + in.read(image); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return image; @@ -119,4 +94,22 @@ public class Resources return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = MsnAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)MsnAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/msnaccregwizz/msnaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/msnaccregwizz/msnaccregwizz.manifest.mf index 38774b6..9cb1ab7 100755 --- a/src/net/java/sip/communicator/plugin/msnaccregwizz/msnaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/msnaccregwizz/msnaccregwizz.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/plugin/notificationconfiguration/resources/folder32*32.png b/src/net/java/sip/communicator/plugin/notificationconfiguration/resources/folder32*32.png Binary files differdeleted file mode 100644 index db2d185..0000000 --- a/src/net/java/sip/communicator/plugin/notificationconfiguration/resources/folder32*32.png +++ /dev/null diff --git a/src/net/java/sip/communicator/plugin/notificationconfiguration/resources/folder48*48.png b/src/net/java/sip/communicator/plugin/notificationconfiguration/resources/folder48*48.png Binary files differdeleted file mode 100644 index 13af311..0000000 --- a/src/net/java/sip/communicator/plugin/notificationconfiguration/resources/folder48*48.png +++ /dev/null diff --git a/src/net/java/sip/communicator/plugin/notificationconfiguration/resources/folder64*64.png b/src/net/java/sip/communicator/plugin/notificationconfiguration/resources/folder64*64.png Binary files differdeleted file mode 100644 index 4878503..0000000 --- a/src/net/java/sip/communicator/plugin/notificationconfiguration/resources/folder64*64.png +++ /dev/null diff --git a/src/net/java/sip/communicator/plugin/pluginmanager/NewBundleDialog.java b/src/net/java/sip/communicator/plugin/pluginmanager/NewBundleDialog.java index 9f2cd90..2726e76 100644 --- a/src/net/java/sip/communicator/plugin/pluginmanager/NewBundleDialog.java +++ b/src/net/java/sip/communicator/plugin/pluginmanager/NewBundleDialog.java @@ -9,7 +9,8 @@ package net.java.sip.communicator.plugin.pluginmanager; import java.awt.*; import java.awt.event.*; - +import java.io.*; +import java.net.*; import javax.swing.*; import net.java.sip.communicator.service.gui.*; @@ -34,6 +35,9 @@ public class NewBundleDialog private JPanel mainPanel = new JPanel(new BorderLayout()); + private JButton fileChooserButton = new JButton(Resources.getString("chooseFile") + ); + public NewBundleDialog () { this.mainPanel.setPreferredSize(new Dimension(450, 150)); @@ -50,11 +54,13 @@ public class NewBundleDialog this.installButton.addActionListener(this); this.cancelButton.addActionListener(this); + this.fileChooserButton.addActionListener(this); this.dataPanel.add(bundlePathLabel, BorderLayout.WEST); this.dataPanel.add(bundlePathField, BorderLayout.CENTER); + this.dataPanel.add(fileChooserButton, BorderLayout.EAST); } public void actionPerformed (ActionEvent e) @@ -72,6 +78,7 @@ public class NewBundleDialog } catch (BundleException ex) { + ex.printStackTrace(); PluginManagerActivator.getUIService().getPopupDialog() .showMessagePopupDialog(ex.getMessage(), "Error", PopupDialog.ERROR_MESSAGE); @@ -82,7 +89,29 @@ public class NewBundleDialog } } } - - dispose(); + else if (sourceButton.equals(fileChooserButton)) + { + JFileChooser fileChooser + = new JFileChooser(); + + int result + = fileChooser.showOpenDialog(NewBundleDialog.this); + + if (result == JFileChooser.APPROVE_OPTION) + { + try + { + File newBundleFile = fileChooser.getSelectedFile(); + + bundlePathField.setText(newBundleFile.toURL().toString()); + } + catch (MalformedURLException ex) + { + ex.printStackTrace(); + } + } + } + else + dispose(); } } diff --git a/src/net/java/sip/communicator/plugin/pluginmanager/PluginManagerConfigForm.java b/src/net/java/sip/communicator/plugin/pluginmanager/PluginManagerConfigForm.java index 7090190..4f89796 100644 --- a/src/net/java/sip/communicator/plugin/pluginmanager/PluginManagerConfigForm.java +++ b/src/net/java/sip/communicator/plugin/pluginmanager/PluginManagerConfigForm.java @@ -151,7 +151,7 @@ public class PluginManagerConfigForm */ public byte[] getIcon() { - return Resources.getImageInBytes("pluginIcon"); + return Resources.getImageInBytes("pluginIconPluginManager"); } /** diff --git a/src/net/java/sip/communicator/plugin/pluginmanager/Resources.java b/src/net/java/sip/communicator/plugin/pluginmanager/Resources.java index da97508..9fe3a6b 100644 --- a/src/net/java/sip/communicator/plugin/pluginmanager/Resources.java +++ b/src/net/java/sip/communicator/plugin/pluginmanager/Resources.java @@ -9,12 +9,15 @@ package net.java.sip.communicator.plugin.pluginmanager; import java.awt.image.*; import java.io.*; -import java.util.*; import javax.imageio.*; import javax.swing.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; + +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -25,45 +28,8 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.pluginmanager.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.pluginmanager.resources"; - - /** - * The name of the resource, where color constants used in this bundle are - * stored. - */ - private static final String COLOR_BUNDLE_NAME - = "resources.colors.colorResources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); - - /** - * The color resource bundle. - */ - private static final ResourceBundle COLOR_RESOURCE_BUNDLE - = ResourceBundle.getBundle(COLOR_BUNDLE_NAME); - + private static ResourceManagementService resourcesService; + /** * Returns an internationalized string corresponding to the given key. * @@ -72,14 +38,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -92,15 +51,19 @@ public class Resources { BufferedImage image = null; - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID); + InputStream in = + getResources().getImageInputStream(imageID); + + if(in == null) + return null; + try { - image = ImageIO.read(Resources.class.getClassLoader() - .getResourceAsStream(path)); + image = ImageIO.read(in); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return new ImageIcon(image); @@ -114,18 +77,22 @@ public class Resources */ public static byte[] getImageInBytes(String imageID) { - byte[] image = new byte[100000]; - - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID); + InputStream in = + getResources().getImageInputStream(imageID); + + if(in == null) + return null; + + byte[] image = null; try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + image = new byte[in.available()]; + in.read(image); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return image; @@ -140,15 +107,24 @@ public class Resources */ public static int getColor(String key) { - try + return getResources().getColor(key); + } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) { - return Integer.parseInt(COLOR_RESOURCE_BUNDLE.getString(key), 16); + ServiceReference serviceReference = PluginManagerActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)PluginManagerActivator.bundleContext + .getService(serviceReference); } - catch (MissingResourceException e) - { - log.error("Missing color resource.", e); - return 0xFFFFFF; - } + return resourcesService; } } diff --git a/src/net/java/sip/communicator/plugin/pluginmanager/pluginmanager.manifest.mf b/src/net/java/sip/communicator/plugin/pluginmanager/pluginmanager.manifest.mf index 615178f..d1202b4 100644 --- a/src/net/java/sip/communicator/plugin/pluginmanager/pluginmanager.manifest.mf +++ b/src/net/java/sip/communicator/plugin/pluginmanager/pluginmanager.manifest.mf @@ -7,6 +7,7 @@ System-Bundle: yes Import-Package: org.osgi.framework, net.java.sip.communicator.util, net.java.sip.communicator.service.gui, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.gui.event, net.java.sip.communicator.service.configuration, javax.swing, diff --git a/src/net/java/sip/communicator/plugin/rssaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/rssaccregwizz/Resources.java index df944c3..14b054e 100644 --- a/src/net/java/sip/communicator/plugin/rssaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/rssaccregwizz/Resources.java @@ -9,8 +9,11 @@ package net.java.sip.communicator.plugin.rssaccregwizz; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -22,41 +25,17 @@ public class Resources private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.rssaccregwizz.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.rssaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); - + private static ResourceManagementService resourcesService; + /** * A constant pointing to the RSS protocol logo image. */ - public static ImageID RSS_LOGO = new ImageID("protocolIcon"); + public static ImageID RSS_LOGO = new ImageID("protocolIconRss"); /** * A constant pointing to the RSS protocol wizard page image. */ - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageRss"); /** * Returns an internationalized string corresponding to the given key. @@ -66,14 +45,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException exc) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -84,17 +56,22 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + image = new byte[in.available()]; + in.read(image); } - catch (IOException exc) + catch (IOException e) { - log.error("Failed to load image:" + path, exc); + log.error("Failed to load image:" + imageID, e); } return image; @@ -118,4 +95,21 @@ public class Resources } } + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = RssAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)RssAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccountRegistrationWizard.java index 8201ef2..b779974 100644 --- a/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccountRegistrationWizard.java @@ -87,7 +87,7 @@ public class RssAccountRegistrationWizard */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameRss"); } /** @@ -97,7 +97,7 @@ public class RssAccountRegistrationWizard */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionRss"); } /** diff --git a/src/net/java/sip/communicator/plugin/rssaccregwizz/rssaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/rssaccregwizz/rssaccregwizz.manifest.mf index 215d410..1aa126c 100644 --- a/src/net/java/sip/communicator/plugin/rssaccregwizz/rssaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/rssaccregwizz/rssaccregwizz.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/plugin/simpleaccreg/Resources.java b/src/net/java/sip/communicator/plugin/simpleaccreg/Resources.java index b382c86..3a542c9 100644 --- a/src/net/java/sip/communicator/plugin/simpleaccreg/Resources.java +++ b/src/net/java/sip/communicator/plugin/simpleaccreg/Resources.java @@ -10,8 +10,11 @@ package net.java.sip.communicator.plugin.simpleaccreg; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -23,56 +26,7 @@ public class Resources private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.simpleaccreg.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * Name of the bundle where we will search for color resources. - */ - private static final String COLOR_BUNDLE_NAME - = "resources.colors.colorResources"; - - /** - * Bundle which handle access to localized resources. - */ - private static final ResourceBundle COLOR_RESOURCE_BUNDLE = ResourceBundle - .getBundle( COLOR_BUNDLE_NAME, - Locale.getDefault(), - Resources.class.getClassLoader()); - - /** - * Name of the bundle where we will search for color resources. - */ - private static final String LOGIN_BUNDLE_NAME - = "resources.login"; - - /** - * Bundle which handle access to localized resources. - */ - private static final ResourceBundle LOGIN_PROPERTIES_BUNDLE = ResourceBundle - .getBundle(LOGIN_BUNDLE_NAME); - - /** - * Name of the bundle where we will search for application resources. - */ - private static final String APPLICATION_RESUORCE_LOCATION - = "resources.application"; - - /** - * Bundle which handle access to application resources. - */ - private static final ResourceBundle applicationBundle - = ResourceBundle.getBundle(APPLICATION_RESUORCE_LOCATION); + private static ResourceManagementService resourcesService; /** * Returns an internationalized string corresponding to the given key. @@ -82,14 +36,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException exc) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -101,16 +48,7 @@ public class Resources */ public static int getColor(String key) { - try - { - return Integer.parseInt(COLOR_RESOURCE_BUNDLE.getString(key), 16); - } - catch (MissingResourceException e) - { - log.error("Missing color resource.", e); - - return 0xFFFFFF; - } + return getResources().getColor(key); } /** @@ -122,16 +60,7 @@ public class Resources */ public static String getLoginProperty(String key) { - try - { - return LOGIN_PROPERTIES_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - log.error("Missing property.", e); - - return ""; - } + return getResources().getSettingsString(key); } /** @@ -143,15 +72,24 @@ public class Resources */ public static String getApplicationProperty(String key) { - try + return getResources().getSettingsString(key); + } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) { - return applicationBundle.getString(key); + ServiceReference serviceReference = SimpleAccountRegistrationActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)SimpleAccountRegistrationActivator.bundleContext + .getService(serviceReference); } - catch (MissingResourceException e) - { - log.error("Missing property.", e); - return ""; - } + return resourcesService; } } diff --git a/src/net/java/sip/communicator/plugin/simpleaccreg/simpleaccreg.manifest.mf b/src/net/java/sip/communicator/plugin/simpleaccreg/simpleaccreg.manifest.mf index 5cba876..aa379ff 100644 --- a/src/net/java/sip/communicator/plugin/simpleaccreg/simpleaccreg.manifest.mf +++ b/src/net/java/sip/communicator/plugin/simpleaccreg/simpleaccreg.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/plugin/sipaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/sipaccregwizz/FirstWizardPage.java index e7c24ad..06ff898 100644 --- a/src/net/java/sip/communicator/plugin/sipaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/sipaccregwizz/FirstWizardPage.java @@ -136,8 +136,8 @@ public class FirstWizardPage private JComboBox keepAliveMethodBox = new JComboBox(new Object [] { - Resources.getString("register"), - Resources.getString("options") + Resources.getString("register").toUpperCase(), + Resources.getString("options").toUpperCase() }); private JTextField keepAliveIntervalValue = new JTextField(); @@ -206,7 +206,7 @@ public class FirstWizardPage uinPassPanel.add(rememberPassBox, BorderLayout.SOUTH); uinPassPanel.setBorder(BorderFactory.createTitledBorder(Resources - .getString("uinAndPassword"))); + .getString("sipUinAndPassword"))); firstTabPanel.add(uinPassPanel, BorderLayout.NORTH); diff --git a/src/net/java/sip/communicator/plugin/sipaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/sipaccregwizz/Resources.java index 8300ad3..66ed257 100644 --- a/src/net/java/sip/communicator/plugin/sipaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/sipaccregwizz/Resources.java @@ -10,8 +10,11 @@ package net.java.sip.communicator.plugin.sipaccregwizz; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -22,35 +25,11 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.sipaccregwizz.resources"; + private static ResourceManagementService resourcesService; - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.sipaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); - - public static ImageID SIP_LOGO = new ImageID("protocolIcon"); + public static ImageID SIP_LOGO = new ImageID("protocolIconSip"); - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageSip"); /** * Returns an internationalized string corresponding to the given key. @@ -59,15 +38,7 @@ public class Resources { */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -78,18 +49,22 @@ public class Resources { */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; - - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + image = new byte[in.available()]; + in.read(image); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return image; @@ -112,4 +87,22 @@ public class Resources { return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = SIPAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)SIPAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/sipaccregwizz/SIPAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/sipaccregwizz/SIPAccountRegistrationWizard.java index 3b7daff..8a6f5cb 100644 --- a/src/net/java/sip/communicator/plugin/sipaccregwizz/SIPAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/sipaccregwizz/SIPAccountRegistrationWizard.java @@ -81,7 +81,7 @@ public class SIPAccountRegistrationWizard * @return String */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameSip"); } /** @@ -90,7 +90,7 @@ public class SIPAccountRegistrationWizard * @return String */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionSip"); } /** diff --git a/src/net/java/sip/communicator/plugin/sipaccregwizz/sipaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/sipaccregwizz/sipaccregwizz.manifest.mf index 4ba1f49..dac3182 100755 --- a/src/net/java/sip/communicator/plugin/sipaccregwizz/sipaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/sipaccregwizz/sipaccregwizz.manifest.mf @@ -7,6 +7,7 @@ Import-Package: org.osgi.framework, net.java.sip.communicator.util, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.protocol.icqconstants, net.java.sip.communicator.service.protocol.event, diff --git a/src/net/java/sip/communicator/plugin/sshaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/sshaccregwizz/Resources.java index bf0fa66..b0eba2c 100644 --- a/src/net/java/sip/communicator/plugin/sshaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/sshaccregwizz/Resources.java @@ -17,8 +17,11 @@ package net.java.sip.communicator.plugin.sshaccregwizz; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -30,35 +33,11 @@ public class Resources private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.sshaccregwizz.resources"; + private static ResourceManagementService resourcesService; - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.sshaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); - - public static ImageID SSH_LOGO = new ImageID("protocolIcon"); + public static ImageID SSH_LOGO = new ImageID("protocolIconSsh"); - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageSsh"); /** * Returns an internationalized string corresponding to the given key. @@ -67,14 +46,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException exc) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -85,23 +57,22 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image=null; - InputStream inputStream; - - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; try { - inputStream = Resources.class.getClassLoader() - .getResourceAsStream(path); - - image = new byte[inputStream.available()]; - - inputStream.read(image); + image = new byte[in.available()]; + in.read(image); } - catch (IOException exc) + catch (IOException e) { - log.error("Failed to load image:" + path, exc); + log.error("Failed to load image:" + imageID, e); } return image; @@ -124,4 +95,22 @@ public class Resources return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = SSHAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)SSHAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/sshaccregwizz/SSHAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/sshaccregwizz/SSHAccountRegistrationWizard.java index 75eed15..b12ccc4 100644 --- a/src/net/java/sip/communicator/plugin/sshaccregwizz/SSHAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/sshaccregwizz/SSHAccountRegistrationWizard.java @@ -92,7 +92,7 @@ public class SSHAccountRegistrationWizard * @return String */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameSsh"); } /** @@ -101,7 +101,7 @@ public class SSHAccountRegistrationWizard * @return String */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionSsh"); } /** diff --git a/src/net/java/sip/communicator/plugin/sshaccregwizz/sshaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/sshaccregwizz/sshaccregwizz.manifest.mf index b75dc1e..663b727 100644 --- a/src/net/java/sip/communicator/plugin/sshaccregwizz/sshaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/sshaccregwizz/sshaccregwizz.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/plugin/statusupdate/Resources.java b/src/net/java/sip/communicator/plugin/statusupdate/Resources.java index 119ccee..7b74902 100644 --- a/src/net/java/sip/communicator/plugin/statusupdate/Resources.java +++ b/src/net/java/sip/communicator/plugin/statusupdate/Resources.java @@ -8,6 +8,10 @@ package net.java.sip.communicator.plugin.statusupdate; import java.util.*;
+import net.java.sip.communicator.service.resources.*;
+
+import org.osgi.framework.*;
+
/**
* The Messages class manages the access to the internationalization properties
* files.
@@ -16,11 +20,7 @@ import java.util.*; */
public class Resources
{
-
- private static final String BUNDLE_NAME = "resources.languages.plugin.statusupdate.resources";
-
- private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
- .getBundle(BUNDLE_NAME);
+ private static ResourceManagementService resourcesService;
/**
* Returns an internationalized string corresponding to the given key.
@@ -31,14 +31,24 @@ public class Resources */
public static String getString(String key)
{
- try
- {
- return RESOURCE_BUNDLE.getString(key);
-
- } catch (MissingResourceException e)
+ return getResources().getI18NString(key);
+ }
+
+ public static ResourceManagementService getResources()
+ {
+ if (resourcesService == null)
{
+ ServiceReference serviceReference = StatusUpdateActivator.bundleContext
+ .getServiceReference(ResourceManagementService.class.getName());
- return '!' + key + '!';
+ if(serviceReference == null)
+ return null;
+
+ resourcesService =
+ (ResourceManagementService)StatusUpdateActivator.bundleContext
+ .getService(serviceReference);
}
+
+ return resourcesService;
}
}
diff --git a/src/net/java/sip/communicator/plugin/statusupdate/StatusUpdateActivator.java b/src/net/java/sip/communicator/plugin/statusupdate/StatusUpdateActivator.java index abc51fa..faaf19e 100644 --- a/src/net/java/sip/communicator/plugin/statusupdate/StatusUpdateActivator.java +++ b/src/net/java/sip/communicator/plugin/statusupdate/StatusUpdateActivator.java @@ -26,7 +26,7 @@ public class StatusUpdateActivator implements BundleActivator private static Logger logger = Logger .getLogger(StatusUpdateActivator.class); - private static BundleContext bundleContext = null; + static BundleContext bundleContext = null; private static Thread thread = null; private static StatusUpdateThread runner = null; diff --git a/src/net/java/sip/communicator/plugin/statusupdate/statusupdate.manifest.mf b/src/net/java/sip/communicator/plugin/statusupdate/statusupdate.manifest.mf index cf9852f..24d2617 100644 --- a/src/net/java/sip/communicator/plugin/statusupdate/statusupdate.manifest.mf +++ b/src/net/java/sip/communicator/plugin/statusupdate/statusupdate.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.2 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.gui, diff --git a/src/net/java/sip/communicator/plugin/updatechecker/Resources.java b/src/net/java/sip/communicator/plugin/updatechecker/Resources.java index 73d4cd2..8c55fba 100644 --- a/src/net/java/sip/communicator/plugin/updatechecker/Resources.java +++ b/src/net/java/sip/communicator/plugin/updatechecker/Resources.java @@ -27,18 +27,6 @@ public class Resources private static Properties configProps = null; - private static final String LANG_BUNDLE_NAME - = "resources.languages.plugin.updatechecker.resources"; - - private static final String BUNDLE_APP_NAME - = "resources.application"; - - private static final ResourceBundle langBundle = ResourceBundle - .getBundle(LANG_BUNDLE_NAME); - - private static final ResourceBundle APP_PROPERTIES_BUNDLE = ResourceBundle - .getBundle( BUNDLE_APP_NAME); - /** * Returns an internationalized string corresponding to the given key. * @@ -64,44 +52,4 @@ public class Resources return null; } } - - /** - * Returns an internationalized string corresponding to the given key. - * - * @param key The key of the string. - * @return An internationalized string corresponding to the given key. - */ - public static String getLangString(String key) - { - try - { - return langBundle.getString(key); - } - catch (MissingResourceException e) - { - logger.error("Missing resources.", e); - - return null; - } - } - - /** - * Returns an string corresponding to the given key. - * - * @param key The key of the string. - * @return An string corresponding to the given key. - */ - public static String getAppPropString(String key) - { - try - { - return APP_PROPERTIES_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - logger.error("Missing resources.", e); - - return null; - } - } } diff --git a/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java b/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java index d4fa543..0781491 100644 --- a/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java +++ b/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java @@ -23,6 +23,7 @@ import javax.swing.text.*; import javax.swing.text.html.*; import net.java.sip.communicator.service.browserlauncher.*; import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.service.version.VersionService; import net.java.sip.communicator.util.*; @@ -42,6 +43,8 @@ public class UpdateCheckActivator private static BrowserLauncherService browserLauncherService; + private static ResourceManagementService resourcesService; + private String downloadLink = null; private String lastVersion = null; @@ -77,21 +80,23 @@ public class UpdateCheckActivator return; final JDialog dialog = new JDialog(); - dialog.setTitle(Resources.getLangString("dialogTitle")); + dialog.setTitle( + getResources().getI18NString("dialogTitle")); JEditorPane contentMessage = new JEditorPane(); contentMessage.setContentType("text/html"); contentMessage.setOpaque(false); contentMessage.setEditable(false); - String dialogMsg = MessageFormat.format( - Resources.getLangString("dialogMessage1"), - Resources.getAppPropString("applicationName")); + String dialogMsg = + getResources().getI18NString("dialogMessage1", + new String[]{getResources().getSettingsString("applicationName")}); if(lastVersion != null) - dialogMsg += MessageFormat.format( - Resources.getLangString("dialogMessage2"), - Resources.getAppPropString("applicationName"), lastVersion); + dialogMsg += + getResources().getI18NString( + "dialogMessage2", + new String[]{getResources().getSettingsString("applicationName")}); contentMessage.setText(dialogMsg); @@ -100,7 +105,8 @@ public class UpdateCheckActivator contentPane.add(contentMessage, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10)); - JButton closeButton = new JButton(Resources.getLangString("buttonClose")); + JButton closeButton = new JButton( + getResources().getI18NString("buttonClose")); closeButton.addActionListener(new ActionListener() { @@ -113,7 +119,7 @@ public class UpdateCheckActivator if(downloadLink != null) { JButton downloadButton = - new JButton(Resources.getLangString("buttonDownload")); + new JButton(getResources().getI18NString("buttonDownload")); downloadButton.addActionListener(new ActionListener() { @@ -172,6 +178,23 @@ public class UpdateCheckActivator return browserLauncherService; } + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = (ResourceManagementService) bundleContext + .getService(serviceReference); + } + + return resourcesService; + } + /** * Check the first link as files on the web are sorted by date * @param currentVersionStr diff --git a/src/net/java/sip/communicator/plugin/updatechecker/updatecheck.manifest.mf b/src/net/java/sip/communicator/plugin/updatechecker/updatecheck.manifest.mf index c081f43..fed044d 100644 --- a/src/net/java/sip/communicator/plugin/updatechecker/updatecheck.manifest.mf +++ b/src/net/java/sip/communicator/plugin/updatechecker/updatecheck.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.gui, net.java.sip.communicator.service.version, net.java.sip.communicator.service.browserlauncher, diff --git a/src/net/java/sip/communicator/plugin/whiteboard/Resources.java b/src/net/java/sip/communicator/plugin/whiteboard/Resources.java index 4e5c9a0..75a5959 100644 --- a/src/net/java/sip/communicator/plugin/whiteboard/Resources.java +++ b/src/net/java/sip/communicator/plugin/whiteboard/Resources.java @@ -14,8 +14,11 @@ import java.util.*; import javax.imageio.*; import javax.swing.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -27,32 +30,7 @@ public class Resources private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.whiteboard.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.whiteboard.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); - + private static ResourceManagementService resourcesService; /** * Returns an internationalized string corresponding to the given key. @@ -62,26 +40,7 @@ public class Resources */ public static String getString(String key) { - try - { - String resourceString = STRING_RESOURCE_BUNDLE.getString(key); - - int mnemonicIndex = resourceString.indexOf('&'); - - if(mnemonicIndex > -1) - { - String firstPart = resourceString.substring(0, mnemonicIndex); - String secondPart = resourceString.substring(mnemonicIndex + 1); - - resourceString = firstPart.concat(secondPart); - } - - return resourceString; - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -95,29 +54,7 @@ public class Resources */ public static String getString(String key, String[] params) { - try - { - String resourceString = STRING_RESOURCE_BUNDLE.getString(key); - - resourceString = MessageFormat.format( - resourceString, (Object[]) params); - - int mnemonicIndex = resourceString.indexOf('&'); - - if(mnemonicIndex > -1) - { - String firstPart = resourceString.substring(0, mnemonicIndex); - String secondPart = resourceString.substring(mnemonicIndex + 1); - - resourceString = firstPart.concat(secondPart); - } - - return resourceString; - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key, params); } /** @@ -128,21 +65,7 @@ public class Resources */ public static char getMnemonic(String key) { - try - { - String resourceString = STRING_RESOURCE_BUNDLE.getString(key); - - int mnemonicIndex = resourceString.indexOf('&'); - - if(mnemonicIndex > -1) - return resourceString.charAt(mnemonicIndex + 1); - } - catch (MissingResourceException e) - { - return 0; - } - - return 0; + return getResources().getI18nMnemonic(key); } /** @@ -155,19 +78,39 @@ public class Resources { BufferedImage image = null; - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID); - + InputStream in = + getResources().getImageInputStream(imageID); + + if(in == null) + return null; + try { - image = - ImageIO.read(Resources.class.getClassLoader() - .getResourceAsStream(path)); + image = ImageIO.read(in); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return new ImageIcon(image); } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = WhiteboardActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)WhiteboardActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } }
\ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/whiteboard/whiteboard.manifest.mf b/src/net/java/sip/communicator/plugin/whiteboard/whiteboard.manifest.mf index c1f1dec..1688917 100644 --- a/src/net/java/sip/communicator/plugin/whiteboard/whiteboard.manifest.mf +++ b/src/net/java/sip/communicator/plugin/whiteboard/whiteboard.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.contactlist, net.java.sip.communicator.service.contactlist.event, net.java.sip.communicator.service.gui, diff --git a/src/net/java/sip/communicator/plugin/yahooaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/yahooaccregwizz/FirstWizardPage.java index c5c86cf..b16eb67 100644 --- a/src/net/java/sip/communicator/plugin/yahooaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/yahooaccregwizz/FirstWizardPage.java @@ -118,7 +118,7 @@ public class FirstWizardPage uinPassPanel.add(rememberPassBox, BorderLayout.SOUTH); uinPassPanel.setBorder(BorderFactory.createTitledBorder(Resources - .getString("uinAndPassword"))); + .getString("yahooUinAndPassword"))); mainPanel.add(uinPassPanel); this.add(mainPanel, BorderLayout.NORTH); diff --git a/src/net/java/sip/communicator/plugin/yahooaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/yahooaccregwizz/Resources.java index 1655955..40760be 100644 --- a/src/net/java/sip/communicator/plugin/yahooaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/yahooaccregwizz/Resources.java @@ -10,8 +10,11 @@ package net.java.sip.communicator.plugin.yahooaccregwizz; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The <tt>Resources</tt> class manages the access to the internationalization * properties files and the image resources used in this plugin. @@ -22,35 +25,11 @@ public class Resources { private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.yahooaccregwizz.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.yahooaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); + private static ResourceManagementService resourcesService; - public static ImageID YAHOO_LOGO = new ImageID("protocolIcon"); + public static ImageID YAHOO_LOGO = new ImageID("protocolIconYahoo"); - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID PAGE_IMAGE = new ImageID("pageImageYahoo"); /** * Returns an internationalized string corresponding to the given key. @@ -59,14 +38,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException e) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -76,17 +48,22 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); + image = new byte[in.available()]; + in.read(image); } catch (IOException e) { - log.error("Failed to load image:" + path, e); + log.error("Failed to load image:" + imageID, e); } return image; @@ -109,5 +86,23 @@ public class Resources return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = YahooAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)YahooAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/yahooaccregwizz/YahooAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/yahooaccregwizz/YahooAccountRegistrationWizard.java index 1064cfa..1a9937a 100644 --- a/src/net/java/sip/communicator/plugin/yahooaccregwizz/YahooAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/yahooaccregwizz/YahooAccountRegistrationWizard.java @@ -80,7 +80,7 @@ public class YahooAccountRegistrationWizard */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameYahoo"); } /** @@ -92,7 +92,7 @@ public class YahooAccountRegistrationWizard */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionYahoo"); } /** diff --git a/src/net/java/sip/communicator/plugin/yahooaccregwizz/yahooaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/yahooaccregwizz/yahooaccregwizz.manifest.mf index 8377e3e..22e25d6 100644 --- a/src/net/java/sip/communicator/plugin/yahooaccregwizz/yahooaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/yahooaccregwizz/yahooaccregwizz.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/Resources.java index ad709cb..9caaa3e 100644 --- a/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/Resources.java +++ b/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/Resources.java @@ -10,8 +10,11 @@ package net.java.sip.communicator.plugin.zeroconfaccregwizz; import java.io.*; import java.util.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; +import org.osgi.framework.*; + /** * The Resources class manages the access to the internationalization * properties files and the images properties file. @@ -24,35 +27,11 @@ public class Resources private static Logger log = Logger.getLogger(Resources.class); - /** - * The name of the resource, where internationalization strings for this - * plugin are stored. - */ - private static final String STRING_RESOURCE_NAME - = "resources.languages.plugin.zeroconfaccregwizz.resources"; - - /** - * The name of the resource, where paths to images used in this bundle are - * stored. - */ - private static final String IMAGE_RESOURCE_NAME - = "net.java.sip.communicator.plugin.zeroconfaccregwizz.resources"; - - /** - * The string resource bundle. - */ - private static final ResourceBundle STRING_RESOURCE_BUNDLE - = ResourceBundle.getBundle(STRING_RESOURCE_NAME); - - /** - * The image resource bundle. - */ - private static final ResourceBundle IMAGE_RESOURCE_BUNDLE - = ResourceBundle.getBundle(IMAGE_RESOURCE_NAME); - - public static ImageID ZEROCONF_LOGO = new ImageID("protocolIcon"); + private static ResourceManagementService resourcesService; - public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + public static ImageID ZEROCONF_LOGO = new ImageID("protocolIconZeroconf"); + + public static ImageID PAGE_IMAGE = new ImageID("pageImageZeroconf"); /** * Returns an internationalized string corresponding to the given key. @@ -61,14 +40,7 @@ public class Resources */ public static String getString(String key) { - try - { - return STRING_RESOURCE_BUNDLE.getString(key); - } - catch (MissingResourceException exc) - { - return '!' + key + '!'; - } + return getResources().getI18NString(key); } /** @@ -78,18 +50,22 @@ public class Resources */ public static byte[] getImage(ImageID imageID) { - byte[] image = new byte[100000]; + InputStream in = + getResources().getImageInputStream(imageID.getId()); + + if(in == null) + return null; + + byte[] image = null; - String path = IMAGE_RESOURCE_BUNDLE.getString(imageID.getId()); try { - Resources.class.getClassLoader() - .getResourceAsStream(path).read(image); - + image = new byte[in.available()]; + in.read(image); } - catch (IOException exc) + catch (IOException e) { - log.error("Failed to load image:" + path, exc); + log.error("Failed to load image:" + imageID, e); } return image; @@ -116,4 +92,22 @@ public class Resources return id; } } + + public static ResourceManagementService getResources() + { + if (resourcesService == null) + { + ServiceReference serviceReference = ZeroconfAccRegWizzActivator.bundleContext + .getServiceReference(ResourceManagementService.class.getName()); + + if(serviceReference == null) + return null; + + resourcesService = + (ResourceManagementService)ZeroconfAccRegWizzActivator.bundleContext + .getService(serviceReference); + } + + return resourcesService; + } } diff --git a/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/ZeroconfAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/ZeroconfAccountRegistrationWizard.java index 57dcee4..56565a0 100644 --- a/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/ZeroconfAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/ZeroconfAccountRegistrationWizard.java @@ -87,7 +87,7 @@ public class ZeroconfAccountRegistrationWizard */ public String getProtocolName() { - return Resources.getString("protocolName"); + return Resources.getString("protocolNameZeroconf"); } /** @@ -97,7 +97,7 @@ public class ZeroconfAccountRegistrationWizard */ public String getProtocolDescription() { - return Resources.getString("protocolDescription"); + return Resources.getString("protocolDescriptionZeroconf"); } /** diff --git a/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/zeroconfaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/zeroconfaccregwizz.manifest.mf index 9762b18..f774a3e 100644 --- a/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/zeroconfaccregwizz.manifest.mf +++ b/src/net/java/sip/communicator/plugin/zeroconfaccregwizz/zeroconfaccregwizz.manifest.mf @@ -5,6 +5,7 @@ Bundle-Vendor: sip-communicator.org Bundle-Version: 0.0.1 Import-Package: org.osgi.framework, net.java.sip.communicator.util, + net.java.sip.communicator.service.resources, net.java.sip.communicator.service.configuration, net.java.sip.communicator.service.configuration.event, net.java.sip.communicator.service.protocol, diff --git a/src/net/java/sip/communicator/service/protocol/msnconstants/MsnStatusEnum.java b/src/net/java/sip/communicator/service/protocol/msnconstants/MsnStatusEnum.java index 13f2f17..d3532f8 100644 --- a/src/net/java/sip/communicator/service/protocol/msnconstants/MsnStatusEnum.java +++ b/src/net/java/sip/communicator/service/protocol/msnconstants/MsnStatusEnum.java @@ -135,7 +135,7 @@ public class MsnStatusEnum public static byte[] loadIcon(String imagePath) { InputStream is = MsnStatusEnum.class.getClassLoader() .getResourceAsStream(imagePath); -logger.info("loadIcon " + imagePath); + byte[] icon = null; try { icon = new byte[is.available()]; diff --git a/src/net/java/sip/communicator/service/resources/ColorPack.java b/src/net/java/sip/communicator/service/resources/ColorPack.java new file mode 100644 index 0000000..f0ec749 --- /dev/null +++ b/src/net/java/sip/communicator/service/resources/ColorPack.java @@ -0,0 +1,17 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.resources; + +/** + * + * @author Damian Minkov + */ +public interface ColorPack + extends ResourcePack +{ + public String RESOURCE_NAME_DEFAULT_VALUE = "DefaultColorPack"; +} diff --git a/src/net/java/sip/communicator/service/resources/ImagePack.java b/src/net/java/sip/communicator/service/resources/ImagePack.java new file mode 100644 index 0000000..70dbe63 --- /dev/null +++ b/src/net/java/sip/communicator/service/resources/ImagePack.java @@ -0,0 +1,17 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.resources; + +/** + * + * @author Damian Minkov + */ +public interface ImagePack + extends ResourcePack +{ + public String RESOURCE_NAME_DEFAULT_VALUE = "DefaultImagePack"; +} diff --git a/src/net/java/sip/communicator/service/resources/LanguagePack.java b/src/net/java/sip/communicator/service/resources/LanguagePack.java new file mode 100644 index 0000000..24843fe --- /dev/null +++ b/src/net/java/sip/communicator/service/resources/LanguagePack.java @@ -0,0 +1,21 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.resources; + +import java.util.*; + +/** + * + * @author Damian Minkov + */ +public interface LanguagePack + extends ResourcePack +{ + public String RESOURCE_NAME_DEFAULT_VALUE = "DefaultLanguagePack"; + + public Iterator getAvailableLocales(); +} diff --git a/src/net/java/sip/communicator/service/resources/ResourceManagementService.java b/src/net/java/sip/communicator/service/resources/ResourceManagementService.java new file mode 100644 index 0000000..cbb8bbc --- /dev/null +++ b/src/net/java/sip/communicator/service/resources/ResourceManagementService.java @@ -0,0 +1,58 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.resources; + +import java.io.*; +import java.net.*; +import java.util.*; + +/** + * + * @author Damian Minkov + */ +public interface ResourceManagementService +{ + // Color pack methods + public int getColor(String key); + public String getColorString(String key); + + // Image pack methods + public InputStream getImageInputStreamForPath(String path); + public InputStream getImageInputStream(String streamKey); + public URL getImageURL(String urlKey); + public URL getImageURLForPath(String path); + + // Language pack methods + public String getI18NString(String key); + public String getI18NString(String key, Locale l); + public String getI18NString(String key, String[] params); + public String getI18NString(String key, String[] params, Locale l); + public char getI18nMnemonic(String key); + public char getI18nMnemonic(String key, Locale l); + + // Settings pack methods + public URL getSettingsURL(String urlKey); + public InputStream getSettingsInputStream(String streamKey); + public String getSettingsString(String key); + public int getSettingsInt(String key); + + // Sound pack methods + public URL getSoundURL(String urlKey); + public URL getSoundURLForPath(String path); + + public Iterator getCurrentColors(); + + public Iterator getCurrentImages(); + + public Iterator getCurrentSettings(); + + public Iterator getCurrentSounds(); + + public Iterator getAvailableLocales(); + + public Iterator getI18nStringsByLocale(Locale l); +} diff --git a/src/net/java/sip/communicator/service/resources/ResourcePack.java b/src/net/java/sip/communicator/service/resources/ResourcePack.java new file mode 100644 index 0000000..976fd17 --- /dev/null +++ b/src/net/java/sip/communicator/service/resources/ResourcePack.java @@ -0,0 +1,20 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.resources; + +/** + * + * @author Damian Minkov + */ +public interface ResourcePack +{ + public String RESOURCE_NAME = "ResourceName"; + + public String getResourcePackBaseName(); + public String getName(); + public String getDescription(); +} diff --git a/src/net/java/sip/communicator/service/resources/SettingsPack.java b/src/net/java/sip/communicator/service/resources/SettingsPack.java new file mode 100644 index 0000000..5e7ea8f --- /dev/null +++ b/src/net/java/sip/communicator/service/resources/SettingsPack.java @@ -0,0 +1,17 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.resources; + +/** + * + * @author Damian Minkov + */ +public interface SettingsPack + extends ResourcePack +{ + public String RESOURCE_NAME_DEFAULT_VALUE = "DefaultSettingsPack"; +} diff --git a/src/net/java/sip/communicator/service/resources/SoundPack.java b/src/net/java/sip/communicator/service/resources/SoundPack.java new file mode 100644 index 0000000..3c6ec52 --- /dev/null +++ b/src/net/java/sip/communicator/service/resources/SoundPack.java @@ -0,0 +1,17 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.resources; + +/** + * + * @author Damian Minkov + */ +public interface SoundPack + extends ResourcePack +{ + public String RESOURCE_NAME_DEFAULT_VALUE = "DefaultSoundPack"; +} |