最古版。新版→https://osdn.jp/users/tacticsrealize/pf/ChlorophyllUploader/wiki/FrontPage
修订版 | 1cf0aedfcb141906f76f9bae13db90e53798f6c0 (tree) |
---|---|
时间 | 2015-07-14 18:35:18 |
作者 | MirrgieRiana Kurilab |
Commiter | MirrgieRiana Kurilab |
FrameSelectPort: new時の処理が重いのを解決。キャンセル時のイベント追加
@@ -10,7 +10,6 @@ | ||
10 | 10 | import java.util.function.Consumer; |
11 | 11 | |
12 | 12 | import javax.swing.JButton; |
13 | -import javax.swing.JFrame; | |
14 | 13 | import javax.swing.JList; |
15 | 14 | import javax.swing.JScrollPane; |
16 | 15 |
@@ -23,14 +22,16 @@ | ||
23 | 22 | |
24 | 23 | private JList<NamedSlot<CommPortIdentifier>> list; |
25 | 24 | private Consumer<CommPortIdentifier> consumer; |
25 | + private boolean isCanceled = true; | |
26 | 26 | |
27 | - public FrameSelectPort(Consumer<CommPortIdentifier> consumer) | |
27 | + public FrameSelectPort( | |
28 | + Consumer<CommPortIdentifier> consumer, | |
29 | + Runnable onCanceled) | |
28 | 30 | { |
29 | 31 | super("ポート選択"); |
30 | 32 | |
31 | 33 | this.consumer = consumer; |
32 | 34 | |
33 | - JFrame frame = this; | |
34 | 35 | { |
35 | 36 | |
36 | 37 | list = new JList<>(); |
@@ -93,14 +94,22 @@ | ||
93 | 94 | GroupLayoutUtil groupLayoutUtil = new GroupLayoutUtil(); |
94 | 95 | |
95 | 96 | groupLayoutUtil.setComponents(compos); |
96 | - groupLayoutUtil.setGroupLayoutTo(frame.getContentPane()); | |
97 | + groupLayoutUtil.setGroupLayoutTo(getContentPane()); | |
97 | 98 | |
98 | 99 | groupLayoutUtil.getGroupLayout().setAutoCreateContainerGaps(true); |
99 | 100 | groupLayoutUtil.getGroupLayout().setAutoCreateGaps(true); |
100 | 101 | } |
101 | 102 | } |
102 | 103 | |
103 | - redraw(list); | |
104 | + onOpened(e -> { | |
105 | + redraw(list); | |
106 | + }); | |
107 | + | |
108 | + onClosed(e -> { | |
109 | + if (isCanceled) { | |
110 | + onCanceled.run(); | |
111 | + } | |
112 | + }); | |
104 | 113 | |
105 | 114 | prepareFrame(); |
106 | 115 | } |
@@ -110,6 +119,7 @@ | ||
110 | 119 | NamedSlot<CommPortIdentifier> portIdentifier = list.getSelectedValue(); |
111 | 120 | if (portIdentifier != null) { |
112 | 121 | if (portIdentifier.get() != null) { |
122 | + isCanceled = false; | |
113 | 123 | dispose(); |
114 | 124 | consumer.accept(portIdentifier.get()); |
115 | 125 | } |
@@ -20,7 +20,11 @@ | ||
20 | 20 | { |
21 | 21 | System.loadLibrary("rxtxSerial"); |
22 | 22 | HSwing.setWindowsLookAndFeel(); |
23 | - new FrameSelectPort(Main::main2).setVisible(true); | |
23 | + new FrameSelectPort(Main::main2, () -> { | |
24 | + | |
25 | + // TODO | |
26 | + | |
27 | + }).setVisible(true); | |
24 | 28 | } |
25 | 29 | |
26 | 30 | private static void main2(CommPortIdentifier portIdentifier) |