~ubuntu-branches/ubuntu/natty/libswingx-java/natty

« back to all changes in this revision

Viewing changes to src/test/org/jdesktop/swingx/JXListVisualCheck.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2010-07-26 12:11:27 UTC
  • mfrom: (4.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100726121127-k0d3b21nhja0dn93
Tags: 1:1.6.1-1
* New upstream release.
* Switch to 3.0 (quilt) format.
* Bump Standards-Version to 3.9.1: no changes needed.
* Drop Depends on JRE: not requested anymore by new Java Policy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
package org.jdesktop.swingx;
6
6
 
7
7
import java.awt.Color;
 
8
import java.awt.Component;
8
9
import java.awt.Cursor;
9
10
import java.awt.event.ActionEvent;
10
11
import java.net.MalformedURLException;
22
23
import javax.swing.JScrollPane;
23
24
import javax.swing.ListModel;
24
25
import javax.swing.RowFilter;
 
26
import javax.swing.SwingUtilities;
25
27
import javax.swing.UIManager;
 
28
import javax.swing.event.ListSelectionEvent;
 
29
import javax.swing.event.ListSelectionListener;
26
30
import javax.swing.plaf.UIResource;
27
31
 
28
32
import org.jdesktop.swingx.decorator.ColorHighlighter;
 
33
import org.jdesktop.swingx.decorator.ComponentAdapter;
29
34
import org.jdesktop.swingx.decorator.HighlightPredicate;
 
35
import org.jdesktop.swingx.decorator.Highlighter;
30
36
import org.jdesktop.swingx.decorator.HighlighterFactory;
31
37
import org.jdesktop.swingx.decorator.PatternPredicate;
32
38
import org.jdesktop.swingx.hyperlink.EditorPaneLinkVisitor;
34
40
import org.jdesktop.swingx.hyperlink.LinkModelAction;
35
41
import org.jdesktop.swingx.renderer.DefaultListRenderer;
36
42
import org.jdesktop.swingx.renderer.HyperlinkProvider;
 
43
import org.jdesktop.swingx.renderer.HighlighterClientVisualCheck.FontHighlighter;
37
44
import org.jdesktop.swingx.sort.RowFilters;
38
45
import org.jdesktop.test.AncientSwingTeam;
39
46
import org.junit.After;
54
61
//            setLookAndFeel("Nimbus");
55
62
//            new XRegion("XList", "XListUI", false);
56
63
//          test.runInteractiveTests();
57
 
            test.runInteractiveTests("interactive.*Match.*");
 
64
            test.runInteractiveTests("interactive.*RowFilter.*");
58
65
        } catch (Exception e) {
59
66
            System.err.println("exception when executing interactive tests:");
60
67
            e.printStackTrace();
62
69
    }
63
70
 
64
71
    /**
 
72
     * Issue #1261-swingx: list goes blank after setting model and filter.
 
73
     * 
 
74
     * To reproduce:
 
75
     * - click on setModel: resets the model and turns on filter (expected)
 
76
     * - click on filterOff: clears the list (unexpected - the expected behaviour
 
77
     *   is to show all entries
 
78
     * 
 
79
     * Workaround:
 
80
     * - click on invalidate to explicitly invalidated the cell size cache 
 
81
     *  (should be done automatically) - fixed to now do in ListSortUI.sorterChanged
 
82
     * 
 
83
     * example adjusted from reporter
 
84
     */
 
