View Javadoc
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 org.mythsim.swing.*; 23 import javax.swing.*; 24 import javax.swing.*; 25 import javax.swing.text.*; 26 import java.io.*; 27 import java.net.*; 28 import java.awt.*; 29 import java.util.regex.*; 30 31 /*** 32 * The Ucode File Window. 33 * @author Jason Vroustouris 34 */ 35 public class MicrocodeSourceFrame extends MythPlugInFrame { 36 int marker[]; 37 int codeMarker[]; 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 JScrollPane jScrollPane = new JScrollPane(jTextPane); 50 Highlighter hl = jTextPane.getHighlighter(); 51 EditorKit ek = jTextPane.getEditorKit(); 52 public MicrocodeSourceFrame(MythSimSwing a, JFrame owner) { 53 super("Ucode File", // title 54 true, // resizable 55 true, // closable 56 true, // maximizable 57 true, // iconifiable 58 600, // set size x 59 300, // set size y 60 0, // set location x 61 300, // set location y 62 a, 63 owner); // MythSim object 64 getContentPane().add(jScrollPane); 65 jTextPane.setEditable(false); 66 jTextPane.setFont(new Font("Courier", Font.PLAIN, 12)); 67 jTextPane.setPreferredSize(new Dimension(10,10)); 68 } 69 public void setup() { 70 try { 71 jTextPane.setText(ms.getMicrocodeSource()); 72 String a = jTextPane.getText(); 73 String aa = jTextPane.getText(); 74 String ls = System.getProperty("line.separator"); 75 a = a.replaceAll(ls,"\n"); 76 String b[] = a.split(ls); 77 int currentLoc = 0; 78 //codeString = a.split(";"); 79 codeString = this.splitControlStrings(a); 80 //System.out.println(codeString.length); 81 codeMarker = new int[codeString.length]; 82 for (int i=0; i<codeString.length; i++) { 83 codeString[i]+=";"; 84 codeMarker[i]=currentLoc; 85 currentLoc+=(codeString[i].length()); 86 } 87 88 } catch (Throwable t) { 89 jTextPane.setText("Ucode file not found."); 90 } 91 } 92 93 /*** 2002-11-12: HACK to fix ";" in comment bug. **/ 94 private String[] splitControlStrings(String a) { 95 String temp[] = new String[1000]; 96 int currentCommand = 0; 97 temp[0] = ""; 98 int scan = 0; 99 int comment = 0; 100 for (int i = 0; i < a.length(); i++) { 101 if (scan == 0) { 102 if (a.charAt(i) == ';') { 103 currentCommand++; 104 temp[currentCommand] = ""; 105 } 106 else if (a.charAt(i) == '/' && a.charAt(i + 1) == '/') { 107 temp[currentCommand] += a.charAt(i); 108 scan = 1; 109 } 110 else { 111 temp[currentCommand] += a.charAt(i); 112 } 113 } else { 114 temp[currentCommand] += a.charAt(i); 115 if (a.charAt(i) == '\n') { 116 scan = 0; 117 } 118 } 119 } 120 return temp; 121 } 122 123 public void step() { 124 setAddress(ms.getStatus(MythSimSwing.CURRENT_ADDRESS)); 125 } 126 127 public void setAddress(int a) { 128 selectAddress(a,this.SELECTION_COLOR_UCODE); 129 } 130 /* FOR TESTING 131 public void setAddressTester(int a) { 132 for (int i=0; i<=a; i++) { 133 switch(i % 4) { 134 case 0: 135 selectAddress(i, new Color(250, 200, 200)); 136 break; 137 case 1: 138 selectAddress(i, new Color(250, 250, 200)); 139 break; 140 case 2: 141 selectAddress(i, new Color(200, 250, 200)); 142 break; 143 case 3: 144 selectAddress(i, new Color(200, 200, 250)); 145 break; 146 } 147 } 148 } 149 */ 150 151 void selectAddress(int a, Color b) { 152 int hStart = 0; 153 int hStop = 0; 154 String s = codeString[a]; 155 char sa[] = s.toCharArray(); 156 int scan = 0; 157 int comment = 0; 158 for (int i = 0; i < sa.length; i++) { 159 if (scan == 0) { 160 if (sa[i] == ';') { 161 hStop=i+1; 162 } 163 else if (sa[i] == '/' && sa[i + 1] == '/') { 164 scan = 1; 165 } 166 } 167 else { 168 if (sa[i] == '\n') { 169 scan = 0; 170 hStart = i; 171 } 172 } 173 } 174 try { 175 hl.removeAllHighlights(); 176 hl.addHighlight(codeMarker[a]+hStart,codeMarker[a]+hStop,new DefaultHighlighter.DefaultHighlightPainter(b)); 177 jTextPane.select(codeMarker[a]+hStart,codeMarker[a]+hStop); 178 } catch (Throwable t) { 179 } 180 } 181 /* TESTING VERSION 182 void selectAddress(int a, Color b) { 183 int hStart = 0; 184 int hStop = 0; 185 String s = codeString[a]; 186 char sa[] = s.toCharArray(); 187 //TESTING int scan = 0; 188 int scan = 0; 189 int comment = 0; 190 for (int i=0; i<sa.length; i++) { 191 if (scan == 0) { 192 switch(sa[i]) { 193 case '/': 194 comment++; 195 if (comment==2) { 196 scan = 1; 197 } 198 //TESTING 199 break; 200 case ';': hStop=i+1; break; 201 default: comment=0; break; 202 } 203 } else { 204 if (sa[i] == '\n') { 205 scan = 0; 206 hStart = i; 207 } 208 } 209 } 210 try { 211 //TESTING hl.removeAllHighlights(); 212 //hl.addHighlight(codeMarker[a]+hStart,codeMarker[a]+hStop,new DefaultHighlighter.DefaultHighlightPainter(b)); 213 hl.addHighlight(codeMarker[a],codeMarker[a+1],new DefaultHighlighter.DefaultHighlightPainter(b)); 214 jTextPane.select(codeMarker[a]+hStart,codeMarker[a]+hStop); 215 } catch (Throwable t) { 216 } 217 } */ 218 219 220 }

This page was automatically generated by Maven