/*
   * Button or JTextField clicked
   */
  public void switchCards(String s) {
    System.out.println("Switching to " + s);

    CardLayout cl = (CardLayout) (mainPanels.getLayout());
    cl.show(mainPanels, s);
    mainPanels.revalidate();

    CardLayout cl2 = (CardLayout) (sidePanels.getLayout());
    cl2.show(sidePanels, s);
    sidePanels.revalidate();
  }
  // Constructor connection receiving a socket number
  public ClientGUI(String host, int port, int udpPort) {

    super("Clash of Clans");
    defaultPort = port;
    defaultUDPPort = udpPort;
    defaultHost = host;

    // the server name and the port number
    JPanel serverAndPort = new JPanel(new GridLayout(1, 5, 1, 3));
    tfServer = new JTextField(host);
    tfPort = new JTextField("" + port);
    tfPort.setHorizontalAlignment(SwingConstants.RIGHT);

    // CHAT COMPONENTS
    chatStatus = new JLabel("Please login first", SwingConstants.LEFT);
    chatField = new JTextField(18);
    chatField.setBackground(Color.WHITE);

    JPanel chatControls = new JPanel();
    chatControls.add(chatStatus);
    chatControls.add(chatField);
    chatControls.setBounds(0, 0, 200, 50);

    chatArea = new JTextArea("Welcome to the Chat room\n", 80, 80);
    chatArea.setEditable(false);
    JScrollPane jsp = new JScrollPane(chatArea);
    jsp.setBounds(0, 50, 200, 550);

    JPanel chatPanel = new JPanel(null);
    chatPanel.setSize(1000, 600);
    chatPanel.add(chatControls);
    chatPanel.add(jsp);

    // LOGIN COMPONENTS
    mainLogin = new MainPanel();
    mainLogin.add(new JLabel("Main Login"));

    usernameField = new JTextField("user", 15);
    passwordField = new JTextField("password", 15);
    login = new CButton("Login");
    login.addActionListener(this);

    sideLogin = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    sideLogin.add(usernameField);
    sideLogin.add(passwordField);
    sideLogin.add(login);

    // MAIN MENU COMPONENTS
    mainMenu = new MainPanel();
    mmLabel = new JLabel("Main Menu");
    timer = new javax.swing.Timer(1000, this);
    mainMenu.add(mmLabel);

    sideMenu = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmButton = new CButton("Customize Map");
    tmButton = new CButton("Troop Movement");
    gsButton = new CButton("Game Start");
    logout = new CButton("Logout");
    cmButton.addActionListener(this);
    tmButton.addActionListener(this);
    gsButton.addActionListener(this);
    logout.addActionListener(this);
    sideMenu.add(cmButton);
    // sideMenu.add(tmButton);
    sideMenu.add(gsButton);
    sideMenu.add(logout);

    // CM COMPONENTS
    mainCM = new MainPanel(new GridLayout(mapSize, mapSize));
    tiles = new Tile[mapSize][mapSize];
    int tileSize = mainCM.getWidth() / mapSize;
    for (int i = 0; i < mapSize; i++) {
      tiles[i] = new Tile[mapSize];
      for (int j = 0; j < mapSize; j++) {
        tiles[i][j] = new Tile(i, j);
        tiles[i][j].setPreferredSize(new Dimension(tileSize, tileSize));
        tiles[i][j].setSize(tileSize, tileSize);
        tiles[i][j].addActionListener(this);

        if ((i + j) % 2 == 0) tiles[i][j].setBackground(new Color(102, 255, 51));
        else tiles[i][j].setBackground(new Color(51, 204, 51));

        mainCM.add(tiles[i][j]);
      }
    }

    sideCM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmBack = new CButton("Main Menu");
    cmBack.setSize(150, 30);
    cmBack.setPreferredSize(new Dimension(150, 30));
    cmBack.addActionListener(this);
    sideCM.add(cmBack);

    // TM COMPONENTS
    mainTM = new MainPanel(null);
    mapTM = new Map(600);
    mapTM.setPreferredSize(new Dimension(600, 600));
    mapTM.setSize(600, 600);
    mapTM.setBounds(0, 0, 600, 600);
    mainTM.add(mapTM);

    sideTM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    tmBack = new CButton("Main Menu");
    tmBack.setSize(150, 30);
    tmBack.setPreferredSize(new Dimension(150, 30));
    tmBack.addActionListener(this);
    sideTM.add(tmBack);

    JRadioButton button;
    ButtonGroup group;

    ub = new ArrayList<JRadioButton>();
    group = new ButtonGroup();

    button = new JRadioButton("Barbarian");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    button = new JRadioButton("Archer");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    createBuildings();
    bb = new ArrayList<JRadioButton>();

    group = new ButtonGroup();

    JRadioButton removeButton = new JRadioButton("Remove Building");
    bb.add(removeButton);
    sideCM.add(removeButton);
    group.add(removeButton);

    for (int i = 0; i < bList.size(); i++) {
      button = new JRadioButton(bList.get(i).getName() + '-' + bList.get(i).getQuantity());
      bb.add(button);
      sideCM.add(button);
      group.add(button);
    }

    mainPanels = new MainPanel(new CardLayout());
    mainPanels.add(mainLogin, "Login");
    mainPanels.add(mainMenu, "Menu");
    mainPanels.add(mainCM, "CM");
    mainPanels.add(mainTM, "TM");

    sidePanels = new SidePanel(new CardLayout());
    sidePanels.add(sideLogin, "Login");
    sidePanels.add(sideMenu, "Menu");
    sidePanels.add(sideCM, "CM");
    sidePanels.add(sideTM, "TM");

    JPanel mainPanel = new JPanel(null);
    mainPanel.setSize(1000, 600);
    mainPanel.add(sidePanels);
    mainPanel.add(mainPanels);
    mainPanel.add(chatPanel);

    add(mainPanel, BorderLayout.CENTER);

    try {
      setIconImage(ImageIO.read(new File("images/logo.png")));
    } catch (IOException exc) {
      exc.printStackTrace();
    }

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(1000, 600);
    setVisible(true);
    setResizable(false);
    chatField.requestFocus();
  }
 public PlaybackPanel getPlaybackPanel() {
   return mainPanel.getPlaybackPanel();
 }
