1 /*
2 * Copyright 2009 - 2010 JEuclid, http://jeuclid.sf.net
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /* $Id $ */
18
19 package net.sourceforge.jeuclid.app.mathviewer;
20
21 // CHECKSTYLE:OFF
22 public class InsertTableDialog extends javax.swing.JDialog {
23 // CHECKSTYLE:OFF
24 private String mathMLText;
25
26 /** Creates new form InsertTableDialog */
27 public InsertTableDialog(final java.awt.Frame parent, final boolean modal) {
28 super(parent, modal);
29 this.initComponents();
30 }
31
32 /**
33 * This method is called from within the constructor to initialize the form.
34 * WARNING: Do NOT modify this code. The content of this method is always
35 * regenerated by the Form Editor.
36 */
37 @SuppressWarnings("unchecked")
38 // <editor-fold defaultstate="collapsed"
39 // desc="Generated Code">//GEN-BEGIN:initComponents
40 private void initComponents() {
41
42 this.buttonGroupType = new javax.swing.ButtonGroup();
43 this.tableRadioButton = new javax.swing.JRadioButton();
44 this.matrixRadioButton = new javax.swing.JRadioButton();
45 this.determinantRadioButton = new javax.swing.JRadioButton();
46 this.cancelButton = new javax.swing.JButton();
47 this.okButton = new javax.swing.JButton();
48 this.columnsLabel = new javax.swing.JLabel();
49 this.rowsSpinner = new javax.swing.JSpinner();
50 this.columnsSpinner = new javax.swing.JSpinner();
51 this.typeLabel = new javax.swing.JLabel();
52 this.rowsLabel = new javax.swing.JLabel();
53
54 this
55 .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
56
57 this.buttonGroupType.add(this.tableRadioButton);
58 this.tableRadioButton.setText("Tabelle");
59
60 this.buttonGroupType.add(this.matrixRadioButton);
61 this.matrixRadioButton.setSelected(true);
62 this.matrixRadioButton.setText("Matrix");
63
64 this.buttonGroupType.add(this.determinantRadioButton);
65 this.determinantRadioButton.setText("Determinante");
66
67 this.cancelButton.setText("Abbrechen");
68 this.cancelButton
69 .addActionListener(new java.awt.event.ActionListener() {
70 public void actionPerformed(
71 final java.awt.event.ActionEvent evt) {
72 InsertTableDialog.this.cancelButtonActionPerformed(evt);
73 }
74 });
75
76 this.okButton.setText("OK");
77 this.okButton.addActionListener(new java.awt.event.ActionListener() {
78 public void actionPerformed(final java.awt.event.ActionEvent evt) {
79 InsertTableDialog.this.okButtonActionPerformed(evt);
80 }
81 });
82
83 this.columnsLabel.setText("Spalten");
84
85 this.rowsSpinner.setModel(new javax.swing.SpinnerNumberModel(3, 1, 99,
86 1));
87
88 this.columnsSpinner.setModel(new javax.swing.SpinnerNumberModel(3, 1,
89 99, 1));
90
91 this.typeLabel.setText("Typ");
92
93 this.rowsLabel.setText("Zeilen");
94
95 final javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this
96 .getContentPane());
97 this.getContentPane().setLayout(layout);
98 layout
99 .setHorizontalGroup(layout
100 .createParallelGroup(
101 javax.swing.GroupLayout.Alignment.LEADING)
102 .addGroup(
103 layout
104 .createSequentialGroup()
105 .addGroup(
106 layout
107 .createParallelGroup(
108 javax.swing.GroupLayout.Alignment.LEADING)
109 .addGroup(
110 layout
111 .createSequentialGroup()
112 .addGap(
113 24,
114 24,
115 24)
116 .addComponent(
117 this.typeLabel)
118 .addGap(
119 18,
120 18,
121 18)
122 .addGroup(
123 layout
124 .createParallelGroup(
125 javax.swing.GroupLayout.Alignment.LEADING)
126 .addComponent(
127 this.tableRadioButton)
128 .addComponent(
129 this.matrixRadioButton)
130 .addComponent(
131 this.determinantRadioButton)))
132 .addGroup(
133 layout
134 .createSequentialGroup()
135 .addGap(
136 24,
137 24,
138 24)
139 .addComponent(
140 this.rowsLabel)
141 .addGap(
142 14,
143 14,
144 14)
145 .addComponent(
146 this.rowsSpinner,
147 javax.swing.GroupLayout.PREFERRED_SIZE,
148 javax.swing.GroupLayout.DEFAULT_SIZE,
149 javax.swing.GroupLayout.PREFERRED_SIZE)
150 .addGap(
151 18,
152 18,
153 18)
154 .addComponent(
155 this.columnsLabel)
156 .addPreferredGap(
157 javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
158 .addComponent(
159 this.columnsSpinner,
160 javax.swing.GroupLayout.PREFERRED_SIZE,
161 javax.swing.GroupLayout.DEFAULT_SIZE,
162 javax.swing.GroupLayout.PREFERRED_SIZE))
163 .addGroup(
164 layout
165 .createSequentialGroup()
166 .addGap(
167 39,
168 39,
169 39)
170 .addComponent(
171 this.okButton,
172 javax.swing.GroupLayout.PREFERRED_SIZE,
173 93,
174 javax.swing.GroupLayout.PREFERRED_SIZE)
175 .addPreferredGap(
176 javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
177 .addComponent(
178 this.cancelButton)))
179 .addContainerGap(44, Short.MAX_VALUE)));
180 layout
181 .setVerticalGroup(layout
182 .createParallelGroup(
183 javax.swing.GroupLayout.Alignment.LEADING)
184 .addGroup(
185 layout
186 .createSequentialGroup()
187 .addGap(25, 25, 25)
188 .addGroup(
189 layout
190 .createParallelGroup(
191 javax.swing.GroupLayout.Alignment.BASELINE)
192 .addComponent(
193 this.rowsLabel)
194 .addComponent(
195 this.columnsLabel)
196 .addComponent(
197 this.rowsSpinner,
198 javax.swing.GroupLayout.PREFERRED_SIZE,
199 javax.swing.GroupLayout.DEFAULT_SIZE,
200 javax.swing.GroupLayout.PREFERRED_SIZE)
201 .addComponent(
202 this.columnsSpinner,
203 javax.swing.GroupLayout.PREFERRED_SIZE,
204 javax.swing.GroupLayout.DEFAULT_SIZE,
205 javax.swing.GroupLayout.PREFERRED_SIZE))
206 .addGap(18, 18, 18)
207 .addGroup(
208 layout
209 .createParallelGroup(
210 javax.swing.GroupLayout.Alignment.BASELINE)
211 .addComponent(
212 this.typeLabel)
213 .addComponent(
214 this.matrixRadioButton))
215 .addPreferredGap(
216 javax.swing.LayoutStyle.ComponentPlacement.RELATED)
217 .addComponent(this.tableRadioButton)
218 .addPreferredGap(
219 javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
220 .addComponent(
221 this.determinantRadioButton)
222 .addGap(18, 18, 18)
223 .addGroup(
224 layout
225 .createParallelGroup(
226 javax.swing.GroupLayout.Alignment.BASELINE)
227 .addComponent(
228 this.cancelButton)
229 .addComponent(
230 this.okButton))
231 .addContainerGap(
232 javax.swing.GroupLayout.DEFAULT_SIZE,
233 Short.MAX_VALUE)));
234
235 this.pack();
236 }// </editor-fold>//GEN-END:initComponents
237
238 private void cancelButtonActionPerformed(
239 final java.awt.event.ActionEvent evt) {// GEN-FIRST:event_cancelButtonActionPerformed
240 this.mathMLText = null;
241 this.setVisible(false);
242 }// GEN-LAST:event_cancelButtonActionPerformed
243
244 public String getMathMLText() {
245 return this.mathMLText;
246 }
247
248 private void okButtonActionPerformed(final java.awt.event.ActionEvent evt) {// GEN-FIRST:event_okButtonActionPerformed
249
250 this.updateMathMLText();
251 this.setVisible(false);
252 }// GEN-LAST:event_okButtonActionPerformed
253
254 private String buildText(final int lines, final int columns,
255 final String type) {
256 // String s = "<" + type + ">" + Helper.nl();
257 String s = "<mrow>" + Helper.nl() + "<mfenced" + type + ">"
258 + Helper.nl() + "<mtable>" + Helper.nl();
259
260 for (int i = 0; i < lines; ++i) {
261 // s += "<matrixrow>" + Helper.nl();
262 s += "<mtr>" + Helper.nl();
263 for (int j = 0; j < columns; ++j) {
264 s += "<mtd><mn>1</mn></mtd>" + Helper.nl();
265 // s+="\t<cn>1</cn>" + Helper.nl();
266 }
267 // s+= "</matrixrow>" + Helper.nl();
268 s += "</mtr>" + Helper.nl();
269 }
270 // s+="</" + type + ">" + Helper.nl();
271 s += "</mtable>" + Helper.nl() + "</mfenced>" + Helper.nl() + "</mrow>"
272 + Helper.nl();
273 return s;
274 }
275
276 private void updateMathMLText() {
277 final int m = (Integer) this.rowsSpinner.getValue();
278 final int n = (Integer) this.columnsSpinner.getValue();
279
280 // matrix
281 if (this.matrixRadioButton.isSelected()) {
282 this.mathMLText = this.buildText(m, n, "");
283 } else if (this.determinantRadioButton.isSelected()) {
284 this.mathMLText = this.buildText(m, n, " open=\"|\" close=\"|\"");
285 } else if (this.tableRadioButton.isSelected()) {
286 this.mathMLText = this.buildText(m, n, " open=\"\" close=\"\"");
287 } else {
288 this.mathMLText = null;
289 }
290 }
291
292 /**
293 * @param args
294 * the command line arguments
295 */
296 public static void main(final String args[]) {
297 java.awt.EventQueue.invokeLater(new Runnable() {
298 public void run() {
299 final InsertTableDialog dialog = new InsertTableDialog(
300 new javax.swing.JFrame(), true);
301 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
302 @Override
303 public void windowClosing(final java.awt.event.WindowEvent e) {
304 System.exit(0);
305 }
306 });
307 dialog.setVisible(true);
308 }
309 });
310 }
311
312 // Variables declaration - do not modify//GEN-BEGIN:variables
313 private javax.swing.ButtonGroup buttonGroupType;
314 private javax.swing.JButton cancelButton;
315 private javax.swing.JLabel columnsLabel;
316 private javax.swing.JSpinner columnsSpinner;
317 private javax.swing.JRadioButton determinantRadioButton;
318 private javax.swing.JRadioButton matrixRadioButton;
319 private javax.swing.JButton okButton;
320 private javax.swing.JLabel rowsLabel;
321 private javax.swing.JSpinner rowsSpinner;
322 private javax.swing.JRadioButton tableRadioButton;
323 private javax.swing.JLabel typeLabel;
324 // End of variables declaration//GEN-END:variables
325
326 }