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

JHexEditorASCII

public class JHexEditorASCII extends JComponent implements MouseListener, KeyListener
Shows the right part of the hex editor. ASCII view.

Fields Summary
private JHexEditor
he
Constructors Summary
public JHexEditorASCII(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);
        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("JHexEditorASCII ==> " + s);
    
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) + (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)


    
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);

        //datos ascii
        int ini = he.getInicio() * 16;
        long fin = ini + (he.getNumberOfVisibleLines() * 16);
        if (fin > he.buff.limit()) fin = he.buff.limit();

        int x = 0;
        int y = 0;

        he.buff.position(ini);

        for (int n = ini; n < fin; n++) {
            if (n == he.cursor) {
                g.setColor(Color.blue);
                if (hasFocus()) he.filledCursor(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 = Iso8859_1.convert(new byte[]{he.buff.get()});
//      if ((he.buff[n] < 20) || (he.buff[n] > 126)) s = "" + (char) 16;
            he.printString(g, s, (x++), y);
            if (x == 16) {
                x = 0;
                y++;
            }
        }