Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing: added class FlatGlazedListsTest for testing Glazed Lists (ht…
…tps://github.com/glazedlists/glazedlists) table sorting (issue #113)
- Loading branch information
Showing
3 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
...af-testing/src/main/java/com/formdev/flatlaf/testing/glazedlists/FlatGlazedListsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* Copyright 2019 FormDev Software GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.formdev.flatlaf.testing.glazedlists; | ||
|
||
import java.util.Comparator; | ||
import javax.swing.*; | ||
import com.formdev.flatlaf.testing.*; | ||
import com.formdev.flatlaf.testing.FlatTestFrame; | ||
import ca.odell.glazedlists.BasicEventList; | ||
import ca.odell.glazedlists.EventList; | ||
import ca.odell.glazedlists.SortedList; | ||
import ca.odell.glazedlists.gui.TableFormat; | ||
import ca.odell.glazedlists.swing.AdvancedTableModel; | ||
import ca.odell.glazedlists.swing.GlazedListsSwing; | ||
import ca.odell.glazedlists.swing.TableComparatorChooser; | ||
import net.miginfocom.swing.*; | ||
|
||
/** | ||
* @author Karl Tauber | ||
*/ | ||
public class FlatGlazedListsTest | ||
extends FlatTestPanel | ||
{ | ||
public static void main( String[] args ) { | ||
SwingUtilities.invokeLater( () -> { | ||
FlatTestFrame frame = FlatTestFrame.create( args, "FlatGlazedListsTest" ); | ||
frame.showFrame( FlatGlazedListsTest::new ); | ||
} ); | ||
} | ||
|
||
FlatGlazedListsTest() { | ||
initComponents(); | ||
|
||
EventList<Item> itemEventList = new BasicEventList<>(); | ||
itemEventList.add( new Item( "item 1", "item 1b", "January", 123, null ) ); | ||
itemEventList.add( new Item( "item 2", "item 2b", "February", 456, true ) ); | ||
itemEventList.add( new Item( "item 3", null, "March", null, false ) ); | ||
itemEventList.add( new Item( "item 4", null, "April", 234, true ) ); | ||
itemEventList.add( new Item( "item 5", null, "May", null, false ) ); | ||
itemEventList.add( new Item( "item 6", null, "June", null, null ) ); | ||
itemEventList.add( new Item( "item 7", null, "July", null, null ) ); | ||
itemEventList.add( new Item( "item 8", null, "August", null, null ) ); | ||
itemEventList.add( new Item( "item 9", null, "September", null, null ) ); | ||
itemEventList.add( new Item( "item 10", null, "October", null, null ) ); | ||
itemEventList.add( new Item( "item 11", null, "November", null, null ) ); | ||
itemEventList.add( new Item( "item 12", null, "December", null, null ) ); | ||
|
||
Comparator<Item> itemComparator = Comparator.comparing( Item::getName ); | ||
SortedList<Item> sortedItems = new SortedList<>( itemEventList, itemComparator ); | ||
AdvancedTableModel<Item> tableModel = GlazedListsSwing.eventTableModelWithThreadProxyList( sortedItems, new ItemTableFormat() ); | ||
itemsTable.setModel( tableModel ); | ||
TableComparatorChooser<Item> tableComparatorChooser = TableComparatorChooser.install( | ||
itemsTable, sortedItems, TableComparatorChooser.MULTIPLE_COLUMN_MOUSE ); | ||
tableComparatorChooser.appendComparator( 0, 0, false ); | ||
|
||
TableComparatorChooser.setIconPath( "resources/windowsxp" ); | ||
} | ||
|
||
private void initComponents() { | ||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents | ||
scrollPane1 = new JScrollPane(); | ||
itemsTable = new JTable(); | ||
|
||
//======== this ======== | ||
setLayout(new MigLayout( | ||
"insets dialog,hidemode 3", | ||
// columns | ||
"[grow,fill]", | ||
// rows | ||
"[grow,fill]")); | ||
|
||
//======== scrollPane1 ======== | ||
{ | ||
scrollPane1.setViewportView(itemsTable); | ||
} | ||
add(scrollPane1, "cell 0 0,growx,width 300"); | ||
// JFormDesigner - End of component initialization //GEN-END:initComponents | ||
} | ||
|
||
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables | ||
private JScrollPane scrollPane1; | ||
private JTable itemsTable; | ||
// JFormDesigner - End of variables declaration //GEN-END:variables | ||
|
||
//---- class Item --------------------------------------------------------- | ||
|
||
private static class Item | ||
{ | ||
final String name; | ||
final String desc; | ||
final String month; | ||
final Integer number; | ||
final Boolean bool; | ||
|
||
Item( String name, String desc, String month, Integer number, Boolean bool ) { | ||
this.name = name; | ||
this.desc = desc; | ||
this.month = month; | ||
this.number = number; | ||
this.bool = bool; | ||
} | ||
|
||
String getName() { | ||
return name; | ||
} | ||
} | ||
|
||
//---- class ItemTableFormat ---------------------------------------------- | ||
|
||
private static class ItemTableFormat | ||
implements TableFormat<Item> | ||
{ | ||
private static String[] COLUMN_NAMES = { | ||
"Name", | ||
"Description", | ||
"Month", | ||
"Integer", | ||
"Boolean", | ||
}; | ||
|
||
@Override | ||
public int getColumnCount() { | ||
return COLUMN_NAMES.length; | ||
} | ||
|
||
@Override | ||
public String getColumnName( int column ) { | ||
return COLUMN_NAMES[column]; | ||
} | ||
|
||
@Override | ||
public Object getColumnValue( Item item, int column ) { | ||
switch( column ) { | ||
case 0: return item.name; | ||
case 1: return item.desc; | ||
case 2: return item.month; | ||
case 3: return item.number; | ||
case 4: return item.bool; | ||
} | ||
throw new IllegalStateException(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...laf-testing/src/main/java/com/formdev/flatlaf/testing/glazedlists/FlatGlazedListsTest.jfd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
JFDML JFormDesigner: "7.0.2.0.298" Java: "13.0.2" encoding: "UTF-8" | ||
|
||
new FormModel { | ||
contentType: "form/swing" | ||
root: new FormRoot { | ||
auxiliary() { | ||
"JavaCodeGenerator.defaultVariableLocal": true | ||
} | ||
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { | ||
"$layoutConstraints": "insets dialog,hidemode 3" | ||
"$columnConstraints": "[grow,fill]" | ||
"$rowConstraints": "[grow,fill]" | ||
} ) { | ||
name: "this" | ||
add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { | ||
name: "scrollPane1" | ||
auxiliary() { | ||
"JavaCodeGenerator.variableLocal": false | ||
} | ||
add( new FormComponent( "javax.swing.JTable" ) { | ||
name: "itemsTable" | ||
auxiliary() { | ||
"JavaCodeGenerator.variableLocal": false | ||
} | ||
} ) | ||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { | ||
"value": "cell 0 0,growx,width 300" | ||
} ) | ||
}, new FormLayoutConstraints( null ) { | ||
"location": new java.awt.Point( 0, 0 ) | ||
"size": new java.awt.Dimension( 500, 500 ) | ||
} ) | ||
} | ||
} |