diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF deleted file mode 100644 index fcb9722..0000000 --- a/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: Solution - diff --git a/Sources/Listeners.java b/Sources/Listeners.java index 29db803..9689958 100644 --- a/Sources/Listeners.java +++ b/Sources/Listeners.java @@ -1,7 +1,5 @@ import javax.imageio.ImageIO; import javax.swing.*; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; import javax.swing.filechooser.FileNameExtensionFilter; import java.awt.*; import java.awt.event.*; @@ -13,7 +11,11 @@ * Protected with GNU GPLv2 and your honesty */ -class Listeners implements ActionListener { +class Listeners { + //I just want to use this name for .java +} + +class Save2File implements ActionListener{ private File lastSave = null; private Boolean firstTime = true; @@ -71,9 +73,7 @@ class getNewNya implements ActionListener{ public void actionPerformed(ActionEvent e) { try { Solution.getNya.drawNya(); - } catch (IOException e1) { - e1.printStackTrace(); - } + } catch (IOException ignored) {} } } @@ -107,200 +107,11 @@ public void actionPerformed(ActionEvent e) { } class Settings implements ActionListener{ - private Integer positionX = 0; - private Integer positionY = 0; - @Override public void actionPerformed(ActionEvent e) { if (!Window.settingsIsOpen) { - Window.settingsIsOpen = true; - - final JFrame settingsDialog = new JFrame("Settings"); - final JTextField tag = new JTextField(Window.tag); - final JTextField widthScan = new JTextField(Integer.toString(Window.customResolution.width)); - final JTextField heightScan = new JTextField(Integer.toString(Window.customResolution.height)); - - JTextField tagPointer = new JTextField(" Tag (only one, could works slowly): "); - JTextField width = new JTextField(" Width: "); - JTextField height = new JTextField(" Height: "); - - 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(); - DocumentListener documentListener = new DocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) { - warn(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - warn(); - } - - @Override - public void changedUpdate(DocumentEvent e) { - warn(); - } - - public void warn() { - if (tag.getText().length() == 0) { - Window.useTag = false; - } else { - Window.useTag = true; - Window.tag = tag.getText().toLowerCase(); - } - } - }; - DocumentListener customWidthListener = new DocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) {warn();} - @Override - public void removeUpdate(DocumentEvent e) {warn();} - @Override - public void changedUpdate(DocumentEvent e) {warn();} - - public void warn() { - if (widthScan.getText().length() == 0) { - Window.currentResolution = false; - Window.customResolution = new Dimension(0, Window.customResolution.height); - } else { - Window.currentResolution = true; - Window.customResolution = new Dimension(Integer.valueOf(widthScan.getText()), Window.customResolution.height); - } - } - }; - DocumentListener customHeightListener = new DocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) {warn();} - @Override - public void removeUpdate(DocumentEvent e) {warn();} - @Override - public void changedUpdate(DocumentEvent e) {warn();} - - public void warn() { - if (heightScan.getText().length() == 0) { - Window.currentResolution = false; - Window.customResolution = new Dimension(Window.customResolution.width, 0); - } else { - Window.currentResolution = true; - Window.customResolution = new Dimension(Window.customResolution.width, Integer.valueOf(heightScan.getText())); - } - } - }; - 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) { - 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.getDocument().addDocumentListener(documentListener); - widthScan.getDocument().addDocumentListener(customWidthListener); - heightScan.getDocument().addDocumentListener(customHeightListener); - - tag.setPreferredSize(new Dimension(100, 20)); - heightScan.setPreferredSize(new Dimension(50, 20)); - widthScan.setPreferredSize(new Dimension(50, 20)); - - 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(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); + SettingsDialog settingsDialog = new SettingsDialog(); + settingsDialog.ShowSettingsDialog(); } } } diff --git a/Sources/SettingsDialog.java b/Sources/SettingsDialog.java new file mode 100644 index 0000000..4ddb312 --- /dev/null +++ b/Sources/SettingsDialog.java @@ -0,0 +1,203 @@ +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import java.awt.*; +import java.awt.event.*; + +/** + * Created by LabunskyA. + * Protected with GNU GPLv2 and your honesty + */ +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 (only one, 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.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.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)); + heightScan.setPreferredSize(new Dimension(50, 20)); + widthScan.setPreferredSize(new Dimension(50, 20)); + + 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(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); + } +} diff --git a/Sources/Window.java b/Sources/Window.java index 47e11f1..08dbc87 100644 --- a/Sources/Window.java +++ b/Sources/Window.java @@ -14,6 +14,10 @@ class Window extends JFrame { static Boolean hdOnly = false; static Boolean currentResolution = false; + static Boolean moreThanX = false; + static Boolean lessThanX = false; + static Boolean moreThanY = false; + static Boolean lessThanY = false; static Boolean settingsIsOpen = false; static Boolean useTag = false; static String tag = ""; @@ -47,7 +51,7 @@ BufferedImage getBufferedFullImage() { setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - ActionListener saveFullNya = new Listeners(); + ActionListener saveFullNya = new Save2File(); ActionListener getNewNya = new getNewNya(); ActionListener exitNya = new CloseNya(); ActionListener maximizeNyaWindow = new MaximizeNya(); @@ -137,6 +141,7 @@ void drawNya() throws MalformedURLException { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Boolean check = true; + Checker checker = new Checker(); LittleParser littleParser = new LittleParser(); while (check) { @@ -144,20 +149,14 @@ void drawNya() throws MalformedURLException { Zerochan.generateNumberNya(); Zerochan.generateURLs(); - if (useTag) { - if (littleParser.parse("http://www.zerochan.net/" + Zerochan.numberNya, LittleParser.TAG).contains(tag)) - check = false; - } else check = false; + check = checker.CheckTag(littleParser, true); } try { bufferedFullImage = ImageIO.read(Zerochan.fullURL); nyaFullHeight = bufferedFullImage.getHeight(); nyaFullWidth = bufferedFullImage.getWidth(); - if (hdOnly && (nyaFullHeight < 1080 || nyaFullWidth < 1920)) - check = true; - else if (currentResolution && (nyaFullHeight != customResolution.getHeight() || nyaFullWidth != customResolution.getWidth())) - check = true; + check = checker.CheckSize(nyaFullWidth, nyaFullHeight, check); } catch (IOException e) { check = true; } //sometimes Zerochan.net blocks some pictures, so I need to handle this occasion and get another url with another picture } @@ -240,4 +239,36 @@ public SimpleButton(String path) { setBackground(Color.WHITE); } catch (IOException ignored) {} } +} + +class Checker { + public boolean CheckTag(LittleParser littleParser, Boolean check) throws MalformedURLException { + if (Window.useTag) { + if (littleParser.parse("http://www.zerochan.net/" + Zerochan.numberNya, LittleParser.TAG).contains(Window.tag)) + check = false; + } else check = false; + + return check; + } + + public boolean CheckSize(Integer nyaWidth, Integer nyaHeight, Boolean check) { + if (Window.hdOnly && (nyaWidth < 1920 || nyaHeight < 1080)) + check = true; + + if (Window.currentResolution) { + if (Window.moreThanY && nyaHeight < Window.customResolution.height) + check = true; + if (Window.lessThanY && nyaHeight > Window.customResolution.height) + check = true; + if (Window.moreThanX && nyaWidth < Window.customResolution.width) + check = true; + if (Window.lessThanX && nyaWidth > Window.customResolution.width) + check = true; + + if (!Window.moreThanY && !Window.moreThanX && !Window.lessThanY && !Window.lessThanX && (nyaHeight != Window.customResolution.height || nyaWidth != Window.customResolution.width)) + check = true; + } + + return check; + } } \ No newline at end of file diff --git a/Sources/resources/closeNya.png b/Sources/resources/closeNya.png index 4b02571..d6db535 100644 Binary files a/Sources/resources/closeNya.png and b/Sources/resources/closeNya.png differ diff --git a/Sources/resources/maximizeNya.png b/Sources/resources/maximizeNya.png index a5c073c..1269f2d 100644 Binary files a/Sources/resources/maximizeNya.png and b/Sources/resources/maximizeNya.png differ diff --git a/Sources/resources/minimizeNya.png b/Sources/resources/minimizeNya.png index e5c19f9..8eb16f8 100644 Binary files a/Sources/resources/minimizeNya.png and b/Sources/resources/minimizeNya.png differ