Skip to content

Commit

Permalink
Multi-tags, about dialog, code arch fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LabunskyA committed Jan 20, 2015
1 parent 0998810 commit 6c54031
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 49 deletions.
53 changes: 50 additions & 3 deletions Sources/SettingsDialog.java → Sources/Dialogs.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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 Dialogs{
//just name
}

class SettingsDialog {
private Integer positionX = 0;
private Integer positionY = 0;
Expand Down Expand Up @@ -37,7 +39,7 @@ else if (Window.lessThanY)
final JTextField widthScan = new JTextField(width4Scan);
final JTextField heightScan = new JTextField(height4Scan);

JTextField tagPointer = new JTextField(" Tag (only one, could works slowly): ");
JTextField tagPointer = new JTextField(" Tag (could works slowly): ");

JPanel mainPanel = new JPanel();
JPanel hdCheckBoxPanel = new JPanel();
Expand Down Expand Up @@ -169,6 +171,7 @@ public void itemStateChanged(ItemEvent e) {
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);
Expand Down Expand Up @@ -205,3 +208,47 @@ public void itemStateChanged(ItemEvent e) {
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.\nUse '+' to search for multiple word tag.\nUse ' ' (space) to search for more than one tag.\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());
}
}
14 changes: 11 additions & 3 deletions Sources/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Save2File implements ActionListener{
public void actionPerformed(ActionEvent e) {
try{
if (firstTime) {
FileInputStream fileIn = new FileInputStream("nyaPrefs.bin");
FileInputStream fileIn = new FileInputStream("nyaPath.path");
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
lastSave = (File) objectIn.readObject();
fileIn.close();
Expand All @@ -47,7 +47,7 @@ public void actionPerformed(ActionEvent e) {
try{
if (lastSave != fileChooser.getSelectedFile()) {
lastSave = fileChooser.getSelectedFile();
FileOutputStream fileOut = new FileOutputStream("nyaPrefs.bin");
FileOutputStream fileOut = new FileOutputStream("nyaPath.path");
ObjectOutputStream prefOut = new ObjectOutputStream(fileOut);
prefOut.writeObject(lastSave);
prefOut.close();
Expand All @@ -68,7 +68,7 @@ public void actionPerformed(ActionEvent e) {
}
}

class getNewNya implements ActionListener{
class GetNewNya implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
try {
Expand Down Expand Up @@ -116,6 +116,14 @@ public void actionPerformed(ActionEvent e) {
}
}

class About implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
AboutDialog aboutNya = new AboutDialog();
aboutNya.ShowAbout();
}
}

class MouseMoveListener extends MouseAdapter {
public void mousePressed(MouseEvent e){
Window.positionX = e.getX();
Expand Down
62 changes: 19 additions & 43 deletions Sources/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ BufferedImage getBufferedFullImage() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

ActionListener saveFullNya = new Save2File();
ActionListener getNewNya = new getNewNya();
ActionListener getNewNya = new GetNewNya();
ActionListener exitNya = new CloseNya();
ActionListener maximizeNyaWindow = new MaximizeNya();
ActionListener minimizeNyaWindow = new MinimizeNya();
ActionListener nyaSettings = new Settings();
ActionListener aboutDialog = new About();

MouseAdapter mouseMove = new MouseMoveListener();
MouseAdapter mouseDrag = new MouseDragListener();
Expand All @@ -66,12 +67,14 @@ BufferedImage getBufferedFullImage() {
SimpleButton closeNya = new SimpleButton("resources/closeNya.png");
SimpleButton maximizeNya = new SimpleButton("resources/maximizeNya.png");
SimpleButton minimizeNya = new SimpleButton("resources/minimizeNya.png");
SimpleButton nyaPrefs = new SimpleButton("resources/nyaPrefs.png", "resources/nyaPrefsPressed.png");
SimpleButton nyaPrefs = new SimpleButton("resources/nyaPrefs.png");
SimpleButton nyaAbout = new SimpleButton("resources/nyaAbout.png");

JPanel centralPanel = new JPanel();
JPanel smallButtonsPanel = new JPanel();
JPanel panelForSmallButtonsPanel = new JPanel();
JPanel panelForSettingsButton = new JPanel();
JPanel settingsPanel = new JPanel();
JPanel panelForSettingsPanel = new JPanel();
nyaLabel = new JLabel();
dataField = new JTextField();

Expand All @@ -86,12 +89,17 @@ BufferedImage getBufferedFullImage() {
maximizeNya.addActionListener(maximizeNyaWindow);
minimizeNya.addActionListener(minimizeNyaWindow);
nyaPrefs.addActionListener(nyaSettings);
nyaPrefs.setBorder(BorderFactory.createLineBorder(Color.white, 1, true));
nyaAbout.addActionListener(aboutDialog);

panelForSettingsButton.setLayout(new BoxLayout(panelForSettingsButton, BoxLayout.Y_AXIS));
panelForSettingsButton.setBackground(Color.WHITE);
panelForSettingsButton.add(Box.createRigidArea(new Dimension(0, 22)));
panelForSettingsButton.add(nyaPrefs);
settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.X_AXIS));
settingsPanel.setBackground(Color.WHITE);
settingsPanel.add(nyaAbout);
settingsPanel.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);

smallButtonsPanel.setLayout(new BoxLayout(smallButtonsPanel, BoxLayout.X_AXIS));
smallButtonsPanel.add(minimizeNya);
Expand All @@ -105,7 +113,7 @@ BufferedImage getBufferedFullImage() {
panelForSmallButtonsPanel.add(smallButtonsPanel);

buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
buttonsPanel.add(panelForSettingsButton);
buttonsPanel.add(panelForSettingsPanel);
buttonsPanel.add(buttonsPanelFirstRigidArea);
buttonsPanel.add(getNya);
buttonsPanel.add(Box.createRigidArea(new Dimension(3, 0)));
Expand Down Expand Up @@ -171,7 +179,7 @@ void draw() {
Integer nyaImageWidth = bufferedNyaImage.getWidth();
Dimension maximumSizeForTheFistArea = new Dimension((nyaImageWidth - 204) / 2 - 16, 48);
Dimension maximumSizeForTheSecondArea = new Dimension((nyaImageWidth - 204) / 2 - 48, 48);
Dimension minimumWindowSize = new Dimension(274, 0); //just buttons size
Dimension minimumWindowSize = new Dimension(297, 0); //just buttons size
Integer maxContentPaneHeight = nyaImageHeight + 48 + dataField.getHeight();

//this on is for small screens, less then 720p
Expand Down Expand Up @@ -233,42 +241,10 @@ public SimpleButton(String path) {
super();
try {
setIcon(new ImageIcon(ImageIO.read(getClass().getResource(path))));
setPressedIcon(new ImageIcon(ImageIO.read(getClass().getResource(path))));
setPressedIcon(new ImageIcon(ImageIO.read(getClass().getResource(path.substring(0, path.indexOf(".")) + "Pressed.png"))));
setMargin(new Insets(0, 0, 0, 0));
setBorder(BorderFactory.createLineBorder(Color.WHITE, 1, false));
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;
}
}
39 changes: 39 additions & 0 deletions Sources/Zerochan.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,43 @@ public String parse(String urlString, char type) throws MalformedURLException {

return stringBuffer.toString().toLowerCase();
}
}

class Checker {
public boolean CheckTag(LittleParser littleParser, Boolean check) throws MalformedURLException {
if (Window.useTag) {
String[] tags = Window.tag.split(" "); //for more than one tag
Integer tagNumContains = 0;

for (String tag : tags)
if (littleParser.parse("http://www.zerochan.net/" + Zerochan.numberNya, LittleParser.TAG).contains(tag))
tagNumContains++;

if (tagNumContains == tags.length)
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;
}
}
Binary file added Sources/resources/closeNyaPressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sources/resources/maximizeNyaPressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sources/resources/minimizeNyaPressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sources/resources/nyaAbout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sources/resources/nyaAboutPressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6c54031

Please sign in to comment.