📄 realeditorframe.java
字号:
package com.ecust.swing;
import java.util.*;
import java.io.*;
import java.net.*;
import java.beans.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.undo.*;
import javax.swing.text.*;
import javax.swing.border.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import javax.swing.plaf.basic.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileView;
import javax.print.attribute.*;
import com.ecust.mainframe.*;
public class RealEditorFrame extends JFrame implements Printable {
/**
*
*/
private static final long serialVersionUID = -1091778153201490448L;
private static final Font plainSerif =
new Font( "Serif", Font.PLAIN, 12 );
private static final Font boldSerif =
new Font( "Serif", Font.BOLD, 12 );
private static final int PORT = 1984;
private static final int PORT2 = 1106;
private static int counter = 0;
private static int remoteCounter = 0;
private static int countForTuner = 0;
private static int fontPaneCounter = 0;
private static int sleepInterval = 100;
private boolean isEditPaneShowed = true;
private Toolkit kit = Toolkit.getDefaultToolkit();
private Dimension screenSize = kit.getScreenSize();
//private Style logicalStyle;
private CardLayout cardLayout = new CardLayout();
private JPanel cardPanel = new JPanel( cardLayout );
private static ArrayList< NewTextPane > textPanes = new ArrayList< NewTextPane >();
private CloseableTabbedPane tabbedPane = new CloseableTabbedPane();
private PerformanceDialog pd;
private JSplitPane splitPane;
private JMenuBar menuBar = new JMenuBar();
// Menus
private JMenu fileMenu = new JMenu( "File" );
private JMenu editMenu = new JMenu( "Edit" );
private JMenu viewMenu = new JMenu( "View" );
private JMenu configureMenu = new JMenu( "Configure" );
private JMenu fontMenu = new JMenu( "Font" );
private JMenu toolsMenu = new JMenu( "Tools" );
private JMenu helpMenu = new JMenu( "Help" );
// File items
private JMenuItem newMenuItem = new JMenuItem( "New" );
private JMenuItem openMenuItem = new JMenuItem( "Open..." );
private JMenuItem saveMenuItem = new JMenuItem( "Save" );
private JMenuItem saveAllMenuItem = new JMenuItem( "Save All" );
private JMenuItem printMenuItem = new JMenuItem( "Print..." );
private JMenuItem printPreviewMenuItem = new JMenuItem( "Print Preview..." );
private JMenuItem printSetupMenuItem = new JMenuItem( "Print Setup..." );
private JMenuItem exitMenuItem = new JMenuItem( "Exit" );
// Edit items
private static JMenuItem undoMenuItem = new JMenuItem( "Undo" );
private static JMenuItem redoMenuItem = new JMenuItem( "Redo" );
private JMenuItem cutMenuItem = new JMenuItem( "Cut" );
private JMenuItem copyMenuItem = new JMenuItem( "Copy" );
private JMenuItem pasteMenuItem = new JMenuItem( "Paste" );
private JMenuItem selectAllMenuItem = new JMenuItem( "Select All" );
private JMenuItem insertImgMenuItem = new JMenuItem( "Insert Images..." );
private JMenuItem findMenuItem = new JMenuItem( "Find..." );
private JMenuItem replaceMenuItem = new JMenuItem( "Replace..." );
// Tools items
private JMenuItem calcMenuItem = new JMenuItem( "Calculator..." );
private JMenuItem paintMenuItem = new JMenuItem( "Paint..." );
private JMenuItem playerMenuItem = new JMenuItem( "Media Player..." );
// View items
private static final String METAL =
"javax.swing.plaf.metal.MetalLookAndFeel";
private static final String MOTIF =
"com.sun.java.swing.plaf.motif.MotifLookAndFeel";
private static final String WINDOWS =
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
private ButtonGroup plafMenuGroup = new ButtonGroup();
private ButtonGroup themesMenuGroup = new ButtonGroup();
//JMenu theme;
private JRadioButtonMenuItem metalMenuItem =
new JRadioButtonMenuItem("Metal Look & Feel");
private JRadioButtonMenuItem motifMenuItem =
new JRadioButtonMenuItem("Motif Look & Feel");
private JRadioButtonMenuItem windowsMenuItem =
new JRadioButtonMenuItem("Windows Look & Feel");
private JRadioButtonMenuItem defaultMenuItem =
new JRadioButtonMenuItem("Metal Theme");
private JRadioButtonMenuItem oceanMenuItem =
new JRadioButtonMenuItem("Ocean Theme");
private JRadioButtonMenuItem contrastMenuItem =
new JRadioButtonMenuItem("Contrast Theme");
private JRadioButtonMenuItem greenMenuItem =
new JRadioButtonMenuItem("Green Theme");
private JRadioButtonMenuItem khakiMenuItem =
new JRadioButtonMenuItem("Khaki Theme");
private JRadioButtonMenuItem aquaMenuItem =
new JRadioButtonMenuItem("Aqua Theme");
private JSeparator separator = new JSeparator();
private PrinterJob printerJob;
private PrintView m_printView;
private PrintRequestAttributeSet attributes =
new HashPrintRequestAttributeSet();
private int count = 0;
private int colorPaneCount = 0;
private JCheckBoxMenuItem lineWrapMenuItem = new JCheckBoxMenuItem( "Line Wrap" );
private JMenuItem fontMenuItem = new JMenuItem( "Font..." );
private JMenuItem fontSizeMenuItem = new JMenuItem( "Font Size..." );
private JMenuItem fontColorMenuItem = new JMenuItem( "Font Color..." );
private JMenuItem backgroundColorMenuItem = new JMenuItem( "Background Color..." );
private JMenuItem performanceMenuItem = new JMenuItem( "Performance..." );
// Help items
private JMenuItem aboutMenuItem = new JMenuItem( "About RealEditor..." );
private JToolBar toolBar = new JToolBar();
private Icon newImageIcon = new ImageIcon( getImgResources( "NEW.gif" ) );
private Icon openImageIcon = new ImageIcon( getImgResources( "OPEN.gif" ) );
private Icon saveImageIcon = new ImageIcon( getImgResources( "SAVE.gif" ) );
private Icon saveAllImageIcon = new ImageIcon( getImgResources( "SAVEALL.gif" ) );
private Icon printImageIcon = new ImageIcon( getImgResources( "PRINT.gif" ) );
private Icon cutImageIcon = new ImageIcon( getImgResources( "CUT.gif" ) );
private Icon copyImageIcon = new ImageIcon( getImgResources( "COPY.gif" ) );
private Icon pasteImageIcon = new ImageIcon( getImgResources( "PASTE.gif" ) );
private Icon undoImageIcon = new ImageIcon( getImgResources( "UNDO.gif" ) );
private Icon redoImageIcon = new ImageIcon( getImgResources( "REDO.gif" ) );
private Icon insertImgImageIcon = new ImageIcon( getImgResources( "INSERTIMG.gif" ) );
private Icon findImageIcon = new ImageIcon( getImgResources( "FIND.gif" ) );
private Icon replaceImageIcon = new ImageIcon( getImgResources( "REPLACE.gif" ) );
private Icon aboutImageIcon = new ImageIcon( getImgResources( "ABOUT.gif" ) );
private Icon javaImageIcon = new ImageIcon( getImgResources( "JAVA.png" ) );
private Icon documentFileViewImageIcon = new ImageIcon( getImgResources( "BLUEPAGE.gif" ) );
private JButton newButton = new JButton( newImageIcon );
private JButton openButton = new JButton( openImageIcon );
private JButton saveButton = new JButton( saveImageIcon );
private JButton saveAllButton = new JButton( saveAllImageIcon );
private JButton cutButton = new JButton( cutImageIcon );
private JButton copyButton = new JButton( copyImageIcon );
private JButton pasteButton = new JButton( pasteImageIcon );
private JButton undoButton = new JButton( undoImageIcon );
private JButton redoButton = new JButton( redoImageIcon );
private JButton insertImgButton = new JButton( insertImgImageIcon );
private JButton findButton = new JButton( findImageIcon );
private JButton replaceButton = new JButton( replaceImageIcon );
private JButton boldButton = new JButton( "<html><b>B</b></html>" );
private JButton italicButton = new JButton( "<html><b><i>I</i><b></html>" );
private JButton underLineButton = new JButton( "<html><b><u>U</u><b></html>" );
private JButton sendButton = new JButton( " Send " );
private JComboBox fontsComboBox = new JComboBox();
private JComboBox fontSizeComboBox = new JComboBox();
private JTextField ipTextField = new JTextField( 12 );
private java.awt.List list = new java.awt.List ();
private JTextField msgTextField = new JTextField();
private JRadioButton editButton = new JRadioButton( "EditPane" );
private JRadioButton communicationButton = new JRadioButton( "MessagePane" );
private ButtonGroup switchBG = new ButtonGroup();
private ServerSocket serverSocket;
private DatagramSocket datagramSocket;
private Thread clockThread = new Clock();
private static JLabel statusLabel = new JLabel();
private JLabel clockLabel = createLabel( " " + TimeFormat.getSimpleTime() + " " );
private FontPane fontPane;
private FontSizePane fontSizePane;
private ColorPane colorPane;
private AboutDialog aboutDialog =
new AboutDialog( RealEditorFrame.this );
private String[] fontNames = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();
private String[] fontSizes = new String[ 92 ];
private URL getImgResources( String filename ) {
URL url = getClass().getResource( "Imgs/" + filename );
return url;
}
public RealEditorFrame() {
super("RealEditor");
try {
serverSocket = new ServerSocket( PORT );
} catch (IOException ex) {
ex.printStackTrace();
}
try {
datagramSocket = new DatagramSocket( PORT2 );
} catch (SocketException ex) {
ex.printStackTrace();
}
accept();
receive();
tabbedPane.addMouseListener( new MouseL() );
tabbedPane.setFont( plainSerif );
Container container = getContentPane();
container.setLayout( new BorderLayout() );
setJMenuBar( createMenuBar() );
container.add( createToolBar(), BorderLayout.NORTH );
container.add( createSplitPane(), BorderLayout.CENTER );
JPanel panel = new JPanel( new BorderLayout() );
//panel.add( createLabel(), BorderLayout.EAST );
ipTextField.setText( "localhost" );
ipTextField.setFont( boldSerif );
ipTextField.setBorder( new LineBorder( Color.GRAY ) );
ipTextField.setToolTipText( "Remote IP Address" );
JPanel sendButtonPanel = new JPanel();
JLabel ipLabel = new JLabel( "IP: " );
ipLabel.setFont( plainSerif );
ipLabel.setForeground( Color.GRAY );
sendButtonPanel.add( ipLabel );
sendButtonPanel.add( ipTextField );
sendButton.setBorder( new LineBorder( Color.GRAY ) );
sendButton.setFont( boldSerif );
sendButton.setForeground( Color.DARK_GRAY );
sendButton.setCursor( new Cursor( Cursor.HAND_CURSOR ) );
sendButton.addActionListener( new SendL() );
sendButton.setToolTipText( "Send Documents" );
sendButtonPanel.add( sendButton );
editButton.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e ) {
cardLayout.show( cardPanel, "tabbedPane" );
isEditPaneShowed = true;
newButton.setEnabled( true );
openButton.setEnabled( true );
newMenuItem.setEnabled( true );
openMenuItem.setEnabled( true );
editButton.setForeground( Color.DARK_GRAY );
communicationButton.setForeground( Color.LIGHT_GRAY );
if ( tabbedPane.getSelectedIndex() != -1 ) {
NewTextPane textPane = getCurrentTextPane();
textPane.setRowCol();
statusLabel.setText(
"Row: " + ( textPane.getRow() + 1 ) +
" Col: " + ( textPane.getCol() + 1 ) +
" Percent: " + textPane.getPercent() +
" Length: " + textPane.getLength() );
}
statusLabel.setVisible( true );
}
}
);
communicationButton.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e ) {
cardLayout.show( cardPanel, "listPane" );
isEditPaneShowed = false;
newButton.setEnabled( false );
openButton.setEnabled( false );
newMenuItem.setEnabled( false );
openMenuItem.setEnabled( false );
editButton.setForeground( Color.LIGHT_GRAY );
communicationButton.setForeground( Color.DARK_GRAY );
statusLabel.setVisible( false );
//statusLabel.setText( "" );
}
}
);
editButton.setFont( plainSerif );
communicationButton.setFont( plainSerif );
editButton.setForeground( Color.DARK_GRAY );
communicationButton.setForeground( Color.LIGHT_GRAY );
editButton.setToolTipText( "Switch To EditPane" );
communicationButton.setToolTipText( "Switch To MessagePane" );
editButton.setSelected( true );
switchBG.add( editButton );
switchBG.add( communicationButton );
JPanel switchPanel = new JPanel( new GridLayout( 1, 2 ) );
switchPanel.add( editButton );
switchPanel.add( communicationButton );
sendButtonPanel.add( switchPanel );
panel.add( sendButtonPanel, BorderLayout.WEST );
panel.add( clockLabel, BorderLayout.EAST );
JPanel rowcolPanel = new JPanel();
rowcolPanel.setLayout( new BoxLayout( rowcolPanel, BoxLayout.X_AXIS ) );
Box box = Box.createHorizontalBox();
statusLabel.setFont( plainSerif );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -