/** Initializes this panel. */
  private void init() {
    JPanel mainPanel = new TransparentPanel(new BorderLayout());

    mainPanel.setBorder(
        BorderFactory.createTitledBorder(
            Sip2SipAccRegWizzActivator.getResources()
                .getI18NString("plugin.sipaccregwizz.CREATE_ACCOUNT_TITLE")));

    JPanel labelsPanel = new TransparentPanel(new GridLayout(0, 1));

    JPanel valuesPanel = new TransparentPanel(new GridLayout(0, 1));

    JLabel usernameLabel =
        new JLabel(
            Sip2SipAccRegWizzActivator.getResources()
                .getI18NString("plugin.sip2sipaccregwizz.USERNAME"));

    JLabel displayNameLabel =
        new JLabel(
            Sip2SipAccRegWizzActivator.getResources()
                .getI18NString("plugin.sipaccregwizz.DISPLAY_NAME"));

    JLabel passLabel =
        new JLabel(Sip2SipAccRegWizzActivator.getResources().getI18NString("service.gui.PASSWORD"));

    JLabel retypePasswordLabel =
        new JLabel(
            Sip2SipAccRegWizzActivator.getResources()
                .getI18NString("plugin.sip2sipaccregwizz.RETYPE_PASSWORD"));

    JLabel emailLabel =
        new JLabel(
            Sip2SipAccRegWizzActivator.getResources()
                .getI18NString("plugin.sip2sipaccregwizz.EMAIL"));

    labelsPanel.add(displayNameLabel);
    labelsPanel.add(usernameLabel);
    labelsPanel.add(passLabel);
    labelsPanel.add(retypePasswordLabel);
    labelsPanel.add(emailLabel);

    valuesPanel.add(displayNameField);
    valuesPanel.add(usernameField);
    valuesPanel.add(passField);
    valuesPanel.add(retypePassField);
    valuesPanel.add(emailField);

    JLabel emailDescriptionLabel =
        new JLabel(
            Sip2SipAccRegWizzActivator.getResources()
                .getI18NString("plugin.sip2sipaccregwizz.EMAIL_NOTE"),
            SwingConstants.CENTER);
    emailDescriptionLabel.setForeground(Color.GRAY);
    emailDescriptionLabel.setFont(emailDescriptionLabel.getFont().deriveFont(8));
    emailDescriptionLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 8, 10));

    initErrorArea();

    mainPanel.add(labelsPanel, BorderLayout.WEST);
    mainPanel.add(valuesPanel, BorderLayout.CENTER);
    mainPanel.add(emailDescriptionLabel, BorderLayout.SOUTH);

    this.add(mainPanel, BorderLayout.CENTER);

    JLabel infoLabel =
        new JLabel(
            Sip2SipAccRegWizzActivator.getResources()
                .getI18NString("plugin.sip2sipaccregwizz.INFO_NOTE"),
            SwingConstants.RIGHT);
    infoLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    infoLabel.setForeground(Color.GRAY);
    infoLabel.setFont(emailDescriptionLabel.getFont().deriveFont(8));
    infoLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
    infoLabel.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            Sip2SipAccRegWizzActivator.getBrowserLauncher().openURL("http://wiki.sip2sip.info");
          }
        });

    this.add(infoLabel, BorderLayout.SOUTH);
  }
