📄 mdoorman.java
字号:
package net.jumperz.app.MDoorman;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.*;
import java.io.*;
import java.util.*;
import java.net.*;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import net.jumperz.util.*;
import net.jumperz.io.*;
import net.jumperz.net.*;
import net.jumperz.app.MDoorman.windows.*;
public class MDoorman
implements Runnable
{
public MMainWindow mainWindow;
public MSessionWindow sessionWindow;
public MPeerWindow peerWindow;
public MRequestWindow requestWindow;
public MResponseWindow responseWindow;
public MOptionWindow optionWindow;
public MFilterWindow filterWindow;
public MGetQueryWindow getQueryWindow;
public MQueryEditWindow queryEditWindow;
public MPostQueryWindow postQueryWindow;
public List filterList, breakList;//, sessionList;
private File configFile;
private MProperties prop;
public Shell mainShell;
public MThreadPool threadPool;
private List windowList = new ArrayList();
private List fontList = new ArrayList();
public MBaseSession selectedSession;
public Image icon;
public boolean closed = false;
private static final String DEFAULT_CONFIG_FILE_NAME = "doorman.conf";
public static final String APPLICATION_NAME = "Doorman@JUMPERZ.NET";
private static final int THREAD_COUNT = 30;
private static MDoorman instance;
public static Display display;
private FontData fontData;
private Font font;
private String enc;
private FileDialog saveDialog, loadDialog;
public boolean useProxy = false;
public String proxyHost1, proxyHost2;
public int proxyPort1, proxyPort2;
// --------------------------------------------------------------------------------
public String loadFile()
{
loadDialog.setFileName( "" );
return loadDialog.open();
}
// --------------------------------------------------------------------------------
public String saveFile()
{
saveDialog.setFileName( "" );
return saveDialog.open();
}
// --------------------------------------------------------------------------------
public void updateGui()
{
display.asyncExec( this );
}
// --------------------------------------------------------------------------------
public void updateGui( MBaseSession session )
{
display.asyncExec( new MSessionGuiUpdator( session ) );
}
// --------------------------------------------------------------------------------
public void run()
{
mainWindow.updateGui();
}
// --------------------------------------------------------------------------------
public static MDoorman getInstance()
{
return instance;
}
// --------------------------------------------------------------------------------
public MDoorman( Shell mainShell )
{
this.mainShell = mainShell;
}
// --------------------------------------------------------------------------------
public void init()
throws Exception
{
MSslManager sslManager = new MSslManager();
sslManager.start();
icon = new Image( display, MStreamUtil.getResourceStream( "net/jumperz/app/MDoorman/resource/doorman.ico" ) );
saveDialog = new FileDialog( mainShell, SWT.SAVE );
saveDialog.setFilterPath( prop.getProperty( "saveDialogPath" ) );
loadDialog = new FileDialog( mainShell, SWT.OPEN );
loadDialog.setFilterPath( prop.getProperty( "loadDialogPath" ) );
filterList = prop.getListProperty( "filterList" );
breakList = prop.getListProperty( "breakList" );
mainWindow = new MMainWindow();
sessionWindow = new MSessionWindow();
requestWindow = new MRequestWindow();
responseWindow = new MResponseWindow();
getQueryWindow = new MGetQueryWindow();
postQueryWindow = new MPostQueryWindow();
//FontData
if( prop.containsKey( "font" ) )
{
fontData = ( FontData )MStringUtil.stringToObject( prop.getProperty( "font" ) );
}
else
{
fontData = mainShell.getFont().getFontData()[ 0 ];
}
setFontData( fontData );
//enc
enc = prop.getProperty( "enc", MCharset.CS_ISO_8859_1 );
//proxy
useProxy = prop.getBooleanProperty( "useProxy" );
proxyHost1 = prop.getProperty( "proxyHost1" );
proxyHost2 = prop.getProperty( "proxyHost2" );
proxyPort1 = prop.getIntProperty( "proxyPort1", 8080 );
proxyPort2 = prop.getIntProperty( "proxyPort2", 8080 );
optionWindow = new MOptionWindow();
peerWindow = new MPeerWindow();
peerWindow.open();
windowList.add( mainWindow );
windowList.add( sessionWindow );
windowList.add( requestWindow );
windowList.add( responseWindow );
windowList.add( optionWindow );
windowList.add( getQueryWindow );
windowList.add( postQueryWindow );
Iterator p = windowList.iterator();
while( p.hasNext() )
{
MWindow window = ( MWindow )p.next();
boolean visible = prop.getBooleanProperty( window.getWindowName() + ".visible" );
window.setVisible( visible );
}
threadPool = new MThreadPool( THREAD_COUNT );
MEngine.getInstance().setThreadPool( threadPool );
if( prop.getBooleanProperty( "debug" ) )
{
MStandardLogger.getInstance().addStream( System.out );
threadPool.setLogger( MStandardLogger.getInstance() );
}
}
// --------------------------------------------------------------------------------
public void shutdown()
{
try
{
closed = true;
saveConfig();
threadPool.stop();
disposeFonts();
deleteTmpFiles();
}
catch( Exception e )
{
handleException( e );
}
}
// --------------------------------------------------------------------------------
private void deleteTmpFiles()
{
MBuffer.closeStreams();
}
// --------------------------------------------------------------------------------
private void disposeFonts()
{
Iterator p = fontList.iterator();
while( p.hasNext() )
{
Font font = ( Font )p.next();
font.dispose();
}
}
// --------------------------------------------------------------------------------
public static void main( String[] args )
throws Exception
{
MHttpData.setStrictDelimiter( false ); // allow single ( CR or LF ) delimiter for HTTP headers
//MBuffer.setStaticMaxMemSize( 1024 * 1024 * 10 );
display = Display.getDefault();
Shell mainShell = new Shell( display );
instance = new MDoorman( mainShell );
instance.loadConfig( args );
instance.init();
while (!mainShell.isDisposed( ))
{
if ( !display.readAndDispatch( ) )
display.sleep( );
}
display.dispose();
}
// --------------------------------------------------------------------------------
private void loadConfig( String[] args )
throws IOException
{
String configFileName = null;
if( args.length == 1 )
{
configFileName = args[ 0 ];
}
else
{
configFileName = DEFAULT_CONFIG_FILE_NAME;
}
prop = new MProperties();
configFile = new File( configFileName );
InputStream in = null;
if( configFile.exists() && configFile.isFile() )
{
in = new FileInputStream( configFile );
}
else
{
in = MStreamUtil.getResourceStream( "net/jumperz/app/MDoorman/resource/doorman.conf" );
}
prop.load( in );
in.close();
}
// --------------------------------------------------------------------------------
private void saveConfig()
throws IOException
{
// window visiblity
Iterator p = windowList.iterator();
while( p.hasNext() )
{
MWindow window = ( MWindow )p.next();
boolean visible = window.isVisible();
prop.setProperty( window.getWindowName() + ".visible", visible );
}
// filter
prop.setProperty( "filterList", filterList );
prop.setProperty( "breakList", breakList );
prop.setProperty( "font", MStringUtil.objectToString( fontData ) );
prop.setProperty( "enc", enc );
prop.setProperty( "useProxy", useProxy );
prop.setProperty( "proxyHost1", proxyHost1 );
prop.setProperty( "proxyHost2", proxyHost2 );
prop.setProperty( "proxyPort1", proxyPort1 );
prop.setProperty( "proxyPort2", proxyPort2 );
//dialog
prop.setProperty( "saveDialogPath", saveDialog.getFilterPath() );
prop.setProperty( "loadDialogPath", loadDialog.getFilterPath() );
OutputStream out = new FileOutputStream( configFile );
try
{
prop.store( out );
}
finally
{
out.close();
}
}
// --------------------------------------------------------------------------------
public MProperties getProperties()
{
return prop;
}
// --------------------------------------------------------------------------------
public void handleException( Exception e )
{
e.printStackTrace();
}
// --------------------------------------------------------------------------------
public List getBreakList( int type )
{
List l = new ArrayList();
Iterator p = breakList.iterator();
while( p.hasNext() )
{
MBreak _break = ( MBreak )p.next();
if( _break.getType() == type )
{
l.add( _break );
}
}
return l;
}
// --------------------------------------------------------------------------------
public Font getFont()
{
return font;
}
// --------------------------------------------------------------------------------
public FontData getFontData()
{
return fontData;
}
// --------------------------------------------------------------------------------
public void setFontData( FontData fd )
{
fontData = fd;
font = new Font( display, fontData );
fontList.add( font );
requestWindow.setFont( font );
responseWindow.setFont( font );
sessionWindow.setFont( font );
getQueryWindow.setFont( font );
postQueryWindow.setFont( font );
}
// --------------------------------------------------------------------------------
public String getEnc()
{
return enc;
}
// --------------------------------------------------------------------------------
public void setEnc( String s )
{
if( !enc.equals( s ) )
{
enc = s;
if( selectedSession != null )
{
updateGui( selectedSession );
}
}
}
// --------------------------------------------------------------------------------
public void notifyException( Throwable e )
{
display.asyncExec( new MExceptionMessageBox( e ) );
}
// --------------------------------------------------------------------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -