Skip to content

Method: getSize()

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * 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
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
22: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.thesefoolishthings.examples.dci.swing.swing;
27:
28: import jakarta.annotation.Nonnull;
29: import java.awt.EventQueue;
30: import javax.swing.Action;
31: import javax.swing.JFrame;
32: import javax.swing.JPanel;
33: import javax.swing.SwingUtilities;
34: import org.jdesktop.beansbinding.BindingGroup;
35: import it.tidalwave.thesefoolishthings.examples.dci.swing.PersonPresentation;
36: import it.tidalwave.thesefoolishthings.examples.person.PersonRegistry;
37:
38: /***************************************************************************************************************************************************************
39: *
40: * @author Fabrizio Giudici
41: *
42: **************************************************************************************************************************************************************/
43: @SuppressWarnings("this-escape")
44: public class SwingPersonPresentation extends JPanel implements PersonPresentation
45: {
46: private final BindingGroup bindings = new BindingGroup();
47:
48: /***********************************************************************************************************************************************************
49: *
50: **********************************************************************************************************************************************************/
51: public SwingPersonPresentation()
52: {
53: initComponents();
54: }
55:
56: /***********************************************************************************************************************************************************
57: *
58: **********************************************************************************************************************************************************/
59: @Override
60: public void bind (@Nonnull final Action okAction, @Nonnull final PersonRegistry personRegistry)
61: {
62: EventQueue.invokeLater(() ->
63: {
64: Bindings.bind(bindings, personRegistry, liPeople);
65: Bindings.bind(bindings, personRegistry, taPeople);
66: bindings.bind();
67: btOk.setAction(okAction);
68: });
69: }
70:
71: /***********************************************************************************************************************************************************
72: *
73: **********************************************************************************************************************************************************/
74: @Override
75: public void dispose()
76: {
77: EventQueue.invokeLater(() ->
78: {
79: bindings.unbind();
80: ((JFrame)SwingUtilities.getAncestorOfClass(JFrame.class, this)).dispose();
81: });
82: }
83:
84: /***********************************************************************************************************************************************************
85: * This method is called from within the constructor to initialize the form.
86: * WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
87: **********************************************************************************************************************************************************/
88: @SuppressWarnings("unchecked")
89: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
90: private void initComponents() {
91:
92: btOk = new javax.swing.JButton();
93: jScrollPane1 = new javax.swing.JScrollPane();
94: taPeople = new javax.swing.JTable();
95: jScrollPane2 = new javax.swing.JScrollPane();
96: liPeople = new javax.swing.JList<>();
97:
98: setName("Form"); // NOI18N
99:
100: btOk.setText("Ok");
101: btOk.setName("btOk"); // NOI18N
102:
103: jScrollPane1.setName("jScrollPane1"); // NOI18N
104:
105: taPeople.setModel(new javax.swing.table.DefaultTableModel(
106: new Object [][] {
107: {null, null, null, null},
108: {null, null, null, null},
109: {null, null, null, null},
110: {null, null, null, null}
111: },
112: new String [] {
113: "Title 1", "Title 2", "Title 3", "Title 4"
114: }
115: ));
116: taPeople.setName("taPeople"); // NOI18N
117: jScrollPane1.setViewportView(taPeople);
118:
119: jScrollPane2.setName("jScrollPane2"); // NOI18N
120:
121: liPeople.setModel(new javax.swing.AbstractListModel<>() {
122: final String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
123: public int getSize() { return strings.length; }
124: public Object getElementAt(final int i) { return strings[i]; }
125: });
126: liPeople.setName("liPeople"); // NOI18N
127: jScrollPane2.setViewportView(liPeople);
128:
129: final var layout = new javax.swing.GroupLayout(this);
130: this.setLayout(layout);
131: layout.setHorizontalGroup(
132: layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
133: .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
134: .addContainerGap()
135: .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
136: .addComponent(btOk, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
137: .addGroup(layout.createSequentialGroup()
138: .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
139: .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
140: .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)))
141: .addContainerGap())
142: );
143: layout.setVerticalGroup(
144: layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
145: .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
146: .addContainerGap()
147: .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
148: .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
149: .addGroup(layout.createSequentialGroup()
150: .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
151: .addGap(0, 0, Short.MAX_VALUE)))
152: .addGap(18, 18, 18)
153: .addComponent(btOk, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
154: .addContainerGap())
155: );
156: }// </editor-fold>//GEN-END:initComponents
157:
158: // Variables declaration - do not modify//GEN-BEGIN:variables
159: private javax.swing.JButton btOk;
160: private javax.swing.JScrollPane jScrollPane1;
161: private javax.swing.JScrollPane jScrollPane2;
162: private javax.swing.JList<Object> liPeople;
163: private javax.swing.JTable taPeople;
164: // End of variables declaration//GEN-END:variables
165: }