Ejemplo n.º 1
0
  public void init() {

    display = new Display();
    shell = new Shell(display, SWT.SHELL_TRIM);
    shell.setText(TXT_WINDOW_TITLE);

    // shell.setLayout(new GridLayout(2, false));
    shell.setLayout(new GridLayout(1, false));

    initMenus();

    // left pane: whiteboard
    {
      Composite compositeWhiteboard =
          new Composite(shell, SWT.EMBEDDED | SWT.NO_BACKGROUND | SWT.BORDER);

      GridData gdWhiteboard =
          new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);

      compositeWhiteboard.setLayoutData(gdWhiteboard);

      clientWhiteboard = new ClientWhiteboardSWT(compositeWhiteboard);
      clientWhiteboard.init(this);

      clientWhiteboard.setLayoutActive(true);
    }

    // right pane: buttons + comments
    {
      /*
      Composite compositeRight = new Composite(shell, SWT.NONE);
      GridData gdRight = new GridData(GridData.FILL_VERTICAL);

      compositeRight.setLayoutData(gdRight);

      compositeRight.setLayout(new GridLayout());
       */
      Composite compositeBottom = new Composite(shell, SWT.NONE);
      GridData gdBottom = new GridData(GridData.FILL_HORIZONTAL);

      compositeBottom.setLayoutData(gdBottom);

      compositeBottom.setLayout(new GridLayout(3, false));

      // scores
      {
        Composite compositeScores = new Composite(compositeBottom, SWT.NONE);
        compositeScores.setLayout(new GridLayout(1, false));
        compositeScores.setLayoutData(
            new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));

        scores = new Label[TypeScore.values().length];
        scoreslab = new Label[TypeScore.values().length];
        rg = new Label[TypeScore.values().length];
        rglab = new Label[TypeScore.values().length];
        scoreevo = new Label[TypeScore.values().length];
        rgevo = new Label[TypeScore.values().length];
        int i = 0;
        scvalprec = new HashMap<Integer, Double>(TypeScore.values().length, 1.0f);
        scrgprec = new HashMap<Integer, Double>(TypeScore.values().length, 1.0f);
        // AD TXT_TOOLTIP_HIGH_SCORE=new ArrayList(TypeScore.values().length); /*
        TXT_TOOLTIP_HIGH_SCORE = new ArrayList<String>(TypeScore.values().length); // */

        for (TypeScore sc : TypeScore.values()) {
          scvalprec.put(i, (double) 0);
          scrgprec.put(i, (double) 1);
          //					compositeSc.setLayout(new RowLayout(SWT.HORIZONTAL));
          Composite compositeSc = new Composite(compositeScores, SWT.NONE);
          GridLayout layoutName = new GridLayout(6, false);
          GridData gdSc =
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
          compositeSc.setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          compositeSc.setLayout(layoutName);
          compositeSc.setLayoutData(gdSc);

          scoreslab[i] = new Label(compositeSc, SWT.READ_ONLY);
          scoreslab[i].setText(sc.nom + ":");
          scoreslab[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          scoreslab[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          scoreslab[i].setToolTipText(sc.tooltip);
          scores[i] = new Label(compositeSc, SWT.READ_ONLY);
          scores[i].setText(" 0000");
          scores[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          scores[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          TXT_TOOLTIP_HIGH_SCORE.add(i, "High Scores");
          scores[i].setToolTipText(TXT_TOOLTIP_HIGH_SCORE.get(i));
          scoreevo[i] = new Label(compositeSc, SWT.READ_ONLY);
          scoreevo[i].setText(" (==)");
          scoreevo[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          scoreevo[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          rglab[i] = new Label(compositeSc, SWT.READ_ONLY);
          rglab[i].setText(" Rg:");
          rglab[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          rglab[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          rg[i] = new Label(compositeSc, SWT.READ_ONLY);
          rg[i].setText(" 00");
          rg[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          rg[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          rgevo[i] = new Label(compositeSc, SWT.READ_ONLY);
          rgevo[i].setText(" (==)");
          rgevo[i].setBackground(LOOK_COLOR_BACKGROUND_SUBSPACES);
          rgevo[i].setLayoutData(
              new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END));
          i++;
        }

        {
          // init the timer for refreshing this
          display.timerExec(
              PERIOD_REFRESH_SCORES,
              new Runnable() {
                public void run() {
                  majScores();
                  display.timerExec(PERIOD_REFRESH_SCORES, this);
                }
              });
        }
      }

      // comments
      {
        Composite compositeComments = new Composite(compositeBottom, SWT.NONE);

        GridData gdComments = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
        compositeComments.setLayoutData(gdComments);

        compositeComments.setLayout(new GridLayout());

        // it is initialy empty, as no idea is selected
        ideaCommentTree = new Tree(compositeComments, SWT.VIRTUAL | SWT.BORDER);

        ideaCommentTree.setLayoutData(
            new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL | GridData.GRAB_HORIZONTAL));

        // this Rennable is used to refresh comments displayed in the bottom part.
        // what ? this should be somewhere else ? hum... that's called anarchy. Or collaborative
        // work ?
        ideaCommentTreeFillerRunnable =
            new Runnable() {
              @Override
              public void run() {
                selectedIdeas = clientWhiteboard.getSelectionControl().getSelectedIdeas();
                if (!selectedIdeas.isEmpty()) {
                  ideaCommentTree.removeAll();
                  for (IIdea i : selectedIdeas) {
                    try {
                      clientCore.displayIdeaComments(i.getUniqueId(), ideaCommentTreeFiller);
                    } catch (RemoteException e) {
                      displayError("an anormal remote exception happened.", e);
                    }
                  }
                }
              }
            };

        // make the tree resets its data when a new idea is selected
        clientWhiteboard
            .getSelectionControl()
            .addListener(
                new ISelectionListener() {
                  @Override
                  public void notifySelectionChanged() {
                    display.asyncExec(ideaCommentTreeFillerRunnable);
                  }
                });
      }

      // buttons
      {
        Composite compositeButtons = new Composite(compositeBottom, SWT.NONE);

        GridData gdButtons =
            new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);

        compositeButtons.setLayoutData(gdButtons);

        compositeButtons.setLayout(new RowLayout(SWT.VERTICAL));

        buttonAddIdea = new Button(compositeButtons, SWT.PUSH);
        buttonAddIdea.setText("Ajouter une idée");
        buttonAddIdea.addSelectionListener(
            new SelectionListener() {

              @Override
              public void widgetSelected(SelectionEvent arg0) {
                clickCreateIdea();
              }

              @Override
              public void widgetDefaultSelected(SelectionEvent arg0) {
                clickCreateIdea();
              }
            });

        buttonComment = new Button(compositeButtons, SWT.PUSH);
        buttonComment.setText("Commenter / Miser");
        buttonComment.addSelectionListener(
            new SelectionListener() {

              @Override
              public void widgetSelected(SelectionEvent arg0) {
                clickVoteOnIdea();
              }

              @Override
              public void widgetDefaultSelected(SelectionEvent arg0) {
                clickVoteOnIdea();
              }
            });

        buttonAddItem = new Button(compositeButtons, SWT.PUSH);
        buttonAddItem.setText("Ajouter un item");
        buttonAddItem.addSelectionListener(
            new SelectionListener() {

              @Override
              public void widgetSelected(SelectionEvent arg0) {
                clickCreateItem();
              }

              @Override
              public void widgetDefaultSelected(SelectionEvent arg0) {
                clickCreateItem();
              }
            });
      }
    }

    clientCore = new DelegatingClientCore(clientWhiteboard);

    updateStates();

    updateShellTitle();
  }
Ejemplo n.º 2
0
  /** NB: should always be called from the SWT thread. */
  public void majScores() {
    if (modeClient != GuiClientMode.PLAYING) // quick exit
    return;

    try {
      if (clientCore.getGame().getPlayer(getPlayerId()) != null) {
        int i = 0;
        @SuppressWarnings("unused")
        Map<Integer, Double> sctab, sccop;
        for (TypeScore sc : TypeScore.values()) {
          sctab = sc.calculer(clientCore.getGame());

          double scval = sctab.get(getPlayerId());
          // ArrayList val=new ArrayList(sctab.values());
          // Collections.sort(val);

          SortedSet<PlayersScores> sortedScores = PlayersScores.calculer(sctab);

          int rgval = PlayersScores.computeRank(sortedScores, getPlayerId());
          StringBuilder sb = new StringBuilder(sc.nom + '\n');
          @SuppressWarnings("unused")
          int idj;
          int rankCurrent = 1;
          for (PlayersScores currentScore : sortedScores) {
            sb.append(rankCurrent);
            sb.append(": ");
            sb.append(clientCore.getGame().getPlayer(currentScore.idplayer).getShortName());
            sb.append(" (");
            sb.append(currentScore.score);
            sb.append(")\n");
            rankCurrent++;
          }
          TXT_TOOLTIP_HIGH_SCORE.set(i, sb.toString());

          scoreslab[i].setText(sc.nom + "");
          scores[i].setText(" " + (int) scval);
          //				scoreevo[i].setText(" (=)");
          if (scvalprec.get(i) > scval) {
            scoreevo[i].setText("(" + ((int) (scval - scvalprec.get(i))) + ")");
            scoreevo[i].setForeground(display.getSystemColor(SWT.COLOR_RED));
          }
          /*				if (scvalprec.get(i)==scval)
          {
          	scoreevo[i].setText(" (=)");
          	scoreevo[i].setForeground(display.getSystemColor(SWT.COLOR_DARK_GRAY));

          }*/
          if (scvalprec.get(i) < scval) {
            scoreevo[i].setText("(+" + ((int) (scval - scvalprec.get(i))) + ")");
            scoreevo[i].setForeground(display.getSystemColor(SWT.COLOR_BLUE));
          }
          rglab[i].setText(" Rg ");
          rg[i].setText("" + rgval);
          if (scrgprec.get(i) > rgval) {
            rgevo[i].setText("(" + ((int) (rgval - scrgprec.get(i))) + ")");
            rgevo[i].setForeground(display.getSystemColor(SWT.COLOR_BLUE));
          }
          /*				if (scrgprec.get(i)==rgval)
          {
          	rgevo[i].setText(" (=)");
          	rgevo[i].setForeground(display.getSystemColor(SWT.COLOR_DARK_GRAY));

          }*/
          if (scrgprec.get(i) < rgval) {
            rgevo[i].setText("(+" + ((int) (rgval - scrgprec.get(i))) + ")");
            rgevo[i].setForeground(display.getSystemColor(SWT.COLOR_RED));
          }
          scvalprec.put(i, scval);
          scrgprec.put(i, (double) rgval);
          scores[i].setToolTipText(TXT_TOOLTIP_HIGH_SCORE.get(i));
          scoreslab[i].setToolTipText(sc.tooltip);
          i++;
        }
      }
    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }