⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 breakpointsframe.java

📁 JPC: x86 PC Hardware Emulator. 牛津大学开发的一个纯JAVA的x86系统结构硬件模拟器。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public class Breakpoint implements Comparable<Breakpoint>    {        private int address;        private boolean isPrimary;        private String name;        Breakpoint(int addr)        {            this(addr, false);        }        Breakpoint(int addr, boolean prim)        {            address = addr;            isPrimary = prim;            name = "";        }                public boolean equals(Object another)        {            if (!(another instanceof Breakpoint))                return false;            return address == ((Breakpoint) another).address;        }        public int compareTo(Breakpoint bp)        {            return address - bp.address;        }        public String getName()        {            return name;        }                public int getAddress()        {            return address;        }        public boolean isPrimary()        {            return isPrimary;        }    }    class BPModel extends BasicTableModel    {        BPModel()        {            super(new String[]{"Address", "Name", "Primary"}, new int[]{100, 250, 100});        }                public int getRowCount()        {            return breakpoints.size();        }        public boolean isCellEditable(int row, int column)        {            return true;        }        public Class getColumnClass(int col)        {            if (col == 2)                return Boolean.class;            return String.class;        }        public void setValueAt(Object obj, int row, int column)        {            Breakpoint bp = breakpoints.elementAt(row);            if (column == 0)            {                try                {                    int addr = (int) Long.parseLong(obj.toString().toLowerCase(), 16);                    bp.address = addr;                }                catch (Exception e) {}            }            else if (column == 2)                bp.isPrimary = ((Boolean) obj).booleanValue();            else if (column == 1)                bp.name = obj.toString();            int selected = sortBreakpoints(row);            JPC.getInstance().refresh();            if (selected >= 0)            {                bpTable.setRowSelectionInterval(selected, selected);                Rectangle rect = bpTable.getCellRect(selected, 0, true);                bpTable.scrollRectToVisible(rect);            }            edited = true;        }        public Object getValueAt(int row, int column)        {            Breakpoint bp = breakpoints.elementAt(row);            switch (column)            {            case 0:                return MemoryViewPanel.zeroPadHex(bp.address, 8);            case 1:                return bp.name;            case 2:                return new Boolean(bp.isPrimary);            default:                return "";            }        }    }    private int sortBreakpoints(int selectedRow)    {        int addr = -1;        if (selectedRow >= 0)            addr = breakpoints.elementAt(selectedRow).address;        Breakpoint[] buffer = new Breakpoint[breakpoints.size()];        breakpoints.toArray(buffer);        Arrays.sort(buffer);        int result = -1;        breakpoints.removeAllElements();        for (int i=0; i<buffer.length; i++)        {            if (buffer[i].address == addr)                result = i;            breakpoints.add(buffer[i]);        }        return result;    }    public boolean importBreakpoints(String fileName, boolean ignoreDots)    {        FileInputStream fin = null;        breakpoints.removeAllElements();        try        {            File f = new File(fileName);            if (!f.exists())                return false;            fin = new FileInputStream(f);            DataInputStream din = new DataInputStream(fin);            while (true)            {                String line = din.readLine();                if (line == null)                    break;                try                {                    int space = line.indexOf(" ");                    String hexAddress = line.substring(0, space).trim();                    String name = line.substring(space+1).trim();                                        if (name.startsWith(".") && ignoreDots)                        continue;                    int addr = Integer.parseInt(hexAddress, 16);                    Breakpoint bp = new Breakpoint(addr, false);                    bp.name = name;                    breakpoints.add(bp);                }                catch (Exception e) {}            }        }        catch (EOFException e) {}        catch (Exception e)        {            System.out.println("Warning: failed to import breakpoints");            e.printStackTrace();            alert("Error importing breakpoints from "+fileName+": "+e, JOptionPane.ERROR_MESSAGE);            return false;        }        finally        {            try            {                fin.close();            }            catch (Exception e) {}            sortBreakpoints(-1);            edited = true;        }             return true;    }    public void loadBreakpoints()    {        FileInputStream fin = null;        breakpoints.removeAllElements();        try        {            File f = new File(breakpointFileName);            if (!f.exists())                return;            fin = new FileInputStream(f);            DataInputStream din = new DataInputStream(fin);                        if (din.readLong() != BREAKPOINT_MAGIC)                throw new IOException("Magic number mismatch");            while (true)            {                int addr = din.readInt();                boolean primary = din.readBoolean();                String name = din.readUTF();                Breakpoint bp = new Breakpoint(addr, primary);                bp.name = name;                breakpoints.add(bp);            }        }        catch (EOFException e)         {            setTitle("Breakpoints: "+breakpointFileName);        }        catch (Exception e)        {            System.out.println("Warning: failed to load breakpoints");            e.printStackTrace();            setTitle("Breakpoints: "+breakpointFileName+" ERROR");            alert("Error loading breakpoints: "+e, JOptionPane.ERROR_MESSAGE);        }        finally        {            try            {                fin.close();            }            catch (Exception e) {}            sortBreakpoints(-1);            edited = false;        }           }    public void saveBreakpoints()    {        FileOutputStream out = null;        try        {            out = new FileOutputStream(breakpointFileName);            DataOutputStream dout = new DataOutputStream(out);            dout.writeLong(BREAKPOINT_MAGIC);            for (int i=0; i<breakpoints.size(); i++)            {                Breakpoint bp = breakpoints.elementAt(i);                dout.writeInt(bp.address);                dout.writeBoolean(bp.isPrimary);                dout.writeUTF(bp.name);            }                        setTitle("Breakpoints: "+breakpointFileName);        }        catch (Exception e)        {            System.out.println("Warning: failed to save breakpoints");            e.printStackTrace();            setTitle("Breakpoints: "+breakpointFileName+" ERROR");            alert("Error saving breakpoints: "+e, JOptionPane.ERROR_MESSAGE);        }        finally        {            try            {                out.close();            }            catch (Exception e) {}            edited = false;        }     }    public void PCCreated() {}    public void PCDisposed() {}        public void executionStarted() {}    public void executionStopped() {}    public void refreshDetails()    {        model.fireTableDataChanged();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -