Skip to contentMethod: initComponents()
1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2023 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
12: * the License. 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
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
23: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.thesefoolishthings.examples.dci.swing.swing;
28:
29: import javax.annotation.Nonnull;
30: import java.awt.EventQueue;
31: import javax.swing.Action;
32: import javax.swing.JFrame;
33: import javax.swing.JPanel;
34: import javax.swing.SwingUtilities;
35: import org.jdesktop.beansbinding.BindingGroup;
36: import it.tidalwave.thesefoolishthings.examples.dci.swing.PersonPresentation;
37: import it.tidalwave.thesefoolishthings.examples.person.PersonRegistry;
38:
39: /***********************************************************************************************************************
40: *
41: * @author Fabrizio Giudici
42: *
43: **********************************************************************************************************************/
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: *
86: * This method is called from within the constructor to initialize the form.
87: * WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
88: *
89: ******************************************************************************************************************/
90: @SuppressWarnings("unchecked")
91: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
92: private void initComponents() {
93:
94: btOk = new javax.swing.JButton();
95: jScrollPane1 = new javax.swing.JScrollPane();
96: taPeople = new javax.swing.JTable();
97: jScrollPane2 = new javax.swing.JScrollPane();
98: liPeople = new javax.swing.JList();
99:
100: setName("Form"); // NOI18N
101:
102: btOk.setText("Ok");
103: btOk.setName("btOk"); // NOI18N
104:
105: jScrollPane1.setName("jScrollPane1"); // NOI18N
106:
107: taPeople.setModel(new javax.swing.table.DefaultTableModel(
108: new Object [][] {
109: {null, null, null, null},
110: {null, null, null, null},
111: {null, null, null, null},
112: {null, null, null, null}
113: },
114: new String [] {
115: "Title 1", "Title 2", "Title 3", "Title 4"
116: }
117: ));
118: taPeople.setName("taPeople"); // NOI18N
119: jScrollPane1.setViewportView(taPeople);
120:
121: jScrollPane2.setName("jScrollPane2"); // NOI18N
122:
123: liPeople.setModel(new javax.swing.AbstractListModel() {
124: final String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
125: public int getSize() { return strings.length; }
126: public Object getElementAt(final int i) { return strings[i]; }
127: });
128: liPeople.setName("liPeople"); // NOI18N
129: jScrollPane2.setViewportView(liPeople);
130:
131: final javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
132: this.setLayout(layout);
133: layout.setHorizontalGroup(
134: layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
135: .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
136: .addContainerGap()
137: .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
138: .addComponent(btOk, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
139: .addGroup(layout.createSequentialGroup()
140: .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
141: .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
142: .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)))
143: .addContainerGap())
144: );
145: layout.setVerticalGroup(
146: layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
147: .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
148: .addContainerGap()
149: .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
150: .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
151: .addGroup(layout.createSequentialGroup()
152: .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
153: .addGap(0, 0, Short.MAX_VALUE)))
154: .addGap(18, 18, 18)
155: .addComponent(btOk, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
156: .addContainerGap())
157: );
158: }// </editor-fold>//GEN-END:initComponents
159:
160: // Variables declaration - do not modify//GEN-BEGIN:variables
161: private javax.swing.JButton btOk;
162: private javax.swing.JScrollPane jScrollPane1;
163: private javax.swing.JScrollPane jScrollPane2;
164: private javax.swing.JList liPeople;
165: private javax.swing.JTable taPeople;
166: // End of variables declaration//GEN-END:variables
167: }