Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added gte/src/gte/icons/clearrectangles.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 gte/src/gte/icons/clearrectangles\.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 gte/src/gte/icons/zoomwidth.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 gte/src/gte/icons/zoomwindow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions gte/src/gte/model/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
import gte.utils.UnsupportedImageTypeException;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Point;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.awt.event.*;
import java.util.Scanner;

/**
* Created by kns10 on 2/24/16.
Expand All @@ -30,6 +35,7 @@ public class Component {
private int page_height;
private String cc_image;
private String image_basePath = "gte/data/sample_ccs/page-";
private String json_basePath = "temp/";
private Rectangle imageCoords;

private String[] everythingElse;
Expand All @@ -54,6 +60,12 @@ public void setAssociatedType(String s) {
associatedType = s;
}

public void setAssociatedWord(String s) { associatedWord = s; }

public String getAssociatedWord() {
return this.associatedWord;
}

public static BufferedImage tintImage(BufferedImage loadImg, int red, int green, int blue, int alpha) {
Graphics g = loadImg.getGraphics();
g.setColor(new Color(red, green, blue, alpha));
Expand Down Expand Up @@ -180,7 +192,25 @@ public Component(String s) {

isSelected = false;

// use rectangle bounding box as unique identifier for each component
// take the hash code to remove all invalid characters
// might change to json eventually
String pathToJSON = json_basePath + imageCoords.toString().hashCode() + "/data.txt";
try {
Scanner in = new Scanner(new FileReader(pathToJSON));
associatedWord = in.nextLine().trim();
in.close();
} catch (Exception e) {
associatedWord = "";
}

}



// on hover
// do stuff
//this.setTooltip(associatedWord);


}
1 change: 1 addition & 0 deletions gte/src/gte/view/Canvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public Canvas(Model model, View view, Controller controller)
mouseListener = new CanvasMouseListener(model, view, controller);
keyboardListener = new CanvasKeyboardListener(model, view, controller);
addMouseListener(mouseListener);
addMouseMotionListener(mouseListener);
addKeyListener(keyboardListener);
}

Expand Down
16 changes: 14 additions & 2 deletions gte/src/gte/view/CanvasMouseListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public void mouseClicked(MouseEvent e)
model.selectComponent(model.whichClicked(e.getPoint()));
}



@Override
public void mousePressed(MouseEvent e)
{
Expand Down Expand Up @@ -125,13 +127,23 @@ public void mouseExited(MouseEvent e)
@Override
public void mouseDragged(MouseEvent e)
{
x2 = (int)(e.getX()/view.getZoomLevel());
y2 = (int)(e.getY()/view.getZoomLevel());
x2 = (int)(e.getX() / view.getZoomLevel());
y2 = (int)(e.getY() / view.getZoomLevel());
view.getCanvas().repaint();
}

@Override
public void mouseMoved(MouseEvent e)
{
try {
String a;
if ((a = model.whichClicked(e.getPoint()).getAssociatedWord()) != null &&
!a.equals(view.getCanvasTooltip())) {
System.out.println(a);
view.setCanvasTooltip(a);
}
} catch (NullPointerException npe) {

}
}
}
23 changes: 23 additions & 0 deletions gte/src/gte/view/TypeEnterBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class TypeEnterBox extends JPanel {
private Model model;
private JTextField field;
private InputKeyboardListener keyboardListener;
private String json_basePath = "temp/";

private TypeEnterBox() {

}
Expand All @@ -41,8 +43,29 @@ public String convertToJSON() {
}

public void convertDataToJSON(String label, Component data) {

try {
data.setAssociatedWord(label);
String pathToJSON = json_basePath + data.toString().hashCode() + "/data.txt";
System.out.println(pathToJSON);
File file= new File(pathToJSON);
FileWriter fw;
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
fw = new FileWriter(file);
fw.write(label);
fw.flush();
fw.close();

} catch (IOException e) {
e.printStackTrace();
}

JSONObject obj = new JSONObject();
obj.put("label", label);
obj.put("hashcode", data.toString().hashCode());
obj.put("data", data.toString());
try {

Expand Down
19 changes: 16 additions & 3 deletions gte/src/gte/view/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public void setZoomLevel(double z) {
repaint();
canvas.repaint();
}

public void setCanvasTooltip(String s) {
canvas.setToolTipText(s);
}

public String getCanvasTooltip() {
return canvas.getToolTipText();
}

public double getZoomLevel() {return zoomLevel;}

public View(Model model, Controller controller)
Expand Down Expand Up @@ -156,22 +165,26 @@ public void windowClosing(WindowEvent we)

//keyboardListener = new CanvasKeyboardListener(model, this, controller);
//addKeyListener(keyboardListener);
System.out.println("wut");


KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addKeyEventDispatcher(new KeyEventDispatcher() {
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getID() == KeyEvent.KEY_PRESSED) {
getTextData();
teb.convertDataToJSON(getTextData(), getRect());
}
/*
int keyCode = e.getKeyCode();
switch( keyCode ) {
case KeyEvent.VK_ENTER:
System.out.println("plserino workerin");
getTextData();
teb.convertDataToJSON(getTextData(), getRect());
break;
}
return false; //continue with the keypress, otherwise it'll be intercepted
*/
return false; //don't intercept
}
});

