From: <mol...@us...> - 2009-02-19 10:55:54
|
Revision: 1024 http://openutils.svn.sourceforge.net/openutils/?rev=1024&view=rev Author: molaschi Date: 2009-02-19 10:55:49 +0000 (Thu, 19 Feb 2009) Log Message: ----------- fix problem on node name editing Modified Paths: -------------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTree.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTree.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTree.java 2009-02-17 09:49:37 UTC (rev 1023) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tree/MediaModuleTree.java 2009-02-19 10:55:49 UTC (rev 1024) @@ -331,10 +331,11 @@ html.append(" />"); //$NON-NLS-1$ } String dblclick = StringUtils.EMPTY; - if (permissionWrite && StringUtils.isNotEmpty(this.getColumns(0).getHtmlEdit()) && !this.isBrowseMode()) + String htmlEdit = this.getColumns(0).getHtmlEdit(); + if (permissionWrite && StringUtils.isNotEmpty(htmlEdit) && !this.isBrowseMode()) // && this.getRequest().getParameter("selectMedia") == null) { - dblclick = " ondblclick=\"" + this.getJavascriptTree() + ".editNodeData(this,'" + handle + "',0);\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + dblclick = " ondblclick=\"" + this.getJavascriptTree() + ".editNodeData(this,'" + handle + "',0,'"+ htmlEdit.replace("\"", """) +"');\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } html.append("<span class=\"mgnlTreeText\" id=\""); html.append(idPre); Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-02-17 09:49:37 UTC (rev 1023) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-02-19 10:55:49 UTC (rev 1024) @@ -24,9 +24,11 @@ import info.magnolia.cms.util.ExclusiveWrite; import info.magnolia.context.MgnlContext; +import java.awt.Color; import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; +import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.io.BufferedOutputStream; @@ -73,6 +75,8 @@ private static SimpleDateFormat sdf; + private static String TRANSPARENT = "transparent"; + private static final String[] extensions = new String[]{"jpg", "gif", "png" }; static @@ -194,6 +198,16 @@ */ public static BufferedImage fitIn(BufferedImage original, int x, int y) { + return resizeInOut(original, x, y, false); + } + + public static BufferedImage resizeNoCrop(BufferedImage original, int x, int y) + { + return resizeInOut(original, x, y, true); + } + + private static BufferedImage resizeInOut(BufferedImage original, int x, int y, boolean external) + { if (original == null) { throw new IllegalArgumentException("input image is null"); @@ -207,67 +221,13 @@ throw new IllegalArgumentException("Broken input image (width=" + oX + ",height=" + oY + ")"); } - float oDelta = oX / oY; - float delta = ((float) x) / ((float) y); - - if (oDelta > delta) - { - int newY = (int) (x * oY / oX); - if (newY < 1) - { - newY = 1; - } - return resizeImage(original, x, newY); - } - else if (oDelta < delta) - { - int newX = (int) (y * oX / oY); - if (newX < 1) - { - newX = 1; - } - return resizeImage(original, newX, y); - } - else - { - return resizeImage(original, x, y); - } - } - - public static BufferedImage resizeNoCrop(BufferedImage original, int x, int y) - { - float oX = original.getWidth(); - float oY = original.getHeight(); - double xRatio = (double) x / oX; double yRatio = (double) y / oY; - double ratio = Math.min(xRatio, yRatio); + double ratio = (external ? Math.min(xRatio, yRatio) : Math.min(xRatio, yRatio)); int newX = (int) Math.round(oX * ratio); int newY = (int) Math.round(oY * ratio); - BufferedImage resizedImage = new BufferedImage(x, y, getType(original.getColorModel())); - - Graphics2D graphics2D = resizedImage.createGraphics(); - graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - - if (ratio > 1) - { - graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - graphics2D.drawImage(original, (x - newX) / 2, (y - newY) / 2, newX, newY, null); - } - else - { - graphics2D.drawImage( - original.getScaledInstance(newX, newY, Image.SCALE_SMOOTH), - (x - newX) / 2, - (y - newY) / 2, - newX, - newY, - null); - } - - return resizedImage; + return resizeImage(original, newX, newY); } /** @@ -302,6 +262,78 @@ } } + private static int[] convertHexToRGB(String hexColor) + { + String hex = hexColor.trim(); + if (hex.startsWith("#")) + { + hex = hex.substring(1); + } + if (hex.equals("transparent")) + { + return new int[]{0, 0, 0, 0 }; + } + if (hex.length() == 3) + { + // allow three digit codes like for css + hex = String.valueOf(hex.charAt(0)) + + String.valueOf(hex.charAt(0)) + + String.valueOf(hex.charAt(1)) + + String.valueOf(hex.charAt(1)) + + String.valueOf(hex.charAt(2)) + + String.valueOf(hex.charAt(2)); + } + + int[] rgb = new int[4]; + try + { + // Convert rrggbb string to hex ints + rgb[0] = Integer.parseInt(hex.substring(0, 2), 16); + rgb[1] = Integer.parseInt(hex.substring(2, 4), 16); + rgb[2] = Integer.parseInt(hex.substring(4), 16); + rgb[3] = 255; + } + catch (NumberFormatException e) + { + log.error("NumberFormatException occured during text-to-image conversion: " + + "Attempting to convert Hex [" + + hex + + "] color to RGB color: " + + e.getMessage(), e); + rgb = new int[]{255, 0, 0, 255 }; // red + } + return rgb; + } + + public static BufferedImage addRoundedCorners(BufferedImage original, String backgroundColor, int radius) + { + BufferedImage resizedImage; + try + { + resizedImage = new BufferedImage(original.getWidth(), original.getHeight(), getType(original + .getColorModel())); + } + catch (NegativeArraySizeException e) + { + throw new RuntimeException("NegativeArraySizeException caught when resizing image]"); + } + + Graphics2D graphics2D = resizedImage.createGraphics(); + graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + + int[] colorAr = convertHexToRGB(backgroundColor); + Color color = new Color(colorAr[0], colorAr[1], colorAr[2], colorAr[3]); + + graphics2D.setBackground(color); + graphics2D.clearRect(0, 0, original.getWidth(), original.getHeight()); + graphics2D + .setClip(new RoundRectangle2D.Double(0, 0, original.getWidth(), original.getHeight(), radius, radius)); + graphics2D.drawImage(original, 0, 0, original.getWidth(), original.getHeight(), null); + + return resizedImage; + } + /** * Save a resolution for an image to a node (in resolutions/res-[width]x[height]/data.jpg) * @param image image to save This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |