开发者

Create a simple form application to edit a textfile

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开发者_StackOverflow中文版(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!


The TeX on Mac OS X wiki recommends jEdit, which supports plugins. LaTeXTools might be a good start.

Addendum:

I do not want to reinvent the wheel.
All I want to do is create a form application.

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.

  1. Class names are usually capitalized, e.g. BasicFrame.

  2. 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 a JFrame.

  3. Always buid your GUI on the EDT.

  4. Keep you view and model separate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