我想我需要重申我的问题...
我想创建一个简单的表单应用程序来编辑一个非常特定的文本文件的某些区域。虽然我有一些网络开发经验,但我不想创建基于浏览器的应用程序。基本上,我想尝试一下桌面应用程序,并且正在寻找一些入门帮助,包括对所选语言的建议。该应用程序应该在 Mac OS X 上运行。此外没有任何限制:Java、Cocoa、Python,甚至一些交互式 shell 脚本也可以。
如果您对详细信息感兴趣,请继续阅读此处,但并不是说我的问题不是 LaTex 特定的......:
我有一个自动生成的报告文件,其中包含 LaTex 代码。现在我想构建一个小应用程序,为每个部分及其标题创建一个表单字段。该文档仅包含几百行,并且应按以下方式工作:
\section{ This is were the header text should go inside the document }
\normalsize{ This is where the normal text should go}
标题/正常大小对在文档中出现 5-6 次。我想要的只是一个小 GUI,允许用户在花括号之间进行编辑,而无需看到任何 TeX 代码。我知道有 LyX 和其他所见即所得的 LaTeX 方法——我不想重新发明轮子。我只是想保护自动生成的代码免受用户的影响,并让他们更舒服一些。
编辑:
这是我的第一次尝试。我想我应该使用 PlainDocument 而不是直接发送它,但我会弄清楚这一点,因为我从trashgod 那里得到了编辑器/文本组件链接的大量帮助。主要问题是从 \section{} 和 \normalsize{} 中挑选出内容。也许我会在这里使用一些正则表达式。我需要为每次出现获取一个新的文本区域。
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileReader;
import javax.swing.*;
public class basicFrame extends JFrame {
// Declare Variables
JScrollPane bildlauf = new JScrollPane();
JTextArea txtfeld = new JTextArea();
public basicFrame() {
super();
// Main window
setTitle("ReportEditor");
setBackground(Color.LIGHT_GRAY);
// components
try {
File datei = new File("report.Rnw");
FileReader in = new FileReader(datei);
txtfeld.read(in, datei);
in.close();
} catch (Exception e) {
System.out.println("Error !");
}
// setLayout(new GridLayout(2,2));
// Scroll Shizzle
bildlauf.getViewport().add(txtfeld, null);
getContentPane().add(bildlauf, BorderLayout.CENTER);
//txtfeld.setSize(500,680);
//add(txtfeld);
//this.getContentPane().add(txtfeld);
// close
addWindowListener(new WindowLauscher());
}
// event handlers...
protected static final class WindowLauscher extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
public static void main(String[] args) {
//Fesnter erzeugen und anzeigen, die main Sache halt
basicFrame hf = new basicFrame();
hf.setSize(500, 700);
hf.setLocation(100, 100);
hf.setVisible(true);
}
}
提前感谢您的任何建议!
I think I need to restate my question ...
I want to create a SIMPLE form application that edits certain areas of one very specific text file. Though I have some web development experience, I do not want to create a browser based application. Basically I want to give a Desktop application a try and I am looking for some help to get started including suggestions for the language of choice. The application should run on Mac OS X. Besides there's no restriction: Java, Cocoa, Python, even a some interactive shell script would be ok.
If you are interested in the details, continue to read here, but not that my question is not LaTex specific...:
I have an automatically generated report file that contains LaTex Code. Now I want to build a little application that creates a form field for every section and it's header. The document contains only a few hundred lines and the should work the following:
\section{ This is were the header text should go inside the document }
\normalsize{ This is where the normal text should go}
The header / normalsize pairs occur 5-6 times within the document. All I want is a little GUI that allows user to edit between the curly braces without seeing any TeX code. I know that there's LyX and other WYSIWYG approaches to LaTeX – I do not want to reinvent the wheel. I just want to protect the auto-generated code a litte from users and make it a little more comfortable to them.
EDIT:
here's my very first try. I guess I should use PlainDocument instead of directly sending it, but I´ll figure that out, since I got plenty of help from trashgod with the editor / Text Component links. The major problem is to single out the content from \section{} and \normalsize{} stuff. Probably I will some regexp here. I need to get a new text area for every appearance.
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileReader;
import javax.swing.*;
public class basicFrame extends JFrame {
// Declare Variables
JScrollPane bildlauf = new JScrollPane();
JTextArea txtfeld = new JTextArea();
public basicFrame() {
super();
// Main window
setTitle("ReportEditor");
setBackground(Color.LIGHT_GRAY);
// components
try {
File datei = new File("report.Rnw");
FileReader in = new FileReader(datei);
txtfeld.read(in, datei);
in.close();
} catch (Exception e) {
System.out.println("Error !");
}
// setLayout(new GridLayout(2,2));
// Scroll Shizzle
bildlauf.getViewport().add(txtfeld, null);
getContentPane().add(bildlauf, BorderLayout.CENTER);
//txtfeld.setSize(500,680);
//add(txtfeld);
//this.getContentPane().add(txtfeld);
// close
addWindowListener(new WindowLauscher());
}
// event handlers...
protected static final class WindowLauscher extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
public static void main(String[] args) {
//Fesnter erzeugen und anzeigen, die main Sache halt
basicFrame hf = new basicFrame();
hf.setSize(500, 700);
hf.setLocation(100, 100);
hf.setVisible(true);
}
}
Thx in advance for any suggestions!
发布评论
评论(1)
Mac OS X 上的 TeX wiki 推荐 jEdit,支持 插件。 LaTeXTools 可能是一个好的开始。
附录:
尽管这些目标有些矛盾,但您始终可以解析文件并使用合适的
JTextComponent
。以下是使用文本组件的概述;请参阅文本组件功能 如果您想创建自己的编辑器工具包,如 自定义文本编辑器。附录:除了本教程之外,您还可以查看此文本字段布局示例。另外,考虑一个两列
JTable
< /a>,这将允许您将文档模型与表单视图完全分离。附录:关于代码的一些注释。
类名通常大写,例如
BasicFrame
。如果您不改变
JFrame
的行为,就不要扩展它;JPanel
是其他组件的良好容器,并且可以在JFrame
中显示。始终在 EDT 上构建 GUI .
让视图和模型分开。
The TeX on Mac OS X wiki recommends jEdit, which supports plugins. LaTeXTools might be a good start.
Addendum:
Although these goals are somewhat contradictory, you can always parse the file and use a suitable
JTextComponent
for each editable section. Here's an overview of Using Text Components; see Text Component Features if you want to create your own editor kit, as discussed in Customizing a Text Editor.Addendum: In addition to the tutorial, you might look at this text field layout example. Also, consider a two-column
JTable
, which would allow you to cleanly separate your document model from your form view.Addendum: A few notes on your code.
Class names are usually capitalized, e.g.
BasicFrame
.Don't extend
JFrame
if you're not changing it's behavior;JPanel
is a good container for other components, and it can be displayed in aJFrame
.Always buid your GUI on the EDT.
Keep you view and model separate.