Skip to content

Commit 8fe8797

Browse files
committed
ui changes
1 parent 8bc3079 commit 8fe8797

File tree

3 files changed

+147
-68
lines changed

3 files changed

+147
-68
lines changed

src/com/mighty16/json/ui/ClassesListDelegate.java

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,99 @@
66
import javax.swing.*;
77
import javax.swing.event.ListSelectionEvent;
88
import javax.swing.event.ListSelectionListener;
9+
import javax.swing.table.AbstractTableModel;
10+
import java.util.HashMap;
911
import java.util.List;
1012

1113
public class ClassesListDelegate {
1214

13-
private List<ClassModel> classData;
1415
private OnClassSelectedListener listener;
1516

16-
public ClassesListDelegate(JList list, OnClassSelectedListener listener, List<ClassModel> classDataList) {
17-
this.classData = classDataList;
17+
public ClassesListDelegate(JTable list, List<ClassModel> classDataList, HashMap<String, String> classNames, OnClassSelectedListener listener) {
18+
1819
this.listener = listener;
19-
list.setLayoutOrientation(JList.VERTICAL);
20+
2021
if (classDataList.size() == 1) {
2122
list.setVisible(false);
2223
} else {
2324
list.setVisible(true);
2425
}
25-
list.setListData(classDataList.toArray());
26-
list.setSelectedIndex(0);
2726

28-
list.setBorder(BorderFactory.createLineBorder(JBColor.BLACK, 1));
27+
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
28+
29+
list.setModel(new ClassesListModel(classDataList,classNames));
30+
31+
ListSelectionModel selectionModel = list.getSelectionModel();
2932

30-
list.addListSelectionListener(new ListSelectionListener() {
31-
@Override
33+
selectionModel.addListSelectionListener(new ListSelectionListener() {
3234
public void valueChanged(ListSelectionEvent e) {
35+
int selectedIndex = e.getFirstIndex();
36+
3337
if (listener != null) {
34-
listener.onClassSelected(classData.get(list.getSelectedIndex()));
35-
}
38+
listener.onClassSelected(classDataList.get(selectedIndex));
39+
}
40+
3641
}
3742
});
43+
44+
45+
//list.setBorder(BorderFactory.createLineBorder(JBColor.BLACK, 1));
46+
47+
// list.addListSelectionListener(new ListSelectionListener() {
48+
// @Override
49+
// public void valueChanged(ListSelectionEvent e) {
50+
// if (listener != null) {
51+
// listener.onClassSelected(classData.get(list.getSelectedIndex()));
52+
// }
53+
// }
54+
// });
55+
3856
}
3957

4058

4159
public interface OnClassSelectedListener {
4260
void onClassSelected(ClassModel classData);
4361
}
4462

63+
class ClassesListModel extends AbstractTableModel {
64+
65+
private HashMap<String, String> classNames;
66+
private List<ClassModel> classData;
67+
68+
public ClassesListModel(List<ClassModel> classDataList, HashMap<String, String> classNames) {
69+
this.classData = classDataList;
70+
this.classNames = classNames;
71+
}
72+
73+
@Override
74+
public int getRowCount() {
75+
return classData.size();
76+
}
77+
78+
@Override
79+
public int getColumnCount() {
80+
return 1;
81+
}
82+
83+
@Override
84+
public Object getValueAt(int rowIndex, int columnIndex) {
85+
return classNames.get(classData.get(rowIndex).name);
86+
}
87+
88+
@Override
89+
public boolean isCellEditable(int rowIndex, int columnIndex) {
90+
return true;
91+
}
92+
93+
@Override
94+
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
95+
classNames.put(classData.get(rowIndex).name, (String) aValue);
96+
}
97+
98+
@Override
99+
public String getColumnName(int column) {
100+
return "";
101+
}
102+
}
103+
45104
}

src/com/mighty16/json/ui/ModelTableDialog.form

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -58,60 +58,16 @@
5858
<properties/>
5959
<border type="none"/>
6060
<children>
61-
<grid id="ef890" layout-manager="GridLayoutManager" row-count="5" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
61+
<grid id="ef890" layout-manager="GridLayoutManager" row-count="4" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
6262
<margin top="0" left="0" bottom="0" right="0"/>
6363
<constraints border-constraint="Center"/>
6464
<properties/>
6565
<border type="none"/>
6666
<children>
67-
<grid id="53ac0" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
68-
<margin top="0" left="0" bottom="0" right="0"/>
69-
<constraints>
70-
<grid row="1" column="5" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
71-
</constraints>
72-
<properties/>
73-
<border type="line"/>
74-
<children>
75-
<scrollpane id="10af2">
76-
<constraints>
77-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
78-
</constraints>
79-
<properties/>
80-
<border type="none"/>
81-
<children>
82-
<component id="24ad2" class="javax.swing.JTable" binding="fieldsTable">
83-
<constraints/>
84-
<properties>
85-
<autoResizeMode value="4"/>
86-
<fillsViewportHeight value="true"/>
87-
</properties>
88-
</component>
89-
</children>
90-
</scrollpane>
91-
</children>
92-
</grid>
93-
<scrollpane id="bde47">
94-
<constraints>
95-
<grid row="1" column="0" row-span="2" col-span="5" vsize-policy="7" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false">
96-
<preferred-size width="200" height="-1"/>
97-
</grid>
98-
</constraints>
99-
<properties/>
100-
<border type="none"/>
101-
<children>
102-
<component id="68bd" class="javax.swing.JList" binding="list1" default-binding="true">
103-
<constraints/>
104-
<properties>
105-
<minimumSize width="100" height="0"/>
106-
<selectionMode value="0"/>
107-
</properties>
108-
</component>
109-
</children>
110-
</scrollpane>
11167
<grid id="f9566" layout-manager="GridLayoutManager" row-count="1" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
11268
<margin top="0" left="0" bottom="0" right="0"/>
11369
<constraints>
114-
<grid row="3" column="5" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
70+
<grid row="2" column="6" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
11571
</constraints>
11672
<properties/>
11773
<border type="line" title="Annotations"/>
@@ -161,7 +117,7 @@
161117
</grid>
162118
<component id="1ca35" class="javax.swing.JTextField" binding="singleFileNameEdit">
163119
<constraints>
164-
<grid row="4" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="2" use-parent-layout="false">
120+
<grid row="3" column="1" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="2" use-parent-layout="false">
165121
<preferred-size width="150" height="-1"/>
166122
</grid>
167123
</constraints>
@@ -171,28 +127,84 @@
171127
</component>
172128
<component id="28fe6" class="javax.swing.JLabel">
173129
<constraints>
174-
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
130+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
175131
</constraints>
176132
<properties>
177133
<text value="File name"/>
178134
</properties>
179135
</component>
180-
<component id="ca18c" class="javax.swing.JLabel">
136+
<component id="c647e" class="javax.swing.JCheckBox" binding="singleFileCheckbox">
181137
<constraints>
182-
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
138+
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="1" use-parent-layout="false"/>
183139
</constraints>
184140
<properties>
185-
<text value="Label"/>
141+
<text value="Use single file"/>
186142
</properties>
187143
</component>
188-
<component id="c647e" class="javax.swing.JCheckBox" binding="singleFileCheckbox">
144+
<splitpane id="73828">
189145
<constraints>
190-
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="1" use-parent-layout="false"/>
146+
<grid row="1" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
147+
<preferred-size width="200" height="200"/>
148+
</grid>
191149
</constraints>
192150
<properties>
193-
<text value="Use single file"/>
151+
<continuousLayout value="false"/>
194152
</properties>
195-
</component>
153+
<border type="none"/>
154+
<children>
155+
<scrollpane id="10af2">
156+
<constraints>
157+
<splitpane position="right"/>
158+
</constraints>
159+
<properties/>
160+
<border type="none"/>
161+
<children>
162+
<component id="24ad2" class="javax.swing.JTable" binding="fieldsTable">
163+
<constraints/>
164+
<properties>
165+
<autoResizeMode value="4"/>
166+
<fillsViewportHeight value="true"/>
167+
</properties>
168+
</component>
169+
</children>
170+
</scrollpane>
171+
<grid id="1c763" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
172+
<margin top="0" left="0" bottom="0" right="0"/>
173+
<constraints>
174+
<splitpane position="left"/>
175+
</constraints>
176+
<properties>
177+
<minimumSize width="150" height="54"/>
178+
</properties>
179+
<border type="none"/>
180+
<children>
181+
<scrollpane id="fde19">
182+
<constraints>
183+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
184+
</constraints>
185+
<properties/>
186+
<border type="none"/>
187+
<children>
188+
<component id="ce3cc" class="javax.swing.JTable" binding="table1" default-binding="true">
189+
<constraints/>
190+
<properties>
191+
<autoResizeMode value="3"/>
192+
</properties>
193+
</component>
194+
</children>
195+
</scrollpane>
196+
<component id="ca18c" class="javax.swing.JLabel">
197+
<constraints>
198+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
199+
</constraints>
200+
<properties>
201+
<text value="&lt;html&gt;Double click on list item&lt;br&gt;to edit class name&lt;/html&gt;"/>
202+
</properties>
203+
</component>
204+
</children>
205+
</grid>
206+
</children>
207+
</splitpane>
196208
</children>
197209
</grid>
198210
</children>

src/com/mighty16/json/ui/ModelTableDialog.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import javax.swing.*;
1010
import java.awt.event.*;
11+
import java.util.HashMap;
1112
import java.util.List;
1213

1314
public class ModelTableDialog extends JDialog implements ClassesListDelegate.OnClassSelectedListener {
@@ -22,14 +23,14 @@ public class ModelTableDialog extends JDialog implements ClassesListDelegate.OnC
2223
private JButton buttonOK;
2324
private JButton buttonCancel;
2425
private JTable fieldsTable;
25-
private JList list1;
2626
private JRadioButton annotationsNoneButton;
2727
private JRadioButton annotationsGsonButton;
2828
private JCheckBox singleFileCheckbox;
2929
private JTextField singleFileNameEdit;
3030
private JRadioButton annotationsFastJson;
3131
private JRadioButton annotationsMoshi;
3232
private JRadioButton annotationsJackson;
33+
private JTable table1;
3334

3435
private FieldsTableDelegate fieldsTableDelegate;
3536
private ClassesListDelegate classesListDelegate;
@@ -42,7 +43,14 @@ public ModelTableDialog(List<ClassModel> data, LanguageResolver resolver, ModelT
4243
init();
4344
this.data = data;
4445
this.callbacks = callbacks;
45-
classesListDelegate = new ClassesListDelegate(list1, this, data);
46+
47+
HashMap<String,String> classNames = new HashMap<>();
48+
49+
for (ClassModel classModel:data){
50+
classNames.put(classModel.name,classModel.name);
51+
}
52+
53+
classesListDelegate = new ClassesListDelegate(table1, data,classNames,this);
4654
fieldsTableDelegate = new FieldsTableDelegate(fieldsTable, resolver);
4755
fieldsTableDelegate.setFieldsData(data.get(0).fields);
4856
}

0 commit comments

Comments
 (0)