This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 24 - Pages: 2 [ Previous | 1 2 ] - Last Post: 6 Sep 17, 15:49 Last Post By: JeffTucker
JeffTucker

Posts: 8,216
Registered: 31-Jan-2006
Re: Repeatable item in JDraggableList()
Posted: 5 Sep 17, 18:04   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Just thinking ahead a bit....

In a UI, let's say that I want to enable/disable some other fields based upon whether a given item is included in the current "used" list. In Minimal, for example, say I want to enable another field only if fileTitle is in the "used" list. What would the statement look like?
RobM

Posts: 3,820
Registered: 4-Aug-2006
Re: Repeatable item in JDraggableList()
Posted: 5 Sep 17, 21:54   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
RobM wrote:
RobM wrote:
Maybe a 'reset' option would be of use too, letting users quickly return the selected list back to the default setting.
Couldn't resist having a go. The attached onload.bsh is modified from the Minimal skin posted above. It offers a reset list, clear all from list and add all to the list.

Nice :-). I have the feeling we'll be seeing some usage of this component in your skins soon. Also check out the updated .small() method that gets you a visually smaller version of these lists. Just add .small() to the constructor call to try it out.

I was going to update Polyglot skin to use the JDraggableList but I need to find some example code to copy.

In short, I don't know how to take a list of items and use that to populate the draggable list - I have a list of languages (from the skin's texts.properties) e.g the list is "en","se","de" and I want to use that to make the list of items - using
setSecondaryList(JDraggableList secondaryList)
I'm guessing.
RobM

Posts: 3,820
Registered: 4-Aug-2006
Re: Repeatable item in JDraggableList()
Posted: 6 Sep 17, 10:59   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
I seem to have a working method
JDraggableList languageList = new JDraggableList(getSupportedLanguages().toArray(), new String[] { "en" }, false);

where getSupportedLanguages() is a linkedList.
davidekholm

Posts: 3,474
Registered: 18-Oct-2002
Re: Repeatable item in JDraggableList()
Posted: 6 Sep 17, 15:04   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
Just thinking ahead a bit....

In a UI, let's say that I want to enable/disable some other fields based upon whether a given item is included in the current "used" list. In Minimal, for example, say I want to enable another field only if fileTitle is in the "used" list. What would the statement look like?


Here's how:
import javax.swing.event.*;
thumbnailItems.getModel().addListDataListener(new ListDataListener()  {
    void intervalAdded(ListDataEvent e) {
    		System.out.println("Added " + e);
    }
    void intervalRemoved(ListDataEvent e) {
    		System.out.println("Removed " + e);			    	
    }
    void contentsChanged(ListDataEvent e) {
    		System.out.println("Changed " + e);			    	
    }
});
JeffTucker

Posts: 8,216
Registered: 31-Jan-2006
Re: Repeatable item in JDraggableList()
Posted: 6 Sep 17, 15:18   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
That's pretty bizarre. I was expecting a more typical StateMonitor() statement, executed upon any change, like:
enable(aCheckBox.isSelected(), someotheritem);
Or:
enable(aComboBox.getSelectedItem().equals("title"), someotheritem);
Edit: You know, something like:
enable(aDraggableList.contains("fileTitle"), someotheritem);
davidekholm

Posts: 3,474
Registered: 18-Oct-2002
Re: Repeatable item in JDraggableList()
Posted: 6 Sep 17, 15:33   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
Just thinking ahead a bit....

In a UI, let's say that I want to enable/disable some other fields based upon whether a given item is included in the current "used" list. In Minimal, for example, say I want to enable another field only if fileTitle is in the "used" list. What would the statement look like?


I should give a better example, but first do a core update to 14.1.12. That version has an updated StateMonitor class that accepts any JList object too (like JDraggableList for instance). Now you can write like this to check the presence of the fileName label:
new StateMonitor() {
	public void onChange() {
		System.out.println("File name present: " + 
		((DefaultListModel)thumbnailItems.getModel()).contains(new Item("fileName")));
	}
}.add(thumbnailItems).done();
JeffTucker

Posts: 8,216
Registered: 31-Jan-2006
Re: Repeatable item in JDraggableList()
Posted: 6 Sep 17, 15:35   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Yes. You were posting while I was editing. That's the kind of thing I was looking for. :)
davidekholm

Posts: 3,474
Registered: 18-Oct-2002
Re: Repeatable item in JDraggableList()
Posted: 6 Sep 17, 15:41   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
I polished JDraggableList further to simplify the coding for you. Do another core update. Now you can write like this:
new StateMonitor() {
	public void onChange() {
		System.out.println("File name present: " + 
		thumbnailItems.contains(new Item("fileName")));
	}
}.add(thumbnailItems).done();


Edited by: davidekholm. Pasted wrong code
davidekholm

Posts: 3,474
Registered: 18-Oct-2002
Re: Repeatable item in JDraggableList()
Posted: 6 Sep 17, 15:44   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
Yes. You were posting while I was editing. That's the kind of thing I was looking for. :)

:-). The main reason for me writing the StateMonitor was to unload the burden of having to remember what interface to implement in order to monitor changes for various components. Each component seem to have its own listener interface. I understand that the reason for this is that components have different properties, but one can usually query the component afterwards for details. In most cases it's enough to know that some state has changed. Such a query should have a uniform look, hence the StateMonitor. Now it supports JLists too.
JeffTucker

Posts: 8,216
Registered: 31-Jan-2006
Re: Repeatable item in JDraggableList()
Posted: 6 Sep 17, 15:49   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
The StateMonitor() has proven to be one of the best tools in the box. I use it almost exclusively. There are only a few odd situations when I have to revert to something more basic.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums