diff options
Diffstat (limited to 'src/net/java/sip/communicator/plugin/branding')
8 files changed, 690 insertions, 1491 deletions
diff --git a/src/net/java/sip/communicator/plugin/branding/AboutWindow.java b/src/net/java/sip/communicator/plugin/branding/AboutWindow.java index 086d891..1f75f1d 100644 --- a/src/net/java/sip/communicator/plugin/branding/AboutWindow.java +++ b/src/net/java/sip/communicator/plugin/branding/AboutWindow.java @@ -1,4 +1,4 @@ -/*
+/* * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Copyright @ 2015 Atlassian Pty Ltd @@ -15,473 +15,440 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.java.sip.communicator.plugin.branding;
-
-import java.awt.*;
-import java.awt.event.*;
-import java.io.*;
-
-import javax.imageio.*;
-import javax.swing.*;
-import javax.swing.event.*;
-
-import net.java.sip.communicator.plugin.desktoputil.*;
-import net.java.sip.communicator.plugin.desktoputil.plaf.*;
-import net.java.sip.communicator.service.browserlauncher.*;
-import net.java.sip.communicator.service.gui.*;
-import net.java.sip.communicator.util.Logger;
-import net.java.sip.communicator.util.skin.*;
-
-import org.jitsi.service.resources.*;
-import org.jitsi.util.*;
-import org.osgi.framework.*;
-
-/**
- * The <tt>AboutWindow</tt> is containing information about the application
- * name, version, license etc..
- *
- * @author Yana Stamcheva
- * @author Adam Netocny
- * @author Lyubomir Marinov
- */
-public class AboutWindow
- extends JDialog
- implements HyperlinkListener,
- ActionListener,
- ExportedWindow,
- Skinnable
-{
- /**
- * Serial version UID.
- */
- private static final long serialVersionUID = 0L;
-
- /**
- * The global/shared <code>AboutWindow</code> currently showing.
- */
- private static AboutWindow aboutWindow;
-
- /**
- * Class id key used in UIDefaults for the version label.
- */
- private static final String uiClassID =
- AboutWindow.class.getName() + "$VersionTextFieldUI";
-
- /**
- * Adds the ui class to UIDefaults.
- */
- static
- {
- UIManager.getDefaults().put(uiClassID,
- SIPCommTextFieldUI.class.getName());
- }
-
- private final JTextField versionLabel;
-
- /**
- * Shows a <code>AboutWindow</code> creating it first if necessary. The
- * shown instance is shared in order to prevent displaying multiple
- * instances of one and the same <code>AboutWindow</code>.
- */
- public static void showAboutWindow()
- {
- if (aboutWindow == null)
- {
- aboutWindow = new AboutWindow(null);
-
- /*
- * When the global/shared AboutWindow closes, don't keep a reference
- * to it and let it be garbage-collected.
- */
- aboutWindow.addWindowListener(new WindowAdapter()
- {
- @Override
- public void windowClosed(WindowEvent e)
- {
- if (aboutWindow == e.getWindow())
- aboutWindow = null;
- }
- });
- }
- aboutWindow.setVisible(true);
- }
-
- private static final int DEFAULT_TEXT_INDENT
- = BrandingActivator.getResources()
- .getSettingsInt("plugin.branding.ABOUT_TEXT_INDENT");
-
- /**
- * Creates an <tt>AboutWindow</tt> by specifying the parent frame owner.
- * @param owner the parent owner
- */
- public AboutWindow(Frame owner)
- {
- super(owner);
-
- ResourceManagementService resources = BrandingActivator.getResources();
-
- String applicationName
- = resources.getSettingsString("service.gui.APPLICATION_NAME");
-
- this.setTitle(
- resources.getI18NString("plugin.branding.ABOUT_WINDOW_TITLE",
- new String[]{applicationName}));
-
- setModal(false);
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- setResizable(false);
-
- JPanel mainPanel = new WindowBackground();
- mainPanel.setLayout(new BorderLayout());
-
- JPanel textPanel = new JPanel();
- textPanel.setPreferredSize(new Dimension(470, 280));
- textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
- textPanel.setBorder(BorderFactory
- .createEmptyBorder(15, 15, 15, 15));
- textPanel.setOpaque(false);
-
- JLabel titleLabel = null;
- if (isApplicationNameShown())
- {
- titleLabel = new JLabel(applicationName);
- titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 28));
- titleLabel.setForeground(Constants.TITLE_COLOR);
- titleLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);
- }
-
- // Force the use of the custom text field UI in order to fix an
- // incorrect rendering on Ubuntu.
- versionLabel
- = new JTextField(" "
- + System.getProperty("sip-communicator.version"))
- {
- /**
- * Returns the name of the L&F class that renders this component.
- *
- * @return the string "TreeUI"
- * @see JComponent#getUIClassID
- * @see UIDefaults#getUI
- */
- @Override
- public String getUIClassID()
- {
- return uiClassID;
- }
- };
-
- versionLabel.setBorder(null);
- versionLabel.setOpaque(false);
- versionLabel.setEditable(false);
- versionLabel.setFont(versionLabel.getFont().deriveFont(Font.BOLD, 18));
- versionLabel.setForeground(Constants.TITLE_COLOR);
- versionLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);
- versionLabel.setHorizontalAlignment(JTextField.RIGHT);
-
- int logoAreaFontSize
- = resources.getSettingsInt("plugin.branding.ABOUT_LOGO_FONT_SIZE");
-
- // FIXME: the message exceeds the window length
- JTextArea logoArea =
- new JTextArea(resources.getI18NString(
- "plugin.branding.LOGO_MESSAGE"));
- logoArea.setFont(
- logoArea.getFont().deriveFont(Font.BOLD, logoAreaFontSize));
- logoArea.setForeground(Constants.TITLE_COLOR);
- logoArea.setOpaque(false);
- logoArea.setLineWrap(true);
- logoArea.setWrapStyleWord(true);
- logoArea.setEditable(false);
- logoArea.setPreferredSize(new Dimension(100, 20));
- logoArea.setAlignmentX(Component.RIGHT_ALIGNMENT);
- logoArea.setBorder(BorderFactory
- .createEmptyBorder(30, DEFAULT_TEXT_INDENT, 0, 0));
-
- StyledHTMLEditorPane rightsArea = new StyledHTMLEditorPane();
- rightsArea.setContentType("text/html");
-
- rightsArea.appendToEnd(resources.getI18NString(
- "plugin.branding.COPYRIGHT",
- new String[]
- { Constants.TEXT_COLOR }));
-
- rightsArea.setPreferredSize(new Dimension(50, 20));
- rightsArea
- .setBorder(BorderFactory
- .createEmptyBorder(0, DEFAULT_TEXT_INDENT, 0, 0));
- rightsArea.setOpaque(false);
- rightsArea.setEditable(false);
- rightsArea.setAlignmentX(Component.RIGHT_ALIGNMENT);
- rightsArea.addHyperlinkListener(this);
-
- StyledHTMLEditorPane licenseArea = new StyledHTMLEditorPane();
- licenseArea.setContentType("text/html");
- licenseArea.appendToEnd(resources.
- getI18NString("plugin.branding.LICENSE",
- new String[]{Constants.TEXT_COLOR}));
-
- licenseArea.setPreferredSize(new Dimension(50, 20));
- licenseArea.setBorder(
- BorderFactory.createEmptyBorder(
- resources.getSettingsInt("plugin.branding.ABOUT_PARAGRAPH_GAP"),
- DEFAULT_TEXT_INDENT,
- 0, 0));
- licenseArea.setOpaque(false);
- licenseArea.setEditable(false);
- licenseArea.setAlignmentX(Component.RIGHT_ALIGNMENT);
- licenseArea.addHyperlinkListener(this);
-
- if (titleLabel != null)
- textPanel.add(titleLabel);
-
- textPanel.add(versionLabel);
- textPanel.add(logoArea);
- textPanel.add(rightsArea);
- textPanel.add(licenseArea);
-
- JButton okButton
- = new JButton(resources.getI18NString("service.gui.OK"));
-
- this.getRootPane().setDefaultButton(okButton);
-
- okButton.setMnemonic(resources.getI18nMnemonic("service.gui.OK"));
- okButton.addActionListener(this);
-
- JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
- buttonPanel.add(okButton);
- buttonPanel.setOpaque(false);
-
- mainPanel.add(textPanel, BorderLayout.CENTER);
- mainPanel.add(buttonPanel, BorderLayout.SOUTH);
-
- this.getContentPane().add(mainPanel);
-
- this.pack();
-
- setLocationRelativeTo(getParent());
-
- this.getRootPane().getActionMap().put("close", new CloseAction());
-
- InputMap imap = this.getRootPane().getInputMap(
- JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
-
- imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
-
- if(OSUtils.IS_MAC)
- {
- imap.put(
- KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.META_DOWN_MASK),
- "close");
- imap.put(
- KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK),
- "close");
- }
-
- WindowUtils.addWindow(this);
- }
-
- /**
- * Reloads text field UI.
- */
- public void loadSkin()
- {
- if(versionLabel.getUI() instanceof Skinnable)
- ((Skinnable)versionLabel.getUI()).loadSkin();
- }
-
- /**
- * Constructs the window background in order to have a background image.
- */
- private static class WindowBackground
- extends JPanel
- implements Skinnable
- {
- /**
- * Serial version UID.
- */
- private static final long serialVersionUID = 0L;
-
- private static final Logger logger
- = Logger.getLogger(WindowBackground.class);
-
- private Image bgImage = null;
-
- public WindowBackground()
- {
- loadSkin();
- }
-
- /**
- * Reloads resources for this component.
- */
- public void loadSkin()
- {
- try
- {
- bgImage = ImageIO.read(BrandingActivator.getResources().
- getImageURL("plugin.branding.ABOUT_WINDOW_BACKGROUND"));
-
- this.setPreferredSize(new Dimension(bgImage.getWidth(this),
- bgImage.getHeight(this)));
- }
- catch (IOException e)
- {
- logger.error("Error cannot obtain background image", e);
- bgImage = null;
- }
- }
-
- @Override
- protected void paintComponent(Graphics g)
- {
- super.paintComponent(g);
-
- g = g.create();
- try
- {
- AntialiasingManager.activateAntialiasing(g);
-
- int bgImageWidth = bgImage.getWidth(null);
- int bgImageHeight = bgImage.getHeight(null);
- boolean bgImageHasBeenDrawn = false;
-
- if ((bgImageWidth != -1) && (bgImageHeight != -1))
- {
- int width = getWidth();
- int height = getHeight();
-
- if ((bgImageWidth < width) || (bgImageHeight < height))
- {
- g.drawImage(bgImage, 0, 0, width, height, null);
- bgImageHasBeenDrawn = true;
- }
- }
-
- if (!bgImageHasBeenDrawn)
- g.drawImage(bgImage, 0, 0, null);
- }
- finally
- {
- g.dispose();
- }
- }
- }
-
- /**
- * Opens a browser when the link has been activated (clicked).
- * @param e the <tt>HyperlinkEvent</tt> that notified us
- */
- public void hyperlinkUpdate(HyperlinkEvent e)
- {
- if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
- {
- String href = e.getDescription();
- ServiceReference serviceReference = BrandingActivator
- .getBundleContext().getServiceReference(
- BrowserLauncherService.class.getName());
-
- if (serviceReference != null)
- {
- BrowserLauncherService browserLauncherService
- = (BrowserLauncherService) BrandingActivator
- .getBundleContext().getService(serviceReference);
-
- browserLauncherService.openURL(href);
- }
- }
- }
-
- /**
- * Indicates that the ok button has been pressed. Closes the window.
- * @param e the <tt>ActionEvent</tt> that notified us
- */
- public void actionPerformed(ActionEvent e)
- {
- setVisible(false);
- dispose();
- }
-
- /**
- * Implements the <tt>ExportedWindow.getIdentifier()</tt> method.
- * @return the identifier of this exported window
- */
- public WindowID getIdentifier()
- {
- return ExportedWindow.ABOUT_WINDOW;
- }
-
- /**
- * This dialog could not be minimized.
- */
- public void minimize()
- {
- }
-
- /**
- * This dialog could not be maximized.
- */
- public void maximize()
- {
- }
-
- /**
- * Implements the <tt>ExportedWindow.bringToFront()</tt> method. Brings
- * this window to front.
- */
- public void bringToFront()
- {
- this.toFront();
- }
-
- /**
- * The source of the window
- * @return the source of the window
- */
- public Object getSource()
- {
- return this;
- }
-
- /**
- * Implementation of {@link ExportedWindow#setParams(Object[])}.
- */
- public void setParams(Object[] windowParams) {}
-
- /**
- * The action invoked when user presses Escape key.
- */
- private class CloseAction extends UIAction
- {
- /**
- * Serial version UID.
- */
- private static final long serialVersionUID = 0L;
-
- public void actionPerformed(ActionEvent e)
- {
- setVisible(false);
- dispose();
- }
- }
-
- /**
- * Indicates if the application name should be shown.
- *
- * @return <tt>true</tt> if the application name should be shown,
- * <tt>false</tt> - otherwise
- */
- private boolean isApplicationNameShown()
- {
- String showApplicationNameProp
- = BrandingActivator.getResources().getSettingsString(
- "plugin.branding.IS_APPLICATION_NAME_SHOWN");
-
- if (showApplicationNameProp != null
- && showApplicationNameProp.length() > 0)
- {
- return Boolean.parseBoolean(showApplicationNameProp);
- }
-
- return true;
- }
-}
+package net.java.sip.communicator.plugin.branding; + +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.net.*; +import java.util.*; + +import javax.imageio.*; +import javax.swing.*; +import javax.swing.event.*; + +import net.java.sip.communicator.plugin.desktoputil.*; +import net.java.sip.communicator.plugin.desktoputil.plaf.*; +import net.java.sip.communicator.service.browserlauncher.*; +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.util.Logger; +import net.java.sip.communicator.util.skin.*; + +import org.jitsi.service.resources.*; +import org.jitsi.util.*; +import org.osgi.framework.*; + +/** + * The <tt>AboutWindow</tt> is containing information about the application + * name, version, license etc.. + * + * @author Yana Stamcheva + * @author Adam Netocny + * @author Lyubomir Marinov + */ +public class AboutWindow + extends JDialog + implements HyperlinkListener, + ActionListener, + ExportedWindow, + Skinnable +{ + /** + * Serial version UID. + */ + private static final long serialVersionUID = 0L; + + private static AboutWindow aboutWindow; + + /** + * Class id key used in UIDefaults for the version label. + */ + private static final String uiClassID = + AboutWindow.class.getName() + "$VersionTextFieldUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(uiClassID, + SIPCommTextFieldUI.class.getName()); + } + + private final JTextField versionLabel; + + /** + * Shows a <code>AboutWindow</code> creating it first if necessary. The + * shown instance is shared in order to prevent displaying multiple + * instances of one and the same <code>AboutWindow</code>. + */ + public static void showAboutWindow() + { + if (aboutWindow == null) + { + aboutWindow = new AboutWindow(null); + + /* + * When the global/shared AboutWindow closes, don't keep a reference + * to it and let it be garbage-collected. + */ + aboutWindow.addWindowListener(new WindowAdapter() + { + @Override + public void windowClosed(WindowEvent e) + { + if (aboutWindow == e.getWindow()) + aboutWindow = null; + } + }); + } + aboutWindow.setVisible(true); + } + + private static final int DEFAULT_TEXT_INDENT + = BrandingActivator.getResources() + .getSettingsInt("plugin.branding.ABOUT_TEXT_INDENT"); + + /** + * Creates an <tt>AboutWindow</tt> by specifying the parent frame owner. + * @param owner the parent owner + */ + public AboutWindow(Frame owner) + { + super(owner); + + ResourceManagementService resources = BrandingActivator.getResources(); + + String applicationName = + resources.getSettingsString("service.gui.APPLICATION_NAME"); + String website = + resources.getSettingsString("service.gui.APPLICATION_WEB_SITE"); + + this.setTitle( + resources.getI18NString("plugin.branding.ABOUT_WINDOW_TITLE", + new String[]{applicationName})); + + setModal(false); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + setResizable(false); + + JPanel mainPanel = new WindowBackground(); + mainPanel.setLayout(new BorderLayout()); + + JPanel textPanel = new JPanel(); + textPanel.setPreferredSize(new Dimension(470, 280)); + textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS)); + textPanel.setBorder(BorderFactory + .createEmptyBorder(15, 15, 15, 15)); + textPanel.setOpaque(false); + + JLabel titleLabel = new JLabel(applicationName); + titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 28)); + titleLabel.setForeground(Constants.TITLE_COLOR); + titleLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); + + // Force the use of the custom text field UI in order to fix an + // incorrect rendering on Ubuntu. + versionLabel + = new JTextField(" " + + System.getProperty("sip-communicator.version")) + { + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + @Override + public String getUIClassID() + { + return uiClassID; + } + }; + + versionLabel.setBorder(null); + versionLabel.setOpaque(false); + versionLabel.setEditable(false); + versionLabel.setFont(versionLabel.getFont().deriveFont(Font.BOLD, 18)); + versionLabel.setForeground(Constants.TITLE_COLOR); + versionLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); + versionLabel.setHorizontalAlignment(JTextField.RIGHT); + + int logoAreaFontSize + = resources.getSettingsInt("plugin.branding.ABOUT_LOGO_FONT_SIZE"); + + JTextArea logoArea = + new JTextArea(resources.getI18NString( + "plugin.branding.LOGO_MESSAGE")); + logoArea.setFont( + logoArea.getFont().deriveFont(Font.BOLD, logoAreaFontSize)); + logoArea.setForeground(Constants.TITLE_COLOR); + logoArea.setOpaque(false); + logoArea.setLineWrap(true); + logoArea.setWrapStyleWord(true); + logoArea.setEditable(false); + logoArea.setAlignmentX(Component.RIGHT_ALIGNMENT); + logoArea.setBorder(BorderFactory + .createEmptyBorder(30, DEFAULT_TEXT_INDENT, 0, 0)); + + StyledHTMLEditorPane rightsArea = new StyledHTMLEditorPane(); + rightsArea.setContentType("text/html"); + + String host = website; + try + { + host = new URL(website).getHost(); + } + catch (Exception ex) + {} + + rightsArea.appendToEnd(resources.getI18NString( + "plugin.branding.COPYRIGHT_LICENSE", + new String[] + { + Constants.TEXT_COLOR, + Integer.toString(Calendar.getInstance().get(Calendar.YEAR)), + website, + host, + applicationName, + "http://www.apache.org/licenses/LICENSE-2.0", + "Apache License 2.0" + })); + + rightsArea.setBorder(BorderFactory + .createEmptyBorder(0, DEFAULT_TEXT_INDENT, 0, 0)); + rightsArea.setOpaque(false); + rightsArea.setEditable(false); + rightsArea.setAlignmentX(Component.RIGHT_ALIGNMENT); + rightsArea.addHyperlinkListener(this); + + textPanel.add(titleLabel); + textPanel.add(versionLabel); + textPanel.add(logoArea); + textPanel.add(rightsArea); + + JButton okButton + = new JButton(resources.getI18NString("service.gui.OK")); + + this.getRootPane().setDefaultButton(okButton); + + okButton.setMnemonic(resources.getI18nMnemonic("service.gui.OK")); + okButton.addActionListener(this); + + JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + buttonPanel.add(okButton); + buttonPanel.setOpaque(false); + + mainPanel.add(textPanel, BorderLayout.CENTER); + mainPanel.add(buttonPanel, BorderLayout.SOUTH); + + this.getContentPane().add(mainPanel); + + this.pack(); + + setLocationRelativeTo(getParent()); + + this.getRootPane().getActionMap().put("close", new CloseAction()); + + InputMap imap = this.getRootPane().getInputMap( + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + + imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close"); + + if(OSUtils.IS_MAC) + { + imap.put( + KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.META_DOWN_MASK), + "close"); + imap.put( + KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK), + "close"); + } + + WindowUtils.addWindow(this); + } + + /** + * Reloads text field UI. + */ + public void loadSkin() + { + if(versionLabel.getUI() instanceof Skinnable) + ((Skinnable)versionLabel.getUI()).loadSkin(); + } + + /** + * Constructs the window background in order to have a background image. + */ + private static class WindowBackground + extends JPanel + implements Skinnable + { + /** + * Serial version UID. + */ + private static final long serialVersionUID = 0L; + + private static final Logger logger + = Logger.getLogger(WindowBackground.class); + + private Image bgImage = null; + + public WindowBackground() + { + loadSkin(); + } + + /** + * Reloads resources for this component. + */ + public void loadSkin() + { + try + { + bgImage = ImageIO.read(BrandingActivator.getResources(). + getImageURL("plugin.branding.ABOUT_WINDOW_BACKGROUND")); + + this.setPreferredSize(new Dimension(bgImage.getWidth(this), + bgImage.getHeight(this))); + } + catch (IOException e) + { + logger.error("Error cannot obtain background image", e); + bgImage = null; + } + } + + @Override + protected void paintComponent(Graphics g) + { + super.paintComponent(g); + + g = g.create(); + try + { + AntialiasingManager.activateAntialiasing(g); + + int bgImageWidth = bgImage.getWidth(null); + int bgImageHeight = bgImage.getHeight(null); + boolean bgImageHasBeenDrawn = false; + + if ((bgImageWidth != -1) && (bgImageHeight != -1)) + { + int width = getWidth(); + int height = getHeight(); + + if ((bgImageWidth < width) || (bgImageHeight < height)) + { + g.drawImage(bgImage, 0, 0, width, height, null); + bgImageHasBeenDrawn = true; + } + } + + if (!bgImageHasBeenDrawn) + g.drawImage(bgImage, 0, 0, null); + } + finally + { + g.dispose(); + } + } + } + + /** + * Opens a browser when the link has been activated (clicked). + * @param e the <tt>HyperlinkEvent</tt> that notified us + */ + public void hyperlinkUpdate(HyperlinkEvent e) + { + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) + { + ServiceReference<BrowserLauncherService> serviceReference = + BrandingActivator.getBundleContext().getServiceReference( + BrowserLauncherService.class); + + if (serviceReference != null) + { + BrowserLauncherService browserLauncherService + = BrandingActivator + .getBundleContext().getService(serviceReference); + + browserLauncherService.openURL(e.getDescription()); + } + } + } + + /** + * Indicates that the ok button has been pressed. Closes the window. + * @param e the <tt>ActionEvent</tt> that notified us + */ + public void actionPerformed(ActionEvent e) + { + setVisible(false); + dispose(); + } + + /** + * Implements the <tt>ExportedWindow.getIdentifier()</tt> method. + * @return the identifier of this exported window + */ + public WindowID getIdentifier() + { + return ExportedWindow.ABOUT_WINDOW; + } + + /** + * This dialog could not be minimized. + */ + public void minimize() + { + } + + /** + * This dialog could not be maximized. + */ + public void maximize() + { + } + + /** + * Implements the <tt>ExportedWindow.bringToFront()</tt> method. Brings + * this window to front. + */ + public void bringToFront() + { + this.toFront(); + } + + /** + * The source of the window + * @return the source of the window + */ + public Object getSource() + { + return this; + } + + /** + * Implementation of {@link ExportedWindow#setParams(Object[])}. + */ + public void setParams(Object[] windowParams) {} + + /** + * The action invoked when user presses Escape key. + */ + private class CloseAction extends UIAction + { + /** + * Serial version UID. + */ + private static final long serialVersionUID = 0L; + + public void actionPerformed(ActionEvent e) + { + setVisible(false); + dispose(); + } + } +} diff --git a/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java b/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java index 333781d..eb2d61a 100644 --- a/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java +++ b/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java @@ -1,4 +1,4 @@ -/*
+/* * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Copyright @ 2015 Atlassian Pty Ltd @@ -15,89 +15,89 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.java.sip.communicator.plugin.branding;
-
-import java.awt.event.*;
-
-import javax.swing.*;
-
-import net.java.sip.communicator.service.gui.*;
-
-/**
- * Implements an About menu item for the Help menu of the application in the
- * form of a <tt>PluginComponent</tt>.
- *
- * @author Lyubomir Marinov
- */
-public class AboutWindowPluginComponent
- extends AbstractPluginComponent
-{
-
- /**
- * Invokes the default action associated with Help > About regardless of the
- * specifics of its visual representation.
- */
- public static void actionPerformed()
- {
- AboutWindow.showAboutWindow();
- }
-
- private JMenuItem aboutMenuItem;
-
- /**
- * Constructor.
- *
- * @param container parent container
- */
- public AboutWindowPluginComponent(Container container,
- PluginComponentFactory parentFactory)
- {
- super(container, parentFactory);
- }
-
- public Object getComponent()
- {
- if (aboutMenuItem == null)
- {
- aboutMenuItem = new JMenuItem(getName());
- aboutMenuItem
- .setMnemonic(
- BrandingActivator
- .getResources()
- .getI18nMnemonic(
- "plugin.branding.ABOUT_MENU_ENTRY"));
-
- aboutMenuItem.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- AboutWindowPluginComponent.actionPerformed();
- }
- });
- }
- return aboutMenuItem;
- }
-
- public String getName()
- {
- return
- BrandingActivator
- .getResources()
- .getI18NString("plugin.branding.ABOUT_MENU_ENTRY");
- }
-
- /**
- * Implements {@link PluginComponent#getPositionIndex()}. Returns
- * <tt>Integer#MAX_VALUE</tt> in order to indicate that the About menu item
- * in the Help menu is conventionally displayed at the very bottom.
- *
- * @return <tt>Integer#MAX_VALUE</tt> in order to indicate that the About
- * menu item in the Help menu is conventionally displayed at the very bottom
- * @see AbstractPluginComponent#getPositionIndex()
- */
- @Override
- public int getPositionIndex()
- {
- return Integer.MAX_VALUE;
- }
-}
+package net.java.sip.communicator.plugin.branding; + +import java.awt.event.*; + +import javax.swing.*; + +import net.java.sip.communicator.service.gui.*; + +/** + * Implements an About menu item for the Help menu of the application in the + * form of a <tt>PluginComponent</tt>. + * + * @author Lyubomir Marinov + */ +public class AboutWindowPluginComponent + extends AbstractPluginComponent +{ + + /** + * Invokes the default action associated with Help > About regardless of the + * specifics of its visual representation. + */ + public static void actionPerformed() + { + AboutWindow.showAboutWindow(); + } + + private JMenuItem aboutMenuItem; + + /** + * Constructor. + * + * @param container parent container + */ + public AboutWindowPluginComponent(Container container, + PluginComponentFactory parentFactory) + { + super(container, parentFactory); + } + + public Object getComponent() + { + if (aboutMenuItem == null) + { + aboutMenuItem = new JMenuItem(getName()); + aboutMenuItem + .setMnemonic( + BrandingActivator + .getResources() + .getI18nMnemonic( + "plugin.branding.ABOUT_MENU_ENTRY")); + + aboutMenuItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + AboutWindowPluginComponent.actionPerformed(); + } + }); + } + return aboutMenuItem; + } + + public String getName() + { + return + BrandingActivator + .getResources() + .getI18NString("plugin.branding.ABOUT_MENU_ENTRY"); + } + + /** + * Implements {@link PluginComponent#getPositionIndex()}. Returns + * <tt>Integer#MAX_VALUE</tt> in order to indicate that the About menu item + * in the Help menu is conventionally displayed at the very bottom. + * + * @return <tt>Integer#MAX_VALUE</tt> in order to indicate that the About + * menu item in the Help menu is conventionally displayed at the very bottom + * @see AbstractPluginComponent#getPositionIndex() + */ + @Override + public int getPositionIndex() + { + return Integer.MAX_VALUE; + } +} diff --git a/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java b/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java index 6d8bdfd..f6de958 100644 --- a/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java +++ b/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java @@ -33,91 +33,12 @@ import org.osgi.framework.*; */ public class BrandingActivator extends AbstractServiceDependentActivator - implements BundleListener { private final Logger logger = Logger.getLogger(BrandingActivator.class); - - /** - * The name of the boolean property which indicates whether the splash - * screen (i.e. <code>WelcomeWindow</code>) is to be shown or to not be - * utilized for the sake of better memory consumption and faster startup. - */ - private static final String PNAME_SHOW_SPLASH_SCREEN - = "net.java.sip.communicator.plugin.branding.SHOW_SPLASH_SCREEN"; - private static BundleContext bundleContext; - private static ResourceManagementService resourcesService; /** - * The welcome window. - */ - private WelcomeWindow welcomeWindow; - - @Override - public void start(BundleContext bc) throws Exception - { - super.start(bc); - - ConfigurationService config = getConfigurationService(); - boolean showSplashScreen - = (config == null) - ? true /* - * Having no ConfigurationService reference is not good - * for the application so we are better off with the - * splash screen to actually see which bundles get loaded - * and maybe be able to debug the problem. - */ - : config.getBoolean(PNAME_SHOW_SPLASH_SCREEN, false); - - /* - * WelcomeWindow is huge because it has a large image spread all over it - * so, given it's only necessary before the UIService gets activated, we - * certainly don't want to keep it around (e.g. as an instance field or - * as a final variable used inside a BundleListener which never gets - * removed). - */ - if (showSplashScreen) - { - welcomeWindow = new WelcomeWindow(); - welcomeWindow.pack(); - welcomeWindow.setVisible(true); - } - else - welcomeWindow = null; - - if (getResources().getSettingsString( - "service.gui.APPLICATION_NAME").equals("SIP Communicator")) - new JitsiWarningWindow(null).setVisible(true); - - bundleContext.addBundleListener(this); - } - - /** - * Bundle has been started if welcome window is available and visible - * update it to show the bundle activity. - * @param evt - */ - public synchronized void bundleChanged(BundleEvent evt) - { - if (welcomeWindow != null - && welcomeWindow.isShowing() - && (evt.getType() == BundleEvent.STARTED)) - { - /* - * The IBM JRE on GNU/Linux reports the Bundle-Name as null while - * the SUN JRE reports it as non-null. Just prevent the throwing of - * a NullPointerException because displaying the Bundle-Name isn't - * vital anyway. - */ - Object bundleName = evt.getBundle().getHeaders().get("Bundle-Name"); - - welcomeWindow.setBundle( - (bundleName == null) ? null : bundleName.toString()); - } - } - - /** * Setting context to the activator, as soon as we have one. * * @param context the context to set. @@ -145,31 +66,12 @@ public class BrandingActivator @Override public void start(Object dependentService) { - // UI-Service started. - - /* - * Don't let bundleContext retain a reference to this - * listener because it'll retain a reference to - * welcomeWindow. Besides, we're no longer interested in - * handling events so it doesn't make sense to even retain - * this listener. - */ - bundleContext.removeBundleListener(this); - // register the about dialog menu entry registerMenuEntry((UIService)dependentService); - - if (welcomeWindow != null) - { - synchronized(this) - { - welcomeWindow.close(); - welcomeWindow = null; - } - } } - public void stop(BundleContext arg0) throws Exception + @Override + public void stop(BundleContext context) throws Exception { } @@ -189,7 +91,6 @@ public class BrandingActivator private boolean registerMenuEntryMacOSX(UIService uiService) { - Exception exception = null; try { Class<?> clazz = @@ -199,28 +100,16 @@ public class BrandingActivator Object result = method.invoke(null, (Object[]) null); if (result instanceof Boolean) + { return ((Boolean) result).booleanValue(); + } } - catch (ClassNotFoundException ex) - { - exception = ex; - } - catch (IllegalAccessException ex) - { - exception = ex; - } - catch (InvocationTargetException ex) - { - exception = ex; - } - catch (NoSuchMethodException ex) + catch (Exception ex) { - exception = ex; + logger.error("Failed to register Mac OS X-specific About handling.", + ex); } - if (exception != null) - logger.error( - "Failed to register Mac OS X-specific About handling.", - exception); + return false; } @@ -276,17 +165,6 @@ public class BrandingActivator return bundleContext; } - private static ConfigurationService getConfigurationService() - { - ServiceReference serRef - = bundleContext - .getServiceReference(ConfigurationService.class.getName()); - return - (serRef == null) - ? null - : (ConfigurationService) bundleContext.getService(serRef); - } - /** * Returns the <tt>ResourceManagementService</tt>. * diff --git a/src/net/java/sip/communicator/plugin/branding/Constants.java b/src/net/java/sip/communicator/plugin/branding/Constants.java index 9d15df4..b098e4d 100644 --- a/src/net/java/sip/communicator/plugin/branding/Constants.java +++ b/src/net/java/sip/communicator/plugin/branding/Constants.java @@ -1,4 +1,4 @@ -/*
+/* * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Copyright @ 2015 Atlassian Pty Ltd @@ -15,65 +15,65 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.java.sip.communicator.plugin.branding;
-
-import java.awt.*;
-import java.io.*;
-
-import javax.swing.text.html.*;
-
-/**
- * All look and feel related constants are stored here.
- *
- * @author Yana Stamcheva
- */
-public class Constants
-{
- /*
- * ======================================================================
- * -------------------- FONTS AND COLOR CONSTANTS ------------------------
- * ======================================================================
- */
-
- /**
- * Dark blue color used in the about window and the splash screen.
- */
- public static final Color TITLE_COLOR
- = new Color(BrandingActivator.getResources()
- .getColor("service.gui.SPLASH_SCREEN_TITLE_COLOR"));
-
- /**
- * Text color used in the about window and the splash screen.
- */
- public static final String TEXT_COLOR
- = BrandingActivator.getResources()
- .getColorString("service.gui.SPLASH_SCREEN_TEXT_COLOR");
-
-
- /*
- * ======================================================================
- * --------------------------- FONT CONSTANTS ---------------------------
- * ======================================================================
- */
-
- /**
- * Temporary method to load the css style used in the chat window.
- *
- * @param style
- */
- public static void loadSimpleStyle(StyleSheet style)
- {
- InputStream is = BrandingActivator.getResources().
- getSettingsInputStream("service.gui.HTML_TEXT_STYLE");
-
- Reader r = new BufferedReader(new InputStreamReader(is));
- try
- {
- style.loadRules(r, null);
- r.close();
- }
- catch (IOException e)
- {
- }
- }
-}
+package net.java.sip.communicator.plugin.branding; + +import java.awt.*; +import java.io.*; + +import javax.swing.text.html.*; + +/** + * All look and feel related constants are stored here. + * + * @author Yana Stamcheva + */ +public class Constants +{ + /* + * ====================================================================== + * -------------------- FONTS AND COLOR CONSTANTS ------------------------ + * ====================================================================== + */ + + /** + * Dark blue color used in the about window and the splash screen. + */ + public static final Color TITLE_COLOR + = new Color(BrandingActivator.getResources() + .getColor("service.gui.SPLASH_SCREEN_TITLE_COLOR")); + + /** + * Text color used in the about window and the splash screen. + */ + public static final String TEXT_COLOR + = BrandingActivator.getResources() + .getColorString("service.gui.SPLASH_SCREEN_TEXT_COLOR"); + + + /* + * ====================================================================== + * --------------------------- FONT CONSTANTS --------------------------- + * ====================================================================== + */ + + /** + * Temporary method to load the css style used in the chat window. + * + * @param style + */ + public static void loadSimpleStyle(StyleSheet style) + { + InputStream is = BrandingActivator.getResources(). + getSettingsInputStream("service.gui.HTML_TEXT_STYLE"); + + Reader r = new BufferedReader(new InputStreamReader(is)); + try + { + style.loadRules(r, null); + r.close(); + } + catch (IOException e) + { + } + } +} diff --git a/src/net/java/sip/communicator/plugin/branding/JitsiWarningWindow.java b/src/net/java/sip/communicator/plugin/branding/JitsiWarningWindow.java deleted file mode 100644 index 0ca6a89..0000000 --- a/src/net/java/sip/communicator/plugin/branding/JitsiWarningWindow.java +++ /dev/null @@ -1,203 +0,0 @@ -/*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Copyright @ 2015 Atlassian Pty Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.java.sip.communicator.plugin.branding;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import javax.swing.*;
-
-import net.java.sip.communicator.plugin.desktoputil.*;
-import net.java.sip.communicator.service.browserlauncher.*;
-
-import org.jitsi.service.resources.*;
-import org.jitsi.util.*;
-import org.osgi.framework.*;
-
-/**
- * The <tt>JitsiWarningWindow</tt>.
- *
- * @author Yana Stamcheva
- */
-public class JitsiWarningWindow
- extends SIPCommDialog
-{
- /**
- * Serial version UID.
- */
- private static final long serialVersionUID = 0L;
-
- /**
- * Creates an <tt>JitsiWarningWindow</tt> by specifying the parent frame
- * owner.
- * @param owner the parent owner
- */
- public JitsiWarningWindow(Frame owner)
- {
- super(owner, false);
-
- ResourceManagementService resources = BrandingActivator.getResources();
-
- this.setTitle(
- resources.getI18NString("service.gui.UPDATE")
- + " " + resources.getSettingsString(
- "service.gui.APPLICATION_NAME"));
-
- setModal(false);
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);
-
- StyledHTMLEditorPane textArea = new StyledHTMLEditorPane();
- textArea.setContentType("text/html");
- textArea.setText(resources.getI18NString("service.gui.JITSI_WARNING"));
- textArea.setOpaque(false);
- textArea.setEditable(false);
-
- JLabel titleLabel = new JLabel(
- resources.getI18NString("service.gui.JITSI_WARNING_TITLE"));
- titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 14f));
- titleLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
- titleLabel.setMaximumSize(new Dimension(400, 50));
-
- JPanel textPanel = new TransparentPanel();
- textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
-
- textPanel.add(titleLabel);
- textPanel.add(Box.createRigidArea(new Dimension(20, 20)));
- textPanel.add(textArea);
-
- JButton downloadButton = new JButton(
- resources.getI18NString("service.gui.DOWNLOAD_NOW"));
- JButton remindButton = new JButton(
- resources.getI18NString("service.gui.REMIND_ME_LATER"));
-
- this.getRootPane().setDefaultButton(downloadButton);
-
- downloadButton.setMnemonic(
- resources.getI18nMnemonic("service.gui.DOWNLOAD_NOW"));
- downloadButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- openURL(getDownloadLink());
- dispose();
- }
- });
- remindButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- dispose();
- }
- });
-
- JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
- buttonPanel.add(remindButton);
- buttonPanel.add(downloadButton);
- buttonPanel.setOpaque(false);
-
- JPanel mainPanel = new TransparentPanel(new BorderLayout(10, 10));
- mainPanel.add(new JLabel(resources.getImage(
- "service.gui.SIP_COMMUNICATOR_LOGO_128x128")), BorderLayout.WEST);
- mainPanel.add(textPanel, BorderLayout.CENTER);
- mainPanel.add(buttonPanel, BorderLayout.SOUTH);
- mainPanel.setPreferredSize(new Dimension(500, 200));
- mainPanel.setBorder(
- BorderFactory.createEmptyBorder(20, 20, 20, 20));
-
- getContentPane().add(mainPanel);
-
- this.pack();
- this.setResizable(false);
-
- setLocationRelativeTo(getParent());
-
- this.getRootPane().getActionMap().put("close", new CloseAction());
-
- InputMap imap = this.getRootPane().getInputMap(
- JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
-
- imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
-
- if(OSUtils.IS_MAC)
- {
- imap.put(
- KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.META_DOWN_MASK),
- "close");
- imap.put(
- KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK),
- "close");
- }
- }
-
- /**
- * The action invoked when user presses Escape key.
- */
- private class CloseAction extends UIAction
- {
- /**
- * Serial version UID.
- */
- private static final long serialVersionUID = 0L;
-
- public void actionPerformed(ActionEvent e)
- {
- setVisible(false);
- dispose();
- }
- }
-
- /**
- * Opens the given url in a new browser window.
- * @param url the url to open
- */
- private void openURL(String url)
- {
- ServiceReference serviceReference = BrandingActivator
- .getBundleContext().getServiceReference(
- BrowserLauncherService.class.getName());
-
- if (serviceReference != null)
- {
- BrowserLauncherService browserLauncherService
- = (BrowserLauncherService) BrandingActivator
- .getBundleContext().getService(
- serviceReference);
-
- browserLauncherService.openURL(url);
- }
- }
-
- /**
- * Indicates if the application name should be shown.
- *
- * @return <tt>true</tt> if the application name should be shown,
- * <tt>false</tt> - otherwise
- */
- private String getDownloadLink()
- {
- if (OSUtils.IS_WINDOWS)
- return "http://download.jitsi.org/jitsi/windows/";
- else if (OSUtils.IS_MAC)
- return "http://download.jitsi.org/jitsi/macosx/";
-
- return "http://download.jitsi.org";
- }
-
- @Override
- protected void close(boolean escaped) {}
-}
diff --git a/src/net/java/sip/communicator/plugin/branding/MacOSXAboutRegistration.java b/src/net/java/sip/communicator/plugin/branding/MacOSXAboutRegistration.java index 22ce126..0648e4b 100644 --- a/src/net/java/sip/communicator/plugin/branding/MacOSXAboutRegistration.java +++ b/src/net/java/sip/communicator/plugin/branding/MacOSXAboutRegistration.java @@ -1,4 +1,4 @@ -/*
+/* * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Copyright @ 2015 Atlassian Pty Ltd @@ -15,34 +15,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.java.sip.communicator.plugin.branding;
-
-import com.apple.eawt.*;
-
-/**
- * @author Lubomir Marinov
- */
-public final class MacOSXAboutRegistration
-{
- /**
- * Show the about dialog on Mac OS X.
- *
- * @return true if the Mac OS X application is not null
- */
- public static boolean run()
- {
- Application application = Application.getApplication();
- if (application != null)
- {
- application.setAboutHandler(new AboutHandler()
- {
- public void handleAbout(AppEvent.AboutEvent aboutEvent)
- {
- AboutWindowPluginComponent.actionPerformed();
- }
- });
- return true;
- }
- return false;
- }
-}
+package net.java.sip.communicator.plugin.branding; + +import com.apple.eawt.*; + +/** + * @author Lubomir Marinov + */ +public final class MacOSXAboutRegistration +{ + /** + * Show the about dialog on Mac OS X. + * + * @return true if the Mac OS X application is not null + */ + public static boolean run() + { + Application application = Application.getApplication(); + if (application != null) + { + application.setAboutHandler(new AboutHandler() + { + public void handleAbout(AppEvent.AboutEvent aboutEvent) + { + AboutWindowPluginComponent.actionPerformed(); + } + }); + return true; + } + return false; + } +} diff --git a/src/net/java/sip/communicator/plugin/branding/StyledHTMLEditorPane.java b/src/net/java/sip/communicator/plugin/branding/StyledHTMLEditorPane.java index 7eb02bc..d67050e 100644 --- a/src/net/java/sip/communicator/plugin/branding/StyledHTMLEditorPane.java +++ b/src/net/java/sip/communicator/plugin/branding/StyledHTMLEditorPane.java @@ -1,4 +1,4 @@ -/*
+/* * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Copyright @ 2015 Atlassian Pty Ltd @@ -15,64 +15,64 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.java.sip.communicator.plugin.branding;
-
-import java.io.*;
-
-import javax.swing.*;
-import javax.swing.text.*;
-import javax.swing.text.html.*;
-
-import net.java.sip.communicator.util.*;
-
-public class StyledHTMLEditorPane
- extends JEditorPane
-{
- private final Logger logger = Logger.getLogger(StyledHTMLEditorPane.class);
-
- private final HTMLDocument document;
-
- public StyledHTMLEditorPane()
- {
- this.setContentType("text/html");
-
- this.document
- = (HTMLDocument) this.getDocument();
-
- this.setDocument(document);
-
- Constants.loadSimpleStyle(document.getStyleSheet());
- }
-
- public void appendToEnd(String text)
- {
- Element root = document.getDefaultRootElement();
- try
- {
- document.insertAfterEnd(root
- .getElement(root.getElementCount() - 1), text);
- }
- catch (BadLocationException e)
- {
- logger.error("Insert in the HTMLDocument failed.", e);
- }
- catch (IOException e)
- {
- logger.error("Insert in the HTMLDocument failed.", e);
- }
- }
-
- public void insertAfterStart(String text)
- {
- Element root = this.document.getDefaultRootElement();
-
- try {
- this.document.insertBeforeStart(root
- .getElement(0), text);
- } catch (BadLocationException e) {
- logger.error("Insert in the HTMLDocument failed.", e);
- } catch (IOException e) {
- logger.error("Insert in the HTMLDocument failed.", e);
- }
- }
-}
+package net.java.sip.communicator.plugin.branding; + +import java.io.*; + +import javax.swing.*; +import javax.swing.text.*; +import javax.swing.text.html.*; + +import net.java.sip.communicator.util.*; + +public class StyledHTMLEditorPane + extends JEditorPane +{ + private final Logger logger = Logger.getLogger(StyledHTMLEditorPane.class); + + private final HTMLDocument document; + + public StyledHTMLEditorPane() + { + this.setContentType("text/html"); + + this.document + = (HTMLDocument) this.getDocument(); + + this.setDocument(document); + + Constants.loadSimpleStyle(document.getStyleSheet()); + } + + public void appendToEnd(String text) + { + Element root = document.getDefaultRootElement(); + try + { + document.insertAfterEnd(root + .getElement(root.getElementCount() - 1), text); + } + catch (BadLocationException e) + { + logger.error("Insert in the HTMLDocument failed.", e); + } + catch (IOException e) + { + logger.error("Insert in the HTMLDocument failed.", e); + } + } + + public void insertAfterStart(String text) + { + Element root = this.document.getDefaultRootElement(); + + try { + this.document.insertBeforeStart(root + .getElement(0), text); + } catch (BadLocationException e) { + logger.error("Insert in the HTMLDocument failed.", e); + } catch (IOException e) { + logger.error("Insert in the HTMLDocument failed.", e); + } + } +} diff --git a/src/net/java/sip/communicator/plugin/branding/WelcomeWindow.java b/src/net/java/sip/communicator/plugin/branding/WelcomeWindow.java deleted file mode 100644 index 7cc78b8..0000000 --- a/src/net/java/sip/communicator/plugin/branding/WelcomeWindow.java +++ /dev/null @@ -1,443 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Copyright @ 2015 Atlassian Pty Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.java.sip.communicator.plugin.branding; - -import java.awt.*; -import java.awt.event.*; -import java.awt.image.*; -import java.io.*; - -import javax.imageio.*; -import javax.swing.*; - -import net.java.sip.communicator.plugin.desktoputil.*; - -import org.jitsi.service.resources.*; - -/** - * The <tt>WelcomeWindow</tt> is actually the splash screen shown while the - * application is loading. It displays the status of the loading process and - * some general information about the version, licenses and contact details. - * - * @author Yana Stamcheva - */ -public class WelcomeWindow extends JDialog -{ - /** - * Serial version UID. - */ - private static final long serialVersionUID = 0L; - - private static final String APPLICATION_NAME - = BrandingActivator.getResources() - .getSettingsString("service.gui.APPLICATION_NAME"); - - private static final int DEFAULT_TEXT_INDENT - = BrandingActivator.getResources() - .getSettingsInt("plugin.branding.SPLASH_SCREEN_TEXT_INDENT"); - - private static final int PREFERRED_HEIGHT = 330; - - private static final int PREFERRED_WIDTH = 570; - - private final JLabel bundleLabel = new JLabel(); - - /** - * Constructor. - */ - public WelcomeWindow() - { - JLabel titleLabel = new JLabel(APPLICATION_NAME); - - JLabel versionLabel = new JLabel(" " - + System.getProperty("sip-communicator.version")); - - JTextArea logoArea = new JTextArea( - BrandingActivator.getResources() - .getI18NString("plugin.branding.LOGO_MESSAGE")); - - StyledHTMLEditorPane rightsArea = new StyledHTMLEditorPane(); - - StyledHTMLEditorPane licenseArea = new StyledHTMLEditorPane(); - - JPanel textPanel = new JPanel(); - - Container mainPanel = new WindowBackground(); - - this.setTitle(APPLICATION_NAME); - - this.setModal(false); - this.setUndecorated(true); - - mainPanel.setLayout(new BorderLayout()); - - textPanel.setPreferredSize(new Dimension(470, 280)); - textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS)); - textPanel - .setBorder(BorderFactory.createEmptyBorder(15, 15, 0, 15)); - textPanel.setOpaque(false); - - this.initTitleLabel(titleLabel); - - this.initVersionLabel(versionLabel); - - this.initLogoArea(logoArea); - - this.initRightsArea(rightsArea); - - this.initLicenseArea(licenseArea); - - Component loadingPanel = initLoadingPanel(); - - textPanel.add(titleLabel); - textPanel.add(versionLabel); - textPanel.add(logoArea); - textPanel.add(rightsArea); - textPanel.add(licenseArea); - - mainPanel.add(textPanel, BorderLayout.CENTER); - mainPanel.add(loadingPanel, BorderLayout.SOUTH); - - this.getContentPane().add(mainPanel); - - this.setResizable(false); - - mainPanel.setPreferredSize( - new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT)); - - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation(screenSize.width / 2 - 527 / 2, - screenSize.height / 2 - 305 / 2); - - this.initCloseActions(); - } - - /** - * Initializes the title label. - * - * @param titleLabel the title label - */ - private void initTitleLabel(JLabel titleLabel) - { - titleLabel.setFont( - titleLabel.getFont().deriveFont(Font.BOLD, 28)); - titleLabel.setForeground(Constants.TITLE_COLOR); - titleLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); - } - - /** - * Initializes the version label. - * - * @param versionLabel the version label - */ - private void initVersionLabel(JLabel versionLabel) - { - versionLabel.setFont( - versionLabel.getFont().deriveFont(Font.BOLD, 18)); - versionLabel.setForeground(Constants.TITLE_COLOR); - versionLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); - } - - /** - * Initializes the logo area. - * - * @param logoArea the logo area - */ - private void initLogoArea(JTextArea logoArea) - { - int logoAreaFontSize = BrandingActivator.getResources(). - getSettingsInt("plugin.branding.ABOUT_LOGO_FONT_SIZE"); - - logoArea.setFont( - logoArea.getFont().deriveFont(Font.BOLD, logoAreaFontSize)); - logoArea.setForeground(Constants.TITLE_COLOR); - logoArea.setOpaque(false); - logoArea.setLineWrap(true); - logoArea.setWrapStyleWord(true); - logoArea.setEditable(false); - logoArea.setPreferredSize(new Dimension(100, 20)); - logoArea.setAlignmentX(Component.RIGHT_ALIGNMENT); - logoArea.setBorder(BorderFactory - .createEmptyBorder(20, DEFAULT_TEXT_INDENT, 0, 0)); - } - - /** - * Initializes the copyright area. - * - * @param rightsArea the copyright area. - */ - private void initRightsArea(StyledHTMLEditorPane rightsArea) - { - rightsArea.setContentType("text/html"); - rightsArea.appendToEnd( - BrandingActivator.getResources().getI18NString( - "plugin.branding.WELCOME_MESSAGE", - new String[]{ - Constants.TEXT_COLOR, - APPLICATION_NAME, - BrandingActivator.getResources() - .getSettingsString("service.gui.APPLICATION_WEB_SITE") - })); - - rightsArea.setPreferredSize(new Dimension(50, 50)); - rightsArea - .setBorder(BorderFactory - .createEmptyBorder(0, DEFAULT_TEXT_INDENT, 0, 0)); - rightsArea.setOpaque(false); - rightsArea.setEditable(false); - rightsArea.setAlignmentX(Component.RIGHT_ALIGNMENT); - } - - /** - * Initializes the license area. - * - * @param licenseArea the license area. - */ - private void initLicenseArea(StyledHTMLEditorPane licenseArea) - { - licenseArea.setContentType("text/html"); - licenseArea.appendToEnd( - BrandingActivator.getResources().getI18NString( - "plugin.branding.LICENSE", - new String[] - { - Constants.TEXT_COLOR - })); - - licenseArea.setPreferredSize(new Dimension(50, 20)); - licenseArea.setBorder(BorderFactory - .createEmptyBorder(0, DEFAULT_TEXT_INDENT, 0, 0)); - licenseArea.setOpaque(false); - licenseArea.setEditable(false); - licenseArea.setAlignmentX(Component.RIGHT_ALIGNMENT); - } - - private JPanel initLoadingPanel() - { - ResourceManagementService resources = BrandingActivator.getResources(); - JLabel loadingLabel - = new JLabel( - resources.getI18NString("plugin.branding.LOADING") + ": "); - JPanel loadingPanel = new JPanel(new BorderLayout()); - - this.bundleLabel.setFont(loadingLabel.getFont().deriveFont(Font.PLAIN)); - - loadingPanel.setOpaque(false); - loadingPanel.add(loadingLabel, BorderLayout.WEST); - loadingPanel.add(bundleLabel, BorderLayout.CENTER); - - int loadingPanelBorder - = resources - .getSettingsInt("plugin.branding.LOADING_BUNDLE_PANEL_BORDER"); - - loadingPanel.setBorder( - BorderFactory.createEmptyBorder(loadingPanelBorder, - loadingPanelBorder, - loadingPanelBorder, - loadingPanelBorder)); - - int loadingPanelHeight - = resources - .getSettingsInt("plugin.branding.LOADING_BUNDLE_PANEL_HEIGHT"); - - loadingPanel.setPreferredSize( - new Dimension(PREFERRED_WIDTH, loadingPanelHeight)); - - return loadingPanel; - } - - /** - * Initializes close actions on mouse click and esc key. - */ - private void initCloseActions() - { - // Close the splash screen on simple click or Esc. - this.getGlassPane().addMouseListener(new MouseAdapter() - { - @Override - public void mouseClicked(MouseEvent e) - { - WelcomeWindow.this.close(); - } - }); - - this.getGlassPane().setVisible(true); - - ActionMap amap = this.getRootPane().getActionMap(); - - amap.put("close", new CloseAction()); - - InputMap imap = this.getRootPane().getInputMap( - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - - imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close"); - } - - /** - * Disposes this window. - */ - protected void close() - { - this.dispose(); - } - - /** - * Sets the name of the currently loading bundle. - * - * @param bundleName the name of the bundle to display - */ - public void setBundle(String bundleName) - { - bundleLabel.setText(bundleName); - - bundleLabel.revalidate(); - bundleLabel.getParent().repaint(); - } - - /** - * The action invoked when user presses Escape key. - */ - private class CloseAction extends UIAction - { - /** - * Serial version UID. - */ - private static final long serialVersionUID = 0L; - - public void actionPerformed(ActionEvent e) - { - WelcomeWindow.this.close(); - } - } - - /** - * Constructs the window background in order to have a background image. - */ - private static class WindowBackground - extends JPanel - { - /** - * Serial version UID. - */ - private static final long serialVersionUID = 0L; - - private BufferedImage cache; - - private int cacheHeight; - - private int cacheWidth; - - private final Image image; - - public WindowBackground() - { - setOpaque(true); - - Image image = null; - try - { - image = - ImageIO.read(BrandingActivator.getResources().getImageURL( - "plugin.branding.SPLASH_SCREEN_BACKGROUND")); - } - catch (IOException e) - { - e.printStackTrace(); - } - this.image = image; - - if (image != null) - { - setPreferredSize(new Dimension(image.getWidth(this), image - .getHeight(this))); - } - } - - @Override - protected void paintComponent(Graphics g) - { - super.paintComponent(g); - - g = g.create(); - try - { - internalPaintComponent(g); - } - finally - { - g.dispose(); - } - } - - private void internalPaintComponent(Graphics g) - { - AntialiasingManager.activateAntialiasing(g); - - Graphics2D g2 = (Graphics2D) g; - - /* - * Drawing an Image with a data layout and color model compatible - * with this JPanel is magnitudes faster so create and use such an - * Image from the original drawn by this instance. - */ - int width = getWidth(); - int height = getHeight(); - boolean imageIsChanging = false; - if ((cache == null) || (cacheWidth != width) - || (cacheHeight != height)) - { - cache = - g2.getDeviceConfiguration().createCompatibleImage(width, - height); - cacheWidth = width; - cacheHeight = height; - - Graphics2D cacheGraphics = cache.createGraphics(); - try - { - super.paintComponent(cacheGraphics); - - AntialiasingManager.activateAntialiasing(cacheGraphics); - - imageIsChanging = - !cacheGraphics.drawImage(image, 0, 0, null); - - cacheGraphics.setColor(new Color(150, 150, 150)); - cacheGraphics.drawRoundRect(0, 0, width - 1, height - 1, 5, - 5); - } - finally - { - cacheGraphics.dispose(); - } - } - - g2.drawImage(cache, 0, 0, null); - - /* - * Once the original Image drawn by this instance has been fully - * loaded, we're free to use its "compatible" caching representation - * for the purposes of optimized execution speed. - */ - if (imageIsChanging) - { - cache = null; - } - } - } -} |