MCPcopy Create free account
hub / github.com/XUANXUQAQ/File-Engine / initGUI

Method initGUI

src/main/java/file/engine/frames/SearchBar.java:206–277  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

204 }
205
206 private void initGUI() {
207 var screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕大小
208 int width = screenSize.width;
209 int height = screenSize.height;
210 int searchBarWidth = (int) (width * SEARCH_BAR_WIDTH_RATIO);
211 int searchBarHeight = (int) (height * SEARCH_BAR_HEIGHT_RATIO);
212 final int positionX = width / 2 - searchBarWidth / 2;
213 final int positionY = height / 2 - searchBarHeight / 3;
214 final Color transparentColor = new Color(0, 0, 0, 0);
215 AllConfigs allConfigs = AllConfigs.getInstance();
216 var configs = allConfigs.getConfigEntity();
217 searchBarColor = new Color(configs.getSearchBarColor());
218 labelColor = new Color(configs.getLabelColor());
219 fontColorWithCoverage = new Color(configs.getFontColorWithCoverage());
220 backgroundColor = new Color(configs.getDefaultBackgroundColor());
221 labelFontColor = new Color(configs.getFontColor());
222 initBorder(allConfigs.getBorderType(), new Color(configs.getBorderColor()), configs.getBorderThickness());
223
224 initFrame(positionX, positionY, searchBarWidth, searchBarHeight);
225
226 int labelHeight = searchBarHeight / 9;
227 int textFieldHeight = (int) (labelHeight * TEXT_FIELD_HEIGHT_RATIO);
228 //TextField
229 textField = new JTextField(1000);
230 textField.setSize(searchBarWidth, textFieldHeight);
231 Font textFieldFont = new Font(Font.SANS_SERIF, Font.PLAIN, getTextFieldFontSizeByTextFieldHeight());
232 textField.setFont(textFieldFont);
233 textField.setForeground(Color.BLACK);
234 textField.setHorizontalAlignment(JTextField.LEFT);
235 textField.setBackground(Color.WHITE);
236 textField.setLocation(0, 0);
237 textField.setOpaque(true);
238
239 //labels
240 final Font labelFont = new Font(Font.SANS_SERIF, Font.BOLD, getLabelFontSizeBySearchBarHeight());
241 searchInfoLabel = new JLabel();
242 searchInfoLabel.setHorizontalAlignment(SwingConstants.CENTER);
243
244 int searchInfoHeight = labelHeight - textFieldHeight;
245 initLabel(labelFont, searchBarWidth, searchInfoHeight, textFieldHeight, searchInfoLabel);
246 initLabel(labelFont, searchBarWidth, labelHeight, labelHeight, label1);
247 initLabel(labelFont, searchBarWidth, labelHeight, labelHeight * 2, label2);
248 initLabel(labelFont, searchBarWidth, labelHeight, labelHeight * 3, label3);
249 initLabel(labelFont, searchBarWidth, labelHeight, labelHeight * 4, label4);
250 initLabel(labelFont, searchBarWidth, labelHeight, labelHeight * 5, label5);
251 initLabel(labelFont, searchBarWidth, labelHeight, labelHeight * 6, label6);
252 initLabel(labelFont, searchBarWidth, labelHeight, labelHeight * 7, label7);
253 initLabel(labelFont, searchBarWidth, labelHeight, labelHeight * 8, label8);
254
255 iconSideLength = labelHeight / 3; //定义图标边长
256
257 URL icon = this.getClass().getResource("/icons/taskbar_32x32.png");
258 if (icon != null) {
259 Image image = new ImageIcon(icon).getImage();
260 searchBar.setIconImage(image);
261 }
262 //panel
263 searchBarContentPane.setDoubleBuffered(true);

Callers 1

SearchBarMethod · 0.95

Calls 8

getInstanceMethod · 0.95
initBorderMethod · 0.95
getBorderTypeMethod · 0.95
initFrameMethod · 0.95
initLabelMethod · 0.95
getConfigEntityMethod · 0.80

Tested by

no test coverage detected