001 /* 002 * Copyright 2009 - 2010 JEuclid, http://jeuclid.sf.net 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 /* $Id $ */ 018 019 package net.sourceforge.jeuclid.app.mathviewer; 020 021 // CHECKSTYLE:OFF 022 public class InsertPolynomDialog extends javax.swing.JDialog { 023 // CHECKSTYLE:OFF 024 /** 025 * Current mathML text. 026 */ 027 private String mathMLText; 028 029 /** Creates new form InsertTableDialog */ 030 public InsertPolynomDialog(final java.awt.Frame parent, final boolean modal) { 031 super(parent, modal); 032 this.initComponents(); 033 } 034 035 /** 036 * This method is called from within the constructor to initialize the form. 037 * WARNING: Do NOT modify this code. The content of this method is always 038 * regenerated by the Form Editor. 039 */ 040 @SuppressWarnings("unchecked") 041 // <editor-fold defaultstate="collapsed" 042 // desc="Generated Code">//GEN-BEGIN:initComponents 043 private void initComponents() { 044 045 this.cancelButton = new javax.swing.JButton(); 046 this.okButton = new javax.swing.JButton(); 047 this.degreeSpinner = new javax.swing.JSpinner(); 048 this.degreeLabel = new javax.swing.JLabel(); 049 050 this 051 .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 052 053 this.cancelButton.setText("Abbrechen"); 054 this.cancelButton 055 .addActionListener(new java.awt.event.ActionListener() { 056 public void actionPerformed( 057 final java.awt.event.ActionEvent evt) { 058 InsertPolynomDialog.this 059 .cancelButtonActionPerformed(evt); 060 } 061 }); 062 063 this.okButton.setText("OK"); 064 this.okButton.addActionListener(new java.awt.event.ActionListener() { 065 public void actionPerformed(final java.awt.event.ActionEvent evt) { 066 InsertPolynomDialog.this.okButtonActionPerformed(evt); 067 } 068 }); 069 070 this.degreeSpinner.setModel(new javax.swing.SpinnerNumberModel(3, 0, 071 25, 1)); 072 073 this.degreeLabel.setText("Grad"); 074 075 final javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this 076 .getContentPane()); 077 this.getContentPane().setLayout(layout); 078 layout 079 .setHorizontalGroup(layout 080 .createParallelGroup( 081 javax.swing.GroupLayout.Alignment.LEADING) 082 .addGroup( 083 layout 084 .createSequentialGroup() 085 .addGap(24, 24, 24) 086 .addGroup( 087 layout 088 .createParallelGroup( 089 javax.swing.GroupLayout.Alignment.LEADING) 090 .addGroup( 091 layout 092 .createSequentialGroup() 093 .addGap( 094 10, 095 10, 096 10) 097 .addComponent( 098 this.okButton, 099 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 }// </editor-fold>//GEN-END:initComponents 159 160 private void cancelButtonActionPerformed( 161 final java.awt.event.ActionEvent evt) {// GEN-FIRST:event_cancelButtonActionPerformed 162 this.mathMLText = null; 163 this.setVisible(false); 164 }// GEN-LAST:event_cancelButtonActionPerformed 165 166 public String getMathMLText() { 167 return this.mathMLText; 168 } 169 170 private void okButtonActionPerformed(final java.awt.event.ActionEvent evt) {// GEN-FIRST:event_okButtonActionPerformed 171 172 this.updateMathMLText(); 173 this.setVisible(false); 174 }// GEN-LAST:event_okButtonActionPerformed 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 * @param args 200 * the command line arguments 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 // Variables declaration - do not modify//GEN-BEGIN:variables 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 // End of variables declaration//GEN-END:variables 224 225 }