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:
Wolf Posdorfer
2011-03-09 09:18:46 +00:00
committed by wolf.posdorfer
parent 5ecd4ec51c
commit 09f6366888
3 changed files with 2325 additions and 2139 deletions

View File

@ -46,10 +46,13 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
@ -61,12 +64,13 @@ import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.util.log.Log;
/**
* <code>GraphicsUtils</code> class defines common user-interface related utility
* functions.
* <code>GraphicsUtils</code> class defines common user-interface related
* utility functions.
*/
public final class GraphicUtils {
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);
protected final static Component component = new Component() {
@ -84,19 +88,22 @@ public final class GraphicUtils {
/**
* 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() {
}
/**
* 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) {
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
final Dimension screenSize = Toolkit.getDefaultToolkit()
.getScreenSize();
final Dimension size = window.getSize();
if (size.height > screenSize.height) {
@ -114,20 +121,27 @@ public final class GraphicUtils {
/**
* Draws a single-line highlight border rectangle.
*
* @param g The graphics context to use for drawing.
* @param x The left edge of the border.
* @param y 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,
* @param g
* The graphics context to use for drawing.
* @param x
* The left edge of the border.
* @param y
* 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.
* @param shadow The shadow color for the border.
* @param highlight The highlight color for the border.
* @param shadow
* The shadow color for the border.
* @param highlight
* The highlight color for the border.
* @see javax.swing.border.EtchedBorder
*/
public static void drawHighlightBorder(Graphics g, int x, int y,
int width, int height, boolean raised,
Color shadow, Color highlight) {
public static void drawHighlightBorder(Graphics g, int x, int y, int width,
int height, boolean raised, Color shadow, Color highlight) {
final Color oldColor = g.getColor();
g.translate(x, y);
@ -154,6 +168,13 @@ public final class GraphicUtils {
return HIGHLIGHT_INSETS;
}
/**
* Creates an ImageIcon from an Image
*
* @param image
* {@link Image}
* @return {@link ImageIcon}
*/
public static ImageIcon createImageIcon(Image image) {
if (image == null) {
return null;
@ -163,8 +184,7 @@ public final class GraphicUtils {
tracker.addImage(image, 0);
try {
tracker.waitForID(0, 0);
}
catch (InterruptedException e) {
} catch (InterruptedException e) {
System.out.println("INTERRUPTED while loading Image");
}
tracker.removeImage(image, 0);
@ -174,47 +194,55 @@ public final class GraphicUtils {
}
/**
* Returns a point where the given popup menu should be shown. The
* point is calculated by adjusting the X and Y coordinates from the
* given mouse event so that the popup menu will not be clipped by
* the screen boundaries.
* Returns a point where the given popup menu should be shown. The point is
* calculated by adjusting the X and Y coordinates from the given mouse
* event so that the popup menu will not be clipped by the screen
* boundaries.
*
* @param popup the popup menu
* @param event the mouse event
* @param popup
* the popup menu
* @param event
* the mouse event
* @return the point where the popup menu should be shown
*/
public static Point getPopupMenuShowPoint(JPopupMenu popup, MouseEvent event) {
Component source = (Component) event.getSource();
Point topLeftSource = source.getLocationOnScreen();
Point ptRet = getPopupMenuShowPoint(popup,
topLeftSource.x + event.getX(),
topLeftSource.y + event.getY());
topLeftSource.x + event.getX(), topLeftSource.y + event.getY());
ptRet.translate(-topLeftSource.x, -topLeftSource.y);
return ptRet;
}
/**
* Returns a point where the given popup menu should be shown. The
* point is calculated by adjusting the X and Y coordinates so that
* the popup menu will not be clipped by the screen boundaries.
* Returns a point where the given popup menu should be shown. The point is
* calculated by adjusting the X and Y coordinates so that the popup menu
* will not be clipped by the screen boundaries.
*
* @param popup the popup menu
* @param x the x position in screen coordinate
* @param y the y position in screen coordinates
* @param popup
* the popup menu
* @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
* coordinates
*/
public static Point getPopupMenuShowPoint(JPopupMenu popup, int x, int y) {
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();
int n = screensBounds.length;
for (int i = 0; i < n; 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();
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;
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).
* The window must already have been sized.
* @param window Window to center.
* @param over Component to center over.
* Centers the window over a component (usually another window). The window
* must already have been sized.
*
* @param window
* Window to center.
* @param over
* Component to center over.
*/
public static void centerWindowOnComponent(Window window, Component over) {
if ((over == null) || !over.isShowing()) {
@ -243,7 +275,6 @@ public final class GraphicUtils {
return;
}
Point parentLocation = over.getLocationOnScreen();
Dimension parentSize = over.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
*/
public static boolean isAncestorOfFocusedComponent(Component c) {
if (c.hasFocus()) {
return true;
}
else {
} else {
if (c instanceof Container) {
Container cont = (Container) c;
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
* the focus.
*
* @param c the root of the component hierarchy to search
* @param c
* the root of the component hierarchy to search
* @see #focusComponentOrChild
* @deprecated replaced by {@link #getFocusableComponentOrChild(Component,boolean)}
* @deprecated replaced by
* {@link #getFocusableComponentOrChild(Component,boolean)}
* @return Component that was focused on.
*/
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
* the focus.
*
* @param c the root of the component hierarchy to search
* @param deepest 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.
* @param c
* the root of the component hierarchy to search
* @param deepest
* 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
* @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 instanceof Container) {
Container cont = (Container) c;
@ -335,7 +372,8 @@ public final class GraphicUtils {
int n = cont.getComponentCount();
for (int i = 0; i < n; i++) {
Component child = cont.getComponent(i);
Component focused = getFocusableComponentOrChild(child, deepest);
Component focused = getFocusableComponentOrChild(child,
deepest);
if (focused != null) {
return focused;
}
@ -348,8 +386,7 @@ public final class GraphicUtils {
return jc;
}
}
}
else {
} else {
return c;
}
}
@ -363,7 +400,8 @@ public final class GraphicUtils {
* can accept the focus.
*
* @see #getFocusableComponentOrChild
* @param c Component to focus on.
* @param c
* Component to focus on.
* @return Component that was focused on.
*/
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
* can accept the focus.
*
* @param c the root of the component hierarchy to search
* @param deepest 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.
* @param c
* the root of the component hierarchy to search
* @param deepest
* 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
* @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
* relative to the Class <code>cls</code>. If the <code>Image</code> can
* not be loaded, then <code>null</code> is returned. Images loaded here
* will be added to an internal cache based upon the full {@link URL} to
* their location.
* relative to the Class <code>cls</code>. If the <code>Image</code> can not
* be loaded, then <code>null</code> is returned. Images loaded here will be
* added to an internal cache based upon the full {@link URL} to their
* location.
* <p/>
* <em>This method replaces legacy code from JDeveloper 3.x and earlier.</em>
*
* @see Class#getResource(String)
* @see Toolkit#createImage(URL)
* @param imageName Name of the resource to load.
* @param cls Class to pull resource from.
* @param imageName
* Name of the resource to load.
* @param cls
* Class to pull resource from.
* @return Image loaded from resource.
*/
public static Image loadFromResource(String imageName, Class<?> cls) {
@ -420,28 +463,39 @@ public final class GraphicUtils {
}
return image;
}
catch (Exception e) {
} catch (Exception e) {
Log.error(e);
}
return null;
}
/**
* Returns the ScreenBounds
*
* @return Array of {@link Rectangle}'s
*/
public static Rectangle[] getScreenBounds() {
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice[] screenDevices = graphicsEnvironment.getScreenDevices();
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment
.getLocalGraphicsEnvironment();
final GraphicsDevice[] screenDevices = graphicsEnvironment
.getScreenDevices();
Rectangle[] screenBounds = new Rectangle[screenDevices.length];
for (int i = 0; i < screenDevices.length; i++) {
GraphicsDevice screenDevice = screenDevices[i];
final GraphicsConfiguration defaultConfiguration = screenDevice.getDefaultConfiguration();
final GraphicsConfiguration defaultConfiguration = screenDevice
.getDefaultConfiguration();
screenBounds[i] = defaultConfiguration.getBounds();
}
return screenBounds;
}
/**
* Makes all Compontens the same Size
*
* @param comps
*/
public static void makeSameSize(JComponent... comps) {
if (comps.length == 0) {
return;
@ -462,7 +516,8 @@ public final class GraphicUtils {
/**
* Return the hexidecimal color from a java.awt.Color
*
* @param c Color to convert.
* @param c
* Color to convert.
* @return hexadecimal string
*/
public static String toHTMLColor(Color c) {
@ -472,16 +527,43 @@ public final class GraphicUtils {
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) {
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) {
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) {
final StringTokenizer tkn = new StringTokenizer(query, " ");
int tokenCount = tkn.countTokens();
@ -493,16 +575,23 @@ public final class GraphicUtils {
String highlightedWords;
try {
highlightedWords = StringUtils.highlightWords(text, words, "<font style=background-color:yellow;font-weight:bold;>", "</font>");
}
catch (Exception e) {
highlightedWords = StringUtils.highlightWords(text, words,
"<font style=background-color:yellow;font-weight:bold;>",
"</font>");
} catch (Exception e) {
highlightedWords = text;
}
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) {
buf = removeTransparency(buf);
@ -513,11 +602,12 @@ public final class GraphicUtils {
int height = buf.getHeight(null);
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();
BufferedImage shadow = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB);
BufferedImage shadow = new BufferedImage(width + extra, height + extra,
BufferedImage.TYPE_INT_ARGB);
Graphics g = shadow.getGraphics();
g.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f));
g.fillRoundRect(0, 0, width, height, 12, 12);
@ -527,6 +617,12 @@ public final class GraphicUtils {
return new ImageIcon(splash);
}
/**
* removes the Transparency of an {@link Image}
*
* @param image
* @return {@link BufferedImage} without Transparency
*/
public static BufferedImage removeTransparency(Image image) {
int w = image.getWidth(null);
int h = image.getHeight(null);
@ -540,10 +636,23 @@ public final class GraphicUtils {
return bi2;
}
/**
* Converts a {@link BufferedImage} to {@link Image}
*
* @param bufferedImage
* , the {@link BufferedImage}
* @return {@link Image}
*/
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) {
float[] data = new 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));
}
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);
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();
bg.drawImage(im, 0, 0, null);
bg.dispose();
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.waitForID(0);
if (tracker.isErrorID(0))
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) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageIO.write(convert(image), "PNG", baos);
}
catch (IOException e) {
} catch (IOException e) {
Log.error(e);
}
catch (InterruptedException e) {
} catch (InterruptedException e) {
Log.error(e);
}
return baos.toByteArray();
}
/**
* Returns a scaled down image if the height or width is smaller than
* the image size.
* Returns a scaled down image if the height or width is smaller than the
* image size.
*
* @param icon the image icon.
* @param newHeight the preferred height.
* @param newWidth the preferred width.
* @param icon
* the image icon.
* @param newHeight
* the preferred height.
* @param newWidth
* the preferred width.
* @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();
int height = icon.getIconHeight();
int width = icon.getIconWidth();
@ -611,14 +784,16 @@ public final class GraphicUtils {
return new ImageIcon(img);
}
/**
* Returns a scaled down image if the height or width is smaller than
* the image size.
* Returns a scaled down image if the height or width is smaller than the
* image size.
*
* @param icon the image icon.
* @param newHeight the preferred height.
* @param newWidth the preferred width.
* @param icon
* the image icon.
* @param newHeight
* the preferred height.
* @param newWidth
* the preferred width.
* @return the icon.
*/
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 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.
*/
public static Icon getIcon(File file) {
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
return new ImageIcon(sf.getIcon(true), sf.getFolderType());
}
catch (Exception e) {
} catch (Exception e) {
try {
return new JFileChooser().getIcon(file);
}
catch (Exception e1) {
} catch (Exception e1) {
// Do nothing.
}
}
@ -653,12 +828,19 @@ public final class GraphicUtils {
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) {
// Why wasn't this using it's code that pulled from the file? Hrm.
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();
ImageIcon i = (ImageIcon) icon;
@ -669,10 +851,8 @@ public final class GraphicUtils {
return bi;
}
public static void centerWindowOnScreen(Runnable runnable)
{
// TODO Auto-generated method stub
}
// public static void centerWindowOnScreen(Runnable runnable) {
// // This method is never used
//
// }
}

File diff suppressed because it is too large Load Diff

View File

@ -68,8 +68,10 @@ public class VCardEditor {
/**
* Displays the VCard for an individual.
*
* @param vCard the users vcard.
* @param parent the parent component, used for location.
* @param vCard
* the users vcard.
* @param parent
* the parent component, used for location.
*/
public void editProfile(final VCard vCard, JComponent parent) {
final JTabbedPane tabbedPane = new JTabbedPane();
@ -103,7 +105,8 @@ public class VCardEditor {
}
// 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.
final JPanel mainPanel = new JPanel();
@ -112,7 +115,8 @@ public class VCardEditor {
// The user should only be able to close this dialog.
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);
@ -132,8 +136,7 @@ public class VCardEditor {
if (Res.getString("cancel").equals(value)) {
pane.removePropertyChangeListener(this);
dlg.dispose();
}
else if (Res.getString("save").equals(value)) {
} else if (Res.getString("save").equals(value)) {
pane.removePropertyChangeListener(this);
dlg.dispose();
saveVCard();
@ -153,8 +156,10 @@ public class VCardEditor {
/**
* Displays the VCard for an individual.
*
* @param vCard the users vcard.
* @param parent the parent component, used for location.
* @param vCard
* the users vcard.
* @param parent
* the parent component, used for location.
*/
public void viewFullProfile(final VCard vCard, JComponent parent) {
final JTabbedPane tabbedPane = new JTabbedPane();
@ -192,7 +197,8 @@ public class VCardEditor {
}
// 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.
final JPanel mainPanel = new JPanel();
@ -201,7 +207,8 @@ public class VCardEditor {
// The user should only be able to close this dialog.
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);
@ -215,7 +222,6 @@ public class VCardEditor {
dlg.setContentPane(mainPanel);
dlg.setLocationRelativeTo(parent);
PropertyChangeListener changeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
Object o = pane.getValue();
@ -245,28 +251,37 @@ public class VCardEditor {
/**
* Displays a users profile.
*
* @param jid the jid of the user.
* @param vcard the users vcard.
* @param parent the parent component, used for location handling.
* @param jid
* the jid of the user.
* @param vcard
* the users vcard.
* @param parent
* the parent component, used for location handling.
*/
public void displayProfile(final String jid, VCard vcard, JComponent parent) {
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.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.
Object[] options = { Res.getString("button.view.profile"), Res.getString("close")};
final JOptionPane pane = new JOptionPane(viewer, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
Object[] options = { Res.getString("button.view.profile"),
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).getImage());
dlg.setIconImage(SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_16x16)
.getImage());
dlg.pack();
dlg.setSize(350, 250);
@ -285,8 +300,7 @@ public class VCardEditor {
if (Res.getString("close").equals(value)) {
pane.removePropertyChangeListener(this);
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);
SparkManager.getVCardManager().viewFullProfile(jid, pane);
}
@ -308,11 +322,11 @@ public class VCardEditor {
dlg.requestFocus();
}
/**
* 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) {
personalPanel.setFirstName(vcard.getFirstName());
@ -405,16 +419,12 @@ public class VCardEditor {
byte[] avatarBytes = avatarPanel.getAvatarBytes();
if (avatarFile != null) {
try {
// Make it 48x48
ImageIcon icon = new ImageIcon(avatarFile.toURI().toURL());
avatarBytes = GraphicUtils.getBytesFromImage(avatarFile);
ImageIcon icon = new ImageIcon(avatarBytes);
Image image = icon.getImage();
image = image.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
avatarBytes = GraphicUtils.getBytesFromImage(image);
}
catch (MalformedURLException e) {
Log.error("Unable to set avatar.", e);
}
}
// If avatar bytes, persist as vcard.
@ -430,24 +440,28 @@ public class VCardEditor {
// Notify users.
if (avatarFile != null || avatarBytes != null) {
Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence();
Presence newPresence = new Presence(presence.getType(), presence.getStatus(), presence.getPriority(), presence.getMode());
Presence presence = SparkManager.getWorkspace().getStatusBar()
.getPresence();
Presence newPresence = new Presence(presence.getType(),
presence.getStatus(), presence.getPriority(),
presence.getMode());
// Change my own presence
SparkManager.getSessionManager().changePresence(newPresence);
// Chnage avatar in status bar.
StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
StatusBar statusBar = SparkManager.getWorkspace()
.getStatusBar();
statusBar.setAvatar(new ImageIcon(vcard.getAvatar()));
}
else {
} else {
String firstName = vcard.getFirstName();
String lastName = vcard.getLastName();
StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
StatusBar statusBar = SparkManager.getWorkspace()
.getStatusBar();
if (ModelUtil.hasLength(firstName)
&& ModelUtil.hasLength(lastName)) {
statusBar.setNickname(firstName + " " + lastName);
}
else if (ModelUtil.hasLength(firstName)) {
} else if (ModelUtil.hasLength(firstName)) {
statusBar.setNickname(firstName);
}
@ -456,14 +470,12 @@ public class VCardEditor {
// Notify listenres
SparkManager.getVCardManager().notifyVCardListeners();
}
catch (XMPPException e) {
} catch (XMPPException 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);
}
}
}