Example #4
0
  public SaveDialog(Frame parent) {
    super(parent, true);
    this.setLayout(new BorderLayout());
    // gather unsaved tab
    Set<Tab> unsaved = new LinkedHashSet<>();
    for (Tab tab : MainPanel.getAllTab()) {
      if (!tab.isSaved()) {
        unsaved.add(tab);
      }
    }
    if (unsaved.isEmpty()) {
      // close directly
      this.setTitle("Confirm close");
      // upper labels
      JPanel labels = new JPanel(new FlowLayout(FlowLayout.LEFT, 11, 7));
      labels.add(iconLabel);
      labels.add(new MyLabel(" Do you really want to close RefluxEdit?"));
      // buttons
      JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7));
      buttons.add(
          new MyButton("YES") {
            {
              SaveDialog.this.getRootPane().setDefaultButton(this);
              this.setFocusPainted(true);
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              close = true;
              SaveDialog.this.setVisible(false);
            }
          });
      buttons.add(
          new MyButton("NO") {
            {
              this.setFocusPainted(true);
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              close = false;
              SaveDialog.this.setVisible(false);
            }
          });
      buttons.setBorder(new EmptyBorder(0, 0, 5, 0));
      //
      this.add(labels, BorderLayout.CENTER);
      this.add(buttons, BorderLayout.PAGE_END);
    } else {
      // ask save changes
      this.setTitle("Unsaved changes");
      // upper components: icon and list
      JPanel upper = new JPanel(new GridBagLayout());
      JPanel listPane = new JPanel(new BorderLayout());
      final DefaultListModel<Tab> listModel = new DefaultListModel<>();
      final JList<Tab> tabList = new JList<>(listModel);
      tabList.setFont(f13);
      tabList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
      tabList.setCellRenderer(
          new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(
                JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
              JLabel label =
                  (JLabel)
                      (super.getListCellRendererComponent(
                          list, value, index, isSelected, cellHasFocus));
              if (value instanceof Tab) {
                String text = ((Tab) value).getTabLabel().getText();
                label.setText(text.substring(1)); // remove "*"
              }
              return label;
            }
          });
      for (Tab tab : unsaved) {
        listModel.addElement(tab);
      }
      tabList.getSelectionModel().setSelectionInterval(0, listModel.size() - 1);
      JScrollPane scrollPane = new JScrollPane(tabList);
      scrollPane.setPreferredSize(new Dimension(350, 170));
      listPane.add(new MyLabel("The following tabs are unsaved:"), BorderLayout.PAGE_START);
      listPane.add(scrollPane, BorderLayout.CENTER);
      // setup upper
      GridBagConstraints c = new GridBagConstraints();
      c.gridx = 0;
      c.gridy = 0;
      c.weightx = 0;
      c.weighty = 1;
      c.insets = new Insets(5, 5, 5, 5);
      c.anchor = GridBagConstraints.FIRST_LINE_START;
      upper.add(iconLabel, c);
      //
      c.gridx = 1;
      c.weightx = 1;
      c.fill = GridBagConstraints.BOTH;
      upper.add(listPane, c);
      // lower components: buttons
      JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7));
      buttons.add(
          new MyButton("Save") {
            {
              this.setFocusPainted(true);
              this.setToolTipText("Save selected tab(s)");
              SaveDialog.this.getRootPane().setDefaultButton(this);
              if (isMetal) {
                this.setPreferredSize(METAL_BUTTON_DIZE);
              }
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              for (Tab tab : tabList.getSelectedValuesList()) {
                if (tab.getFile() != null) {
                  try {
                    tab.save();
                    MainPanel.close(tab);
                    listModel.removeElement(tab);
                  } catch (Exception ex) {
                    exception(ex);
                    break;
                  }
                } else {
                  File file =
                      FileChooser.showPreferredFileDialog(
                          RefluxEdit.getInstance(), FileChooser.SAVE, new String[0]);
                  if (file != null) {
                    try {
                      tab.save(file, false);
                      MainPanel.close(tab);
                      listModel.removeElement(tab);
                    } catch (Exception ex) {
                      exception(ex);
                      break;
                    }
                  }
                }
              }
              if (listModel.size() == 0) {
                RefluxEdit.getInstance().close();
              }
            }
          });
      buttons.add(
          new MyButton("Discard") {
            {
              this.setFocusPainted(true);
              this.setToolTipText("Discard selected tab(s)");
              if (isMetal) {
                this.setPreferredSize(METAL_BUTTON_DIZE);
              }
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              for (Tab tab : tabList.getSelectedValuesList()) {
                MainPanel.close(tab);
                listModel.removeElement(tab);
              }
              if (listModel.size() == 0) {
                RefluxEdit.getInstance().close();
              }
            }
          });
      buttons.add(
          new MyButton("Close") {
            {
              this.setFocusPainted(true);
              this.setToolTipText("Close RefluxEdit");
              if (isMetal) {
                this.setPreferredSize(METAL_BUTTON_DIZE);
              }
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              SaveDialog.this.close = true;
              SaveDialog.this.setVisible(false);
            }
          });
      buttons.add(
          new MyButton("Cancel") {
            {
              this.setFocusPainted(true);
              if (isMetal) {
                this.setPreferredSize(METAL_BUTTON_DIZE);
              }
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              SaveDialog.this.close = false;
              SaveDialog.this.setVisible(false);
            }
          });
      this.add(upper, BorderLayout.CENTER);
      this.add(buttons, BorderLayout.PAGE_END);
    }
  }