Skip to content

Commit

Permalink
修复无法预览搜索框的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxuqaq committed Feb 3, 2023
1 parent 4b658ff commit 89fca93
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
16 changes: 8 additions & 8 deletions src/main/java/file/engine/frames/SearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class SearchBar {
private final AtomicBoolean isMergeThreadExist = new AtomicBoolean();
private volatile boolean isStartMerge = false;
private final AtomicBoolean isRoundRadiusSet = new AtomicBoolean();
private static final AtomicBoolean isPreviewMode = new AtomicBoolean();
private final AtomicBoolean isPreviewMode = new AtomicBoolean();
private final AtomicBoolean isTutorialMode = new AtomicBoolean();
private final AtomicBoolean isSwitchToNormalManual = new AtomicBoolean();
private Border fullBorder;
Expand Down Expand Up @@ -130,13 +130,13 @@ public class SearchBar {
private final JMenuItem openLast;
private int lastMousePositionX = 0;
private int lastMousePositionY = 0;
private final String PLUGIN_RESULT_SPLITTER_STR = "-@-@-";
private static final String PLUGIN_RESULT_SPLITTER_STR = "-@-@-";
private static final int SEND_PREPARE_SEARCH_TIMEOUT = 350; //毫秒(ms)
private static final int SEND_START_SEARCH_TIMEOUT = 500; //ms
private static final int SHOW_RESULTS_TIMEOUT = 500; //ms
private static final float SEARCH_BAR_WIDTH_RATIO = 0.3f;
private static final float SEARCH_BAR_HEIGHT_RATIO = 0.4f;
private final float TEXT_FIELD_HEIGHT_RATIO = 0.7f;
private static final float TEXT_FIELD_HEIGHT_RATIO = 0.7f;

private static volatile SearchBar instance = null;

Expand Down Expand Up @@ -278,7 +278,7 @@ private void initGUI() {
}

/**
* 插件返回的结果为plugin[pluginResultSplitStr]pluginIdentifier-result
* 插件返回的结果为plugin[pluginResultSplitStr]pluginIdentifier[pluginResultSplitStr]result
*
* @param res 结果
* @return 以pluginResultSplitStr分开的字符串
Expand Down Expand Up @@ -2715,10 +2715,10 @@ static class IsStartTimeSet {

@EventRegister(registerClass = PreviewSearchBarEvent.class)
private static void previewSearchBarEvent(Event event) {
if (isPreviewMode.get()) {
SearchBar searchBar = getInstance();
if (searchBar.isPreviewMode.get()) {
EventManagement eventManagement = EventManagement.getInstance();
PreviewSearchBarEvent preview = (PreviewSearchBarEvent) event;
SearchBar searchBar = getInstance();
searchBar.setBorderColor(preview.borderType, preview.borderColor, preview.borderThickness);
searchBar.setSearchBarColor(preview.searchBarColor);
searchBar.setDefaultBackgroundColor(preview.defaultBackgroundColor);
Expand Down Expand Up @@ -2756,12 +2756,12 @@ private static void previewSearchBarEvent(Event event) {

@EventRegister(registerClass = StartPreviewEvent.class)
private static void startPreviewEvent(Event event) {
isPreviewMode.set(true);
getInstance().isPreviewMode.set(true);
}

@EventRegister(registerClass = StopPreviewEvent.class)
private static void stopPreviewEvent(Event event) {
isPreviewMode.set(false);
getInstance().isPreviewMode.set(false);
IsStartTimeSet.isStartTimeSet.set(false);
}

Expand Down
32 changes: 21 additions & 11 deletions src/main/java/file/engine/frames/SettingsFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

public class SettingsFrame {
private Set<String> cacheSet;
private boolean isFramePrepared = false;
private volatile boolean isFramePrepared = false;
private boolean isSuffixChanged = false;
private static volatile int tmp_copyPathKeyCode;
private static volatile int tmp_runAsAdminKeyCode;
Expand All @@ -91,7 +91,7 @@ public class SettingsFrame {
private static final TranslateService translateService = TranslateService.getInstance();
private static final EventManagement eventManagement = EventManagement.getInstance();
private static final AllConfigs allConfigs = AllConfigs.getInstance();
private static final ThreadPoolUtil THREAD_POOL_UTIL = ThreadPoolUtil.getInstance();
private static final ThreadPoolUtil threadPoolUtil = ThreadPoolUtil.getInstance();
private final HashMap<TabNameAndTitle, Component> tabComponentNameMap = new HashMap<>();
private Map<String, String> cudaDeviceMap = new HashMap<>();
private HashMap<String, Integer> suffixMap;
Expand Down Expand Up @@ -382,7 +382,7 @@ private void addButtonRemoveDesktopListener() {
}
int isConfirmed = JOptionPane.showConfirmDialog(frame, translateService.getTranslation("Whether to remove and backup all files on the desktop," + "they will be in the program's Files folder, which may take a few minutes"));
if (isConfirmed == JOptionPane.YES_OPTION) {
Future<Boolean> future = THREAD_POOL_UTIL.executeTask(MoveDesktopFilesUtil::start, true);
Future<Boolean> future = threadPoolUtil.executeTask(MoveDesktopFilesUtil::start, true);
try {
if (future == null) {
return;
Expand Down Expand Up @@ -641,7 +641,7 @@ private void addCheckForUpdateButtonListener() {
downloadManager.newJar = new DownloadManager((String) updateInfo.get("url64"), Constants.FILE_NAME, new File("tmp").getAbsolutePath());
downloadManager.newLauncher = new DownloadManager((String) updateInfo.get("urlLauncher"), Constants.LAUNCH_WRAPPER_NAME, new File("tmp").getAbsolutePath());
eventManagement.putEvent(new StartDownloadEvent(downloadManager.newLauncher));
THREAD_POOL_UTIL.executeTask(() -> {
threadPoolUtil.executeTask(() -> {
try {
if (!downloadManager.newLauncher.waitFor(10 * 60 * 1000)) {
return;
Expand All @@ -654,7 +654,7 @@ private void addCheckForUpdateButtonListener() {
}
});
eventManagement.putEvent(new StartDownloadEvent(downloadManager.newJar));
THREAD_POOL_UTIL.executeTask(() -> {
threadPoolUtil.executeTask(() -> {
boolean isDownloadSuccess = SetDownloadProgress.setProgress(labelDownloadProgress,
buttonCheckUpdate,
downloadManager.newLauncher,
Expand Down Expand Up @@ -745,6 +745,7 @@ private void addResetColorButtonListener() {
* @param max 最大值
* @return boolean
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean canParseInteger(String str, int min, int max) {
try {
int ret = Integer.parseInt(str);
Expand Down Expand Up @@ -812,7 +813,7 @@ private void setColorChooserLabel(Color color, JLabel label) {
* 实时监测textField中保存的颜色信息,并尝试更新label
*/
private void addColorChooserLabelListener() {
THREAD_POOL_UTIL.executeTask(() -> {
threadPoolUtil.executeTask(() -> {
try {
Color labelColor;
Color fontColorWithCoverage;
Expand Down Expand Up @@ -1074,7 +1075,7 @@ private void addButtonVacuumListener() {
System.out.println("开始优化");
}
eventManagement.putEvent(new OptimiseDatabaseEvent());
THREAD_POOL_UTIL.executeTask(() -> {
threadPoolUtil.executeTask(() -> {
//实时显示VACUUM状态
try {
DatabaseService instance = DatabaseService.getInstance();
Expand Down Expand Up @@ -1995,7 +1996,7 @@ private void addButtonPreviewListener() {
buttonPreviewColor.addActionListener(e -> {
PreviewStatus.isPreview = true;
eventManagement.putEvent(new StartPreviewEvent());
THREAD_POOL_UTIL.executeTask(() -> {
threadPoolUtil.executeTask(() -> {
try {
String borderColor;
String searchBarColor;
Expand All @@ -2016,7 +2017,16 @@ private void addButtonPreviewListener() {
defaultBackgroundColor = textFieldBackgroundDefault.getText();
borderThickness = textFieldBorderThickness.getText();
borderType = (Constants.Enums.BorderType) comboBoxBorderType.getSelectedItem();
if (canParseToRGB(borderColor) && canParseToRGB(searchBarColor) && canParseToRGB(searchBarFontColor) && canParseToRGB(labelColor) && canParseToRGB(fontColorCoverage) && canParseToRGB(fontColor) && canParseToRGB(defaultBackgroundColor) && canParseInteger(borderThickness, 1, 5)) {
if (
canParseToRGB(borderColor) &&
canParseToRGB(searchBarColor) &&
canParseToRGB(searchBarFontColor) &&
canParseToRGB(labelColor) &&
canParseToRGB(fontColorCoverage) &&
canParseToRGB(fontColor) &&
canParseToRGB(defaultBackgroundColor) &&
canParseFloat(borderThickness, 0, 4)
) {
eventManagement.putEvent(new PreviewSearchBarEvent(borderColor, searchBarColor, searchBarFontColor, labelColor, fontColorCoverage, fontColor, defaultBackgroundColor, borderType, borderThickness));
}
TimeUnit.SECONDS.sleep(1);
Expand Down Expand Up @@ -2502,7 +2512,7 @@ private void addButtonPluginUpdateCheckListener() {
eventManagement.putEvent(new StartDownloadEvent(downloadManagerContainer.downloadManager));
pluginInfoMap.put(pluginName, downloadManagerContainer.downloadManager);
DownloadManager finalDownloadManager = downloadManagerContainer.downloadManager;
THREAD_POOL_UTIL.executeTask(() ->
threadPoolUtil.executeTask(() ->
SetDownloadProgress.setProgress(labelProgress,
buttonUpdatePlugin,
finalDownloadManager,
Expand Down Expand Up @@ -3149,7 +3159,7 @@ private static void showSettingsFrameEvent(Event event) {
} else {
settingsFrame.showWindow(showSettingsFrameEvent.showTabName);
}
THREAD_POOL_UTIL.executeTask(() -> {
threadPoolUtil.executeTask(() -> {
try {
final long startVisible = System.currentTimeMillis();
while (SettingsFrame.frame.isVisible() || System.currentTimeMillis() - startVisible < 3000) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/file/engine/services/DatabaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,7 @@ private static void updateDatabaseEvent(Event event) {
}

@EventRegister(registerClass = OptimiseDatabaseEvent.class)
private static void optimiseDatabaseEvent(Event event) {
private static void optimizeDatabaseEvent(Event event) {
DatabaseService databaseService = getInstance();
if (databaseService.status.get() == Constants.Enums.DatabaseStatus._TEMP) {
return;
Expand All @@ -1991,7 +1991,8 @@ private static void optimiseDatabaseEvent(Event event) {
throw new RuntimeException("databaseService status设置VACUUM状态失败");
}
//执行VACUUM命令
for (String eachDisk : RegexUtil.comma.split(AllConfigs.getInstance().getAvailableDisks())) {
String[] splitDisks = RegexUtil.comma.split(AllConfigs.getInstance().getAvailableDisks());
for (String eachDisk : splitDisks) {
try (Statement stmt = SQLiteUtil.getStatement(String.valueOf(eachDisk.charAt(0)))) {
stmt.execute("VACUUM;");
} catch (Exception ex) {
Expand Down

0 comments on commit 89fca93

Please sign in to comment.