001package csheets.ext.share.ui; 002 003import java.util.*; 004 005import javax.swing.JOptionPane; 006 007import csheets.core.Cell; 008import csheets.ext.share.controller.SendController; 009import csheets.ext.share.core.Validate; 010 011/** 012 * Create a user interface for the send action 013 * 014 * @author Andre 015 * 016 */ 017public class SendUI implements Observer { 018 019 /** 020 * Create the UI for the send action 021 * 022 * @param cells 023 * the cells to be shared 024 */ 025 public void createUI(Cell[][] cells) { 026 boolean portIsNotCorrect = true; 027 boolean portAsNumber; 028 int port = 0; 029 String props = null; 030 while (portIsNotCorrect) { 031 String portTemp = JOptionPane 032 .showInputDialog("Please input a port (49152 to 65535)"); 033 props = JOptionPane 034 .showInputDialog("Writable (wr) or Read-only (r)"); 035 if (portTemp != null) { 036 portAsNumber = Validate.checkIfANumber(portTemp); 037 if (portAsNumber) { 038 port = Integer.parseInt(portTemp); 039 portIsNotCorrect = !Validate.checkPort(port); 040 } 041 } else { 042 break; 043 } 044 } 045 if (!portIsNotCorrect) { 046 SendController sc = new SendController(); 047 String password = JOptionPane 048 .showInputDialog("Please input the password!"); 049 sc.startServer(port, cells, Validate.encrypt(password.getBytes()), 050 props, this); 051 } 052 } 053 054 @Override 055 public void update(Observable o, Object arg) { 056 JOptionPane.showMessageDialog(null, "Connection Error"); 057 } 058}