undo = new ArrayList(); undoPos = -1; ta.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { if (undoPos + 1 != undo.size()) for (int i = undo.size() - 1; i > undoPos; i--) undo.remove(i); undo.add(e.getEdit()); undoPos++; } });
    protected void init()    {        mainWindow = createBaseWindow(this);        mainWindow.setTitle(this.getDescription());        //menu        JMenuBar mb = new JMenuBar();        JMenu editMenu = new JMenu("Edit");        editMenu.setMnemonic('e');        editMenu.add(HackModule.createJMenuItem("Cut", 't', "ctrl X", "cut",            this));        editMenu.add(HackModule.createJMenuItem("Copy", 'c', "ctrl C", "copy",            this));        editMenu.add(HackModule.createJMenuItem("Paste", 'p', "ctrl V",            "paste", this));        editMenu.add(HackModule.createJMenuItem("Delete", 'd', "DELETE",            "delete", this));        editMenu.add(new JSeparator());        editMenu.add(HackModule.createJMenuItem("Find", 'f', "ctrl F", "find",            this));        editMenu.add(HackModule.createJMenuItem("Find Next", 'n', "F3",            "findNext", this));        editMenu.add(new JSeparator());        editMenu.add(HackModule.createJMenuItem("Goto", 'g', "ctrl G", "goto",            this));        mb.add(editMenu);        JMenu optionMenu = new JMenu("Options");        optionMenu.setMnemonic('o');        optionMenu.add(HackModule.createJMenuItem("Show Code Help", 'h',            "alt F1", "showCodeHelp", this));        optionMenu.add(codesOnly = new PrefsCheckBox("Codes Only", JHack.main            .getPrefs(), "eb_text_editor.codes_only", false, 'c', "alt C",            "codesOnly", this));        optionMenu.add(useComp = new PrefsCheckBox("Use Compression",            JHack.main.getPrefs(), "eb_text_editor.use_compression", true, 'u',            "alt U", "useComp", this));        optionMenu            .add(preventOverwrites = new PrefsCheckBox("Prevent Overwrites",                JHack.main.getPrefs(), "eb_text_editor.prevent_overwrites",                true, 'p', "alt P", null, null));        mb.add(optionMenu);        JMenu toolsMenu = new JMenu("Tools");        toolsMenu.setMnemonic('t');        toolsMenu.add(showEntry = HackModule.createJMenuItem("Edit TPT Entry",            'e', "ctrl e", "showEntry", this));        showPreview = new JMenuItem("Show Text Preview");        showPreview.setMnemonic('p');        showPreview.setAccelerator(KeyStroke.getKeyStroke("ctrl P"));        showPreview.setActionCommand("showPreview");        showPreview.addActionListener(this);        //        toolsMenu.add(showPreview);        mb.add(toolsMenu);        mainWindow.setJMenuBar(mb);        //end menu        Box entry = new Box(BoxLayout.Y_AXIS);        String[] tabNames = new String[]{"Text Pointer Table", "Raw Text",            "Expanded Area"};        final List[] tabContents = textLists;        textJLists = new JList[tabNames.length];        selectorArea = new JTabbedPane();        for (int i = 0; i < tabNames.length; i++)        {            JPanel contents = new JPanel();            final int j = i;            JList textList = new JList(new ListModel()            {                public int getSize()                {                    return tabContents[j].size();                }                public Object getElementAt(int a)                {                    //                    if(a < 10)                    //                    System.out.println(                    //                        "("                    //                            + new Date().toGMTString()                    //                            + ") Getting element below 10 at "                    //                            + a                    //                            + " on "                    //                            + tabShortNames[j]                    //                            + " JList.");                    //                    return cc.parseHeader(                    //                        ((StrInfo) tabContents[j].get(a)).str);                    return ((StrInfo) tabContents[j].get(a)).header;                }                List listeners = new ArrayList();                public void addListDataListener(ListDataListener ldl)                {                    listeners.add(ldl);                }                public void removeListDataListener(ListDataListener ldl)                {                    listeners.remove(ldl);                }            });            textList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);            textList.addListSelectionListener(new ActionCreator(textList, this,                tabShortNames[i]));            textList.addMouseListener(new MouseListener()            {                public void mouseClicked(MouseEvent me)                {                    if (me.getButton() == 1)                    {                        if (textJLists[j].getSelectedIndex() > -1)                            showInfo(j, textJLists[j].getSelectedIndex());                    }                    else if (me.getButton() == 3)                    {                        showEntry();                    }                }                public void mouseEntered(MouseEvent me)                {}                public void mouseExited(MouseEvent me)                {}                public void mousePressed(MouseEvent me)                {}                public void mouseReleased(MouseEvent me)                {}            });            JScrollPane scroll = new JScrollPane(textList,                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);            scroll.setPreferredSize(new Dimension(550, 270));            contents.add(scroll);            selectorArea.addTab(tabNames[i], contents);            textJLists[i] = textList;        }        entry.add(selectorArea);        entry            .add(HackModule.createFlowLayout(new Component[]{                positionLabel = new JLabel("Line:  /    "),                Box.createHorizontalStrut(10),                addressLabel = new JLabel("Address: 0x       | $      "),                Box.createHorizontalStrut(10),                sizeLabel = new JLabel("Size:   ")}));        Box bottomLabels = new Box(BoxLayout.X_AXIS);        bottomLabels.add(currSizeLabel = new JLabel("Current Size: "));        bottomLabels.add(Box.createHorizontalStrut(10));        bottomLabels.add(currPosLabel = new JLabel("Current Position: "));        bottomLabels.add(Box.createHorizontalGlue());        entry.add(HackModule.pairComponents(new JScrollPane(            ta = new JTextArea(), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), bottomLabels, false));        ta.setWrapStyleWord(true);        ta.setLineWrap(true);        ta.setColumns(30);        ta.setRows(7);        ta.getDocument().addDocumentListener(new DocumentListener()        {            public void changedUpdate(DocumentEvent de)            {                updateCurrSize();                updateCurrPos();            }            public void insertUpdate(DocumentEvent de)            {                updateCurrSize();                updateCurrPos();            }            public void removeUpdate(DocumentEvent de)            {                if (!ta.getText().equals(""))                {                    updateCurrSize();                    updateCurrPos();                }            }        });        ta.addCaretListener(new CaretListener()        {            public void caretUpdate(CaretEvent e)            {                updateCurrPos();            }        });        mainWindow.getContentPane().add(entry, BorderLayout.CENTER);        mainWindow.pack();    }