public void search() {
    hilit.removeAllHighlights();

    String s = entry.getText();
    if (s.length() <= 0) {
      message("Nothing to search");
      return;
    }

    String content = textArea.getText();
    int index = content.indexOf(s, 0);
    if (index >= 0) {
      try {
        int end = index + s.length();
        hilit.addHighlight(index, end, painter);
        textArea.setCaretPosition(end);
        entry.setBackground(entryBg);
        message("'" + s + "' found. Press ESC to end search");
      } catch (BadLocationException e) {
        e.printStackTrace();
      }
    } else {
      entry.setBackground(ERROR_COLOR);
      message("'" + s + "' found. Press ESC to start a new search");
    }
  }
  public void save() {
    for (String key : fields.keySet()) {
      JComponent comp = fields.get(key);

      if (comp instanceof JTextField) {
        JTextField c = (JTextField) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      } else if (comp instanceof JTextArea) {
        JTextArea c = (JTextArea) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      }
    }

    sketch.saveConfig();
  }
Beispiel #3
0
  public void save() {
    BufferedWriter sourceFile = null;

    try {
      String sourceText = sourceArea.getText();

      String cleanText = cleanupSource(sourceText);

      if (cleanText.length() != sourceText.length()) {
        sourceArea.setText(cleanText);

        String message =
            String.format(
                "One or more invalid characters at the end of the source file have been removed.");
        JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.INFORMATION_MESSAGE);
      }

      sourceFile = new BufferedWriter(new FileWriter(sourcePath, false));
      sourceFile.write(cleanText);

      setSourceChanged(false);

      setupMenus();
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      if (sourceFile != null) {
        try {
          sourceFile.close();
        } catch (IOException ignore) {
        }
      }
    }
  }
 public void valueChanged(ListSelectionEvent event) {
   if (table.getSelectedRow() == -1) textArea.setText(null);
   else {
     TableItem item = table.getTableItemAt(table.getSelectedRow());
     textArea.setText(item.toString());
   }
   textArea.setCaretPosition(0);
 }
 /** Override setText to do formatting */
 public void setText(String text) {
   original = text;
   formatted = null;
   if (format) {
     doFormat();
     super.setText(formatted);
   } else {
     super.setText(original);
   }
 }
 /** Turn reflow on or off */
 public void setReflowXML(boolean reflow) {
   format = reflow;
   if (format) {
     if (formatted == null) {
       doFormat();
     }
     super.setText(formatted);
   } else {
     super.setText(original);
   }
 }
