Exemple #1
0
  public void testBufferWithLargeFile() throws Exception {
    final char[] chars = "0123456789abcdef".toCharArray();
    final char[] manyChars = new char[10000];

    for (int i = 0; i < manyChars.length; ++i) {
      manyChars[i] = chars[i % chars.length];
    }

    final String s0 = new String(manyChars);
    final StringTextSource textSource = new StringTextSource(s0);
    assertSame(s0, textSource.getText());

    final File file = new File(getDirectory(), "myfile.txt");

    final Buffer buffer = new BufferImplementation(s_resources, textSource, file);

    assertEquals(Buffer.TEXT_BUFFER, buffer.getType());
    assertTrue(!buffer.isDirty());
    assertTrue(!buffer.isUpToDate());
    assertEquals(file, buffer.getFile());
    assertEquals(textSource, buffer.getTextSource());

    buffer.save();

    assertTrue(!buffer.isDirty());
    assertTrue(buffer.isUpToDate());
    assertSame(s0, textSource.getText());

    buffer.load();

    assertTrue(!buffer.isDirty());
    assertTrue(buffer.isUpToDate());
    assertEquals(canonicaliseLineEndings(s0), textSource.getText());
    assertNotSame(s0, textSource.getText());
  }
Exemple #2
0
  public void testBufferWithAssociatedFile() throws Exception {

    final String s0 = "A shield for your eyes\na beast in the well on your hand";

    final String s1 =
        "Catch the mean beast\nin the well in the hell on the back\n"
            + "Watch out! You've got no shield\n"
            + "Break up! He's got no peace";

    final StringTextSource textSource = new StringTextSource(s0);
    assertSame(s0, textSource.getText());

    final File file = new File(getDirectory(), "myfile.txt");

    final Buffer buffer = new BufferImplementation(s_resources, textSource, file);

    assertEquals(Buffer.TEXT_BUFFER, buffer.getType());
    assertTrue(!buffer.isDirty());
    assertTrue(!buffer.isUpToDate());
    assertEquals(file, buffer.getFile());
    assertEquals(textSource, buffer.getTextSource());

    buffer.save();

    assertTrue(!buffer.isDirty());
    assertTrue(buffer.isUpToDate());

    assertSame(s0, textSource.getText());

    textSource.setText(s1);
    textSource.markDirty();

    assertTrue(buffer.isDirty());
    assertTrue(buffer.isUpToDate());
    assertSame(s1, textSource.getText());

    buffer.load();

    assertTrue(!buffer.isDirty());
    assertTrue(buffer.isUpToDate());
    assertEquals(canonicaliseLineEndings(s0), textSource.getText());
    assertNotSame(s0, textSource.getText());

    // Add an error margin, as Linux does not support setting the modification
    // date with millisecond precision.
    assertTrue(file.setLastModified(System.currentTimeMillis() + 1000));

    assertTrue(!buffer.isUpToDate());

    buffer.load();

    assertTrue(buffer.isUpToDate());
    assertEquals(textSource, buffer.getTextSource());
  }
Exemple #3
0
  public void testBufferWithNoFile() throws Exception {
    final String text = "Some text for testing with";

    final TextSource textSource = new StringTextSource(text);

    assertEquals(text, textSource.getText());

    final Buffer buffer = new BufferImplementation(s_resources, textSource, "My Buffer");

    assertNotNull(textSource.getText());
    assertEquals(text, textSource.getText());
    assertEquals("My Buffer", buffer.getDisplayName());
    assertTrue(buffer.toString().indexOf(buffer.getDisplayName()) >= 0);

    try {
      buffer.load();
      fail("Expected EditorException");
    } catch (EditorException e) {
    }

    try {
      buffer.save();
      fail("Expected EditorException");
    } catch (EditorException e) {
    }

    assertTrue(!buffer.isDirty());
    assertTrue(buffer.isUpToDate());
    assertNull(buffer.getFile());
    assertEquals(textSource, buffer.getTextSource());

    assertEquals(Buffer.UNKNOWN_BUFFER, buffer.getType());

    assertTrue(!buffer.isDirty());
    assertTrue(buffer.isUpToDate());
    assertNull(buffer.getFile());
    assertEquals(textSource, buffer.getTextSource());
  }
Exemple #4
0
  @EBHandler
  public void handleBufferUpdate(BufferUpdate msg) {
    Buffer _buffer = msg.getBuffer();
    if (msg.getWhat() == BufferUpdate.CREATED) {
      if (bufferSwitcher != null) bufferSwitcher.updateBufferList();

      if (buffer.isClosed()) {

        recentBuffer = null;
      }
    } else if (msg.getWhat() == BufferUpdate.CLOSED) {
      if (bufferSwitcher != null) bufferSwitcher.updateBufferList();

      if (_buffer == buffer) {

        Buffer newBuffer = recentBuffer != null ? recentBuffer : _buffer.getPrev();

        if (newBuffer != null && !newBuffer.isClosed()) {
          setBuffer(newBuffer);
          recentBuffer = newBuffer.getPrev();
        }
      } else if (_buffer == recentBuffer) recentBuffer = null;

      Buffer closedBuffer = msg.getBuffer();
      if (closedBuffer.isUntitled()) {

        caretsForPath.remove(closedBuffer.getPath());
      }
    } else if (msg.getWhat() == BufferUpdate.LOAD_STARTED) {
      if (_buffer == buffer) {
        textArea.setCaretPosition(0);
        textArea.getPainter().repaint();
      }
    } else if (msg.getWhat() == BufferUpdate.LOADED) {
      if (_buffer == buffer) {
        textArea.repaint();
        if (bufferSwitcher != null) bufferSwitcher.updateBufferList();

        if (view.getEditPane() == this) {
          StatusBar status = view.getStatus();
          status.updateCaretStatus();
          status.updateBufferStatus();
          status.updateMiscStatus();
        }

        loadCaretInfo();
      }

    } else if (msg.getWhat() == BufferUpdate.DIRTY_CHANGED) {
      if (_buffer == buffer && bufferSwitcher != null) {
        if (buffer.isDirty()) bufferSwitcher.repaint();
        else bufferSwitcher.updateBufferList();
      }
    } else if (msg.getWhat() == BufferUpdate.MARKERS_CHANGED) {
      if (_buffer == buffer) textArea.getGutter().repaint();
    } else if (msg.getWhat() == BufferUpdate.PROPERTIES_CHANGED) {
      if (_buffer == buffer && buffer.isLoaded()) {
        textArea.propertiesChanged();
        if (view.getEditPane() == this) view.getStatus().updateBufferStatus();
      }
    } else if (msg.getWhat() == BufferUpdate.SAVED && _buffer == buffer) {
      textArea.propertiesChanged();
    }
  }