FileDocCategorySizeDatePackage
JHexEditorHEX.javaAPI Docmp4parser 1.0-RC-174589Wed Dec 19 20:10:21 GMT 2012com.coremedia.iso.gui.hex

JHexEditorHEX

public class JHexEditorHEX extends JComponent implements MouseListener, KeyListener
Shows the left part of the hex editor. Hex view.

Fields Summary
private JHexEditor
he
private int
cursor
Constructors Summary
public JHexEditorHEX(JHexEditor he)


       
        this.he = he;
        addMouseListener(this);
        addKeyListener(this);
        addFocusListener(he);
    
Methods Summary
public intcalcularPosicionRaton(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);
    
private voiddebug(java.lang.String s)

        if (he.DEBUG) System.out.println("JHexEditorHEX ==> " + s);
    
public java.awt.DimensiongetMaximumSize()

        debug("getMaximumSize()");
        return getMinimumSize();
    
public java.awt.DimensiongetMinimumSize()

        debug("getMinimumSize()");

        Dimension d = new Dimension();
        FontMetrics fn = getFontMetrics(JHexEditor.font);
        int h = fn.getHeight();
        int nl = he.getNumberOfVisibleLines();
        d.setSize(((fn.stringWidth(" ") + 1) * +((16 * 3) - 1)) + (he.border * 2) + 1, h * nl + (he.border * 2) + 1);
        return d;
    
public java.awt.DimensiongetPreferredSize()

        debug("getPreferredSize()");
        return getMinimumSize();
    
public booleanisFocusable()

        return true;
    
public voidkeyPressed(java.awt.event.KeyEvent e)

        debug("keyPressed(" + e + ")");
        he.keyPressed(e);
    
public voidkeyReleased(java.awt.event.KeyEvent e)

        debug("keyReleased(" + e + ")");
    
public voidkeyTyped(java.awt.event.KeyEvent e)



    
public voidmouseClicked(java.awt.event.MouseEvent e)

        debug("mouseClicked(" + e + ")");
        he.cursor = calcularPosicionRaton(e.getX(), e.getY());
        this.requestFocus();
        he.repaint();
    
public voidmouseEntered(java.awt.event.MouseEvent e)

    
public voidmouseExited(java.awt.event.MouseEvent e)

    
public voidmousePressed(java.awt.event.MouseEvent e)

    
public voidmouseReleased(java.awt.event.MouseEvent e)

    
public voidpaint(java.awt.Graphics g)

        debug("paint(" + g + ")");
        debug("cursor=" + he.cursor + " buff.length=" + he.buff.limit());
        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;
        long fin = ini + (he.getNumberOfVisibleLines() * 16);
        if (fin > he.buff.limit()) fin = he.buff.limit();

        //datos hex
        int x = 0;
        int y = 0;
        he.buff.position(ini);
        for (int n = ini; n < fin; n++) {
            if (n == he.cursor) {
                if (hasFocus()) {
                    g.setColor(Color.black);
                    he.filledCursor(g, (x * 3), y, 2);
                    g.setColor(Color.blue);
                    he.filledCursor(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.get()));
            s = s.substring(s.length() - 2);
            he.printString(g, s, ((x++) * 3), y);
            if (x == 16) {
                x = 0;
                y++;
            }
        }