[SWT]Dialog
SWTのDialogは、おそらく大多数の人の想像とはだいぶかけ離れた実装になっています。
まず、他のクラスから継承しているのではなく、Objectから継承しています。
普通ならShellとかWindowなどから継承していると考えるハズです。
ソースをみるとさらに驚きます。以下は、コメントを取り、適当に整形したものです。
package org.eclipse.swt.widgets; import org.eclipse.swt.*; public abstract class Dialog { int style; Shell parent; String title; public Dialog (Shell parent) { this (parent, SWT.PRIMARY_MODAL); } public Dialog (Shell parent, int style) { checkParent (parent); this.parent = parent; this.style = style; title = ""; } protected void checkSubclass () { if (!Display.isValidClass (getClass ())) { error (SWT.ERROR_INVALID_SUBCLASS); } } void checkParent (Shell parent) { if (parent == null) error (SWT.ERROR_NULL_ARGUMENT); parent.checkWidget (); } void error (int code) { SWT.error(code); } public Shell getParent () { return parent; } public int getStyle () { return style; } public String getText () { return title; } public void setText (String string) { if (string == null) error (SWT.ERROR_NULL_ARGUMENT); title = string; } }
なんと、たったのコレだけです。内容を見てみると、getterや簡単なチェックをするメソッドぐらいで、ほとんど何もしていません。
内部にネイティブなウィンドウクラスがあると想像していたのですが、それがありません。
それどころか、自分自身のShellのクラスすらありません。(親をあらわすShell parentはありますがそれだけです)
だから、ウィンドウを作る場合、Shellを明示的に作らなければなりません。
Dialogをnewしても、それはShellやそれに類するものがnewされたわけではないのです。
不思議な実装です。