• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jiangxincode / ApkToolBoxGUI / #1276

25 Oct 2025 01:00PM UTC coverage: 2.853% (-0.04%) from 2.89%
#1276

push

jiangxincode
[New Feature]Pictures to Pdf converter

0 of 111 new or added lines in 3 files covered. (0.0%)

1 existing line in 1 file now uncovered.

248 of 8693 relevant lines covered (2.85%)

0.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/edu/jiangxin/apktoolbox/pdf/pic2pdf/Pic2PdfPanel.java
1
package edu.jiangxin.apktoolbox.pdf.pic2pdf;
2

3
import edu.jiangxin.apktoolbox.pdf.PdfUtils;
4
import edu.jiangxin.apktoolbox.swing.extend.EasyPanel;
5
import edu.jiangxin.apktoolbox.swing.extend.FileListPanel;
6
import edu.jiangxin.apktoolbox.swing.extend.filepanel.FilePanel;
7
import edu.jiangxin.apktoolbox.utils.Constants;
8
import edu.jiangxin.apktoolbox.utils.FileUtils;
9

10
import javax.swing.*;
11
import java.awt.event.ActionEvent;
12
import java.awt.event.ActionListener;
13
import java.io.File;
14
import java.io.Serial;
15
import java.util.List;
16
import java.util.Set;
17
import java.util.TreeSet;
18
import java.util.concurrent.ExecutorService;
19
import java.util.concurrent.Executors;
20

NEW
21
public class Pic2PdfPanel  extends EasyPanel {
×
22
    @Serial
23
    private static final long serialVersionUID = 1L;
24

25
    private FileListPanel fileListPanel;
26

27
    private JCheckBox isRecursiveSearched;
28

29
    private FilePanel targetDirPanel;
30

31
    private JButton startButton;
32
    private JButton cancelButton;
33

34
    private transient WorkderThread convertThread;
35

36
    @Override
37
    public void initUI() {
NEW
38
        BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
×
NEW
39
        setLayout(boxLayout);
×
40

NEW
41
        createInputPanel();
×
NEW
42
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
43

NEW
44
        createOutputPanel();
×
NEW
45
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
46

NEW
47
        createOptionPanel();
×
NEW
48
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
49

NEW
50
        createOperationPanel();
×
NEW
51
    }
×
52

53
    private void createInputPanel() {
NEW
54
        fileListPanel = new FileListPanel();
×
NEW
55
        fileListPanel.initialize();
×
NEW
56
        add(fileListPanel);
×
NEW
57
    }
×
58

59
    private void createOutputPanel() {
NEW
60
        targetDirPanel = new FilePanel("Target Directory");
×
NEW
61
        targetDirPanel.initialize();
×
NEW
62
        targetDirPanel.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
×
NEW
63
        add(targetDirPanel);
×
NEW
64
    }
×
65

66
    private void createOptionPanel() {
NEW
67
        JPanel optionPanel = new JPanel();
×
NEW
68
        optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.X_AXIS));
×
NEW
69
        optionPanel.setBorder(BorderFactory.createTitledBorder("Options"));
×
70

NEW
71
        isRecursiveSearched = new JCheckBox("Recursive Search");
×
NEW
72
        isRecursiveSearched.setSelected(true);
×
NEW
73
        optionPanel.add(isRecursiveSearched);
×
NEW
74
        optionPanel.add(Box.createHorizontalGlue());
×
75

NEW
76
        add(optionPanel);
×
NEW
77
    }
×
78

79
    private void createOperationPanel() {
NEW
80
        JPanel operationPanel = new JPanel();
×
NEW
81
        operationPanel.setLayout(new BoxLayout(operationPanel, BoxLayout.X_AXIS));
×
NEW
82
        operationPanel.setBorder(BorderFactory.createTitledBorder("Operations"));
×
83

NEW
84
        startButton = new JButton("Start");
×
NEW
85
        cancelButton = new JButton("Cancel");
×
NEW
86
        cancelButton.setEnabled(false);
×
NEW
87
        startButton.addActionListener(new OperationButtonActionListener());
×
NEW
88
        cancelButton.addActionListener(new OperationButtonActionListener());
×
NEW
89
        operationPanel.add(startButton);
×
NEW
90
        operationPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
NEW
91
        operationPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
NEW
92
        operationPanel.add(cancelButton);
×
NEW
93
        operationPanel.add(Box.createHorizontalGlue());
×
94

NEW
95
        add(operationPanel);
×
NEW
96
    }
×
97

98
    private void processFile(File encryptedFile, File targetDir) {
99
        try {
NEW
100
            if (Thread.currentThread().isInterrupted()) {
×
NEW
101
                return;
×
102
            }
NEW
103
            PdfUtils.removePasswordWithIText(encryptedFile, targetDir);
×
NEW
104
        } catch (Throwable t) {
×
NEW
105
            logger.error("Process file failed: {}", encryptedFile.getAbsolutePath(), t);
×
NEW
106
        }
×
NEW
107
    }
×
108

NEW
109
    class OperationButtonActionListener implements ActionListener {
×
110
        @Override
111
        public void actionPerformed(ActionEvent e) {
NEW
112
            Object source = e.getSource();
×
NEW
113
            if (source.equals(startButton)) {
×
NEW
114
                startButton.setEnabled(false);
×
NEW
115
                cancelButton.setEnabled(true);
×
NEW
116
                convertThread = new WorkderThread(isRecursiveSearched.isSelected());
×
NEW
117
                convertThread.start();
×
NEW
118
            } else if (source.equals(cancelButton)) {
×
NEW
119
                startButton.setEnabled(true);
×
NEW
120
                cancelButton.setEnabled(false);
×
NEW
121
                if (convertThread.isAlive()) {
×
NEW
122
                    convertThread.interrupt();
×
NEW
123
                    convertThread.executorService.shutdownNow();
×
124
                }
125
            }
126

NEW
127
        }
×
128
    }
129

130
    class WorkderThread extends Thread {
131
        public final ExecutorService executorService;
132
        private final boolean isRecursiveSearched;
133

NEW
134
        public WorkderThread(boolean isRecursiveSearched) {
×
NEW
135
            super();
×
NEW
136
            this.isRecursiveSearched = isRecursiveSearched;
×
NEW
137
            this.executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
×
NEW
138
        }
×
139

140
        @Override
141
        public void run() {
142
            try {
NEW
143
                List<File> fileList = fileListPanel.getFileList();
×
NEW
144
                Set<File> fileSet = new TreeSet<>();
×
NEW
145
                String[] extensions = new String[]{"jpg", "jpeg", "png"};
×
NEW
146
                for (File file : fileList) {
×
NEW
147
                    fileSet.addAll(FileUtils.listFiles(file, extensions, isRecursiveSearched));
×
NEW
148
                }
×
149

NEW
150
                PdfUtils.imagesToPdf(fileSet, new File(targetDirPanel.getFile(), "result.pdf"));
×
NEW
151
            } catch (Exception e) {
×
NEW
152
                logger.error("Remove process failed", e);
×
153
            } finally {
NEW
154
                executorService.shutdown();
×
NEW
155
                SwingUtilities.invokeLater(() -> {
×
NEW
156
                    startButton.setEnabled(true);
×
NEW
157
                    cancelButton.setEnabled(false);
×
NEW
158
                });
×
159
            }
NEW
160
        }
×
161
    }
162
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc