private void adjustSize() { int newHeight = mTextArea.getPreferredSize().height; int maxHeight = mChatView.getHeight() / 3; mScrollPane.setPreferredSize( new Dimension( mScrollPane.getWidth(), newHeight < maxHeight ? // grow newHeight + 1 : // +1 for border // fixed height maxHeight)); // swing does not figure this out itself mChatView.revalidate(); }
private void statusChanged() { Control.Status status = mControl.getCurrentStatus(); switch (status) { case CONNECTING: mStatusBarLabel.setText(Tr.tr("Connecting...")); break; case CONNECTED: mChatView.setColor(Color.WHITE); mStatusBarLabel.setText(Tr.tr("Connected")); NotificationManager.hideAllNotifications(); break; case DISCONNECTING: mStatusBarLabel.setText(Tr.tr("Disconnecting...")); break; case DISCONNECTED: mChatView.setColor(Color.LIGHT_GRAY); mStatusBarLabel.setText(Tr.tr("Not connected")); // if (mTrayIcon != null) // trayIcon.setImage(updatedImage); break; case SHUTTING_DOWN: mMainFrame.save(); mChatListView.save(); mTrayManager.removeTray(); mMainFrame.setVisible(false); mMainFrame.dispose(); break; case FAILED: mStatusBarLabel.setText(Tr.tr("Connecting failed")); break; case ERROR: mChatView.setColor(Color.lightGray); mStatusBarLabel.setText(Tr.tr("Connection error")); break; } mMainFrame.onStatusChanged(status); }
/** * Initializes all the gui components. Calls methods setupPanel(), setupLayout(), * setupListeners(). * * @param baseController */ public ChatPanel(ChatController baseController) { this.baseController = baseController; myView = new ChatView(); String userName = myView.grabAnswer("What is your name?"); myBot = new Chatbot(userName); baseLayout = new SpringLayout(); chatArea = new JTextArea(10, 30); typingField = new JTextField(30); promptLabel = new JLabel("Chat with me"); submitButton = new JButton("asda"); twitterButton = new JButton("Twitter"); myTwitter = new CTECTwitter(baseController); analyzeTwitterButton = new JButton("Analyze some tweets"); setupPanel(); setupLayout(); setupListeners(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get subject subject = getIntent().getStringExtra("subject"); // Set title if ((subject == null) || (subject.length() == 0)) { setTitle(getString(R.string.title_chat_view_group)); } else { setTitle(getString(R.string.title_chat_view_group) + " " + subject); } // Set the message composer max length InputFilter[] filterArray = new InputFilter[1]; filterArray[0] = new InputFilter.LengthFilter(RcsSettings.getInstance().getMaxGroupChatMessageLength()); composeText.setFilters(filterArray); }
ComposingArea(ChatView chatView) { mChatView = chatView; mTextArea = new WebTextArea(); mTextArea.setMargin(View.MARGIN_SMALL); mTextArea.setBorder(null); mTextArea.setLineWrap(true); mTextArea.setWrapStyleWord(true); mTextArea.setFontSize(View.FONT_SIZE_NORMAL); mTextArea.setInputPrompt(Tr.tr("Type to compose")); mTextArea.setInputPromptHorizontalPosition(SwingConstants.LEFT); mTextArea.setComponentPopupMenu(Utils.createCopyMenu(true)); mTextArea .getDocument() .addDocumentListener( new DocumentChangeListener() { @Override public void documentChanged(DocumentEvent e) { mChatView.onKeyTypeEvent(e.getDocument().getLength() == 0); } }); mScrollPane = new ComponentUtils.ScrollPane(mTextArea, false); mScrollPane.setBorder(null); // text area overlay mOverlayLabel = new WebLabel().setBoldFont(); mOverlay = new WebOverlay(mScrollPane, mOverlayLabel, SwingConstants.CENTER, SwingConstants.CENTER); mOverlay.setUndecorated(false).setMargin(View.MARGIN_SMALL).setWebColoredBackground(false); // old transfer handler of text area is fallback for bottom panel mDropHandler = new FileDropHandler(mTextArea.getTransferHandler()); mTextArea.setTransferHandler(mDropHandler); // when text changed... mTextArea .getDocument() .addDocumentListener( new DocumentChangeListener() { @Override public void documentChanged(DocumentEvent e) { // these are strange times SwingUtilities.invokeLater( new Runnable() { public void run() { ComposingArea.this.adjustSize(); } }); } }); ((AbstractDocument) mTextArea.getDocument()) .setDocumentFilter( new DocumentFilter() { @Override public void replace( FilterBypass fb, int offset, int length, String string, AttributeSet attr) throws BadLocationException { // input implementation of the "/me" command, XEP-0245 if (length == 0 && offset == 0 && string.equals("/")) { fb.insertString(0, View.THE_ME_COMMAND, attr); return; } super.replace(fb, offset, length, string, attr); } }); // ...or window is resized mChatView.addComponentListener( new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { ComposingArea.this.adjustSize(); } }); }
void reloadChatBG() { mChatView.loadDefaultBG(); }
void setHotkeys() { boolean enterSends = Config.getInstance().getBoolean(Config.MAIN_ENTER_SENDS); mChatView.setHotkeys(enterSends); }