Permalink
Browse files

Add area selection tool & major refractor

  • Loading branch information...
ferrybig committed Nov 24, 2018
1 parent db2ff9a commit 45f865d20c59c79af1dd46c22b8bb66347712184
Showing with 847 additions and 200 deletions.
  1. +17 −2 src/main/java/me/ferrybig/screencapture/Main.java
  2. +96 −0 src/main/java/me/ferrybig/screencapture/Mouse.java
  3. +0 −51 src/main/java/me/ferrybig/screencapture/NewJFrame.form
  4. +0 −98 src/main/java/me/ferrybig/screencapture/NewJFrame.java
  5. +71 −26 src/main/java/me/ferrybig/screencapture/ScreenCaptureModel.java
  6. +1 −1 src/main/java/me/ferrybig/screencapture/WindowInfo.java
  7. +0 −1 src/main/java/me/ferrybig/screencapture/WindowInfoBuilder.java
  8. +2 −1 src/main/java/me/ferrybig/screencapture/{ → events}/EventBus.java
  9. +66 −0 src/main/java/me/ferrybig/screencapture/events/MouseEvent.java
  10. +74 −0 src/main/java/me/ferrybig/screencapture/events/MouseEventBus.java
  11. +21 −0 src/main/java/me/ferrybig/screencapture/events/MouseListener.java
  12. +101 −0 src/main/java/me/ferrybig/screencapture/tools/AreaSelectTool.java
  13. +27 −0 src/main/java/me/ferrybig/screencapture/tools/ExitTool.java
  14. +16 −0 src/main/java/me/ferrybig/screencapture/tools/Tool.java
  15. +40 −0 src/main/java/me/ferrybig/screencapture/tools/ToolInfo.java
  16. +69 −0 src/main/java/me/ferrybig/screencapture/tools/WindowSelectTool.java
  17. +32 −0 src/main/java/me/ferrybig/screencapture/ui/ContainerPanel.java
  18. +77 −0 src/main/java/me/ferrybig/screencapture/ui/MousePanel.java
  19. +5 −18 src/main/java/me/ferrybig/screencapture/{SelectorPanel.java → ui/PaintPanel.java}
  20. +2 −2 src/main/java/me/ferrybig/screencapture/{ → ui}/PicturePanel.java
  21. +130 −0 src/main/java/me/ferrybig/screencapture/ui/ToolbarPanel.java
  22. BIN src/main/resources/me/ferrybig/screencapture/test.png
@@ -5,6 +5,9 @@
*/
package me.ferrybig.screencapture;

import me.ferrybig.screencapture.ui.MousePanel;
import me.ferrybig.screencapture.ui.PaintPanel;
import me.ferrybig.screencapture.ui.PicturePanel;
import java.awt.AWTException;
import java.awt.Container;
import java.awt.Graphics2D;
@@ -32,6 +35,12 @@
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import me.ferrybig.screencapture.tools.AreaSelectTool;
import me.ferrybig.screencapture.tools.ExitTool;
import me.ferrybig.screencapture.tools.ToolInfo;
import me.ferrybig.screencapture.tools.WindowSelectTool;
import me.ferrybig.screencapture.ui.ContainerPanel;
import me.ferrybig.screencapture.ui.ToolbarPanel;

/**
*
@@ -180,7 +189,11 @@ public static void main(String[] args) throws AWTException, IOException, Interru

System.out.println("Done!");
windows.forEach(System.out::println);
ScreenCaptureModel model = new ScreenCaptureModel(windows, result);
List<ToolInfo> tools = new ArrayList<>();
tools.add(new ToolInfo(WindowSelectTool::new, Toolkit.getDefaultToolkit().getImage(Main.class.getResource("test.png")), "Windows"));
tools.add(new ToolInfo(AreaSelectTool::new, Toolkit.getDefaultToolkit().getImage(Main.class.getResource("test.png")), "Select"));
tools.add(new ToolInfo(ExitTool::new, Toolkit.getDefaultToolkit().getImage(Main.class.getResource("test.png")), "Exit"));
ScreenCaptureModel model = new ScreenCaptureModel(windows, tools, result);
SwingUtilities.invokeLater(() -> {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screens = ge.getScreenDevices();
@@ -204,7 +217,9 @@ private static void makeFrame(ScreenCaptureModel model, GraphicsDevice device, R
constraints.weightx = 1;
constraints.weighty = 1;

contentFrame.add(new SelectorPanel(model, offset), constraints);
contentFrame.add(new MousePanel(model, offset), constraints);
contentFrame.add(new ContainerPanel(offset, new ToolbarPanel(model)), constraints);
contentFrame.add(new PaintPanel(model, offset), constraints);
contentFrame.add(new PicturePanel(model, offset), constraints);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -0,0 +1,96 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package me.ferrybig.screencapture;

import java.awt.Point;
import java.util.Objects;

/**
*
* @author fernando
*/
public class Mouse {

private final Point position;
private final boolean left;
private final boolean right;

public Mouse(Point position, boolean left, boolean right) {
this.position = position;
this.left = left;
this.right = right;
}

public Mouse setLeft(boolean left) {
return new Mouse(position, left, right);
}

public Mouse setRight(boolean right) {
return new Mouse(position, left, right);
}

public Mouse setPosition(Point position) {
return new Mouse(position, left, right);
}

public Point getPosition() {
return position;
}

public boolean isLeft() {
return left;
}

public boolean isRight() {
return right;
}

public double getX() {
return position.getX();
}

public double getY() {
return position.getY();
}

@Override
public String toString() {
return "Mouse{" + "position=" + position + ", left=" + left + ", right=" + right + '}';
}

@Override
public int hashCode() {
int hash = 3;
hash = 47 * hash + Objects.hashCode(this.position);
hash = 47 * hash + (this.left ? 1 : 0);
hash = 47 * hash + (this.right ? 1 : 0);
return hash;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Mouse other = (Mouse) obj;
if (this.left != other.left) {
return false;
}
if (this.right != other.right) {
return false;
}
if (!Objects.equals(this.position, other.position)) {
return false;
}
return true;
}
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 45f865d

Please sign in to comment.