最終年度のプロジェクトの一環として、「グラフィカルIDE」のカテゴリに該当するデスクトップアプリケーションを開発しました。情報アーキテクチャとインタラクションデザインのためのJessyJamesGarrett Visual Vocabularyの小さなサブセットを実装したので、ユーザーはWebアプリでのユーザーエクスペリエンスを表す図(つまり、有向グラフ)を描画し、ページにHTMLテンプレートを割り当てて、次のように書くことができます。アプリケーションがコンパイルされ、ユーザーが対応するハイパーリンクをクリックすると、実行されるコネクタ/トランジションへのコード。
(複数のハイパーリンクを投稿することはできませんが、JJGのビジュアルボキャブラリーで説明されているユーザーエクスペリエンスの要素のようなページとコネクタを参照しています)
そのため、別のSwingWorkersを使用して、ダイアグラムが変換されるC++ソースファイルのセットを生成しています。ログを見ると、アプリが再利用するのではなく、常に新しいスレッドを作成していることがわかります。
15:29:55.750 [SwingWorker-pool-2-thread-26] DEBUG i.v.a.ui.worker.ConnectorGenerator - Building source code for transition: connector_29
15:29:55.750 [SwingWorker-pool-2-thread-26] DEBUG i.v.a.ui.worker.ConnectorGenerator - Project retrieved: sasdasdasd
15:29:55.750 [SwingWorker-pool-2-thread-26] INFO i.v.a.webapp.htcpp.CTransition - Generated C:\Workspaces\PFC\aedifico-ui\sasdasdasd\connector_29_action.h...
15:29:55.750 [SwingWorker-pool-2-thread-26] INFO i.v.a.webapp.htcpp.CTransition - Generated C:\Workspaces\PFC\aedifico-ui\sasdasdasd\connector_29_action.cpp...
15:29:55.750 [SwingWorker-pool-2-thread-26] DEBUG i.v.a.ui.worker.ConnectorGenerator - Transition generated at: C:\Workspaces\PFC\aedifico-ui\sasdasdasd/connector_29_action.cpp
私のすべての労働者は同じ2つのことをします:
Freemarkerテンプレートエンジンを使用して、C++ソースファイルとヘッダーファイルのペアを生成します。
公開プロセスメカニズムを介してにメッセージを送信し、
EDT
状況がどのように進んでいるかをユーザーに通知します。
SwingWorker
を慎重にコーディングしたと思います。FileWriterインスタンスが期待どおりに閉じられないことを特に心配していましたが、ThreadPoolExecutor
以前に作成したスレッドを再利用していない理由がわかりません。
魔法はで起こりConnectorGenerator
ます。BaseWorker
拡張し、SwingWorker<V,T>
ユーザーにメッセージを表示するためにコンポーネントと通信する動作を保持します。
public class ConnectorGenerator<Void> extends BaseWorker<Void> {
@Override
public Void doInBackground() {
Transition transition = connector.getModel().getTransition();
logger.debug("Building source code for transition: {}", transition.getName());
logger.debug("Project retrieved: {}", project.getName());
try {
publish("Generating transition (%s) source code at %s", transition.getName(), project.getBaseDir());
/**
* Transition.build(String), attached below, is responsible of generating and writing the files
*/
transition.build(project.getBaseDir().getPath());
publish("Transition generated.");
} catch (BuilderException e) {
logger.error("Error: {}", e);
publish("There was an error that prevented generating %s's source code", transition.getName());
}
logger.debug("Transition generated at: {}/{}", project.getBaseDir(), transition.getSource());
return null;
}
}
そして、Transition.build(String)
醜い地獄のtry-catch-finallyブロックを含むメソッド:
@Override
public void build(String path) throws BuilderException {
generateFile(String.format("%s%s%s", path, File.separator, getHeader()), "action.h.ftl");
generateFile(String.format("%s%s%s", path, File.separator, getSource()), "action.cpp.ftl");
}
private void generateFile(String path, String templateName) throws BuilderException {
FileWriter out = null;
try {
Map<String, Object> model = new HashMap<String, Object>();
model.put("transition", this);
Configuration config = new Configuration();
config.setClassForTemplateLoading(CTransition.class, "/");
config.setObjectWrapper(ObjectWrapper.DEFAULT_WRAPPER);
out = new FileWriter(path);
freemarker.template.Template template = config.getTemplate(templateName);
template.process(model, out, ObjectWrapper.BEANS_WRAPPER);
stdout.info("Generated {}...", path);
} catch (IOException e) {
throw new BuilderException(e);
} catch (TemplateException e) {
throw new BuilderException(e);
} finally {
if (out != null)
try {
out.flush();
out.close();
} catch (IOException e) {
throw new BuilderException(e);
}
}
}
誰かが私がおそらく見逃しているものを見たり知ったりしていますか?