1
- package com .zxzinn .novelai .gui ;
1
+ package com .zxzinn .novelai .gui . generation ;
2
2
3
3
import com .zxzinn .novelai .GenerationState ;
4
4
import com .zxzinn .novelai .api .GenerationRequest ;
5
5
import com .zxzinn .novelai .api .GenerationRequestBuilder ;
6
6
import com .zxzinn .novelai .api .NAIConstants ;
7
- import com .zxzinn .novelai .config .ConfigManager ;
8
7
import com .zxzinn .novelai .event .ImageReceivedEvent ;
9
8
import com .zxzinn .novelai .event .ImageReceivedListener ;
10
9
import com .zxzinn .novelai .event .PromptUpdateEvent ;
11
10
import com .zxzinn .novelai .event .PromptUpdateListener ;
12
11
import com .zxzinn .novelai .gui .common .ImagePreviewPanel ;
13
- import com .zxzinn .novelai .gui .filewindow .FileManagerTab ;
14
- import com .zxzinn .novelai .gui .generation .*;
15
12
import com .zxzinn .novelai .service .ImageGenerationService ;
16
13
import com .zxzinn .novelai .utils .Cache ;
17
14
import com .zxzinn .novelai .utils .I18nManager ;
18
15
import com .zxzinn .novelai .utils .UIComponent ;
19
16
import lombok .Getter ;
20
- import lombok .Setter ;
21
17
import lombok .extern .log4j .Log4j2 ;
22
18
23
19
import javax .swing .*;
24
20
import javax .swing .border .EmptyBorder ;
25
21
import java .awt .*;
26
- import java .awt .event .WindowAdapter ;
27
- import java .awt .event .WindowEvent ;
28
22
import java .awt .image .BufferedImage ;
29
23
import java .util .concurrent .CompletableFuture ;
30
24
31
25
@ Log4j2
32
26
@ Getter
33
- @ Setter
34
- public class MainGUI extends JFrame implements UIComponent , ImageReceivedListener , PromptUpdateListener {
35
- private static final ConfigManager config = ConfigManager .getInstance ();
36
- public static final int WINDOW_WIDTH = config .getInteger ("ui.window.width" );
37
- public static final int WINDOW_HEIGHT = config .getInteger ("ui.window.height" );
38
-
27
+ public class GenerationGUI extends JPanel implements UIComponent , ImageReceivedListener , PromptUpdateListener {
39
28
private volatile boolean isGenerating = false ;
40
29
private final Object generationLock = new Object ();
41
30
42
- private JTabbedPane mainTabbedPane ;
43
31
private PromptPanel promptPanel ;
44
32
private AbstractParametersPanel currentParametersPanel ;
45
33
private GenerationParametersPanel generationParametersPanel ;
46
34
private Img2ImgParametersPanel img2ImgParametersPanel ;
47
35
private ImagePreviewPanel imagePreviewPanel ;
48
36
private HistoryPanel historyPanel ;
49
37
private GenerationControlPanel generationControlPanel ;
50
- private FileManagerTab fileManagerTab ;
51
38
52
39
private JPanel leftPanel ;
53
40
private JPanel parameterPanel ;
@@ -56,34 +43,22 @@ public class MainGUI extends JFrame implements UIComponent , ImageReceivedListen
56
43
private JComboBox <String > actionComboBox ;
57
44
58
45
private final Cache cache ;
59
-
60
46
private final ImageGenerationService imageGenerationService ;
61
-
62
47
private PromptPanel .PromptResult currentPromptResult ;
63
48
64
- public MainGUI () {
49
+ public GenerationGUI () {
65
50
this .cache = Cache .getInstance ();
66
-
67
- setTitle (config .getString ("application.name" ) + " v" + config .getString ("application.version" ));
68
- setSize (WINDOW_WIDTH , WINDOW_HEIGHT );
69
- setLocationRelativeTo (null );
70
-
71
- setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
72
-
73
- imageGenerationService = new ImageGenerationService ();
51
+ this .imageGenerationService = new ImageGenerationService ();
74
52
75
53
initializeComponents ();
76
54
layoutComponents ();
77
55
bindEvents ();
78
- setupWindowListener ();
79
56
80
- log .info ("MainGUI initialized" );
57
+ log .info ("GenerationGUI initialized" );
81
58
}
82
59
83
60
@ Override
84
61
public void initializeComponents () {
85
- mainTabbedPane = new JTabbedPane ();
86
-
87
62
promptPanel = new PromptPanel ();
88
63
promptPanel .addPromptUpdateListener (this );
89
64
@@ -96,8 +71,6 @@ public void initializeComponents() {
96
71
97
72
generationControlPanel = new GenerationControlPanel ();
98
73
99
- fileManagerTab = new FileManagerTab ();
100
-
101
74
leftPanel = new JPanel (new BorderLayout ());
102
75
parameterPanel = new JPanel (new BorderLayout ());
103
76
cardLayout = new CardLayout ();
@@ -125,14 +98,8 @@ public void layoutComponents() {
125
98
generatorPanel .add (new JScrollPane (imagePreviewPanel ), BorderLayout .CENTER );
126
99
generatorPanel .add (historyPanel , BorderLayout .EAST );
127
100
128
- JPanel mainGeneratorPanel = new JPanel (new BorderLayout ());
129
- mainGeneratorPanel .add (generatorPanel , BorderLayout .CENTER );
130
- mainGeneratorPanel .add (leftPanel , BorderLayout .WEST );
131
-
132
- mainTabbedPane .addTab (I18nManager .getString ("tab.generator" ), mainGeneratorPanel );
133
- mainTabbedPane .addTab (I18nManager .getString ("tab.fileManager" ), fileManagerTab );
134
-
135
- add (mainTabbedPane , BorderLayout .CENTER );
101
+ add (generatorPanel , BorderLayout .CENTER );
102
+ add (leftPanel , BorderLayout .WEST );
136
103
}
137
104
138
105
@ Override
@@ -144,7 +111,7 @@ public void bindEvents() {
144
111
145
112
private void startImageGeneration () {
146
113
if (isGenerating ) {
147
- log .info ("已經在生成圖像中, 忽略新的請求" );
114
+ log .info ("已經在生成圖像中, 忽略新的請求" );
148
115
return ;
149
116
}
150
117
@@ -224,7 +191,7 @@ public void onImageReceived(ImageReceivedEvent event) {
224
191
imageGenerationService .saveImage (image , outputDir );
225
192
226
193
log .info ("圖像處理完成" );
227
- if (!promptPanel .isLocked ()){
194
+ if (!promptPanel .isLocked ()) {
228
195
refreshPromptPreview ();
229
196
}
230
197
@@ -273,26 +240,17 @@ private void switchPanel(AbstractParametersPanel newPanel, String cardName) {
273
240
repaint ();
274
241
}
275
242
276
- private void setupWindowListener () {
277
- addWindowListener (new WindowAdapter () {
278
- @ Override
279
- public void windowClosing (WindowEvent e ) {
280
- log .info ("Application closing" );
281
- saveAllCache ();
282
- fileManagerTab .shutdownFileWatcher ();
283
- promptPanel .getPreviewManager ().shutdown ();
284
- log .info ("Application closed" );
285
- }
286
- });
287
- }
288
-
289
- private void saveAllCache () {
243
+ public void saveAllCache () {
290
244
promptPanel .saveToCache ();
291
245
currentParametersPanel .saveToCache ();
292
- fileManagerTab .saveWatchedFolders ();
293
246
cache .setParameter ("action" , (String ) actionComboBox .getSelectedItem ());
294
247
cache .saveCache ();
295
- log .info ("Cache saved" );
248
+ log .info ("Generation GUI cache saved" );
249
+ }
250
+
251
+ public void shutdown () {
252
+ promptPanel .getPreviewManager ().shutdown ();
253
+ log .info ("Generation GUI shutdown completed" );
296
254
}
297
255
298
256
@ Override
0 commit comments