[Schmitzm-commits] r2123 - in trunk/schmitzm-core/src/main: java/de/schmitzm/swing resources/de/schmitzm/swing/resource/icons resources/de/schmitzm/swing/resource/icons/checkbox
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Fri Nov 9 15:00:46 CET 2012
Author: mojays
Date: 2012-11-09 15:00:46 +0100 (Fri, 09 Nov 2012)
New Revision: 2123
Added:
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/checked.png
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/disabled_checked.png
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/disabled_unchecked.png
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/unchecked.png
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
Log:
SwingUtil: new icons for checked and unchecked JCheckBox (used to resize checkbox)
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2012-11-04 16:04:32 UTC (rev 2122)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2012-11-09 14:00:46 UTC (rev 2123)
@@ -246,7 +246,16 @@
public static final Cursor SELECTION_REMOVE_CURSOR = createCursorFromResourcePath(
"resource/cursor/selection_remove.png", 10, 10, null);
-
+ /** Icon of default checkbox with state enabled and checked */
+ public static final ImageIcon ICON_CHECKBOX_CHECKED = SwingUtil.createImageIconFromResourcePath(SwingUtil.class, "resource/icons/checkbox/checked.png", null);
+ /** Icon of default checkbox with state enabled and unchecked */
+ public static final ImageIcon ICON_CHECKBOX_UNCHECKED = SwingUtil.createImageIconFromResourcePath(SwingUtil.class, "resource/icons/checkbox/unchecked.png", null);
+ /** Icon of default checkbox with state disabled and checked */
+ public static final ImageIcon ICON_CHECKBOX_DISABLED_CHECKED = SwingUtil.createImageIconFromResourcePath(SwingUtil.class, "resource/icons/checkbox/disabled_checked.png", null);
+ /** Icon of default checkbox with state disabled and unchecked */
+ public static final ImageIcon ICON_CHECKBOX_DISABLED_UNCHECKED = SwingUtil.createImageIconFromResourcePath(SwingUtil.class, "resource/icons/checkbox/disabled_unchecked.png", null);
+
+
/**
* Modus "Innen".
*
@@ -1441,6 +1450,11 @@
defaults.put(key, new Font(font.getName(), font.getStyle(), newSize));
}
}
+
+// if ( value instanceof Image )
+// System.out.println(key);
+// if ( value instanceof ImageIcon )
+// System.out.println(key);
}
// Increase default font
@@ -2574,6 +2588,49 @@
table.setIntercellSpacing(new Dimension(0,0));
}
+ /**
+ * Resizes an image by a scale factor, keeping aspect ratio unchanged.
+ * @param image the image to resize
+ * @param scaleFactor the factor to rescale with
+ */
+ public static Image scaleImage(Image image, double scaleFactor) {
+ double w = image.getWidth(null);
+ double h = image.getHeight(null);
+
+ w *= scaleFactor;
+ h *= scaleFactor;
+
+ w = Math.round(w);
+ h = Math.round(h);
+
+ Image scaledImage = image.getScaledInstance((int)w,(int)h,Image.SCALE_DEFAULT);
+
+ return scaledImage;
+ }
+
+ /**
+ * Resizes an icon by a scale factor, keeping aspect ratio unchanged.
+ * @param icon the image to resize
+ * @param scaleFactor the factor to rescale with
+ */
+ public static ImageIcon scaleImage(ImageIcon icon, double scaleFactor) {
+ Image scaledImage = scaleImage(icon.getImage(),scaleFactor);
+ return new ImageIcon(scaledImage);
+ }
+
+ /**
+ * Resizes a {@link JCheckBox} by scale factor. This method only scales
+ * the checkbox icon and not the checkbox text. The method assumes that the
+ * checkbox text is resized independently, e.g. generally by {@link #increaseUIFontSize(double)}.
+ * @param cb checkbox to resize
+ * @param scaleFactor factor to resize with
+ */
+ public static void scaleCheckBox(JCheckBox cb, double scaleFactor) {
+ cb.setIcon( SwingUtil.scaleImage(SwingUtil.ICON_CHECKBOX_UNCHECKED, scaleFactor) );
+ cb.setSelectedIcon( SwingUtil.scaleImage(SwingUtil.ICON_CHECKBOX_CHECKED, scaleFactor) );
+ cb.setDisabledIcon( SwingUtil.scaleImage(SwingUtil.ICON_CHECKBOX_DISABLED_UNCHECKED, scaleFactor) );
+ cb.setDisabledSelectedIcon( SwingUtil.scaleImage(SwingUtil.ICON_CHECKBOX_DISABLED_CHECKED, scaleFactor) );
+ }
/**
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/checked.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/checked.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/disabled_checked.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/disabled_checked.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/disabled_unchecked.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/disabled_unchecked.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/unchecked.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/checkbox/unchecked.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
More information about the Schmitzm-commits
mailing list