⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userpanel.java

📁 简介: 一款用JAVA制作开发的小型聊天软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package at.ac.uni_linz.tk.vchat;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;


/**
 * A UserPanel is used for displaying and editing User-data, including color
 * settings, password changement, Images and keywords for different moods.
 *
 * @author      Arno Huetter
 * (C)opyright by the Institute for Computer Science, Telecooperation Department, University of Linz
 */

public class UserPanel extends Panel {

  static final double PORTRAIT_SCALE = 0.6;

  ChatApplet chatApplet;

  InsetsPanel userDataPanel;
  Panel avatarPanelLevel2, colorPasswordPanel;
  FramedPanel namePanel, infoPanel, colorPanel, passwordPanel, avatarPanelLevel1;
  TextField nameField, roomField, loginDateField, emailField, homepageField, oldPasswordField, newPasswordField1, newPasswordField2;
  TextArea infoArea;
  Vector singleAvatarPanel, avatarURLField, avatarKeywordsField, avatarCanvas, iconCanvas, webAvatarCheck, serverAvatarCheck, avatarGroup, serverAvatarChoice, moodNameField, moodTimeoutField;
  PortraitCanvas currentPortraitCanvas;
  Scrollbar redBar, greenBar, blueBar;
  ScrollPane avatarScrollPane;


/**
 * Constructs the UserPanel.
 *
 * @param chatParam      the ChatApplet which administrates the
 *                                Users
 */

  public UserPanel(ChatApplet chatParam) {

    super();

    Image image;
    GridBagConstraints constraints;

    Label label;

    chatApplet = chatParam;

    namePanel = new FramedPanel("User", ChatRepository.INSETS);
    namePanel.setLayout(new GridBagLayout());
    currentPortraitCanvas = new PortraitCanvas();
    currentPortraitCanvas.setSize((int)(ChatRepository.PORTRAIT_DIMENSION.width * PORTRAIT_SCALE), (int)(ChatRepository.PORTRAIT_DIMENSION.height * PORTRAIT_SCALE));
    ChatUtil.addWithRemainingConstraints(namePanel, currentPortraitCanvas, ChatRepository.SMALL_INSETS);
    ChatUtil.addWithBeginningConstraints(namePanel, new Label("Name: ", Label.RIGHT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(namePanel, nameField = new TextField(), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithBeginningConstraints(namePanel, new Label("Room: ", Label.RIGHT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(namePanel, roomField = new TextField(), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithBeginningConstraints(namePanel, new Label("Online since: ", Label.RIGHT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(namePanel, loginDateField = new TextField(), ChatRepository.SMALL_INSETS);
    nameField.setEditable(false);
    roomField.setEditable(false);
    loginDateField.setEditable(false);
    currentPortraitCanvas.setDrawFrame(true);

    infoPanel = new FramedPanel("Info", ChatRepository.INSETS);
    infoPanel.setLayout(new GridBagLayout());
    ChatUtil.addWithRemainingConstraints(infoPanel, new Label("E-Mail:", Label.LEFT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(infoPanel, emailField = new TextField(), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(infoPanel, new Label("Homepage:", Label.LEFT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(infoPanel, homepageField = new TextField(), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(infoPanel, new Label("Info:", Label.LEFT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(infoPanel, infoArea = new TextArea("", 3, 25, TextArea.SCROLLBARS_NONE), ChatRepository.SMALL_INSETS);

    colorPanel = new FramedPanel("Color", ChatRepository.INSETS);
    colorPanel.setLayout(new GridBagLayout());
    ChatUtil.addWithBeginningConstraints(colorPanel, new Label("Red: ", Label.RIGHT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(colorPanel, redBar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, ChatRepository.MAX_COLOR_VALUE), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithBeginningConstraints(colorPanel, new Label("Green: ", Label.RIGHT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(colorPanel, greenBar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, ChatRepository.MAX_COLOR_VALUE), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithBeginningConstraints(colorPanel, new Label("Blue: ", Label.RIGHT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(colorPanel, blueBar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, ChatRepository.MAX_COLOR_VALUE), ChatRepository.SMALL_INSETS);

    passwordPanel = new FramedPanel("Password", ChatRepository.INSETS);
    passwordPanel.setLayout(new GridBagLayout());
    ChatUtil.addWithBeginningConstraints(passwordPanel, new Label("Old:", Label.RIGHT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(passwordPanel, oldPasswordField = new TextField(), ChatRepository.SMALL_INSETS);
    oldPasswordField.setEchoChar('*');
    ChatUtil.addWithBeginningConstraints(passwordPanel, new Label("New:", Label.RIGHT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(passwordPanel, newPasswordField1 = new TextField(), ChatRepository.SMALL_INSETS);
    newPasswordField1.setEchoChar('*');
    ChatUtil.addWithBeginningConstraints(passwordPanel, new Label("New (Verify):", Label.RIGHT), ChatRepository.SMALL_INSETS);
    ChatUtil.addWithRemainingConstraints(passwordPanel, newPasswordField2 = new TextField(), ChatRepository.SMALL_INSETS);
    newPasswordField2.setEchoChar('*');

    colorPasswordPanel = new Panel();
    colorPasswordPanel.setLayout(new GridLayout(2, 1));
    if (chatApplet.getBooleanParam("ExtendedAvatarConfigVisibility", true)) {
      colorPasswordPanel.add(colorPanel);
    }
    colorPasswordPanel.add(passwordPanel);

    userDataPanel = new InsetsPanel();
    userDataPanel.setLayout(new GridLayout(1, 3));
    userDataPanel.add(namePanel);
    userDataPanel.add(infoPanel);
    userDataPanel.add(colorPasswordPanel);

    avatarCanvas = new Vector();
    iconCanvas = new Vector();
    singleAvatarPanel = new Vector();
    avatarURLField = new Vector();
    avatarKeywordsField = new Vector();
    moodNameField = new Vector();
    moodTimeoutField = new Vector();

    webAvatarCheck = new Vector();
    serverAvatarCheck = new Vector();
    avatarGroup = new Vector();
    serverAvatarChoice = new Vector();

    avatarPanelLevel2 = new Panel();

    avatarScrollPane = new ScrollPane();
    avatarScrollPane.add(avatarPanelLevel2);

    for (int i = 0; i <= ChatRepository.PREDEFINED_NR_OF_MOODS; i++) {
      addAvatarPanel();
    }

    avatarPanelLevel1 = new FramedPanel("Avatars", ChatRepository.INSETS);
    avatarPanelLevel1.setLayout(new BorderLayout());
    avatarPanelLevel1.add(avatarScrollPane, "Center");

    setLayout(new BorderLayout());
    setFont(ChatRepository.STANDARD_FONT);

    add(userDataPanel, "North");
    add(avatarPanelLevel1, "Center");
  }


/**
 * Displays the data of a given User within the UserPanel.
 *
 * @param userParam      the User whose data should be displayed
 */

  public void showUser(User userParam) {
    Image image;

    currentPortraitCanvas.setImage(chatApplet.getUserAvatar(userParam.getId()));
    currentPortraitCanvas.setFrameColor(userParam.getColor());
    nameField.setText(userParam.getName());
    roomField.setText(chatApplet.getRoom(userParam.getRoom()).getName());
    loginDateField.setText(DateFormat.getTimeInstance().format(userParam.getLoginDate()));
    emailField.setText(userParam.getEmail());
    homepageField.setText(userParam.getHomepage());
    infoArea.setText(userParam.getInfo());
    redBar.setValue(userParam.getColor().getRed());
    greenBar.setValue(userParam.getColor().getGreen());
    blueBar.setValue(userParam.getColor().getBlue());

//    removeAllAvatarPanels();

    for (int i = ChatRepository.PREDEFINED_NR_OF_MOODS; i > userParam.getNrOfMoods(); i++) {
      removeLastAvatarPanel();
    }

    for (int i = 0; i <= userParam.getNrOfMoods(); i++) {
      if (i >= getNrOfAvatarPanels()) {
        addAvatarPanel();
      }
      if (i == 0) {
        ((PortraitCanvas)avatarCanvas.firstElement()).setImage(chatApplet.getUserBackAvatar(userParam.getId()));
        ((TextField)avatarURLField.firstElement()).setText(userParam.getBackAvatarURL());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -