📄 mtomato.java
字号:
package net.jumperz.app.MTomato;
import java.util.*;
import java.io.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class MTomato
implements Listener
{
protected static String appName = "MTomato@JUMPERZ.NET";
private static final String defaultHeight = "320";
private static final String defaultWidth = "500";
private static final String defaultTop = "100";
private static final String defaultLeft = "100";
private int height;
private int width;
private int top;
private int left;
private File configFile;
protected Properties prop;
protected Shell shell;
private static MTomato instance;
//-----------------------------------------------------------------------------------
public static final MTomato getInstance()
{
return instance;
}
//-----------------------------------------------------------------------------------
public static void main( String[] args )
throws Exception
{
if( args.length == 1 )
{
instance = new MTomato( args[ 0 ] );
instance.startShell();
}
else
{
System.out.println( "Usage: java net.jumperz.app.MTomato.MTomato [ CONFIG_FILE_NAME ]" );
return;
}
}
//-----------------------------------------------------------------------------------
public MTomato( String configFileName )
throws IOException
{
configFile = new File( configFileName );
loadConfig();
}
//-----------------------------------------------------------------------------------
private void loadConfig()
throws IOException
{
prop = new Properties();
if( configFile.exists() )
{
FileInputStream inifile_in = new FileInputStream( configFile );
prop.load( inifile_in );
}
height = Integer.parseInt( prop.getProperty( "height" , defaultHeight ) );
width = Integer.parseInt( prop.getProperty( "width" , defaultWidth ) );
top = Integer.parseInt( prop.getProperty( "top" , defaultTop ) );
left = Integer.parseInt( prop.getProperty( "left" , defaultLeft ) );
}
//-----------------------------------------------------------------------------------
public void startShell()
throws Exception
{
Display display = new Display();
shell = new Shell( display );
startApplication();
shell.setText( appName );
shell.setSize( width, height );
shell.setLocation( left, top );
shell.setLayout( new FillLayout() );
Button button1 = new Button( shell,SWT.NULL );
button1.setText( "button1" );
shell.addListener( SWT.Close , this );
shell.open ();
//shell.addListener( SWT.Resize , this );
while (!shell.isDisposed ())
{
if ( !display.readAndDispatch () )
{
display.sleep ();
}
}
display.dispose ();
}
//-----------------------------------------------------------------------------------
private void saveConfig()
throws IOException
{
Point size = shell.getSize();
prop.setProperty( "width" , String.valueOf( size.x ) );
prop.setProperty( "height" , String.valueOf( size.y ) );
Point location = shell.getLocation();
prop.setProperty( "top" , String.valueOf( location.y ) );
prop.setProperty( "left" , String.valueOf( location.x ) );
FileOutputStream configFileOut = new FileOutputStream( configFile );
prop.store( configFileOut, "" );
}
//-----------------------------------------------------------------------------------
public final void handleEvent( Event event )
{
try
{
switch( event.type )
{
case SWT.Close:
this.onClose();
break;
case SWT.Resize:
this.onResize();
break;
}
}
catch( Exception e )
{
System.out.println( event );
e.printStackTrace();
}
}
//-----------------------------------------------------------------------------------
protected void onResize()
throws Exception
{
}
//-----------------------------------------------------------------------------------
protected void onClose()
throws Exception
{
saveConfig();
}
//-----------------------------------------------------------------------------------
protected void startApplication()
throws Exception
{
}
//-----------------------------------------------------------------------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -