forked from Konloch/bytecode-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJHexEditorHEX.java
More file actions
154 lines (130 loc) · 4.35 KB
/
Copy pathJHexEditorHEX.java
File metadata and controls
154 lines (130 loc) · 4.35 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
142
143
144
145
146
147
148
149
150
151
152
153
154
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:32
*/
public class JHexEditorHEX extends JComponent implements MouseListener,
KeyListener {
private static final long serialVersionUID = 1481995655372014571L;
private JHexEditor he;
private int cursor = 0;
public JHexEditorHEX(JHexEditor he) {
this.he = he;
addMouseListener(this);
addKeyListener(this);
addFocusListener(he);
}
/*
* public Dimension getPreferredSize() { debug("getPreferredSize()"); return
* getMinimumSize(); }
*/
public Dimension getMaximumSize() {
debug("getMaximumSize()");
return getMinimumSize();
}
/*
* public Dimension getMinimumSize() { debug("getMinimumSize()");
*
* Dimension d=new Dimension(); FontMetrics fn=getFontMetrics(he.font); int
* h=fn.getHeight(); int nl=he.getLineas();
* d.setSize(((fn.stringWidth(" ")+1
* )*+((16*3)-1))+(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);
int ini = he.getInicio() * 16;
int fin = ini + (he.getLineas() * 16);
if (fin > he.buff.length)
fin = he.buff.length;
// datos hex
int x = 0;
int y = 0;
for (int n = ini; n < fin; n++) {
if (n == he.cursor) {
if (hasFocus()) {
g.setColor(Color.black);
he.fondo(g, (x * 3), y, 2);
g.setColor(Color.blue);
he.fondo(g, (x * 3) + cursor, y, 1);
} else {
g.setColor(Color.blue);
he.cuadro(g, (x * 3), y, 2);
}
if (hasFocus())
g.setColor(Color.white);
else
g.setColor(Color.black);
} else {
g.setColor(Color.black);
}
String s = ("0" + Integer.toHexString(he.buff[n]));
s = s.substring(s.length() - 2);
he.printString(g, s, ((x++) * 3), y);
if (x == 16) {
x = 0;
y++;
}
}
}
private void debug(String s) {
if (he.DEBUG)
System.out.println("JHexEditorHEX ==> " + s);
}
// calcular la posicion del raton
public int calcularPosicionRaton(int x, int y) {
FontMetrics fn = getFontMetrics(JHexEditor.font);
x = x / ((fn.stringWidth(" ") + 1) * 3);
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 + ")");
/*
* char c=e.getKeyChar();
* if(((c>='0')&&(c<='9'))||((c>='A')&&(c<='F'))||((c>='a')&&(c<='f')))
* { char[] str=new char[2]; String
* n="00"+Integer.toHexString((int)he.buff[he.cursor]); if(n.length()>2)
* n=n.substring(n.length()-2); str[1-cursor]=n.charAt(1-cursor);
* str[cursor]=e.getKeyChar();
* he.buff[he.cursor]=(byte)Integer.parseInt(new String(str),16);
*
* if(cursor!=1) cursor=1; else if(he.cursor!=(he.buff.length-1)){
* he.cursor++; cursor=0;} he.actualizaCursor(); }
*/
}
public void keyPressed(KeyEvent e) {
debug("keyPressed(" + e + ")");
he.keyPressed(e);
}
public void keyReleased(KeyEvent e) {
debug("keyReleased(" + e + ")");
}
public boolean isFocusTraversable() {
return true;
}
}