OSDN Git Service

NG設定パネルを別クラス化
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / NgRegisterPanel.java
1 package yukihane.inqubus.gui;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import javax.swing.DefaultListModel;
6 import javax.swing.GroupLayout;
7 import javax.swing.JButton;
8 import javax.swing.JList;
9 import javax.swing.JPanel;
10 import javax.swing.JScrollPane;
11 import javax.swing.JTextField;
12 import javax.swing.LayoutStyle.ComponentPlacement;
13
14 /**
15  *
16  * @author yuki
17  */
18 class NgRegisterPanel extends JPanel {
19     private static final long serialVersionUID = 1L;
20     private final DefaultListModel<String> mdlNgWord = new DefaultListModel<>();
21     private final JList<String> lstNgWord = new JList<>();
22     private final JTextField fldNgWord = new JTextField();
23     private final JButton btnNgWordAdd = new JButton("追加");
24     private final JButton btnNgWordDel = new JButton("削除");
25
26     NgRegisterPanel() {
27         final JScrollPane scrNgWord = new JScrollPane();
28         lstNgWord.setModel(mdlNgWord);
29         scrNgWord.setViewportView(lstNgWord);
30
31
32         GroupLayout gl_pnlNgWord = new GroupLayout(this);
33         setLayout(gl_pnlNgWord);
34         gl_pnlNgWord.setHorizontalGroup(
35             gl_pnlNgWord.createParallelGroup(GroupLayout.Alignment.LEADING)
36             .addGroup(gl_pnlNgWord.createSequentialGroup()
37                 .addContainerGap()
38                 .addGroup(gl_pnlNgWord.createParallelGroup(GroupLayout.Alignment.LEADING)
39                     .addComponent(scrNgWord, GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)
40                     .addGroup(gl_pnlNgWord.createSequentialGroup()
41                         .addComponent(fldNgWord, GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
42                         .addPreferredGap(ComponentPlacement.RELATED)
43                         .addComponent(btnNgWordAdd)
44                         .addGap(18, 18, 18)
45                         .addComponent(btnNgWordDel)))
46                 .addContainerGap())
47         );
48         gl_pnlNgWord.setVerticalGroup(
49             gl_pnlNgWord.createParallelGroup(GroupLayout.Alignment.LEADING)
50             .addGroup(gl_pnlNgWord.createSequentialGroup()
51                 .addComponent(scrNgWord, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
52                 .addPreferredGap(ComponentPlacement.RELATED)
53                 .addGroup(gl_pnlNgWord.createParallelGroup(GroupLayout.Alignment.BASELINE)
54                     .addComponent(fldNgWord, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
55                     .addComponent(btnNgWordDel)
56                     .addComponent(btnNgWordAdd))
57                 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
58         );
59
60     }
61
62     void init(List<String> ngWords) {
63         for (String s : ngWords) {
64             mdlNgWord.addElement(s);
65         }
66     }
67
68     List<String> getAllElements() {
69         List<String> res = new ArrayList<>(mdlNgWord.getSize());
70         for (int i = 0; i < mdlNgWord.getSize(); i++) {
71             res.add(mdlNgWord.get(i));
72         }
73         return res;
74     }
75 }