diff --git a/Sources/Dialogs.java b/Sources/Dialogs.java deleted file mode 100644 index 94db481..0000000 --- a/Sources/Dialogs.java +++ /dev/null @@ -1,257 +0,0 @@ -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; - -/** - * Created by LabunskyA. - * Protected with GNU GPLv2 and your honesty - */ -class Dialogs{ - //just name -} - -class SettingsDialog { - private Integer positionX = 0; - private Integer positionY = 0; - - public void ShowSettingsDialog(){ - Window.settingsIsOpen = true; - - final JFrame settingsDialog = new JFrame("Settings"); - final JTextField width = new JTextField(" Width: "); - final JTextField height = new JTextField(" Height: "); - final JTextField tag = new JTextField(Window.tag); - - String width4Scan = ""; - String height4Scan = ""; - if (Window.lessThanX) - width4Scan = "<"; - else if (Window.moreThanX) - width4Scan = ">"; - if (Window.moreThanY) - height4Scan = ">"; - else if (Window.lessThanY) - height4Scan = "<"; - if (Window.customResolution.width != 0) - width4Scan = width4Scan + Integer.toString(Window.customResolution.width); - if (Window.customResolution.height != 0) - height4Scan = height4Scan + Integer.toString(Window.customResolution.height); - final JTextField widthScan = new JTextField(width4Scan); - final JTextField heightScan = new JTextField(height4Scan); - - JTextField tagPointer = new JTextField(" Tag (could works slowly): "); - - JPanel mainPanel = new JPanel(); - JPanel hdCheckBoxPanel = new JPanel(); - JPanel buttonsPanel = new JPanel(); - JPanel tagPanel = new JPanel(); - JPanel sizePanel = new JPanel(); - JPanel prevNyaPanel = new JPanel(); - JPanel closePanel = new JPanel(); - - Checkbox hdCheckBox = new Checkbox("HD nya only"); - - SimpleButton closeButton = new SimpleButton("resources/closeNya.png"); - SimpleButton prevNya = new SimpleButton("resources/prevNya.png", "resources/prevNyaPressed.png"); - - ActionListener getPrevNya = new GetPrevNya(); - - MouseAdapter dragDialogListener = new MouseAdapter() { - @Override - public void mouseDragged(MouseEvent e) { - super.mouseDragged(e); - settingsDialog.setLocation(e.getXOnScreen() - positionX, e.getYOnScreen() - positionY); - } - }; - MouseAdapter mouseMoveListener = new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - super.mousePressed(e); - positionX = e.getX(); - positionY = e.getY(); - } - }; - ActionListener closeSettings = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String value = widthScan.getText(); - if (value.length() == 0) { - Window.currentResolution = false; - Window.moreThanX = false; - Window.lessThanX = false; - Window.customResolution = new Dimension(0, Window.customResolution.height); - } else { - Window.currentResolution = true; - if (value.contains(">")) { - Window.moreThanX = true; - value = value.substring(1); - } - else Window.moreThanX = false; - if (value.contains("<")) { - Window.lessThanX = true; - value = value.substring(1); - } - else Window.lessThanX = false; - Window.customResolution = new Dimension(Integer.valueOf(value), Window.customResolution.height); - } - - value = heightScan.getText(); - if (value.length() == 0) { - Window.currentResolution = false; - Window.moreThanY = false; - Window.lessThanY = false; - Window.customResolution = new Dimension(Window.customResolution.width, 0); - } else { - Window.currentResolution = true; - if (value.contains(">")) { - Window.moreThanY = true; - value = value.substring(1); - } - else Window.moreThanY = false; - if (value.contains("<")) { - Window.lessThanY = true; - value = value.substring(1); - } - else Window.lessThanY = false; - Window.customResolution = new Dimension(Window.customResolution.width, Integer.valueOf(value)); - } - - if (tag.getText().length() == 0) { - Window.useTag = false; - Window.tag = ""; - } else { - Window.useTag = true; - Window.tag = tag.getText().toLowerCase(); - } - - settingsDialog.dispose(); - Window.settingsIsOpen = false; - } - }; - - hdCheckBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - Window.hdOnly = !Window.hdOnly; - } - }); - mainPanel.addMouseListener(mouseMoveListener); - mainPanel.addMouseMotionListener(dragDialogListener); - closeButton.addActionListener(closeSettings); - prevNya.addActionListener(getPrevNya); - - tag.setPreferredSize(new Dimension(100, 20)); - tag.setBackground(Color.WHITE); - heightScan.setPreferredSize(new Dimension(50, 20)); - heightScan.setBackground(Color.WHITE); - widthScan.setPreferredSize(new Dimension(50, 20)); - widthScan.setBackground(Color.WHITE); - - hdCheckBox.setBackground(Color.WHITE); - hdCheckBoxPanel.setLayout(new FlowLayout()); - hdCheckBoxPanel.setBackground(Color.WHITE); - hdCheckBoxPanel.add(hdCheckBox); - - sizePanel.setBackground(Color.WHITE); - sizePanel.setLayout(new FlowLayout()); - sizePanel.add(width); - sizePanel.add(widthScan); - sizePanel.add(height); - sizePanel.add(heightScan); - - tagPanel.setLayout(new FlowLayout()); - tagPanel.setBackground(Color.WHITE); - tagPanel.add(tagPointer); - tagPanel.add(tag); - - prevNyaPanel.setLayout(new FlowLayout()); - prevNyaPanel.setBackground(Color.WHITE); - prevNyaPanel.add(prevNya); - - closePanel.setLayout(new BoxLayout(closePanel, BoxLayout.Y_AXIS)); - closePanel.setBackground(Color.WHITE); - closePanel.add(Box.createRigidArea(new Dimension(0, 10))); - closePanel.add(closeButton); - - buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); - buttonsPanel.add(Box.createRigidArea(new Dimension(16, 0))); - buttonsPanel.add(prevNyaPanel); - buttonsPanel.add(closePanel); - buttonsPanel.setBackground(Color.WHITE); - - tagPointer.setBackground(Color.WHITE); - tagPointer.setDisabledTextColor(Color.BLACK); - tagPointer.setEnabled(false); - - height.setBackground(Color.WHITE); - height.setDisabledTextColor(Color.BLACK); - height.setEnabled(false); - - width.setBackground(Color.WHITE); - width.setDisabledTextColor(Color.BLACK); - width.setEnabled(false); - - mainPanel.setBackground(Color.WHITE); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.add(hdCheckBoxPanel); - mainPanel.add(tagPanel); - mainPanel.add(sizePanel); - mainPanel.add(buttonsPanel); - - settingsDialog.add(mainPanel); - settingsDialog.setUndecorated(true); - settingsDialog.setAlwaysOnTop(true); - settingsDialog.pack(); - settingsDialog.setLocation(Solution.getNya.getX() + Solution.getNya.getWidth() / 2 - settingsDialog.getSize().width / 2, Solution.getNya.getY() + Solution.getNya.getHeight() / 2 - settingsDialog.getSize().height); - settingsDialog.setVisible(true); - - if (Window.hdOnly) - hdCheckBox.setState(true); - else - hdCheckBox.setState(false); - } -} - -class AboutDialog{ - void ShowAbout(){ - final JFrame about = new JFrame("About"); - - JPanel southPanel = new JPanel(); - JTextField madeBy = new JTextField("Made by Labunsky Artem"); - JTextArea aboutNya = new JTextArea("Simple Zerochan.net image downloader.\nClose settings to save fields state\nUse '+' to search for multiple words tag.\nUse ' ' (space) as logical and in the text field.\nUse 'or' as logical or in text field.\nUse '>' and '<' before size in height and width fields to specify nya size."); - SimpleButton closeAbout = new SimpleButton("resources/closeNya.png"); - ActionListener closeDialog = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - about.dispose(); - } - }; - - closeAbout.addActionListener(closeDialog); - - madeBy.setEnabled(false); - madeBy.setFont(Font.getFont("Open Sans")); - madeBy.setDisabledTextColor(Color.BLACK); - madeBy.setBackground(Color.WHITE); - madeBy.setBorder(BorderFactory.createEmptyBorder()); - - southPanel.setBackground(Color.WHITE); - southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.X_AXIS)); - southPanel.add(Box.createRigidArea(new Dimension(2, 0))); - southPanel.add(madeBy); - southPanel.add(closeAbout); - - aboutNya.setEnabled(false); - aboutNya.setBackground(Color.WHITE); - aboutNya.setFont(Font.getFont("Open Sans")); - aboutNya.setDisabledTextColor(Color.BLACK); - about.add(aboutNya, BorderLayout.CENTER); - about.add(southPanel, BorderLayout.SOUTH); - - about.setUndecorated(true); - about.pack(); - about.setLocation(Solution.getNya.getX() + Solution.getNya.getWidth() / 2 - about.getSize().width / 2, Solution.getNya.getY() + Solution.getNya.getHeight() / 2 - about.getSize().height); - about.setVisible(true); - System.out.println(madeBy.getWidth()); - } -} \ No newline at end of file diff --git a/Sources/Listeners.java b/Sources/Listeners.java index 72a0287..25f392e 100644 --- a/Sources/Listeners.java +++ b/Sources/Listeners.java @@ -111,8 +111,61 @@ class Settings implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { if (!Window.settingsIsOpen) { - SettingsDialog settingsDialog = new SettingsDialog(); - settingsDialog.ShowSettingsDialog(); + Window.settingsPanel.setVisible(true); + Window.settingsIsOpen = true; + } else { + String value = SettingsPanel.widthScan.getText(); + if (value.length() == 0) { + Window.currentResolution = false; + Window.moreThanX = false; + Window.lessThanX = false; + Window.customResolution = new Dimension(0, Window.customResolution.height); + } else { + Window.currentResolution = true; + if (value.contains(">")) { + Window.moreThanX = true; + value = value.substring(1); + } + else Window.moreThanX = false; + if (value.contains("<")) { + Window.lessThanX = true; + value = value.substring(1); + } + else Window.lessThanX = false; + Window.customResolution = new Dimension(Integer.valueOf(value), Window.customResolution.height); + } + + value = SettingsPanel.heightScan.getText(); + if (value.length() == 0) { + Window.currentResolution = false; + Window.moreThanY = false; + Window.lessThanY = false; + Window.customResolution = new Dimension(Window.customResolution.width, 0); + } else { + Window.currentResolution = true; + if (value.contains(">")) { + Window.moreThanY = true; + value = value.substring(1); + } + else Window.moreThanY = false; + if (value.contains("<")) { + Window.lessThanY = true; + value = value.substring(1); + } + else Window.lessThanY = false; + Window.customResolution = new Dimension(Window.customResolution.width, Integer.valueOf(value)); + } + + if (SettingsPanel.tag.getText().length() == 0) { + Window.useTag = false; + Window.tag = ""; + } else { + Window.useTag = true; + Window.tag = SettingsPanel.tag.getText().toLowerCase(); + } + + Window.settingsPanel.setVisible(false); + Window.settingsIsOpen = false; } } } @@ -120,8 +173,14 @@ public void actionPerformed(ActionEvent e) { class About implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - AboutDialog aboutNya = new AboutDialog(); - aboutNya.ShowAbout(); + if (!Window.aboutIsOpen) { + Window.aboutPanel.setVisible(true); + Window.aboutIsOpen = !Window.aboutIsOpen; + } + else { + Window.aboutPanel.setVisible(false); + Window.aboutIsOpen = !Window.aboutIsOpen; + } } } diff --git a/Sources/Window.java b/Sources/Window.java index 763b8f3..6bc9fea 100644 --- a/Sources/Window.java +++ b/Sources/Window.java @@ -2,6 +2,8 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.awt.event.MouseAdapter; import java.awt.image.BufferedImage; import java.io.IOException; @@ -19,12 +21,15 @@ class Window extends JFrame { static Boolean moreThanY = false; static Boolean lessThanY = false; static Boolean settingsIsOpen = false; + static Boolean aboutIsOpen = false; static Boolean useTag = false; static String tag = ""; static Integer positionX; static Integer positionY; static Dimension customResolution = new Dimension(0, 0); static final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + static JPanel settingsPanel = new SettingsPanel(); + static JPanel aboutPanel = new AboutPanel(); private BufferedImage bufferedNyaImage; private BufferedImage bufferedFullImage; @@ -73,8 +78,9 @@ BufferedImage getBufferedFullImage() { JPanel centralPanel = new JPanel(); JPanel smallButtonsPanel = new JPanel(); JPanel panelForSmallButtonsPanel = new JPanel(); - JPanel settingsPanel = new JPanel(); + JPanel settingsButtonsPanel = new JPanel(); JPanel panelForSettingsPanel = new JPanel(); + JPanel settingsAndAboutPanel = new JPanel(); nyaLabel = new JLabel(); dataField = new JTextField(); @@ -91,15 +97,15 @@ BufferedImage getBufferedFullImage() { nyaPrefs.addActionListener(nyaSettings); nyaAbout.addActionListener(aboutDialog); - settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.X_AXIS)); - settingsPanel.setBackground(Color.WHITE); - settingsPanel.add(nyaAbout); - settingsPanel.add(nyaPrefs); + settingsButtonsPanel.setLayout(new BoxLayout(settingsButtonsPanel, BoxLayout.X_AXIS)); + settingsButtonsPanel.setBackground(Color.WHITE); + settingsButtonsPanel.add(nyaAbout); + settingsButtonsPanel.add(nyaPrefs); panelForSettingsPanel.setLayout(new BoxLayout(panelForSettingsPanel, BoxLayout.Y_AXIS)); panelForSettingsPanel.setBackground(Color.WHITE); panelForSettingsPanel.add(Box.createRigidArea(new Dimension(0, 22))); - panelForSettingsPanel.add(settingsPanel); + panelForSettingsPanel.add(settingsButtonsPanel); smallButtonsPanel.setLayout(new BoxLayout(smallButtonsPanel, BoxLayout.X_AXIS)); smallButtonsPanel.add(minimizeNya); @@ -135,9 +141,16 @@ BufferedImage getBufferedFullImage() { centralPanel.add(dataField); centralPanel.setBackground(Color.WHITE); - getContentPane().add(centralPanel, BorderLayout.CENTER); - getContentPane().add(buttonsPanel, BorderLayout.SOUTH); - getContentPane().setBackground(Color.WHITE); + settingsAndAboutPanel.setLayout(new BorderLayout()); + settingsAndAboutPanel.add(settingsPanel, BorderLayout.NORTH); + settingsAndAboutPanel.add(aboutPanel, BorderLayout.SOUTH); + settingsAndAboutPanel.setBackground(Color.WHITE); + + add(settingsAndAboutPanel, BorderLayout.WEST); + add(centralPanel, BorderLayout.CENTER); + add(buttonsPanel, BorderLayout.SOUTH); + + setBackground(Color.WHITE); setResizable(false); setUndecorated(true); @@ -198,22 +211,15 @@ else if (nyaFullHeight < screenSize.height - 48 - dataField.getHeight() && nyaFu nyaImageWidth = bufferedFullImage.getWidth(); } else { //mmm, FULLSCREEN - BufferedImage scaledImage = null; if (nyaFullHeight >= screenSize.height - dataField.getHeight() - 48) - scaledImage = toBufferedImage(bufferedFullImage.getScaledInstance(-1, screenSize.height - 48 - dataField.getHeight(), Image.SCALE_SMOOTH)); - - if (scaledImage.getWidth() >= screenSize.width) - scaledImage = toBufferedImage(scaledImage.getScaledInstance(screenSize.width, -1, Image.SCALE_SMOOTH)); + bufferedFullImage = toBufferedImage(bufferedFullImage.getScaledInstance(-1, screenSize.height - 48 - dataField.getHeight(), Image.SCALE_SMOOTH)); - if (nyaFullWidth >= screenSize.width) - scaledImage = toBufferedImage(bufferedFullImage.getScaledInstance(screenSize.width, -1, Image.SCALE_SMOOTH)); + if (bufferedFullImage.getWidth() >= screenSize.width) + bufferedFullImage = toBufferedImage(bufferedFullImage.getScaledInstance(screenSize.width, -1, Image.SCALE_SMOOTH)); - if (scaledImage.getHeight() >= screenSize.height - dataField.getHeight() - 48) - scaledImage = toBufferedImage(bufferedFullImage.getScaledInstance(-1, screenSize.height - 48 - dataField.getHeight(), Image.SCALE_SMOOTH)); - - nyaLabel.setIcon(new ImageIcon(scaledImage)); - nyaImageHeight = scaledImage.getHeight(); - nyaImageWidth = scaledImage.getWidth(); + nyaLabel.setIcon(new ImageIcon(bufferedFullImage)); + nyaImageHeight = bufferedFullImage.getHeight(); + nyaImageWidth = bufferedFullImage.getWidth(); } if (getExtendedState() == Frame.NORMAL && (nyaImageWidth - 206) / 2 - 48 >= 0) { @@ -234,6 +240,12 @@ else if (nyaFullHeight < screenSize.height - 48 - dataField.getHeight() && nyaFu buttonsPaneSecondRigidArea.setMaximumSize(maximumSizeForTheSecondArea); setMinimumSize(minimumWindowSize); + //this will not allow window to set it's width to settings panel width + image width + if (settingsIsOpen) + settingsPanel.setVisible(!settingsIsOpen); + if (aboutIsOpen) + aboutPanel.setVisible(!aboutIsOpen); + if (getExtendedState() == Frame.MAXIMIZED_BOTH) { setMinimumSize(getSize()); pack(); @@ -241,9 +253,12 @@ else if (nyaFullHeight < screenSize.height - 48 - dataField.getHeight() && nyaFu } else pack(); + settingsPanel.setVisible(settingsIsOpen); + aboutPanel.setVisible(aboutIsOpen); + setCursor(Cursor.getDefaultCursor()); - if (getExtendedState() == Frame.NORMAL && !settingsIsOpen) + if (getExtendedState() == Frame.NORMAL) mouseMover.mouseMove(getNya.getX() + getX() + 50, getY() + nyaImageHeight + 40); //102 is the width of buttons } catch (IOException | AWTException ignored) {} } @@ -298,4 +313,150 @@ public SimpleButton(String path) { setBackground(Color.WHITE); } catch (IOException ignored) {} } +} + +class SettingsPanel extends JPanel { + static final JTextField widthScan = new JTextField(); + static final JTextField heightScan = new JTextField(); + static final JTextField tag = new JTextField(); + + SettingsPanel() { + super(); + + setVisible(false); + + final JTextField width = new JTextField(" Width: "); + final JTextField height = new JTextField(" Height: "); + + String width4Scan = ""; + String height4Scan = ""; + + JTextField tagPointer = new JTextField(" Tag (could works slowly): "); + JTextField closeToSave = new JTextField("Close settings to save"); + + JPanel hdCheckBoxPanel = new JPanel(); + JPanel tagPanel = new JPanel(); + JPanel sizePanel = new JPanel(); + JPanel prevNyaPanel = new JPanel(); + JPanel closeToSavePanel = new JPanel(); + + Checkbox hdCheckBox = new Checkbox("HD nya only"); + + SimpleButton prevNya = new SimpleButton("resources/prevNya.png", "resources/prevNyaPressed.png"); + + ActionListener getPrevNya = new GetPrevNya(); + + if (Window.lessThanX) + width4Scan = "<"; + else if (Window.moreThanX) + width4Scan = ">"; + if (Window.moreThanY) + height4Scan = ">"; + else if (Window.lessThanY) + height4Scan = "<"; + if (Window.customResolution.width != 0) + width4Scan = width4Scan + Integer.toString(Window.customResolution.width); + if (Window.customResolution.height != 0) + height4Scan = height4Scan + Integer.toString(Window.customResolution.height); + + hdCheckBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + Window.hdOnly = !Window.hdOnly; + } + }); + prevNya.addActionListener(getPrevNya); + + height.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + width.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + + tag.setText(Window.tag); + tag.setPreferredSize(new Dimension(100, 20)); + tag.setBackground(Color.WHITE); + tag.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + + closeToSave.setBackground(Color.WHITE); + closeToSave.setBorder(BorderFactory.createEmptyBorder()); + + heightScan.setText(height4Scan); + heightScan.setPreferredSize(new Dimension(50, 20)); + heightScan.setBackground(Color.WHITE); + heightScan.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + + widthScan.setText(width4Scan); + widthScan.setPreferredSize(new Dimension(50, 20)); + widthScan.setBackground(Color.WHITE); + widthScan.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + + hdCheckBox.setBackground(Color.WHITE); + hdCheckBoxPanel.setLayout(new FlowLayout()); + hdCheckBoxPanel.setBackground(Color.WHITE); + hdCheckBoxPanel.add(hdCheckBox); + + sizePanel.setBackground(Color.WHITE); + sizePanel.setLayout(new FlowLayout()); + sizePanel.add(width); + sizePanel.add(widthScan); + sizePanel.add(height); + sizePanel.add(heightScan); + + tagPanel.setLayout(new FlowLayout()); + tagPanel.setBackground(Color.WHITE); + tagPanel.add(tagPointer); + tagPanel.add(tag); + + prevNyaPanel.setLayout(new FlowLayout()); + prevNyaPanel.setBackground(Color.WHITE); + prevNyaPanel.add(prevNya); + + closeToSavePanel.setLayout(new FlowLayout()); + closeToSavePanel.setBackground(Color.WHITE); + closeToSavePanel.add(closeToSave); + + tagPointer.setBackground(Color.WHITE); + tagPointer.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + tagPointer.setDisabledTextColor(Color.BLACK); + tagPointer.setEnabled(false); + + height.setBackground(Color.WHITE); + height.setDisabledTextColor(Color.BLACK); + height.setEnabled(false); + + width.setBackground(Color.WHITE); + width.setDisabledTextColor(Color.BLACK); + width.setEnabled(false); + + setBackground(Color.WHITE); + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + add(hdCheckBoxPanel); + add(tagPanel); + add(sizePanel); + add(prevNyaPanel); + add(closeToSavePanel); + + setBackground(Color.WHITE); + + if (Window.hdOnly) + hdCheckBox.setState(true); + else + hdCheckBox.setState(false); + } +} + +class AboutPanel extends JPanel{ + AboutPanel(){ + super(); + setVisible(false); + + JTextArea aboutNya = new JTextArea("Simple Zerochan.net image downloader.\nClose settings to save fields state\nUse '+' to search for multiple words tag.\nUse ' ' (space) as logical and in the text field.\nUse 'or' as logical or in text field.\nUse '>' and '<' before size in height and width\n fields to specify nya size.\n\nMade by Labunsky Artem"); + SimpleButton closeAbout = new SimpleButton("resources/closeNya.png"); + + aboutNya.setEnabled(false); + aboutNya.setBackground(Color.WHITE); + aboutNya.setFont(Font.getFont("Open Sans")); + aboutNya.setDisabledTextColor(Color.BLACK); + + setLayout(new BorderLayout()); + add(aboutNya, BorderLayout.CENTER); + } } \ No newline at end of file