-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSample.java
More file actions
131 lines (111 loc) · 3.54 KB
/
Sample.java
File metadata and controls
131 lines (111 loc) · 3.54 KB
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
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.event.*;
import net.ericaro.surfaceplotter.DefaultSurfaceModel;
import net.ericaro.surfaceplotter.JSurfacePanel;
import net.ericaro.surfaceplotter.Mapper;
import net.ericaro.surfaceplotter.ProgressiveSurfaceModel;
import net.ericaro.surfaceplotter.surface.SurfaceUtils;
/**
* @author User #1
*/
public class Sample extends JPanel {
private ProgressiveSurfaceModel model;
public Sample() {
initComponents();
//DefaultSurfaceModel model = new DefaultSurfaceModel();
model = new ProgressiveSurfaceModel() ;
surfacePanel1.setModel(model);
model.setMapper(new Mapper() {
public float f1( float x, float y)
{
float r = x*x+y*y;
if (r == 0 ) return 1f;
return (float)( Math.sin(r)/(r));
}
public float f2( float x, float y)
{
return (float)(Math.sin(x*y));
}
});
model.plot().execute();
}
private void button1ActionPerformed() {
JFileChooser jfc = new JFileChooser();
try {
if (jfc.showSaveDialog(surfacePanel1) == JFileChooser.APPROVE_OPTION )
SurfaceUtils.doExportSVG(surfacePanel1.getSurface(), jfc.getSelectedFile());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Sample sample = new Sample();
JFrame jf = new JFrame("sample");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.getContentPane().add(sample);
jf.pack();
jf.setVisible(true);
}
private void slider1StateChanged(ChangeEvent e) {
if (!slider1.getValueIsAdjusting())
model.setCurrentDefinition(slider1.getValue());
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
surfacePanel1 = new JSurfacePanel();
toolBar1 = new JToolBar();
button1 = new JButton();
slider1 = new JSlider();
//======== this ========
setLayout(new BorderLayout());
//---- surfacePanel1 ----
surfacePanel1.setTitleText("title");
surfacePanel1.setBackground(Color.white);
surfacePanel1.setTitleFont(surfacePanel1.getTitleFont().deriveFont(surfacePanel1.getTitleFont().getStyle() | Font.BOLD, surfacePanel1.getTitleFont().getSize() + 6f));
surfacePanel1.setConfigurationVisible(false);
add(surfacePanel1, BorderLayout.CENTER);
//======== toolBar1 ========
{
//---- button1 ----
button1.setText("export SVG");
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button1ActionPerformed();
}
});
toolBar1.add(button1);
//---- slider1 ----
slider1.setMaximum(6);
slider1.setValue(0);
slider1.setPaintTicks(true);
slider1.setSnapToTicks(true);
slider1.setMinorTickSpacing(1);
slider1.setMajorTickSpacing(1);
slider1.setPaintLabels(true);
slider1.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
slider1StateChanged(e);
}
});
toolBar1.add(slider1);
}
add(toolBar1, BorderLayout.NORTH);
// JFormDesigner - End of component initialization //GEN-END:initComponents
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
private JSurfacePanel surfacePanel1;
private JToolBar toolBar1;
private JButton button1;
private JSlider slider1;
// JFormDesigner - End of variables declaration //GEN-END:variables
}