📄 realeditorframe.java
字号:
underLineButton.addActionListener( new PressL() );
toolBar.setLayout( new GridBagLayout() );
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets( 1, 1, 1, 1 );
gbc.ipadx = 2;
toolBar.add( newButton, gbc );
toolBar.add( openButton, gbc );
toolBar.add( saveButton, gbc );
toolBar.add( saveAllButton, gbc );
toolBar.add( cutButton, gbc );
toolBar.add( copyButton, gbc );
toolBar.add( pasteButton, gbc );
toolBar.add( undoButton, gbc );
toolBar.add( redoButton, gbc );
toolBar.add( insertImgButton, gbc );
toolBar.add( findButton, gbc );
toolBar.add( replaceButton, gbc );
toolBar.add( fontsComboBox, gbc );
toolBar.add( fontSizeComboBox, gbc );
gbc.ipadx = 14;
toolBar.add( boldButton, gbc );
gbc.ipadx = 18;
toolBar.add( italicButton, gbc );
gbc.ipadx = 14;
toolBar.add( underLineButton, gbc );
JPanel panel = new JPanel();
gbc.anchor = GridBagConstraints.NORTHEAST;
gbc.weightx = 1;
toolBar.add( panel, gbc );
return toolBar;
}
private JPopupMenu createPopupMenu() {
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem cutMenuItem = new JMenuItem( "Cut" );
JMenuItem copyMenuItem = new JMenuItem( "Copy" );
JMenuItem pasteMenuItem = new JMenuItem( "Paste" );
JMenuItem selectAllMenuItem = new JMenuItem( "Select All" );
popupMenu.add( cutMenuItem );
popupMenu.add( copyMenuItem );
popupMenu.add( pasteMenuItem );
popupMenu.addSeparator();
popupMenu.add( selectAllMenuItem );
cutMenuItem.addActionListener( new CutL() );
copyMenuItem.addActionListener( new CopyL() );
pasteMenuItem.addActionListener( new PasteL() );
selectAllMenuItem.addActionListener( new SelectAllL() );
cutMenuItem.setAccelerator(
KeyStroke.getKeyStroke( 'X', InputEvent.CTRL_MASK, false ) );
cutMenuItem.setMnemonic( KeyEvent.VK_T );
copyMenuItem.setAccelerator(
KeyStroke.getKeyStroke( 'C', InputEvent.CTRL_MASK, false ) );
copyMenuItem.setMnemonic( KeyEvent.VK_C );
pasteMenuItem.setAccelerator(
KeyStroke.getKeyStroke( 'V', InputEvent.CTRL_MASK, false ) );
pasteMenuItem.setMnemonic( KeyEvent.VK_P );
selectAllMenuItem.setAccelerator(
KeyStroke.getKeyStroke( 'A', InputEvent.CTRL_MASK, false ) );
selectAllMenuItem.setMnemonic( KeyEvent.VK_A );
return popupMenu;
}
private JSplitPane createSplitPane() {
tabbedPane.setTabLayoutPolicy( JTabbedPane.SCROLL_TAB_LAYOUT );
//tabbedPane.setTabPlacement( JTabbedPane.BOTTOM );
JScrollPane scrollPane = new JScrollPane( list );
JPanel bottomPanel = new JPanel( new BorderLayout() );
bottomPanel.add( scrollPane, BorderLayout.CENTER );
JPanel southPanel = new JPanel( new BorderLayout() );
southPanel.add( msgTextField, BorderLayout.CENTER );
JButton clearButton = new JButton( " Clear " );
clearButton.setBorder( new LineBorder( Color.GRAY ) );
clearButton.setFont( boldSerif );
clearButton.setToolTipText( "Clear All Messages" );
clearButton.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e ) {
list.removeAll();
}
}
);
southPanel.add( clearButton, BorderLayout.EAST );
bottomPanel.add( southPanel, BorderLayout.SOUTH );
msgTextField.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e ) {
send();
}
}
);
cardPanel.add( tabbedPane, "tabbedPane" );
cardPanel.add( bottomPanel, "listPane" );
splitPane =
new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT, true,
new WorkPanel(), cardPanel );
splitPane.setOneTouchExpandable( true );
return splitPane;
}
private NewTextPane createTextPane() {
NewTextPane textPane = new NewTextPane();
textPane.setDragEnabled( true );
textPanes.add( textPane );
textPane.addMouseListener( new PopupL() );
//fontSizeComboBox.setSelectedItem( "12" );
return textPane;
}
private JLabel createLabel( String string ) {
JLabel label = new JLabel();
label.setText( string );
return label;
}
public static JLabel getStatusLabel() {
return statusLabel;
}
public Dimension getPreferredSize() {
int width = ( int )super.getPreferredSize().getWidth();
int height = ( int )( width * 0.618 );
return new Dimension( width, height );
}
private NewTextPane getCurrentTextPane() {
return ( ( NewTextPane )textPanes.get( tabbedPane.getSelectedIndex() ) );
}
private int getTabIndex( int x, int y ) {
return tabbedPane.getUI().tabForCoordinate( tabbedPane, x, y );
}
private void returnToLastEditLocation( NewTextPane jtp, int caretPosition ) {
Object[] option = {
"Yes", "No"
};
int n = JOptionPane.showOptionDialog(
RealEditorFrame.this,
"Do you want to return to last edit location ?",
"Save ", JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null, option, option[ 0 ] );
switch ( n ) {
case JOptionPane.YES_OPTION:
jtp.setCaretPosition( caretPosition );
break;
case JOptionPane.NO_OPTION:
break;
default:
break;
}
}
private void sendDocMsg() {
if ( isEditPaneShowed ) {
if ( tabbedPane.getSelectedIndex() != -1 ) {
Socket socket = null;
ObjectOutputStream oos = null;
try {
InetAddress address =
InetAddress.getByName( ipTextField.getText() );
socket = new Socket( address, PORT );
oos =
new ObjectOutputStream(
new BufferedOutputStream(
socket.getOutputStream() ) );
NewTextPane textPane = getCurrentTextPane();
oos.writeObject( textPane );
oos.close();
textPane.setPath( null );
JOptionPane.showMessageDialog(
RealEditorFrame.this, "Send Document Successfully !",
"INFORMATION", JOptionPane.INFORMATION_MESSAGE );
} catch (Exception ex) {
JOptionPane.showMessageDialog(
RealEditorFrame.this, ex.getMessage(),
"ERROR", JOptionPane.ERROR_MESSAGE );
ex.printStackTrace();
} finally {
try {
if ( socket != null )
socket.close();
if ( oos != null )
oos.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
} else {
Toolkit.getDefaultToolkit().beep();
}
} else {
send();
}
}
private void send() {
String msg = msgTextField.getText();
byte[] buffer = msg.getBytes();
try {
InetAddress address = InetAddress.getByName( ipTextField.getText() );
DatagramPacket datagramPacket =
new DatagramPacket(
buffer, buffer.length,
address, PORT2 );
String s = address.toString();
if ( s.indexOf( "/" ) == 0 ) {
s = s.substring( 1 );
}
try {
datagramSocket.send( datagramPacket );
list.add( "\" " + msg + " \"" +
" [ To " + s +
" ] [ " + TimeFormat.getSimpleTime() + " ]", 0 );
msgTextField.setText( "" );
} catch (IOException e) {
JOptionPane.showMessageDialog(
RealEditorFrame.this, e.getMessage(),
"ERROR", JOptionPane.ERROR_MESSAGE );
e.printStackTrace();
}
} catch (UnknownHostException e) {
JOptionPane.showMessageDialog(
RealEditorFrame.this, e.getMessage(),
"ERROR", JOptionPane.ERROR_MESSAGE );
e.printStackTrace();
}
}
private synchronized void accept() {
Thread acceptThread = new Thread() {
public void run() {
Socket socket = null;
try {
while( true ) {
socket = serverSocket.accept();
new DealThread( socket ).start();
}
} catch (Exception e) {
if ( socket != null )
if ( !socket.isClosed() )
e.printStackTrace();
} finally {
try {
if ( socket != null )
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
};
acceptThread.start();
}
private void receive() {
Thread receiveThread = new Thread() {
public void run() {
byte[] buffer = new byte[ 1024 ];
DatagramPacket datagramPacket =
new DatagramPacket( buffer, buffer.length );
try {
while ( true ) {
datagramSocket.receive( datagramPacket );
list.add(
"\" " + new String( buffer, 0, datagramPacket.getLength() ) + " \"" +
" [ From " + datagramPacket.getAddress().getHostAddress() +
" ] [ " +
TimeFormat.getSimpleTime() + " ]", 0 );
}
} catch (IOException e) {
if ( !datagramSocket.isClosed() )
e.printStackTrace();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -