Icons disappear in gutter when scrolled with folding.

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Icons disappear in gutter when scrolled with folding.

Postby Tom K. » Tue May 15, 2012 6:25 pm

I've noticed a problem with icons disappearing in the gutter, when folding is enabled
and the window is scrolled. Here's a program that demonstrates this:

Code: Select all

/*
Demonstrate disappearing icons in gutter when scrolled.

Run the program:

- Note: All folds are expanded, the scroll bar is positioned
at the bottom of its range.
- Scroll to the top.  Note the icons in the gutter every 10 lines.
- Use the popup menu: Folding->Collapse all folds.
  Note the icons are still visible in the gutter for the folds
  that fit in the window.
- Scroll down to the bottom.  Note that the icons do not appear on the
expected lines.
- Scroll back to the top.  Only the icon on line 1 is visible.
- Resize the window slightly to force a refresh.  The
icons within the visible region will reappear.
- Scroll to the bottom.  Resize the window slightly. Note
that the icons do not reappear.
- Resize the window so that all lines are visible.  All
of the icons in the gutter will be visible.
*/

import java.awt.*;
import javax.swing.*;

import org.fife.ui.rtextarea.*;
import org.fife.ui.rsyntaxtextarea.*;
import javax.swing.text.BadLocationException;

public class FoldingTest extends JFrame {

  private static final long serialVersionUID = 1L;
 
  private TextEditorPane editPane;
  private RTextScrollPane sp;
  private Gutter gutter;
  private int nRegions = 10;

  public FoldingTest() throws java.io.IOException {

    JPanel cp = new JPanel(new BorderLayout());

    editPane = new TextEditorPane();
    editPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_C);
    editPane.setCodeFoldingEnabled(true);

    sp = new RTextScrollPane(editPane);
    int width = 600;
    int height = 300;
    sp.setPreferredSize(new Dimension(width, height));
    cp.add(sp);

    fillTextArea();

    // Set up gutter and icon
    sp.setIconRowHeaderEnabled(true);
    gutter = sp.getGutter();

    // Add icons at regular intervals to the gutter.
    String iconName = "FileChooser.upFolderIcon";
    Icon icon = UIManager.getIcon(iconName);
    if (icon == null) {
      System.err.println("Could not find icon: " + iconName);
      System.exit(1);
    }

    for (int i=0; i < nRegions; ++i) {
      setIconOnLine(i*10 + 1, icon);
    }

    setContentPane(cp);
    setTitle("RSyntaxTextArea Gutter Icon Test");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    pack();
    setLocationRelativeTo(null);

  }

  private void fillTextArea() {
    // add multiple non-nested folding regions

    for (int i=0; i<nRegions; ++i) {
      editPane.append("// loop " + i + "\n");
      editPane.append("for (;;) {");
      editPane.append("\n\n\n\n\n\n");
      editPane.append("}\n");
      editPane.append("\n\n");
    }

  }

  private void setIconOnLine(int lineNum, Icon icon) {
   
   try {
      gutter.addLineTrackingIcon(lineNum-1, icon);
    } catch (BadLocationException except) {
      System.err.println(except);
    }
  }


   public static void main(String[] args) {

      // Start all Swing applications on the EDT.
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
           try {
            FoldingTest demo = new FoldingTest();
            demo.setVisible(true);
           }
           catch(java.io.IOException except) {
             except.printStackTrace();
           }
           

         }
      });

   }

}



Thanks
Tom K.
Tom K.
 

Re: Icons disappear in gutter when scrolled with folding.

Postby robert » Thu May 17, 2012 12:10 pm

Thanks Tom! I'll take a look.
User avatar
robert
 
Posts: 796
Joined: Sat May 10, 2008 5:16 pm

Re: Icons disappear in gutter when scrolled with folding.

Postby robert » Tue May 29, 2012 3:32 am

Fixed in SVN revision 542. It will be included in the 2.0.4 release in a few weeks.
User avatar
robert
 
Posts: 796
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron