📄 messageswindow.java
字号:
} } public void mouseClicked(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) { // popup menu event (right click) if (e.isPopupTrigger()) doContext(e); } public void mouseReleased(MouseEvent e) { // popup menu event (right click) if (e.isPopupTrigger()) doContext(e); } public void lostOwnership (Clipboard parClipboard, Transferable parTransferable) {} private void doContext(MouseEvent e) { JPopupMenu menu = new JPopupMenu("Messages Window"); JMenuItem menuItem = new JMenuItem("Cut"); menu.add(menuItem); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { copyText(false, true); } }); menuItem = new JMenuItem("Copy"); menu.add(menuItem); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { copyText(false, false); } }); menuItem = new JMenuItem("Paste"); menu.add(menuItem); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pasteText(); } }); menu.addSeparator(); menuItem = new JMenuItem("Cut All"); menu.add(menuItem); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { copyText(true, true); } }); menuItem = new JMenuItem("Copy All"); menu.add(menuItem); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { copyText(true, false); } }); menuItem = new JMenuItem("Clear"); menu.add(menuItem); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { clear(); } }); menu.show((Component)e.getSource(), e.getX(), e.getY()); } private void pasteText() { info.paste(); } private void copyText(boolean all, boolean cut) { if (all) { if (cut) { info.selectAll(); info.cut(); } else { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(info.getText()), this); } } else { if (cut) info.cut(); else info.copy(); } } /************************************ MESSAGES WINDOW FONT SETTING ************************************/ /** * Method to interactively select the messages window font. */ public void selectFont() { if (TopLevel.isMDIMode()) { JFrame jf = TopLevel.getCurrentJFrame(); new FontSelectDialog(jf); } else { new FontSelectDialog(null); } } private class FontSelectDialog extends EDialog { private Font initialFont; private String initialFontName; private int initialFontSize; private JLabel sampleText; private JList fontNameList; private JList fontSizeList; public FontSelectDialog(Frame parent) { super(parent, true); setTitle("Set Messages Window Font"); getContentPane().setLayout(new java.awt.GridBagLayout()); // get the current messages window font initialFont = info.getFont(); initialFontName = initialFont.getName(); initialFontSize = initialFont.getSize(); // the title of the font column JLabel fontLabel = new JLabel("Font:"); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.anchor = java.awt.GridBagConstraints.WEST; gbc.insets = new java.awt.Insets(4, 4, 4, 4); getContentPane().add(fontLabel, gbc); // the font column GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String [] fontNames = ge.getAvailableFontFamilyNames(); JScrollPane fontNamePane = new JScrollPane(); DefaultListModel fontNameListModel = new DefaultListModel(); fontNameList = new JList(fontNameListModel); fontNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontNamePane.setViewportView(fontNameList); int initialIndex = 0; for(int i=0; i<fontNames.length; i++) { if (fontNames[i].equals(initialFontName)) initialIndex = i; fontNameListModel.addElement(fontNames[i]); } fontNameList.setSelectedIndex(initialIndex); fontNameList.ensureIndexIsVisible(initialIndex); fontNameList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { updateSampleText(); } }); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.weightx = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; gbc.anchor = java.awt.GridBagConstraints.WEST; gbc.insets = new java.awt.Insets(4, 4, 4, 4); getContentPane().add(fontNamePane, gbc); // the title of the font size column JLabel sizeLabel = new JLabel("Size:"); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 0; gbc.anchor = java.awt.GridBagConstraints.WEST; gbc.insets = new java.awt.Insets(4, 4, 4, 4); getContentPane().add(sizeLabel, gbc); // the font size column JScrollPane fontSizePane = new JScrollPane(); DefaultListModel fontSizeListModel = new DefaultListModel(); fontSizeList = new JList(fontSizeListModel); fontSizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontSizePane.setViewportView(fontSizeList); fontSizeListModel.addElement("8"); fontSizeListModel.addElement("9"); fontSizeListModel.addElement("10"); fontSizeListModel.addElement("11"); fontSizeListModel.addElement("12"); fontSizeListModel.addElement("14"); fontSizeListModel.addElement("16"); fontSizeListModel.addElement("18"); fontSizeListModel.addElement("20"); fontSizeListModel.addElement("22"); fontSizeListModel.addElement("24"); fontSizeListModel.addElement("28"); fontSizeListModel.addElement("32"); fontSizeListModel.addElement("36"); fontSizeListModel.addElement("40"); fontSizeListModel.addElement("48"); fontSizeListModel.addElement("72"); fontSizeList.setSelectedValue(Integer.toString(initialFontSize), true); fontSizeList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { updateSampleText(); } }); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 1; gbc.fill = GridBagConstraints.BOTH; gbc.anchor = java.awt.GridBagConstraints.WEST; gbc.insets = new java.awt.Insets(4, 4, 4, 4); getContentPane().add(fontSizePane, gbc); // the sample text sampleText = new JLabel("The Electric VLSI Design System"); sampleText.setBorder(javax.swing.BorderFactory.createTitledBorder("Sample text")); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = 2; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = java.awt.GridBagConstraints.WEST; gbc.insets = new java.awt.Insets(4, 4, 4, 4); getContentPane().add(sampleText, gbc); sampleText.setFont(initialFont); // the "OK" button JButton okButton = new JButton("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { OK(); } }); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 3; gbc.anchor = java.awt.GridBagConstraints.WEST; gbc.insets = new java.awt.Insets(4, 4, 4, 4); getContentPane().add(okButton, gbc); // the "Cancel" button JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancel(); } }); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 3; gbc.anchor = java.awt.GridBagConstraints.WEST; gbc.insets = new java.awt.Insets(4, 4, 4, 4); getContentPane().add(cancelButton, gbc); pack(); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { cancel(); } }); setVisible(true); } private void cancel() { dispose(); } private void updateSampleText() { String currentFontName = initialFontName; if (fontNameList.getSelectedIndex() != -1) currentFontName = (String)fontNameList.getSelectedValue(); int currentFontSize = initialFontSize; if (fontSizeList.getSelectedIndex() != -1) currentFontSize = TextUtils.atoi((String)fontSizeList.getSelectedValue()); Font font = new Font(currentFontName, 0, currentFontSize); sampleText.setFont(font); } private void OK() { String currentFontName = initialFontName; if (fontNameList.getSelectedIndex() != -1) currentFontName = (String)fontNameList.getSelectedValue(); int currentFontSize = initialFontSize; if (fontSizeList.getSelectedIndex() != -1) currentFontSize = TextUtils.atoi((String)fontSizeList.getSelectedValue()); if (!currentFontName.equals(initialFontName) || currentFontSize != initialFontSize) { initialFont = new Font(currentFontName, 0, currentFontSize); info.setFont(initialFont); System.out.println("Messages window font is now " + currentFontName + ", size " + currentFontSize); } cancel(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -