예제 #1
0
 void sendMessageToAll(String msg) {
   if (UserProfile == JTC.CLIENT) {
     MainClient.sendTextMsg(JTC.COMMON_TEXT_MSG, null, msg);
   } else if (UserProfile == JTC.SERVER) {
     MainServer.sendTextMsg(JTC.COMMON_TEXT_MSG, null, null, msg, null, null);
   }
 }
예제 #2
0
  public void setProfile(String newProfile) {
    if (UserProfile == newProfile) return;
    else if (newProfile == JTC.CLIENT) {
      UserProfile = newProfile;
      MainServer.switchToClient();
      destroy();

    } else if (newProfile == JTC.SERVER) {
      UserProfile = newProfile;
      MainClient.switchToServer();
      destroy();
    }
  }
예제 #3
0
  void userNameWin(Shell ParentShell) {

    GPFlag = false;
    Shell SubShell = new Shell(ParentShell.getDisplay());
    GridLayout SubShellGL = new GridLayout();
    SubShell.setLayout(SubShellGL);
    SubShellGL.numColumns = 2;
    SubShellGL.makeColumnsEqualWidth = true;

    String UserName = "";

    Label UserNameLab;
    Text UserNameInp;
    Button ApplyBut, CancelBut;

    UserNameLab = new Label(SubShell, SWT.NORMAL | SWT.CENTER);
    UserNameLab.setLayoutData(new GridData());
    UserNameLab.setText("Your User Name:");

    UserNameInp = new Text(SubShell, SWT.SINGLE | SWT.BORDER);
    UserNameInp.setLayoutData(new GridData());

    ApplyBut = new Button(SubShell, SWT.PUSH);
    ApplyBut.setLayoutData(new GridData());
    ApplyBut.setText("Apply");
    ApplyBut.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent Evt) {
            if (confirmWin(
                    ((Button) Evt.widget).getShell(),
                    "Are you sure you want to save changes?",
                    JTC.YESNO)
                == true) {
              GPFlag = true;
            }
          }
        });
    CancelBut = new Button(SubShell, SWT.PUSH);
    CancelBut.setLayoutData(new GridData());
    CancelBut.setText("Cancel");
    CancelBut.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent Evt) {
            ((Button) Evt.widget).getShell().dispose();
          }
        });
    if (UserProfile == JTC.SERVER) {
      UserNameInp.setText(MainServer.getLocalUserName());
    } else if (UserProfile == JTC.CLIENT) {
      UserNameInp.setText(MainClient.getLocalUserName());
    }
    SubShell.pack();
    SubShell.setLocation(centralize(ParentShell.getBounds(), SubShell));
    SubShell.open();

    while (!SubShell.isDisposed()) {

      if (!SubShell.getDisplay().readAndDispatch()) SubShell.getDisplay().sleep();
      if (GPFlag == true) {
        UserName = UserNameInp.getText();
        SubShell.dispose();
      }
    }
    if (GPFlag == true) {
      if (UserProfile == JTC.SERVER) {
        if (MainServer.setLocalUserName(UserName))
          MainShell.setText("JeremeTalk v1.0 : Welcome " + UserName + " | You are " + UserProfile);
      } else if (UserProfile == JTC.CLIENT) {
        if (MainClient.setLocalUserName(UserName))
          MainShell.setText("JeremeTalk v1.0 : Welcome " + UserName + " | You are " + UserProfile);
      }
    }
  }
