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

Method showTaskBar

src/main/java/file/engine/frames/TaskBar.java:133–184  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

131 }
132
133 private void showTaskBar() {
134 // 判断是否支持系统托盘
135 if (SystemTray.isSupported()) {
136 Image image;
137 URL icon;
138 systemTray = SystemTray.getSystemTray();
139 EventManagement eventManagement = EventManagement.getInstance();
140 // 创建托盘图标
141 icon = TaskBar.class.getResource("/icons/taskbar.png");
142 if (icon != null) {
143 image = new ImageIcon(icon).getImage();
144 trayIcon = new TrayIcon(image);
145 } else {
146 throw new RuntimeException("初始化图片失败/icons/taskbar.png");
147 }
148 // 添加工具提示文本
149 if (IsDebug.isDebug()) {
150 trayIcon.setToolTip("File-Engine(Debug)");
151 } else {
152 trayIcon.setToolTip("File-Engine," + TranslateService.getInstance().getTranslation("Double click to open settings"));
153 }
154 // 为托盘图标加弹出菜单
155
156 trayIcon.addMouseListener(new MouseAdapter() {
157
158 @Override
159 public void mouseClicked(MouseEvent e) {
160 if (MouseEvent.BUTTON1 == e.getButton() && e.getClickCount() == 2) {
161 eventManagement.putEvent(new ShowSettingsFrameEvent());
162 }
163 }
164
165 @Override
166 public void mouseReleased(MouseEvent e) {
167 if (e.isPopupTrigger()) {
168 popupMenu = getPopupMenu();
169 popupMenu.setInvoker(popupMenu);
170 popupMenu.setVisible(true);
171 double dpi = DpiUtil.getDpi();
172 popupMenu.setLocation((int) (e.getX() / dpi), (int) ((e.getY() - popupMenu.getHeight()) / dpi));
173 }
174 }
175 });
176 // 获得系统托盘对象
177 try {
178 // 为系统托盘加托盘图标
179 systemTray.add(trayIcon);
180 } catch (AWTException e) {
181 log.error("error: {}", e.getMessage(), e);
182 }
183 }
184 }
185
186 /**
187 * 创建弹出菜单

Callers 1

TaskBarMethod · 0.95

Calls 5

getInstanceMethod · 0.95
isDebugMethod · 0.95
getInstanceMethod · 0.95
getTranslationMethod · 0.80
getMessageMethod · 0.80

Tested by

no test coverage detected