/
Context.java
123 lines (103 loc) · 3.61 KB
/
Context.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright 2003-2012 Yusuke Yamamoto
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package samurai.swing;
import samurai.util.Configuration;
import samurai.util.CustomizableKeyStroke;
import samurai.util.ExecuteThread;
import samurai.util.GUIResourceBundle;
import samurai.util.Task;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import java.awt.Component;
public class Context {
private static GUIResourceBundle resources = GUIResourceBundle.getInstance();
private final Configuration config = new Configuration("samurai");
private final FileHistory fileHistory = new FileHistory(config);
private LocalProcesses localProcesses = null;
private final CustomizableKeyStroke keyStroke = new CustomizableKeyStroke(resources);
ExecuteThread executeThread = new ExecuteThread();
private final JLabel statusBar;
private TileTabPanel<SamuraiPanel> tab;
private SearchPanel searchPanel;
public Context(JLabel statusBar, TileTabPanel<SamuraiPanel> tab) {
this.statusBar = statusBar;
this.tab = tab;
this.searchPanel = new SearchPanel(this);
this.resources.inject(searchPanel);
this.config.apply(searchPanel);
try {
this.localProcesses = new LocalProcesses(config, fileHistory);
}catch(java.lang.NoClassDefFoundError toolsJarNotFound){
}
executeThread.start();
}
public SearchPanel getSearchPanel() {
return searchPanel;
}
public Configuration getConfig() {
return this.config;
}
public LocalProcesses getLocalProcesses() {
return this.localProcesses;
}
public FileHistory getFileHistory() {
return this.fileHistory;
}
public void setIcon(ImageIcon icon, JComponent component) {
for (int i = 0; i < tab.getComponentSize(); i++) {
Component theComponent = tab.getComponentAt(i);
if (component == theComponent) {
tab.setIconAt(i, icon);
break;
}
}
}
public void setText(String text, JComponent component) {
for (int i = 0; i < tab.getComponentSize(); i++) {
Component theComponent = tab.getComponentAt(i);
if (component == theComponent) {
tab.setTitleAt(i, text);
break;
}
}
}
public void setTemporaryStatus(String temporaryStatus) {
this.statusBar.setText(temporaryStatus);
executeThread.invokeLater(new Task() {
public void execute() {
setStatusBar();
}
}, 2);
}
private String statusText = "";
public void setStatusBar() {
this.statusBar.setText(statusText);
}
public void setStatus(String text) {
this.statusText = text;
setStatusBar();
}
public void invokeLater(Task task) {
executeThread.addTask(task);
}
public void invokeLater(Task task, int delaySecs) {
executeThread.invokeLater(task, delaySecs);
}
public CustomizableKeyStroke getKeyStroke() {
return this.keyStroke;
}
}