@Override public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(client.getTheme().getTransparentPanelBg()); if (messagesPane.isVisible()) { g2.fillRect(0, 0, getWidth(), getHeight()); } else { g2.fillRect(0, getHeight() - 40, getWidth(), 40); } super.paint(g); }
@Subscribe public void displayChatMessage(ChatEvent ev) { ReceivedChatMessage fm = createReceivedMessage(ev); formattedMessages.addLast(fm); if (client.getState() == JFrame.ICONIFIED) { messageReceivedWhileIconified = true; } else { setForceFocus(); } DefaultStyledDocument doc = new DefaultStyledDocument(); int offset = 0; try { for (ReceivedChatMessage msg : formattedMessages) { SimpleAttributeSet attrs = new SimpleAttributeSet(); ColorConstants.setForeground(attrs, msg.color); String nick = msg.nickname; String text = msg.ev.getText(); doc.insertString(offset, nick + ": ", attrs); offset += nick.length() + 2; Color textColor = client.getTheme().getTextColor(); if (textColor == null) { attrs = null; } else { attrs = new SimpleAttributeSet(); ColorConstants.setForeground(attrs, client.getTheme().getTextColor()); } doc.insertString(offset, text + "\n", attrs); offset += text.length() + 1; } } catch (BadLocationException e) { logger.error(e.getMessage(), e); //should never happen } messagesPane.setDocument(doc); repaint(); }
public void initHidingMode() { hidingMode = true; repaintTimer = new Timer(DISPLAY_MESSAGES_INTERVAL, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { forceFocus = false; repaintTimer.stop(); updateMessaagesVisibility(); } }); this.addComponentListener(new ComponentAdapter() { @Override public void componentHidden(ComponentEvent e) { repaintTimer.stop(); } }); if (forceFocus) { repaintTimer.start(); } setBackground(new Color(0, 0, 0, 0)); input.setBackground(client.getTheme().getInputBg()); updateMessaagesVisibility(); }
public ChatPanel(final Client client) { this.client = client; input = new JTextField(); //prevent unintended focus (by window activate etc. - allow focus just on direct click) input.setFocusable(false); input.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { activateChat(); } }); input.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { clean(); } } }); input.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String msg = input.getText(); if (!"".equals(msg)) { forceFocus = true; //prevent panel flashing client.getConnection().send(createPostChatMessage(msg)); } clean(); } }); input.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { updateMessaagesVisibility(); } @Override public void focusGained(FocusEvent e) { updateMessaagesVisibility(); } }); input.setOpaque(false); input.setBackground(client.getTheme().getTransparentInputBg()); Color textColor = client.getTheme().getTextColor(); if (textColor != null) { input.setForeground(client.getTheme().getTextColor()); input.setCaretColor(client.getTheme().getTextColor()); } TextPrompt tp = new TextPrompt(_("Type to chat"), input); tp.setShow(Show.FOCUS_LOST); tp.changeStyle(Font.ITALIC); tp.changeAlpha(0.4f); messagesPane = new JTextPane(); messagesPane.setEditorKit(new WrapEditorKit()); messagesPane.setFocusable(false); messagesPane.setOpaque(false); setBackground(client.getTheme().getTransparentPanelBg()); setLayout(new MigLayout("")); add(messagesPane, "pos 10 n (100%-10) (100%-35)"); add(input, "pos 10 (100%-35) (100%-10) (100%-10)"); }