X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Futil%2FCmsLink.java;h=b18770f189f3959db89684938580aeb60da7009d;hb=a82653f31be99193d0e309521d724197860a3367;hp=7c51e2ead877c08ad1287b3fdf0059a038aded05;hpb=23362de6ff41f86c923dc9fa0034c97427bda99b;p=lgpl%2Fargeo-commons.git
diff --git a/org.argeo.cms.ui/src/org/argeo/cms/util/CmsLink.java b/org.argeo.cms.ui/src/org/argeo/cms/util/CmsLink.java
index 7c51e2ead..b18770f18 100644
--- a/org.argeo.cms.ui/src/org/argeo/cms/util/CmsLink.java
+++ b/org.argeo.cms.ui/src/org/argeo/cms/util/CmsLink.java
@@ -37,6 +37,7 @@ public class CmsLink implements CmsUiProvider {
private String image;
private MouseListener mouseListener;
+ private int horizontalAlignment = SWT.CENTER;
private int verticalAlignment = SWT.CENTER;
private String loggedInLabel = null;
@@ -65,29 +66,37 @@ public class CmsLink implements CmsUiProvider {
public void init() {
if (image != null) {
ImageData image = loadImage();
- imageWidth = image.width;
- imageHeight = image.height;
+ if (imageHeight == null && imageWidth == null) {
+ imageWidth = image.width;
+ imageHeight = image.height;
+ } else if (imageHeight == null) {
+ imageHeight = (imageWidth * image.height) / image.width;
+ } else if (imageWidth == null) {
+ imageWidth = (imageHeight * image.width) / image.height;
+ }
}
}
/** @return {@link Composite} with a single {@link Label} child. */
@Override
public Control createUi(final Composite parent, Node context) {
- if (image != null && (imageWidth == null || imageHeight == null)) {
- throw new CmsException("Image is not properly configured."
- + " Make sure bundleContext property is set and init() method has been called.");
- }
+// if (image != null && (imageWidth == null || imageHeight == null)) {
+// throw new CmsException("Image is not properly configured."
+// + " Make sure bundleContext property is set and init() method has been called.");
+// }
- Composite comp = new Composite(parent, SWT.BOTTOM);
+ Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(CmsUtils.noSpaceGridLayout());
Label link = new Label(comp, SWT.NONE);
link.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);
- GridData layoutData = new GridData(SWT.CENTER, verticalAlignment, true, true);
+ GridData layoutData = new GridData(horizontalAlignment, verticalAlignment, false, false);
if (image != null) {
- layoutData.heightHint = imageHeight;
+ if (imageHeight != null)
+ layoutData.heightHint = imageHeight;
if (label == null)
- layoutData.widthHint = imageWidth;
+ if (imageWidth != null)
+ layoutData.widthHint = imageWidth;
}
link.setLayoutData(layoutData);
@@ -123,8 +132,12 @@ public class CmsLink implements CmsUiProvider {
if (image != null) {
registerImageIfNeeded();
String imageLocation = RWT.getResourceManager().getLocation(image);
- labelText.append("");
+ labelText.append("");
}
@@ -250,4 +263,12 @@ public class CmsLink implements CmsUiProvider {
return !CurrentUser.isAnonymous();
}
+ public void setImageWidth(Integer imageWidth) {
+ this.imageWidth = imageWidth;
+ }
+
+ public void setImageHeight(Integer imageHeight) {
+ this.imageHeight = imageHeight;
+ }
+
}