001: /*
002: * Magnification.java
003: *
004: * Created on 16 March 2007, 15:32
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: package com.xoetrope.svgcomponentswizard;
011:
012: import com.kitfox.svg.SVGDiagram;
013: import com.xoetrope.svg.XSvgImageMap;
014: import com.xoetrope.svg.XSvgMagnifyingGlass;
015: import com.xoetrope.svg.XSvgMagnifyingWindow;
016: import java.awt.BorderLayout;
017: import java.awt.Color;
018: import java.awt.Point;
019: import java.awt.event.MouseEvent;
020: import java.awt.event.MouseListener;
021: import java.awt.event.MouseMotionListener;
022: import javax.swing.BorderFactory;
023: import javax.swing.JComponent;
024: import net.xoetrope.swing.XApplet;
025: import net.xoetrope.swing.XComboBox;
026: import net.xoetrope.swing.XPanel;
027: import net.xoetrope.swing.XRadioButton;
028: import net.xoetrope.xui.XPage;
029: import net.xoetrope.xui.XPageManager;
030: import net.xoetrope.xui.XProjectManager;
031: import net.xoetrope.xui.data.XBaseModel;
032: import net.xoetrope.xui.data.XModel;
033:
034: /**
035: *
036: * @author kingsley.elmes
037: */
038: public class Magnification extends XPage implements
039: MouseMotionListener, MouseListener {
040: protected XPanel mainPanel, imageMapPanel;
041: protected XSvgImageMap imageMap;
042: protected XSvgMagnifyingWindow magWindow;
043: protected XSvgMagnifyingGlass magGlass;
044: protected XComboBox svgSelect;
045: protected XRadioButton glassButton, windowButton;
046: protected JComponent glassPane;
047: protected boolean finished, magGlassRunning, magWindowRunning;
048: protected int c;
049:
050: /** Creates a new instance of Magnification */
051: public Magnification() {
052: }
053:
054: /**
055: * Set-up magnifying glass and add mouse listeners to svg image map.
056: */
057: public void pageCreated() {
058: imageMapPanel = (XPanel) findComponent("imageMapPanel");
059: imageMap = (XSvgImageMap) findComponent("imageMap");
060: magWindow = (XSvgMagnifyingWindow) findComponent("magWindow");
061: svgSelect = (XComboBox) findComponent("svgSelect");
062: windowButton = (XRadioButton) findComponent("windowButton");
063: glassButton = (XRadioButton) findComponent("glassButton");
064: glassPane = (XPanel) findComponent("glassPane");
065:
066: windowButton.setFocusable(false);
067: glassButton.setFocusable(false);
068: svgSelect.setFocusable(false);
069: glassPane.setLayout(new BorderLayout());
070:
071: imageMap.addMouseMotionListener(this );
072: imageMap.addMouseListener(this );
073:
074: SVGDiagram diagram = imageMap.getSvgDiagram();
075:
076: magWindow.setBorder(BorderFactory.createLineBorder(Color.GRAY,
077: 2));
078: magWindow.setDiagram(diagram);
079: magWindow.setImageMap(imageMap);
080: magWindow.setScaleFactor(5.0F);
081: magWindowRunning = true;
082:
083: magGlass = new XSvgMagnifyingGlass();
084: magGlass.setDiagram(diagram);
085: magGlass.setImageMap(imageMap);
086: magGlass.setScaleFactor(5.0F);
087: magGlass.setRotational(true);
088: magGlassRunning = false;
089:
090: finished = true;
091: }
092:
093: /**
094: * Updates the displayed svg image with a differnt svg image.
095: */
096: public void drawSvg() {
097: if (finished) {
098: XBaseModel rootModel = (XBaseModel) XProjectManager
099: .getModel();
100: XModel m2 = (XModel) rootModel.get("svgs/"
101: + (svgSelect.getSelectedIndex() + 1));
102: String svgFile = (String) m2.getAttribValue(m2
103: .getAttribute("image"));
104:
105: imageMap.setURL(project.findResource(svgFile));
106: SVGDiagram diagram = imageMap.display();
107: imageMap.resetBuffer();
108: imageMap.resize();
109: imageMap.repaint();
110:
111: magWindow.setDiagram(diagram);
112: magGlass.setDiagram(diagram);
113: }
114: }
115:
116: /**
117: * Use the magnifying window for displaying the magnified svg.
118: */
119: public void selectWindow() {
120: magGlass.stopThreads();
121: glassPane.setVisible(false);
122: glassPane.remove(magGlass);
123: magWindow.setVisible(true);
124: magWindowRunning = true;
125: }
126:
127: /**
128: * Use the magnifying glass for displaying the magnified svg.
129: */
130: public void selectGlass() {
131: magWindow.setVisible(false);
132: magWindow.stopRenderer();
133: glassPane.add(magGlass);
134:
135: new Thread(magGlass).start();
136:
137: glassPane.setComponentZOrder(magGlass, 0);
138: glassPane.setVisible(true);
139:
140: magWindowRunning = false;
141: }
142:
143: /**
144: * Show the welcome page if the back button is pressed.
145: */
146: public void showPage() {
147: XPageManager pageMgr = XProjectManager.getPageManager();
148: pageMgr.showPage("Welcome");
149: }
150:
151: /**
152: * Pass the mouse dragged event to the mouseMoved method.
153: * @param e the passed <CODE>MouseEvent</CODE>.
154: */
155: public void mouseDragged(MouseEvent e) {
156: mouseMoved(e);
157: }
158:
159: /**
160: * Pass the current mouse location to the magnifictaion components.
161: * @param e the passed <CODE>MouseEvent</CODE>.
162: */
163: public void mouseMoved(MouseEvent e) {
164: if (magWindowRunning) {
165: magWindow.setZoomPoint(e.getPoint());
166: } else {
167: Point mouseLocation = new Point((int) (e.getPoint().getX()
168: + imageMapPanel.getX() + imageMap.getX()), (int) (e
169: .getPoint().getY()
170: + imageMapPanel.getY() + imageMap.getY()));
171: magGlass.setZoomPoint(e.getPoint(), mouseLocation);
172: }
173: }
174:
175: /**
176: * Run the fade-in animation on the magnifying glass if the mouse enters the svg image.
177: */
178: public void mouseEntered(MouseEvent e) {
179: magGlass.setAnimationMode(XSvgMagnifyingGlass.FADE_IN, 20F);
180: }
181:
182: /**
183: * Run the fade-out animation on the magnifying glass if the mouse exits the svg image.
184: */
185: public void mouseExited(MouseEvent e) {
186: magGlass.setAnimationMode(XSvgMagnifyingGlass.FADE_OUT, 10F);
187: }
188:
189: public void mouseClicked(MouseEvent e) {
190: }
191:
192: public void mousePressed(MouseEvent e) {
193: }
194:
195: public void mouseReleased(MouseEvent e) {
196: }
197: }
|