1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.app.mathviewer;
20
21
22 public class InsertPolynomDialog extends javax.swing.JDialog {
23
24
25
26
27 private String mathMLText;
28
29
30 public InsertPolynomDialog(final java.awt.Frame parent, final boolean modal) {
31 super(parent, modal);
32 this.initComponents();
33 }
34
35
36
37
38
39
40 @SuppressWarnings("unchecked")
41
42
43 private void initComponents() {
44
45 this.cancelButton = new javax.swing.JButton();
46 this.okButton = new javax.swing.JButton();
47 this.degreeSpinner = new javax.swing.JSpinner();
48 this.degreeLabel = new javax.swing.JLabel();
49
50 this
51 .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
52
53 this.cancelButton.setText("Abbrechen");
54 this.cancelButton
55 .addActionListener(new java.awt.event.ActionListener() {
56 public void actionPerformed(
57 final java.awt.event.ActionEvent evt) {
58 InsertPolynomDialog.this
59 .cancelButtonActionPerformed(evt);
60 }
61 });
62
63 this.okButton.setText("OK");
64 this.okButton.addActionListener(new java.awt.event.ActionListener() {
65 public void actionPerformed(final java.awt.event.ActionEvent evt) {
66 InsertPolynomDialog.this.okButtonActionPerformed(evt);
67 }
68 });
69
70 this.degreeSpinner.setModel(new javax.swing.SpinnerNumberModel(3, 0,
71 25, 1));
72
73 this.degreeLabel.setText("Grad");
74
75 final javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this
76 .getContentPane());
77 this.getContentPane().setLayout(layout);
78 layout
79 .setHorizontalGroup(layout
80 .createParallelGroup(
81 javax.swing.GroupLayout.Alignment.LEADING)
82 .addGroup(
83 layout
84 .createSequentialGroup()
85 .addGap(24, 24, 24)
86 .addGroup(
87 layout
88 .createParallelGroup(
89 javax.swing.GroupLayout.Alignment.LEADING)
90 .addGroup(
91 layout
92 .createSequentialGroup()
93 .addGap(
94 10,
95 10,
96 10)
97 .addComponent(
98 this.okButton,
99 javax.swing.GroupLayout.PREFERRED_SIZE,
100 93,
101 javax.swing.GroupLayout.PREFERRED_SIZE)
102 .addGap(
103 18,
104 18,
105 18)
106 .addComponent(
107 this.cancelButton))
108 .addGroup(
109 layout
110 .createSequentialGroup()
111 .addGap(
112 11,
113 11,
114 11)
115 .addComponent(
116 this.degreeLabel)
117 .addPreferredGap(
118 javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
119 .addComponent(
120 this.degreeSpinner,
121 javax.swing.GroupLayout.PREFERRED_SIZE,
122 javax.swing.GroupLayout.DEFAULT_SIZE,
123 javax.swing.GroupLayout.PREFERRED_SIZE)))
124 .addGap(41, 41, 41)));
125 layout
126 .setVerticalGroup(layout
127 .createParallelGroup(
128 javax.swing.GroupLayout.Alignment.LEADING)
129 .addGroup(
130 layout
131 .createSequentialGroup()
132 .addGap(25, 25, 25)
133 .addGroup(
134 layout
135 .createParallelGroup(
136 javax.swing.GroupLayout.Alignment.BASELINE)
137 .addComponent(
138 this.degreeLabel)
139 .addComponent(
140 this.degreeSpinner,
141 javax.swing.GroupLayout.PREFERRED_SIZE,
142 javax.swing.GroupLayout.DEFAULT_SIZE,
143 javax.swing.GroupLayout.PREFERRED_SIZE))
144 .addGap(18, 18, 18)
145 .addGroup(
146 layout
147 .createParallelGroup(
148 javax.swing.GroupLayout.Alignment.BASELINE)
149 .addComponent(
150 this.cancelButton)
151 .addComponent(
152 this.okButton))
153 .addContainerGap(
154 javax.swing.GroupLayout.DEFAULT_SIZE,
155 Short.MAX_VALUE)));
156
157 this.pack();
158 }
159
160 private void cancelButtonActionPerformed(
161 final java.awt.event.ActionEvent evt) {
162 this.mathMLText = null;
163 this.setVisible(false);
164 }
165
166 public String getMathMLText() {
167 return this.mathMLText;
168 }
169
170 private void okButtonActionPerformed(final java.awt.event.ActionEvent evt) {
171
172 this.updateMathMLText();
173 this.setVisible(false);
174 }
175
176 private void updateMathMLText() {
177 final int degree = (Integer) this.degreeSpinner.getValue();
178
179 String s = "";
180 char c = 'a';
181 for (int i = degree; i >= 0; --i) {
182 s += "<mi>" + c + "</mi>" + Helper.nl();
183
184 if (i > 0) {
185 if (i != 1) {
186 s += "<msup><mi>x</mi><mn>" + i + "</mn></msup>"
187 + Helper.nl();
188 } else {
189 s += "<mi>x</mi>" + Helper.nl();
190 }
191 s += "<mo>+</mo>" + Helper.nl();
192 }
193 c++;
194 }
195 this.mathMLText = s;
196 }
197
198
199
200
201
202 public static void main(final String args[]) {
203 java.awt.EventQueue.invokeLater(new Runnable() {
204 public void run() {
205 final InsertPolynomDialog dialog = new InsertPolynomDialog(
206 new javax.swing.JFrame(), true);
207 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
208 @Override
209 public void windowClosing(final java.awt.event.WindowEvent e) {
210 System.exit(0);
211 }
212 });
213 dialog.setVisible(true);
214 }
215 });
216 }
217
218
219 private javax.swing.JButton cancelButton;
220 private javax.swing.JLabel degreeLabel;
221 private javax.swing.JSpinner degreeSpinner;
222 private javax.swing.JButton okButton;
223
224
225 }