-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaperf.java
281 lines (241 loc) · 7.38 KB
/
Paperf.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package graph;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.JToggleButton;
import javax.swing.border.EmptyBorder;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.JToolBar;
import javax.swing.JPopupMenu;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;
public class Paperf extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
public static JLabel txtXvalue ,txtYvalue;
Paper panel;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Paperf frame = new Paperf();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Paperf() {
/////////
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(0,5, 1406, 739);
getContentPane().setLayout(null);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
setVisible(true);
panel = new Paper();
panel.setBounds(15, 15, 1080, 600);
panel.addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent zm) {
if(panel.zoom>=10)
panel.zoom-=zm.getWheelRotation()*10;
else {
panel.zoom=10;
}
panel.repaint();
}
});
contentPane.setLayout(null);
contentPane.add(panel);
JPanel panel_1 = new JPanel();
panel_1.setBounds(1105, 15, 252, 600);
contentPane.add(panel_1);
panel_1.setLayout(null);
JLabel lblFunc = new JLabel("Function");
lblFunc.setFont(new Font("Segoe UI", Font.PLAIN, 20));
lblFunc.setBounds(10, 11, 232, 58);
panel_1.add(lblFunc);
txtXvalue = new JLabel();
txtXvalue.setBounds(59, 116, 86, 20);
panel_1.add(txtXvalue);
txtYvalue = new JLabel();
txtYvalue.setBounds(59, 146, 86, 20);
panel_1.add(txtYvalue);
JLabel lblY = new JLabel("Y =");
lblY.setBounds(10, 152, 46, 14);
panel_1.add(lblY);
JLabel lblX = new JLabel("X =");
lblX.setBounds(10, 122, 46, 14);
panel_1.add(lblX);
JLabel lblCoordinates = new JLabel("Coordinates");
lblCoordinates.setBounds(31, 177, 96, 14);
panel_1.add(lblCoordinates);
JButton btnReset = new JButton("Reset");
btnReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ereset) {
panel.func=0;
panel.repaint();
}
});
btnReset.setBounds(20, 271, 86, 23);
panel_1.add(btnReset);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu mnFile = new JMenu("File");
menuBar.add(mnFile);
JMenuItem mntmImportCsv = new JMenuItem("Import CSV");
mntmImportCsv.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ecsv) {
//new CSVreader();
}
});
mnFile.add(mntmImportCsv);
JMenu mnNewMenu = new JMenu("Create");
menuBar.add(mnNewMenu);
JMenu mnfunc = new JMenu("Function");
mnNewMenu.add(mnfunc);
JMenuItem mntmYSine = new JMenuItem("y = sin(x)");
mntmYSine.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent esin) {
panel.func =1;
panel.repaint();
lblFunc.setText("y = sin(x)");
}
});
mnfunc.add(mntmYSine);
JMenuItem mntmYCos = new JMenuItem("y = cos(x)");
mntmYCos.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ecos) {
panel.func =2;
panel.repaint();
lblFunc.setText("y = cos(x)");
}
});
mnfunc.add(mntmYCos);
JMenuItem mntmYTan = new JMenuItem("y = tan(x)");
mntmYTan.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent etan) {
panel.func =3;
panel.repaint();
lblFunc.setText("y = tan(x)");
}
});
mnfunc.add(mntmYTan);
JMenuItem mntmYLog = new JMenuItem("y = log(x)");
mntmYLog.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent elog) {
panel.func =4;
panel.repaint();
lblFunc.setText("y = log(x)");
}
});
mnfunc.add(mntmYLog);
JMenuItem mntmYSin2 = new JMenuItem("y = sin^2(x)");
mntmYSin2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent esin2) {
panel.func =5;
panel.repaint();
lblFunc.setText("y = sin^2(x)");
}
});
mnfunc.add(mntmYSin2);
JMenuItem mntmCharts = new JMenuItem("Charts");
mntmCharts.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Chart chart = new Chart();
}
});
mnNewMenu.add(mntmCharts);
JMenuItem mntmPaint = new JMenuItem("Paint");
mntmPaint.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
mnNewMenu.add(mntmPaint);
JMenu mnGraph = new JMenu("Properties");
menuBar.add(mnGraph);
JToggleButton tglinvert = new JToggleButton("Invert");
mnGraph.add(tglinvert);
tglinvert.setSelected(panel.invert);
JPopupMenu popupMenu = new JPopupMenu();
addPopup(panel, popupMenu);
JToggleButton tglcursor = new JToggleButton();
tglcursor.setHorizontalAlignment(SwingConstants.LEFT);
tglcursor.setFont(new Font("Tahoma", Font.PLAIN, 13));
tglcursor.setSelected(panel.highlightCursor);
if(tglcursor.isSelected())
tglcursor.setText("Cursor ON");
else
tglcursor.setText("Cursor OFF");
tglcursor.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
panel.highlightCursor= tglcursor.isSelected();
if(tglcursor.isSelected())
tglcursor.setText("Cursor ON");
else
tglcursor.setText("Cursor OFF");
}
});
popupMenu.add(tglcursor);
JToggleButton toggleButton = new JToggleButton("Invert");
toggleButton.setSelected(false);
//popupMenu.add(tglinvert);
//popupMenu.add(btnReset);
JMenu mnCntrl = new JMenu("Controls");
menuBar.add(mnCntrl);
JMenuItem mntmZoomMouse = new JMenuItem("Zoom : Mouse wheel rotation");
mnCntrl.add(mntmZoomMouse);
tglinvert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
panel.invert=tglinvert.isSelected();
panel.repaint();
}
});
}
private static void addPopup(Component component, final JPopupMenu popup) {
component.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
showMenu(e);
}
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
showMenu(e);
}
}
private void showMenu(MouseEvent e) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
});
}
}