1 /* 2 * Copyright (C) 2020 tonikelope 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 package com.tonikelope.coronapoker; 18 19 import com.tonikelope.coronapoker.Helpers.JTextFieldRegularPopupMenu; 20 import java.awt.Dimension; 21 import java.awt.Image; 22 import java.awt.event.KeyAdapter; 23 import java.awt.event.KeyEvent; 24 import java.io.File; 25 import java.io.IOException; 26 import java.nio.file.Files; 27 import java.nio.file.Paths; 28 import java.util.logging.Level; 29 import java.util.logging.Logger; 30 import javax.imageio.ImageIO; 31 import javax.swing.ImageIcon; 32 import javax.swing.JFileChooser; 33 import javax.swing.JFrame; 34 import javax.swing.JSpinner.DefaultEditor; 35 import javax.swing.SpinnerNumberModel; 36 import javax.swing.filechooser.FileFilter; 37 import javax.swing.filechooser.FileNameExtensionFilter; 38 import org.apache.commons.codec.binary.Base64; 39 40 /** 41 * 42 * @author tonikelope 43 */ 44 public class NewGameDialog extends javax.swing.JDialog { 45 46 public static final int DEFAULT_PORT = 7234; 47 public final static int DEFAULT_AVATAR_WIDTH = 50; 48 public final static int DEFAULT_AVATAR_HEIGHT = 50; 49 public final static int AVATAR_MAX_FILESIZE = 200; //KB 50 public final static int MAX_NICK_LENGTH = 20; 51 public final static int MAX_PORT_LENGTH = 5; 52 53 private boolean dialog_ok = false; 54 private final boolean partida_local; 55 private File avatar = null; 56 isDialog_ok()57 public boolean isDialog_ok() { 58 return dialog_ok; 59 } 60 61 /** 62 * Creates new form CrearTimba 63 */ NewGameDialog(java.awt.Frame parent, boolean modal, boolean local)64 public NewGameDialog(java.awt.Frame parent, boolean modal, boolean local) { 65 super(parent, modal); 66 initComponents(); 67 68 nick.addKeyListener(new KeyAdapter() { 69 @Override 70 public void keyTyped(KeyEvent e) { 71 if (nick.getText().length() >= MAX_NICK_LENGTH && nick.getSelectedText() == null) { 72 e.consume(); 73 } 74 } 75 }); 76 77 server_port_textfield.addKeyListener(new KeyAdapter() { 78 @Override 79 public void keyTyped(KeyEvent e) { 80 if (e.getKeyChar() < '0' || e.getKeyChar() > '9' || (server_port_textfield.getText().length() >= MAX_PORT_LENGTH && server_port_textfield.getSelectedText() == null)) { 81 e.consume(); 82 } 83 } 84 }); 85 86 this.partida_local = local; 87 88 JTextFieldRegularPopupMenu.addTo(this.server_ip_textfield); 89 JTextFieldRegularPopupMenu.addTo(this.server_port_textfield); 90 JTextFieldRegularPopupMenu.addTo(this.randomorg_apikey); 91 JTextFieldRegularPopupMenu.addTo(this.nick); 92 93 String elnick = Helpers.PROPERTIES.getProperty("nick", ""); 94 95 this.nick.setText(elnick.substring(0, Math.min(MAX_NICK_LENGTH, elnick.length()))); 96 97 String avatar_path = Helpers.PROPERTIES.getProperty("avatar", ""); 98 99 if (!avatar_path.isEmpty()) { 100 101 this.avatar = new File(avatar_path); 102 103 if (avatar.exists() && avatar.canRead() && avatar.length() <= AVATAR_MAX_FILESIZE * 1024) { 104 avatar_img.setSize(new Dimension(NewGameDialog.DEFAULT_AVATAR_WIDTH, NewGameDialog.DEFAULT_AVATAR_HEIGHT)); 105 avatar_img.setIcon(new ImageIcon(new ImageIcon(avatar.getAbsolutePath()).getImage().getScaledInstance(NewGameDialog.DEFAULT_AVATAR_WIDTH, NewGameDialog.DEFAULT_AVATAR_HEIGHT, Image.SCALE_SMOOTH))); 106 107 } else { 108 avatar = null; 109 } 110 } 111 112 Helpers.updateFonts(this, Helpers.GUI_FONT, null); 113 114 if (this.partida_local) { 115 this.server_ip_textfield.setText("localhost"); 116 this.server_ip_textfield.setEnabled(false); 117 this.server_port_textfield.setText(Helpers.PROPERTIES.getProperty("local_port", String.valueOf(DEFAULT_PORT))); 118 this.config_partida_panel.setVisible(true); 119 this.random_combobox.setSelectedIndex(Integer.parseInt(Helpers.PROPERTIES.getProperty("random_generator", String.valueOf(Helpers.SPRNG))) - 1); 120 this.randomorg_apikey.setText(Helpers.PROPERTIES.getProperty("randomorg_api", "")); 121 this.rebuy_checkbox.setSelected(true); 122 this.doblar_checkbox.setSelected(true); 123 ((DefaultEditor) doblar_ciegas_spinner.getEditor()).getTextField().setEditable(false); 124 125 String[] valores = ((String) ciegas_combobox.getSelectedItem()).split("/"); 126 127 float ciega_grande = Float.valueOf(valores[1].trim()); 128 129 buyin_spinner.setModel(new SpinnerNumberModel((int) (ciega_grande * 50f), (int) (ciega_grande * 10f), (int) (ciega_grande * 100f), (int) Math.pow(10, Math.floor(ciegas_combobox.getSelectedIndex() / 3)))); 130 131 ((DefaultEditor) buyin_spinner.getEditor()).getTextField().setEditable(false); 132 133 this.updateCiegasLabel(); 134 Helpers.setTranslatedTitle(this, "Crear timba"); 135 136 } else { 137 this.server_port_textfield.setText(Helpers.PROPERTIES.getProperty("server_port", String.valueOf(DEFAULT_PORT))); 138 this.server_ip_textfield.setText(Helpers.PROPERTIES.getProperty("server_ip", "localhost")); 139 Helpers.setTranslatedTitle(this, "Unirme a timba"); 140 } 141 142 Helpers.translateComponents(this, false); 143 144 pack(); 145 } 146 updateCiegasLabel()147 private void updateCiegasLabel() { 148 149 int buyin = (int) this.buyin_spinner.getValue(); 150 151 float big = Math.max(Game.MIN_BIG_BLIND, buyin / 50f); 152 153 float small = big / 2f; 154 155 } 156 157 /** 158 * This method is called from within the constructor to initialize the form. 159 * WARNING: Do NOT modify this code. The content of this method is always 160 * regenerated by the Form Editor. 161 */ 162 @SuppressWarnings("unchecked") 163 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents initComponents()164 private void initComponents() { 165 166 vamos = new javax.swing.JButton(); 167 server_port_textfield = new javax.swing.JTextField(); 168 server_ip_textfield = new javax.swing.JTextField(); 169 jLabel2 = new javax.swing.JLabel(); 170 config_partida_panel = new javax.swing.JPanel(); 171 randomorg_label = new javax.swing.JLabel(); 172 random_label = new javax.swing.JLabel(); 173 random_combobox = new javax.swing.JComboBox<>(); 174 randomorg_apikey = new javax.swing.JTextField(); 175 buyin_spinner = new javax.swing.JSpinner(); 176 buyin_label = new javax.swing.JLabel(); 177 doblar_checkbox = new javax.swing.JCheckBox(); 178 doblar_ciegas_spinner = new javax.swing.JSpinner(); 179 jLabel3 = new javax.swing.JLabel(); 180 recover_checkbox = new javax.swing.JCheckBox(); 181 rebuy_checkbox = new javax.swing.JCheckBox(); 182 ciegas_label = new javax.swing.JLabel(); 183 ciegas_combobox = new javax.swing.JComboBox<>(); 184 jPanel1 = new javax.swing.JPanel(); 185 avatar_img = new javax.swing.JLabel(); 186 nick = new javax.swing.JTextField(); 187 jLabel1 = new javax.swing.JLabel(); 188 189 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 190 setTitle("CoronaPoker - Nueva timba"); 191 setIconImage(new javax.swing.ImageIcon(getClass().getResource("/images/avatar_default.png")).getImage()); 192 setMinimumSize(new java.awt.Dimension(533, 0)); 193 194 vamos.setFont(new java.awt.Font("Dialog", 1, 48)); // NOI18N 195 vamos.setText("¡VAMOS!"); 196 vamos.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); 197 vamos.setDoubleBuffered(true); 198 vamos.addActionListener(new java.awt.event.ActionListener() { 199 public void actionPerformed(java.awt.event.ActionEvent evt) { 200 vamosActionPerformed(evt); 201 } 202 }); 203 204 server_port_textfield.setFont(new java.awt.Font("Dialog", 0, 16)); // NOI18N 205 server_port_textfield.setText("72345"); 206 server_port_textfield.setDoubleBuffered(true); 207 208 server_ip_textfield.setFont(new java.awt.Font("Dialog", 0, 16)); // NOI18N 209 server_ip_textfield.setHorizontalAlignment(javax.swing.JTextField.TRAILING); 210 server_ip_textfield.setText("localhost"); 211 server_ip_textfield.setDoubleBuffered(true); 212 213 jLabel2.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N 214 jLabel2.setText(":"); 215 jLabel2.setDoubleBuffered(true); 216 217 config_partida_panel.setVisible(false); 218 config_partida_panel.setOpaque(false); 219 220 randomorg_label.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N 221 randomorg_label.setText("RANDOM.ORG API KEY:"); 222 randomorg_label.setDoubleBuffered(true); 223 224 random_label.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N 225 random_label.setText("Generador de números aleatorios:"); 226 random_label.setToolTipText("Se usará para barajar las cartas"); 227 random_label.setDoubleBuffered(true); 228 229 random_combobox.setFont(new java.awt.Font("Dialog", 0, 16)); // NOI18N 230 random_combobox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Muy seguro", "Seguro", "Normal" })); 231 random_combobox.setDoubleBuffered(true); 232 random_combobox.addActionListener(new java.awt.event.ActionListener() { 233 public void actionPerformed(java.awt.event.ActionEvent evt) { 234 random_comboboxActionPerformed(evt); 235 } 236 }); 237 238 randomorg_apikey.setFont(new java.awt.Font("Dialog", 0, 16)); // NOI18N 239 randomorg_apikey.setHorizontalAlignment(javax.swing.JTextField.RIGHT); 240 randomorg_apikey.setDoubleBuffered(true); 241 242 buyin_spinner.setFont(new java.awt.Font("Dialog", 0, 16)); // NOI18N 243 buyin_spinner.setModel(new javax.swing.SpinnerNumberModel(10, 5, null, 1)); 244 buyin_spinner.setDoubleBuffered(true); 245 buyin_spinner.addChangeListener(new javax.swing.event.ChangeListener() { 246 public void stateChanged(javax.swing.event.ChangeEvent evt) { 247 buyin_spinnerStateChanged(evt); 248 } 249 }); 250 251 buyin_label.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N 252 buyin_label.setText("Compra inicial:"); 253 buyin_label.setToolTipText("[10-100] ciegas grandes"); 254 buyin_label.setDoubleBuffered(true); 255 256 doblar_checkbox.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N 257 doblar_checkbox.setText("Doblar ciegas (minutos):"); 258 doblar_checkbox.setDoubleBuffered(true); 259 doblar_checkbox.addActionListener(new java.awt.event.ActionListener() { 260 public void actionPerformed(java.awt.event.ActionEvent evt) { 261 doblar_checkboxActionPerformed(evt); 262 } 263 }); 264 265 doblar_ciegas_spinner.setFont(new java.awt.Font("Dialog", 0, 16)); // NOI18N 266 doblar_ciegas_spinner.setModel(new javax.swing.SpinnerNumberModel(60, 5, null, 5)); 267 doblar_ciegas_spinner.setDoubleBuffered(true); 268 269 jLabel3.setFont(new java.awt.Font("Dialog", 2, 12)); // NOI18N 270 jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); 271 jLabel3.setText("Nota: no olvides mapear el puerto en tu router si quieres compartir la timba por Internet"); 272 jLabel3.setDoubleBuffered(true); 273 274 recover_checkbox.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N 275 recover_checkbox.setText("RECUPERAR TIMBA (o intentarlo)"); 276 recover_checkbox.setToolTipText("El MODO RECUPERACIÓN permite arrancar una timba que se interrumpió previamente"); 277 recover_checkbox.setDoubleBuffered(true); 278 recover_checkbox.addActionListener(new java.awt.event.ActionListener() { 279 public void actionPerformed(java.awt.event.ActionEvent evt) { 280 recover_checkboxActionPerformed(evt); 281 } 282 }); 283 284 rebuy_checkbox.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N 285 rebuy_checkbox.setText("Permitir recomprar"); 286 rebuy_checkbox.setToolTipText("Si algún jugador se queda sin fichas"); 287 rebuy_checkbox.setDoubleBuffered(true); 288 289 ciegas_label.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N 290 ciegas_label.setText("Ciegas:"); 291 ciegas_label.setDoubleBuffered(true); 292 293 ciegas_combobox.setFont(new java.awt.Font("Dialog", 0, 16)); // NOI18N 294 ciegas_combobox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "0.10 / 0.20", "0.20 / 0.40", "0.50 / 1", "1 / 2", "2 / 4", "5 / 10", "10 / 20", "20 / 40", "50 / 100", "100 / 200", "200 / 400", "500 / 1000", "1000 / 2000", "2000 / 4000", "5000 / 10000", "10000 / 20000", "20000 / 40000", "50000 / 100000", "100000 / 200000", "200000 / 400000", "500000 / 1000000" })); 295 ciegas_combobox.setDoubleBuffered(true); 296 ciegas_combobox.addActionListener(new java.awt.event.ActionListener() { 297 public void actionPerformed(java.awt.event.ActionEvent evt) { 298 ciegas_comboboxActionPerformed(evt); 299 } 300 }); 301 302 javax.swing.GroupLayout config_partida_panelLayout = new javax.swing.GroupLayout(config_partida_panel); 303 config_partida_panel.setLayout(config_partida_panelLayout); 304 config_partida_panelLayout.setHorizontalGroup( 305 config_partida_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 306 .addGroup(config_partida_panelLayout.createSequentialGroup() 307 .addComponent(random_label) 308 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 309 .addComponent(random_combobox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 310 .addGroup(config_partida_panelLayout.createSequentialGroup() 311 .addGroup(config_partida_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 312 .addGroup(config_partida_panelLayout.createSequentialGroup() 313 .addComponent(buyin_label) 314 .addGap(38, 38, 38)) 315 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, config_partida_panelLayout.createSequentialGroup() 316 .addComponent(randomorg_label) 317 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) 318 .addGroup(config_partida_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 319 .addComponent(randomorg_apikey) 320 .addComponent(buyin_spinner, javax.swing.GroupLayout.Alignment.TRAILING))) 321 .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 612, Short.MAX_VALUE) 322 .addGroup(config_partida_panelLayout.createSequentialGroup() 323 .addComponent(doblar_checkbox) 324 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 325 .addComponent(doblar_ciegas_spinner)) 326 .addGroup(config_partida_panelLayout.createSequentialGroup() 327 .addGroup(config_partida_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 328 .addComponent(recover_checkbox) 329 .addComponent(rebuy_checkbox)) 330 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 331 .addGroup(config_partida_panelLayout.createSequentialGroup() 332 .addComponent(ciegas_label) 333 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 334 .addComponent(ciegas_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 335 ); 336 config_partida_panelLayout.setVerticalGroup( 337 config_partida_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 338 .addGroup(config_partida_panelLayout.createSequentialGroup() 339 .addGap(0, 0, 0) 340 .addComponent(jLabel3) 341 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 342 .addGroup(config_partida_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 343 .addComponent(random_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 344 .addComponent(random_label)) 345 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 346 .addGroup(config_partida_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 347 .addComponent(randomorg_label) 348 .addComponent(randomorg_apikey, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 349 .addGap(18, 18, 18) 350 .addGroup(config_partida_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 351 .addComponent(ciegas_label) 352 .addComponent(ciegas_combobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 353 .addGap(18, 18, 18) 354 .addGroup(config_partida_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 355 .addComponent(buyin_spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 356 .addComponent(buyin_label)) 357 .addGap(18, 18, 18) 358 .addComponent(rebuy_checkbox) 359 .addGap(18, 18, 18) 360 .addGroup(config_partida_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 361 .addComponent(doblar_checkbox) 362 .addComponent(doblar_ciegas_spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 363 .addGap(18, 18, 18) 364 .addComponent(recover_checkbox) 365 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 366 ); 367 368 avatar_img.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/avatar_default.png"))); // NOI18N 369 avatar_img.setToolTipText("Haz click para cambiar el avatar"); 370 avatar_img.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); 371 avatar_img.setDoubleBuffered(true); 372 avatar_img.addMouseListener(new java.awt.event.MouseAdapter() { 373 public void mouseClicked(java.awt.event.MouseEvent evt) { 374 avatar_imgMouseClicked(evt); 375 } 376 }); 377 378 nick.setFont(new java.awt.Font("Dialog", 0, 16)); // NOI18N 379 nick.setDoubleBuffered(true); 380 381 jLabel1.setFont(new java.awt.Font("Dialog", 1, 16)); // NOI18N 382 jLabel1.setText("Nick:"); 383 jLabel1.setToolTipText("Haz click para cambiar el avatar"); 384 jLabel1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); 385 jLabel1.setDoubleBuffered(true); 386 jLabel1.addMouseListener(new java.awt.event.MouseAdapter() { 387 public void mouseClicked(java.awt.event.MouseEvent evt) { 388 jLabel1MouseClicked(evt); 389 } 390 }); 391 392 javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 393 jPanel1.setLayout(jPanel1Layout); 394 jPanel1Layout.setHorizontalGroup( 395 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 396 .addGroup(jPanel1Layout.createSequentialGroup() 397 .addComponent(avatar_img) 398 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 399 .addComponent(jLabel1) 400 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 401 .addComponent(nick)) 402 ); 403 jPanel1Layout.setVerticalGroup( 404 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 405 .addGroup(jPanel1Layout.createSequentialGroup() 406 .addGap(0, 0, 0) 407 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 408 .addComponent(avatar_img) 409 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 410 .addComponent(jLabel1) 411 .addComponent(nick, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) 412 .addGap(0, 0, 0)) 413 ); 414 415 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 416 getContentPane().setLayout(layout); 417 layout.setHorizontalGroup( 418 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 419 .addGroup(layout.createSequentialGroup() 420 .addContainerGap() 421 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 422 .addComponent(vamos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 423 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 424 .addComponent(server_ip_textfield) 425 .addGap(0, 0, 0) 426 .addComponent(jLabel2) 427 .addGap(0, 0, 0) 428 .addComponent(server_port_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)) 429 .addComponent(config_partida_panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 430 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 431 .addContainerGap()) 432 ); 433 layout.setVerticalGroup( 434 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 435 .addGroup(layout.createSequentialGroup() 436 .addContainerGap() 437 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 438 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 439 .addComponent(server_ip_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 440 .addComponent(jLabel2)) 441 .addComponent(server_port_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 442 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 443 .addComponent(config_partida_panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 444 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 445 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 446 .addGap(18, 18, 18) 447 .addComponent(vamos, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) 448 .addContainerGap()) 449 ); 450 451 pack(); 452 }// </editor-fold>//GEN-END:initComponents 453 vamosActionPerformed(java.awt.event.ActionEvent evt)454 private void vamosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vamosActionPerformed 455 // TODO add your handling code here: 456 457 if (!this.nick.getText().trim().isEmpty() && !this.server_ip_textfield.getText().trim().isEmpty() && !this.server_port_textfield.getText().trim().isEmpty()) { 458 459 Helpers.playWavResource("misc/allin.wav"); 460 461 String elnick = this.nick.getText().trim(); 462 463 Helpers.PROPERTIES.setProperty("nick", elnick); 464 465 Helpers.PROPERTIES.setProperty("server_ip", this.server_ip_textfield.getText().trim()); 466 467 Helpers.PROPERTIES.setProperty(this.partida_local ? "local_port" : "server_port", this.server_port_textfield.getText().trim()); 468 469 if (this.config_partida_panel.isVisible()) { 470 Helpers.PROPERTIES.setProperty("random_generator", String.valueOf(Helpers.DECK_RANDOM_GENERATOR)); 471 Helpers.PROPERTIES.setProperty("randomorg_api", this.randomorg_apikey.getText().trim()); 472 Helpers.DECK_RANDOM_GENERATOR = this.random_combobox.getSelectedIndex() + 1; 473 Helpers.RANDOM_ORG_APIKEY = this.randomorg_apikey.getText().trim(); 474 } 475 476 if (this.avatar != null) { 477 Helpers.PROPERTIES.setProperty("avatar", this.avatar.getAbsolutePath()); 478 } else { 479 Helpers.PROPERTIES.setProperty("avatar", ""); 480 } 481 482 Helpers.savePropertiesFile(); 483 484 Game.setRECOVER(this.recover_checkbox.isSelected()); 485 486 Game.REBUY = this.rebuy_checkbox.isSelected(); 487 488 Game.BUYIN = (int) this.buyin_spinner.getValue(); 489 490 String[] valores_ciegas = ((String) ciegas_combobox.getSelectedItem()).split("/"); 491 492 Game.CIEGA_GRANDE = Float.valueOf(valores_ciegas[1].trim()); 493 494 Game.CIEGA_PEQUEÑA = Float.valueOf(valores_ciegas[0].trim()); 495 496 if (this.doblar_checkbox.isSelected()) { 497 Game.CIEGAS_TIME = (int) this.doblar_ciegas_spinner.getValue(); 498 } else { 499 Game.CIEGAS_TIME = 0; 500 } 501 502 this.dialog_ok = true; 503 504 WaitingRoom espera = new WaitingRoom((Init) getParent(), partida_local, elnick, server_ip_textfield.getText().trim() + ":" + server_port_textfield.getText().trim(), avatar); 505 506 espera.setLocationRelativeTo(this); 507 508 setVisible(false); 509 510 espera.setVisible(true); 511 512 } else { 513 Helpers.mostrarMensajeError((JFrame) this.getParent(), "Te falta algún campo obligatorio por completar"); 514 } 515 516 }//GEN-LAST:event_vamosActionPerformed 517 random_comboboxActionPerformed(java.awt.event.ActionEvent evt)518 private void random_comboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_random_comboboxActionPerformed 519 // TODO add your handling code here: 520 521 Helpers.DECK_RANDOM_GENERATOR = this.random_combobox.getSelectedIndex() + 1; 522 523 this.randomorg_label.setVisible(Helpers.DECK_RANDOM_GENERATOR == Helpers.TRNG); 524 this.randomorg_apikey.setVisible(Helpers.DECK_RANDOM_GENERATOR == Helpers.TRNG); 525 526 if (Helpers.DECK_RANDOM_GENERATOR == Helpers.TRNG) { 527 this.randomorg_apikey.setText(Helpers.PROPERTIES.getProperty("randomorg_api", "")); 528 Helpers.RANDOM_ORG_APIKEY = Helpers.PROPERTIES.getProperty("randomorg_api", ""); 529 } 530 531 pack(); 532 }//GEN-LAST:event_random_comboboxActionPerformed 533 avatar_imgMouseClicked(java.awt.event.MouseEvent evt)534 private void avatar_imgMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_avatar_imgMouseClicked 535 // TODO add your handling code here: 536 JFileChooser fileChooser = new JFileChooser(); 537 538 FileFilter imageFilter = new FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes()); 539 540 fileChooser.setFileFilter(imageFilter); 541 542 fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); 543 544 int result = fileChooser.showOpenDialog(this); 545 546 if (result == JFileChooser.APPROVE_OPTION) { 547 File selectedFile = fileChooser.getSelectedFile(); 548 549 if (selectedFile.length() > NewGameDialog.AVATAR_MAX_FILESIZE * 1024) { 550 Helpers.mostrarMensajeError((JFrame) this.getParent(), "MAX: " + NewGameDialog.AVATAR_MAX_FILESIZE + " KB"); 551 } else { 552 this.avatar = selectedFile; 553 554 avatar_img.setSize(new Dimension(NewGameDialog.DEFAULT_AVATAR_WIDTH, NewGameDialog.DEFAULT_AVATAR_HEIGHT)); 555 avatar_img.setIcon(new ImageIcon(new ImageIcon(avatar.getAbsolutePath()).getImage().getScaledInstance(NewGameDialog.DEFAULT_AVATAR_WIDTH, NewGameDialog.DEFAULT_AVATAR_HEIGHT, Image.SCALE_SMOOTH))); 556 557 } 558 559 } else { 560 561 this.avatar = null; 562 563 avatar_img.setSize(new Dimension(NewGameDialog.DEFAULT_AVATAR_WIDTH, NewGameDialog.DEFAULT_AVATAR_HEIGHT)); 564 avatar_img.setIcon(new ImageIcon(getClass().getResource("/images/avatar_default.png"))); 565 566 } 567 }//GEN-LAST:event_avatar_imgMouseClicked 568 doblar_checkboxActionPerformed(java.awt.event.ActionEvent evt)569 private void doblar_checkboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doblar_checkboxActionPerformed 570 // TODO add your handling code here: 571 this.doblar_ciegas_spinner.setEnabled(this.doblar_checkbox.isSelected()); 572 }//GEN-LAST:event_doblar_checkboxActionPerformed 573 buyin_spinnerStateChanged(javax.swing.event.ChangeEvent evt)574 private void buyin_spinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_buyin_spinnerStateChanged 575 // TODO add your handling code here: 576 Helpers.playWavResource("misc/cash_register.wav"); 577 // updateCiegasLabel(); 578 }//GEN-LAST:event_buyin_spinnerStateChanged 579 jLabel1MouseClicked(java.awt.event.MouseEvent evt)580 private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked 581 // TODO add your handling code here: 582 avatar_imgMouseClicked(evt); 583 }//GEN-LAST:event_jLabel1MouseClicked 584 recover_checkboxActionPerformed(java.awt.event.ActionEvent evt)585 private void recover_checkboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_recover_checkboxActionPerformed 586 // TODO add your handling code here: 587 588 if (this.recover_checkbox.isSelected()) { 589 590 if (Files.exists(Paths.get(Crupier.RECOVER_BALANCE_FILE))) { 591 592 try { 593 String datos = Files.readString(Paths.get(Crupier.RECOVER_BALANCE_FILE)); 594 595 String[] partes = datos.split("#"); 596 597 this.buyin_spinner.setEnabled(false); 598 599 this.buyin_label.setEnabled(false); 600 601 this.rebuy_checkbox.setEnabled(false); 602 603 this.ciegas_label.setEnabled(false); 604 605 this.ciegas_combobox.setEnabled(false); 606 607 this.doblar_ciegas_spinner.setEnabled(false); 608 609 this.doblar_checkbox.setEnabled(false); 610 611 this.nick.setText(new String(Base64.decodeBase64(partes[0]), "UTF-8")); 612 613 this.nick.setEnabled(false); 614 615 Helpers.mostrarMensajeInformativo((JFrame) this.getParent(), "En el MODO RECUPERACIÓN se continuará la timba anterior desde donde se paró:\n\n1) Es OBLIGATORIO que los jugadores antiguos usen los MISMOS NICKS.\n\n2) Para poder continuar desde el PUNTO EXACTO (con la mismas cartas) es OBLIGATORIO que se conecten TODOS los jugadores antiguos.\nSi esto no es posible, se \"perderá\" la mano que estaba en curso cuando se interrumpió la timba.\n\n3) Está permitido que se unan a la timba jugadores nuevos (estarán la primera mano de espectadores)."); 616 617 } catch (IOException ex) { 618 Logger.getLogger(NewGameDialog.class.getName()).log(Level.SEVERE, null, ex); 619 } 620 } else { 621 this.recover_checkbox.setSelected(false); 622 } 623 } else { 624 this.buyin_spinner.setEnabled(true); 625 626 this.buyin_label.setEnabled(true); 627 628 this.rebuy_checkbox.setEnabled(true); 629 630 this.ciegas_label.setEnabled(true); 631 632 this.ciegas_combobox.setEnabled(true); 633 634 this.doblar_ciegas_spinner.setEnabled(true); 635 636 this.doblar_checkbox.setEnabled(true); 637 638 this.nick.setEnabled(true); 639 } 640 }//GEN-LAST:event_recover_checkboxActionPerformed 641 ciegas_comboboxActionPerformed(java.awt.event.ActionEvent evt)642 private void ciegas_comboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ciegas_comboboxActionPerformed 643 // TODO add your handling code here: 644 645 String[] valores = ((String) ciegas_combobox.getSelectedItem()).split("/"); 646 647 float ciega_grande = Float.valueOf(valores[1].trim()); 648 649 buyin_spinner.setModel(new SpinnerNumberModel((int) (ciega_grande * 50f), (int) (ciega_grande * 10f), (int) (ciega_grande * 100f), (int) Math.pow(10, Math.floor(ciegas_combobox.getSelectedIndex() / 3)))); 650 651 ((DefaultEditor) buyin_spinner.getEditor()).getTextField().setEditable(false); 652 653 }//GEN-LAST:event_ciegas_comboboxActionPerformed 654 655 // Variables declaration - do not modify//GEN-BEGIN:variables 656 private javax.swing.JLabel avatar_img; 657 private javax.swing.JLabel buyin_label; 658 private javax.swing.JSpinner buyin_spinner; 659 private javax.swing.JComboBox<String> ciegas_combobox; 660 private javax.swing.JLabel ciegas_label; 661 private javax.swing.JPanel config_partida_panel; 662 private javax.swing.JCheckBox doblar_checkbox; 663 private javax.swing.JSpinner doblar_ciegas_spinner; 664 private javax.swing.JLabel jLabel1; 665 private javax.swing.JLabel jLabel2; 666 private javax.swing.JLabel jLabel3; 667 private javax.swing.JPanel jPanel1; 668 private javax.swing.JTextField nick; 669 private javax.swing.JComboBox<String> random_combobox; 670 private javax.swing.JLabel random_label; 671 private javax.swing.JTextField randomorg_apikey; 672 private javax.swing.JLabel randomorg_label; 673 private javax.swing.JCheckBox rebuy_checkbox; 674 private javax.swing.JCheckBox recover_checkbox; 675 private javax.swing.JTextField server_ip_textfield; 676 private javax.swing.JTextField server_port_textfield; 677 private javax.swing.JButton vamos; 678 // End of variables declaration//GEN-END:variables 679 } 680