📄 mwindow.java
字号:
package net.jumperz.app.MDoorman.windows;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import java.io.*;
import java.util.*;
import net.jumperz.app.MDoorman.*;
import net.jumperz.util.*;
public abstract class MWindow
implements Listener, MConstants
{
protected Shell shell;
protected MProperties prop;
protected boolean permanent = true;
private String windowName;
protected int[] windowValue = new int[]{ 200, 300, 100, 100 };
protected MDoorman doorman;
protected FormLayout formLayout;
protected static FormData buttonFormData1, buttonFormData2, buttonFormData3;
private boolean initialized = false;
static
{
buttonFormData1 = new FormData( BUTTON_WIDTH, BUTTON_HEIGHT );
buttonFormData1.right = new FormAttachment( 100, BUTTON1_RIGHT );
buttonFormData1.bottom = new FormAttachment( 100, BUTTON1_BOTTOM );
buttonFormData2 = new FormData( BUTTON_WIDTH, BUTTON_HEIGHT );
buttonFormData2.right = new FormAttachment( 100, BUTTON2_RIGHT );
buttonFormData2.bottom = new FormAttachment( 100, BUTTON2_BOTTOM );
buttonFormData3 = new FormData( BUTTON_WIDTH, BUTTON_HEIGHT );
buttonFormData3.right = new FormAttachment( 100, BUTTON3_RIGHT );
buttonFormData3.bottom = new FormAttachment( 100, BUTTON3_BOTTOM );
}
// --------------------------------------------------------------------------------
public MWindow( String windowName, Shell shell )
{
this.windowName = windowName;
this.shell = shell;
init();
}
// --------------------------------------------------------------------------------
protected void onClose2()
{
}
// --------------------------------------------------------------------------------
public void close()
{
shell.close();
}
// --------------------------------------------------------------------------------
public Shell getShell()
{
return shell;
}
// --------------------------------------------------------------------------------
private void init()
{
doorman = MDoorman.getInstance();
prop = doorman.getProperties();
shell.setImage( doorman.icon );
shell.setText( windowName );
formLayout = new FormLayout();
shell.setLayout( formLayout );
init2();
loadShellBounds();
shell.addListener( SWT.Close, this );
shell.addListener( SWT.Resize, this );
shell.addListener( SWT.Move, this );
initialized = true;
}
// --------------------------------------------------------------------------------
protected void init2()
{
}
// --------------------------------------------------------------------------------
protected void handleEvent2( Event event )
{
}
// --------------------------------------------------------------------------------
public void loadShellBounds()
{
int height = prop.getIntProperty( windowName + ".height" , windowValue[ 0 ] );
int width = prop.getIntProperty( windowName + ".width" , windowValue[ 1 ] );
int top = prop.getIntProperty( windowName + ".top" , windowValue[ 2 ] );
int left = prop.getIntProperty( windowName + ".left" , windowValue[ 3 ] );
shell.setSize( width, height );
shell.setLocation( left, top );
}
// --------------------------------------------------------------------------------
public void saveWindowBounds()
{
prop.setProperty( windowName + ".height", shell.getSize().y );
prop.setProperty( windowName + ".width", shell.getSize().x );
prop.setProperty( windowName + ".top", shell.getLocation().y );
prop.setProperty( windowName + ".left", shell.getLocation().x );
}
// --------------------------------------------------------------------------------
public final void handleEvent( Event event )
{
if( !initialized )
{
return;
}
if( event.widget == shell )
{
switch( event.type )
{
case SWT.Close:
onClose( event );
break;
case SWT.Resize:
onShellResize();
break;
case SWT.Move:
onMove();
break;
}
}
if( prop.getBooleanProperty( "debug" ) )
{
System.out.println( event );
}
handleEvent2( event );
}
// --------------------------------------------------------------------------------
protected void onMove()
{
onShellResize();
}
// --------------------------------------------------------------------------------
protected void onShellResize()
{
saveWindowBounds();
}
// --------------------------------------------------------------------------------
private void onClose( Event e )
{
saveWindowBounds();
onClose2();
if( permanent )
{
e.doit = false;
shell.setVisible( false );
}
}
// --------------------------------------------------------------------------------
public void setVisible( boolean b )
{
shell.setVisible( b );
}
// --------------------------------------------------------------------------------
public boolean isVisible()
{
return shell.isVisible();
}
// --------------------------------------------------------------------------------
public String getWindowName()
{
return windowName;
}
// --------------------------------------------------------------------------------
public void open()
{
shell.open();
}
// --------------------------------------------------------------------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -