From 036cab07fac396fd4959e4f4c5c654ebc21cdbaa Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Wed, 16 May 2012 10:28:04 +0000 Subject: [PATCH] Fixes NullPointerExceptions and blank contactlist when UI is uninstalled and then installed(changing theme on windows). --- .../gui/customcontrols/SIPCommToolBar.java | 31 ++++- .../impl/gui/lookandfeel/SIPCommTreeUI.java | 84 +++++++++--- .../impl/gui/main/DialPadFieldUI.java | 14 ++ .../impl/gui/main/GeneralDialPadDialog.java | 41 +++++- .../gui/main/chat/SmileysSelectorBox.java | 29 +++- .../contactlist/DefaultTreeContactList.java | 28 +++- .../gui/main/contactlist/SearchField.java | 39 ++++-- .../gui/main/contactlist/SearchFieldUI.java | 117 ++++++++-------- .../gui/main/presence/AccountStatusPanel.java | 33 ++++- .../presence/GlobalStatusSelectorBox.java | 29 +++- .../impl/gui/utils/ExtendedTooltip.java | 75 ++++++++-- .../plugin/branding/AboutWindow.java | 41 +++++- .../util/swing/SIPCommLinkButton.java | 23 ++-- .../util/swing/SIPCommMenuBar.java | 27 +++- .../util/swing/SIPCommTabbedPane.java | 28 +++- .../util/swing/SIPCommTextButton.java | 27 +++- .../util/swing/plaf/SIPCommTextFieldUI.java | 129 ++++++++++-------- 17 files changed, 602 insertions(+), 193 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommToolBar.java b/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommToolBar.java index 3aeda3ef1..af886d01e 100644 --- a/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommToolBar.java +++ b/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommToolBar.java @@ -29,6 +29,21 @@ public class SIPCommToolBar { private static final long serialVersionUID = 0L; + /** + * Class id key used in UIDefaults. + */ + private static final String uiClassID = + SIPCommToolBar.class.getName() + "ToolBarSeparatorUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(uiClassID, + SIPCommToolBarSeparatorUI.class.getName()); + } + /** * Creates an instance of SIPCommToolBar. */ @@ -40,9 +55,9 @@ public SIPCommToolBar() { * Adds a separator to this toolbar. The separator is added after * the last component in the toolbar. */ - public void addSeparator() { + public void addSeparator() + { JToolBar.Separator s = new JToolBar.Separator(new Dimension(8, 22)); - s.setUI(new SIPCommToolBarSeparatorUI()); if (getOrientation() == VERTICAL) { s.setOrientation(JSeparator.HORIZONTAL); @@ -67,4 +82,16 @@ protected void paintBorder(Graphics g) { g2.drawImage(dragImage, 0, (this.getHeight() - dragImage .getHeight(null)) / 2 - 2, null); } + + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + return uiClassID; + } } diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTreeUI.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTreeUI.java index d331fd980..f67dc0c8f 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTreeUI.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTreeUI.java @@ -25,6 +25,8 @@ */ public class SIPCommTreeUI extends BasicTreeUI + implements HierarchyListener, + TreeSelectionListener { private static JTree tree; @@ -59,33 +61,71 @@ public void installUI(JComponent c) tree = (JTree)c; - tree.getSelectionModel().addTreeSelectionListener( - new TreeSelectionListener() - { - public void valueChanged(TreeSelectionEvent e) - { - // Update cell size. - selectionChanged( e.getOldLeadSelectionPath(), - e.getNewLeadSelectionPath()); - } - }); + JViewport v = getFirstParentViewport(tree); + if(v != null) + this.parentViewport = v; + else + tree.addHierarchyListener(this); - tree.addHierarchyListener(new HierarchyListener() - { - public void hierarchyChanged(HierarchyEvent e) - { - if (e.getID() == HierarchyEvent.HIERARCHY_CHANGED - && (e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0 - && e.getChangedParent() instanceof JViewport) - { - parentViewport = (JViewport) e.getChangedParent(); - } - } - }); + tree.getSelectionModel().addTreeSelectionListener(this); super.installUI(c); } + /** + * Returns the first parent view port found. + * @param c the component parents we search + * @return the first parent view port found. + */ + private JViewport getFirstParentViewport(Container c) + { + if(c == null) + return null; + else + if(c instanceof JViewport) + return (JViewport)c; + else + return getFirstParentViewport(c.getParent()); + } + + /** + * On uninstalling the ui remove the listeners. + * @param c + */ + public void uninstallUI(JComponent c) + { + tree.getSelectionModel().clearSelection(); + tree.getSelectionModel().removeTreeSelectionListener(this); + tree.removeHierarchyListener(this); + + super.uninstallUI(c); + } + + /** + * HierarchyListener's method. + * @param e the event. + */ + public void hierarchyChanged(HierarchyEvent e) + { + if (e.getID() == HierarchyEvent.HIERARCHY_CHANGED + && (e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0 + && e.getChangedParent() instanceof JViewport) + { + parentViewport = (JViewport) e.getChangedParent(); + } + } + + /** + * The TreeSelectionListener's method. + * @param e the event. + */ + public void valueChanged(TreeSelectionEvent e) + { + // Update cell size. + selectionChanged( e.getOldLeadSelectionPath(), + e.getNewLeadSelectionPath()); + } + /** * Installs the defaults of this UI. */ diff --git a/src/net/java/sip/communicator/impl/gui/main/DialPadFieldUI.java b/src/net/java/sip/communicator/impl/gui/main/DialPadFieldUI.java index f60a58602..a3e2adbb9 100644 --- a/src/net/java/sip/communicator/impl/gui/main/DialPadFieldUI.java +++ b/src/net/java/sip/communicator/impl/gui/main/DialPadFieldUI.java @@ -12,6 +12,9 @@ import net.java.sip.communicator.util.swing.*; import net.java.sip.communicator.util.swing.plaf.*; +import javax.swing.*; +import javax.swing.plaf.*; + /** * The SearchTextFieldUI is the one responsible for the search field * look & feel. It draws a search icon inside the field and adjusts the bounds @@ -89,4 +92,15 @@ protected Rectangle getVisibleEditorRect() } return null; } + + /** + * Creates a UI. + * + * @param c the text field + * @return the UI + */ + public static ComponentUI createUI(JComponent c) + { + return new DialPadFieldUI(); + } } \ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/gui/main/GeneralDialPadDialog.java b/src/net/java/sip/communicator/impl/gui/main/GeneralDialPadDialog.java index 36f31d1df..d40260f3e 100644 --- a/src/net/java/sip/communicator/impl/gui/main/GeneralDialPadDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/GeneralDialPadDialog.java @@ -315,10 +315,25 @@ public boolean dispatchKeyEvent(KeyEvent e) /** * A custom call field. */ - private class CallField + private static class CallField extends SIPCommTextField implements Skinnable { + /** + * Class id key used in UIDefaults. + */ + private static final String uiClassID = + CallField.class.getName() + "FieldUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(uiClassID, + DialPadFieldUI.class.getName()); + } + /** * The text field ui. */ @@ -333,11 +348,12 @@ public CallField(String text) { super(text); - textFieldUI = new DialPadFieldUI(); - textFieldUI.setDeleteButtonEnabled(true); + if(getUI() instanceof DialPadFieldUI) + { + ((DialPadFieldUI)getUI()).setDeleteButtonEnabled(true); + } this.setPreferredSize(new Dimension(200, 23)); - this.setUI(textFieldUI); this.setBorder(null); this.setOpaque(false); @@ -351,6 +367,11 @@ public CallField(String text) */ public void loadSkin() { + if(getUI() instanceof SIPCommTextFieldUI) + textFieldUI = (SIPCommTextFieldUI)getUI(); + else + return; + textFieldUI.loadSkin(); if (OSUtils.IS_MAC) @@ -366,5 +387,17 @@ public void loadSkin() setCaretColor(Color.WHITE); } } + + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + return uiClassID; + } } } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/SmileysSelectorBox.java b/src/net/java/sip/communicator/impl/gui/main/chat/SmileysSelectorBox.java index 304d294e7..5754409ef 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/SmileysSelectorBox.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/SmileysSelectorBox.java @@ -157,6 +157,21 @@ public void actionPerformed(ActionEvent e) private static class SmileyMenuItem extends JMenuItem { + /** + * Class id key used in UIDefaults. + */ + private static final String uiClassID = + SmileyMenuItem.class.getName() + "TreeUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(uiClassID, + SIPCommMenuItemUI.class.getName()); + } + /** * The Smiley depicted by this instance. */ @@ -172,10 +187,20 @@ public SmileyMenuItem(Smiley smiley) { super(GuiActivator.getResources().getImage(smiley.getImageID())); - this.setUI(new SIPCommMenuItemUI()); - this.smiley = smiley; } + + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + return uiClassID; + } } /** diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultTreeContactList.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultTreeContactList.java index b6fd626cf..b795c48d6 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultTreeContactList.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultTreeContactList.java @@ -35,6 +35,21 @@ public class DefaultTreeContactList { private static final long serialVersionUID = 0L; + /** + * Class id key used in UIDefaults. + */ + private static final String uiClassID = + DefaultTreeContactList.class.getName() + "TreeUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(uiClassID, + SIPCommTreeUI.class.getName()); + } + /** * The cached selection event. */ @@ -50,7 +65,6 @@ public class DefaultTreeContactList */ public DefaultTreeContactList() { - this.setUI(new SIPCommTreeUI()); this.setBackground(Color.WHITE); this.setDragEnabled(true); this.setTransferHandler(new ContactListTransferHandler(this)); @@ -236,4 +250,16 @@ public void loadSkin() { renderer.loadSkin(); } + + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + return uiClassID; + } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchField.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchField.java index c0d03b1cf..931eed773 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchField.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchField.java @@ -31,14 +31,24 @@ public class SearchField Skinnable { /** - * The main application window. + * Class id key used in UIDefaults. */ - private final MainFrame mainFrame; + private static final String uiClassID = + SearchField.class.getName() + "FieldUI"; /** - * SearchFieldUI defs. + * Adds the ui class to UIDefaults. */ - private final SearchFieldUI textFieldUI; + static + { + UIManager.getDefaults().put(uiClassID, + SearchFieldUI.class.getName()); + } + + /** + * The main application window. + */ + private final MainFrame mainFrame; /** * Creates the SearchField. @@ -51,9 +61,9 @@ public SearchField(MainFrame frame) this.mainFrame = frame; - textFieldUI = new SearchFieldUI(); - textFieldUI.setDeleteButtonEnabled(true); - this.setUI(textFieldUI); + if(getUI() instanceof SearchFieldUI) + ((SearchFieldUI)getUI()).setDeleteButtonEnabled(true); + this.setBorder(null); this.setOpaque(false); @@ -200,6 +210,19 @@ public void filterQuerySucceeded(FilterQuery query) */ public void loadSkin() { - textFieldUI.loadSkin(); + if(getUI() instanceof SearchFieldUI) + ((SearchFieldUI)getUI()).loadSkin(); + } + + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + return uiClassID; } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFieldUI.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFieldUI.java index 22c3367b0..22d5e7517 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFieldUI.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFieldUI.java @@ -10,6 +10,7 @@ import java.awt.event.*; import javax.swing.*; +import javax.swing.plaf.*; import javax.swing.text.*; import net.java.sip.communicator.impl.gui.*; @@ -29,7 +30,9 @@ */ public class SearchFieldUI extends SIPCommTextFieldUI - implements Skinnable + implements Skinnable, + MouseMotionListener, + MouseListener { /** * The icon indicating that this is a search field. @@ -98,14 +101,23 @@ protected void installListeners() if (isCallButtonEnabled) { - getComponent().addMouseListener( - new TextFieldMouseListener()); + getComponent().addMouseListener(this); - getComponent().addMouseMotionListener( - new TextFieldMouseMotionListener()); + getComponent().addMouseMotionListener(this); } } + /** + * Uninstalls listeners for the UI. + */ + protected void uninstallListeners() + { + super.uninstallListeners(); + + getComponent().removeMouseListener(this); + getComponent().removeMouseMotionListener(this); + } + /** * Implements parent paintSafely method and enables antialiasing. * @param g the Graphics object that notified us @@ -193,66 +205,52 @@ protected Rectangle getVisibleEditorRect() } /** - * The MouseListener that listens for mouse events in order to - * update the delete icon. + * Updates the call button when the mouse was clicked. + * @param e the MouseEvent that notified us of the click */ - protected class TextFieldMouseListener implements MouseListener + public void mouseClicked(MouseEvent e) { - /** - * Updates the call button when the mouse was clicked. - * @param e the MouseEvent that notified us of the click - */ - public void mouseClicked(MouseEvent e) - { - updateCallIcon(e); - } + updateCallIcon(e); + } - /** - * Updates the call button when the mouse is enters the component area. - * @param e the MouseEvent that notified us - */ - public void mouseEntered(MouseEvent e) - { - updateCallIcon(e); - } + /** + * Updates the call button when the mouse is enters the component area. + * @param e the MouseEvent that notified us + */ + public void mouseEntered(MouseEvent e) + { + updateCallIcon(e); + } - /** - * Updates the call button when the mouse exits the component area. - * @param e the MouseEvent that notified us - */ - public void mouseExited(MouseEvent e) - { - updateCallIcon(e); - } + /** + * Updates the call button when the mouse exits the component area. + * @param e the MouseEvent that notified us + */ + public void mouseExited(MouseEvent e) + { + updateCallIcon(e); + } - public void mousePressed(MouseEvent e) {} + public void mousePressed(MouseEvent e) {} - public void mouseReleased(MouseEvent e) {} - } + public void mouseReleased(MouseEvent e) {} /** - * The MouseMotionListener that listens for mouse events in order - * to update the delete icon. + * Updates the delete icon when the mouse is dragged over. + * @param e the MouseEvent that notified us */ - protected class TextFieldMouseMotionListener implements MouseMotionListener + public void mouseDragged(MouseEvent e) { - /** - * Updates the delete icon when the mouse is dragged over. - * @param e the MouseEvent that notified us - */ - public void mouseDragged(MouseEvent e) - { - updateCallIcon(e); - } + updateCallIcon(e); + } - /** - * Updates the delete icon when the mouse is moved over. - * @param e the MouseEvent that notified us - */ - public void mouseMoved(MouseEvent e) - { - updateCallIcon(e); - } + /** + * Updates the delete icon when the mouse is moved over. + * @param e the MouseEvent that notified us + */ + public void mouseMoved(MouseEvent e) + { + updateCallIcon(e); } /** @@ -350,4 +348,15 @@ public void loadSkin() .getImage(); } } + + /** + * Creates a UI for a SearchFieldUI. + * + * @param c the text field + * @return the UI + */ + public static ComponentUI createUI(JComponent c) + { + return new SearchFieldUI(); + } } \ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java b/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java index 1f6280898..ae65a58f0 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java @@ -40,6 +40,21 @@ public class AccountStatusPanel AvatarListener, Skinnable { + /** + * Class id key used in UIDefaults. + */ + private static final String uiClassID = + AccountStatusPanel.class.getName() + "OpaquePanelUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(uiClassID, + SIPCommOpaquePanelUI.class.getName()); + } + /** * The desired height of the avatar. */ @@ -120,9 +135,6 @@ public AccountStatusPanel(MainFrame mainFrame) { super(new BorderLayout(10, 0)); - if (ConfigurationManager.isTransparentWindowEnabled()) - this.setUI(new SIPCommOpaquePanelUI()); - FramedImageWithMenu imageWithMenu = new FramedImageWithMenu( mainFrame, @@ -596,4 +608,19 @@ public void serverStoredDetailsChanged(ServerStoredDetailsChangeEvent evt) accountNameLabel.setText(accountName); } } + + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + if(ConfigurationManager.isTransparentWindowEnabled()) + return uiClassID; + else + return super.getUIClassID(); + } } diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusSelectorBox.java b/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusSelectorBox.java index 87e2082c3..6ea1931c9 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusSelectorBox.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/GlobalStatusSelectorBox.java @@ -43,6 +43,21 @@ public class GlobalStatusSelectorBox extends StatusSelectorMenu implements ActionListener { + /** + * Class id key used in UIDefaults. + */ + private static final String uiClassID = + GlobalStatusSelectorBox.class.getName() + "StatusMenuUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(uiClassID, + SIPCommStatusMenuUI.class.getName()); + } + /** * The indent of the image. */ @@ -151,8 +166,6 @@ public GlobalStatusSelectorBox(MainFrame mainFrame) this.addSeparator(); - this.setUI(new SIPCommStatusMenuUI()); - this.setFont(titleLabel.getFont().deriveFont(Font.PLAIN, 11f)); this.setIcon(offlineItem.getIcon()); this.setIconTextGap(2); @@ -1007,4 +1020,16 @@ public void loadSkin() updateGlobalStatus(); } + + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + return uiClassID; + } } diff --git a/src/net/java/sip/communicator/impl/gui/utils/ExtendedTooltip.java b/src/net/java/sip/communicator/impl/gui/utils/ExtendedTooltip.java index 94ed5bb55..48dc8eedc 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ExtendedTooltip.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ExtendedTooltip.java @@ -10,6 +10,7 @@ import java.awt.event.*; import javax.swing.*; +import javax.swing.plaf.*; import javax.swing.plaf.metal.*; import net.java.sip.communicator.util.*; @@ -26,6 +27,21 @@ public class ExtendedTooltip private static final Logger logger = Logger.getLogger(ExtendedTooltip.class); + /** + * Class id key used in UIDefaults. + */ + private static final String uiClassID = + ExtendedTooltip.class.getName() + "ToolTipUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(uiClassID, + ImageToolTipUI.class.getName()); + } + private final JLabel imageLabel = new JLabel(); private final JLabel titleLabel = new JLabel(); @@ -48,8 +64,6 @@ public ExtendedTooltip(final Window parentWindow, boolean isListViewEnabled) { this.isListViewEnabled = isListViewEnabled; - this.setUI(new ImageToolTipUI()); - this.setLayout(new BorderLayout()); JPanel mainPanel = new JPanel(new BorderLayout(5, 5)); @@ -289,8 +303,20 @@ private void recalculateTooltipSize(int newTextWidth, int newTextHeight) /** * Customized UI for this MetaContactTooltip. */ - private class ImageToolTipUI extends MetalToolTipUI + public static class ImageToolTipUI extends MetalToolTipUI { + static ImageToolTipUI sharedInstance = new ImageToolTipUI(); + + /** + * Creates the UI. + * @param c + * @return + */ + public static ComponentUI createUI(JComponent c) + { + return sharedInstance; + } + /** * Overwrite the UI paint method to do nothing in order fix double * painting of the tooltip text. @@ -309,6 +335,9 @@ public void paint(Graphics g, JComponent c) @Override public void update(Graphics g, JComponent c) { + JTextArea bottomTextArea = + ((ExtendedTooltip)c).bottomTextArea; + String bottomText = bottomTextArea.getText(); if(bottomText == null || bottomText.length() <= 0) bottomTextArea.setVisible(false); @@ -325,40 +354,56 @@ public void update(Graphics g, JComponent c) @Override public Dimension getPreferredSize(JComponent c) { - Icon icon = imageLabel.getIcon(); + ExtendedTooltip tooltip = (ExtendedTooltip)c; + + Icon icon = tooltip.imageLabel.getIcon(); int width = 0; if (icon != null) width += icon.getIconWidth(); - if (isListViewEnabled) - width += textWidth + 15; + if (tooltip.isListViewEnabled) + width += tooltip.textWidth + 15; else - width = textWidth > width ? textWidth : width; + width = tooltip.textWidth > width ? tooltip.textWidth : width; int imageHeight = 0; if (icon != null) imageHeight = icon.getIconHeight(); int height = 0; - if (isListViewEnabled) + if (tooltip.isListViewEnabled) { - height = imageHeight > textHeight ? imageHeight : textHeight; + height = imageHeight > tooltip.textHeight + ? imageHeight : tooltip.textHeight; } else - height = imageHeight + textHeight; + height = imageHeight + tooltip.textHeight; - String bottomText = bottomTextArea.getText(); + String bottomText = tooltip.bottomTextArea.getText(); if(bottomText != null && bottomText.length() > 0) { // Seems a little messy, but sets the proper size. - bottomTextArea.setColumns(5); - bottomTextArea.setSize(0,0); - bottomTextArea.setSize(bottomTextArea.getPreferredSize()); + tooltip.bottomTextArea.setColumns(5); + tooltip.bottomTextArea.setSize(0,0); + tooltip.bottomTextArea.setSize( + tooltip.bottomTextArea.getPreferredSize()); - height += bottomTextArea.getPreferredSize().height; + height += tooltip.bottomTextArea.getPreferredSize().height; } return new Dimension(width, height); } } + + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + return uiClassID; + } } diff --git a/src/net/java/sip/communicator/plugin/branding/AboutWindow.java b/src/net/java/sip/communicator/plugin/branding/AboutWindow.java index f183f227e..35ea79554 100644 --- a/src/net/java/sip/communicator/plugin/branding/AboutWindow.java +++ b/src/net/java/sip/communicator/plugin/branding/AboutWindow.java @@ -49,7 +49,22 @@ public class AboutWindow */ private static AboutWindow aboutWindow; - private final SIPCommTextFieldUI textFieldUI; + /** + * 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 AboutWindow creating it first if necessary. The @@ -122,13 +137,24 @@ public AboutWindow(Frame owner) titleLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); } - JTextField versionLabel - = new JTextField(" " - + System.getProperty("sip-communicator.version")); // Force the use of the custom text field UI in order to fix an // incorrect rendering on Ubuntu. - textFieldUI = new SIPCommTextFieldUI(); - versionLabel.setUI(textFieldUI); + 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 + */ + public String getUIClassID() + { + return uiClassID; + } + }; versionLabel.setBorder(null); versionLabel.setOpaque(false); @@ -246,7 +272,8 @@ public AboutWindow(Frame owner) */ public void loadSkin() { - textFieldUI.loadSkin(); + if(versionLabel.getUI() instanceof Skinnable) + ((Skinnable)versionLabel.getUI()).loadSkin(); } /** diff --git a/src/net/java/sip/communicator/util/swing/SIPCommLinkButton.java b/src/net/java/sip/communicator/util/swing/SIPCommLinkButton.java index d5cac4aaa..57da9a723 100644 --- a/src/net/java/sip/communicator/util/swing/SIPCommLinkButton.java +++ b/src/net/java/sip/communicator/util/swing/SIPCommLinkButton.java @@ -21,7 +21,19 @@ public class SIPCommLinkButton { private static final long serialVersionUID = 1L; + /** + * Class id key used in UIDefaults. + */ private static final String UIClassID = "LinkButtonUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(UIClassID, + SIPCommLinkButtonUI.class.getName()); + } public static final int ALWAYS_UNDERLINE = 0; @@ -77,10 +89,7 @@ public SIPCommLinkButton(URL url) public SIPCommLinkButton(String text, URL url) { super(text); - - // Define UI - this.setUI(SIPCommLinkButtonUI.createUI(this)); - UIManager.getDefaults().put("LinkButtonUI", "SIPCommLinkButtonUI"); + linkBehavior = SIPCommLinkButton.HOVER_UNDERLINE; linkColor = Color.blue; @@ -96,12 +105,6 @@ public SIPCommLinkButton(String text, URL url) this.setRolloverEnabled(true); this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } - - @Override - public void updateUI() - { - this.setUI(SIPCommLinkButtonUI.createUI(this)); - } public String getUIClassID() { diff --git a/src/net/java/sip/communicator/util/swing/SIPCommMenuBar.java b/src/net/java/sip/communicator/util/swing/SIPCommMenuBar.java index 1afce04b8..b27771851 100644 --- a/src/net/java/sip/communicator/util/swing/SIPCommMenuBar.java +++ b/src/net/java/sip/communicator/util/swing/SIPCommMenuBar.java @@ -27,6 +27,20 @@ public class SIPCommMenuBar */ private static final long serialVersionUID = 0L; + /** + * Class id key used in UIDefaults. + */ + private static final String UIClassID = "SIPCommMenuBarUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(UIClassID, + SIPCommMenuBarUI.class.getName()); + } + /** * Creates an instance of SIPCommMenuBar. */ @@ -41,6 +55,17 @@ public SIPCommMenuBar() public void loadSkin() { this.setBorder(BorderFactory.createEmptyBorder()); - this.setUI(new SIPCommMenuBarUI()); } + + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + return UIClassID; + } } diff --git a/src/net/java/sip/communicator/util/swing/SIPCommTabbedPane.java b/src/net/java/sip/communicator/util/swing/SIPCommTabbedPane.java index cad2c1091..51c401707 100644 --- a/src/net/java/sip/communicator/util/swing/SIPCommTabbedPane.java +++ b/src/net/java/sip/communicator/util/swing/SIPCommTabbedPane.java @@ -42,6 +42,20 @@ public class SIPCommTabbedPane */ private static final long serialVersionUID = 0L; + /** + * Class id key used in UIDefaults. + */ + private static final String UIClassID = "SIPCommTabbedPaneEnhancedUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(UIClassID, + SIPCommTabbedPaneEnhancedUI.class.getName()); + } + private int overTabIndex = -1; private int lastSelectedIndex; @@ -72,8 +86,6 @@ public SIPCommTabbedPane(boolean closingTabs, boolean maximizingTabs) new Color(UtilActivator.getResources() .getColor("service.gui.TAB_TITLE"))); - this.setUI(new SIPCommTabbedPaneEnhancedUI()); - if(closingTabs) this.setCloseIcon(true); @@ -510,4 +522,16 @@ public void loadSkin() ((SIPCommTabbedPaneEnhancedUI)this.getUI()).loadSkin(); } + + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + return UIClassID; + } } diff --git a/src/net/java/sip/communicator/util/swing/SIPCommTextButton.java b/src/net/java/sip/communicator/util/swing/SIPCommTextButton.java index 8259d12a9..14b130ee9 100644 --- a/src/net/java/sip/communicator/util/swing/SIPCommTextButton.java +++ b/src/net/java/sip/communicator/util/swing/SIPCommTextButton.java @@ -29,6 +29,20 @@ public class SIPCommTextButton extends JButton */ private static final long serialVersionUID = 0L; + /** + * Class id key used in UIDefaults. + */ + private static final String UIClassID = "BasicButtonUI"; + + /** + * Adds the ui class to UIDefaults. + */ + static + { + UIManager.getDefaults().put(UIClassID, + BasicButtonUI.class.getName()); + } + private final float[] borderColor = Color.DARK_GRAY.getRGBComponents(null); @@ -70,7 +84,6 @@ public SIPCommTextButton(String text, Image bgImage) * and feel. */ this.setContentAreaFilled(false); - this.setUI(new BasicButtonUI()); } public void setBgImage(Image image) @@ -152,6 +165,18 @@ private void internalPaintComponent(Graphics2D g) } + /** + * Returns the name of the L&F class that renders this component. + * + * @return the string "TreeUI" + * @see JComponent#getUIClassID + * @see UIDefaults#getUI + */ + public String getUIClassID() + { + return UIClassID; + } + /** * The ButtonRepaintCallback is charged to repaint this button * when the fade animation is performed. diff --git a/src/net/java/sip/communicator/util/swing/plaf/SIPCommTextFieldUI.java b/src/net/java/sip/communicator/util/swing/plaf/SIPCommTextFieldUI.java index e9d6775a8..fb303ed49 100644 --- a/src/net/java/sip/communicator/util/swing/plaf/SIPCommTextFieldUI.java +++ b/src/net/java/sip/communicator/util/swing/plaf/SIPCommTextFieldUI.java @@ -8,6 +8,8 @@ import java.awt.*; import java.awt.event.*; +import javax.swing.*; +import javax.swing.plaf.*; import javax.swing.plaf.metal.*; import javax.swing.text.*; @@ -23,7 +25,9 @@ */ public class SIPCommTextFieldUI extends MetalTextFieldUI - implements Skinnable + implements Skinnable, + MouseMotionListener, + MouseListener { /** * Indicates if the mouse is currently over the delete button. @@ -127,11 +131,20 @@ protected void installListeners() { super.installListeners(); - getComponent().addMouseListener( - new TextFieldMouseListener()); + getComponent().addMouseListener(this); - getComponent().addMouseMotionListener( - new TextFieldMouseMotionListener()); + getComponent().addMouseMotionListener(this); + } + + /** + * Uninstalls listeners for the UI. + */ + protected void uninstallListeners() + { + super.uninstallListeners(); + + getComponent().removeMouseListener(this); + getComponent().removeMouseMotionListener(this); } /** @@ -381,71 +394,58 @@ public void loadSkin() } /** - * The MouseListener that listens for mouse events in order to - * update the delete icon. + * Updates the delete icon when the mouse was clicked. + * @param e the MouseEvent that notified us of the click */ - protected class TextFieldMouseListener implements MouseListener + public void mouseClicked(MouseEvent e) { - /** - * Updates the delete icon when the mouse was clicked. - * @param e the MouseEvent that notified us of the click - */ - public void mouseClicked(MouseEvent e) - { - updateDeleteIcon(e); - updateCursor(e); - } + updateDeleteIcon(e); + updateCursor(e); + } - /** - * Updates the delete icon when the mouse is enters the component area. - * @param e the MouseEvent that notified us - */ - public void mouseEntered(MouseEvent e) - { - updateDeleteIcon(e); - updateCursor(e); - } + /** + * Updates the delete icon when the mouse is enters the component area. + * @param e the MouseEvent that notified us + */ + public void mouseEntered(MouseEvent e) + { + updateDeleteIcon(e); + updateCursor(e); + } - /** - * Updates the delete icon when the mouse exits the component area. - * @param e the MouseEvent that notified us - */ - public void mouseExited(MouseEvent e) - { - updateDeleteIcon(e); - updateCursor(e); - } + /** + * Updates the delete icon when the mouse exits the component area. + * @param e the MouseEvent that notified us + */ + public void mouseExited(MouseEvent e) + { + updateDeleteIcon(e); + updateCursor(e); + } - public void mousePressed(MouseEvent e) {} + public void mousePressed(MouseEvent e) {} + + public void mouseReleased(MouseEvent e) {} - public void mouseReleased(MouseEvent e) {} - } /** - * The MouseMotionListener that listens for mouse events in order - * to update the delete icon. + * Updates the delete icon when the mouse is dragged over. + * @param e the MouseEvent that notified us */ - protected class TextFieldMouseMotionListener implements MouseMotionListener + public void mouseDragged(MouseEvent e) { - /** - * Updates the delete icon when the mouse is dragged over. - * @param e the MouseEvent that notified us - */ - public void mouseDragged(MouseEvent e) - { - updateDeleteIcon(e); - updateCursor(e); - } + updateDeleteIcon(e); + updateCursor(e); + } - /** - * Updates the delete icon when the mouse is moved over. - * @param e the MouseEvent that notified us - */ - public void mouseMoved(MouseEvent e) - { - updateDeleteIcon(e); - updateCursor(e); - } + /** + * Updates the delete icon when the mouse is moved over. + * @param e the MouseEvent that notified us + */ + public void mouseMoved(MouseEvent e) + { + updateDeleteIcon(e); + updateCursor(e); } private void updateCursor(MouseEvent mouseEvent) @@ -457,4 +457,15 @@ private void updateCursor(MouseEvent mouseEvent) Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); } } + + /** + * Creates a UI for a SIPCommTextFieldUI. + * + * @param c the text field + * @return the UI + */ + public static ComponentUI createUI(JComponent c) + { + return new SIPCommTextFieldUI(); + } } \ No newline at end of file