1 /*
2 * MythSim
3 *
4 * Copyright (C) 2002-2004 Jason Vroustouris <jasonv@jasonv.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 package org.mythsim.swing.plugin;
22 import javax.swing.*;
23 import javax.swing.text.*;
24 import java.io.*;
25 import java.net.*;
26 import java.awt.*;
27 import java.util.regex.*;
28 import org.mythsim.swing.*;
29
30 /***
31 * The Memory File Window.
32 * @author Jason Vroustouris
33 */
34 public class MemorySourceFrame extends MythPlugInFrame {
35 int marker[];
36 int codeMarker[] = new int[256];
37 int codeLength[] = new int[256];
38 String codeString[];
39 JTextPane jTextPane = new JTextPane(){
40 public void setSize(Dimension d){
41 if (d.width < getParent().getSize().width)
42 d.width = getParent().getSize().width;
43 super.setSize(d);
44 }
45 public boolean getScrollableTracksViewportWidth(){
46 return false;
47 }
48 };
49
50 JScrollPane jScrollPane = new JScrollPane(jTextPane);
51 Highlighter hl = jTextPane.getHighlighter();
52 EditorKit ek = jTextPane.getEditorKit();
53
54 public MemorySourceFrame(MythSimSwing a, JFrame owner) {
55 super("Memory File", // title
56 true, // resizable
57 true, // closable
58 true, // maximizable
59 true, // iconifiable
60 200, // set size x
61 300, // set size y
62 0, // set location x
63 300, // set location y
64 a,
65 owner); // MythSim object
66 jTextPane.setEditable(false);
67 jTextPane.setFont(new Font("Courier", Font.PLAIN, 12));
68 jTextPane.setPreferredSize(new Dimension(10,10));
69 setContentPane(jScrollPane);
70 }
71 public void setup() {
72 for (int i=0; i<256; i++) {
73 codeMarker[i] = 0;
74 codeLength[i] = 5;
75 }
76 jTextPane.setText(ms.getMemorySource());
77 }
78 public void step() {
79 setAddress(ms.tc2normal(ms.getStatus(MythSimSwing.MAR)));
80 }
81
82 /*** Select a give address in the source */
83 public void setAddress(int a) {
84 selectAddress(a,this.SELECTION_COLOR_MEM);
85 }
86
87 void selectAddress(int a, Color b) {
88 String file = jTextPane.getText();
89 String ls = System.getProperty("line.separator");
90 file = file.replaceAll(ls,"\n");
91 String line[] = file.split("\n");
92 int lineMarker[] = new int[line.length];
93 int codeMarker[] = new int[256];
94 for (int i=0; i<256; i++) codeMarker[i]=0;
95 int currentMarker = 0;
96 for (int i=0; i<line.length; i++) {
97 lineMarker[i] = currentMarker;
98 String pair[] = line[i].split(":");
99 if (pair.length == 2) {
100 int addr = Integer.parseInt(pair[0]);
101 codeMarker[addr]=i;
102 }
103 currentMarker += line[i].length() + 1;
104 }
105 try {
106 hl.removeAllHighlights();
107 hl.addHighlight(lineMarker[codeMarker[a]],lineMarker[codeMarker[a]+1],new DefaultHighlighter.DefaultHighlightPainter(b));
108 jTextPane.select(lineMarker[codeMarker[a]],lineMarker[codeMarker[a]+1]);
109 } catch (Throwable t) {
110 }
111 }
112 }
This page was automatically generated by Maven