示例#1
0
文件: HexEdit.java 项目: khyuna/hyun
 @Override
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   int addr = startAddress;
   if (addr > SICXE.MAX_ADDR) return;
   int y = getInsets().top + lineHeight;
   int rows = (getHeight() - getInsets().top - getInsets().bottom) / lineHeight;
   for (int row = 0; row < rows; row++) {
     // address
     int x = getInsets().left + COL_ADDR * charWidth;
     g.setColor(Colors.fg);
     g.drawString(Conversion.addrToHex(addr), x, y);
     // hex and chr
     int x1 = getInsets().left + COL_HEX * charWidth;
     int x2 = getInsets().left + COL_CHR * charWidth;
     for (int col = 0; col < 16; col++) {
       // cursor background
       if (addr == cursorAddress) {
         // hex part
         g.setColor(Colors.bg(true, focusOnHex && isFocusOwner()));
         g.fillRect(x1 - 2, y - lineHeight + 3, 2 * charWidth + 4, lineHeight);
         // chr part
         g.setColor(Colors.bg(true, !focusOnHex && isFocusOwner()));
         g.fillRect(x2 - 1, y - lineHeight + 3, charWidth + 2, lineHeight);
       }
       // contents
       // hex part
       g.setColor(Colors.fg(addr == cursorAddress, focusOnHex && isFocusOwner()));
       int b = get(addr);
       if (b < 0) return;
       char[] ch = {'.'};
       if (b >= 0x20 && b < 0x7E) ch[0] = (char) b;
       g.drawString(Conversion.byteToHex(b), x1, y);
       x1 += 3 * charWidth;
       // chr part
       g.setColor(Colors.fg(addr == cursorAddress, !focusOnHex && isFocusOwner()));
       g.drawChars(ch, 0, 1, x2, y);
       x2 += charWidth;
       if (++addr > SICXE.MAX_ADDR) return;
     }
     y += lineHeight;
   }
 }
示例#2
0
文件: HexEdit.java 项目: khyuna/hyun
 @Override
 public void keyTyped(KeyEvent e) {
   if (e.getKeyChar() == KeyEvent.VK_TAB || e.getKeyChar() == KeyEvent.VK_ENTER) return;
   int addr = getCursorAddress();
   if (addr > SICXE.MAX_ADDR) return;
   if (focusOnHex) {
     int val = Conversion.hexToInt(String.valueOf(e.getKeyChar()), -1);
     if (val == -1) return;
     int b = get(addr);
     if (b < 0) return;
     if (firstNibble) b = (b & 0x0F) | ((val & 0x0F) << 4);
     else b = (b & 0xF0) | (val & 0x0F);
     set(addr, b);
     firstNibble = !firstNibble;
     if (firstNibble) moveCursor(1, 0);
   } else {
     set(addr, e.getKeyChar());
     moveCursor(1, 0);
   }
   repaint();
 }