mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
Testing: added class FlatGlazedListsTest for testing Glazed Lists (https://github.com/glazedlists/glazedlists) table sorting (issue #113)
This commit is contained in:
@@ -38,6 +38,7 @@ dependencies {
|
|||||||
implementation( "org.swinglabs.swingx:swingx-all:1.6.5-1" )
|
implementation( "org.swinglabs.swingx:swingx-all:1.6.5-1" )
|
||||||
implementation( "org.swinglabs.swingx:swingx-beaninfo:1.6.5-1" )
|
implementation( "org.swinglabs.swingx:swingx-beaninfo:1.6.5-1" )
|
||||||
implementation( "com.jidesoft:jide-oss:3.6.18" )
|
implementation( "com.jidesoft:jide-oss:3.6.18" )
|
||||||
|
implementation( "com.glazedlists:glazedlists:1.11.0" )
|
||||||
implementation( "org.netbeans.api:org-openide-awt:RELEASE112" )
|
implementation( "org.netbeans.api:org-openide-awt:RELEASE112" )
|
||||||
|
|
||||||
// implementation( "org.pushing-pixels:radiance-substance:2.5.1" )
|
// implementation( "org.pushing-pixels:radiance-substance:2.5.1" )
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 )
|
||||||
|
} )
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user