KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > demo > MouseZoomDemo


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * ------------------
23  * MouseZoomDemo.java
24  * ------------------
25  * (C) Copyright 2002, by Viktor Rajewski and Contributors.
26  *
27  * Original Author: Viktor Rajewski;
28  * Contributor(s): David Gilbert (for Object Refinery Limited);
29  *
30  *
31  * Changes
32  * -------
33  * 12-Aug-2002 : Version 1, based on XYSeriesDemo (VR);
34  * 11-Oct-2002 : Renamed XYSeriesMouseZoomDemo --> MouseZoomDemo, altered layout, and fixed errors
35  * reported by Checkstyle (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 import java.awt.BorderLayout JavaDoc;
42 import java.awt.event.ItemEvent JavaDoc;
43 import java.awt.event.ItemListener JavaDoc;
44
45 import javax.swing.JCheckBox JavaDoc;
46 import javax.swing.JPanel JavaDoc;
47
48 import org.jfree.chart.ChartFactory;
49 import org.jfree.chart.ChartPanel;
50 import org.jfree.chart.JFreeChart;
51 import org.jfree.chart.plot.PlotOrientation;
52 import org.jfree.ui.ApplicationFrame;
53 import org.jfree.ui.RefineryUtilities;
54
55 /**
56  * A simple demo showing mouse zooming.
57  *
58  * @author Viktor Rajewski
59  */

60 public class MouseZoomDemo extends ApplicationFrame {
61
62     /** The chart panel. */
63     private ChartPanel chartPanel;
64
65     /** X zoom. */
66     private JCheckBox JavaDoc xzoom;
67
68     /** Y zoom. */
69     private JCheckBox JavaDoc yzoom;
70
71     /**
72      * A demonstration of mouse zooming.
73      *
74      * @param title the frame title.
75      */

76     public MouseZoomDemo(String JavaDoc title) {
77
78         super(title);
79         SampleXYDataset data = new SampleXYDataset();
80         JFreeChart chart = ChartFactory.createXYLineChart(
81             "Mouse Zoom Demo",
82             "X",
83             "Y",
84             data,
85             PlotOrientation.VERTICAL,
86             true,
87             true,
88             false
89         );
90
91         chartPanel = new ChartPanel(chart);
92         chartPanel.setHorizontalZoom(false);
93         chartPanel.setVerticalZoom(false);
94         chartPanel.setHorizontalAxisTrace(false);
95         chartPanel.setVerticalAxisTrace(false);
96         chartPanel.setFillZoomRectangle(true);
97         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
98
99         JPanel JavaDoc main = new JPanel JavaDoc(new BorderLayout JavaDoc());
100         JPanel JavaDoc checkpanel = new JPanel JavaDoc();
101         xzoom = new JCheckBox JavaDoc("Horizontal Mouse Zooming");
102         xzoom.setSelected(false);
103         yzoom = new JCheckBox JavaDoc("Vertical Mouse Zooming");
104         yzoom.setSelected(false);
105         CheckListener clisten = new CheckListener();
106         xzoom.addItemListener(clisten);
107         yzoom.addItemListener(clisten);
108         checkpanel.add(xzoom);
109         checkpanel.add(yzoom);
110         main.add(checkpanel, BorderLayout.SOUTH);
111         main.add(chartPanel);
112         setContentPane(main);
113
114     }
115
116     // ****************************************************************************
117
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
118
// * Please note that commercial support and documentation is available from: *
119
// * *
120
// * http://www.object-refinery.com/jfreechart/support.html *
121
// * *
122
// * This is not only a great service for developers, but is a VERY IMPORTANT *
123
// * source of funding for the JFreeChart project. Please support us so that *
124
// * we can continue developing free software. *
125
// ****************************************************************************
126

127     /**
128      * Starting point for the demonstration application.
129      *
130      * @param args ignored.
131      */

132     public static void main(String JavaDoc[] args) {
133
134         MouseZoomDemo demo = new MouseZoomDemo("Mouse Zoom Demo");
135         demo.pack();
136         RefineryUtilities.centerFrameOnScreen(demo);
137         demo.setVisible(true);
138
139     }
140
141     /**
142      * An item listener.
143      *
144      * @author VR
145      */

146     class CheckListener implements ItemListener JavaDoc {
147
148         /**
149          * Receives change events.
150          *
151          * @param e the event.
152          */

153         public void itemStateChanged(ItemEvent JavaDoc e) {
154             Object JavaDoc source = e.getItemSelectable();
155             if (source == xzoom) {
156                 if (e.getStateChange() == ItemEvent.DESELECTED) {
157                     chartPanel.setHorizontalZoom(false);
158                     chartPanel.setHorizontalAxisTrace(false);
159                     chartPanel.repaint();
160                 }
161                 else {
162                     chartPanel.setHorizontalZoom(true);
163                     chartPanel.setHorizontalAxisTrace(true);
164                 }
165             }
166             else if (source == yzoom) {
167                 if (e.getStateChange() == ItemEvent.DESELECTED) {
168                     chartPanel.setVerticalZoom(false);
169                     chartPanel.setVerticalAxisTrace(false);
170                     chartPanel.repaint();
171                 }
172                 else {
173                     chartPanel.setVerticalZoom(true);
174                     chartPanel.setVerticalAxisTrace(true);
175                 }
176             }
177        }
178     }
179
180 }
181
Popular Tags