1 | /* |
---|
2 | * This program is free software; you can redistribute it and/or modify |
---|
3 | * it under the terms of the GNU General Public License as published by |
---|
4 | * the Free Software Foundation; either version 2 of the License, or |
---|
5 | * (at your option) any later version. |
---|
6 | * |
---|
7 | * This program is distributed in the hope that it will be useful, |
---|
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
10 | * GNU General Public License for more details. |
---|
11 | * |
---|
12 | * You should have received a copy of the GNU General Public License |
---|
13 | * along with this program; if not, write to the Free Software |
---|
14 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
15 | */ |
---|
16 | |
---|
17 | /* |
---|
18 | * PrintablePanel.java |
---|
19 | * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand |
---|
20 | * |
---|
21 | */ |
---|
22 | |
---|
23 | package weka.gui.visualize; |
---|
24 | |
---|
25 | import java.util.Hashtable; |
---|
26 | |
---|
27 | import javax.swing.JPanel; |
---|
28 | |
---|
29 | /** |
---|
30 | * This Panel enables the user to print the panel to various file formats. |
---|
31 | * The Print dialog is accessible via Ctrl-Shft-Left Mouse Click. <p> |
---|
32 | * The individual JComponentWriter-descendants can be accessed by the |
---|
33 | * <code>getWriter(String)</code> method, if the parameters need to be changed. |
---|
34 | * |
---|
35 | * @see #getWriters() |
---|
36 | * @see #getWriter(String) |
---|
37 | * @author FracPete (fracpete at waikato dot ac dot nz) |
---|
38 | * @version $Revision: 1.3 $ |
---|
39 | */ |
---|
40 | public class PrintablePanel |
---|
41 | extends JPanel |
---|
42 | implements PrintableHandler { |
---|
43 | |
---|
44 | /** for serialization */ |
---|
45 | private static final long serialVersionUID = 6281532227633417538L; |
---|
46 | |
---|
47 | /** the class responsible for printing */ |
---|
48 | protected PrintableComponent m_Printer = null; |
---|
49 | |
---|
50 | /** |
---|
51 | * initializes the panel |
---|
52 | */ |
---|
53 | public PrintablePanel() { |
---|
54 | super(); |
---|
55 | m_Printer = new PrintableComponent(this); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * returns a Hashtable with the current available JComponentWriters in the |
---|
60 | * save dialog. the key of the Hashtable is the description of the writer. |
---|
61 | * |
---|
62 | * @return all currently available JComponentWriters |
---|
63 | * @see JComponentWriter#getDescription() |
---|
64 | */ |
---|
65 | public Hashtable getWriters() { |
---|
66 | return m_Printer.getWriters(); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * returns the JComponentWriter associated with the given name, is |
---|
71 | * <code>null</code> if not found |
---|
72 | * |
---|
73 | * @return the writer associated with the given name |
---|
74 | * @see JComponentWriter#getDescription() |
---|
75 | */ |
---|
76 | public JComponentWriter getWriter(String name) { |
---|
77 | return m_Printer.getWriter(name); |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * sets the title for the save dialog |
---|
82 | */ |
---|
83 | public void setSaveDialogTitle(String title) { |
---|
84 | m_Printer.setSaveDialogTitle(title); |
---|
85 | } |
---|
86 | |
---|
87 | /** |
---|
88 | * returns the title for the save dialog |
---|
89 | */ |
---|
90 | public String getSaveDialogTitle() { |
---|
91 | return m_Printer.getSaveDialogTitle(); |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * sets the scale factor |
---|
96 | * @param x the scale factor for the x-axis |
---|
97 | * @param y the scale factor for the y-axis |
---|
98 | */ |
---|
99 | public void setScale(double x, double y) { |
---|
100 | m_Printer.setScale(x, y); |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | * returns the scale factor for the x-axis |
---|
105 | */ |
---|
106 | public double getXScale() { |
---|
107 | return m_Printer.getXScale(); |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * returns the scale factor for the y-axis |
---|
112 | */ |
---|
113 | public double getYScale() { |
---|
114 | return m_Printer.getYScale(); |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | * displays a save dialog for saving the panel to a file. |
---|
119 | */ |
---|
120 | public void saveComponent() { |
---|
121 | m_Printer.saveComponent(); |
---|
122 | } |
---|
123 | } |
---|