85
    public void interactiveRowFilterAfterSetModel() {
 
86
        final JXList list = new JXList(true);
 
87
        JXFrame frame = wrapWithScrollingInFrame(list, "filter after model");
 
88
        
 
89
        final Action filterOnAction = new AbstractAction("filter on") {
 
90
            
 
91
            @Override
 
92
            public void actionPerformed(ActionEvent e) {
 
93
                list.setRowFilter(new RowFilter<ListModel, Integer>() {
 
94
 
 
95
                    @Override
 
96
                    public boolean include(
 
97
                            Entry<? extends ListModel, ? extends Integer> entry) {
 
98
                        boolean include = entry.getStringValue(entry.getIdentifier())
 
99
                                .toLowerCase().contains("o");
 
100
                        return include;
 
101
                    }
 
102
 
 
103
                });
 
104
            }
 
105
        };
 
106
        
 
107
//        addAction(frame, filterOnAction);
 
108
        
 
109
        Action modelAction = new AbstractAction("setModel") {
 
110
            int count;
 
111
            @Override
 
112
            public void actionPerformed(ActionEvent e) {
 
113
                DefaultListModel model = new DefaultListModel();
 
114
                model.addElement("One" + count++);
 
115
                model.addElement("Two");
 
116
                model.addElement("Three");
 
117
                model.addElement("Four");
 
118
                model.addElement("Five");
 
119
                list.setModel(model);
 
120
                filterOnAction.actionPerformed(e);
 
121
            }
 
122
        };
 
123
        addAction(frame, modelAction);
 
124
        
 
125
        Action filterOffAction = new AbstractAction("filter off") {
 
126
            
 
127
            @Override
 
128
            public void actionPerformed(ActionEvent e) {
 
129
                list.setRowFilter(new RowFilter<ListModel, Integer>() {
 
130
 
 
131
                    @Override
 
132
                    public boolean include(
 
133
                            Entry<? extends ListModel, ? extends Integer> entry) {
 
134
                        return true;
 
135
                    }
 
136
 
 
137
                });
 
138
            }
 
139
        };
 
140
        
 
141
        addAction(frame, filterOffAction);
 
142
        
 
143
        Action invalidateCacheAction = new AbstractAction("invalidateCache") {
 
144
            
 
145
            @Override
 
146
            public void actionPerformed(ActionEvent e) {
 
147
                // this shouldn't be necessary
 
148
                list.invalidateCellSizeCache();
 
149
            }
 
150
        };
 
151
        addAction(frame, invalidateCacheAction);
 
152
        addStatusMessage(frame, "setModel == new Model + rowFilter on; filterOff = rowFilter off (should show all)");
 
153
        show(frame, 500, 300);
 
154
    }
 
155
    
 
156
    /**
 
157
     * Issue #1255-swingx: enhance dynamic row sizing.
 
158
     */
 
159
    public void interactiveDynamicCellHeight() {
 
160
        final JXList list = new JXList(AncientSwingTeam.createNamedColorListModel(), true);
 
161
        ListSelectionListener l = new ListSelectionListener() {
 
162
            
 
163
            @Override
 
164
            public void valueChanged(final ListSelectionEvent e) {
 
165
                SwingUtilities.invokeLater(new Runnable() {
 
166
                    public void run() {
 
167
                        list.invalidateCellSizeCache();
 
168
                    }
 
169
                });
 
170
            }
 
171
            
 
172
        };
 
173
        list.addListSelectionListener(l);
 
174
        HighlightPredicate selected = new HighlightPredicate() {
 
175
            
 
176
            @Override
 
177
            public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
 
178
                return adapter.isSelected();
 
179
            }
 
180
        };
 
181
        Highlighter hl = new FontHighlighter(selected, list.getFont().deriveFont(50f));
 
182
        list.addHighlighter(hl);
 
183
        JXFrame frame = wrapWithScrollingInFrame(list, "big font on focus");
 
184
        Action toggleSort = new AbstractAction("toggle sort") {
 
185
            
 
186
            @Override
 
187
            public void actionPerformed(ActionEvent e) {
 
188
                list.toggleSortOrder();
 
189
            }
 
190
        };
 
191
        addAction(frame, toggleSort);
 
192
        show(frame);
 
193
    }
 
194
 
 
195
    /**
65
196
     * Issue 1161-swingx: JXList not completely updated on setRowFilter
66
197
     * Issue 1162-swingx: JXList getNextMatch access model directly
67
198
     */