2

目前我正在构建一个应该用于一些声音处理的应用程序。我正在使用 swt/jface 在 java/eclipse 中执行此操作。处理本身需要一些内部算法的选项/属性。此时,我有一个 .properties 文件,其中包含所有选项,例如:

trimLeadingSilence=20
trimtrailingSilence=20
trimhold=5
fftFrameSize=512 ...

我不希望用户在像 notepad++ 这样的文本编辑器中编辑这些选项,而是在我的应用程序的 gui 中。

现在我在考虑如何做到这一点。我有 2 个“想法”:为每个选项集创建一个类,并手动编写所有这些无聊的 gui 代码行。就像这里只有一个选项;-)

Spinner spinnerSilenceBack = new Spinner(shell, SWT.BORDER);
        spinnerSilenceBack.setMinimum(0);
        spinnerSilenceBack.setMaximum(200);
        selection = Integer.valueOf(PropertyManager.getPropertyValue("trimming", "trailingSilence"));
        spinnerSilenceBack.setSelection(selection);
        spinnerSilenceBack.setIncrement(5);
        spinnerSilenceBack.setPageIncrement(20);
        spinnerSilenceBack.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                int selection = ((Spinner) e.getSource()).getSelection();
                int digits = ((Spinner) e.getSource()).getDigits();
                int result = (int) (selection / Math.pow(10, digits));

                PropertyManager.setPropertyValue("trimming", "trailingSilence", String
                        .valueOf(result));

            }
        });

这需要很多时间,因为有很多不同的选择。所以我想到了如何动态创建这样的 gui 代码,或者只是在启动应用程序时动态创建这些 gui 窗口。至少我需要一个“gui creator”的配置文件,但我不想重新发明这样的东西——这就是我问你们的原因:)

4

3 回答 3

0

I couldn't get clearly what you are asking.

But, since your question was How to dynamicly build up a gui, i have a a suggestion:

You could use Java Template Engine library like Freemarker. This would help you create GUI's that can be built to work on the fly. With freemarker you can have one single template file and then replace the values accordingly.

I have used it to generate HTML files on the fly. You could evaluate if you can use it otherwise. The API Documentation is rich. So you could go through that once.

于 2010-05-20T11:58:36.757 回答
-1

Do you mean, you want to make an UI which will have all options you specified? It doesn't matter its a form OR a menu, its up to you. But yeah you can surely configure the names and types in .properties file.

See, you build a Menu OR form in AWT/Swing OR Servlet, but you can read it from properties file right?

You can also configure the same using Spring bean XML definitions, which can provide more support like you can specify all details in some Map OR List etc...

thanks.

于 2010-05-20T12:01:11.917 回答
-1

很长时间没有使用 Swing,所以这里只是一个基本的原理。
配置应该在 xml 中完成,.properties 文件在这里不好,因为它没有描述开箱即用的对象。
添加按钮(“应用配置”),附加 actionListener,它 1)解析 xml 配置,2)然后创建表单或更改现有表单、文本区域、颜色等的设置。

xml配置示例:

找到 - 检查它的 x_coordinate、y_coord(或使用 layoutManager,取决于逻辑)、动作,而不是 jframe.getLayout().add(new Button(x_coord, y_coord, action)。
找到 - 相同。

比 jframe.setVisible(true);

于 2010-05-25T05:55:01.307 回答