|
| 1 | +/* |
| 2 | + * Copyright 2022 Enaium |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package cn.enaium.joe.dialog; |
| 18 | + |
| 19 | +import cn.enaium.joe.JavaOctetEditor; |
| 20 | +import cn.enaium.joe.task.AbstractTask; |
| 21 | +import org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair; |
| 22 | + |
| 23 | +import javax.swing.*; |
| 24 | +import java.awt.*; |
| 25 | +import java.util.concurrent.CompletableFuture; |
| 26 | +import java.util.concurrent.Executors; |
| 27 | +import java.util.concurrent.ScheduledExecutorService; |
| 28 | +import java.util.concurrent.TimeUnit; |
| 29 | + |
| 30 | +/** |
| 31 | + * @author Enaium |
| 32 | + * @since 0.10.0 |
| 33 | + */ |
| 34 | +public class TaskDialog extends Dialog { |
| 35 | + public TaskDialog() { |
| 36 | + super("TaskList"); |
| 37 | + setSize(300, 400); |
| 38 | + setLayout(new BorderLayout()); |
| 39 | + JList<AbstractTask<?>> comp = new JList<>(); |
| 40 | + comp.setCellRenderer((list, value, index, isSelected, cellHasFocus) -> new JProgressBar() {{ |
| 41 | + setValue(value.getProgress()); |
| 42 | + setStringPainted(true); |
| 43 | + setString(String.format("%s:%s", value.getName(), value.getProgress()) + "%"); |
| 44 | + }}); |
| 45 | + add(new JScrollPane(comp), BorderLayout.CENTER); |
| 46 | + ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1); |
| 47 | + scheduledExecutorService.scheduleAtFixedRate(() -> { |
| 48 | + SwingUtilities.invokeLater(() -> { |
| 49 | + DefaultListModel<AbstractTask<?>> abstractTaskDefaultListModel = new DefaultListModel<>(); |
| 50 | + for (Pair<AbstractTask<?>, CompletableFuture<?>> abstractTaskCompletableFuturePair : JavaOctetEditor.getInstance().task.getTask()) { |
| 51 | + abstractTaskDefaultListModel.addElement(abstractTaskCompletableFuturePair.getFirst()); |
| 52 | + } |
| 53 | + comp.setModel(abstractTaskDefaultListModel); |
| 54 | + }); |
| 55 | + }, 1, 1, TimeUnit.MILLISECONDS); |
| 56 | + } |
| 57 | +} |
0 commit comments