Exemplo n.º 2
0
  /**
   * Returns a JPanel that represents the mancala board using strategy pattern to insert style.
   *
   * @param strat concrete strategy
   * @return JPanel containing both users' pits as controllers
   */
  public JPanel boardContextDoWork(Strategy strat) {
    this.s = strat;
    Color boardColor = s.getBoardColor();
    Color fontColor = s.getFontColor();
    Font font = s.getFont();
    JPanel panCenter = new JPanel();
    JPanel panLeft = new JPanel();
    JPanel panRight = new JPanel();

    panCenter.setLayout(new GridLayout(2, 6, 10, 10));
    // B6 to B1 Controllers
    for (int i = 12; i > 6; i--) {
      final Pits temp = new Pits(i);
      final int pit = i;
      final JLabel tempLabel = new JLabel(temp);
      tempLabel.addMouseListener(
          new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
              if (Model.player == 1) {
                JFrame frame = new JFrame();
                JOptionPane.showMessageDialog(frame, "Player A's turn!");
              } else if (model.data[pit] == 0) {
                JFrame frame = new JFrame();
                JOptionPane.showMessageDialog(frame, "Pit is Empty try another one.");
              } else {
                if (temp.pitShape.contains(e.getPoint())) {
                  model.move(pit); // mutator
                  undoBtn.setText("Undo : " + model.getUndoCounter());
                  model.display();
                }
              }
            }
          });
      JPanel tempPanel = new JPanel(new BorderLayout());

      JTextPane textPane = new JTextPane();
      textPane.setEditable(false);
      textPane.setBackground(boardColor);
      textPane.setForeground(fontColor);
      textPane.setFont(font);
      textPane.setText("B" + (i - 6));
      StyledDocument doc = textPane.getStyledDocument();
      SimpleAttributeSet center = new SimpleAttributeSet();
      StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
      doc.setParagraphAttributes(0, doc.getLength(), center, false);
      tempPanel.add(textPane, BorderLayout.NORTH);
      tempPanel.add(tempLabel, BorderLayout.SOUTH);
      panCenter.add(tempPanel, BorderLayout.SOUTH);

      tempPanel.setBackground(boardColor);
    }
    // A1 to A6 Controllers
    for (int i = 0; i < 6; i++) {
      final Pits newPits = new Pits(i);
      JLabel label = new JLabel(newPits);
      final int pit = i;
      label.addMouseListener(
          new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
              if (Model.player == 2) {
                JFrame frame = new JFrame();
                JOptionPane.showMessageDialog(frame, "Player B's turn!");
              } else if (model.data[pit] == 0) {
                JFrame frame = new JFrame();
                JOptionPane.showMessageDialog(frame, "Pit is Empty try another one.");
              } else {
                if (newPits.pitShape.contains(e.getPoint())) {
                  model.move(pit); // mutator
                  undoBtn.setText("Undo : " + model.getUndoCounter());
                  model.display();
                }
              }
            }
          });
      JPanel tempPanel = new JPanel(new BorderLayout());

      tempPanel.add(label, BorderLayout.NORTH);
      JTextPane textPane = new JTextPane();
      textPane.setBackground(boardColor);
      textPane.setForeground(fontColor);
      textPane.setFont(font);
      textPane.setEditable(false);
      textPane.setText("A" + (i + 1));
      StyledDocument doc = textPane.getStyledDocument();
      SimpleAttributeSet center = new SimpleAttributeSet();
      StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
      doc.setParagraphAttributes(0, doc.getLength(), center, false);
      tempPanel.add(textPane, BorderLayout.SOUTH);
      tempPanel.setBackground(boardColor);
      panCenter.add(tempPanel, BorderLayout.SOUTH);
    }

    // left text pane
    JTextPane paneLeft = new JTextPane();
    paneLeft.setBackground(boardColor);
    paneLeft.setForeground(fontColor);
    paneLeft.setFont(font);
    paneLeft.setEditable(false);
    paneLeft.setText("M\nA\nN\nC\nA\nL\nA\n \nB");

    // right text pane
    JTextPane paneRight = new JTextPane();
    paneRight.setBackground(boardColor);
    paneRight.setForeground(fontColor);
    paneRight.setFont(font);
    paneRight.setEditable(false);
    paneRight.setText("M\nA\nN\nC\nA\nL\nA\n \nA");

    // Add text panes to left and right panels
    panLeft.setLayout(new BorderLayout());
    panRight.setLayout(new BorderLayout());
    panLeft.add(paneLeft, BorderLayout.WEST);
    panRight.add(paneRight, BorderLayout.EAST);
    panLeft.add(new JLabel(new Pits(13)), BorderLayout.EAST);
    panRight.add(new JLabel(new Pits(6)), BorderLayout.WEST);

    // add the 2 mancala panels and pit panel to larger displayPanel
    JPanel displayPanel = new JPanel();
    displayPanel.add(panLeft, BorderLayout.WEST);
    displayPanel.add(panCenter, BorderLayout.CENTER);
    displayPanel.add(panRight, BorderLayout.EAST);

    // set color
    panCenter.setBackground(boardColor);
    panLeft.setBackground(boardColor);
    panRight.setBackground(boardColor);
    displayPanel.setBackground(boardColor);

    // return display panel which contains the containers and elements created
    return displayPanel;
  }
