Blame view

BRIC/src/GUI/save.java 6.52 KB
eeb5cac08   Madiel de Souza Conserva Filho   first
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  /*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package GUI;
  
  import LOGIC.Internacional;
  import LOGIC.ObjectList;
  import LOGIC.Serialize;
  import javax.swing.JOptionPane;
  import javax.swing.table.DefaultTableModel;
  
  /**
   *
   * @author Dalay
   */
  public class save extends javax.swing.JFrame {
  
      public save(Internacional inter, ObjectList listas) {
          initComponents();
  
          mostrar();
          this.listas = listas;
          nome.setText(inter.retornarMensagem("COD0032"));
          salvar.setText(inter.retornarMensagem("COD0022"));
          cancelar.setText(inter.retornarMensagem("COD0026"));
      }
      DefaultTableModel tabTipo = new DefaultTableModel(null, new String[]{"Nome"}) {
          public boolean isCellEditable(int rowIndex, int mColIndex) {
              return false;
          }
      };
      Serialize s = new Serialize();
      ObjectList listas;
  
      /**
       * 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() {
  
          jScrollPane1 = new javax.swing.JScrollPane();
          jTable1 = new javax.swing.JTable();
          salvar = new javax.swing.JButton();
          cancelar = new javax.swing.JButton();
          nome = new javax.swing.JLabel();
          name = new javax.swing.JTextField();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
          setMinimumSize(new java.awt.Dimension(251, 282));
  
          jTable1.setModel(tabTipo);
          jScrollPane1.setViewportView(jTable1);
  
          salvar.setText("Save");
          salvar.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  salvarActionPerformed(evt);
              }
          });
  
          cancelar.setText("Cancel");
          cancelar.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  cancelarActionPerformed(evt);
              }
          });
  
          nome.setText("Nome:");
  
          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)
                      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                      .addGroup(layout.createSequentialGroup()
                          .addGap(0, 122, Short.MAX_VALUE)
                          .addComponent(salvar)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(cancelar))
                      .addGroup(layout.createSequentialGroup()
                          .addComponent(nome)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(name)))
                  .addContainerGap())
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(nome)
                      .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGap(18, 18, 18)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(salvar)
                      .addComponent(cancelar))
                  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
          );
  
          pack();
      }// </editor-fold>//GEN-END:initComponents
  
      private void salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarActionPerformed
  
          miracleMethod();
  
          if (name.getText() != "" || checaNome()) {
              s.serializaLista();
              this.dispose();
          }
      }//GEN-LAST:event_salvarActionPerformed
  
      private void cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarActionPerformed
          this.dispose();        // TODO add your handling code here:
      }//GEN-LAST:event_cancelarActionPerformed
  
      public void miracleMethod() {
          if (name.getText() != "") {
              if (checaNome()) {
                  s.save(name.getText(), listas);
              } else {
                  JOptionPane.showMessageDialog(null, "nome já existe...");
              }
          } else {
              JOptionPane.showMessageDialog(null, "coloque um nome...");
          }
  
      }
  
      public boolean checaNome() {
          if (s.getSaves() != null) {
  
              for (int i = 0; i < s.getSaves().size(); i++) {
                  if (name.getText().equals(s.getSaves().get(i).getNome())) {
                      return false;
                  }
              }
          }
          return true;
  
      }
  
      public void mostrar() {
          while (tabTipo.getRowCount() > 0) {
              tabTipo.removeRow(0);
          }
          if (s.getSaves() == null) {
          } else {
              if (s.getSaves().isEmpty()) {
              } else {
  
                  String[] linha = new String[]{null, null};
                  for (int j = 0; j < s.getSaves().size(); j++) {
                      tabTipo.addRow(linha);
                      tabTipo.setValueAt(s.getSaves().get(j).getNome(), j, 0);
  
                  }
              }
          }
      }
      // Variables declaration - do not modify//GEN-BEGIN:variables
      private javax.swing.JButton cancelar;
      private javax.swing.JScrollPane jScrollPane1;
      private javax.swing.JTable jTable1;
      private javax.swing.JTextField name;
      private javax.swing.JLabel nome;
      private javax.swing.JButton salvar;
      // End of variables declaration//GEN-END:variables
  }