📄 moptionwindow.java
字号:
package net.jumperz.app.MDoorman.windows;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import net.jumperz.app.MDoorman.MBreak;
import net.jumperz.app.MDoorman.MDoorman;
import net.jumperz.app.MDoorman.MFilter;
import net.jumperz.gui.MSwtUtil;
import net.jumperz.util.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
public class MOptionWindow
extends MWindow
{
private static final String WINDOW_NAME = "Options";
public static final int WINDOW_STYLE = SWT.MAX | SWT.MIN | SWT.RESIZE ;
//public static final int WINDOW_STYLE = SWT.MAX | SWT.MIN | SWT.RESIZE | SWT.APPLICATION_MODAL;
private Tree optionTree;
private Label label1, fontLabel, proxyLabel1;
private Button okButton, cancelButton;
private Composite baseComposite, filterComposite, breakComposite, fontComposite, encodingComposite, proxyComposite;
private SashForm sashForm;
private TreeItem filterItem, breakItem, fontItem, encodingItem, proxyItem;
private java.util.List compositeList;
private Map itemCompositeMap;
private Table filterTable, breakTable;
private TableColumn filterTableColumn1, filterTableColumn2, filterTableColumn3, filterTableColumn4, breakTableColumn1, breakTableColumn2, breakTableColumn3, breakTableColumn4, breakTableColumn5;
private Button filterEditButton, filterAddButton, filterRemoveButton, breakEditButton, breakAddButton, breakRemoveButton, fontButton, applyButton, proxyButton1;
public java.util.List filterList, breakList;
private FontData fontData;
private Combo encodingCombo;
private String enc;
private Text proxyHostText1, proxyHostText2, proxyPortText1, proxyPortText2;
public boolean useProxy = false;
public String proxyHost1, proxyHost2;
public int proxyPort1, proxyPort2;
// --------------------------------------------------------------------------------
public MOptionWindow()
{
super( WINDOW_NAME, new Shell( MDoorman.getInstance().mainShell, WINDOW_STYLE ) );
}
//-------------------------------------------------------------------------------
protected void init2()
{
getOptions();
//permanent = false;
shell.addListener( SWT.Activate, this );
itemCompositeMap = new HashMap();
compositeList = new ArrayList();
windowValue = new int[]{ 200, 300, 100, 500 };
okButton = new Button( shell, SWT.PUSH );
okButton.setLayoutData( buttonFormData1 );
okButton.setText( "&OK" );
okButton.addListener( SWT.Selection, this );
cancelButton = new Button( shell, SWT.PUSH );
cancelButton.setLayoutData( buttonFormData2 );
cancelButton.setText( "&Cancel" );
cancelButton.addListener( SWT.Selection, this );
applyButton = new Button( shell, SWT.PUSH );
applyButton.setLayoutData( buttonFormData3 );
applyButton.setText( "&Apply" );
applyButton.addListener( SWT.Selection, this );
FormData d4 = new FormData();
d4.bottom = new FormAttachment( 100, -43 );
d4.left = new FormAttachment( 0, 1 );
d4.right = new FormAttachment( 100, -1 );
label1 = new Label( shell, SWT.SEPARATOR | SWT.HORIZONTAL );
label1.setLayoutData( d4 );
FormData d1 = new FormData();
d1.top = new FormAttachment( 0, 1 );
d1.left = new FormAttachment( 0, 1 );
d1.right = new FormAttachment( 100, 0 );
d1.bottom = new FormAttachment( 100, -45 );
sashForm = new SashForm( shell, SWT.HORIZONTAL );
sashForm.setLayoutData( d1 );
optionTree = new Tree( sashForm, SWT.BORDER );
optionTree.addListener( SWT.Resize, this );
optionTree.addListener( SWT.Selection, this );
baseComposite = new Composite( sashForm, SWT.NULL );
baseComposite.setLayout( formLayout );
filterItem = new TreeItem( optionTree, SWT.NULL );
filterItem.setText( "Filter" );
breakItem = new TreeItem( optionTree, SWT.NULL );
breakItem.setText( "Break" );
fontItem = new TreeItem( optionTree, SWT.NULL );
fontItem.setText( "Font" );
encodingItem = new TreeItem( optionTree, SWT.NULL );
encodingItem.setText( "Encoding" );
proxyItem = new TreeItem( optionTree, SWT.NULL );
proxyItem.setText( "Proxy" );
int[] weights = new int[ 2 ];
weights[ 0 ] = prop.getIntProperty( WINDOW_NAME + ".weight1", 30 );
weights[ 1 ] = prop.getIntProperty( WINDOW_NAME + ".weight2", 70 );
sashForm.setWeights( weights );
// filter
filterComposite = new Composite( baseComposite, SWT.NULL );
compositeList.add( filterComposite );
itemCompositeMap.put( filterItem, filterComposite );
filterComposite.setVisible( false );
filterComposite.setLayout( formLayout );
FormData d5 = new FormData();
d5.top = new FormAttachment( 0, 10 );
d5.left = new FormAttachment( 0, 10 );
d5.right = new FormAttachment( 100, -10 );
d5.bottom = new FormAttachment( 100, -10 );
filterComposite.setLayoutData( d5 );
filterTable = new Table( filterComposite, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION );
filterTable.addListener( SWT.Selection, this );
filterTable.addListener( SWT.MouseDoubleClick, this );
filterTable.setHeaderVisible( true );
filterTable.setLinesVisible( true );
FormData d7 = new FormData();
d7.top = new FormAttachment( 0, 1 );
d7.left = new FormAttachment( 0, 1 );
d7.right = new FormAttachment( 100, -1 );
d7.bottom = new FormAttachment( 100, -45 );
filterTable.setLayoutData( d7 );
filterTableColumn1 = new TableColumn( filterTable, SWT.NONE );
filterTableColumn1.setText( "Enabled" );
filterTableColumn2 = new TableColumn( filterTable, SWT.NONE );
filterTableColumn2.setText( "Name" );
filterTableColumn3 = new TableColumn( filterTable, SWT.NONE );
filterTableColumn3.setText( "Pattern" );
filterTableColumn4 = new TableColumn( filterTable, SWT.NONE );
filterTableColumn4.setText( "Ignore case" );
MSwtUtil.getTableColumnWidthFromProperties( "filterTable", filterTable, prop );
filterEditButton = new Button( filterComposite, SWT.PUSH );
filterEditButton.setText( "Edit" );
filterEditButton.setLayoutData( buttonFormData1 );
filterEditButton.addListener( SWT.Selection, this );
filterAddButton = new Button( filterComposite, SWT.PUSH );
filterAddButton.setText( "Add" );
filterAddButton.setLayoutData( buttonFormData3 );
filterAddButton.addListener( SWT.Selection, this );
filterRemoveButton = new Button( filterComposite, SWT.PUSH );
filterRemoveButton.setText( "Remove" );
filterRemoveButton.setLayoutData( buttonFormData2 );
filterRemoveButton.addListener( SWT.Selection, this );
MSwtUtil.addListenerToTableColumns( filterTable, this );
// break
breakComposite = new Composite( baseComposite, SWT.NULL );
compositeList.add( breakComposite );
itemCompositeMap.put( breakItem, breakComposite );
breakComposite.setVisible( false );
breakComposite.setLayout( formLayout );
breakComposite.setLayoutData( d5 );
breakTable = new Table( breakComposite, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION );
breakTable.addListener( SWT.Selection, this );
breakTable.addListener( SWT.MouseDoubleClick, this );
breakTable.setHeaderVisible( true );
breakTable.setLinesVisible( true );
breakTable.setLayoutData( d7 );
breakTableColumn1 = new TableColumn( breakTable, SWT.NONE );
breakTableColumn1.setText( "Enabled" );
breakTableColumn2 = new TableColumn( breakTable, SWT.NONE );
breakTableColumn2.setText( "Name" );
breakTableColumn3 = new TableColumn( breakTable, SWT.NONE );
breakTableColumn3.setText( "Pattern" );
breakTableColumn4 = new TableColumn( breakTable, SWT.NONE );
breakTableColumn4.setText( "Ignore case" );
breakTableColumn5 = new TableColumn( breakTable, SWT.NONE );
breakTableColumn5.setText( "Type" );
breakEditButton = new Button( breakComposite, SWT.PUSH );
breakEditButton.setText( "Edit" );
breakEditButton.setLayoutData( buttonFormData1 );
breakEditButton.addListener( SWT.Selection, this );
breakAddButton = new Button( breakComposite, SWT.PUSH );
breakAddButton.setText( "Add" );
breakAddButton.setLayoutData( buttonFormData3 );
breakAddButton.addListener( SWT.Selection, this );
breakRemoveButton = new Button( breakComposite, SWT.PUSH );
breakRemoveButton.setText( "Remove" );
breakRemoveButton.setLayoutData( buttonFormData2 );
breakRemoveButton.addListener( SWT.Selection, this );
//font
fontComposite = new Composite( baseComposite, SWT.NULL );
compositeList.add( fontComposite );
itemCompositeMap.put( fontItem, fontComposite );
fontComposite.setVisible( false );
fontComposite.setLayout( formLayout );
fontComposite.setLayoutData( d5 );
FormData d9 = new FormData();
d9.top = new FormAttachment( 0, 40 );
d9.left = new FormAttachment( 0, 10 );
fontButton = new Button( fontComposite, SWT.PUSH );
fontButton.setText( "Change ..." );
fontButton.setLayoutData( d9 );
fontButton.addListener( SWT.Selection, this );
FormData d8 = new FormData();
d8.top = new FormAttachment( 0, 10 );
d8.left = new FormAttachment( 0, 10 );
fontLabel = new Label( fontComposite, SWT.NULL );
fontLabel.setLayoutData( d8 );
//encoding
encodingComposite = new Composite( baseComposite, SWT.NULL );
compositeList.add( encodingComposite );
itemCompositeMap.put( encodingItem, encodingComposite );
encodingComposite.setVisible( false );
encodingComposite.setLayout( formLayout );
encodingComposite.setLayoutData( d5 );
encodingCombo = new Combo( encodingComposite, SWT.READ_ONLY );
FormData d10 = new FormData( 150, 10 );
d10.top = new FormAttachment( 0, 10 );
d10.left = new FormAttachment( 0, 10 );
encodingCombo.setLayoutData( d10 );
Iterator p = java.nio.charset.Charset.availableCharsets().keySet().iterator();
while( p.hasNext() )
{
encodingCombo.add( ( String )p.next() );
}
encodingCombo.setVisibleItemCount( 20 );
encodingCombo.addListener( SWT.Selection, this );
//proxy
proxyComposite = new Composite( baseComposite, SWT.NULL );
compositeList.add( proxyComposite );
itemCompositeMap.put( proxyItem, proxyComposite );
proxyComposite.setVisible( false );
proxyComposite.setLayout( formLayout );
proxyComposite.setLayoutData( d5 );
proxyButton1 = new Button( proxyComposite, SWT.CHECK );
FormData d11 = new FormData();
d11.left = new FormAttachment( 0, 10 );
d11.top = new FormAttachment( 0, 10 );
proxyButton1.setLayoutData( d11 );
proxyLabel1 = new Label( proxyComposite, SWT.NONE );
proxyLabel1.setText( "Use External Proxy" );
FormData d12 = new FormData();
d12.left = new FormAttachment( 0, 30 );
d12.top = new FormAttachment( 0, 10 );
proxyLabel1.setLayoutData( d12 );
proxyLabel1.addListener( SWT.MouseDown, this );
Label proxyLabel2 = new Label( proxyComposite, SWT.NONE );
proxyLabel2.setText( "HTTP:" );
FormData d13 = new FormData();
d13.left = new FormAttachment( 0, 30 );
d13.top = new FormAttachment( 0, 40 );
proxyLabel2.setLayoutData( d13 );
Label proxyLabel3 = new Label( proxyComposite, SWT.NONE );
proxyLabel3.setText( "HTTPS:" );
FormData d14 = new FormData();
d14.left = new FormAttachment( 0, 30 );
d14.top = new FormAttachment( 0, 70 );
proxyLabel3.setLayoutData( d14 );
proxyHostText1 = new Text( proxyComposite, SWT.BORDER );
FormData d15 = new FormData();
d15.left = new FormAttachment( 0, 70 );
d15.right = new FormAttachment( 0, 180 );
d15.top = new FormAttachment( 0, 38 );
proxyHostText1.setLayoutData( d15 );
proxyPortText1 = new Text( proxyComposite, SWT.BORDER );
FormData d18 = new FormData();
d18.left = new FormAttachment( 0, 220 );
d18.right = new FormAttachment( 0, 280 );
d18.top = new FormAttachment( 0, 38 );
proxyPortText1.setLayoutData( d18 );
proxyHostText2 = new Text( proxyComposite, SWT.BORDER );
FormData d16 = new FormData();
d16.left = new FormAttachment( 0, 70 );
d16.right = new FormAttachment( 0, 180 );
d16.top = new FormAttachment( 0, 68 );
proxyHostText2.setLayoutData( d16 );
proxyPortText2 = new Text( proxyComposite, SWT.BORDER );
FormData d17 = new FormData();
d17.left = new FormAttachment( 0, 220 );
d17.right = new FormAttachment( 0, 280 );
d17.top = new FormAttachment( 0, 68 );
proxyPortText2.setLayoutData( d17 );
Label proxyLabel4 = new Label( proxyComposite, SWT.NONE );
proxyLabel4.setText( "Port:" );
FormData d19 = new FormData();
d19.left = new FormAttachment( 0, 190 );
d19.top = new FormAttachment( 0, 70 );
proxyLabel4.setLayoutData( d19 );
Label proxyLabel5 = new Label( proxyComposite, SWT.NONE );
proxyLabel5.setText( "Port:" );
FormData d20 = new FormData();
d20.left = new FormAttachment( 0, 190 );
d20.top = new FormAttachment( 0, 40 );
proxyLabel5.setLayoutData( d20 );
//
MSwtUtil.getTableColumnWidthFromProperties( "breakTable", breakTable, prop );
MSwtUtil.addListenerToTableColumns( breakTable, this );
shell.setDefaultButton( okButton );
updateFilterTable();
updateBreakTable();
updateGui();
showComposite( filterComposite );
}
//--------------------------------------------------------------------------------
private void proxyEnableSelect()
{
proxyButton1.setSelection( !proxyButton1.getSelection() );
}
// --------------------------------------------------------------------------------
public void getOptions()
{
filterList = new ArrayList();
MSystemUtil.deepCopy( doorman.filterList, filterList );
breakList = new ArrayList();
MSystemUtil.deepCopy( doorman.breakList, breakList );
fontData = doorman.getFontData();
enc = doorman.getEnc();
useProxy = doorman.useProxy;
proxyHost1 = doorman.proxyHost1;
proxyHost2 = doorman.proxyHost2;
proxyPort1 = doorman.proxyPort1;
proxyPort2 = doorman.proxyPort2;
}
// --------------------------------------------------------------------------------
private void setFontLabel()
{
fontLabel.setText( "Font : " + fontData.getName() + "," + fontData.getHeight() );
fontLabel.pack();
}
// --------------------------------------------------------------------------------
private void showComposite( Composite c )
{
Iterator p = compositeList.iterator();
while( p.hasNext() )
{
Composite composite = ( Composite )p.next();
if( composite == c )
{
composite.setVisible( true );
}
else
{
composite.setVisible( false );
}
}
}
// --------------------------------------------------------------------------------
protected void handleEvent2( Event event )
{
if( event.widget == shell )
{
switch( event.type )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -