|
|
@@ -22,9 +22,11 @@ import java.util.Properties;
|
|
|
import javax.swing.BoxLayout;
|
|
|
import javax.swing.ButtonGroup;
|
|
|
import javax.swing.JButton;
|
|
|
+import javax.swing.JComboBox;
|
|
|
import javax.swing.JFileChooser;
|
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JLabel;
|
|
|
+import javax.swing.JOptionPane;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JRadioButton;
|
|
|
import javax.swing.JScrollPane;
|
|
|
@@ -38,30 +40,55 @@ public class ToolUI {
|
|
|
|
|
|
private static final String TAG = "ToolUI";
|
|
|
private static final String PROPERTIES_FILE = "setting.properties";
|
|
|
- private final int WIDTH = 550;
|
|
|
- private final int HEIGHT = 350;
|
|
|
+ public static final int WIDTH = 900;
|
|
|
+ public static final int HEIGHT = 700;
|
|
|
|
|
|
+ private final JFrame frame = new JFrame("VAP tool");
|
|
|
private final ButtonGroup group = new ButtonGroup();
|
|
|
- private final JRadioButton btnH265 = new JRadioButton("h265");
|
|
|
private final JRadioButton btnH264 = new JRadioButton("h264");
|
|
|
+ private final JRadioButton btnH265 = new JRadioButton("h265");
|
|
|
private final SpinnerModel modelFps = new SpinnerNumberModel(24, 1, 60, 1);
|
|
|
+ private final Float[] scaleArray = new Float[]{0.5f, 1f};
|
|
|
+ private final JComboBox<Float> boxScale = new JComboBox<>(scaleArray);
|
|
|
private final JTextField textInputPath = new JTextField();
|
|
|
private final JButton btnCreate = new JButton("create VAP");
|
|
|
private final JTextArea txtAreaLog = new JTextArea();
|
|
|
+ private final JTextField textAudioPath = new JTextField();
|
|
|
+ private final JPanel panelAudioPath = new JPanel();
|
|
|
+
|
|
|
private final JLabel labelOutInfo = new JLabel();
|
|
|
private final Dimension labelSize = new Dimension(100, 20);
|
|
|
private final Properties props = new Properties();
|
|
|
+ private final VapxUI vapxUI = new VapxUI();
|
|
|
|
|
|
+ private boolean needAudio = false;
|
|
|
|
|
|
-
|
|
|
- public void run() {
|
|
|
+ public ToolUI() {
|
|
|
TLog.logger = new TLog.ITLog() {
|
|
|
@Override
|
|
|
public void i(String tag, String msg) {
|
|
|
log(tag, msg);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void e(String tag, String msg) {
|
|
|
+ log(tag, "Error:" + msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void w(String tag, String msg) {
|
|
|
+ log(tag, "Warning:" + msg);
|
|
|
+ }
|
|
|
};
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void run() {
|
|
|
createUI();
|
|
|
+ loadProperties();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadProperties() {
|
|
|
try {
|
|
|
File file = new File(PROPERTIES_FILE);
|
|
|
if (!file.exists()) {
|
|
|
@@ -72,12 +99,19 @@ public class ToolUI {
|
|
|
group.setSelected(commonArg.enableH265 ? btnH265.getModel() : btnH264.getModel(), true);
|
|
|
modelFps.setValue(commonArg.fps);
|
|
|
textInputPath.setText(commonArg.inputPath);
|
|
|
+ textAudioPath.setText(commonArg.audioPath);
|
|
|
+ float scale = commonArg.scale;
|
|
|
+ for (int i=0; i<scaleArray.length ; i++) {
|
|
|
+ if (scaleArray[i] == scale) {
|
|
|
+ boxScale.setSelectedIndex(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
- TLog.i(TAG, "ERROR -> " + e.getMessage());
|
|
|
+ TLog.e(TAG, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void runTool() {
|
|
|
txtAreaLog.setText("");
|
|
|
new Thread(new Runnable() {
|
|
|
@@ -86,7 +120,7 @@ public class ToolUI {
|
|
|
try {
|
|
|
runAnimTool();
|
|
|
} catch (Exception e) {
|
|
|
- TLog.i(TAG, "ERROR -> " + e.getMessage());
|
|
|
+ TLog.e(TAG, e.getMessage());
|
|
|
btnCreate.setEnabled(true);
|
|
|
}
|
|
|
}
|
|
|
@@ -112,6 +146,20 @@ public class ToolUI {
|
|
|
commonArg.enableH265 = group.isSelected(btnH265.getModel());
|
|
|
commonArg.fps = (Integer)modelFps.getValue();
|
|
|
commonArg.inputPath = textInputPath.getText();
|
|
|
+ commonArg.scale = scaleArray[boxScale.getSelectedIndex()];
|
|
|
+ if (needAudio) {
|
|
|
+ commonArg.needAudio = true;
|
|
|
+ commonArg.audioPath = textAudioPath.getText();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (vapxUI.isVapxEnable()) {
|
|
|
+ commonArg.isVapx = true;
|
|
|
+ commonArg.srcSet = vapxUI.getSrcSet();
|
|
|
+ if (commonArg.srcSet == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
TLog.i(TAG, commonArg.toString());
|
|
|
|
|
|
AnimTool animTool = new AnimTool();
|
|
|
@@ -122,6 +170,11 @@ public class ToolUI {
|
|
|
labelOutInfo.setText((Math.min(p, 99)) + "%");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onWarning(String msg) {
|
|
|
+ JOptionPane.showMessageDialog(frame, msg, "Warning", JOptionPane.WARNING_MESSAGE);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onError() {
|
|
|
btnCreate.setEnabled(true);
|
|
|
@@ -135,7 +188,7 @@ public class ToolUI {
|
|
|
setProperties(commonArg);
|
|
|
Desktop.getDesktop().open(new File(commonArg.outputPath));
|
|
|
} catch (IOException e) {
|
|
|
- TLog.i(TAG, "ERROR -> " + e.getMessage());
|
|
|
+ TLog.e(TAG, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -145,7 +198,6 @@ public class ToolUI {
|
|
|
}
|
|
|
|
|
|
private void createUI() {
|
|
|
- JFrame frame = new JFrame("VAP tool");
|
|
|
frame.setSize(WIDTH, HEIGHT);
|
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
@@ -166,8 +218,14 @@ public class ToolUI {
|
|
|
panel.add(getCodecLayout());
|
|
|
// fps
|
|
|
panel.add(getFpsLayout());
|
|
|
+ // scale
|
|
|
+ panel.add(getScaleLayout());
|
|
|
// path
|
|
|
panel.add(getPathLayout());
|
|
|
+ // audio path
|
|
|
+ panel.add(getAudioPathLayout());
|
|
|
+ // vapx
|
|
|
+ panel.add(vapxUI.createUI());
|
|
|
// create
|
|
|
panel.add(getCreateLayout());
|
|
|
// log
|
|
|
@@ -187,11 +245,11 @@ public class ToolUI {
|
|
|
|
|
|
JPanel panelRadio = new JPanel();
|
|
|
panelRadio.setLayout(new GridLayout(1, 2));
|
|
|
- panelRadio.add(btnH265);
|
|
|
panelRadio.add(btnH264);
|
|
|
- group.add(btnH265);
|
|
|
+ panelRadio.add(btnH265);
|
|
|
group.add(btnH264);
|
|
|
- group.setSelected(btnH265.getModel(), true);
|
|
|
+ group.add(btnH265);
|
|
|
+ group.setSelected(btnH264.getModel(), true);
|
|
|
panel.add(panelRadio);
|
|
|
|
|
|
return panel;
|
|
|
@@ -209,11 +267,22 @@ public class ToolUI {
|
|
|
return panel;
|
|
|
}
|
|
|
|
|
|
+ private JPanel getScaleLayout() {
|
|
|
+ JPanel panel = new JPanel();
|
|
|
+ panel.setLayout(new FlowLayout(FlowLayout.LEFT));
|
|
|
+ JLabel label = new JLabel("alpha scale");
|
|
|
+ label.setPreferredSize(labelSize);
|
|
|
+ panel.add(label);
|
|
|
+
|
|
|
+ panel.add(boxScale);
|
|
|
+ return panel;
|
|
|
+ }
|
|
|
+
|
|
|
private JPanel getPathLayout() {
|
|
|
JPanel panel = new JPanel();
|
|
|
|
|
|
panel.setLayout(new FlowLayout(FlowLayout.LEFT));
|
|
|
- JLabel label = new JLabel("input path");
|
|
|
+ JLabel label = new JLabel("frames path");
|
|
|
label.setPreferredSize(labelSize);
|
|
|
panel.add(label);
|
|
|
JPanel gPanel = new JPanel();
|
|
|
@@ -222,7 +291,7 @@ public class ToolUI {
|
|
|
BoxLayout layout = new BoxLayout(gPanel, BoxLayout.LINE_AXIS);
|
|
|
gPanel.setLayout(layout);
|
|
|
|
|
|
- textInputPath.setPreferredSize(new Dimension(300,20));
|
|
|
+ textInputPath.setPreferredSize(new Dimension(400,20));
|
|
|
gPanel.add(textInputPath);
|
|
|
|
|
|
JButton btnInputPath = new JButton("choose");
|
|
|
@@ -244,6 +313,55 @@ public class ToolUI {
|
|
|
return panel;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private JPanel getAudioPathLayout() {
|
|
|
+ JPanel panel = new JPanel();
|
|
|
+
|
|
|
+ panel.setLayout(new FlowLayout(FlowLayout.LEFT));
|
|
|
+ JLabel label = new JLabel("audio(mp3)");
|
|
|
+ label.setPreferredSize(labelSize);
|
|
|
+ panel.add(label);
|
|
|
+ panel.add(panelAudioPath);
|
|
|
+ final JLabel labelAudioAction = new JLabel("+");
|
|
|
+ panel.add(labelAudioAction);
|
|
|
+ labelAudioAction.addMouseListener(new MouseAdapter() {
|
|
|
+ @Override
|
|
|
+ public void mouseClicked(MouseEvent mouseEvent) {
|
|
|
+ needAudio = !needAudio;
|
|
|
+ panelAudioPath.setVisible(needAudio);
|
|
|
+ labelAudioAction.setText(needAudio ? "x" : "+");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ BoxLayout layout = new BoxLayout(panelAudioPath, BoxLayout.LINE_AXIS);
|
|
|
+ panelAudioPath.setLayout(layout);
|
|
|
+
|
|
|
+ textAudioPath.setPreferredSize(new Dimension(400,20));
|
|
|
+ panelAudioPath.add(textAudioPath);
|
|
|
+
|
|
|
+ JButton btnInputPath = new JButton("choose");
|
|
|
+ panelAudioPath.add(btnInputPath);
|
|
|
+ btnInputPath.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent actionEvent) {
|
|
|
+ JFileChooser fileChooser = new JFileChooser();
|
|
|
+ fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
|
|
+ int returnVal = fileChooser.showOpenDialog(fileChooser);
|
|
|
+ if(returnVal == JFileChooser.APPROVE_OPTION) {
|
|
|
+ // 文件夹路径
|
|
|
+ String filePath = fileChooser.getSelectedFile().getAbsolutePath();
|
|
|
+ textAudioPath.setText(filePath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!needAudio) {
|
|
|
+ panelAudioPath.setVisible(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ return panel;
|
|
|
+ }
|
|
|
+
|
|
|
private void setOutput(final String path) {
|
|
|
labelOutInfo.setText("<html><font color='blue'>open output</font></html>");
|
|
|
labelOutInfo.addMouseListener(new MouseAdapter() {
|
|
|
@@ -252,7 +370,7 @@ public class ToolUI {
|
|
|
try {
|
|
|
Desktop.getDesktop().open(new File(path));
|
|
|
} catch (IOException e) {
|
|
|
- TLog.i(TAG, "ERROR -> " + e.getMessage());
|
|
|
+ TLog.e(TAG, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -286,7 +404,8 @@ public class ToolUI {
|
|
|
JScrollPane areaScrollPane = new JScrollPane(txtAreaLog);
|
|
|
areaScrollPane.setVerticalScrollBarPolicy(
|
|
|
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
|
|
- areaScrollPane.setPreferredSize(new Dimension(WIDTH, 200));
|
|
|
+ areaScrollPane.setPreferredSize(new Dimension(WIDTH, 100));
|
|
|
+ areaScrollPane.setMinimumSize(new Dimension(WIDTH, 100));
|
|
|
|
|
|
panel.add(areaScrollPane);
|
|
|
panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
|
|
|
@@ -317,25 +436,36 @@ public class ToolUI {
|
|
|
|
|
|
private CommonArg getProperties() {
|
|
|
CommonArg commonArg = new CommonArg();
|
|
|
- String enableH265 = props.getProperty("enableH265", Boolean.TRUE.toString());
|
|
|
- String fps = props.getProperty("fps", "24");
|
|
|
- String inputPath = props.getProperty("inputPath", "");
|
|
|
-
|
|
|
- commonArg.enableH265 = Boolean.TRUE.toString().equals(enableH265);
|
|
|
try {
|
|
|
+ String version = props.getProperty("version", "0");
|
|
|
+ String enableH265 = props.getProperty("enableH265", Boolean.toString(commonArg.enableH265));
|
|
|
+ String fps = props.getProperty("fps", String.valueOf(commonArg.fps));
|
|
|
+ String inputPath = props.getProperty("inputPath", "");
|
|
|
+ String scale = props.getProperty("scale", String.valueOf(scaleArray[0]));
|
|
|
+ String audioPath = props.getProperty("audioPath", "");
|
|
|
+
|
|
|
+ int v = Integer.parseInt(version);
|
|
|
+ // 版本不符直接返回默认值
|
|
|
+ if (v != commonArg.version) return commonArg;
|
|
|
commonArg.fps = Integer.parseInt(fps);
|
|
|
+ commonArg.scale = Float.parseFloat(scale);
|
|
|
+ commonArg.enableH265 = Boolean.TRUE.toString().equals(enableH265);
|
|
|
+ commonArg.inputPath = inputPath;
|
|
|
+ commonArg.audioPath = audioPath;
|
|
|
} catch (Exception e) {
|
|
|
- commonArg.fps = 24;
|
|
|
+ TLog.e(TAG, "getProperties error:" + e.getMessage());
|
|
|
}
|
|
|
- commonArg.inputPath = inputPath;
|
|
|
return commonArg;
|
|
|
}
|
|
|
|
|
|
|
|
|
private void setProperties(CommonArg commonArg) throws IOException {
|
|
|
+ props.setProperty("version", commonArg.version + "");
|
|
|
props.setProperty("enableH265", commonArg.enableH265? Boolean.TRUE.toString() : Boolean.FALSE.toString());
|
|
|
props.setProperty("fps", commonArg.fps + "");
|
|
|
props.setProperty("inputPath", commonArg.inputPath == null ? "" : commonArg.inputPath);
|
|
|
+ props.setProperty("audioPath", commonArg.audioPath == null ? "" : commonArg.audioPath);
|
|
|
+ props.setProperty("scale", commonArg.scale + "");
|
|
|
props.store(new FileOutputStream(PROPERTIES_FILE), "");
|
|
|
}
|
|
|
|