Skip to content

Commit

Permalink
Settings dialog moved to external class, new search
Browse files Browse the repository at this point in the history
Now you can search with ">", "<" and "" prefix in height and width
fields, you can also do it separately
+many small fixes
  • Loading branch information
LabunskyA committed Jan 19, 2015
1 parent c08037e commit 1e03335
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 209 deletions.
3 changes: 0 additions & 3 deletions META-INF/MANIFEST.MF

This file was deleted.

205 changes: 8 additions & 197 deletions Sources/Listeners.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -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;

Expand Down Expand Up @@ -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) {}
}
}

Expand Down Expand Up @@ -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();
}
}
}
Expand Down
Loading

0 comments on commit 1e03335

Please sign in to comment.