📄 socketswingclient.java
字号:
/* ===========================================================
* JDBMonitor : a flexiable JDBC Monitor for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2006-2006, by yang zhongke
*
* Project Info: http://www.cownew.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ---------------
* SocketSwingClient.java
* ---------------
* (C) Copyright 2006-2006, by yang zhongke
*
* Original Author: yang zhongke;
*
* Changes
* -------
*
*/
package com.cownew.JDBMonitor.listenerImpl.sckListenerClient;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import com.cownew.JDBMonitor.common.InstanceUtils;
import com.cownew.JDBMonitor.common.SQLInfo;
import com.cownew.JDBMonitor.listenerImpl.uicommon.SwingUtils;
public class SocketSwingClient extends AbstractSocketSwingClient
implements IDBSocketClientListener
{
private static final long serialVersionUID = -1459937898254143632L;
private ConnectConfigDialog dialog;
protected ListenerClient listenerClient;
protected boolean isScrollLock = false;
protected void menuItemCreateConnect_actionPerformed(ActionEvent arg0)
{
showConnectDialog();
}
private boolean showConnectDialog()
{
if(dialog==null)
{
dialog = new ConnectConfigDialog(this);
dialog.setSize(300, 100);
}
dialog.show();
if(dialog.isOK())
{
try
{
if(listenerClient!=null)
{
disconnect();
}
connect();
menuItemStop.setEnabled(true);
menuItemStart.setEnabled(false);
} catch (IOException e)
{
handleException(e);
}
return true;
}
return false;
}
protected void menuItemStart_actionPerformed(ActionEvent e)
{
try
{
connect();
} catch (IOException ioe)
{
handleException(ioe);
}
menuItemStop.setEnabled(true);
menuItemStart.setEnabled(false);
}
protected void menuItemStop_actionPerformed(ActionEvent e)
{
try
{
disconnect();
} catch (IOException ioe)
{
handleException(ioe);
}
menuItemStop.setEnabled(false);
menuItemStart.setEnabled(true);
}
protected void connect() throws IOException
{
listenerClient = new ListenerClient(dialog.getHostName(),dialog.getPort(),this);
listenerClient.connect();
textAreaMsg.append("connected!\n");
}
protected void disconnect() throws IOException
{
if(listenerClient!=null)
listenerClient.close();
}
public void receive(SQLInfo msg)
{
textAreaMsg.append(msg.toString());
textAreaMsg.append("\n");
if(!isScrollLock)
{
textAreaMsg.setCaretPosition(textAreaMsg.getText().length());
}
}
protected void menuItemClear_actionPerformed(ActionEvent arg0)
{
textAreaMsg.setText("");
}
protected void menuItemCopy_actionPerformed(ActionEvent arg0)
{
textAreaMsg.copy();
}
protected void menuItemSelectAll_actionPerformed(ActionEvent arg0)
{
textAreaMsg.selectAll();
}
protected void menuItemAbout_actionPerformed(ActionEvent arg0)
{
StringBuffer sb = new StringBuffer();
sb.append("CopyRight by Yang Zhongke\n");
sb.append("about521@163.com\n");
sb.append("www.cownew.com\n");
sb.append("Made in China!\n");
JOptionPane.showMessageDialog(this,sb.toString());
}
protected void menuItemScrollLock_actionPerformed(ActionEvent arg0)
{
isScrollLock = ! isScrollLock;
}
protected void menuItemSave_actionPerformed(ActionEvent arg0)
{
JFileChooser fileDlg = new JFileChooser();
if(fileDlg.showSaveDialog(this)==JFileChooser.APPROVE_OPTION)
{
DataOutputStream dos = null;
try
{
File file = fileDlg.getSelectedFile();
dos = new DataOutputStream(new FileOutputStream(file));
dos.writeBytes(textAreaMsg.getText());
} catch (FileNotFoundException e)
{
handleException(e);
} catch (IOException e)
{
handleException(e);
}
finally
{
InstanceUtils.closeOutStream(dos);
}
}
}
protected void menuItemFind_actionPerformed(ActionEvent arg0)
{
FindDialog findDlg = FindDialog.getFindDialog(this,textAreaMsg);
findDlg.show();
}
public static void main(String[] args)
{
JFrame mainForm = new SocketSwingClient();
mainForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SwingUtils.initWindowSize(mainForm);
mainForm.setTitle("JDBMonitor Client Listener");
mainForm.show();
}
protected void onOpend(WindowEvent e)
{
super.onOpend(e);
if(showConnectDialog()==false)
{
dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -