/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package feuille.drawing.dialog;
import javax.swing.SpinnerNumberModel;
import feuille.lib.Language;
/**
*
* @author The Wingate 2940
*/
public class SelectGeoDialog extends javax.swing.JDialog {
private ButtonPressed bp;
private SpinnerNumberModel snmSide;
private double angle;
private Language localeLanguage = feuille.MainFrame.getLanguage();
public enum ButtonPressed{
NONE, OK_BUTTON, CANCEL_BUTTON;
}
/**
* Creates new form SelectGeoDialog
*/
public SelectGeoDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
bp = ButtonPressed.NONE;
snmSide = new SpinnerNumberModel(2, 2, 100, 1);
spiSide.setModel(snmSide);
if(localeLanguage.getValueOf("titleGeo")!=null){setTitle(localeLanguage.getValueOf("titleGeo"));}
if(localeLanguage.getValueOf("buttonOk")!=null){OK_Button.setText(localeLanguage.getValueOf("buttonOk"));}
if(localeLanguage.getValueOf("buttonCancel")!=null){Cancel_Button.setText(localeLanguage.getValueOf("buttonCancel"));}
if(localeLanguage.getValueOf("labelGeoText")!=null){lblText.setText(localeLanguage.getValueOf("labelGeoText"));}
if(localeLanguage.getValueOf("labelGeoSide")!=null){lblSide.setText(localeLanguage.getValueOf("labelGeoSide"));}
if(localeLanguage.getValueOf("rbuttonGeoClk")!=null){rbClockwise.setText(localeLanguage.getValueOf("rbuttonGeoClk"));}
if(localeLanguage.getValueOf("rbuttonGeoAntiClk")!=null){rbAntiClockwise.setText(localeLanguage.getValueOf("rbuttonGeoAntiClk"));}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
bgDirection = new javax.swing.ButtonGroup();
lblText = new javax.swing.JLabel();
lblSide = new javax.swing.JLabel();
rbClockwise = new javax.swing.JRadioButton();
lblAngle = new javax.swing.JLabel();
rbAntiClockwise = new javax.swing.JRadioButton();
OK_Button = new javax.swing.JButton();
Cancel_Button = new javax.swing.JButton();
spiSide = new javax.swing.JSpinner();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Copie selon cotés");
lblText.setText("<html>Choisissez le nombre de coté au total pour faire<br />le tour de votre forme (exemple : hexagone, 6 cotés) :");
lblSide.setText("cotés");
bgDirection.add(rbClockwise);
rbClockwise.setSelected(true);
rbClockwise.setText("Sens horaire");
rbClockwise.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rbClockwiseActionPerformed(evt);
}
});
lblAngle.setText("180°");
bgDirection.add(rbAntiClockwise);
rbAntiClockwise.setText("Sens anti-horaire");
rbAntiClockwise.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rbAntiClockwiseActionPerformed(evt);
}
});
OK_Button.setText("OK");
OK_Button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
OK_ButtonActionPerformed(evt);
}
});
Cancel_Button.setText("Annuler");
Cancel_Button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Cancel_ButtonActionPerformed(evt);
}
});
spiSide.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
spiSideStateChanged(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(rbClockwise)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(rbAntiClockwise)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(Cancel_Button, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(OK_Button, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lblText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(spiSide, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblSide, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lblAngle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblSide)
.addComponent(spiSide, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblAngle))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(rbClockwise)
.addComponent(rbAntiClockwise))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(OK_Button)
.addComponent(Cancel_Button))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void OK_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OK_ButtonActionPerformed
bp = ButtonPressed.OK_BUTTON;
dispose();
}//GEN-LAST:event_OK_ButtonActionPerformed
private void Cancel_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cancel_ButtonActionPerformed
bp = ButtonPressed.CANCEL_BUTTON;
dispose();
}//GEN-LAST:event_Cancel_ButtonActionPerformed
private void spiSideStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spiSideStateChanged
if(rbClockwise.isSelected()){
angle = 360 / snmSide.getNumber().doubleValue();
}else{
angle = -360 / snmSide.getNumber().doubleValue();
}
lblAngle.setText(angle+"°");
}//GEN-LAST:event_spiSideStateChanged
private void rbClockwiseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbClockwiseActionPerformed
if(rbClockwise.isSelected()){
angle = 360 / snmSide.getNumber().doubleValue();
}else{
angle = -360 / snmSide.getNumber().doubleValue();
}
lblAngle.setText(angle+"°");
}//GEN-LAST:event_rbClockwiseActionPerformed
private void rbAntiClockwiseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbAntiClockwiseActionPerformed
if(rbClockwise.isSelected()){
angle = 360 / snmSide.getNumber().doubleValue();
}else{
angle = -360 / snmSide.getNumber().doubleValue();
}
lblAngle.setText(angle+"°");
}//GEN-LAST:event_rbAntiClockwiseActionPerformed
public boolean showDialog(){
setLocationRelativeTo(null);
setVisible(true);
if(bp.equals(ButtonPressed.OK_BUTTON)){
return true;
}else{
return false;
}
}
public int getSide(){
return snmSide.getNumber().intValue();
}
public double getAngle(){
return angle;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(SelectGeoDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SelectGeoDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SelectGeoDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(SelectGeoDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
SelectGeoDialog dialog = new SelectGeoDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton Cancel_Button;
private javax.swing.JButton OK_Button;
private javax.swing.ButtonGroup bgDirection;
private javax.swing.JLabel lblAngle;
private javax.swing.JLabel lblSide;
private javax.swing.JLabel lblText;
private javax.swing.JRadioButton rbAntiClockwise;
private javax.swing.JRadioButton rbClockwise;
private javax.swing.JSpinner spiSide;
// End of variables declaration//GEN-END:variables
}