Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
JavArrow MicroEdition - SetOptions.java

SetOptions.java

Caricato da: Netarrow
Scarica il programma completo

  1. import java.awt.Dimension;
  2. import java.awt.Toolkit;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.WindowAdapter;
  6. import java.awt.event.WindowEvent;
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.util.Vector;
  10.  
  11. import javax.swing.JButton;
  12. import javax.swing.JComboBox;
  13. import javax.swing.JFileChooser;
  14. import javax.swing.JLabel;
  15. import javax.swing.JOptionPane;
  16. import javax.swing.JTextField;
  17. import javax.swing.UIManager.LookAndFeelInfo;
  18. /**
  19. @author netarrow
  20. */
  21. class SetOptions extends javax.swing.JDialog {
  22.         private JTextField pathsdk;
  23.         private JLabel InPath;
  24.         private JButton annulla;
  25.         private JButton ok;
  26.         private JComboBox LAFList;
  27.         private JLabel SelectLaF;
  28.         private JButton cerca;
  29.         private JavArrow frame;
  30.         private Vector v;
  31.         private boolean isFirstSet;
  32.        
  33.         public SetOptions(JavArrow frame, LookAndFeelInfo[] uim, boolean b) {
  34.                 super(frame);
  35.                 v = new Vector();
  36.                 for(int i = 0; i < uim.length; i++) {
  37.                         v.add(uim[i].getName());
  38.                 }
  39.                 initGUI();
  40.                 centerFrame();
  41.                 this.frame = frame;
  42.                 setVisible(true);
  43.                 isFirstSet = b;
  44.         }
  45.  
  46.         public void centerFrame() {
  47.                 Toolkit t = Toolkit.getDefaultToolkit();
  48.                 Dimension d=t.getScreenSize();
  49.                 Dimension win=getSize();
  50.                 win=getSize();
  51.                 setLocation(d.width/2-(win.width/2)-1,d.height/2-(win.height/2)-1);
  52.         }
  53.        
  54.         private void initGUI() {
  55.                 try {
  56.                         this.setSize(385, 207);
  57.                         this.setTitle("Opzioni di JavArrow MicroEdition");
  58.                         this.getContentPane().setLayout(null);
  59.                         this.setModal(true);
  60.                         this.addWindowListener(new WindowAdapter() {
  61.                                 public void windowClosing(WindowEvent evt) {
  62.                                         if(isFirstSet)
  63.                                         System.exit(0);
  64.                                         else
  65.                                                 setVisible(false);
  66.                                 }
  67.                         });
  68.                         {
  69.                                 pathsdk = new JTextField();
  70.                                 this.getContentPane().add(pathsdk);
  71.                                 pathsdk.setBounds(10, 47, 213, 19);
  72.                                 pathsdk.setEditable(false);
  73.                         }
  74.                         {
  75.                                 cerca = new JButton();
  76.                                 this.getContentPane().add(cerca);
  77.                                 cerca.setText("Cerca");
  78.                                 cerca.setBounds(263, 47, 96, 20);
  79.                                 final SetOptions jf = this;
  80.                                 cerca.addActionListener(new ActionListener() {
  81.                                         public void actionPerformed(ActionEvent evt) {
  82.                                                 JFileChooser jfc = new JFileChooser();
  83.                                                 int i = jfc.showOpenDialog(jf);
  84.                                                 if(i == JFileChooser.APPROVE_OPTION) {
  85.                                                         pathsdk.setText(jfc.getSelectedFile().toString().substring(0, jfc.getSelectedFile().toString().lastIndexOf(File.separator)));
  86.                                                 }
  87.                                         }
  88.                                 });
  89.                         }
  90.                         {
  91.                                 InPath = new JLabel();
  92.                                 this.getContentPane().add(InPath);
  93.                                 InPath.setText("Inserire il path del jdk");
  94.                                 InPath.setBounds(12, 31, 203, 14);
  95.                         }
  96.                         {
  97.                                 SelectLaF = new JLabel();
  98.                                 this.getContentPane().add(SelectLaF);
  99.                                 SelectLaF.setText("Slezionare il LookAndFeel(aspetto grafico)");
  100.                                 SelectLaF.setBounds(9, 80, 246, 21);
  101.                         }
  102.                         {
  103.                                 LAFList = new JComboBox();
  104.                                 for(int i = 0; i < v.size(); i++) {
  105.                                 LAFList.addItem(v.get(i));
  106.                                 }
  107.                                 this.getContentPane().add(LAFList);
  108.                                 LAFList.setBounds(263, 81, 95, 19);
  109.                         }
  110.                         {
  111.                                 ok = new JButton();
  112.                                 this.getContentPane().add(ok);
  113.                                 ok.setText("Ok");
  114.                                 ok.setBounds(169, 144, 84, 21);
  115.                                 ok.addActionListener(new ActionListener() {
  116.                                         public void actionPerformed(ActionEvent evt) {
  117.                                                 if(!pathsdk.getText().endsWith("bin")) {
  118.                                                         JOptionPane.showMessageDialog(null, "Inserire il path dell'sdk, bisogna trovarsi all'interno della cartella bin", "Errore", JOptionPane.ERROR_MESSAGE);
  119.                                                         return;
  120.                                                 }
  121.                                                 JavArrow.pathsdk = pathsdk.getText().replace('\\', '/');
  122.                                                 try {
  123.                                                         JavArrow.saveOption(JavArrow.pathsdk, LAFList.getSelectedIndex());
  124.                                                         JOptionPane.showMessageDialog(null, "Al prossimo avvio le opzioni saranno caricate", "Configurazione riuscita", JOptionPane.INFORMATION_MESSAGE);
  125.                                                         setVisible(false);
  126.                                                 } catch (IOException e) {
  127.                                                         e.printStackTrace();
  128.                                                 }
  129.                                         }
  130.                                 });
  131.                         }
  132.                         {
  133.                                 annulla = new JButton();
  134.                                 this.getContentPane().add(annulla);
  135.                                 annulla.setText("Annulla");
  136.                                 annulla.setBounds(266, 144, 84, 21);
  137.                                 annulla.addActionListener(new ActionListener() {
  138.                                         public void actionPerformed(ActionEvent evt) {
  139.                                                 if(isFirstSet)
  140.                                                 System.exit(0);
  141.                                                 else
  142.                                                         setVisible(false);
  143.                                         }
  144.                                 });
  145.                         }
  146.                 } catch (Exception e) {
  147.                         e.printStackTrace();
  148.                 }
  149.         }
  150.  
  151. }