mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
StringUtils.java : Created missing JavaDoc for methods
GraphicUtils.java: Created missing JavaDoc for methods VCardEditor.java: Created missing JavaDoc for methods - Sun Coding Conventions git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@12079 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
committed by
wolf.posdorfer
parent
5ecd4ec51c
commit
09f6366888
@ -46,10 +46,13 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.imageio.ImageReader;
|
||||||
|
import javax.imageio.stream.ImageInputStream;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
@ -61,12 +64,13 @@ import org.jivesoftware.resource.SparkRes;
|
|||||||
import org.jivesoftware.spark.util.log.Log;
|
import org.jivesoftware.spark.util.log.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>GraphicsUtils</code> class defines common user-interface related utility
|
* <code>GraphicsUtils</code> class defines common user-interface related
|
||||||
* functions.
|
* utility functions.
|
||||||
*/
|
*/
|
||||||
public final class GraphicUtils {
|
public final class GraphicUtils {
|
||||||
private static final Insets HIGHLIGHT_INSETS = new Insets(1, 1, 1, 1);
|
private static final Insets HIGHLIGHT_INSETS = new Insets(1, 1, 1, 1);
|
||||||
public static final Color SELECTION_COLOR = new java.awt.Color(166, 202, 240);
|
public static final Color SELECTION_COLOR = new java.awt.Color(166, 202,
|
||||||
|
240);
|
||||||
public static final Color TOOLTIP_COLOR = new java.awt.Color(166, 202, 240);
|
public static final Color TOOLTIP_COLOR = new java.awt.Color(166, 202, 240);
|
||||||
|
|
||||||
protected final static Component component = new Component() {
|
protected final static Component component = new Component() {
|
||||||
@ -84,19 +88,22 @@ public final class GraphicUtils {
|
|||||||
/**
|
/**
|
||||||
* The default Text Cursor.
|
* The default Text Cursor.
|
||||||
*/
|
*/
|
||||||
public static final Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
|
public static final Cursor DEFAULT_CURSOR = new Cursor(
|
||||||
|
Cursor.DEFAULT_CURSOR);
|
||||||
|
|
||||||
private GraphicUtils() {
|
private GraphicUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the location of the specified window so that it is centered on screen.
|
* Sets the location of the specified window so that it is centered on
|
||||||
|
* screen.
|
||||||
*
|
*
|
||||||
* @param window The window to be centered.
|
* @param window
|
||||||
|
* The window to be centered.
|
||||||
*/
|
*/
|
||||||
public static void centerWindowOnScreen(Window window) {
|
public static void centerWindowOnScreen(Window window) {
|
||||||
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
final Dimension screenSize = Toolkit.getDefaultToolkit()
|
||||||
|
.getScreenSize();
|
||||||
final Dimension size = window.getSize();
|
final Dimension size = window.getSize();
|
||||||
|
|
||||||
if (size.height > screenSize.height) {
|
if (size.height > screenSize.height) {
|
||||||
@ -114,20 +121,27 @@ public final class GraphicUtils {
|
|||||||
/**
|
/**
|
||||||
* Draws a single-line highlight border rectangle.
|
* Draws a single-line highlight border rectangle.
|
||||||
*
|
*
|
||||||
* @param g The graphics context to use for drawing.
|
* @param g
|
||||||
* @param x The left edge of the border.
|
* The graphics context to use for drawing.
|
||||||
* @param y The top edge of the border.
|
* @param x
|
||||||
* @param width The width of the border.
|
* The left edge of the border.
|
||||||
* @param height The height of the border.
|
* @param y
|
||||||
* @param raised <code>true</code> if the border is to be drawn raised,
|
* The top edge of the border.
|
||||||
|
* @param width
|
||||||
|
* The width of the border.
|
||||||
|
* @param height
|
||||||
|
* The height of the border.
|
||||||
|
* @param raised
|
||||||
|
* <code>true</code> if the border is to be drawn raised,
|
||||||
* <code>false</code> if lowered.
|
* <code>false</code> if lowered.
|
||||||
* @param shadow The shadow color for the border.
|
* @param shadow
|
||||||
* @param highlight The highlight color for the border.
|
* The shadow color for the border.
|
||||||
|
* @param highlight
|
||||||
|
* The highlight color for the border.
|
||||||
* @see javax.swing.border.EtchedBorder
|
* @see javax.swing.border.EtchedBorder
|
||||||
*/
|
*/
|
||||||
public static void drawHighlightBorder(Graphics g, int x, int y,
|
public static void drawHighlightBorder(Graphics g, int x, int y, int width,
|
||||||
int width, int height, boolean raised,
|
int height, boolean raised, Color shadow, Color highlight) {
|
||||||
Color shadow, Color highlight) {
|
|
||||||
final Color oldColor = g.getColor();
|
final Color oldColor = g.getColor();
|
||||||
g.translate(x, y);
|
g.translate(x, y);
|
||||||
|
|
||||||
@ -154,6 +168,13 @@ public final class GraphicUtils {
|
|||||||
return HIGHLIGHT_INSETS;
|
return HIGHLIGHT_INSETS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an ImageIcon from an Image
|
||||||
|
*
|
||||||
|
* @param image
|
||||||
|
* {@link Image}
|
||||||
|
* @return {@link ImageIcon}
|
||||||
|
*/
|
||||||
public static ImageIcon createImageIcon(Image image) {
|
public static ImageIcon createImageIcon(Image image) {
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -163,8 +184,7 @@ public final class GraphicUtils {
|
|||||||
tracker.addImage(image, 0);
|
tracker.addImage(image, 0);
|
||||||
try {
|
try {
|
||||||
tracker.waitForID(0, 0);
|
tracker.waitForID(0, 0);
|
||||||
}
|
} catch (InterruptedException e) {
|
||||||
catch (InterruptedException e) {
|
|
||||||
System.out.println("INTERRUPTED while loading Image");
|
System.out.println("INTERRUPTED while loading Image");
|
||||||
}
|
}
|
||||||
tracker.removeImage(image, 0);
|
tracker.removeImage(image, 0);
|
||||||
@ -174,47 +194,55 @@ public final class GraphicUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a point where the given popup menu should be shown. The
|
* Returns a point where the given popup menu should be shown. The point is
|
||||||
* point is calculated by adjusting the X and Y coordinates from the
|
* calculated by adjusting the X and Y coordinates from the given mouse
|
||||||
* given mouse event so that the popup menu will not be clipped by
|
* event so that the popup menu will not be clipped by the screen
|
||||||
* the screen boundaries.
|
* boundaries.
|
||||||
*
|
*
|
||||||
* @param popup the popup menu
|
* @param popup
|
||||||
* @param event the mouse event
|
* the popup menu
|
||||||
|
* @param event
|
||||||
|
* the mouse event
|
||||||
* @return the point where the popup menu should be shown
|
* @return the point where the popup menu should be shown
|
||||||
*/
|
*/
|
||||||
public static Point getPopupMenuShowPoint(JPopupMenu popup, MouseEvent event) {
|
public static Point getPopupMenuShowPoint(JPopupMenu popup, MouseEvent event) {
|
||||||
Component source = (Component) event.getSource();
|
Component source = (Component) event.getSource();
|
||||||
Point topLeftSource = source.getLocationOnScreen();
|
Point topLeftSource = source.getLocationOnScreen();
|
||||||
Point ptRet = getPopupMenuShowPoint(popup,
|
Point ptRet = getPopupMenuShowPoint(popup,
|
||||||
topLeftSource.x + event.getX(),
|
topLeftSource.x + event.getX(), topLeftSource.y + event.getY());
|
||||||
topLeftSource.y + event.getY());
|
|
||||||
ptRet.translate(-topLeftSource.x, -topLeftSource.y);
|
ptRet.translate(-topLeftSource.x, -topLeftSource.y);
|
||||||
return ptRet;
|
return ptRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a point where the given popup menu should be shown. The
|
* Returns a point where the given popup menu should be shown. The point is
|
||||||
* point is calculated by adjusting the X and Y coordinates so that
|
* calculated by adjusting the X and Y coordinates so that the popup menu
|
||||||
* the popup menu will not be clipped by the screen boundaries.
|
* will not be clipped by the screen boundaries.
|
||||||
*
|
*
|
||||||
* @param popup the popup menu
|
* @param popup
|
||||||
* @param x the x position in screen coordinate
|
* the popup menu
|
||||||
* @param y the y position in screen coordinates
|
* @param x
|
||||||
|
* the x position in screen coordinate
|
||||||
|
* @param y
|
||||||
|
* the y position in screen coordinates
|
||||||
* @return the point where the popup menu should be shown in screen
|
* @return the point where the popup menu should be shown in screen
|
||||||
* coordinates
|
* coordinates
|
||||||
*/
|
*/
|
||||||
public static Point getPopupMenuShowPoint(JPopupMenu popup, int x, int y) {
|
public static Point getPopupMenuShowPoint(JPopupMenu popup, int x, int y) {
|
||||||
Dimension sizeMenu = popup.getPreferredSize();
|
Dimension sizeMenu = popup.getPreferredSize();
|
||||||
Point bottomRightMenu = new Point(x + sizeMenu.width, y + sizeMenu.height);
|
Point bottomRightMenu = new Point(x + sizeMenu.width, y
|
||||||
|
+ sizeMenu.height);
|
||||||
|
|
||||||
Rectangle[] screensBounds = getScreenBounds();
|
Rectangle[] screensBounds = getScreenBounds();
|
||||||
int n = screensBounds.length;
|
int n = screensBounds.length;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
Rectangle screenBounds = screensBounds[i];
|
Rectangle screenBounds = screensBounds[i];
|
||||||
if (screenBounds.x <= x && x <= (screenBounds.x + screenBounds.width)) {
|
if (screenBounds.x <= x
|
||||||
|
&& x <= (screenBounds.x + screenBounds.width)) {
|
||||||
Dimension sizeScreen = screenBounds.getSize();
|
Dimension sizeScreen = screenBounds.getSize();
|
||||||
sizeScreen.height -= 32; // Hack to help prevent menu being clipped by Windows/Linux/Solaris Taskbar.
|
sizeScreen.height -= 32; // Hack to help prevent menu being
|
||||||
|
// clipped by Windows/Linux/Solaris
|
||||||
|
// Taskbar.
|
||||||
|
|
||||||
int xOffset = 0;
|
int xOffset = 0;
|
||||||
if (bottomRightMenu.x > (screenBounds.x + sizeScreen.width))
|
if (bottomRightMenu.x > (screenBounds.x + sizeScreen.width))
|
||||||
@ -228,14 +256,18 @@ public final class GraphicUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Point(x, y); // ? that would mean that the top left point was not on any screen.
|
return new Point(x, y); // ? that would mean that the top left point was
|
||||||
|
// not on any screen.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Centers the window over a component (usually another window).
|
* Centers the window over a component (usually another window). The window
|
||||||
* The window must already have been sized.
|
* must already have been sized.
|
||||||
* @param window Window to center.
|
*
|
||||||
* @param over Component to center over.
|
* @param window
|
||||||
|
* Window to center.
|
||||||
|
* @param over
|
||||||
|
* Component to center over.
|
||||||
*/
|
*/
|
||||||
public static void centerWindowOnComponent(Window window, Component over) {
|
public static void centerWindowOnComponent(Window window, Component over) {
|
||||||
if ((over == null) || !over.isShowing()) {
|
if ((over == null) || !over.isShowing()) {
|
||||||
@ -243,7 +275,6 @@ public final class GraphicUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Point parentLocation = over.getLocationOnScreen();
|
Point parentLocation = over.getLocationOnScreen();
|
||||||
Dimension parentSize = over.getSize();
|
Dimension parentSize = over.getSize();
|
||||||
Dimension size = window.getSize();
|
Dimension size = window.getSize();
|
||||||
@ -273,14 +304,14 @@ public final class GraphicUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param c Component to check on.
|
* @param c
|
||||||
|
* Component to check on.
|
||||||
* @return returns true if the component of one of its child has the focus
|
* @return returns true if the component of one of its child has the focus
|
||||||
*/
|
*/
|
||||||
public static boolean isAncestorOfFocusedComponent(Component c) {
|
public static boolean isAncestorOfFocusedComponent(Component c) {
|
||||||
if (c.hasFocus()) {
|
if (c.hasFocus()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (c instanceof Container) {
|
if (c instanceof Container) {
|
||||||
Container cont = (Container) c;
|
Container cont = (Container) c;
|
||||||
int n = cont.getComponentCount();
|
int n = cont.getComponentCount();
|
||||||
@ -298,9 +329,11 @@ public final class GraphicUtils {
|
|||||||
* Returns the first component in the tree of <code>c</code> that can accept
|
* Returns the first component in the tree of <code>c</code> that can accept
|
||||||
* the focus.
|
* the focus.
|
||||||
*
|
*
|
||||||
* @param c the root of the component hierarchy to search
|
* @param c
|
||||||
|
* the root of the component hierarchy to search
|
||||||
* @see #focusComponentOrChild
|
* @see #focusComponentOrChild
|
||||||
* @deprecated replaced by {@link #getFocusableComponentOrChild(Component,boolean)}
|
* @deprecated replaced by
|
||||||
|
* {@link #getFocusableComponentOrChild(Component,boolean)}
|
||||||
* @return Component that was focused on.
|
* @return Component that was focused on.
|
||||||
*/
|
*/
|
||||||
public static Component getFocusableComponentOrChild(Component c) {
|
public static Component getFocusableComponentOrChild(Component c) {
|
||||||
@ -311,14 +344,18 @@ public final class GraphicUtils {
|
|||||||
* Returns the first component in the tree of <code>c</code> that can accept
|
* Returns the first component in the tree of <code>c</code> that can accept
|
||||||
* the focus.
|
* the focus.
|
||||||
*
|
*
|
||||||
* @param c the root of the component hierarchy to search
|
* @param c
|
||||||
* @param deepest if <code>deepest</code> is true the method will return the first and deepest component that can accept the
|
* the root of the component hierarchy to search
|
||||||
* focus. For example, if both a child and its parent are focusable and <code>deepest</code> is true, the child is
|
* @param deepest
|
||||||
* returned.
|
* if <code>deepest</code> is true the method will return the
|
||||||
|
* first and deepest component that can accept the focus. For
|
||||||
|
* example, if both a child and its parent are focusable and
|
||||||
|
* <code>deepest</code> is true, the child is returned.
|
||||||
* @see #focusComponentOrChild
|
* @see #focusComponentOrChild
|
||||||
* @return Component that was focused on.
|
* @return Component that was focused on.
|
||||||
*/
|
*/
|
||||||
public static Component getFocusableComponentOrChild(Component c, boolean deepest) {
|
public static Component getFocusableComponentOrChild(Component c,
|
||||||
|
boolean deepest) {
|
||||||
if (c != null && c.isEnabled() && c.isVisible()) {
|
if (c != null && c.isEnabled() && c.isVisible()) {
|
||||||
if (c instanceof Container) {
|
if (c instanceof Container) {
|
||||||
Container cont = (Container) c;
|
Container cont = (Container) c;
|
||||||
@ -335,7 +372,8 @@ public final class GraphicUtils {
|
|||||||
int n = cont.getComponentCount();
|
int n = cont.getComponentCount();
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
Component child = cont.getComponent(i);
|
Component child = cont.getComponent(i);
|
||||||
Component focused = getFocusableComponentOrChild(child, deepest);
|
Component focused = getFocusableComponentOrChild(child,
|
||||||
|
deepest);
|
||||||
if (focused != null) {
|
if (focused != null) {
|
||||||
return focused;
|
return focused;
|
||||||
}
|
}
|
||||||
@ -348,8 +386,7 @@ public final class GraphicUtils {
|
|||||||
return jc;
|
return jc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -363,7 +400,8 @@ public final class GraphicUtils {
|
|||||||
* can accept the focus.
|
* can accept the focus.
|
||||||
*
|
*
|
||||||
* @see #getFocusableComponentOrChild
|
* @see #getFocusableComponentOrChild
|
||||||
* @param c Component to focus on.
|
* @param c
|
||||||
|
* Component to focus on.
|
||||||
* @return Component that was focused on.
|
* @return Component that was focused on.
|
||||||
*/
|
*/
|
||||||
public static Component focusComponentOrChild(Component c) {
|
public static Component focusComponentOrChild(Component c) {
|
||||||
@ -374,10 +412,13 @@ public final class GraphicUtils {
|
|||||||
* Puts the focus on the first component in the tree of <code>c</code> that
|
* Puts the focus on the first component in the tree of <code>c</code> that
|
||||||
* can accept the focus.
|
* can accept the focus.
|
||||||
*
|
*
|
||||||
* @param c the root of the component hierarchy to search
|
* @param c
|
||||||
* @param deepest if <code>deepest</code> is true the method will focus the first and deepest component that can
|
* the root of the component hierarchy to search
|
||||||
* accept the focus.
|
* @param deepest
|
||||||
* For example, if both a child and its parent are focusable and <code>deepest</code> is true, the child is focused.
|
* if <code>deepest</code> is true the method will focus the
|
||||||
|
* first and deepest component that can accept the focus. For
|
||||||
|
* example, if both a child and its parent are focusable and
|
||||||
|
* <code>deepest</code> is true, the child is focused.
|
||||||
* @see #getFocusableComponentOrChild
|
* @see #getFocusableComponentOrChild
|
||||||
* @return Component that was focused on.
|
* @return Component that was focused on.
|
||||||
*/
|
*/
|
||||||
@ -391,17 +432,19 @@ public final class GraphicUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an {@link Image} named <code>imageName</code> as a resource
|
* Loads an {@link Image} named <code>imageName</code> as a resource
|
||||||
* relative to the Class <code>cls</code>. If the <code>Image</code> can
|
* relative to the Class <code>cls</code>. If the <code>Image</code> can not
|
||||||
* not be loaded, then <code>null</code> is returned. Images loaded here
|
* be loaded, then <code>null</code> is returned. Images loaded here will be
|
||||||
* will be added to an internal cache based upon the full {@link URL} to
|
* added to an internal cache based upon the full {@link URL} to their
|
||||||
* their location.
|
* location.
|
||||||
* <p/>
|
* <p/>
|
||||||
* <em>This method replaces legacy code from JDeveloper 3.x and earlier.</em>
|
* <em>This method replaces legacy code from JDeveloper 3.x and earlier.</em>
|
||||||
*
|
*
|
||||||
* @see Class#getResource(String)
|
* @see Class#getResource(String)
|
||||||
* @see Toolkit#createImage(URL)
|
* @see Toolkit#createImage(URL)
|
||||||
* @param imageName Name of the resource to load.
|
* @param imageName
|
||||||
* @param cls Class to pull resource from.
|
* Name of the resource to load.
|
||||||
|
* @param cls
|
||||||
|
* Class to pull resource from.
|
||||||
* @return Image loaded from resource.
|
* @return Image loaded from resource.
|
||||||
*/
|
*/
|
||||||
public static Image loadFromResource(String imageName, Class<?> cls) {
|
public static Image loadFromResource(String imageName, Class<?> cls) {
|
||||||
@ -420,28 +463,39 @@ public final class GraphicUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
Log.error(e);
|
Log.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ScreenBounds
|
||||||
|
*
|
||||||
|
* @return Array of {@link Rectangle}'s
|
||||||
|
*/
|
||||||
public static Rectangle[] getScreenBounds() {
|
public static Rectangle[] getScreenBounds() {
|
||||||
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment
|
||||||
final GraphicsDevice[] screenDevices = graphicsEnvironment.getScreenDevices();
|
.getLocalGraphicsEnvironment();
|
||||||
|
final GraphicsDevice[] screenDevices = graphicsEnvironment
|
||||||
|
.getScreenDevices();
|
||||||
Rectangle[] screenBounds = new Rectangle[screenDevices.length];
|
Rectangle[] screenBounds = new Rectangle[screenDevices.length];
|
||||||
for (int i = 0; i < screenDevices.length; i++) {
|
for (int i = 0; i < screenDevices.length; i++) {
|
||||||
GraphicsDevice screenDevice = screenDevices[i];
|
GraphicsDevice screenDevice = screenDevices[i];
|
||||||
final GraphicsConfiguration defaultConfiguration = screenDevice.getDefaultConfiguration();
|
final GraphicsConfiguration defaultConfiguration = screenDevice
|
||||||
|
.getDefaultConfiguration();
|
||||||
screenBounds[i] = defaultConfiguration.getBounds();
|
screenBounds[i] = defaultConfiguration.getBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
return screenBounds;
|
return screenBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes all Compontens the same Size
|
||||||
|
*
|
||||||
|
* @param comps
|
||||||
|
*/
|
||||||
public static void makeSameSize(JComponent... comps) {
|
public static void makeSameSize(JComponent... comps) {
|
||||||
if (comps.length == 0) {
|
if (comps.length == 0) {
|
||||||
return;
|
return;
|
||||||
@ -462,7 +516,8 @@ public final class GraphicUtils {
|
|||||||
/**
|
/**
|
||||||
* Return the hexidecimal color from a java.awt.Color
|
* Return the hexidecimal color from a java.awt.Color
|
||||||
*
|
*
|
||||||
* @param c Color to convert.
|
* @param c
|
||||||
|
* Color to convert.
|
||||||
* @return hexadecimal string
|
* @return hexadecimal string
|
||||||
*/
|
*/
|
||||||
public static String toHTMLColor(Color c) {
|
public static String toHTMLColor(Color c) {
|
||||||
@ -472,16 +527,43 @@ public final class GraphicUtils {
|
|||||||
return s.substring(2);
|
return s.substring(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Tooltip with specified width
|
||||||
|
*
|
||||||
|
* @param text
|
||||||
|
* the Text appearing in the Tooltip
|
||||||
|
* @param width
|
||||||
|
* the width of the Tooltip
|
||||||
|
* @return HTML-String displaying the Tooltip
|
||||||
|
*/
|
||||||
public static String createToolTip(String text, int width) {
|
public static String createToolTip(String text, int width) {
|
||||||
final String htmlColor = toHTMLColor(TOOLTIP_COLOR);
|
final String htmlColor = toHTMLColor(TOOLTIP_COLOR);
|
||||||
return "<html><table width=" + width + " bgColor=" + htmlColor + "><tr><td>" + text + "</td></tr></table></table>";
|
return "<html><table width=" + width + " bgColor=" + htmlColor
|
||||||
|
+ "><tr><td>" + text + "</td></tr></table></table>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Tooltop
|
||||||
|
*
|
||||||
|
* @param text
|
||||||
|
* , the Text appearing in the Tooltip
|
||||||
|
* @return HTML-String displaying the Tooltip
|
||||||
|
*/
|
||||||
public static String createToolTip(String text) {
|
public static String createToolTip(String text) {
|
||||||
final String htmlColor = toHTMLColor(TOOLTIP_COLOR);
|
final String htmlColor = toHTMLColor(TOOLTIP_COLOR);
|
||||||
return "<html><table bgColor=" + htmlColor + "><tr><td>" + text + "</td></tr></table></table>";
|
return "<html><table bgColor=" + htmlColor + "><tr><td>" + text
|
||||||
|
+ "</td></tr></table></table>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Highlights Words
|
||||||
|
*
|
||||||
|
* @param text
|
||||||
|
* , the Text containing Words that should be Highlighted
|
||||||
|
* @param query
|
||||||
|
* , the Words that should be Highlighted
|
||||||
|
* @return HTML-String, with Highlighted Words
|
||||||
|
*/
|
||||||
public static String getHighlightedWords(String text, String query) {
|
public static String getHighlightedWords(String text, String query) {
|
||||||
final StringTokenizer tkn = new StringTokenizer(query, " ");
|
final StringTokenizer tkn = new StringTokenizer(query, " ");
|
||||||
int tokenCount = tkn.countTokens();
|
int tokenCount = tkn.countTokens();
|
||||||
@ -493,16 +575,23 @@ public final class GraphicUtils {
|
|||||||
|
|
||||||
String highlightedWords;
|
String highlightedWords;
|
||||||
try {
|
try {
|
||||||
highlightedWords = StringUtils.highlightWords(text, words, "<font style=background-color:yellow;font-weight:bold;>", "</font>");
|
highlightedWords = StringUtils.highlightWords(text, words,
|
||||||
}
|
"<font style=background-color:yellow;font-weight:bold;>",
|
||||||
catch (Exception e) {
|
"</font>");
|
||||||
|
} catch (Exception e) {
|
||||||
highlightedWords = text;
|
highlightedWords = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return highlightedWords;
|
return highlightedWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an {@link ImageIcon} with a Shadow
|
||||||
|
*
|
||||||
|
* @param buf
|
||||||
|
* , the {@link Image} where a Shadow will be applied
|
||||||
|
* @return {@link ImageIcon} with shadow
|
||||||
|
*/
|
||||||
public static ImageIcon createShadowPicture(Image buf) {
|
public static ImageIcon createShadowPicture(Image buf) {
|
||||||
buf = removeTransparency(buf);
|
buf = removeTransparency(buf);
|
||||||
|
|
||||||
@ -513,11 +602,12 @@ public final class GraphicUtils {
|
|||||||
int height = buf.getHeight(null);
|
int height = buf.getHeight(null);
|
||||||
int extra = 4;
|
int extra = 4;
|
||||||
|
|
||||||
splash = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB);
|
splash = new BufferedImage(width + extra, height + extra,
|
||||||
|
BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics2D g2 = (Graphics2D) splash.getGraphics();
|
Graphics2D g2 = (Graphics2D) splash.getGraphics();
|
||||||
|
|
||||||
|
BufferedImage shadow = new BufferedImage(width + extra, height + extra,
|
||||||
BufferedImage shadow = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB);
|
BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics g = shadow.getGraphics();
|
Graphics g = shadow.getGraphics();
|
||||||
g.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f));
|
g.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f));
|
||||||
g.fillRoundRect(0, 0, width, height, 12, 12);
|
g.fillRoundRect(0, 0, width, height, 12, 12);
|
||||||
@ -527,6 +617,12 @@ public final class GraphicUtils {
|
|||||||
return new ImageIcon(splash);
|
return new ImageIcon(splash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes the Transparency of an {@link Image}
|
||||||
|
*
|
||||||
|
* @param image
|
||||||
|
* @return {@link BufferedImage} without Transparency
|
||||||
|
*/
|
||||||
public static BufferedImage removeTransparency(Image image) {
|
public static BufferedImage removeTransparency(Image image) {
|
||||||
int w = image.getWidth(null);
|
int w = image.getWidth(null);
|
||||||
int h = image.getHeight(null);
|
int h = image.getHeight(null);
|
||||||
@ -540,10 +636,23 @@ public final class GraphicUtils {
|
|||||||
return bi2;
|
return bi2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a {@link BufferedImage} to {@link Image}
|
||||||
|
*
|
||||||
|
* @param bufferedImage
|
||||||
|
* , the {@link BufferedImage}
|
||||||
|
* @return {@link Image}
|
||||||
|
*/
|
||||||
public static Image toImage(BufferedImage bufferedImage) {
|
public static Image toImage(BufferedImage bufferedImage) {
|
||||||
return Toolkit.getDefaultToolkit().createImage(bufferedImage.getSource());
|
return Toolkit.getDefaultToolkit().createImage(
|
||||||
|
bufferedImage.getSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param size
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private static ConvolveOp getBlurOp(int size) {
|
private static ConvolveOp getBlurOp(int size) {
|
||||||
float[] data = new float[size * size];
|
float[] data = new float[size * size];
|
||||||
float value = 1 / (float) (size * size);
|
float value = 1 / (float) (size * size);
|
||||||
@ -553,49 +662,113 @@ public final class GraphicUtils {
|
|||||||
return new ConvolveOp(new Kernel(size, size, data));
|
return new ConvolveOp(new Kernel(size, size, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BufferedImage convert(Image im) throws InterruptedException, IOException {
|
/**
|
||||||
|
* Converting an {@link Image} into a {@link BufferedImage} Transparency
|
||||||
|
* some Images gets lost
|
||||||
|
*
|
||||||
|
* @param im
|
||||||
|
* @return {@link BufferedImage}
|
||||||
|
* @throws InterruptedException
|
||||||
|
* @throws {@link IOException}
|
||||||
|
*/
|
||||||
|
public static BufferedImage convert(Image im) throws InterruptedException,
|
||||||
|
IOException {
|
||||||
load(im);
|
load(im);
|
||||||
BufferedImage bi = new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_INT_ARGB_PRE);
|
BufferedImage bi = new BufferedImage(im.getWidth(null),
|
||||||
|
im.getHeight(null), BufferedImage.TYPE_INT_ARGB_PRE);
|
||||||
Graphics bg = bi.getGraphics();
|
Graphics bg = bi.getGraphics();
|
||||||
bg.drawImage(im, 0, 0, null);
|
bg.drawImage(im, 0, 0, null);
|
||||||
bg.dispose();
|
bg.dispose();
|
||||||
return bi;
|
return bi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void load(Image image) throws InterruptedException, IOException {
|
/**
|
||||||
MediaTracker tracker = new MediaTracker(new Label()); //any component will do
|
* Loading an image via a MediaTracker
|
||||||
|
*
|
||||||
|
* @param image
|
||||||
|
* @throws InterruptedException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static void load(Image image) throws InterruptedException,
|
||||||
|
IOException {
|
||||||
|
MediaTracker tracker = new MediaTracker(new Label()); // any component
|
||||||
|
// will do
|
||||||
tracker.addImage(image, 0);
|
tracker.addImage(image, 0);
|
||||||
tracker.waitForID(0);
|
tracker.waitForID(0);
|
||||||
if (tracker.isErrorID(0))
|
if (tracker.isErrorID(0))
|
||||||
throw new IOException("error loading image");
|
throw new IOException("error loading image");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Bytes from an Image using an ImageInputStream, this way
|
||||||
|
* transparency is kept
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
* , input {@link File}
|
||||||
|
* @return byte[]
|
||||||
|
*/
|
||||||
|
public static byte[] getBytesFromImage(File file) {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
|
Object input = file;
|
||||||
|
|
||||||
|
ImageInputStream stream = ImageIO.createImageInputStream(input);
|
||||||
|
Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
|
||||||
|
|
||||||
|
if (!readers.hasNext())
|
||||||
|
throw new RuntimeException("no image reader found");
|
||||||
|
|
||||||
|
ImageReader reader = readers.next();
|
||||||
|
reader.setInput(stream);
|
||||||
|
int n = reader.getNumImages(true);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
BufferedImage image = reader.read(i);
|
||||||
|
ImageIO.write(image, "PNG", baos);
|
||||||
|
}
|
||||||
|
stream.close();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.error(e);
|
||||||
|
}
|
||||||
|
return baos.toByteArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ByteArray From an Image using ImageIO.write Transparency is
|
||||||
|
* not handled
|
||||||
|
*
|
||||||
|
* @param image
|
||||||
|
* , input {@link Image}
|
||||||
|
* @return byte[]
|
||||||
|
*/
|
||||||
public static byte[] getBytesFromImage(Image image) {
|
public static byte[] getBytesFromImage(Image image) {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
ImageIO.write(convert(image), "PNG", baos);
|
ImageIO.write(convert(image), "PNG", baos);
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
Log.error(e);
|
Log.error(e);
|
||||||
}
|
} catch (InterruptedException e) {
|
||||||
catch (InterruptedException e) {
|
|
||||||
Log.error(e);
|
Log.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a scaled down image if the height or width is smaller than
|
* Returns a scaled down image if the height or width is smaller than the
|
||||||
* the image size.
|
* image size.
|
||||||
*
|
*
|
||||||
* @param icon the image icon.
|
* @param icon
|
||||||
* @param newHeight the preferred height.
|
* the image icon.
|
||||||
* @param newWidth the preferred width.
|
* @param newHeight
|
||||||
|
* the preferred height.
|
||||||
|
* @param newWidth
|
||||||
|
* the preferred width.
|
||||||
* @return the icon.
|
* @return the icon.
|
||||||
*/
|
*/
|
||||||
public static ImageIcon scaleImageIcon(ImageIcon icon, int newHeight, int newWidth) {
|
public static ImageIcon scaleImageIcon(ImageIcon icon, int newHeight,
|
||||||
|
int newWidth) {
|
||||||
Image img = icon.getImage();
|
Image img = icon.getImage();
|
||||||
int height = icon.getIconHeight();
|
int height = icon.getIconHeight();
|
||||||
int width = icon.getIconWidth();
|
int width = icon.getIconWidth();
|
||||||
@ -611,14 +784,16 @@ public final class GraphicUtils {
|
|||||||
return new ImageIcon(img);
|
return new ImageIcon(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a scaled down image if the height or width is smaller than
|
* Returns a scaled down image if the height or width is smaller than the
|
||||||
* the image size.
|
* image size.
|
||||||
*
|
*
|
||||||
* @param icon the image icon.
|
* @param icon
|
||||||
* @param newHeight the preferred height.
|
* the image icon.
|
||||||
* @param newWidth the preferred width.
|
* @param newHeight
|
||||||
|
* the preferred height.
|
||||||
|
* @param newWidth
|
||||||
|
* the preferred width.
|
||||||
* @return the icon.
|
* @return the icon.
|
||||||
*/
|
*/
|
||||||
public static ImageIcon scale(ImageIcon icon, int newHeight, int newWidth) {
|
public static ImageIcon scale(ImageIcon icon, int newHeight, int newWidth) {
|
||||||
@ -631,21 +806,21 @@ public final class GraphicUtils {
|
|||||||
* Returns the native icon, if one exists for the filetype, otherwise
|
* Returns the native icon, if one exists for the filetype, otherwise
|
||||||
* returns a default document icon.
|
* returns a default document icon.
|
||||||
*
|
*
|
||||||
* @param file the file to check icon type.
|
* @param file
|
||||||
|
* the file to check icon type.
|
||||||
* @return the native icon, otherwise default document icon.
|
* @return the native icon, otherwise default document icon.
|
||||||
*/
|
*/
|
||||||
public static Icon getIcon(File file) {
|
public static Icon getIcon(File file) {
|
||||||
try {
|
try {
|
||||||
sun.awt.shell.ShellFolder sf = sun.awt.shell.ShellFolder.getShellFolder(file);
|
sun.awt.shell.ShellFolder sf = sun.awt.shell.ShellFolder
|
||||||
|
.getShellFolder(file);
|
||||||
|
|
||||||
// Get large icon
|
// Get large icon
|
||||||
return new ImageIcon(sf.getIcon(true), sf.getFolderType());
|
return new ImageIcon(sf.getIcon(true), sf.getFolderType());
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
try {
|
try {
|
||||||
return new JFileChooser().getIcon(file);
|
return new JFileChooser().getIcon(file);
|
||||||
}
|
} catch (Exception e1) {
|
||||||
catch (Exception e1) {
|
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -653,12 +828,19 @@ public final class GraphicUtils {
|
|||||||
return SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32);
|
return SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a File holding an Image into a Buffered Image
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
* {@link File}
|
||||||
|
* @return {@link BufferedImage}
|
||||||
|
*/
|
||||||
public static BufferedImage getBufferedImage(File file) {
|
public static BufferedImage getBufferedImage(File file) {
|
||||||
// Why wasn't this using it's code that pulled from the file? Hrm.
|
// Why wasn't this using it's code that pulled from the file? Hrm.
|
||||||
Icon icon = SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32);
|
Icon icon = SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32);
|
||||||
|
|
||||||
BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.OPAQUE);
|
BufferedImage bi = new BufferedImage(icon.getIconWidth(),
|
||||||
|
icon.getIconHeight(), BufferedImage.OPAQUE);
|
||||||
Graphics bg = bi.getGraphics();
|
Graphics bg = bi.getGraphics();
|
||||||
|
|
||||||
ImageIcon i = (ImageIcon) icon;
|
ImageIcon i = (ImageIcon) icon;
|
||||||
@ -669,10 +851,8 @@ public final class GraphicUtils {
|
|||||||
return bi;
|
return bi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public static void centerWindowOnScreen(Runnable runnable) {
|
||||||
public static void centerWindowOnScreen(Runnable runnable)
|
// // This method is never used
|
||||||
{
|
//
|
||||||
// TODO Auto-generated method stub
|
// }
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -68,8 +68,10 @@ public class VCardEditor {
|
|||||||
/**
|
/**
|
||||||
* Displays the VCard for an individual.
|
* Displays the VCard for an individual.
|
||||||
*
|
*
|
||||||
* @param vCard the users vcard.
|
* @param vCard
|
||||||
* @param parent the parent component, used for location.
|
* the users vcard.
|
||||||
|
* @param parent
|
||||||
|
* the parent component, used for location.
|
||||||
*/
|
*/
|
||||||
public void editProfile(final VCard vCard, JComponent parent) {
|
public void editProfile(final VCard vCard, JComponent parent) {
|
||||||
final JTabbedPane tabbedPane = new JTabbedPane();
|
final JTabbedPane tabbedPane = new JTabbedPane();
|
||||||
@ -103,7 +105,8 @@ public class VCardEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the title panel for this dialog
|
// Create the title panel for this dialog
|
||||||
titlePanel = new TitlePanel(Res.getString("title.edit.profile"), Res.getString("message.save.profile"), icon, true);
|
titlePanel = new TitlePanel(Res.getString("title.edit.profile"),
|
||||||
|
Res.getString("message.save.profile"), icon, true);
|
||||||
|
|
||||||
// Construct main panel w/ layout.
|
// Construct main panel w/ layout.
|
||||||
final JPanel mainPanel = new JPanel();
|
final JPanel mainPanel = new JPanel();
|
||||||
@ -112,7 +115,8 @@ public class VCardEditor {
|
|||||||
|
|
||||||
// The user should only be able to close this dialog.
|
// The user should only be able to close this dialog.
|
||||||
Object[] options = { Res.getString("save"), Res.getString("cancel") };
|
Object[] options = { Res.getString("save"), Res.getString("cancel") };
|
||||||
pane = new JOptionPane(tabbedPane, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
|
pane = new JOptionPane(tabbedPane, JOptionPane.PLAIN_MESSAGE,
|
||||||
|
JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
|
||||||
|
|
||||||
mainPanel.add(pane, BorderLayout.CENTER);
|
mainPanel.add(pane, BorderLayout.CENTER);
|
||||||
|
|
||||||
@ -132,8 +136,7 @@ public class VCardEditor {
|
|||||||
if (Res.getString("cancel").equals(value)) {
|
if (Res.getString("cancel").equals(value)) {
|
||||||
pane.removePropertyChangeListener(this);
|
pane.removePropertyChangeListener(this);
|
||||||
dlg.dispose();
|
dlg.dispose();
|
||||||
}
|
} else if (Res.getString("save").equals(value)) {
|
||||||
else if (Res.getString("save").equals(value)) {
|
|
||||||
pane.removePropertyChangeListener(this);
|
pane.removePropertyChangeListener(this);
|
||||||
dlg.dispose();
|
dlg.dispose();
|
||||||
saveVCard();
|
saveVCard();
|
||||||
@ -153,8 +156,10 @@ public class VCardEditor {
|
|||||||
/**
|
/**
|
||||||
* Displays the VCard for an individual.
|
* Displays the VCard for an individual.
|
||||||
*
|
*
|
||||||
* @param vCard the users vcard.
|
* @param vCard
|
||||||
* @param parent the parent component, used for location.
|
* the users vcard.
|
||||||
|
* @param parent
|
||||||
|
* the parent component, used for location.
|
||||||
*/
|
*/
|
||||||
public void viewFullProfile(final VCard vCard, JComponent parent) {
|
public void viewFullProfile(final VCard vCard, JComponent parent) {
|
||||||
final JTabbedPane tabbedPane = new JTabbedPane();
|
final JTabbedPane tabbedPane = new JTabbedPane();
|
||||||
@ -192,7 +197,8 @@ public class VCardEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the title panel for this dialog
|
// Create the title panel for this dialog
|
||||||
titlePanel = new TitlePanel(Res.getString("title.profile.information"), "", icon, true);
|
titlePanel = new TitlePanel(Res.getString("title.profile.information"),
|
||||||
|
"", icon, true);
|
||||||
|
|
||||||
// Construct main panel w/ layout.
|
// Construct main panel w/ layout.
|
||||||
final JPanel mainPanel = new JPanel();
|
final JPanel mainPanel = new JPanel();
|
||||||
@ -201,7 +207,8 @@ public class VCardEditor {
|
|||||||
|
|
||||||
// The user should only be able to close this dialog.
|
// The user should only be able to close this dialog.
|
||||||
Object[] options = { Res.getString("close") };
|
Object[] options = { Res.getString("close") };
|
||||||
pane = new JOptionPane(tabbedPane, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
|
pane = new JOptionPane(tabbedPane, JOptionPane.PLAIN_MESSAGE,
|
||||||
|
JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
|
||||||
|
|
||||||
mainPanel.add(pane, BorderLayout.CENTER);
|
mainPanel.add(pane, BorderLayout.CENTER);
|
||||||
|
|
||||||
@ -215,7 +222,6 @@ public class VCardEditor {
|
|||||||
dlg.setContentPane(mainPanel);
|
dlg.setContentPane(mainPanel);
|
||||||
dlg.setLocationRelativeTo(parent);
|
dlg.setLocationRelativeTo(parent);
|
||||||
|
|
||||||
|
|
||||||
PropertyChangeListener changeListener = new PropertyChangeListener() {
|
PropertyChangeListener changeListener = new PropertyChangeListener() {
|
||||||
public void propertyChange(PropertyChangeEvent e) {
|
public void propertyChange(PropertyChangeEvent e) {
|
||||||
Object o = pane.getValue();
|
Object o = pane.getValue();
|
||||||
@ -245,28 +251,37 @@ public class VCardEditor {
|
|||||||
/**
|
/**
|
||||||
* Displays a users profile.
|
* Displays a users profile.
|
||||||
*
|
*
|
||||||
* @param jid the jid of the user.
|
* @param jid
|
||||||
* @param vcard the users vcard.
|
* the jid of the user.
|
||||||
* @param parent the parent component, used for location handling.
|
* @param vcard
|
||||||
|
* the users vcard.
|
||||||
|
* @param parent
|
||||||
|
* the parent component, used for location handling.
|
||||||
*/
|
*/
|
||||||
public void displayProfile(final String jid, VCard vcard, JComponent parent) {
|
public void displayProfile(final String jid, VCard vcard, JComponent parent) {
|
||||||
VCardViewer viewer = new VCardViewer(jid);
|
VCardViewer viewer = new VCardViewer(jid);
|
||||||
|
|
||||||
final JFrame dlg = new JFrame(Res.getString("title.view.profile.for", jid));
|
final JFrame dlg = new JFrame(Res.getString("title.view.profile.for",
|
||||||
|
jid));
|
||||||
|
|
||||||
avatarLabel = new JLabel();
|
avatarLabel = new JLabel();
|
||||||
avatarLabel.setHorizontalAlignment(JButton.RIGHT);
|
avatarLabel.setHorizontalAlignment(JButton.RIGHT);
|
||||||
avatarLabel.setBorder(BorderFactory.createBevelBorder(0, Color.white, Color.lightGray));
|
avatarLabel.setBorder(BorderFactory.createBevelBorder(0, Color.white,
|
||||||
|
Color.lightGray));
|
||||||
|
|
||||||
// The user should only be able to close this dialog.
|
// The user should only be able to close this dialog.
|
||||||
Object[] options = { Res.getString("button.view.profile"), Res.getString("close")};
|
Object[] options = { Res.getString("button.view.profile"),
|
||||||
final JOptionPane pane = new JOptionPane(viewer, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
|
Res.getString("close") };
|
||||||
|
final JOptionPane pane = new JOptionPane(viewer,
|
||||||
|
JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,
|
||||||
|
options, options[0]);
|
||||||
|
|
||||||
// mainPanel.add(pane, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0));
|
// mainPanel.add(pane, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
|
||||||
|
// GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5,
|
||||||
|
// 5, 5), 0, 0));
|
||||||
|
|
||||||
|
dlg.setIconImage(SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_16x16)
|
||||||
dlg.setIconImage(SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_16x16).getImage());
|
.getImage());
|
||||||
|
|
||||||
dlg.pack();
|
dlg.pack();
|
||||||
dlg.setSize(350, 250);
|
dlg.setSize(350, 250);
|
||||||
@ -285,8 +300,7 @@ public class VCardEditor {
|
|||||||
if (Res.getString("close").equals(value)) {
|
if (Res.getString("close").equals(value)) {
|
||||||
pane.removePropertyChangeListener(this);
|
pane.removePropertyChangeListener(this);
|
||||||
dlg.dispose();
|
dlg.dispose();
|
||||||
}
|
} else if (Res.getString("button.view.profile").equals(value)) {
|
||||||
else if (Res.getString("button.view.profile").equals(value)) {
|
|
||||||
pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
|
pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
|
||||||
SparkManager.getVCardManager().viewFullProfile(jid, pane);
|
SparkManager.getVCardManager().viewFullProfile(jid, pane);
|
||||||
}
|
}
|
||||||
@ -308,11 +322,11 @@ public class VCardEditor {
|
|||||||
dlg.requestFocus();
|
dlg.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the UI based on a VCard.
|
* Builds the UI based on a VCard.
|
||||||
*
|
*
|
||||||
* @param vcard the vcard used to build the UI.
|
* @param vcard
|
||||||
|
* the vcard used to build the UI.
|
||||||
*/
|
*/
|
||||||
private void buildUI(VCard vcard) {
|
private void buildUI(VCard vcard) {
|
||||||
personalPanel.setFirstName(vcard.getFirstName());
|
personalPanel.setFirstName(vcard.getFirstName());
|
||||||
@ -405,16 +419,12 @@ public class VCardEditor {
|
|||||||
byte[] avatarBytes = avatarPanel.getAvatarBytes();
|
byte[] avatarBytes = avatarPanel.getAvatarBytes();
|
||||||
|
|
||||||
if (avatarFile != null) {
|
if (avatarFile != null) {
|
||||||
try {
|
avatarBytes = GraphicUtils.getBytesFromImage(avatarFile);
|
||||||
// Make it 48x48
|
ImageIcon icon = new ImageIcon(avatarBytes);
|
||||||
ImageIcon icon = new ImageIcon(avatarFile.toURI().toURL());
|
|
||||||
Image image = icon.getImage();
|
Image image = icon.getImage();
|
||||||
image = image.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
|
image = image.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
|
||||||
avatarBytes = GraphicUtils.getBytesFromImage(image);
|
avatarBytes = GraphicUtils.getBytesFromImage(image);
|
||||||
}
|
|
||||||
catch (MalformedURLException e) {
|
|
||||||
Log.error("Unable to set avatar.", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If avatar bytes, persist as vcard.
|
// If avatar bytes, persist as vcard.
|
||||||
@ -430,24 +440,28 @@ public class VCardEditor {
|
|||||||
|
|
||||||
// Notify users.
|
// Notify users.
|
||||||
if (avatarFile != null || avatarBytes != null) {
|
if (avatarFile != null || avatarBytes != null) {
|
||||||
Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence();
|
Presence presence = SparkManager.getWorkspace().getStatusBar()
|
||||||
Presence newPresence = new Presence(presence.getType(), presence.getStatus(), presence.getPriority(), presence.getMode());
|
.getPresence();
|
||||||
|
Presence newPresence = new Presence(presence.getType(),
|
||||||
|
presence.getStatus(), presence.getPriority(),
|
||||||
|
presence.getMode());
|
||||||
|
|
||||||
// Change my own presence
|
// Change my own presence
|
||||||
SparkManager.getSessionManager().changePresence(newPresence);
|
SparkManager.getSessionManager().changePresence(newPresence);
|
||||||
|
|
||||||
// Chnage avatar in status bar.
|
// Chnage avatar in status bar.
|
||||||
StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
|
StatusBar statusBar = SparkManager.getWorkspace()
|
||||||
|
.getStatusBar();
|
||||||
statusBar.setAvatar(new ImageIcon(vcard.getAvatar()));
|
statusBar.setAvatar(new ImageIcon(vcard.getAvatar()));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
String firstName = vcard.getFirstName();
|
String firstName = vcard.getFirstName();
|
||||||
String lastName = vcard.getLastName();
|
String lastName = vcard.getLastName();
|
||||||
StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
|
StatusBar statusBar = SparkManager.getWorkspace()
|
||||||
if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
|
.getStatusBar();
|
||||||
|
if (ModelUtil.hasLength(firstName)
|
||||||
|
&& ModelUtil.hasLength(lastName)) {
|
||||||
statusBar.setNickname(firstName + " " + lastName);
|
statusBar.setNickname(firstName + " " + lastName);
|
||||||
}
|
} else if (ModelUtil.hasLength(firstName)) {
|
||||||
else if (ModelUtil.hasLength(firstName)) {
|
|
||||||
statusBar.setNickname(firstName);
|
statusBar.setNickname(firstName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,14 +470,12 @@ public class VCardEditor {
|
|||||||
|
|
||||||
// Notify listenres
|
// Notify listenres
|
||||||
SparkManager.getVCardManager().notifyVCardListeners();
|
SparkManager.getVCardManager().notifyVCardListeners();
|
||||||
}
|
} catch (XMPPException e) {
|
||||||
catch (XMPPException e) {
|
|
||||||
Log.error(e);
|
Log.error(e);
|
||||||
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.vcard.not.supported"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(SparkManager.getMainWindow(),
|
||||||
|
Res.getString("message.vcard.not.supported"),
|
||||||
|
Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user