Processing...
Description & Source Code

The Fisheye component takes images generated by Java graphical libraries.

dynamic_fisheye_menu.zul
<zk>
	<div style="padding:50px 30px">
		<fisheyebar id="fisheyebar" itemWidth="70" itemHeight="70" itemMaxHeight="120" itemMaxWidth="120" />
	</div>
</zk>
dynamic_fisheye_menu_ctrl.zul
<zk>
	<!-- Control Panel -->
	
	<vlayout apply="demo.menu.dynamic_fisheye_menu.DynamicFisheyeMenuConfigController">
		<hlayout spacing="20px" width="100%">
			<hlayout spacing="5px">
				Font Color :
				<colorbox id="fontColor" color="#008BB6" />
			</hlayout>
			<hlayout spacing="5px">
				Shadow Color :
				<colorbox id="shadowColor" color="#AAAAAA" />
			</hlayout>
			<hlayout spacing="5px">
				Rotation Angle :
				<radiogroup id="angle">
					<radio label="30 Degree" value="30" checked="true" />
					<radio label="-30 Degree" value="-30" />
				</radiogroup>
			</hlayout>
		</hlayout>
		<hlayout spacing="5px">
			Fisheye Text :
			<textbox id="fisheyeText" value="Framework" style="background:#FFFFCC" maxlength="10" />
		</hlayout>
	</vlayout>
</zk>
DynamicFisheyeMenuConfigController.java
package demo.menu.dynamic_fisheye_menu;

import java.awt.image.RenderedImage;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zkex.zul.Colorbox;
import org.zkoss.zkex.zul.Fisheye;
import org.zkoss.zkex.zul.Fisheyebar;
import org.zkoss.zul.Radiogroup;
import org.zkoss.zul.Textbox;

public class DynamicFisheyeMenuConfigController extends
		SelectorComposer<Component> {

	@Wire
	Fisheyebar fisheyebar;
	@Wire
	Textbox fisheyeText;
	@Wire
	Colorbox fontColor;
	@Wire
	Colorbox shadowColor;
	@Wire
	Radiogroup angle;

	private FisheyeRenderer fisheyeRenderer;

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		fisheyeRenderer = new FisheyeRenderer(180, 200) {
			@Override
			protected void onImageRendered(RenderedImage image) {
				Fisheye fisheye = new Fisheye();
				fisheye.setImageContent(image);
				fisheyebar.appendChild(fisheye);
			}
		};
		drawEye();
	}

	@Listen("onChange = #fontColor, #shadowColor, #fisheyeText; onOK = #fisheyeText; onCheck = #angle")
	public void onConfigChanged() {
		drawEye();
	}

	private void drawEye() {
		String drawText = fisheyeText.getValue().length() == 0 ? "ZK Rocks"
				: fisheyeText.getValue();
		double rotationAngle = Double.parseDouble((String) angle
				.getSelectedItem().getValue());

		fisheyebar.getChildren().clear();
		fisheyeRenderer.draw(drawText.length(), drawText, fontColor.getRGB(),
				shadowColor.getRGB(), rotationAngle);
	}
}
FisheyeRenderer.java
package demo.menu.dynamic_fisheye_menu;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;

public abstract class FisheyeRenderer {

	private Font font;
	private int imageSize;

	public FisheyeRenderer(int fontSize, int imageSize) {
		this.imageSize = imageSize;
		font = new Font("Courier New", Font.BOLD, fontSize);
	}

	public void draw(int leng, String name, int fontColor, int shadowColor, double angle) {
		AffineTransform transformation = AffineTransform.getTranslateInstance(imageSize / 2, imageSize / 2);
		transformation.rotate(angle / 360.0 * 2 * Math.PI);

		for(char letter : name.toCharArray()) {
			BufferedImage image = new BufferedImage(imageSize, imageSize, BufferedImage.TYPE_INT_ARGB);
			Graphics2D g2d = image.createGraphics();
			Rectangle2D bounds = font.getMaxCharBounds(g2d.getFontRenderContext());
			g2d.setTransform(transformation);
			g2d.setFont(font);
			g2d.setColor(new Color(shadowColor));
			g2d.drawString("" + letter, (int)-bounds.getWidth() / 4 + 10, (int)bounds.getHeight() / 4 + 5);
			g2d.setColor(new Color(fontColor));
			g2d.drawString("" + letter, (int)-bounds.getWidth() / 4, (int)bounds.getHeight() / 4);

			onImageRendered(image);
		}
	}
	
	protected abstract void onImageRendered(RenderedImage image);
}