Ejemplo n.º 1
0
 public Marker(Buffer buffer, Position pos) {
   this.buffer = buffer;
   this.pos = new Position(pos);
   file = buffer.getFile();
   lineNumber = pos.lineNumber();
   offset = pos.getOffset();
 }
Ejemplo n.º 2
0
  /**
   * Close a buffer.
   *
   * @param buffer The buffer.
   */
  public void closeBuffer(final Buffer buffer) {
    final boolean removed;

    synchronized (m_bufferList) {
      removed = m_bufferList.remove(buffer);
    }

    if (removed) {
      final File file = buffer.getFile();

      if (buffer.equals(getBufferForFile(file))) {
        m_fileBuffers.remove(file);
      }

      if (buffer.equals(getSelectedBuffer())) {
        final Buffer bufferToSelect;

        synchronized (m_bufferList) {
          final int numberOfBuffers = m_bufferList.size();

          bufferToSelect =
              numberOfBuffers > 0 ? (Buffer) m_bufferList.get(numberOfBuffers - 1) : null;
        }

        selectBuffer(bufferToSelect);
      }

      m_listeners.apply(
          new ListenerSupport.Informer<Listener>() {
            public void inform(Listener l) {
              l.bufferRemoved(buffer);
            }
          });
    }
  }
Ejemplo n.º 3
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());
  }
Ejemplo n.º 4
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());
  }
Ejemplo n.º 5
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());
  }