📄 chatdialogview.java
字号:
action = UIConstants.EDITOR; am.addAction(createAction(action, resource = STRINGS.getString(UIConstants.ACTION_EDITOR), getImagePath(UIConstants.EDITOR_IMAGE), resource, null, UIConstants.EDITOR_MNEMONIC, true, true, this, "setEditor")); this.colorActions = new ArrayList<StyledEditorKit.ForegroundAction>(); resource = STRINGS.getString("label.color.red"); this.colorActions.add( new StyledEditorKit.ForegroundAction(resource, Color.red)); resource = STRINGS.getString("label.color.green"); this.colorActions.add( new StyledEditorKit.ForegroundAction(resource, Color.green)); resource = STRINGS.getString("label.color.blue"); this.colorActions.add( new StyledEditorKit.ForegroundAction(resource, Color.blue)); resource = STRINGS.getString("label.color.black"); this.colorActions.add( new StyledEditorKit.ForegroundAction(resource, Color.black)); if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("End createManager()"); } return am; } private String getImagePath(String name) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("In getImagePath(String)"); } return getImagePath(name, UIConstants.IMAGE_SIZE_SMALL); } private String getImagePath(String name, int size) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("In getImagePath(String, int)"); } return getImagePath(name, size, UIConstants.MIME_GIF); } private String getImagePath(String name, int size, String type) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("In getImagePath(String, int, String)"); LOG.fine("name = " + name); LOG.fine("size = " + size); LOG.fine("type = " + type); } return name + size + type; } private Component createRenderer() { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Begin createRenderer()"); } add(this.rendererPopup = createRendererPopup(), "0,0"); JPanel p = new JPanel(); GridBagLayout gb = new GridBagLayout(); p.setLayout(gb); //p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); this.renderer = new JXEditorPane(); this.renderer.setContentType(UIConstants.MIME_HTML); if (this.style != null) { StyleSheet ds = ((HTMLDocument) this.renderer.getDocument()).getStyleSheet(); if (ds != null) { ds.addStyleSheet(this.style); } else { ds = this.style; } ((HTMLEditorKit) this.renderer.getEditorKit()).setStyleSheet(ds); }// this.renderer.setPreferredSize(new Dimension(UIConstants.RENDERER_WIDTH,// UIConstants.RENDERER_HEIGHT)); this.renderer.setMinimumSize(this.renderer.getPreferredSize()); this.renderer.setMargin(new Insets(3, 3, 3, 3)); this.renderer.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() == renderer) { rendererPopup.show(renderer, me.getX(), me.getY()); } } }); this.renderer.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent ke) { if (ke.isControlDown()) { Font f; switch (ke.getKeyCode()) { case KeyEvent.VK_0: setFont(rendererDefaultFont); break; case KeyEvent.VK_EQUALS: f = getFont(); setFont(new Font(f.getName(), f.getStyle(), f.getSize() + 1)); break; case KeyEvent.VK_MINUS: f = getFont(); setFont(new Font(f.getName(), f.getStyle(), f.getSize() - 1)); break; default: } } } private Font getFont() { return renderer.getFont(); } private void setFont(Font f) { renderer.setFont(f); } }); this.renderer.setEditable(false); this.renderer.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent he) { if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { final URL url = he.getURL(); if (url != null) ExecFactory.getExec().execDocument(url); } } }); this.rendererDefaultFont = this.renderer.getFont(); this.rendererScroller = new JScrollPane(this.renderer, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);// this.rendererScroller.setMinimumSize(this.renderer.getPreferredSize()); this.rendererScroller.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); GridBagConstraints gbc = new GridBagConstraints(); 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; gb.setConstraints(this.rendererScroller, gbc); p.add(this.rendererScroller); if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("End createRenderer()"); } return p; } private JPopupMenu createRendererPopup() { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("In createRendererPopup()"); } List<String> l = new ArrayList<String>(this.rendererActions); return manager.getFactory().createPopup(l); } /** * Creates a panel for the editor and its related components. * Added TableLayout for better handling when ChatDialogView is resized. * TableLayout does a slightly better job than GridBagLayout however * the constrainsts based appoach alone is not sufficent. A rules engine * would allow for specific case component adjustment. * <p/> * ie: the editor panel is given the constraint of 25%. This is fine for * maximized or normal sized ChatDialogView. When the ChatDialogView size * goes below 200 the editor window is no longer large enuff to display * readable characters. Even anonymous subclassing with the addition of * getMinimumSize() seems to be ignored. Possible Solution: Along with * the normal FILL contraints for the editor check for a rule of * <p/> * if [getSize().height < 200] * use components minimum size * (instead of the resize constraint of 25% ) * fi * * @modified 2005-04-24 jamoore added TableLayout for better resize handling */ private Component createEditor() { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Begin createEditor()"); } add(this.editorPopup = createEditorPopup(), "0,0"); JToolBar tb = this.manager.getFactory().createToolBar(this.editorActions); tb.setFloatable(false); double sizes[][] = {{TableLayout.FILL, 5, TableLayout.PREFERRED}, {TableLayout.FILL}}; TableLayout editorLayout = new TableLayout(sizes); JPanel p = new JPanel(editorLayout); this.add(tb, "1, 3"); this.editorScroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); this.editorScroller.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); p.add(editorScroller, "0, 0"); this.send = new JButton(new AbstractAction() { public void actionPerformed(ActionEvent ae) { if (send.isEnabled()) { dispatch(); } } }); this.send.setText(STRINGS.getString(UIConstants.ACTION_SEND)); this.send.setEnabled(false); this.send.addKeyListener(new AbstractButtonKeyListener(this.send) { public void keyPressed(KeyEvent ke) { getButton().getAction().actionPerformed(null); } }); p.add(this.send, "2, 0,c,c"); if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("End createEditor()"); } return p; } private JPopupMenu createEditorPopup() { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Begin createEditorPopup()"); } List<String> l = new ArrayList<String>(this.editorActions); l.add(null); l.add(UIConstants.SELECT_ALL); l.add(null); l.add(UIConstants.EDITOR); JPopupMenu pm = manager.getFactory().createPopup(l); JMenu cm = new JMenu(STRINGS.getString("label.color")); for (StyledEditorKit.ForegroundAction colorAction : colorActions) { cm.add(colorAction); } pm.add(cm); if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("End createEditorPopup()"); } return pm; } private Action createAction(String id, String name, String icon, String desc, String group, String mnemonic, boolean toggle, boolean isEnabled) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("In createAction(String, String, String, String, String, String, boolean, boolean)"); } return createAction(id, name, icon, desc, group, mnemonic, toggle, isEnabled, null, null); } private Action createAction(String id, String name, String icon, String desc, String group, String mnemonic, boolean toggle, boolean isEnabled, Object callback, String handler) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Begin createAction(String, String, String, String, String, String, boolean, boolean, Object, String)"); LOG.fine("id = " + id); LOG.fine("name = " + name); LOG.fine("icon = " + icon); LOG.fine("desc = " + desc); LOG.fine("group = " + group); LOG.fine("mnemonic = " + mnemonic); LOG.fine("toggle = " + toggle); LOG.fine("isEnabled = " + isEnabled); LOG.fine("callback = " + callback); LOG.fine("handler = " + handler); } AbstractAction a = createAction(id, name, mnemonic, toggle, group, callback, handler); ImageIcon ii = null; if (icon != null) { try { ii = new ImageIcon(getClass().getResource(icon)); } catch (Exception e) { LOG.info("failed to create icon for \'" + icon + "\'."); } } ActionFactory.decorateAction(a, desc, desc, ii, ii, null); if (callback != null && handler != null && handler.trim().length() > 0) { ((BoundAction) a).registerCallback(callback, handler); } a.setEnabled(isEnabled); if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("End createAction(String, String, String, String, String, String, boolean, boolean, Object, String)"); } return a; } private AbstractAction createAction(String id, String name,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -