From a65f31cae6adc96e132711954f9d8c9704b096bb Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Wed, 29 Dec 2021 17:06:40 -0400 Subject: [PATCH 1/7] Refactor --- src/main/java/core/MainApp.java | 970 ++++++++++++++++---------------- 1 file changed, 476 insertions(+), 494 deletions(-) diff --git a/src/main/java/core/MainApp.java b/src/main/java/core/MainApp.java index 55898df..9969c9e 100644 --- a/src/main/java/core/MainApp.java +++ b/src/main/java/core/MainApp.java @@ -1,69 +1,55 @@ package core; -import java.awt.EventQueue; - -import javax.swing.JFrame; -import javax.swing.JTabbedPane; -import java.awt.Color; -import java.awt.Component; -import java.awt.Container; - -import javax.swing.text.BadLocationException; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyledDocument; - import com.formdev.flatlaf.extras.FlatSVGIcon; import com.google.common.base.Stopwatch; - -import org.lwjgl.PointerBuffer; -import org.lwjgl.system.MemoryUtil; -import org.lwjgl.util.nfd.NativeFileDialog; - -import javax.swing.JPanel; -import javax.swing.JScrollPane; - +import static core.Utils.SCARLET; +import static core.Utils.write; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Toolkit; +import java.io.File; +import java.net.URL; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.concurrent.ExecutionException; import javax.swing.AbstractButton; -import javax.swing.BoxLayout; -import javax.swing.ButtonGroup; -import javax.swing.JSplitPane; -import java.awt.BorderLayout; -import javax.swing.JTextPane; -import javax.swing.JRadioButton; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.SwingWorker; -import javax.swing.UIManager; -import javax.swing.WindowConstants; -import javax.swing.JSeparator; import javax.swing.Icon; import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.SwingWorker; +import javax.swing.UIManager; +import org.lwjgl.PointerBuffer; +import org.lwjgl.system.MemoryUtil; +import org.lwjgl.util.nfd.NativeFileDialog; +import static org.lwjgl.util.nfd.NativeFileDialog.NFD_PathSet_Free; +import static org.lwjgl.util.nfd.NativeFileDialog.NFD_PathSet_GetCount; +import static org.lwjgl.util.nfd.NativeFileDialog.NFD_PathSet_GetPath; +import org.lwjgl.util.nfd.NFDPathSet; -import java.awt.Dimension; -import javax.swing.JButton; +public class MainApp extends javax.swing.JFrame { -import java.awt.Toolkit; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.io.File; -import java.util.Enumeration; -import java.util.concurrent.TimeUnit; + public static MainApp window; + private String savePath; + private final ArrayList loadPaths = new ArrayList<>(); + private FlatSVGIcon startSVG, loadSVG, loadOkSVG, saveSVG, saveOkSVG; + private Icon whiteLoadingGIF, blackLoadingGIF; -public class MainApp { - //[0]=Button Name, [1]=Algorithm, [2]=Scale private static final String ES = "espcn", - ED = "edsr", - FS = "fsrcnn", - LA = "lapsrn"; - private static final String[][] MODES = { + ED = "edsr", + FS = "fsrcnn", + LA = "lapsrn"; + + private static final String[][] MODES = { {"ESPCNx2", ES, "2"}, // 0 {"ESPCNx3", ES, "3"}, // 1 {"ESPCNx4", ES, "4"}, // 2 {"EDSRx2", ED, "2"}, // 3 - {"EDSRx3", ED, "3"}, // 4 - {"EDSRx4", ED, "4"}, // 5 + {"EDSRx3", ED, "3"}, // 4 + {"EDSRx4", ED, "4"}, // 5 {"FSRCNNx2", FS, "2"}, // 6 {"FSRCNNx3", FS, "3"}, // 7 {"FSRCNNx4", FS, "4"}, // 8 @@ -71,466 +57,444 @@ public class MainApp { {"LapSRNx4", LA, "4"}, // 10 {"LapSRNx8", LA, "8"} // 11 }; - public static final Color SVGBLUE = new Color(115, 208, 244), - SCARLET = new Color(255, 36, 0), - LIGHT = new Color(194,236,255), - DARK = new Color(17,19,19); - private JFrame frame; - private JSplitPane upperSplitPane; - private JTextPane console; - private JTabbedPane tabbedPane; - - private ButtonGroup mode; - - private JButton startButton, - loadButton, - saveButton; - private JRadioButton btnLapSRNx8; - private final Icon whiteLoadingGIF, - blackLoadingGIF; - - private FlatSVGIcon startSVG, - loadSVG, - loadOkSVG, - saveSVG, - saveOkSVG; - private MouseAdapter skinChanger; - private String loadPath, - savePath; - - private long clickTimer = 0; - - - private static MainApp window; - - public String[] getPath () { - return new String[]{loadPath, savePath}; + public MainApp() { + uiCode(); + initComponents(); + uiActions(); + redrawCounter(); } - /** - * Launch the application. - * - * @wbp.parser.entryPoint - */ - public static void main (String[] args) { + public static void main(String[] args) { EventQueue.invokeLater(() -> { try { - window = new MainApp(); - window.setSelected(); - window.startTabbedPanel(); - window.frame.setVisible(true); - window.console.grabFocus(); + java.awt.EventQueue.invokeLater(() -> { + window = new MainApp(); + window.setVisible(true); + Utils.attach(window); + }); } catch (Exception e) { - e.printStackTrace(); } }); } - public MainApp () { + private void uiCode() { JFrame.setDefaultLookAndFeelDecorated(true); //custom window decoration - setSkin(false); UIManager.put("TabbedPane.showTabSeparators", true); - whiteLoadingGIF = new ImageIcon(MainApp.class.getClassLoader().getResource("loadingWHITE.gif")); - blackLoadingGIF = new ImageIcon(MainApp.class.getClassLoader().getResource("loadingBLACK.gif")); - initialize(); - } - - private void initialize () { - frame = new JFrame(); - frame.setIconImage((new ImageIcon(MainApp.class.getClassLoader().getResource("Icon.png")).getImage())); - frame.setAutoRequestFocus(true); - frame.setMinimumSize(new Dimension(500, 180)); - frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.X_AXIS)); - //set default appearance to middle of the screen + URL _url = MainApp.class.getClassLoader().getResource("loadingWHITE.gif"); + URL _url2 = MainApp.class.getClassLoader().getResource("loadingBLACK.gif"); + if (_url != null) { + whiteLoadingGIF = new ImageIcon(_url); + } + if (_url2 != null) { + blackLoadingGIF = new ImageIcon(_url2); + } + Utils.setSkin(false); + URL _url3 = MainApp.class.getClassLoader().getResource("Icon.png"); + if (_url3 != null) { + setIconImage((new ImageIcon(_url3).getImage())); + } + setTitle("PNG Upscaler v1.0.1"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - frame.setLocation((screenSize.width - frame.getBounds().width) / 2, - (screenSize.height - frame.getBounds().height) / 2); + setLocation((screenSize.width - getBounds().width) / 2, + (screenSize.height - getBounds().height) / 2); + startSVG = new FlatSVGIcon("start.svg", 36, 36, ClassLoader.getSystemClassLoader()); + loadSVG = new FlatSVGIcon("load.svg", 36, 36, ClassLoader.getSystemClassLoader()); + loadOkSVG = new FlatSVGIcon("loadOK.svg", 36, 36, ClassLoader.getSystemClassLoader()); + saveOkSVG = new FlatSVGIcon("saveOK.svg", 36, 36, ClassLoader.getSystemClassLoader()); + saveSVG = new FlatSVGIcon("save.svg", 36, 36, ClassLoader.getSystemClassLoader()); + } - mode = new ButtonGroup(); + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + mode = new javax.swing.ButtonGroup(); + mainSplitPane = new javax.swing.JSplitPane(); + upperSplitPanel = new javax.swing.JSplitPane(); + jPanel1 = new javax.swing.JPanel(); + button_start = new javax.swing.JButton(); + button_import = new javax.swing.JButton(); + button_export_folder = new javax.swing.JButton(); + tabbedPane = new javax.swing.JTabbedPane(); + ESPCNpanel = new javax.swing.JPanel(); + jSeparator1 = new javax.swing.JSeparator(); + btnESPCNx2 = new javax.swing.JRadioButton(); + jSeparator2 = new javax.swing.JSeparator(); + btnESPCNx3 = new javax.swing.JRadioButton(); + jSeparator3 = new javax.swing.JSeparator(); + btnESPCNx4 = new javax.swing.JRadioButton(); + jSeparator4 = new javax.swing.JSeparator(); + EDSRpanel = new javax.swing.JPanel(); + jSeparator5 = new javax.swing.JSeparator(); + btnESPCNx5 = new javax.swing.JRadioButton(); + jSeparator6 = new javax.swing.JSeparator(); + btnESPCNx6 = new javax.swing.JRadioButton(); + jSeparator7 = new javax.swing.JSeparator(); + btnESPCNx7 = new javax.swing.JRadioButton(); + jSeparator8 = new javax.swing.JSeparator(); + FSRCNNpanel = new javax.swing.JPanel(); + jSeparator9 = new javax.swing.JSeparator(); + btnESPCNx8 = new javax.swing.JRadioButton(); + jSeparator10 = new javax.swing.JSeparator(); + btnESPCNx9 = new javax.swing.JRadioButton(); + jSeparator11 = new javax.swing.JSeparator(); + btnESPCNx10 = new javax.swing.JRadioButton(); + jSeparator12 = new javax.swing.JSeparator(); + LapSRNpanel = new javax.swing.JPanel(); + jSeparator13 = new javax.swing.JSeparator(); + btnESPCNx11 = new javax.swing.JRadioButton(); + jSeparator14 = new javax.swing.JSeparator(); + btnESPCNx12 = new javax.swing.JRadioButton(); + jSeparator15 = new javax.swing.JSeparator(); + btnESPCNx13 = new javax.swing.JRadioButton(); + jSeparator16 = new javax.swing.JSeparator(); + jPanel3 = new javax.swing.JPanel(); + jScrollPane1 = new javax.swing.JScrollPane(); + console = new javax.swing.JTextPane(); + jPanel2 = new javax.swing.JPanel(); + item_counter = new javax.swing.JTextPane(); + button_remove_items = new javax.swing.JButton(); + button_change_theme = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setMinimumSize(new java.awt.Dimension(500, 180)); + setPreferredSize(new java.awt.Dimension(640, 480)); + getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.X_AXIS)); + + mainSplitPane.setDividerLocation(90); + mainSplitPane.setDividerSize(4); + mainSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); + mainSplitPane.setMinimumSize(new java.awt.Dimension(315, 75)); + + upperSplitPanel.setDividerLocation(300); + + jPanel1.setLayout(new java.awt.GridLayout()); + + button_start.setIcon(startSVG); + button_start.setText("Start"); + button_start.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + button_start.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + jPanel1.add(button_start); + + button_import.setIcon(loadSVG); + button_import.setText("Import Files"); + button_import.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + button_import.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + jPanel1.add(button_import); + + button_export_folder.setIcon(startSVG); + button_export_folder.setText("Export Folder"); + button_export_folder.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + button_export_folder.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + jPanel1.add(button_export_folder); + + upperSplitPanel.setRightComponent(jPanel1); + + tabbedPane.setMinimumSize(new java.awt.Dimension(255, 75)); + + ESPCNpanel.setToolTipText(""); + ESPCNpanel.setLayout(new javax.swing.BoxLayout(ESPCNpanel, javax.swing.BoxLayout.X_AXIS)); + ESPCNpanel.add(jSeparator1); - JSplitPane mainSplitPane = new JSplitPane(); - mainSplitPane.setEnabled(true); - mainSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); - mainSplitPane.setResizeWeight(0.55); + mode.add(btnESPCNx2); + btnESPCNx2.setText("x2"); + btnESPCNx2.setToolTipText("Upscale the image x2"); + btnESPCNx2.setActionCommand(MODES[0][0]); + btnESPCNx2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + ESPCNpanel.add(btnESPCNx2); + ESPCNpanel.add(jSeparator2); - frame.getContentPane().add(mainSplitPane); - //console - console = new JTextPane(); - console.setEditable(false); - console.setMinimumSize(new Dimension(150, 100)); - skinChanger = new MouseAdapter() { - @Override - public void mousePressed (MouseEvent e) { - if (clickTimer == 0) { - clickTimer = System.currentTimeMillis(); - return; - } - if (System.currentTimeMillis() - clickTimer < 600) - SwingUtilities.invokeLater(() -> setSkin(true)); + mode.add(btnESPCNx3); + btnESPCNx3.setText("x3"); + btnESPCNx3.setToolTipText("Upscale the image x3"); + btnESPCNx3.setActionCommand(MODES[1][0]); + btnESPCNx3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + ESPCNpanel.add(btnESPCNx3); + ESPCNpanel.add(jSeparator3); - clickTimer = 0; - } - }; - console.addMouseListener(skinChanger); + mode.add(btnESPCNx4); + btnESPCNx4.setText("x4"); + btnESPCNx4.setToolTipText("Upscale the image x4"); + btnESPCNx4.setActionCommand(MODES[2][0]); + btnESPCNx4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + ESPCNpanel.add(btnESPCNx4); + ESPCNpanel.add(jSeparator4); + + tabbedPane.addTab("ESPCN", ESPCNpanel); + + EDSRpanel.setToolTipText(""); + EDSRpanel.setLayout(new javax.swing.BoxLayout(EDSRpanel, javax.swing.BoxLayout.X_AXIS)); + EDSRpanel.add(jSeparator5); + + mode.add(btnESPCNx5); + btnESPCNx5.setText("x2"); + btnESPCNx5.setToolTipText("Upscale the image x2"); + btnESPCNx5.setActionCommand(MODES[3][0]); + btnESPCNx5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + EDSRpanel.add(btnESPCNx5); + EDSRpanel.add(jSeparator6); + + mode.add(btnESPCNx6); + btnESPCNx6.setText("x3"); + btnESPCNx6.setToolTipText("Upscale the image x3"); + btnESPCNx6.setActionCommand(MODES[4][0]); + btnESPCNx6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + EDSRpanel.add(btnESPCNx6); + EDSRpanel.add(jSeparator7); + + mode.add(btnESPCNx7); + btnESPCNx7.setText("x4"); + btnESPCNx7.setToolTipText("Upscale the image x4"); + btnESPCNx7.setActionCommand(MODES[5][0]); + btnESPCNx7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + EDSRpanel.add(btnESPCNx7); + EDSRpanel.add(jSeparator8); + + tabbedPane.addTab("EDSR", EDSRpanel); + + FSRCNNpanel.setToolTipText(""); + FSRCNNpanel.setLayout(new javax.swing.BoxLayout(FSRCNNpanel, javax.swing.BoxLayout.X_AXIS)); + FSRCNNpanel.add(jSeparator9); + + mode.add(btnESPCNx8); + btnESPCNx8.setText("x2"); + btnESPCNx8.setToolTipText("Upscale the image x2"); + btnESPCNx8.setActionCommand(MODES[6][0]); + btnESPCNx8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + FSRCNNpanel.add(btnESPCNx8); + FSRCNNpanel.add(jSeparator10); + + mode.add(btnESPCNx9); + btnESPCNx9.setText("x3"); + btnESPCNx9.setToolTipText("Upscale the image x3"); + btnESPCNx9.setActionCommand(MODES[7][0]); + btnESPCNx9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + FSRCNNpanel.add(btnESPCNx9); + FSRCNNpanel.add(jSeparator11); + + mode.add(btnESPCNx10); + btnESPCNx10.setText("x4"); + btnESPCNx10.setToolTipText("Upscale the image x4"); + btnESPCNx10.setActionCommand(MODES[8][0]); + btnESPCNx10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + FSRCNNpanel.add(btnESPCNx10); + FSRCNNpanel.add(jSeparator12); + + tabbedPane.addTab("FSRCNN", FSRCNNpanel); + + LapSRNpanel.setToolTipText(""); + LapSRNpanel.setLayout(new javax.swing.BoxLayout(LapSRNpanel, javax.swing.BoxLayout.X_AXIS)); + LapSRNpanel.add(jSeparator13); + + mode.add(btnESPCNx11); + btnESPCNx11.setText("x2"); + btnESPCNx11.setToolTipText("Upscale the image x2"); + btnESPCNx11.setActionCommand(MODES[9][0]); + btnESPCNx11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + LapSRNpanel.add(btnESPCNx11); + LapSRNpanel.add(jSeparator14); + + mode.add(btnESPCNx12); + btnESPCNx12.setText("x3"); + btnESPCNx12.setToolTipText("Upscale the image x3"); + btnESPCNx12.setActionCommand(MODES[10][0]); + btnESPCNx12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + LapSRNpanel.add(btnESPCNx12); + LapSRNpanel.add(jSeparator15); + + mode.add(btnESPCNx13); + btnESPCNx13.setText("x4"); + btnESPCNx13.setToolTipText("Upscale the image x4"); + btnESPCNx13.setActionCommand(MODES[11][0]); + btnESPCNx13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + LapSRNpanel.add(btnESPCNx13); + LapSRNpanel.add(jSeparator16); + + tabbedPane.addTab("LapSRN", LapSRNpanel); + + upperSplitPanel.setLeftComponent(tabbedPane); + + mainSplitPane.setTopComponent(upperSplitPanel); + + jPanel3.setLayout(new java.awt.BorderLayout()); + + jScrollPane1.setMinimumSize(new java.awt.Dimension(1, 1)); - JScrollPane scrollPane = new JScrollPane(console); - scrollPane.setMinimumSize(new Dimension(150, 100)); - mainSplitPane.setRightComponent(scrollPane); + console.setEditable(false); + console.setMinimumSize(new java.awt.Dimension(150, 100)); + jScrollPane1.setViewportView(console); - upperSplitPane = new JSplitPane(); - upperSplitPane.setMinimumSize(new Dimension(400, 90)); - upperSplitPane.setEnabled(false); - upperSplitPane.setResizeWeight(1.0); - mainSplitPane.setLeftComponent(upperSplitPane); + jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER); - JSplitPane leftSplitPane = new JSplitPane(); - mainSplitPane.setMinimumSize(new Dimension(315, 75)); - leftSplitPane.setEnabled(false); - leftSplitPane.setResizeWeight(0.7); - upperSplitPane.setLeftComponent(leftSplitPane); + jPanel2.setMinimumSize(new java.awt.Dimension(0, 0)); + jPanel2.setPreferredSize(new java.awt.Dimension(10, 20)); + jPanel2.setLayout(new java.awt.GridBagLayout()); - tabbedPane = new JTabbedPane(SwingConstants.TOP); - tabbedPane.setMinimumSize(new Dimension(255, 75)); - leftSplitPane.setLeftComponent(tabbedPane); + item_counter.setEnabled(false); + item_counter.setMinimumSize(new java.awt.Dimension(200, 20)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 1.0; + jPanel2.add(item_counter, gridBagConstraints); - JPanel ESPCNpanel = new JPanel(); - tabbedPane.addTab("ESPCN", null, ESPCNpanel, null); - ESPCNpanel.setLayout(new BoxLayout(ESPCNpanel, BoxLayout.X_AXIS)); + button_remove_items.setLabel("Remove all items"); + button_remove_items.setMinimumSize(new java.awt.Dimension(160, 20)); + jPanel2.add(button_remove_items, new java.awt.GridBagConstraints()); - JSeparator separator = new JSeparator(); - ESPCNpanel.add(separator); + button_change_theme.setLabel("Theme"); + button_change_theme.setMinimumSize(new java.awt.Dimension(100, 20)); + jPanel2.add(button_change_theme, new java.awt.GridBagConstraints()); - JRadioButton btnESPCNx2 = new JRadioButton("x2"); - btnESPCNx2.setActionCommand(MODES[0][0]); - mode.add(btnESPCNx2); - btnESPCNx2.setToolTipText("x2"); - ESPCNpanel.add(btnESPCNx2); - btnESPCNx2.setHorizontalAlignment(SwingConstants.CENTER); + jPanel3.add(jPanel2, java.awt.BorderLayout.PAGE_END); - JSeparator s1 = new JSeparator(); - ESPCNpanel.add(s1); + mainSplitPane.setRightComponent(jPanel3); - JRadioButton btnESPCNx3 = new JRadioButton("x3"); - btnESPCNx3.setActionCommand(MODES[1][0]); - mode.add(btnESPCNx3); - btnESPCNx3.setToolTipText("x3"); - ESPCNpanel.add(btnESPCNx3); - btnESPCNx3.setHorizontalAlignment(SwingConstants.CENTER); + getContentPane().add(mainSplitPane); - JSeparator s2 = new JSeparator(); - ESPCNpanel.add(s2); + pack(); + }// - JRadioButton btnESPCNx4 = new JRadioButton("x4"); - btnESPCNx4.setActionCommand(MODES[2][0]); - mode.add(btnESPCNx4); - btnESPCNx4.setToolTipText("x4"); - ESPCNpanel.add(btnESPCNx4); - btnESPCNx4.setHorizontalAlignment(SwingConstants.CENTER); - - JSeparator s3 = new JSeparator(); - ESPCNpanel.add(s3); - - JPanel EDSRpanel = new JPanel(); - tabbedPane.addTab("EDSR", null, EDSRpanel, null); - EDSRpanel.setLayout(new BoxLayout(EDSRpanel, BoxLayout.X_AXIS)); - - JSeparator s4 = new JSeparator(); - EDSRpanel.add(s4); - - JRadioButton btnEDSRx2 = new JRadioButton("x2"); - btnEDSRx2.setActionCommand(MODES[3][0]); - mode.add(btnEDSRx2); - btnEDSRx2.setToolTipText("x2"); - btnEDSRx2.setHorizontalAlignment(SwingConstants.CENTER); - EDSRpanel.add(btnEDSRx2); - - JSeparator s5 = new JSeparator(); - EDSRpanel.add(s5); - - JRadioButton btnEDSRx3 = new JRadioButton("x3"); - btnEDSRx3.setActionCommand(MODES[4][0]); - mode.add(btnEDSRx3); - btnEDSRx3.setToolTipText("x3"); - btnEDSRx3.setHorizontalAlignment(SwingConstants.CENTER); - EDSRpanel.add(btnEDSRx3); - - JSeparator s6 = new JSeparator(); - EDSRpanel.add(s6); - - JRadioButton btnEDSRx4 = new JRadioButton("x4"); - btnEDSRx4.setActionCommand(MODES[5][0]); - mode.add(btnEDSRx4); - btnEDSRx4.setToolTipText("x4"); - btnEDSRx4.setHorizontalAlignment(SwingConstants.CENTER); - EDSRpanel.add(btnEDSRx4); - - JSeparator s7 = new JSeparator(); - EDSRpanel.add(s7); - - JPanel FSRCNNpanel = new JPanel(); - tabbedPane.addTab("FSRCNN", null, FSRCNNpanel, null); - FSRCNNpanel.setLayout(new BoxLayout(FSRCNNpanel, BoxLayout.X_AXIS)); - - JSeparator s8 = new JSeparator(); - FSRCNNpanel.add(s8); - - JRadioButton btnFSRCNNx2 = new JRadioButton("x2"); - btnFSRCNNx2.setActionCommand(MODES[6][0]); - mode.add(btnFSRCNNx2); - btnFSRCNNx2.setToolTipText("x2"); - btnFSRCNNx2.setHorizontalAlignment(SwingConstants.CENTER); - FSRCNNpanel.add(btnFSRCNNx2); - - JSeparator s9 = new JSeparator(); - FSRCNNpanel.add(s9); - - JRadioButton btnFSRCNNx3 = new JRadioButton("x3"); - btnFSRCNNx3.setActionCommand(MODES[7][0]); - mode.add(btnFSRCNNx3); - btnFSRCNNx3.setToolTipText("x3"); - btnFSRCNNx3.setHorizontalAlignment(SwingConstants.CENTER); - FSRCNNpanel.add(btnFSRCNNx3); - - JSeparator s10 = new JSeparator(); - FSRCNNpanel.add(s10); - - JRadioButton btnFSRCNNx4 = new JRadioButton("x4"); - btnFSRCNNx4.setActionCommand(MODES[8][0]); - mode.add(btnFSRCNNx4); - btnFSRCNNx4.setVerticalAlignment(SwingConstants.TOP); - btnFSRCNNx4.setToolTipText("x4"); - btnFSRCNNx4.setHorizontalAlignment(SwingConstants.CENTER); - FSRCNNpanel.add(btnFSRCNNx4); - - JSeparator s11 = new JSeparator(); - FSRCNNpanel.add(s11); - - JPanel LapSRNpanel = new JPanel(); - tabbedPane.addTab("LapSRN", null, LapSRNpanel, null); - LapSRNpanel.setLayout(new BoxLayout(LapSRNpanel, BoxLayout.X_AXIS)); - - JSeparator s12 = new JSeparator(); - LapSRNpanel.add(s12); - - JRadioButton btnLapSRNx2 = new JRadioButton("x2"); - btnLapSRNx2.setActionCommand(MODES[9][0]); - mode.add(btnLapSRNx2); - btnLapSRNx2.setToolTipText("x2"); - btnLapSRNx2.setHorizontalAlignment(SwingConstants.CENTER); - LapSRNpanel.add(btnLapSRNx2); - - JSeparator s13 = new JSeparator(); - LapSRNpanel.add(s13); - - JRadioButton btnLapSRNx4 = new JRadioButton("x4"); - btnLapSRNx4.setActionCommand(MODES[10][0]); - mode.add(btnLapSRNx4); - btnLapSRNx4.setToolTipText("x4"); - btnLapSRNx4.setHorizontalAlignment(SwingConstants.CENTER); - LapSRNpanel.add(btnLapSRNx4); - - JSeparator s14 = new JSeparator(); - LapSRNpanel.add(s14); - - btnLapSRNx8 = new JRadioButton("x8"); - btnLapSRNx8.setActionCommand(MODES[11][0]); - mode.add(btnLapSRNx8); - btnLapSRNx8.setVerticalAlignment(SwingConstants.TOP); - btnLapSRNx8.setToolTipText("x8"); - btnLapSRNx8.setHorizontalAlignment(SwingConstants.CENTER); - LapSRNpanel.add(btnLapSRNx8); - - JSeparator s15 = new JSeparator(); - LapSRNpanel.add(s15); - - JPanel startPanel = new JPanel(); - startPanel.setMinimumSize(new Dimension(70, 75)); - leftSplitPane.setRightComponent(startPanel); - startPanel.setLayout(new BorderLayout(0, 0)); - startSVG = new FlatSVGIcon("start.svg", 36, 36, ClassLoader.getSystemClassLoader()); - startButton = new JButton("Start", startSVG); - startButton.setVerticalTextPosition(SwingConstants.BOTTOM); - startButton.setHorizontalTextPosition(SwingConstants.CENTER); - startButton.addActionListener(e -> { - if (loadPath != null) + private void uiActions() { + button_start.addActionListener(e -> { + if (!loadPaths.isEmpty()) { createWorker().execute(); - else - write("Load File First !", SCARLET); + } else { + write("No images are in queue, add some by clicking 'Import Files'", SCARLET); + } + }); + button_import.addActionListener((e) -> { + NFDPathSet pathSet = NFDPathSet.calloc(); + switch (NativeFileDialog.NFD_OpenDialogMultiple("png", null, pathSet)) { + case NativeFileDialog.NFD_OKAY -> { + long count = NFD_PathSet_GetCount(pathSet); + for (long i = 0; i < count; i++) { + String path = NFD_PathSet_GetPath(pathSet, i); + loadPaths.add(path); + write("Added file: " + path, null); + } + NFD_PathSet_Free(pathSet); + button_import.setIcon(loadOkSVG); + redrawCounter(); + } + case NativeFileDialog.NFD_CANCEL -> write("Canceled Image Selection", null); + default -> // NFD_ERROR + write("Error: %s%n" + NativeFileDialog.NFD_GetError(), SCARLET); + } + }); + button_export_folder.addActionListener((e) -> { + PointerBuffer path = MemoryUtil.memAllocPointer(1); + switch (NativeFileDialog.NFD_PickFolder((ByteBuffer) null, path)) { + case NativeFileDialog.NFD_OKAY -> { + savePath = path.getStringUTF8(0); + write("Export Folder set to:" + savePath, null); + MemoryUtil.memFree(path); + button_export_folder.setIcon(saveOkSVG); + } + case NativeFileDialog.NFD_CANCEL -> write("Canceled Save Location Selection", null); + default -> // NFD_ERROR + write("Error: %s%n" + NativeFileDialog.NFD_GetError(), SCARLET); + } + }); + + button_remove_items.addActionListener((e) -> { + loadPaths.clear(); + redrawCounter(); + Utils.write("All items in queue have been removed!", null); + }); + + button_change_theme.addActionListener((e) -> { + Utils.setSkin(true); }); - startPanel.add(startButton, BorderLayout.CENTER); - - JSplitPane rightSplitPane = new JSplitPane(); - rightSplitPane.setMinimumSize(new Dimension(120, 75)); - rightSplitPane.setResizeWeight(0.5); - upperSplitPane.setRightComponent(rightSplitPane); - - JPanel loadPanel = new JPanel(); - rightSplitPane.setLeftComponent(loadPanel); - loadPanel.setLayout(new BorderLayout(0, 0)); - loadPanel.setMinimumSize(new Dimension(60, 75)); - - loadSVG = new FlatSVGIcon("load.svg", 36, 36, ClassLoader.getSystemClassLoader()); - loadOkSVG = new FlatSVGIcon("loadOK.svg", 36, 36, ClassLoader.getSystemClassLoader()); - loadButton = new JButton("Load", loadSVG); - loadButton.setVerticalTextPosition(SwingConstants.BOTTOM); - loadButton.setHorizontalTextPosition(SwingConstants.CENTER); - loadButton.addActionListener(loadListener); - - loadPanel.add(loadButton, BorderLayout.CENTER); - - JPanel savePanel = new JPanel(); - rightSplitPane.setRightComponent(savePanel); - savePanel.setLayout(new BorderLayout(0, 0)); - savePanel.setMinimumSize(new Dimension(60, 75)); - saveOkSVG = new FlatSVGIcon("saveOK.svg", 36, 36, ClassLoader.getSystemClassLoader()); - saveSVG = new FlatSVGIcon("save.svg", 36, 36, ClassLoader.getSystemClassLoader()); - saveButton = new JButton("Save", saveSVG); - saveButton.setVerticalTextPosition(SwingConstants.BOTTOM); - saveButton.setHorizontalTextPosition(SwingConstants.CENTER); - saveButton.addActionListener(saveListener); - savePanel.add(saveButton, BorderLayout.CENTER); - frame.pack(); - mainSplitPane.setDividerLocation(0.47); + setSelected(); + startTabbedPanel(); } - public void setMode (boolean mode) { - enableComponents(upperSplitPane, mode); - if (mode) { - startButton.setIcon(startSVG); - startButton.setText("Start"); - saveButton.setIcon(saveSVG); - loadButton.setIcon(loadSVG); - console.addMouseListener(skinChanger); - return; - } - startButton.setText(null); - enableComponents(upperSplitPane, false); - console.removeMouseListener(skinChanger); - if (Config.FIELD03.getBoolean()) { - startButton.setIcon(blackLoadingGIF); - startButton.setDisabledIcon(blackLoadingGIF); - } - else { - startButton.setIcon(whiteLoadingGIF); - startButton.setDisabledIcon(whiteLoadingGIF); + private void setSelected() { + Enumeration buttons = mode.getElements(); + AbstractButton button; + while (buttons.hasMoreElements()) { + button = buttons.nextElement(); + if (button.getActionCommand().equals(Config.FIELD02.getString())) { + button.setSelected(true); + } } } - private Stopwatch stopwatch; - - private ActionListener saveListener = event -> { - PointerBuffer path = MemoryUtil.memAllocPointer(1); - String openPath = loadPath!=null ? loadPath : Config.FIELD01.getString(); - switch (NativeFileDialog.NFD_SaveDialog("png",openPath, path)) { - case NativeFileDialog.NFD_OKAY: - savePath = path.getStringUTF8(0); - if (!savePath.endsWith(".png")) - savePath+=".png"; - write("Saving to "+savePath,null); - NativeFileDialog.nNFD_Free(path.get(0)); - saveButton.setIcon(saveOkSVG); - break; - case NativeFileDialog.NFD_CANCEL: - write("Canceled Save Location Selection",null); - break; - default: // NFD_ERROR - write("Error: %s%n"+NativeFileDialog.NFD_GetError(),SCARLET); - } - }; - - private ActionListener loadListener = event -> { - PointerBuffer path = MemoryUtil.memAllocPointer(1); - switch (NativeFileDialog.NFD_OpenDialog("png",Config.FIELD01.getString(), path)) { - case NativeFileDialog.NFD_OKAY: - loadPath = path.getStringUTF8(0); - Config.FIELD01.setValue(new File(loadPath).getParent()); - write("Loaded "+loadPath,null); - NativeFileDialog.nNFD_Free(path.get(0)); - loadButton.setIcon(loadOkSVG); - break; - case NativeFileDialog.NFD_CANCEL: - write("Canceled Image Selection",null); - break; - default: // NFD_ERROR - write("Error: %s%n"+NativeFileDialog.NFD_GetError(),SCARLET); - } - }; + private void startTabbedPanel() { + int index; + index = switch (Config.FIELD02.getString().substring(0, 2)) { + case "ES" -> 0; + case "ED" -> 1; + case "FS" -> 2; + default -> 3; + }; + tabbedPane.setSelectedIndex(index); + } - public SwingWorker createWorker () { - return new SwingWorker() { + public SwingWorker createWorker() { + return new SwingWorker<>() { @Override - protected Boolean doInBackground() throws Exception { + protected Boolean doInBackground() { setMode(false); - stopwatch = Stopwatch.createStarted(); - return Upscale.run(loadPath, savePath); - } + Utils.stopwatch = Stopwatch.createStarted(); + while (!loadPaths.isEmpty()) { + File tempFile = new File(loadPaths.get(0)); + String local_path = savePath != null ? savePath : tempFile.getPath(); + local_path = local_path + "\\" + (savePath != null ? "" : "Upscaled_") + tempFile.getName(); + Upscale.run(loadPaths.get(0), local_path); + loadPaths.remove(0); + redrawCounter(); + } + return true; + } @Override - protected void done () { + protected void done() { boolean success = false; try { success = get(); - } catch (Exception ex) { - ex.printStackTrace(); + } catch (InterruptedException | ExecutionException ex) { } - stopwatch.stop(); + Utils.stopwatch.stop(); setMode(true); if (success) { savePath = null; - printStopwatch(); - } + Utils.printStopwatch(); + } } }; } - private void printStopwatch () { - long minutes = stopwatch.elapsed(TimeUnit.MINUTES); - long seconds = stopwatch.elapsed(TimeUnit.SECONDS); - String minutesString = ""; - if (minutes!=0) { - seconds = seconds%60; - minutesString = minutes+" "; - if (minutes>1) - minutesString+="Minutes"; - else - minutesString+="Minute"; + public void setMode(boolean mode) { + enableComponents(mainSplitPane, mode); + if (mode) { + button_start.setIcon(startSVG); + button_start.setText("Start"); + button_export_folder.setIcon(saveSVG); + button_import.setIcon(loadSVG); + return; } - String secondsString=""; - if (!minutesString.equals("")) - secondsString+=", "; - secondsString+=seconds; - secondsString += " Second"; - if (seconds!=1) - secondsString += "s"; - if (seconds > 10 || minutes >= 1) - write("Done In " + minutesString + secondsString,null); - } - - public static void write (String text, Color color) { - StyledDocument doc = window.console.getStyledDocument(); - Style style = window.console.addStyle("Color Style", null); - if (color == null) { - color = window.btnLapSRNx8.getForeground(); - } else if (color.equals(SVGBLUE)) - color=new Color(40,164,195); - StyleConstants.setForeground(style, color); - StyleConstants.setFontFamily(style, "Segoe UI"); - StyleConstants.setFontSize(style, 13); - try { - int length = doc.getLength(); - doc.insertString(length, " > " + text + "\n", style); - doc.setParagraphAttributes(length, 1, style, false); - window.console.setCaretPosition(doc.getLength()); - } catch (BadLocationException e) { - e.printStackTrace(); + button_start.setText(null); + enableComponents(mainSplitPane, false); + if (Config.FIELD03.getBoolean() && blackLoadingGIF != null) { + button_start.setIcon(blackLoadingGIF); + button_start.setDisabledIcon(blackLoadingGIF); + } else if (whiteLoadingGIF != null) { + button_start.setIcon(whiteLoadingGIF); + button_start.setDisabledIcon(whiteLoadingGIF); } } - public void enableComponents (Container container, boolean enable) { + public void enableComponents(Container container, boolean enable) { Component[] components = container.getComponents(); for (Component component : components) { component.setEnabled(enable); @@ -542,49 +506,67 @@ public void enableComponents (Container container, boolean enable) { public static String[] getMode() { String thisMode = window.mode.getSelection().getActionCommand(); - for (int i = 0; i < MODES.length; i++) - if (thisMode.equals(MODES[i][0])) - return MODES[i]; + for (String[] strings : MODES) { + if (thisMode.equals(strings[0])) { + return strings; + } + } return new String[]{"ERROR"}; } + + private void redrawCounter(){ + item_counter.setText("Number of items: " +loadPaths.size()+"."); + } - private void setSelected() { - Enumeration buttons = mode.getElements(); - AbstractButton button; - while (buttons.hasMoreElements()) { - button = buttons.nextElement(); - if (button.getActionCommand().equals(Config.FIELD02.getString())) - button.setSelected(true); - } - } - - private void startTabbedPanel () { - int index; - switch (Config.FIELD02.getString().substring(0, 2)) { - case "ES": index = 0; break; - case "ED": index = 1; break; - case "FS": index = 2; break; - default: index = 3; - } - tabbedPane.setSelectedIndex(index); - } - - private void setSkin (boolean next) { - - if (next) - Config.FIELD03.setValue(!Config.FIELD03.getBoolean()); - - if (Config.FIELD03.getBoolean()) { - com.formdev.flatlaf.intellijthemes.FlatGruvboxDarkHardIJTheme.install(); - UIManager.put("TabbedPane.selectedBackground", DARK); - } - else { - com.formdev.flatlaf.intellijthemes.FlatCyanLightIJTheme.install(); - UIManager.put("TabbedPane.selectedBackground", LIGHT); - } - if (next) - SwingUtilities.updateComponentTreeUI(frame); - } - + // Variables declaration - do not modify + private javax.swing.JPanel EDSRpanel; + private javax.swing.JPanel ESPCNpanel; + private javax.swing.JPanel FSRCNNpanel; + private javax.swing.JPanel LapSRNpanel; + private javax.swing.JRadioButton btnESPCNx10; + private javax.swing.JRadioButton btnESPCNx11; + private javax.swing.JRadioButton btnESPCNx12; + private javax.swing.JRadioButton btnESPCNx13; + private javax.swing.JRadioButton btnESPCNx2; + private javax.swing.JRadioButton btnESPCNx3; + private javax.swing.JRadioButton btnESPCNx4; + private javax.swing.JRadioButton btnESPCNx5; + private javax.swing.JRadioButton btnESPCNx6; + private javax.swing.JRadioButton btnESPCNx7; + private javax.swing.JRadioButton btnESPCNx8; + private javax.swing.JRadioButton btnESPCNx9; + private javax.swing.JButton button_change_theme; + private javax.swing.JButton button_export_folder; + private javax.swing.JButton button_import; + private javax.swing.JButton button_remove_items; + private javax.swing.JButton button_start; + public javax.swing.JTextPane console; + private javax.swing.JTextPane item_counter; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JPanel jPanel3; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JSeparator jSeparator1; + private javax.swing.JSeparator jSeparator10; + private javax.swing.JSeparator jSeparator11; + private javax.swing.JSeparator jSeparator12; + private javax.swing.JSeparator jSeparator13; + private javax.swing.JSeparator jSeparator14; + private javax.swing.JSeparator jSeparator15; + private javax.swing.JSeparator jSeparator16; + private javax.swing.JSeparator jSeparator2; + private javax.swing.JSeparator jSeparator3; + private javax.swing.JSeparator jSeparator4; + private javax.swing.JSeparator jSeparator5; + private javax.swing.JSeparator jSeparator6; + private javax.swing.JSeparator jSeparator7; + private javax.swing.JSeparator jSeparator8; + private javax.swing.JSeparator jSeparator9; + private javax.swing.JSplitPane mainSplitPane; + private javax.swing.ButtonGroup mode; + private javax.swing.JTabbedPane tabbedPane; + private javax.swing.JSplitPane upperSplitPanel; + // End of variables declaration + } From dc244dbe348379045daf975179506c5a3fa56da5 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Wed, 29 Dec 2021 17:07:16 -0400 Subject: [PATCH 2/7] Refactor --- src/main/java/core/SimpleProperties.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/core/SimpleProperties.java b/src/main/java/core/SimpleProperties.java index abcb7fd..bdb69e2 100644 --- a/src/main/java/core/SimpleProperties.java +++ b/src/main/java/core/SimpleProperties.java @@ -5,15 +5,13 @@ import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.InvalidPropertiesFormatException; import java.util.Properties; @SuppressWarnings({"java:S1659", "java:S116", "java:S3066"}) enum Config - { - FIELD01 ("Selected Directory", System.getProperty("user.home")) , + { FIELD02 ("Selected Mode", "ESPCNx2") , FIELD03 ("Dark Mode", true); @@ -180,4 +178,4 @@ private boolean checkPath() { return false; } } -} \ No newline at end of file +} From 8ec6b0c7c49fb9c304160e0c20a43067ff7f84e2 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Wed, 29 Dec 2021 17:07:44 -0400 Subject: [PATCH 3/7] Refactor --- src/main/java/core/Upscale.java | 36 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/java/core/Upscale.java b/src/main/java/core/Upscale.java index 9a8d92e..6a73114 100644 --- a/src/main/java/core/Upscale.java +++ b/src/main/java/core/Upscale.java @@ -1,11 +1,13 @@ package core; +import java.awt.Color; import org.bytedeco.opencv.opencv_core.Mat; import org.bytedeco.opencv.opencv_dnn_superres.DnnSuperResImpl; import static org.bytedeco.opencv.global.opencv_imgcodecs.*; import java.io.File; +import java.net.URISyntaxException; import javax.swing.ImageIcon; @SuppressWarnings({"java:S106","java:S2093"}) @@ -13,8 +15,9 @@ public class Upscale { private Upscale(){} public static boolean run(String loadPath, String savePath) { + Utils.write("aypaco",null); String[] mode = MainApp.getMode(); - MainApp.write("Started Upscale Process ["+mode[0]+"]", null); + Utils.write("Started Upscale Process ["+mode[0]+"]", null); ImageIcon s = new ImageIcon(loadPath); int width = s.getIconWidth(); int height = s.getIconHeight(); @@ -23,14 +26,14 @@ public static boolean run(String loadPath, String savePath) { height *= Integer.valueOf(mode[2]); String newSize = "["+width+"x"+height+"]"; if(width > 6666 || height > 6666) { - MainApp.write("ERROR: Expected output has a side thats bigger than 6666 pixels", MainApp.SCARLET); + Utils.write("ERROR: Expected output has a side thats bigger than 6666 pixels", Utils.SCARLET); return false; } //should never happen if (mode[0].equals("ERROR")) { - MainApp.write("Error Loading Config", MainApp.SCARLET); + Utils.write("Error Loading Config", Utils.SCARLET); return false; } @@ -41,42 +44,44 @@ public static boolean run(String loadPath, String savePath) { } - MainApp.write("Loading Image",null); + Utils.write("Loading Image",null); Mat image = imread(loadPath); if (image.empty()) { - MainApp.write("Error Loading Image",MainApp.SCARLET); + Utils.write("Error Loading Image",Utils.SCARLET); return false; } String modelName = "Models/"+mode[0]+".pb"; Mat imageNew = new Mat(); - MainApp.write("Loading AI",null); + Utils.write("Loading AI",null); DnnSuperResImpl sr = null; try { sr = new DnnSuperResImpl(); File modelPath = new File(new File(Upscale.class.getProtectionDomain().getCodeSource().getLocation() .toURI().getPath()).getParent()+File.separator+modelName); if (!modelPath.exists()) { - MainApp.write("Model not found!",MainApp.SCARLET); + Utils.write("Model not found!",Utils.SCARLET); return false; } - MainApp.write("Trying to read model from "+modelPath,null); + Utils.write("Trying to read model from "+modelPath,null); sr.readModel(modelPath.toString()); sr.setModel(mode[1], Integer.valueOf(mode[2])); - MainApp.write("Algorithm and Size Checked"+"\n \t Starting conversion",null); + Utils.write(""" + Algorithm and Size Checked + \t Starting conversion""",null); sr.upsample(image, imageNew); if(imageNew.isNull()){ - MainApp.write("Error UpScaling !",MainApp.SCARLET); + Utils.write("Error UpScaling !",Utils.SCARLET); return false; } - MainApp.write("Image was successfully upScaled from "+originalSize+"x"+mode[2]+", to "+newSize+"and saved to:",null); - MainApp.write(savePath,MainApp.SVGBLUE); + Utils.write("Image was successfully upScaled from "+originalSize+"x"+mode[2]+", to "+newSize+"and saved to:",null); + Utils.write(savePath,Utils.SVGBLUE); Config.FIELD02.setValue(mode[0]); imwrite(savePath, imageNew); return true; - } catch(Exception e) { - MainApp.write("Error UpScaling !",MainApp.SCARLET); - e.printStackTrace(); + } catch(NumberFormatException | URISyntaxException e) { + Utils.write("Error UpScaling !",Utils.SCARLET); + Utils.write(e.getMessage(), Color.yellow); return false; } finally { @@ -87,4 +92,3 @@ public static boolean run(String loadPath, String savePath) { } } - From 379f7c2dbf5d86db5284a0aa0647b665a1c55b40 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Wed, 29 Dec 2021 17:08:31 -0400 Subject: [PATCH 4/7] Create Utils.java --- src/main/java/core/Utils.java | 116 ++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/main/java/core/Utils.java diff --git a/src/main/java/core/Utils.java b/src/main/java/core/Utils.java new file mode 100644 index 0000000..1324c89 --- /dev/null +++ b/src/main/java/core/Utils.java @@ -0,0 +1,116 @@ +package core; + +import com.formdev.flatlaf.FlatDarculaLaf; +import com.formdev.flatlaf.FlatIntelliJLaf; +import com.google.common.base.Stopwatch; +import java.awt.Color; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.concurrent.TimeUnit; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.text.BadLocationException; +import javax.swing.text.Style; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; + +/** + * + * @author USUARIO + */ +public class Utils { + + private static long clickTimer = 0; + public static Stopwatch stopwatch; + private static MainApp _frame; + public static final Color SVGBLUE = new Color(115, 208, 244), + SCARLET = new Color(255, 36, 0), + LIGHT = new Color(194, 236, 255), + DARK = new Color(17, 19, 19); + + public static void attach(MainApp frame) { + if (frame != null) { + _frame = frame; + } + } + public static MouseAdapter mouseListener = new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + if (clickTimer == 0) { + clickTimer = System.currentTimeMillis(); + return; + } + if (System.currentTimeMillis() - clickTimer < 600) { + SwingUtilities.invokeLater(() -> setSkin(true)); + } + clickTimer = 0; + } + }; + + public static void printStopwatch() { + long minutes = stopwatch.elapsed(TimeUnit.MINUTES); + long seconds = stopwatch.elapsed(TimeUnit.SECONDS); + String minutesString = ""; + if (minutes != 0) { + seconds = seconds % 60; + minutesString = minutes + " "; + if (minutes > 1) { + minutesString += "Minutes"; + } else { + minutesString += "Minute"; + } + } + String secondsString = ""; + if (!minutesString.equals("")) { + secondsString += ", "; + } + secondsString += seconds; + secondsString += " Second"; + if (seconds != 1) { + secondsString += "s"; + } + if (seconds > 10 || minutes >= 1) { + write("Done In " + minutesString + secondsString, null); + } + stopwatch = null; + } + + public static void setSkin(boolean next) { + if (next) { + Config.FIELD03.setValue(!Config.FIELD03.getBoolean()); + } + if (Config.FIELD03.getBoolean()) { + + FlatDarculaLaf.install(); + UIManager.put("tabbedPane.selectedBackground", DARK); + } else { + FlatIntelliJLaf.install(); + UIManager.put("tabbedPane.selectedBackground", LIGHT); + } + + if (next && _frame != null) { + SwingUtilities.updateComponentTreeUI(_frame); + } + } + + public static void write(String text, Color color) { + StyledDocument doc = _frame.console.getStyledDocument(); + Style style = _frame.console.addStyle("Color Style", null); + if (color == null) { + color = UIManager.getColor("Button.foreground"); + } else if (color.equals(SVGBLUE)) { + color = new Color(40, 164, 195); + } + StyleConstants.setForeground(style, color); + StyleConstants.setFontFamily(style, "Segoe UI"); + StyleConstants.setFontSize(style, 13); + try { + int length = doc.getLength(); + doc.insertString(length, " > " + text + "\n", style); + doc.setParagraphAttributes(length, 1, style, false); + _frame.console.setCaretPosition(doc.getLength()); + } catch (BadLocationException e) { + } + } + +} From f0c1505a8fe775ac27f1ca2076e7df607d22bd78 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Wed, 29 Dec 2021 17:09:05 -0400 Subject: [PATCH 5/7] Added java packager --- pom.xml | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c294e4b..476c5bc 100644 --- a/pom.xml +++ b/pom.xml @@ -147,9 +147,30 @@ - - + + io.github.fvarrui + javapackager + 1.6.2 + + + package + + package + + + mandatory + core.MainApp + optional + true + false + false + windows + + + + + - \ No newline at end of file + From 9d0b1970b0cf86b645570715909b3cef590c48dd Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Wed, 29 Dec 2021 19:11:56 -0400 Subject: [PATCH 6/7] Update Upscale.java --- src/main/java/core/Upscale.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/core/Upscale.java b/src/main/java/core/Upscale.java index 6a73114..5d2a996 100644 --- a/src/main/java/core/Upscale.java +++ b/src/main/java/core/Upscale.java @@ -1,21 +1,19 @@ package core; import java.awt.Color; -import org.bytedeco.opencv.opencv_core.Mat; -import org.bytedeco.opencv.opencv_dnn_superres.DnnSuperResImpl; - -import static org.bytedeco.opencv.global.opencv_imgcodecs.*; - import java.io.File; import java.net.URISyntaxException; import javax.swing.ImageIcon; +import org.bytedeco.opencv.opencv_core.Mat; +import org.bytedeco.opencv.opencv_dnn_superres.DnnSuperResImpl; +import static org.bytedeco.opencv.global.opencv_imgcodecs.imwrite; +import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; + -@SuppressWarnings({"java:S106","java:S2093"}) public class Upscale { private Upscale(){} public static boolean run(String loadPath, String savePath) { - Utils.write("aypaco",null); String[] mode = MainApp.getMode(); Utils.write("Started Upscale Process ["+mode[0]+"]", null); ImageIcon s = new ImageIcon(loadPath); @@ -45,6 +43,7 @@ public static boolean run(String loadPath, String savePath) { Utils.write("Loading Image",null); + Mat image = imread(loadPath); if (image.empty()) { Utils.write("Error Loading Image",Utils.SCARLET); @@ -70,7 +69,7 @@ public static boolean run(String loadPath, String savePath) { \t Starting conversion""",null); sr.upsample(image, imageNew); - if(imageNew.isNull()){ + if(imageNew.empty()){ Utils.write("Error UpScaling !",Utils.SCARLET); return false; } @@ -85,10 +84,11 @@ public static boolean run(String loadPath, String savePath) { return false; } finally { - imageNew.close(); + imageNew.release(); sr.deallocate(); sr.close(); } } } + From 58487452d02758f4ab6855e0ed43b2dfe3815173 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Wed, 29 Dec 2021 19:21:11 -0400 Subject: [PATCH 7/7] Fix name --- src/main/java/core/MainApp.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/core/MainApp.java b/src/main/java/core/MainApp.java index 9969c9e..250261f 100644 --- a/src/main/java/core/MainApp.java +++ b/src/main/java/core/MainApp.java @@ -176,7 +176,7 @@ private void initComponents() { upperSplitPanel.setDividerLocation(300); - jPanel1.setLayout(new java.awt.GridLayout()); + jPanel1.setLayout(new java.awt.GridLayout(1, 0)); button_start.setIcon(startSVG); button_start.setText("Start"); @@ -448,8 +448,8 @@ protected Boolean doInBackground() { Utils.stopwatch = Stopwatch.createStarted(); while (!loadPaths.isEmpty()) { File tempFile = new File(loadPaths.get(0)); - String local_path = savePath != null ? savePath : tempFile.getPath(); - local_path = local_path + "\\" + (savePath != null ? "" : "Upscaled_") + tempFile.getName(); + String local_path = savePath != null ? savePath : tempFile.getParent(); + local_path = local_path + "\\" + (savePath != null ? "" : Config.FIELD02.getString()+"_")+ tempFile.getName(); Upscale.run(loadPaths.get(0), local_path); loadPaths.remove(0); redrawCounter();