Click here to Skip to main content
15,884,176 members
Articles / Web Development / HTML

Java Class Viewer

Rate me:
Please Sign up or sign in to vote.
4.93/5 (41 votes)
21 Jun 2016MIT8 min read 178.1K   7.8K   96  
Watch the Java class file visually & interactively for the meaning of every byte
/*
 * JRowViewer.java    September 12, 2007, 2:28 PM
 *
 * Copyright  2007, FreeInternals.org. All rights reserved.
 * Use is subject to license terms.
 */
package org.freeinternals.commonlib.ui.binviewer;

import org.freeinternals.commonlib.ui.HTMLKit;
import java.awt.Component;
import javax.swing.JTextPane;
import org.freeinternals.commonlib.ui.JBinaryViewer;

/**
 *
 * @author Amos Shi
 * @since JDK 6.0
 */
public class JRowViewer extends JTextPane {

    private static final long serialVersionUID = 4876543219876500000L;
    public static final int WIDTH_VALUE = 110;

    public JRowViewer() {
        super();
        this.setAlignmentX(Component.LEFT_ALIGNMENT);
        this.setEditable(false);
        this.setBorder(null);
        this.setContentType("text/html");
    }

    public void setData(final int rowStart, final int rowCount, final int rowMax) {

        // Update contents
        this.setText(null);
        if (rowCount <= 0) {
            return;
        }
        if (rowStart >= rowMax) {
            return;
        }

        StringBuilder sb = new StringBuilder(1024);
        sb.append(HTMLKit.Start());

        int rowValue = rowStart * JBinaryViewer.ROW_ITEM_MAX;
        for (int i = 0; i < rowCount; i++) {
            if ((rowStart + i) < rowMax) {
                sb.append(HTMLKit.Span(String.format("%08Xh\n", rowValue)));
                sb.append(HTMLKit.NewLine());
                rowValue += JBinaryViewer.ROW_ITEM_MAX;
            }
        }

        sb.append(HTMLKit.End());
        this.setText(sb.toString());
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
United States United States
Deliver useful software to the world.

Comments and Discussions