Expand Down
2 changes: 1 addition & 1 deletion gte/src/gte/view/actions/ClearRectangles.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ClearRectangles extends AbstractAction {

{
putValue(NAME, "Clear Rectangles");
putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/gte/icons/rightarrow.png")));
putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/gte/icons/clearrectangles.png")));
putValue(SHORT_DESCRIPTION, "Erases rectangles.");
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control ."));
}
Expand Down
2 changes: 1 addition & 1 deletion gte/src/gte/view/actions/ZoomPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ZoomPage extends AbstractAction{

{
putValue(NAME, "Zoom Page");
putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/gte/icons/zoomin.png")));
putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/gte/icons/zoomwindow.png")));
putValue(SHORT_DESCRIPTION, "fits page on window");
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control 7"));
}
Expand Down
2 changes: 1 addition & 1 deletion gte/src/gte/view/actions/ZoomWidth.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ZoomWidth extends AbstractAction {

{
putValue(NAME, "Zoom Out");
putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/gte/icons/zoomin.png")));
putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/gte/icons/zoomwidth.png")));
putValue(SHORT_DESCRIPTION, "Zoom width");
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control 9"));
}
Expand Down
1 change: 1 addition & 0 deletions temp/1427703697/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions temp/1667058427/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AL
1 change: 1 addition & 0 deletions temp/348922169/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
i mu pi
1 change: 1 addition & 0 deletions temp/471483599/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
imupi
1 change: 1 addition & 0 deletions temp/616820736/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e
1 change: 1 addition & 0 deletions temp/722488033/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
2 changes: 1 addition & 1 deletion test.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"data":"java.awt.Rectangle[x=287,y=153,width=27,height=52]","label":"1"}{"data":"java.awt.Rectangle[x=287,y=153,width=27,height=52]","label":"1"}{"data":"java.awt.Rectangle[x=287,y=153,width=27,height=52]","label":"1"}{"data":"java.awt.Rectangle[x=319,y=153,width=33,height=51]","label":"3"}{"data":"java.awt.Rectangle[x=319,y=153,width=33,height=51]","label":"3"}{"data":"java.awt.Rectangle[x=353,y=152,width=37,height=52]","label":"6"}{"data":"java.awt.Rectangle[x=353,y=152,width=37,height=52]","label":"6"}
{"data":"java.awt.Rectangle[x=287,y=153,width=27,height=52]","hashcode":1427703697,"label":"1"}{"data":"java.awt.Rectangle[x=287,y=153,width=27,height=52]","hashcode":1427703697,"label":"1"}{"data":"java.awt.Rectangle[x=1847,y=340,width=92,height=42]","hashcode":471483599,"label":"imupi"}