1 19 20 package com.sslexplorer.agent.client.gui.swt; 21 22 import java.io.IOException ; 23 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.events.PaintEvent; 26 import org.eclipse.swt.events.PaintListener; 27 import org.eclipse.swt.events.SelectionAdapter; 28 import org.eclipse.swt.events.SelectionEvent; 29 import org.eclipse.swt.events.SelectionListener; 30 import org.eclipse.swt.graphics.Image; 31 import org.eclipse.swt.layout.GridData; 32 import org.eclipse.swt.layout.GridLayout; 33 import org.eclipse.swt.widgets.Button; 34 import org.eclipse.swt.widgets.Canvas; 35 import org.eclipse.swt.widgets.Composite; 36 import org.eclipse.swt.widgets.Dialog; 37 import org.eclipse.swt.widgets.Label; 38 import org.eclipse.swt.widgets.Link; 39 import org.eclipse.swt.widgets.Shell; 40 41 import com.sslexplorer.agent.client.util.BrowserLauncher; 42 43 public class SWTAboutDialog extends Dialog { 44 45 private Shell shell; 46 private Composite accessory; 47 48 public SWTAboutDialog(Shell parent, String closeText, String title, final Image image, String message, String description, 49 String copyright, final String link) { 50 super(parent, SWT.TITLE | SWT.CLOSE | SWT.BORDER | SWT.RESIZE); 51 52 53 shell = new Shell(getParent(), getStyle()); 55 shell.setText(getText()); 56 shell.setLayout(new GridLayout(1, true)); 57 58 60 Composite commonAboutDetails = new Composite(shell, 0); 61 GridLayout gridLayout = new GridLayout(1, false); 62 gridLayout.verticalSpacing = 10; 63 GridData data = new GridData(GridData.CENTER, GridData.CENTER, true, true); 64 commonAboutDetails.setLayoutData(data); 67 commonAboutDetails.setLayout(gridLayout); 68 69 70 Button close = new Button(shell, SWT.PUSH); 72 close.setText(closeText); 73 close.addSelectionListener(new SelectionAdapter() { 74 public void widgetSelected(SelectionEvent event) { 75 shell.close(); 76 } 77 }); 78 data = new GridData(); 79 data.horizontalAlignment = GridData.CENTER; 80 data.grabExcessHorizontalSpace = true; 81 close.setLayoutData(data); 82 83 85 Canvas canvas = new Canvas(commonAboutDetails, SWT.NONE); 86 canvas.addPaintListener(new PaintListener() { 87 public void paintControl(PaintEvent e) { 88 e.gc.drawImage(image, 0, 0); 89 } 90 }); 91 data = new GridData(GridData.CENTER, GridData.CENTER, true, true); 92 data.widthHint = 48; 93 data.heightHint = 48; 94 canvas.setLayoutData(data); 95 96 Label messageLabel = new Label(commonAboutDetails, SWT.CENTER); 97 messageLabel.setFont(SWTUtil.newFont(parent.getDisplay(), messageLabel.getFont(), 18, SWT.BOLD)); 98 messageLabel.setText(message); 99 100 Label descriptionLabel = new Label(commonAboutDetails, SWT.WRAP | SWT.BEGINNING); 101 descriptionLabel.setText(description); 102 data = new GridData(); 103 data.widthHint = 400; 104 data.horizontalAlignment = GridData.CENTER; 105 data.grabExcessHorizontalSpace = true; 106 descriptionLabel.setLayoutData(data); 107 108 if (copyright != null) { 109 Label copyrightLabel = new Label(commonAboutDetails, SWT.WRAP | SWT.CENTER); 110 copyrightLabel.setText(copyright); 111 copyrightLabel.setFont(SWTUtil.newFont(parent.getDisplay(), copyrightLabel.getFont(), 8, 0)); 112 data = new GridData(); 113 data.horizontalAlignment = GridData.CENTER; 114 data.grabExcessHorizontalSpace = true; 115 copyrightLabel.setLayoutData(data); 116 } 117 118 if(link != null) { 119 Link linkButton = new Link(commonAboutDetails, SWT.CENTER); 120 linkButton.setText("<a HREF=\"" + link + "\">" + link + "</a>"); 121 data = new GridData(); 122 data.horizontalAlignment = GridData.CENTER; 123 data.grabExcessHorizontalSpace = true; 124 linkButton.setLayoutData(data); 125 linkButton.addSelectionListener(new SelectionListener() { 126 public void widgetDefaultSelected(SelectionEvent e) { 127 } 128 129 public void widgetSelected(SelectionEvent e) { 130 try { 131 BrowserLauncher.openURL(link); 132 } catch (IOException e1) { 133 e1.printStackTrace(); 134 } 135 } 136 }); 137 } 138 139 141 accessory = new Composite(commonAboutDetails, 0); 142 accessory.setLayout(new GridLayout(1, false)); 143 data = new GridData(); 144 data.horizontalAlignment = GridData.CENTER; 145 data.grabExcessHorizontalSpace = true; 146 accessory.setLayoutData(data); 147 } 148 149 public void open() { 150 shell.pack(); 151 SWTUtil.center(shell); 152 shell.open(); 153 } 154 155 public Composite getAccessory() { 156 return accessory; 157 } 158 } 159 | Popular Tags |