Java by API/org.eclipse.jface.dialogs/IconAndMessageDialog — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:32, 31 мая 2010
extends IconAndMessageDialog
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.IconAndMessageDialog;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.ruposite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class MainClass extends ApplicationWindow {
public MainClass() {
super(null);
}
public void run() {
setBlockOnOpen(true);
open();
Display.getCurrent().dispose();
}
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText("Send Message");
shell.setSize(500, 400);
MyMessageDialog dlg = new MyMessageDialog(shell);
dlg.open();
}
public static void main(String[] args) {
new MainClass().run();
}
}
class MyMessageDialog extends IconAndMessageDialog {
public static final int MyID = IDialogConstants.CLIENT_ID;
public static final String MyLABEL = "Custom";
private Image image;
private Label label;
public MyMessageDialog(Shell parent) {
super(parent);
try {
image = new Image(parent.getDisplay(), new FileInputStream("images/loser.gif"));
} catch (FileNotFoundException e) {
}
message = "message";
}
public void setMessage(String message) {
this.message = message;
}
public boolean close() {
if (image != null)
image.dispose();
return super.close();
}
protected Control createDialogArea(Composite parent) {
createMessageArea(parent);
Composite composite = new Composite(parent, SWT.NONE);
GridData data = new GridData(GridData.FILL_BOTH);
data.horizontalSpan = 2;
composite.setLayoutData(data);
composite.setLayout(new FillLayout());
label = new Label(composite, SWT.LEFT);
return composite;
}
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
createButton(parent, MyID, MyLABEL, false);
}
protected void buttonPressed(int buttonId) {
if (buttonId == MyID) {
setReturnCode(buttonId);
close();
} else {
label.setText("Yeah, right. You know nothing.");
}
}
protected Image getImage() {
return image;
}
}