Skip to contentPackage: SwingPersonPresentation$1
SwingPersonPresentation$1
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2024 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 javax.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: public class SwingPersonPresentation extends JPanel implements PersonPresentation
44: {
45: private final BindingGroup bindings = new BindingGroup();
46:
47: /***********************************************************************************************************************************************************
48: *
49: **********************************************************************************************************************************************************/
50: public SwingPersonPresentation()
51: {
52: initComponents();
53: }
54:
55: /***********************************************************************************************************************************************************
56: *
57: **********************************************************************************************************************************************************/
58: @Override
59: public void bind (@Nonnull final Action okAction, @Nonnull final PersonRegistry personRegistry)
60: {
61: EventQueue.invokeLater(() ->
62: {
63: Bindings.bind(bindings, personRegistry, liPeople);
64: Bindings.bind(bindings, personRegistry, taPeople);
65: bindings.bind();
66: btOk.setAction(okAction);
67: });
68: }
69:
70: /***********************************************************************************************************************************************************
71: *
72: **********************************************************************************************************************************************************/
73: @Override
74: public void dispose()
75: {
76: EventQueue.invokeLater(() ->
77: {
78: bindings.unbind();
79: ((JFrame)SwingUtilities.getAncestorOfClass(JFrame.class, this)).dispose();
80: });
81: }
82:
83: /***********************************************************************************************************************************************************
84: * This method is called from within the constructor to initialize the form.
85: * WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
86: **********************************************************************************************************************************************************/
87: @SuppressWarnings("unchecked")
88: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
89: private void initComponents() {
90:
91: btOk = new javax.swing.JButton();
92: jScrollPane1 = new javax.swing.JScrollPane();
93: taPeople = new javax.swing.JTable();
94: jScrollPane2 = new javax.swing.JScrollPane();
95: liPeople = new javax.swing.JList();
96:
97: setName("Form"); // NOI18N
98:
99: btOk.setText("Ok");
100: btOk.setName("btOk"); // NOI18N
101:
102: jScrollPane1.setName("jScrollPane1"); // NOI18N
103:
104: taPeople.setModel(new javax.swing.table.DefaultTableModel(
105: new Object [][] {
106: {null, null, null, null},
107: {null, null, null, null},
108: {null, null, null, null},
109: {null, null, null, null}
110: },
111: new String [] {
112: "Title 1", "Title 2", "Title 3", "Title 4"
113: }
114: ));
115: taPeople.setName("taPeople"); // NOI18N
116: jScrollPane1.setViewportView(taPeople);
117:
118: jScrollPane2.setName("jScrollPane2"); // NOI18N
119:
120: liPeople.setModel(new javax.swing.AbstractListModel() {
121: final String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
122: public int getSize() { return strings.length; }
123: public Object getElementAt(final int i) { return strings[i]; }
124: });
125: liPeople.setName("liPeople"); // NOI18N
126: jScrollPane2.setViewportView(liPeople);
127:
128: final var layout = new javax.swing.GroupLayout(this);
129: this.setLayout(layout);
130: layout.setHorizontalGroup(
131: layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
132: .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
133: .addContainerGap()
134: .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
135: .addComponent(btOk, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
136: .addGroup(layout.createSequentialGroup()
137: .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
138: .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
139: .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)))
140: .addContainerGap())
141: );
142: layout.setVerticalGroup(
143: layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144: .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
145: .addContainerGap()
146: .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
147: .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
148: .addGroup(layout.createSequentialGroup()
149: .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
150: .addGap(0, 0, Short.MAX_VALUE)))
151: .addGap(18, 18, 18)
152: .addComponent(btOk, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
153: .addContainerGap())
154: );
155: }// </editor-fold>//GEN-END:initComponents
156:
157: // Variables declaration - do not modify//GEN-BEGIN:variables
158: private javax.swing.JButton btOk;
159: private javax.swing.JScrollPane jScrollPane1;
160: private javax.swing.JScrollPane jScrollPane2;
161: private javax.swing.JList liPeople;
162: private javax.swing.JTable taPeople;
163: // End of variables declaration//GEN-END:variables
164: }