Searchable w/timeout

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Searchable w/timeout

Postby sbrattla » Wed Jan 26, 2011 2:58 am

Hi,

I needed the Searchable pop up to hide after a given number of miliseconds, so I extended ListSearchable
and wrote a few lines of code which takes care of it. If anyone else needs this functionality, then feel
free to use the below code. I haven't put too much effort in documenting the code, but it is fairly self
explanatory so you shouldn't have too much trouble reading it if you need to make any adjustments.

Usage:
Code: Select all
JList l = new JList();
ListSearchable lS = new ListSearchableWithTimeOut(l, 350);


The ListSearchableWithTimeOut has two constructors. One which accepts the JList which is to be made
searchable (and which hides the searchable pop up after 350 miliseconds) and one which accepts the JList along
with the delay specified in miliseconds.

Code: Select all
package com.tracker.utilities.swing.components;

import com.jidesoft.swing.ListSearchable;
import com.jidesoft.swing.event.SearchableEvent;
import com.jidesoft.swing.event.SearchableListener;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JList;


public class ListSearchableWithTimeOut extends ListSearchable {

    private final int delay;
    private TimerTask task;
    private Timer timer;

    public ListSearchableWithTimeOut(JList list) {
        this(list, 350);
    }

    public ListSearchableWithTimeOut(JList list, int delay) {
        super(list);
        this.delay = delay;
        initialise();
    }

    private void initialise() {

        timer = new Timer();

        addSearchableListener(new SearchableListener() {
            public void searchableEventFired(SearchableEvent evt) {
                if (task != null) {
                    task.cancel();
                }

                task = new HideTask();
                timer.schedule(task, delay);
            }
        });
    }

    private ListSearchable getListSearchable() {
        return this;
    }

    private class HideTask extends TimerTask {
        @Override
        public void run() {
            getListSearchable().hidePopup();
        }
    }
}
sbrattla
 
Posts: 20
Joined: Wed Apr 01, 2009 2:38 am

Re: Searchable w/timeout

Postby Walter Laan » Wed Jan 26, 2011 4:25 am

That's a really nice idea!
Your implementation ignores the EDT so perhaps Jide could add the following to SearchableUtils using javax.swing.Timer (or make it a method of Searchable itself). I think java.net is still in migration lock down so can't be committed atm.

Code: Select all
public static void installPopupTimeout(final Searchable searchable, int delay) {
        final Timer timer = new Timer(delay, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                searchable.hidePopup();
            }
        });
        timer.setRepeats(false);

        searchable.addSearchableListener(new SearchableListener() {
            public void searchableEventFired(SearchableEvent e) {
                if(e.getID() == SearchableEvent.SEARCHABLE_END) {
                    timer.stop();
                }
                else {
                    timer.restart();
                }
            }
        });
    }
Walter Laan
 
Posts: 383
Joined: Mon May 01, 2006 12:13 am

Re: Searchable w/timeout

Postby JIDE Support » Wed Jan 26, 2011 10:54 am

Thanks for contributions. Will try to include your ideas into the open source project as long as it's unlocked.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Searchable w/timeout

Postby JIDE Support » Thu Mar 10, 2011 7:33 pm

Just so you know, Searchable#setPopupTimeout() is added in 2.11.2 just released.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Searchable w/timeout

Postby sbrattla » Tue Jun 21, 2011 1:17 am

That's great.

Thank you for taking suggestions into consideration. It's great to see a company being able to react fairly quick to improvement suggestions.
sbrattla
 
Posts: 20
Joined: Wed Apr 01, 2009 2:38 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 15 guests

cron