Esempio n. 1
0
  /**
   * Sets the current Tool, the right listeners and the Cursor
   *
   * @param tool, Tool to set as current
   * @param button, JButton to set as current
   */
  public void setTool(Tool tool, JButton button) {
    // IF NO CURSORTOOL
    if (this.currentTool instanceof CursorTool && !(tool instanceof CursorTool)) {
      board.removeMouseListener(listeners[0]);

      // IF CURSORTOOL
    } else if (tool instanceof CursorTool && !(this.currentTool instanceof CursorTool)) {

      board.addMouseListener(listeners[0]);
    }
    if (tool == null) throw new IllegalArgumentException("Tool must not be null.");

    if (this.currentTool != tool) {
      if (this.currentButton != null) {
        this.currentButton.setEnabled(true);
      }
      this.currentButton = button;
      this.currentTool = tool;
    }
    if (tool instanceof CursorTool || tool instanceof ArrowTool || tool instanceof TextBoxTool) {
      board.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    } else {
      board.setCursor(tool.getItemType().getCursor());
    }
  }
Esempio n. 2
0
  /** Creates the WorkingView */
  private void createWorkingView() {
    workingViewLabels = getResourceBundle(tbe.getLang());
    this.setLayout(new BorderLayout());
    this.setBackground(Color.WHITE);
    Invoker.getInstance().clear();

    // Toolbar
    this.add(toolbar, BorderLayout.NORTH);

    // Attributebar
    sideBar = new SideBar(board);
    this.add(sideBar, BorderLayout.WEST);

    // gemeinsames Panel für Board und Legend
    rightPanel.setLayout(new BorderLayout());

    rightPanel.add(new JScrollPane(board), BorderLayout.CENTER);
    class ViewMouseListener extends MouseAdapter {
      public void mousePressed(MouseEvent e) {
        if (e.getButton() == 3 && !(currentTool instanceof CursorTool)) {
          setTool(cursorTool, cursorButton);
        } else {
          Point p = new Point(e.getX(), e.getY());
          WorkingView.this.getTool().mouseDown(p.x, p.y, e);
        }
        if (currentTool instanceof ArrowTool || currentTool instanceof TextBoxTool) {
          setTool(cursorTool, cursorButton);
        }
        board.requestFocus();
      }

      public void mouseReleased(MouseEvent e) {

        checkDefaultButtonVisibility();
      }
    }
    initDefaultTools();

    initSportTools();

    listeners[0] = board.getMouseListeners()[0];
    listeners[1] = new ViewMouseListener();
    board.addMouseListener(listeners[1]);

    // Legend
    legendBar = new LegendBar(board);
    rightPanel.add(legendBar, BorderLayout.SOUTH);

    this.add(rightPanel, BorderLayout.CENTER);
    this.activatePoints(false);

    tbe.getMenu().setVisibleToolbar(!this.toolbar.isVisible());
    tbe.getMenu().setVisibleLegend(!this.legendBar.isVisible());
    tbe.getMenu().setVisibleSidebar(!this.sideBar.isVisible());
  }
Esempio n. 3
0
 public TetrisWindow(String hostName, int serverPortNumber) throws IOException {
   super("Rainbow Tetris");
   connection = new TetrisClient(hostName, serverPortNumber);
   myID = connection.getID();
   board = new Board();
   message = new JLabel("Waiting for two players to connect.", JLabel.CENTER);
   board.setBackground(Color.WHITE);
   board.setPreferredSize(new Dimension(300, 660));
   board.addMouseListener(
       new MouseAdapter() {
         public void mousePressed(MouseEvent evt) {
           doMouseClick();
         }
       });
   message.setBackground(Color.LIGHT_GRAY);
   message.setOpaque(true);
   JPanel content = new JPanel();
   content.setLayout(new BorderLayout(2, 2));
   content.setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
   content.setBackground(Color.GRAY);
   content.add(board, BorderLayout.CENTER);
   content.add(message, BorderLayout.SOUTH);
   setContentPane(content);
   pack();
   setResizable(false);
   setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent evt) {
           dispose();
           connection.disconnect();
           try {
             Thread.sleep(333);
           } catch (InterruptedException e) {
           }
           System.exit(0);
         }
       });
   setLocation(200, 100);
   setVisible(true);
 }