📄 addressbar.java
字号:
/*
* Copyright (c) 2007 Software Wizards Pty Ltd, Victoria, Australia.
* mailto:enquires@swz.com.au. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted. See the GNU General Public License
* for more details.
*
* Redistribution of the SWTtoCOM software is not permitted as part of any
* commercial product. Licensing terms for such distribution may be
* obtained from the copyright holder.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package au.com.swz.swttocom.example.browser;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class AddressBar {
private static final Image ICON = ImageDescriptor.createFromFile(
SWTBrowser.class, "actions/images/go.gif").createImage(); //$NON-NLS-1$
private SWTBrowser browserManager;
private Text addressText;
public AddressBar(SWTBrowser browserManager) {
this.browserManager = browserManager;
}
public Composite createComposite(Composite parent) {
Composite client = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(1, true);
gridLayout.marginWidth = 2;
gridLayout.marginHeight = 2;
gridLayout.numColumns = 3;
gridLayout.makeColumnsEqualWidth = false;
gridLayout.horizontalSpacing = 2;
gridLayout.verticalSpacing = 0;
client.setLayout(gridLayout);
Label label = new Label(client, SWT.LEFT);
GridData layoutData = new GridData();
layoutData.verticalAlignment = GridData.CENTER;
layoutData.horizontalAlignment = GridData.BEGINNING;
layoutData.widthHint = -1;
layoutData.heightHint = -1;
layoutData.horizontalIndent = 0;
layoutData.horizontalSpan = 1;
layoutData.verticalSpan = 1;
layoutData.grabExcessHorizontalSpace = false;
layoutData.grabExcessVerticalSpace = false;
label.setLayoutData(layoutData);
label.setText("Address");
addressText = new Text(client, SWT.FLAT|SWT.BORDER);
layoutData = new GridData();
layoutData.verticalAlignment = GridData.CENTER;
layoutData.horizontalAlignment = GridData.FILL;
layoutData.widthHint = -1;
layoutData.heightHint = -1;
layoutData.horizontalIndent = 0;
layoutData.horizontalSpan = 1;
layoutData.verticalSpan = 1;
layoutData.grabExcessHorizontalSpace = true;
layoutData.grabExcessVerticalSpace = true;
addressText.setLayoutData(layoutData);
addressText.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
navigate();
}
}
});
Button goBtn = new Button(client, SWT.PUSH|SWT.FLAT);
goBtn.setImage(ICON);
layoutData = new GridData();
layoutData.verticalAlignment = GridData.CENTER;
layoutData.horizontalAlignment = GridData.CENTER;
layoutData.widthHint = -1;
layoutData.heightHint = -1;
layoutData.horizontalIndent = 0;
layoutData.horizontalSpan = 1;
layoutData.verticalSpan = 1;
layoutData.grabExcessHorizontalSpace = false;
layoutData.grabExcessVerticalSpace = false;
goBtn.setLayoutData(layoutData);
goBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
navigate();
}
});
return client;
}
public void setAddress(String text) {
addressText.setText(text);
}
private void navigate() {
BrowserTabItem tabItem = browserManager.getSelection();
if (tabItem != null) {
tabItem.navigate(addressText.getText());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -