private void jbInit() throws Exception {
   border1 = BorderFactory.createEmptyBorder(20, 20, 20, 20);
   contentPane.setBorder(border1);
   contentPane.setLayout(borderLayout1);
   controlsPane.setLayout(gridLayout1);
   gridLayout1.setColumns(1);
   gridLayout1.setHgap(10);
   gridLayout1.setRows(0);
   gridLayout1.setVgap(10);
   okButton.setVerifyInputWhenFocusTarget(true);
   okButton.setMnemonic('O');
   okButton.setText("OK");
   buttonsPane.setLayout(flowLayout1);
   flowLayout1.setAlignment(FlowLayout.CENTER);
   messagePane.setEditable(false);
   messagePane.setText("");
   borderLayout1.setHgap(10);
   borderLayout1.setVgap(10);
   this.setTitle("Subscription Authorization");
   this.getContentPane().add(contentPane, BorderLayout.CENTER);
   contentPane.add(controlsPane, BorderLayout.SOUTH);
   controlsPane.add(responsesComboBox, null);
   controlsPane.add(buttonsPane, null);
   buttonsPane.add(okButton, null);
   contentPane.add(messageScrollPane, BorderLayout.CENTER);
   messageScrollPane.getViewport().add(messagePane, null);
 }
示例#2
0
  public void substarterEnd(String prefix, String userName, String input) {
    System.out.println("ending give");
    if (substarter.end(winNum)) {

      g_start.setEnabled(true);
      g_end.setEnabled(false);

      String winner = substarter.returnWinner(winNum);

      input = "Congrats to the new sub winner: " + winner + "!";
      prefix = "<b><font color=blue>[" + userName + "]:</font></b> ";

      registeredUserList.setText(winner + "\n");

    } else {
      g_start.setEnabled(true);
      g_end.setEnabled(false);

      prefix = "<b><font color=blue>[" + userName + "]:</font></b> ";
      input = "No one entered giveaway, ending giveaway.";
    }
    sock.outputToChannel(input, channelName);
    try {
      toChatScreen(prefix + input, false);
    } catch (IOException | BadLocationException ex) {
      Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  public FindSynonymsActionHandler(String word, int position, Chapter c, AbstractEditorPanel p) {

    this.word = word;
    this.position = position;
    // this.chapter = c;
    this.editorPanel = p;
    this.projectViewer = this.editorPanel.getViewer();

    final FindSynonymsActionHandler _this = this;

    // Show a panel of all the items.
    this.popup =
        new QPopup(
            "Synonyms for: " + word,
            Environment.getIcon(Constants.FIND_ICON_NAME, Constants.ICON_POPUP),
            null);

    JButton close =
        UIUtils.createButton(
            Constants.CLOSE_ICON_NAME, Constants.ICON_MENU, "Click to close", null);

    List<JButton> buts = new ArrayList();
    buts.add(close);

    this.popup.getHeader().setControls(UIUtils.createButtonBar(buts));

    close.addActionListener(
        new ActionAdapter() {

          public void actionPerformed(ActionEvent ev) {

            _this.popup.setVisible(false);

            _this.editorPanel.getEditor().removeHighlight(_this.highlight);
          }
        });

    p.addPopup(this.popup, true, true);
    /*
          this.highlight = this.editorPanel.getEditor ().addHighlight (position,
                                                                       position + word.length (),
                                                                       null,
                                                                       true);
    */
    this.popup.setOpaque(false);
    this.popup.setVisible(false);

    this.popup.setDraggable(this.editorPanel);
  }
示例#4
0
 /** sets this user to be an admin */
 public void setAdmin() {
   admin = true;
   popup.add("kick user").addActionListener(myAction);
   if (chanAdmin) {
     butCreate.setEnabled(true);
   }
 }
示例#5
0
 /**
  * used to manage the connection icons to signify connection and secure status
  *
  * @param b true if connected
  */
 public void setConnected(boolean b) {
   if (b) {
     conIcon.setIcon(conYes);
     conIcon.setToolTipText("Connected");
     secIcon.setIcon(secYes);
     secIcon.setToolTipText("Secure Connection");
     butChannel.setEnabled(true);
   } else {
     conIcon.setIcon(conNo);
     conIcon.setToolTipText("Not Connected");
     secIcon.setIcon(secNo);
     secIcon.setToolTipText("Connection not Secured");
     butChannel.setEnabled(false);
     butCreate.setEnabled(false);
     butInvite.setEnabled(false);
   }
 }
示例#6
0
  public void substarterBegin(String prefix, String userName, String input) {
    if (substarter.start(winNum)) {
      System.out.println("Starting give");
      g_start.setEnabled(false);
      g_end.setEnabled(true);

      registeredUserList.setText("");

      prefix = "<b><font color=blue>[" + userName + "]:</font></b> ";
      input =
          "Substarter giveaway is starting, make sure to register at http://substarter.com/my-account to participate.  Type !substarter for a chance to win a free sub!";
      sock.outputToChannel(input, channelName);
    } else {
      input =
          "<font color='red'>[WARNING]: Giveaway already started, perhaps in another chat window.</font>";
    }

    try {
      toChatScreen(prefix + input, false);
    } catch (IOException | BadLocationException ex) {
      Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  private void initComponents() {
    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

    messagePane.setBackground(contentPane.getBackground());
    messagePane.setEditorKit(new HTMLEditorKit());
    messagePane.setForeground(contentPane.getForeground());

    setSize(450, 360);

    // center the window
    int x = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() - getWidth()) / 2;
    int y = (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() - getHeight()) / 2;
    setLocation(x, y);

    okButton.addActionListener(this);
  }
 public void updateKeyboardUI() {
   if (Skin.VIETNAMESE_KEY.isEnabled()) {
     chkVietnamese.setText(" V ");
     chkVietnamese.setBackground(Color.yellow);
     chkVietnamese.setBorder(BorderFactory.createLineBorder(Color.red, 1));
   } else {
     chkVietnamese.setText(" E ");
     chkVietnamese.setBackground(Color.cyan);
     chkVietnamese.setBorder(BorderFactory.createLineBorder(Color.blue, 1));
   }
 }
 private void jbInit() throws Exception {
   ////////////////////////////////////////////////////////
   // Init LAF
   ////////////////////////////////////////////////////////
   ButtonGroup grpLAF = new ButtonGroup();
   ActionListener lsnLAF =
       new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           int iIndex = mvtLAFItem.indexOf(evt.getSource());
           if (iIndex >= 0) changeLAF(iIndex);
         }
       };
   ////////////////////////////////////////////////////////
   UIManager.LookAndFeelInfo laf =
       new UIManager.LookAndFeelInfo(
           "Kunststoff", "com.incors.plaf.kunststoff.KunststoffLookAndFeel");
   marrLaf = UIManager.getInstalledLookAndFeels();
   int iIndex = 0;
   while (iIndex < marrLaf.length && !marrLaf[iIndex].getName().equals(laf.getName())) iIndex++;
   if (iIndex >= marrLaf.length) {
     UIManager.installLookAndFeel(laf);
     marrLaf = UIManager.getInstalledLookAndFeels();
   }
   for (iIndex = 0; iIndex < marrLaf.length; iIndex++) {
     JMenuItem mnu = new JRadioButtonMenuItem(marrLaf[iIndex].getName());
     mnu.addActionListener(lsnLAF);
     mvtLAFItem.addElement(mnu);
     mnuUI.add(mnu);
     grpLAF.add(mnu);
   }
   mnuUI.addSeparator();
   ////////////////////////////////////////////////////////
   // Init language
   ////////////////////////////////////////////////////////
   ButtonGroup grpLanguage = new ButtonGroup();
   ActionListener lsnLanguage =
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           int iIndex = mvtLanguageItem.indexOf(e.getSource());
           if (iIndex >= 0) changeDictionary((String) mvtLanguage.elementAt(iIndex));
         }
       };
   ////////////////////////////////////////////////////////
   String[] str = MonitorDictionary.getSupportedLanguage();
   for (iIndex = 0; iIndex < str.length; iIndex++) {
     JMenuItem mnu =
         new JRadioButtonMenuItem(MonitorDictionary.getDictionary(str[iIndex]).getLanguage());
     mnu.addActionListener(lsnLanguage);
     mvtLanguage.addElement(str[iIndex]);
     mvtLanguageItem.addElement(mnu);
     mnuUI.add(mnu);
     grpLanguage.add(mnu);
   }
   ////////////////////////////////////////////////////////
   // Add to main menu
   ////////////////////////////////////////////////////////
   mnuMain.removeAll();
   mnuMain.add(mnuSystem);
   mnuSystem.add(mnuSystem_Login);
   mnuSystem.add(mnuSystem_ChangePassword);
   mnuSystem.addSeparator();
   mnuSystem.add(mnuSystem_StopServer);
   mnuSystem.add(mnuSystem_EnableThreads);
   mnuMain.add(mnuUI);
   mnuMain.add(mnuHelp);
   mnuHelp.add(mnuHelp_About);
   ////////////////////////////////////////////////////////
   mnuMain.add(chkVietnamese);
   mnuMain.add(lblStatus);
   ////////////////////////////////////////////////////////
   pnlThread.setTabPlacement(JTabbedPane.LEFT);
   pnlThread.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
   ////////////////////////////////////////////////////////
   tblUser.addColumn("", 1, false);
   tblUser.addColumn("", 2, false, Global.FORMAT_DATE_TIME);
   tblUser.addColumn("", 3, false);
   ////////////////////////////////////////////////////////
   JPanel pnlMessage = new JPanel();
   pnlMessage.setLayout(new GridBagLayout());
   pnlMessage.add(
       new JScrollPane(txtBoard),
       new GridBagConstraints(
           0,
           0,
           2,
           1,
           1.0,
           1.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(2, 2, 2, 2),
           0,
           0));
   pnlMessage.add(
       txtMessage,
       new GridBagConstraints(
           0,
           1,
           1,
           1,
           1.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(2, 2, 2, 2),
           0,
           0));
   pnlMessage.add(
       btnSend,
       new GridBagConstraints(
           1,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(2, 2, 2, 2),
           0,
           0));
   txtBoard.setEditable(false);
   txtBoard.setAutoscrolls(true);
   txtBoard.setContentType("text/html");
   clearAll(txtBoard);
   ////////////////////////////////////////////////////////
   JPanel pnlUserButton = new JPanel(new GridLayout(1, 2, 4, 4));
   pnlUserButton.add(btnKick);
   pnlUserButton.add(btnRefresh);
   ////////////////////////////////////////////////////////
   JPanel pnlManager = new JPanel(new GridBagLayout());
   pnlManager.add(
       new JScrollPane(tblUser),
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           1.0,
           1.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(2, 2, 2, 2),
           0,
           0));
   pnlManager.add(
       pnlUserButton,
       new GridBagConstraints(
           0,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(4, 2, 4, 2),
           0,
           0));
   ////////////////////////////////////////////////////////
   pnlUser.setDividerLocation(320);
   pnlUser.setLeftComponent(pnlManager);
   pnlUser.setRightComponent(pnlMessage);
   pnlUser.setOneTouchExpandable(true);
   ////////////////////////////////////////////////////////
   setOrientation(JSplitPane.VERTICAL_SPLIT);
   setOneTouchExpandable(true);
   pnlThread.setVisible(false);
   pnlUser.setVisible(false);
   setTopComponent(pnlThread);
   setBottomComponent(pnlUser);
   ////////////////////////////////////////////////////////
   pmn.add(mnuSelectAll);
   pmn.addSeparator();
   pmn.add(mnuClearSelected);
   pmn.add(mnuClearAll);
   ////////////////////////////////////////////////////////
   setBorder(BorderFactory.createEmptyBorder());
   pnlUser.setBorder(BorderFactory.createEmptyBorder());
   pnlManager.setBorder(
       BorderFactory.createBevelBorder(
           javax.swing.border.BevelBorder.RAISED,
           Color.white,
           UIManager.getColor("Panel.background"),
           UIManager.getColor("Panel.background"),
           UIManager.getColor("Panel.background")));
   pnlMessage.setBorder(
       BorderFactory.createBevelBorder(
           javax.swing.border.BevelBorder.RAISED,
           Color.white,
           UIManager.getColor("Panel.background"),
           UIManager.getColor("Panel.background"),
           UIManager.getColor("Panel.background")));
   ////////////////////////////////////////////////////////
   Skin.applySkin(mnuMain);
   Skin.applySkin(tblUser);
   Skin.applySkin(pmn);
   Skin.applySkin(this);
   ////////////////////////////////////////////////////////
   // Default setting
   ////////////////////////////////////////////////////////
   Hashtable prt = null;
   try {
     prt = Global.loadHashtable(Global.FILE_CONFIG);
   } catch (Exception e) {
     prt = new Hashtable();
   }
   changeLAF(Integer.parseInt(StringUtil.nvl(prt.get("LAF"), "0")));
   changeDictionary(StringUtil.nvl(prt.get("Language"), "VN"));
   Skin.LANGUAGE_CHANGE_LISTENER = this;
   MonitorProcessor.setRootObject(this);
   updateKeyboardUI();
   ////////////////////////////////////////////////////////
   // Event handler
   ////////////////////////////////////////////////////////
   tblUser.addMouseListener(
       new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           if (e.getClickCount() > 1) btnKick.doClick();
         }
       });
   ////////////////////////////////////////////////////////
   btnRefresh.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           try {
             DDTP request = new DDTP();
             request.setRequestID(String.valueOf(System.currentTimeMillis()));
             DDTP response = channel.sendRequest("ThreadProcessor", "queryUserList", request);
             if (response != null) {
               tblUser.setData((Vector) response.getReturn());
               if (mstrChannel != null) removeUser(mstrChannel);
             }
           } catch (Exception e) {
             e.printStackTrace();
             MessageBox.showMessageDialog(pnlThread, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
           }
         }
       });
   ////////////////////////////////////////////////////////
   btnKick.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           int iSelected = tblUser.getSelectedRow();
           if (iSelected < 0) return;
           int iResult =
               MessageBox.showConfirmDialog(
                   pnlThread,
                   mdic.getString("ConfirmKick"),
                   Global.APP_NAME,
                   MessageBox.YES_NO_OPTION);
           if (iResult == MessageBox.NO_OPTION) return;
           try {
             String strChannel = (String) tblUser.getRow(iSelected).elementAt(0);
             DDTP request = new DDTP();
             request.setRequestID(String.valueOf(System.currentTimeMillis()));
             request.setString("strChannel", strChannel);
             DDTP response = channel.sendRequest("ThreadProcessor", "kickUser", request);
           } catch (Exception e) {
             e.printStackTrace();
             MessageBox.showMessageDialog(pnlThread, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
           }
         }
       });
   ////////////////////////////////////////////////////////
   txtMessage.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           btnSend.doClick();
         }
       });
   ////////////////////////////////////////////////////////
   btnSend.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent evt) {
           if (txtMessage.getText().length() == 0) return;
           try {
             DDTP request = new DDTP();
             request.setString("strMessage", txtMessage.getText());
             channel.sendRequest("ThreadProcessor", "sendMessage", request);
             txtMessage.setText("");
           } catch (Exception e) {
             e.printStackTrace();
             MessageBox.showMessageDialog(pnlThread, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
           }
         }
       });
   ////////////////////////////////////////////////////////
   mnuClearAll.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           clearAll(txtBoard);
         }
       });
   ////////////////////////////////////////////////////////
   mnuClearSelected.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           txtBoard.setEditable(true);
           txtBoard.replaceSelection("");
           txtBoard.setEditable(false);
         }
       });
   ////////////////////////////////////////////////////////
   mnuSelectAll.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           txtBoard.requestFocus();
           txtBoard.selectAll();
         }
       });
   ////////////////////////////////////////////////////////
   txtBoard.addMouseListener(
       new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           if (e.getButton() == e.BUTTON3) pmn.show(txtBoard, e.getX(), e.getY());
         }
       });
   ////////////////////////////////////////////////////////
   mnuSystem_Login.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           login();
         }
       });
   ////////////////////////////////////////////////////////
   mnuSystem_ChangePassword.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           changePassword();
         }
       });
   ////////////////////////////////////////////////////////
   mnuSystem_StopServer.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           stopServer();
         }
       });
   ////////////////////////////////////////////////////////
   mnuSystem_EnableThreads.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           manageThreads();
         }
       });
   ////////////////////////////////////////////////////////
   mnuHelp_About.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           WindowManager.centeredWindow(new DialogAbout(PanelThreadManager.this));
         }
       });
   ////////////////////////////////////////////////////////
   chkVietnamese.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           switchKeyboard();
         }
       });
 }
  public void login() {
    mbAutoLogIn = false;
    while (!mbAutoLogIn) {
      try {
        // Confirm logout
        if (isOpen()) {
          if (MessageBox.showConfirmDialog(
                  this,
                  MonitorDictionary.getString("Confirm.Exit"),
                  Global.APP_NAME,
                  MessageBox.YES_NO_OPTION)
              == MessageBox.NO_OPTION) return;

          // Disconnect from server
          disconnect();
        }

        // Login
        DialogLogin dlgLogin = new DialogLogin(this);
        WindowManager.centeredWindow(dlgLogin);

        if (dlgLogin.miReturn == JOptionPane.OK_OPTION) {
          // Update UI
          SwingUtilities.updateComponentTreeUI(pnlUser);
          SwingUtilities.updateComponentTreeUI(pnlThread);

          // Request to connect
          Socket sck = new Socket(dlgLogin.mstrHost, Integer.parseInt(dlgLogin.mstrPort));
          sck.setSoLinger(true, 0);

          // Start up a channel thread that reads messages from the server
          channel =
              new SocketTransmitter(sck) {
                public void close() {
                  if (msckMain != null) {
                    super.close();
                    closeAll();
                    if (mbAutoLogIn) login();
                  }
                }
              };
          channel.setUserName(dlgLogin.mstrUserName);
          channel.setPackage("com.fss.thread.");
          channel.start();

          // Request to Server
          DDTP request = new DDTP();
          request.setRequestID(String.valueOf(System.currentTimeMillis()));
          request.setString("UserName", dlgLogin.mstrUserName);
          request.setString("Password", dlgLogin.mstrPassword);

          // Response from Server
          DDTP response = channel.sendRequest("ThreadProcessor", "login", request);
          mstrThreadAppName = response.getString("strThreadAppName");
          mstrThreadAppVersion = response.getString("strThreadAppVersion");
          mstrAppName = response.getString("strAppName");
          mstrAppVersion = response.getString("strAppVersion");
          if (response != null) {
            if (response.getString("PasswordExpired") != null) {
              DialogChangePassword frm = new DialogChangePassword(this, channel);
              WindowManager.centeredWindow(frm);
              if (frm.miReturnValue != JOptionPane.OK_OPTION) throw new AppException("FSS-10003");
            }
            String strLog = StringUtil.nvl(response.getString("strLog"), "");
            showResult(txtBoard, strLog);
            Vector vtThread = response.getVector("vtThread");
            updateTabBar(vtThread);

            mstrChannel = response.getString("strChannel");
            if (mstrChannel != null) removeUser(mstrChannel);
          }
          btnRefresh.doClick();
          pnlThread.setVisible(true);
          pnlUser.setVisible(true);
          setResizeWeight(1);
          setDividerLocation((int) (getSize().getHeight() - 160));
        }
        mbAutoLogIn = true;
        updateLanguage();
      } catch (Exception e) {
        e.printStackTrace();
        MessageBox.showMessageDialog(this, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);

        // Disconnect from server
        mstrChannel = null;
        disconnect();
      }
    }
  }
示例#11
0
    protected void addMyControls() {
      // add browser-style control buttons
      JButton home = new JButton(new ImageIcon("data/Home24.gif"));
      JButton back = new JButton(new ImageIcon("data/Back24.gif"));
      JButton fwd = new JButton(new ImageIcon("data/Forward24.gif"));

      home.setToolTipText("Home");
      home.addActionListener(this);
      home.setActionCommand(homeCmd);

      back.setToolTipText("Back");
      back.addActionListener(this);
      back.setActionCommand(backCmd);
      back.setEnabled(false); // initially disabled

      fwd.setToolTipText("Forward");
      fwd.addActionListener(this);
      fwd.setActionCommand(forwardCmd);
      fwd.setEnabled(false); // initially disabled

      add(home);
      add(back);
      add(fwd);
      add(new JToolBar.Separator());

      // set built-in index variables
      homeIndex = getComponentIndex(home);
      backIndex = getComponentIndex(back);
      forwardIndex = getComponentIndex(fwd);

      JComboBox comboBox = new JComboBox();
      comboBox.setEditable(true);
      comboBox.addActionListener(this);
      comboBox.setActionCommand(comboCmd);
      comboBox.setMaximumRowCount(3); // don't let it get too long
      comboBox.insertItemAt(mainBrowserURL, 0); // don't start it out empty

      add(comboBox);

      comboBoxIndex = getComponentIndex(comboBox);
    }
示例#12
0
  public IRCBOT(boolean uList, String channel, int chatNum) {

    // chatter = new ChatDisplay("<html><body bgcolor='black'><table border=0pt width=100%>");
    winNum = chatNum;
    URL iconURL = getClass().getResource("P_300x300.png");
    ImageIcon icon = new ImageIcon(iconURL);
    setIconImage(icon.getImage());

    Action doNothing =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {}
        };

    channelName = channel;
    standardWindow = uList;

    chatInput = new JTextArea(4, 55);
    chatInput.setWrapStyleWord(true);
    chatInput.setLineWrap(true);
    chatInput.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "doNothing");
    chatScreen = new JTextPane();
    chatScreen.setContentType("text/html");
    chatScreen.setEditorKit(kit);
    chatScreen.setDocument(doc);
    userList = new JTextPane();
    registeredUserList = new JTextPane();
    sendButton = new JButton("SEND");
    g_start = new JButton("START");
    g_end = new JButton("END");
    g_reroll = new JButton("secret");

    JLabel l_giveaway = new JLabel("Giveaway", JLabel.CENTER);
    JLabel l_chat = new JLabel("Chat", JLabel.CENTER);
    JLabel l_uList = new JLabel("User List", JLabel.CENTER);

    sendButton.addActionListener(this);
    g_start.addActionListener(this);
    g_end.addActionListener(this);
    g_reroll.addActionListener(this);

    g_start.setEnabled(false); // disabled for basic irc client
    g_end.setEnabled(false);
    g_reroll.setEnabled(false);

    // String start = "<html><body>";

    Dimension min = new Dimension(100, 1);
    Dimension pref = new Dimension(150, 1);
    Dimension max = new Dimension(600, 600);
    // chatScreen.setMinimumSize(min);
    // userList.setMinimumSize(min);
    // chatInput.addKeyListener(KeyBoardListener);

    JPanel mainPanel = new JPanel(new BorderLayout(5, 5));
    JPanel left = new JPanel(new BorderLayout(5, 5));
    JPanel mid = new JPanel(new BorderLayout(5, 5));
    JPanel right = new JPanel(new BorderLayout(5, 5));
    JPanel giveaway_buttons = new JPanel(new BorderLayout(5, 5));

    JPanel sendBar = new JPanel();
    scrollChat = new JScrollPane(chatScreen);
    JScrollPane scrollChatInput = new JScrollPane(chatInput);
    userListScroll = new JScrollPane(userList);
    JScrollPane regUserListScroll = new JScrollPane(registeredUserList);

    userListScroll.setMinimumSize(min);
    // userListScroll.setPreferredSize(pref);
    // userListScroll.setMaximumSize(new Dimension(800,600));
    // userListScroll.setPreferredSize(new Dimension(100,100));
    // scrollChat.setPreferredSize(pref);
    scrollChat.setMinimumSize(min);
    // scrollChat.setMaximumSize(new Dimension(500,500));
    regUserListScroll.setPreferredSize(pref);

    mid.add(l_chat, BorderLayout.NORTH);
    mid.add(scrollChat, BorderLayout.CENTER);

    right.add(l_uList, BorderLayout.NORTH);
    right.add(userListScroll, BorderLayout.CENTER);

    giveaway_buttons.add(g_start, BorderLayout.WEST);
    giveaway_buttons.add(g_end, BorderLayout.CENTER);
    giveaway_buttons.add(g_reroll, BorderLayout.PAGE_END);

    left.add(giveaway_buttons, BorderLayout.PAGE_END);

    JSplitPane chat_userList = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mid, right);
    chat_userList.setOneTouchExpandable(true);
    chat_userList.setDividerLocation(500);
    chat_userList.setResizeWeight(0.5);
    chat_userList.setContinuousLayout(true);
    // chat_userList.setPreferredSize(new Dimension(100,100));
    chat_userList.setMinimumSize(min);
    // chat_userList.setMaximumSize(max);

    userListScroll.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
    // scroll.add(chatScreen);

    sendBar.add(scrollChatInput);
    sendBar.add(sendButton);

    if (standardWindow) {

      mainPanel.add(chat_userList, BorderLayout.CENTER);
      mainPanel.add(sendBar, BorderLayout.PAGE_END);

      JMenuBar menuBar = new JMenuBar();
      JMenu fileMenu = new JMenu("File");
      settings = new JMenuItem("Settings");

      settings.addActionListener(this);

      fileMenu.add(settings);
      menuBar.add(fileMenu);

      left.add(l_giveaway, BorderLayout.NORTH);
      left.add(regUserListScroll, BorderLayout.CENTER);
      // left.setBorder(new EmptyBorder(0,5,0,0));
      // chat_userList.setBorder(new EtchedBorder(0,0,0,5));
      mainPanel.add(left, BorderLayout.WEST);
      mainPanel.add(menuBar, BorderLayout.PAGE_START);
      // mainPanel.setBorder(new EmptyBorder(0,10,10,10));
    } else {
      mainPanel.add(scrollChat, BorderLayout.CENTER);
    }
    registeredUserList.setEditable(false);
    userList.setEditable(false);
    chatScreen.setEditable(false);

    registeredUserList.setFont(new Font("Courier New", Font.PLAIN, 12));
    chatScreen.setFont(new Font("Courier New", Font.PLAIN, 12));
    chatInput.setFont(new Font("Courier New", Font.PLAIN, 12));

    getContentPane().add(mainPanel);
    setSize(800, 500);
    setVisible(true);
    setResizable(true);
    setLocationRelativeTo(null);
    setTitle("IRC Chatter");
    setMinimumSize(new Dimension(500, 200));

    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n");
            if (sock.isSafe() == true) sock.outputText("PART " + channelName + "\r\n");
            // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n");
          }
        });
    chatInput.addKeyListener(this);
    chatInput.requestFocus();
  }
示例#13
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();
  }