001package csheets.ext.share.ui; 002 003import java.awt.event.ActionEvent; 004import java.util.Observer; 005 006import csheets.core.Cell; 007import csheets.ext.share.controller.ReceiveController; 008import csheets.ext.share.core.Connections; 009import csheets.ui.ctrl.*; 010 011/** 012 * An action for the receive action in the sharing extension 013 * 014 * @see FocusOwnerAction 015 * @author Andre 016 * 017 */ 018public class ReceiveAction extends FocusOwnerAction { 019 020 /** generated id */ 021 private static final long serialVersionUID = 1L; 022 /** User Interface Controller */ 023 protected UIController uiController; 024 025 /** The first instance of this action */ 026 private static ReceiveAction instance; 027 028 /** 029 * Method that returns the first instance of this action 030 * 031 * @return the first instance of this action 032 */ 033 protected static ReceiveAction getInstance() { 034 return instance; 035 } 036 037 /** 038 * Creates a new receive action 039 * 040 * @param uiController 041 * user interface controller 042 */ 043 public ReceiveAction(UIController uiController) { 044 this.uiController = uiController; 045 if (instance == null) { 046 instance = this; 047 } 048 } 049 050 @Override 051 public void actionPerformed(ActionEvent event) { 052 ReceiveUI rui = new ReceiveUI(); 053 Cell cellStart = focusOwner.getSelectedCell(); 054 rui.createUI(cellStart); 055 } 056 057 @Override 058 protected String getName() { 059 return "Receive"; 060 } 061 062 /** 063 * Method that will get the active cell and sends that information to the 064 * controller 065 * 066 * @param IP 067 * the server IP 068 * @param port 069 * the connection port 070 * @param password 071 * the connection password 072 * @param observer 073 * the observer class 074 */ 075 public void clickOnSidebar(String IP, int port, String password, 076 Observer observer) { 077 Cell cellStart = focusOwner.getSelectedCell(); 078 ReceiveController rc = new ReceiveController(); 079 rc.startClient(IP, port, cellStart, password, observer); 080 } 081 082 /** 083 * Method that will get the active cell and sends that information to the 084 * controller 085 * 086 * @param connection 087 * the connection details 088 * @param observer 089 * the observer class 090 * @param password 091 * the password connection 092 * 093 */ 094 public void clickOnSidebar(Connections connection, Observer observer, 095 String password) { 096 Cell cellStart = focusOwner.getSelectedCell(); 097 ReceiveController rc = new ReceiveController(); 098 rc.startClient(connection, cellStart, observer, password); 099 } 100}