예제 #4
0
  public GUI(String Profile, NetworkInterface NetObj) {

    MainDisplay = new Display();
    MainShell = new Shell(MainDisplay);
    Updater = new GUIUpdaterThread(NetObj, this);
    Updater.setDaemon(true);

    // restartOpt=false;
    if (Profile.equals("SERVER") == true) {
      // FIX THIS ASAP
      UserProfile = "SERVER";
      MainServer = (JTServer) NetObj;
      MainServer.test();
      System.out.println(
          "GUI invoked with " + MainServer.getLocalUserIP() + ":" + MainServer.getLocalUserPort());
      MainClient = null;
    } else if (Profile.equals("CLIENT") == true) {
      // FIX THIS ASAP
      UserProfile = "CLIENT";
      MainClient = (JTClient) NetObj;
      MainClient.test();
      MainServer = null;
      System.out.println(
          "GUI invoked with target " + MainClient.getTargetIP() + ":" + MainClient.getTargetPort());
      System.out.println(
          "and client "
              + MainClient.getLocalUserName()
              + "@"
              + MainClient.getLocalUserIP()
              + ":"
              + MainClient.getLocalUserPort());
    } else {
      confirmWin(
          MainShell,
          "Internal Error! No extension of JTNetworkInterface active!",
          jeremeTalk.JTC.OK);
      destroy();
    }

    Calibri = new Font(MainDisplay, "Calibri", 12, SWT.NORMAL);

    Red = new Color(MainDisplay, 0x80, 0, 0);
    Green = new Color(MainDisplay, 0, 0x80, 0);
    Blue = new Color(MainDisplay, 0, 0, 0x80);
    White = new Color(MainDisplay, 0xFF, 0xFF, 0xFF);
    Black = new Color(MainDisplay, 0, 0, 0);
    Gray = new Color(MainDisplay, 0xCC, 0xCC, 0xCC);

    GridLayout GlobalWinGL = new GridLayout();
    GlobalWinGL.numColumns = 3;
    GlobalWinGL.marginHeight = 10;
    GlobalWinGL.marginWidth = 10;
    GlobalWinGL.verticalSpacing = 5;
    GlobalWinGL.horizontalSpacing = 5;

    MainShell.setLayout(GlobalWinGL);

    initWidgets();

    addWidgetListeners();

    MainShell.setMenuBar(GlobalMainMenu);
    MainShell.pack();

    MainShell.setLocation(centralize(MainDisplay.getPrimaryMonitor().getBounds(), MainShell));

    MainShell.setText(
        "JeremeTalk v1.0 : Welcome " + NetObj.getLocalUserName() + " | You are " + UserProfile);

    MainShell.open();
    Updater.start();
    while (!MainShell.isDisposed()) {
      if (!MainDisplay.readAndDispatch()) MainDisplay.sleep();
    }
    if (MainServer == null) MainClient.freePort();
    else MainServer.freePort();
    Updater.kill();
    System.out.println("GUI Destroyed!");
  }
