From 212c553904f75aae7e9b6928f252aab8f3fd24b7 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 16 Jun 2020 16:48:00 +0200 Subject: [PATCH] Testing: added class FlatGlazedListsTest for testing Glazed Lists (https://github.com/glazedlists/glazedlists) table sorting (issue #113) --- flatlaf-testing/build.gradle.kts | 1 + .../glazedlists/FlatGlazedListsTest.java | 157 ++++++++++++++++++ .../glazedlists/FlatGlazedListsTest.jfd | 34 ++++ 3 files changed, 192 insertions(+) create mode 100644 flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/glazedlists/FlatGlazedListsTest.java create mode 100644 flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/glazedlists/FlatGlazedListsTest.jfd diff --git a/flatlaf-testing/build.gradle.kts b/flatlaf-testing/build.gradle.kts index b17d94ab..3bdbc774 100644 --- a/flatlaf-testing/build.gradle.kts +++ b/flatlaf-testing/build.gradle.kts @@ -38,6 +38,7 @@ dependencies { implementation( "org.swinglabs.swingx:swingx-all:1.6.5-1" ) implementation( "org.swinglabs.swingx:swingx-beaninfo:1.6.5-1" ) 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.pushing-pixels:radiance-substance:2.5.1" ) diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/glazedlists/FlatGlazedListsTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/glazedlists/FlatGlazedListsTest.java new file mode 100644 index 00000000..cc6c1414 --- /dev/null +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/glazedlists/FlatGlazedListsTest.java @@ -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 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 itemComparator = Comparator.comparing( Item::getName ); + SortedList sortedItems = new SortedList<>( itemEventList, itemComparator ); + AdvancedTableModel tableModel = GlazedListsSwing.eventTableModelWithThreadProxyList( sortedItems, new ItemTableFormat() ); + itemsTable.setModel( tableModel ); + TableComparatorChooser 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 + { + 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(); + } + } +} diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/glazedlists/FlatGlazedListsTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/glazedlists/FlatGlazedListsTest.jfd new file mode 100644 index 00000000..02c995cf --- /dev/null +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/glazedlists/FlatGlazedListsTest.jfd @@ -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 ) + } ) + } +}