Exemplo n.º 3
0
  /** Initializes the graphical components */
  public void init() {
    username = getParameter("username");
    if (username == null) {
      username =
          JOptionPane.showInputDialog(
              this, "Please enter a username", "Login", JOptionPane.QUESTION_MESSAGE);
    }
    try {
      PORT = Integer.valueOf(getParameter("port")).intValue();
    } catch (NumberFormatException e) {
      PORT = 42412;
    }

    URL url = getDocumentBase();
    site = url.getHost();
    locationURL = "http://" + site + ":" + url.getPort() + "/" + url.getPath();

    setSize(615, 362);
    c = getContentPane();

    c.setBackground(new Color(224, 224, 224));

    if (site == null || locationURL == null) {
      c.add(new JLabel("ERROR: did not recieve needed data from page"));
    }

    myAction = new MyAction();
    myKeyListener = new MyKeyListener();
    myMouseListener = new MyMouseListener();
    myHyperlinkListener = new MyHyperlinkListener();

    c.setLayout(null);

    cboChannels = new JComboBox();
    cboChannels.setBounds(5, 5, 150, 24);

    butChannel = new JButton("Join");
    butChannel.setToolTipText("Join channel");
    butChannel.addActionListener(myAction);
    butChannel.setBounds(160, 5, 60, 24);

    butCreate = new JButton("Create");
    butCreate.setToolTipText("Create new channel");
    butCreate.addActionListener(myAction);
    butCreate.setBounds(230, 5, 100, 24);
    butCreate.setEnabled(false);

    butInvite = new JButton("Invite");
    butInvite.setToolTipText("Invite Friend");
    butInvite.addActionListener(myAction);
    butInvite.setBounds(340, 5, 80, 24);

    mainChat = new ChatPane(this);
    textScroller =
        new JScrollPane(
            mainChat,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    textScroller.setBounds(5, 34, 500, 270);

    userList = new JList();
    userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    userList.setCellRenderer(new MyCellRenderer());
    userList.setBackground(new Color(249, 249, 250));
    JScrollPane userScroller = new JScrollPane(userList);
    userScroller.setBounds(510, 34, 100, 297);

    messageText = new JTextField();
    messageText.setBounds(5, 309, 500, 22);
    messageText.setColumns(10);
    messageText.setBackground(new Color(249, 249, 250));

    JMenuItem item;
    popup = new JPopupMenu("test");
    popup.add("whisper").addActionListener(myAction);
    popup.add("private message").addActionListener(myAction);
    popup.add("ignore").addActionListener(myAction);
    popup.add("clear ignore list").addActionListener(myAction);

    conNo = new ImageIcon(getURL("images/connect_no.gif"));
    conYes = new ImageIcon(getURL("images/connect_established.gif"));
    secNo = new ImageIcon(getURL("images/decrypted.gif"));
    secYes = new ImageIcon(getURL("images/encrypted.gif"));

    conIcon = new JLabel(conNo);
    conIcon.setBorder(new EtchedBorder());
    secIcon = new JLabel(secNo);
    secIcon.setBorder(new EtchedBorder());

    conIcon.setBounds(563, 334, 22, 22);
    secIcon.setBounds(588, 334, 22, 22);

    bottomText =
        new JLabel(
            "<html><body><font color=#445577><b>"
                + "LlamaChat "
                + VERSION
                + "</b></font> &nbsp;&copy; "
                + "<a href=\""
                + linkURL
                + "\">Joseph Monti</a> 2002-2003"
                + "</body></html>");
    bottomText.setBounds(5, 336, 500, 20);

    c.add(cboChannels);
    c.add(butChannel);
    c.add(butCreate);
    c.add(butInvite);
    c.add(textScroller);
    c.add(userScroller);
    c.add(messageText);
    c.add(conIcon);
    c.add(secIcon);
    c.add(bottomText);

    userList.addMouseListener(myMouseListener);
    messageText.addKeyListener(myKeyListener);
    bottomText.addMouseListener(myMouseListener);

    users = new ArrayList();
    ignores = new ArrayList(5);
    afks = new ArrayList(5);
    admins = new ArrayList(5);
    history = new CommandHistory(10);
    admin = false;
    channels = new Hashtable();
    privates = new PrivateMsg(this);
    showUserStatus = false;

    myColors[0] = new Color(200, 0, 0);
    myColors[1] = new Color(0, 150, 0);
    myColors[2] = new Color(0, 0, 200);

    rect = new Rectangle(0, 0, 1, 1);

    String opening =
        "<font color=#333333>"
            + "==================================<br>"
            + "Welcome to LlamaChat "
            + VERSION
            + "<br>"
            + "If you need assistance, type \\help<br>"
            + "Enjoy your stay!<br>"
            + "Maestria Aplicada en Redes<br>"
            + "==================================<br></font>";
    HTMLDocument doc = (HTMLDocument) mainChat.getDocument();
    HTMLEditorKit kit = (HTMLEditorKit) mainChat.getEditorKit();
    try {
      kit.insertHTML(doc, doc.getLength(), opening, 0, 0, HTML.Tag.FONT);
    } catch (Throwable t) {
      t.printStackTrace(System.out);
    }

    // validate the name
    if (!username.matches("[\\w_-]+?")) {
      error(
          "username contains invalid characters, changing to "
              + "'invalid' for now. "
              + "Type \\rename to chose a new name");
      username = "******";
    }
    if (username.length() > 10) {
      username = username.substring(0, 10);
      error("username too long, changed to " + username);
    }

    connect();
  }