Bookmark

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Bookmark

Postby Matias22 » Sun Mar 28, 2010 11:33 am

Hello, im looking for function to call Bookmark. Like on this sample aplet Click

Thanx.
Matias22
 
Posts: 13
Joined: Fri Feb 26, 2010 4:46 pm

Re: Bookmark

Postby Matias22 » Sun Mar 28, 2010 11:48 am

I made something like this:
Code: Select all
        jCheckBoxMenuItem3.addChangeListener(new ChangeListener()  { 
            public void stateChanged(ChangeEvent e)  {   
               
               if(jCheckBoxMenuItem2.isSelected())
                  jScrollPane1.setIconRowHeaderEnabled(true);
                  
               else
                  jScrollPane1.setIconRowHeaderEnabled(false);
            } 
        });


But it doesnt work, any hints?
Matias22
 
Posts: 13
Joined: Fri Feb 26, 2010 4:46 pm

Re: Bookmark

Postby robert » Sun Mar 28, 2010 1:59 pm

Hi Matias,

Just so you know, you can check out the source for that demo here. You can also download the source for it on the SourceForge page.

As for your specific question, calling setIconRowHeaderEnabled() like you are doing is good if you want to add arbitrary icons (breakpoints, etc.), but to use the built-in bookmarking support, you should use Gutter.setBookmarkingEnabled(true):

Code: Select all
scrollPane = new RTextScrollPane(textArea, true);
Gutter gutter = scrollPane.getGutter();
gutter.setBookmarkingEnabled(true);
URL url = getClass().getClassLoader().getResource("bookmark.png");
gutter.setBookmarkIcon(new ImageIcon(url));


Enabling bookmark icons should automatically make the icon row header visible. Note that you'll have to call setBookmarkingIcon(Icon) to truly enable bookmarking, as if no icon is set, no icon will be rendered for the bookmarked lines.

Enabling bookmarking causes F2/Ctrl+F2 to move to the next/previous bookmark, respectively. Bookmarking a line is done via Ctrl+F2.
User avatar
robert
 
Posts: 786
Joined: Sat May 10, 2008 5:16 pm

Re: Bookmark

Postby Matias22 » Thu Apr 01, 2010 2:03 pm

Works, but I have strange problem, my code :

Code: Select all
        jCheckBoxMenuItem3.addChangeListener(new ChangeListener()  {
            public void stateChanged(ChangeEvent e)  {

               if(jCheckBoxMenuItem3.isSelected()){
                  gutter.setBookmarkingEnabled(true);
                  gutter.setBookmarkIcon(new ImageIcon(getClass().getResource("/eu/l2jcustom/l2jeditor/images/bookmark.png")));
                  jScrollPane1.setIconRowHeaderEnabled(true);
               }
               else{
                  gutter.setBookmarkingEnabled(false);
                  jScrollPane1.setIconRowHeaderEnabled(false);
               }

            }
        });


my jCheckBoxMenuItem3 is set to enabled so it should add this bookmark by default at startup of my program (I made Line Count and Line Highlighting with the same method and it works..)

And here on startup it doesnt show this bookmark field (is like disabled)...but if i will ROLL OVER (Not release :(!) it show me this bookmark file and i can bookmark my lines..but if I will ROLL OVER on my jCheckBoxMenuItem3 once again..my Bookmars are removed oO (but field for bookmarks is still there)

Can You help me?
Matias22
 
Posts: 13
Joined: Fri Feb 26, 2010 4:46 pm

Re: Bookmark

Postby robert » Thu Apr 01, 2010 3:23 pm

Hmm, I don't think ChangeListener is what you want. IIRC, ChangeListener sends out notification to all listeners for all kinds of events, even rollover events, like you're experiencing. You should instead switch over to an ActionListener. Then your listener will only be called when the user clicks on the item. Or, even better than adding an ActionListener is to use a javax.swing.Action. Create an Action that does what you've been doing in your ChangeListener/ActionListener and create your JMenuItem from that Action. For an example of using Actions in menu items, see this source code from the RSTA demo.

If after you switch over to either ActionListener or Actions, you are still experiencing the problem, please post an SSCCE that shows the problem, and we can take it from there.

Thanks!
User avatar
robert
 
Posts: 786
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 3 guests

cron