Beispiel #7
0
 /*
  * Creates the JTextArea for the GUI with the ScrollPane.
  */
 private JScrollPane responseArea() {
   responseArea = new JTextArea();
   responseArea.setSize(10, 10);
   responseArea.setLineWrap(true);
   responseArea.setWrapStyleWord(true);
   scrollPane =
       new JScrollPane(
           responseArea,
           ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
           ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   return scrollPane;
 }
  public void init() {
    task_name = new String[1];
    task_name[0] = "当前没有任务";
    task_description = "";
    jl_taskname = new JList(task_name);
    scrollpane1 = new JScrollPane(jl_taskname);

    jta_taskdescription = new JTextArea("", 20, 20);
    jta_taskdescription.setLineWrap(true);
    jta_taskdescription.setWrapStyleWord(true);
    jta_taskdescription.setEditable(true);
    scrollpane2 = new JScrollPane(jta_taskdescription);
  }
 void addTextArea(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextArea field = new JTextArea();
   field.setText(sketch.configFile.get(key));
   field.setLineWrap(true);
   field.setWrapStyleWord(true);
   fields.put(key, field);
   JScrollPane scroll = new JScrollPane(field);
   scroll.setAlignmentX(0.0f);
   panel.add(scroll);
 }
  boolean initControlCenter(String title) {

    this.setTitle(title);
    // set up content pane
    Container content = this.getContentPane();
    content.setLayout(new BorderLayout());
    panelAbout.setLayout(new BorderLayout());

    JTextArea textArea =
        new JTextArea(
            "PlayStation 2 Virtual File System release 1.0 \n\nSpecials thanks to our betatester\nPS2Linux Betatester: Mrbrown and Sarah\nPS2 betatester: Oobles, Caveman, Gamebytes, Ping^Spike, Josekenshin, Padawan, pakor, SandraThx and Rolando\n\nAdded little gui in java swing\nAdded feature to choose directory for media files\nAdded support for properties files\nCheck for updates at ps2dev.org\n\nRelease 1.2\n\nRewrite io with java NIO\nadded console mode support\n");
    textArea.setEditable(false);

    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setPreferredSize(new Dimension(250, 250));
    TitledBorder aboutBorder = BorderFactory.createTitledBorder("Change log and Greets");
    aboutBorder.setTitleColor(Color.blue);
    panelAbout.setBorder(aboutBorder);

    panelAbout.add(areaScrollPane);
    // set up tabbed pane
    content.add(jtpMain);

    jtpMain.addTab("Configure", panelChooser);
    jtpMain.addTab("About", panelAbout);
    //  set up display area
    // jtaDisplay.setEditable(false);
    // jtaDisplay.setLineWrap(true);
    // jtaDisplay.setMargin(new Insets(5, 5, 5, 5));
    // jtaDisplay.setFont(
    // new Font("Monospaced", Font.PLAIN, iDEFAULT_FontSize));
    // jspDisplay.setViewportView(jtaDisplay);
    // jspDisplay.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
    // panelConsole.add(jspDisplay, BorderLayout.CENTER);
    // panelConsole.add(jtfCommand, BorderLayout.SOUTH);
    // panelConsole.add(jtaDisplay, BorderLayout.CENTER);

    // listener: window closer
    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    this.vResize();
    return true;
  }
Beispiel #11
0
 public void setSelectedFont(Font font) {
   selectedFont = font;
   family = font.getFamily();
   style = font.getStyle();
   size = font.getSize();
   preview.setFont(font);
 }
Beispiel #12
0
    public HelpFrame(JFrame f) {
      super("Help menu");
      setSize(320, 240);
      setLocationRelativeTo(f);
      setResizable(false);

      JTextArea message = new JTextArea();
      message.setEditable(false);
      message.setText(
          "Default keybindings:\n     -Cmd+e to toggle terminal\n     -Cmd+k to run\n     -Cmd+/ to show help\n     -Cmd+o for options\n\n"
              + "Special keywords: \n     -'import' can be typed anywhere \n     -'method' and then a method will compile\n\n"
              + "Other: \n     -You can also use this for normal Java editing!");

      add(message, "Center");
      setVisible(true);
    }
Beispiel #13
0
 public void stateChanged(ChangeEvent e) {
   texta.setText(
       lblName.getText()
           + text0.getText()
           + '\n'
           + lblAge.getText()
           + ((JSpinner) e.getSource()).getValue());
 }
Beispiel #14
0
 public void actionPerformed(ActionEvent e) {
   texta.setText(
       lblName.getText()
           + text0.getText()
           + '\n'
           + lblSex.getText()
           + ((JRadioButton) e.getSource()).getText());
 }
 public static void fresh_taskname() {
   task_name = new String[Runner.count_task];
   for (int i = 0; i < Runner.count_task; i++) {
     task_name[i] = Runner.task[i].get_taskname();
   }
   jl_taskname.setListData(task_name);
   jl_taskname.setSelectedIndex(0);
   jta_taskdescription.setText(MainFrame.str_description[0]);
 }
Beispiel #16
0
  private Action getAction(String name) {
    for (Action action : sourceArea.getActions()) {
      if (name.equals(action.getValue(Action.NAME).toString())) {
        return action;
      }
    }

    return null;
  }
Beispiel #17
0
 public void update(JTextArea area) {
   DBItem item = dataList.getSelectedValue();
   if (item != null && !isSet) {
     isSet = true;
     try {
       if (area == hexKey) {
         if (area.getText().isEmpty()) {
           return;
         }
         item.key =
             new BigInteger(area.getText().replaceAll("\n", "").replaceAll("%\\{EOL}", "\n"), 16)
                 .toByteArray();
         stringKey.setText(cutToLine(new String(item.key), 64));
         dataList.updateUI();
       } else if (area == stringKey) {
         if (area.getText().isEmpty()) {
           return;
         }
         item.key = area.getText().replaceAll("\n", "").replaceAll("%\\{EOL}", "\n").getBytes();
         hexKey.setText(cutToLine(LevelDBViewer.toHexString(item.key), 64));
         dataList.updateUI();
       } else if (area == hexValue) {
         item.value =
             new BigInteger(area.getText().replaceAll("\n", "").replaceAll("%\\{EOL}", "\n"), 16)
                 .toByteArray();
         stringValue.setText(cutToLine(new String(item.value), 64));
       } else if (area == stringValue) {
         item.value = area.getText().replaceAll("\n", "").replaceAll("%\\{EOL}", "\n").getBytes();
         hexValue.setText(cutToLine(LevelDBViewer.toHexString(item.value), 64));
       }
       notice.setVisible(false);
       notice.setText("");
       saveButton.setEnabled(true);
     } catch (Exception e) {
       notice.setVisible(true);
       notice.setText("Invalid number!");
     } finally {
       lengthLabel.setText(String.valueOf(item.value.length + item.key.length));
       keyLength.setText(String.valueOf(item.key.length));
       valueLength.setText(String.valueOf(item.value.length));
       isSet = false;
     }
   }
 }
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   Insets i = getInsets();
   // int y = g2.getFontMetrics().getHeight()*getLineAtCaret(this)+i.top;
   int y = caret.y + caret.height - 1;
   g2.setPaint(cfc);
   g2.drawLine(i.left, y, getSize().width - i.left - i.right, y);
 }
 @Override
 protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
   // String literal pool
   // if (propertyName == "document" || ((propertyName == "font" || propertyName == "foreground")
   // && oldValue != newValue)) {
   if ("document".equals(propertyName)
       || !Objects.equals(oldValue, newValue)
           && ("font".equals(propertyName) || "foreground".equals(propertyName))) {
     super.firePropertyChange(propertyName, oldValue, newValue);
   }
 }
Beispiel #20
0
  @Override
  public void internalFrameActivated(InternalFrameEvent e) {
    super.internalFrameActivated(e);

    mainFrame.pasteItem.setEnabled(canPaste());

    Caret caret = sourceArea.getCaret();
    doCaretUpdate(caret.getDot(), caret.getMark());

    setUndoItem();
    setRedoItem();
  }
  public TextFieldDemo() {
    initComponents();

    InputStream in = getClass().getResourceAsStream("content.txt");
    try {
      textArea.read(new InputStreamReader(in), null);
    } catch (IOException e) {
      e.printStackTrace();
    }

    hilit = new DefaultHighlighter();
    painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR);
    textArea.setHighlighter(hilit);

    entryBg = entry.getBackground();
    entry.getDocument().addDocumentListener(this);

    InputMap im = entry.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap am = entry.getActionMap();
    im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION);
    am.put(CANCEL_ACTION, new CancelAction());
  }
 void insertMatchButton_actionPerformed(ActionEvent e) {
   String key = (String) matchComboBox.getSelectedItem();
   String format = (String) matchesKeys.get(key);
   if (key.equals(STRING_LITERAL)) {
     format =
         escapeReservedChars(
             (String)
                 JOptionPane.showInputDialog(
                     this,
                     "Enter the string you wish to match",
                     "String Literal Input",
                     JOptionPane.OK_CANCEL_OPTION));
     if (StringUtil.isNullString(format)) {
       return;
     }
   }
   if (selectedPane == 0) {
     insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
   } else {
     // add the combobox data value to the edit box
     int pos = formatTextArea.getCaretPosition();
     formatTextArea.insert(format, pos);
   }
 }
