forked from Konloch/bytecode-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJHexEditorASCII.java
More file actions
141 lines (118 loc) · 3.7 KB
/
Copy pathJHexEditorASCII.java
File metadata and controls
141 lines (118 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.jhe.hexed;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Created by IntelliJ IDEA. User: laullon Date: 09-abr-2003 Time: 12:47:18
*/
public class JHexEditorASCII extends JComponent implements MouseListener,
KeyListener {
private static final long serialVersionUID = 5505374841731053461L;
private JHexEditor he;
public JHexEditorASCII(JHexEditor he) {
this.he = he;
addMouseListener(this);
addKeyListener(this);
addFocusListener(he);
}
public Dimension getPreferredSize() {
debug("getPreferredSize()");
return getMinimumSize();
}
public Dimension getMinimumSize() {
debug("getMinimumSize()");
Dimension d = new Dimension();
FontMetrics fn = getFontMetrics(JHexEditor.font);
int h = fn.getHeight();
int nl = he.getLineas();
d.setSize((fn.stringWidth(" ") + 1) * (16) + (he.border * 2) + 1, h
* nl + (he.border * 2) + 1);
return d;
}
public void paint(Graphics g) {
debug("paint(" + g + ")");
debug("cursor=" + he.cursor + " buff.length=" + he.buff.length);
Dimension d = getMinimumSize();
g.setColor(Color.white);
g.fillRect(0, 0, d.width, d.height);
g.setColor(Color.black);
g.setFont(JHexEditor.font);
// datos ascii
int ini = he.getInicio() * 16;
int fin = ini + (he.getLineas() * 16);
if (fin > he.buff.length)
fin = he.buff.length;
int x = 0;
int y = 0;
for (int n = ini; n < fin; n++) {
if (n == he.cursor) {
g.setColor(Color.blue);
if (hasFocus())
he.fondo(g, x, y, 1);
else
he.cuadro(g, x, y, 1);
if (hasFocus())
g.setColor(Color.white);
else
g.setColor(Color.black);
} else {
g.setColor(Color.black);
}
String s = "" + new Character((char) he.buff[n]);
if ((he.buff[n] < 20) || (he.buff[n] > 126))
s = "" + (char) 16;
he.printString(g, s, (x++), y);
if (x == 16) {
x = 0;
y++;
}
}
}
private void debug(String s) {
if (he.DEBUG)
System.out.println("JHexEditorASCII ==> " + s);
}
// calcular la posicion del raton
public int calcularPosicionRaton(int x, int y) {
FontMetrics fn = getFontMetrics(JHexEditor.font);
x = x / (fn.stringWidth(" ") + 1);
y = y / fn.getHeight();
debug("x=" + x + " ,y=" + y);
return x + ((y + he.getInicio()) * 16);
}
// mouselistener
public void mouseClicked(MouseEvent e) {
debug("mouseClicked(" + e + ")");
he.cursor = calcularPosicionRaton(e.getX(), e.getY());
this.requestFocus();
he.repaint();
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
// KeyListener
public void keyTyped(KeyEvent e) {
/*
* debug("keyTyped("+e+")");
*
* he.buff[he.cursor]=(byte)e.getKeyChar();
*
* if(he.cursor!=(he.buff.length-1)) he.cursor++; he.repaint();
*/
}
public void keyPressed(KeyEvent e) {
debug("keyPressed(" + e + ")");
he.keyPressed(e);
}
public void keyReleased(KeyEvent e) {
debug("keyReleased(" + e + ")");
}
public boolean isFocusTraversable() {
return true;
}
}