예제 #5
0
  void connectionWin(Shell ParentShell) {

    GPFlag = false;
    GPFlag2 = false;
    Shell SubShell = new Shell(ParentShell.getDisplay());
    GridLayout SubShellGL = new GridLayout();
    SubShell.setLayout(SubShellGL);
    SubShellGL.numColumns = 3;
    SubShellGL.makeColumnsEqualWidth = false;

    String Portval = "", IPval2 = "", Portval2 = "";

    Label ServerIPLab, ServerIPLab2, ServerPortLab, ServerPortLab2;
    Text ServerIPInp, ServerIPInp2, ServerPortInp, ServerPortInp2;
    Button ApplyBut, CancelBut, TestBut;

    ServerIPLab = new Label(SubShell, SWT.NORMAL | SWT.CENTER);
    ServerIPLab.setLayoutData(new GridData());

    ServerIPInp = new Text(SubShell, SWT.SINGLE | SWT.BORDER);
    ServerIPInp.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));

    ServerPortLab = new Label(SubShell, SWT.NORMAL | SWT.CENTER);
    ServerPortLab.setLayoutData(new GridData());

    ServerPortInp = new Text(SubShell, SWT.SINGLE | SWT.BORDER);
    ServerPortInp.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));

    ServerIPLab.setText("Your IP Address :");
    ServerPortLab.setText("Your Connection Port :");

    ServerIPInp.setEnabled(false);

    ServerIPLab2 = null;
    ServerIPInp2 = null;
    ServerPortLab2 = null;
    ServerPortInp2 = null;

    if (UserProfile == JTC.SERVER) {
      ServerIPInp.setText(MainServer.getLocalUserIP());
      ServerPortInp.setText(MainServer.getLocalUserPort());

    } else if (UserProfile == JTC.CLIENT) {
      ServerIPLab2 = new Label(SubShell, SWT.NORMAL | SWT.CENTER);
      ServerIPInp2 = new Text(SubShell, SWT.SINGLE | SWT.BORDER);
      ServerPortLab2 = new Label(SubShell, SWT.NORMAL | SWT.CENTER);
      ServerPortInp2 = new Text(SubShell, SWT.SINGLE | SWT.BORDER);

      ServerIPInp.setText(MainClient.getLocalUserIP());
      ServerPortInp.setText(MainClient.getLocalUserPort());

      ServerIPLab2.setLayoutData(new GridData());

      ServerIPInp2.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));

      ServerPortLab2.setLayoutData(new GridData());

      ServerPortInp2.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));

      ServerIPLab2.setText("Server IP Address :");
      ServerPortLab2.setText("Server Connection Port :");

      ServerIPInp2.setText(MainClient.getTargetIP());
      ServerPortInp2.setText(MainClient.getTargetPort());
    }
    TestBut = new Button(SubShell, SWT.PUSH);
    TestBut.setLayoutData(new GridData());
    TestBut.setText("TEST");
    TestBut.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent Evt) {
            GPFlag2 = true;
          }
        });
    if (UserProfile == JTC.SERVER) TestBut.setEnabled(false);
    ApplyBut = new Button(SubShell, SWT.PUSH);
    ApplyBut.setLayoutData(new GridData());
    ApplyBut.setText("OK");
    ApplyBut.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent Evt) {
            if (confirmWin(
                    ((Button) Evt.widget).getShell(),
                    "Are you sure you want to save changes?",
                    JTC.YESNO)
                == true) {
              GPFlag = true;
            }
          }
        });
    CancelBut = new Button(SubShell, SWT.PUSH);
    CancelBut.setLayoutData(new GridData());
    CancelBut.setText("Cancel");
    CancelBut.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent Evt) {
            ((Button) Evt.widget).getShell().dispose();
          }
        });

    SubShell.pack();
    SubShell.setLocation(centralize(ParentShell.getBounds(), SubShell));
    SubShell.open();

    while (!SubShell.isDisposed()) {

      if (!SubShell.getDisplay().readAndDispatch()) SubShell.getDisplay().sleep();
      if (GPFlag == true) {
        Portval = ServerPortInp.getText();
        if (UserProfile == JTC.CLIENT) {
          IPval2 = ServerIPInp2.getText();
          Portval2 = ServerPortInp2.getText();
        }
        SubShell.dispose();
      }
      if (GPFlag2 == true) {
        if (ServerIPInp.getText().equals(ServerIPInp2.getText())
            && ServerPortInp.getText().equals(ServerPortInp2.getText()))
          confirmWin(SubShell, "Ofcourse you are up and running!", JTC.OK);
        else if (MainClient.testHostActive(ServerIPInp2.getText(), ServerPortInp2.getText())
            == true) confirmWin(SubShell, "The Server is Active!", JTC.OK);
        else confirmWin(SubShell, "The Server is Down!", JTC.OK);
        GPFlag2 = false;
      }
    }
    if (GPFlag == true) {
      if (UserProfile == JTC.SERVER) {
        MainServer.setLocalUserPort(Portval);
      } else if (UserProfile == JTC.CLIENT) {
        MainClient.setLocalUserPort(Portval);
        MainClient.setTargetHostIP(IPval2);
        MainClient.setTargetHostPort(Portval2);
      }
    }
  }