Beispiel #23
0
  public void saveAs() {
    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();

    if (fileExt.equals("m") || fileExt.equals("mac")) {
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    } else {
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
    }
    filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Save Source File");
    String fileName = String.format("%s.%s", baseName, fileExt);
    chooser.setSelectedFile(new File(selectedPath, fileName));
    JTextField field = chooser.getTextField();
    field.setSelectionStart(0);
    field.setSelectionEnd(baseName.length());
    File file = chooser.save(ROPE.mainFrame);
    if (file != null) {
      selectedPath = file.getParent();

      BufferedWriter writer = null;
      try {
        writer = new BufferedWriter(new FileWriter(file));
        writer.write(sourceArea.getText());
      } catch (IOException ex) {
        ex.printStackTrace();
      } finally {
        try {
          if (writer != null) {
            writer.close();
          }
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
Beispiel #24
0
  void doCaretUpdate(int dot, int mark) {
    if (dot == mark) {
      mainFrame.cutItem.setEnabled(false);
      mainFrame.copyItem.setEnabled(false);
      mainFrame.deleteItem.setEnabled(false);
    } else {
      mainFrame.cutItem.setEnabled(true);
      mainFrame.copyItem.setEnabled(true);
      mainFrame.deleteItem.setEnabled(true);
    }

    int length = sourceArea.getText().length();
    if (length == 0 || abs(mark - dot) == length) {
      mainFrame.selectAllItem.setEnabled(false);
    } else {
      mainFrame.selectAllItem.setEnabled(true);
    }

    try {
      if (length == 0) {
        mainFrame.selectLineItem.setEnabled(false);
      } else {
        int lineNum = sourceArea.getLineOfOffset(dot);
        int startLine = sourceArea.getLineStartOffset(lineNum);
        int endLine = sourceArea.getLineEndOffset(lineNum);
        if (endLine - startLine <= 1) {
          mainFrame.selectLineItem.setEnabled(false);
        } else {
          mainFrame.selectLineItem.setEnabled(true);
        }
      }
    } catch (BadLocationException ex) {
      ex.printStackTrace();
    }

    try {
      int line = sourceArea.getLineOfOffset(dot);
      lineText.setText(Integer.toString(line + 1));
      int column = dot - sourceArea.getLineStartOffset(line);
      columnText.setText(Integer.toString(column + 1));
    } catch (BadLocationException ex) {
      ex.printStackTrace();
    }
  }
Beispiel #25
0
  private void highlightError(int index) {
    String message = (String) messages.elementAt(index);
    int i = message.indexOf(":");

    if ((i != -1) && (i < 10)) {
      try {
        int lineNumber = Integer.parseInt(message.substring(0, i).trim()) - 1;
        if (lineNumber < sourceArea.getLineCount()) {
          int start = sourceArea.getLineStartOffset(lineNumber);
          int end = sourceArea.getLineEndOffset(lineNumber);

          sourceArea.requestFocus();
          sourceArea.setSelectionStart(start);
          sourceArea.setSelectionEnd(end - 1);
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
Beispiel #26
0
 public static JTextArea getTextArea(String s) {
   JTextArea ret = new JTextArea(s);
   ret.setFont(new Font("Courier", Font.PLAIN, 12));
   ret.setTabSize(4);
   return ret;
 }
 public void run() {
   WindowBlocker blocker = new WindowBlocker(NearInfinity.getInstance());
   blocker.setBlocked(true);
   List<ResourceEntry> files = new ArrayList<ResourceEntry>();
   for (final String fileType : FILETYPES)
     files.addAll(ResourceFactory.getInstance().getResources(fileType));
   ProgressMonitor progress =
       new ProgressMonitor(NearInfinity.getInstance(), "Searching...", null, 0, files.size());
   table =
       new SortableTable(
           new String[] {"String", "StrRef"},
           new Class[] {Object.class, Integer.class},
           new int[] {450, 20});
   StringResource.getStringRef(0);
   strUsed = new boolean[StringResource.getMaxIndex() + 1];
   for (int i = 0; i < files.size(); i++) {
     ResourceEntry entry = files.get(i);
     Resource resource = ResourceFactory.getResource(entry);
     if (resource instanceof DlgResource) checkDialog((DlgResource) resource);
     else if (resource instanceof BcsResource) checkScript((BcsResource) resource);
     else if (resource instanceof PlainTextResource) checkTextfile((PlainTextResource) resource);
     else if (resource != null) checkStruct((AbstractStruct) resource);
     progress.setProgress(i + 1);
     if (progress.isCanceled()) {
       JOptionPane.showMessageDialog(
           NearInfinity.getInstance(),
           "Operation canceled",
           "Info",
           JOptionPane.INFORMATION_MESSAGE);
       blocker.setBlocked(false);
       return;
     }
   }
   for (int i = 0; i < strUsed.length; i++)
     if (!strUsed[i]) table.addTableItem(new UnusedStringTableItem(new Integer(i)));
   if (table.getRowCount() == 0)
     JOptionPane.showMessageDialog(
         NearInfinity.getInstance(),
         "No unused strings found",
         "Info",
         JOptionPane.INFORMATION_MESSAGE);
   else {
     table.tableComplete(1);
     textArea = new JTextArea(10, 40);
     textArea.setEditable(false);
     textArea.setWrapStyleWord(true);
     textArea.setLineWrap(true);
     JScrollPane scrollText = new JScrollPane(textArea);
     resultFrame = new ChildFrame("Result", true);
     save = new JMenuItem("Save");
     save.addActionListener(this);
     JMenu fileMenu = new JMenu("File");
     fileMenu.add(save);
     JMenuBar menuBar = new JMenuBar();
     menuBar.add(fileMenu);
     resultFrame.setJMenuBar(menuBar);
     resultFrame.setIconImage(Icons.getIcon("Find16.gif").getImage());
     JLabel count = new JLabel(table.getRowCount() + " unused string(s) found", JLabel.CENTER);
     count.setFont(count.getFont().deriveFont((float) count.getFont().getSize() + 2.0f));
     JScrollPane scrollTable = new JScrollPane(table);
     scrollTable.getViewport().setBackground(table.getBackground());
     JPanel pane = (JPanel) resultFrame.getContentPane();
     pane.setLayout(new BorderLayout(0, 3));
     pane.add(count, BorderLayout.NORTH);
     pane.add(scrollTable, BorderLayout.CENTER);
     JPanel bottomPanel = new JPanel(new BorderLayout());
     JPanel searchPanel = SearchMaster.createAsPanel(this, resultFrame);
     bottomPanel.add(scrollText, BorderLayout.CENTER);
     bottomPanel.add(searchPanel, BorderLayout.EAST);
     pane.add(bottomPanel, BorderLayout.SOUTH);
     table.setFont(BrowserMenuBar.getInstance().getScriptFont());
     pane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
     table.getSelectionModel().addListSelectionListener(this);
     resultFrame.pack();
     Center.center(resultFrame, NearInfinity.getInstance().getBounds());
     resultFrame.setVisible(true);
   }
   blocker.setBlocked(false);
 }
  private void initComponents() {
    entry = new JTextField();
    textArea = new JTextArea();
    status = new JLabel();
    jLabel1 = new JLabel();

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setTitle("TextFieldDemo");

    textArea.setColumns(20);
    textArea.setLineWrap(true);
    textArea.setRows(5);
    textArea.setWrapStyleWord(true);
    textArea.setEditable(false);
    jScrollPane1 = new JScrollPane(textArea);

    jLabel1.setText("Enter text to search:");

    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);

    ParallelGroup hGroup = layout.createParallelGroup(GroupLayout.Alignment.LEADING);

    SequentialGroup h1 = layout.createSequentialGroup();
    ParallelGroup h2 = layout.createParallelGroup(GroupLayout.Alignment.TRAILING);

    h1.addContainerGap();

    h2.addComponent(
        jScrollPane1,
        GroupLayout.Alignment.LEADING,
        GroupLayout.DEFAULT_SIZE,
        450,
        Short.MAX_VALUE);
    h2.addComponent(
        status, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE);

    SequentialGroup h3 = layout.createSequentialGroup();
    h3.addComponent(jLabel1);
    h3.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
    h3.addComponent(entry, GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE);

    h2.addGroup(h3);
    h1.addGroup(h2);

    h1.addContainerGap();

    hGroup.addGroup(GroupLayout.Alignment.TRAILING, h1);
    layout.setHorizontalGroup(hGroup);

    ParallelGroup vGroup = layout.createParallelGroup(GroupLayout.Alignment.LEADING);
    SequentialGroup v1 = layout.createSequentialGroup();
    v1.addContainerGap();
    ParallelGroup v2 = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
    v2.addComponent(jLabel1);
    v2.addComponent(
        entry, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
    v1.addGroup(v2);
    v1.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED);
    v1.addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE);

    v1.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED);
    v1.addComponent(status);
    v1.addContainerGap();

    vGroup.addGroup(v1);
    layout.setVerticalGroup(vGroup);
    pack();
  }
Beispiel #29
0
 public void copyMenuAction(ActionEvent event) {
   if (sourceArea != null) {
     sourceArea.copy();
   }
 }
Beispiel #30
0
  EditFrame(RopeFrame parent) {
    super(parent);

    // Implement a smarter way to set the initial frame position and size
    setLocation(0, 0);
    setSize(670, 705);

    try {
      jbInit();
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    sourceArea.addCaretListener(this);
    browseButton.addActionListener(this);
    optionsButton.addActionListener(this);
    assembleButton.addActionListener(this);
    saveButton.addActionListener(this);

    messageList.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent event) {
            highlightError(messageList.locationToIndex(event.getPoint()));
          }
        });

    undoMgr = new CompoundUndoManager(sourceArea);

    undoAction = undoMgr.getUndoAction();
    redoAction = undoMgr.getRedoAction();

    undoMgr.updateUndoAction = new UpdateUndoAction();
    undoMgr.updateRedoAction = new UpdateRedoAction();

    document = sourceArea.getDocument();

    ActionMap am = sourceArea.getActionMap();
    InputMap im = sourceArea.getInputMap(JComponent.WHEN_FOCUSED);

    // Remove automatic key bindings because we want them controlled by menu items
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, RopeHelper.modifierMaks), "none");
    im.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_Z, RopeHelper.modifierMaks + InputEvent.SHIFT_MASK),
        "none");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, RopeHelper.modifierMaks), "none");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, RopeHelper.modifierMaks), "none");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, RopeHelper.modifierMaks), "none");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, RopeHelper.modifierMaks), "none");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, RopeHelper.modifierMaks), "none");

    // Set custom binding action for tab key
    String action = "tabKeyAction";
    im.put(KeyStroke.getKeyStroke("TAB"), action);
    am.put(
        action,
        new AbstractAction() {
          private static final long serialVersionUID = 1L;

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              int caretPos = sourceArea.getCaretPosition();
              int lineNum = sourceArea.getLineOfOffset(caretPos);
              int startLine = sourceArea.getLineStartOffset(lineNum);
              int endLine = sourceArea.getLineEndOffset(lineNum);
              int linePos = caretPos - startLine;

              if (linePos >= 39 && linePos < 79) {
                caretPos = startLine + linePos + 10 - ((linePos + 1) % 10);
              } else if (linePos >= 20 && linePos <= 39) {
                caretPos = startLine + 39;
              } else if (linePos >= 15 && linePos <= 19) {
                caretPos = startLine + 20;
              } else if (linePos >= 5 && linePos <= 14) {
                caretPos = startLine + 15;
              } else {
                caretPos = startLine + 5;
              }

              // If the line is shorter than the new position fo the caret add enough spaces...
              if (caretPos > endLine) {
                StringBuilder str = new StringBuilder();
                int size = caretPos - endLine;
                while (size-- >= 0) {
                  str.append(' ');
                }
                document.insertString(endLine - 1, str.toString(), null);
              }

              sourceArea.setCaretPosition(caretPos);
            } catch (BadLocationException ex) {
              ex.printStackTrace();
            }
          }
        });

    // Set custom binding action for return/enter key
    String actionKey = "backspaceKeyAction";
    im.put(KeyStroke.getKeyStroke("BACK_SPACE"), actionKey);
    am.put(
        actionKey,
        new AbstractAction()
        // How can I get the original action?
        {
          private static final long serialVersionUID = 1L;

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              int caretPos = sourceArea.getCaretPosition();
              int lineNum = sourceArea.getLineOfOffset(caretPos);
              int startLine = sourceArea.getLineStartOffset(lineNum);
              int endLine = sourceArea.getLineEndOffset(lineNum);
              int linePos = caretPos - startLine;

              if (linePos == 15) {
                int endPos = 5;
                int charPos = linePos;
                for (; charPos > endPos; charPos--) {
                  char ch = sourceArea.getText().charAt((startLine + charPos) - 1);
                  if (!Character.isWhitespace(ch)) {
                    break;
                  }
                }

                sourceArea.setCaretPosition(startLine + charPos);
              } else {
                int startSel = sourceArea.getSelectionStart();
                int endSel = sourceArea.getSelectionEnd();
                if (startSel == endSel) {
                  startSel = caretPos - 1;
                  endSel = caretPos;
                }

                StringBuilder sb = new StringBuilder(sourceArea.getText());
                sb.replace(startSel, endSel, "");
                sourceArea.setText(sb.toString());
                sourceArea.setCaretPosition(startSel);
              }
            } catch (BadLocationException ex) {
              ex.printStackTrace();
            }
          }
        });

    // Set custom binding action for return/enter key
    action = "enterKeyAction";
    im.put(KeyStroke.getKeyStroke("ENTER"), action);
    am.put(
        action,
        new AbstractAction() {
          private static final long serialVersionUID = 1L;

          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              int caretPos = sourceArea.getCaretPosition();
              int lineNum = sourceArea.getLineOfOffset(caretPos);
              int startLine = sourceArea.getLineStartOffset(lineNum);
              int linePos = caretPos - startLine;

              if (linePos >= 5) {
                document.insertString(caretPos, "\n     ", null);
              } else {
                document.insertString(caretPos, "\n", null);
              }
            } catch (BadLocationException ex) {
              ex.printStackTrace();
            }
          }
        });

    document.addDocumentListener(
        new DocumentListener() {
          @Override
          public void insertUpdate(DocumentEvent e) {
            setSourceChanged(true);
          }

          @Override
          public void removeUpdate(DocumentEvent e) {
            setSourceChanged(true);
          }

          @Override
          public void changedUpdate(DocumentEvent e) {
            setSourceChanged(true);
          }
        });
  }