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

📄 chatdialogview.java

📁 myjxta是用jxta开发的一个p2p通讯软件 有聊天 文件共享 视频3大功能 界面采用swing
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @param reset     */    public void setEditor(boolean selected, boolean reset) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin setEditor(boolean, boolean)");            LOG.fine("selected = " + selected);            LOG.fine("reset    = " + reset);        }        final String contentType = !selected ?                UIConstants.MIME_HTML : UIConstants.MIME_PLAIN;        String t = (!reset && this.editor != null) ? removeText(this.editor) : "";        this.editor = new JXEditorPane();        this.editor.setContentType(contentType);        if (contentType.equalsIgnoreCase(UIConstants.MIME_HTML) &&                this.style != null) {            StyleSheet ds = ((HTMLDocument) this.editor.getDocument()).getStyleSheet();            if (ds != null) {                ds.addStyleSheet(this.style);            } else {                ds = this.style;            }            ((HTMLEditorKit) this.editor.getEditorKit()).setStyleSheet(ds);        }//        this.editor.setPreferredSize(new Dimension(UIConstants.EDITOR_WIDTH,//            UIConstants.EDITOR_HEIGHT));        this.editor.setMargin(new Insets(3, 3, 3, 3));        this.editor.addMouseListener(new MouseAdapter() {            public void mousePressed(MouseEvent me) {                showPopupMenu(me);            }            public void mouseReleased(MouseEvent me) {                showPopupMenu(me);            }            private void showPopupMenu(MouseEvent me) {                if (me.isPopupTrigger() &&                        me.getSource() == editor) {                    editorPopup.show(editor, me.getX(), me.getY());                }            }        });        this.editor.addKeyListener(new KeyAdapter() {            public void keyPressed(KeyEvent ke) {                if (ke.isControlDown()) {                    if (ke.getKeyCode() == KeyEvent.VK_UP ||                            ke.getKeyCode() == KeyEvent.VK_DOWN) {                        ke.consume();                        if (ke.getKeyCode() == KeyEvent.VK_UP &&                                historyIndex < HISTORY_MAX - 1 &&                                historyIndex < history.size() - 1) {                            if (historyIndex == 0) {                                addHistory(removeText(editor));                            }                            setText(editor, history.get(++historyIndex));                        } else if (ke.getKeyCode() == KeyEvent.VK_DOWN &&                                historyIndex > 0) {                            setText(editor, history.get(--historyIndex));                        }                    } else {                        Font f;                        int i;                        switch (ke.getKeyCode()) {                            case KeyEvent.VK_0:                                setFont(editorDefaultFont);                                break;                            case KeyEvent.VK_EQUALS:                                f = getFont();                                i = f.getSize();                                setFont(new Font(f.getName(), f.getStyle(),                                        Math.min(++i, MAX_FONT_SIZE)));                                break;                            case KeyEvent.VK_MINUS:                                f = getFont();                                i = f.getSize();                                setFont(new Font(f.getName(), f.getStyle(),                                        Math.max(--i, MIN_FONT_SIZE)));                                break;                            default:                        }                    }                } else {                    if (ke.getKeyCode() == KeyEvent.VK_ENTER &&                            contentType.equals(UIConstants.MIME_HTML)) {                        ke.consume();                        send.getAction().actionPerformed(null);                    }                }            }            private Font getFont() {                return editor.getFont();            }            private void setFont(Font f) {                editor.setFont(f);            }        });        this.editor.getActionMap().put(DefaultEditorKit.pasteAction,                new AbstractAction() {                    public Object getValue(String key) {                        Object o = super.getValue(key);                        if (Logging.SHOW_FINE &&                                LOG.isLoggable(Level.FINE)) {                            LOG.fine("In setEditor#AbstractAction.getValue(String)");                            LOG.fine("Key = \"" + key +                                    "\", Value = \"" + o +                                    "\"");                        }                        return UIConstants.PRE_PREFIX + o +                                UIConstants.PRE_POSTFIX;                    }                    public void actionPerformed(ActionEvent ae) {                        if (Logging.SHOW_FINE &&                                LOG.isLoggable(Level.FINE)) {                            LOG.fine("In setEditor#AbstractAction.actionPerformed(ActionEvent)");                        }                        Clipboard clipboard = getToolkit().getSystemClipboard();                        Transferable content = clipboard.getContents(this);                        dropper.handleExternalDataInput(new PastedExternalObject(content));                    }                });        this.editor.setCaretPosition(this.editor.getDocument().getLength());        this.editorDefaultFont = this.editor.getFont();        InputMap im = this.editor.getInputMap();        im.put(KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK),                DefaultEditorKit.backwardAction);        im.put(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK),                DefaultEditorKit.forwardAction);        im.put(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK),                DefaultEditorKit.upAction);        im.put(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK),                DefaultEditorKit.downAction);        im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Event.CTRL_MASK),                UIConstants.BREAK);        new DropTarget(this.editor, this.dropper);        setText(this.editor, t);        float lineHeight = editor.getFontMetrics(editor.getFont()).getLineMetrics("A", 0, 1, this.getGraphics()).getHeight();        int prefHeight = (int) (2 * (Math.floor(lineHeight) + 1));        int prefWidth = editor.getPreferredSize().width;        this.editor.setPreferredSize(new Dimension(prefWidth, prefHeight));        this.editorScroller.setViewportView(this.editor);        this.manager.setEnabled(UIConstants.BOLD, !selected);        this.manager.setEnabled(UIConstants.ITALIC, !selected);        this.manager.setEnabled(UIConstants.UNDERLINE, !selected);        this.manager.setEnabled(UIConstants.LEFT, !selected);        this.manager.setEnabled(UIConstants.CENTER, !selected);        this.manager.setEnabled(UIConstants.RIGHT, !selected);        this.manager.setSelected(UIConstants.EDITOR, selected);        //if (reset) {        // xxx: don't reset but honor currently selected        //this.manager.setSelected(Constants.LEFT, true);        //}        this.historyIndex = 0;        setFocus();        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   setEditor(boolean, boolean)");        }    }    /**     * Init Components and layout panel     *     * @modified 2005-04-24 jamoore added TableLayout for better resize handling     */    private void init() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin init()");        }        this.manager = createManager();        this.dropper = createDropper();        this.logFormatter = new SimpleDateFormat(LOG_TIMESTAMP_FORMAT);        this.style = createStyle();        /*        GridBagLayout gb = new GridBagLayout();        GridBagConstraints gbc = new GridBagConstraints();        setLayout(gb);//        setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));        gbc.gridx = 0;        gbc.gridy = 0;        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.insets = new Insets(3, 3, 3, 3);        gbc.anchor = GridBagConstraints.NORTHWEST;        gbc.weightx = 1.0;        gbc.weighty = 1.0;        gbc.fill = GridBagConstraints.BOTH;                Component c = createRenderer();        gb.setConstraints(c, gbc);        add(c);        c = createEditor();        gbc.gridy++;        gbc.weighty = 0.0;        gbc.fill = GridBagConstraints.HORIZONTAL;        gb.setConstraints(c, gbc);        add(c);        */        double blank = 5;        double sizes[][] = {{blank, TableLayout.FILL, blank},                {blank, .75, blank, TableLayout.MINIMUM, blank, .25}};        TableLayout tbl = new TableLayout(sizes);        setLayout(tbl);        Component c = createRenderer();        add(c, "1,1");        c = createEditor();        add(c, "1,5");        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   init()");        }    }    private ActionManager createManager() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin createManager()");        }        ActionManager am = ActionManager.getInstance();        String action;        String resource;        this.rendererActions = new ArrayList<String>();        // xxx: shouldn't have to set toggle state        this.rendererActions.add(action = UIConstants.SAVE_AS);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_SAVE_AS),                getImagePath(UIConstants.SAVE_AS_IMAGE), resource, null,                UIConstants.SAVE_AS_MNEMONIC, false, true, this, "saveAsDialog"));        this.rendererActions.add(action = UIConstants.CLEAR);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_CLEAR),                null, resource, null, UIConstants.CLEAR_MNEMONIC, false, true, this,                "clearDialog"));        this.editorActions = new ArrayList<String>();        //todo: remvoe the false here if we have a working preference system to determine if the user        //whants em        if (false) { // remove the undo/redo buttons until we can reenable em via preferences            this.editorActions.add(action = UIConstants.UNDO);            am.addAction(createAction(action,                    resource = STRINGS.getString(UIConstants.ACTION_UNDO),                    getImagePath(UIConstants.UNDO_IMAGE), resource, null,                    UIConstants.UNDO_MNEMONIC, false, false));            this.editorActions.add(action = UIConstants.REDO);            am.addAction(createAction(action,                    resource = STRINGS.getString(UIConstants.ACTION_REDO),                    getImagePath(UIConstants.REDO_IMAGE), resource, null,                    UIConstants.REDO_MNEMONIC, false, false));            this.editorActions.add(null);        }        this.editorActions.add(action = UIConstants.BOLD);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_BOLD),                getImagePath(UIConstants.BOLD_IMAGE), resource, null,                UIConstants.BOLD_MNEMONIC, true, true));        this.editorActions.add(action = UIConstants.ITALIC);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_ITALIC),                getImagePath(UIConstants.ITALIC_IMAGE), resource, null,                UIConstants.ITALIC_MNEMONIC, true, true));        this.editorActions.add(action = UIConstants.UNDERLINE);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_UNDERLINE),                getImagePath(UIConstants.UNDERLINE_IMAGE), resource, null,                UIConstants.UNDERLINE_MNEMONIC, true, true));        this.editorActions.add(null);        this.editorActions.add(action = UIConstants.CUT);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_CUT),                getImagePath(UIConstants.CUT_IMAGE), resource, null,                UIConstants.CUT_MNEMONIC, false, true));        this.editorActions.add(action = UIConstants.COPY);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_COPY),                getImagePath(UIConstants.COPY_IMAGE), resource, null,                UIConstants.COPY_MNEMONIC, false, true));        this.editorActions.add(action = UIConstants.PASTE);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_PASTE),                getImagePath(UIConstants.PASTE_IMAGE), resource, null,                UIConstants.PASTE_MNEMONIC, false, true));        this.editorActions.add(null);        this.editorActions.add(action = UIConstants.LEFT);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_LEFT),                getImagePath(UIConstants.LEFT_IMAGE), resource,                UIConstants.PARAGRAPH, UIConstants.LEFT_MNEMONIC, true, true));        this.editorActions.add(action = UIConstants.CENTER);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_CENTER),                getImagePath(UIConstants.CENTER_IMAGE), resource,                UIConstants.PARAGRAPH, UIConstants.CENTER_MNEMONIC, true, true));        this.editorActions.add(action = UIConstants.RIGHT);        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_RIGHT),                getImagePath(UIConstants.RIGHT_IMAGE), resource,                UIConstants.PARAGRAPH, UIConstants.RIGHT_MNEMONIC, true, true));        action = UIConstants.SELECT_ALL;        am.addAction(createAction(action,                resource = STRINGS.getString(UIConstants.ACTION_SELECT_ALL),                null, resource, null, UIConstants.SELECT_ALL_MNEMONIC, false, true));

⌨️ 快捷键说明

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