01: /*
02: * SvgRocker.java
03: *
04: * Created on 19 April 2007, 10:06
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package com.xoetrope.svgcomponentswizard;
11:
12: import java.awt.Color;
13: import java.awt.event.ComponentAdapter;
14: import java.awt.event.ComponentEvent;
15: import net.xoetrope.optional.svg.XSvgButton;
16: import net.xoetrope.swing.XPanel;
17: import net.xoetrope.xui.XPage;
18: import net.xoetrope.xui.XPageManager;
19: import net.xoetrope.xui.XProjectManager;
20:
21: /**
22: *
23: * @author kingsley.elmes
24: */
25: public class SvgRocker extends XPage {
26: protected XSvgButton svgRocker;
27: protected XPanel rockerPanel, buttonPanel;
28: protected int x, y, rockerWidth, rockerHeight;
29:
30: /**
31: * Creates a new instance of SvgRocker
32: */
33: public SvgRocker() {
34: }
35:
36: /**
37: * Set-up rocker component and add component listener to rocker panel.
38: */
39: public void pageCreated() {
40: rockerPanel = (XPanel) findComponent("rockerPanel");
41: rockerPanel.setBackground(Color.white);
42:
43: buttonPanel = (XPanel) findComponent("buttonPanel");
44: buttonPanel.setBackground(Color.white);
45:
46: svgRocker = new XSvgButton();
47: rockerPanel.add(svgRocker);
48: svgRocker.setOpaque(false);
49: svgRocker.setImage(project.findResource("rocker.svg"));
50:
51: String[][] ids = { { "rocker", "border_over", null },
52: { "north", "rollover_north", "pressed_north" },
53: { "south", "rollover_south", "pressed_south" },
54: { "east", "rollover_east", "pressed_east" },
55: { "west", "rollover_west", "pressed_west" }, };
56: svgRocker.setElementIds(ids);
57:
58: // If the rocker panel is resized update the position of the svg rocker.
59: rockerPanel.addComponentListener(new ComponentAdapter() {
60: public void componentResized(ComponentEvent evt) {
61: int height = rockerPanel.getHeight();
62: int width = rockerPanel.getWidth();
63:
64: if (svgRocker.getWidth() == 0
65: && svgRocker.getHeight() == 0) {
66: rockerWidth = height;
67: rockerHeight = height;
68: } else {
69: if (width < height) {
70: rockerWidth = width;
71: rockerHeight = width;
72: } else {
73: rockerWidth = height;
74: rockerHeight = height;
75: }
76: }
77:
78: if (height < width) {
79: x = (width - rockerWidth) / 2;
80: width = height;
81: } else {
82: y = (height - rockerHeight) / 2;
83: height = width;
84: }
85:
86: svgRocker.setBounds(x, y, width, height);
87: }
88: });
89: }
90:
91: /**
92: * Show welcome page if back button is pressed.
93: */
94: public void showPage() {
95: XPageManager pageMgr = XProjectManager.getPageManager();
96: pageMgr.showPage("Welcome");
97: }
98: }
|