/** * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles * Enumeration of StyleRanges, need to be in order. (output) LineStyleEvent.background line * background color (output) */ public void lineGetStyle(LineStyleEvent event) { Vector styles = new Vector(); int token; StyleRange lastStyle; // If the line is part of a block comment, create one style for the entire line. if (inBlockComment(event.lineOffset, event.lineOffset + event.lineText.length())) { styles.addElement( new StyleRange(event.lineOffset, event.lineText.length(), getColor(COMMENT), null)); event.styles = new StyleRange[styles.size()]; styles.copyInto(event.styles); return; } Color defaultFgColor = ((Control) event.widget).getForeground(); scanner.setRange(event.lineText); token = scanner.nextToken(); while (token != EOF) { if (token == OTHER) { // do nothing for non-colored tokens } else if (token != WHITE) { Color color = getColor(token); // Only create a style if the token color is different than the // widget's default foreground color and the token's style is not // bold. Keywords are bolded. if ((!color.equals(defaultFgColor)) || (token == KEY)) { StyleRange style = new StyleRange( scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null); if (token == KEY) { style.fontStyle = SWT.BOLD; } if (styles.isEmpty()) { styles.addElement(style); } else { // Merge similar styles. Doing so will improve performance. lastStyle = (StyleRange) styles.lastElement(); if (lastStyle.similarTo(style) && (lastStyle.start + lastStyle.length == style.start)) { lastStyle.length += style.length; } else { styles.addElement(style); } } } } else if ((!styles.isEmpty()) && ((lastStyle = (StyleRange) styles.lastElement()).fontStyle == SWT.BOLD)) { int start = scanner.getStartOffset() + event.lineOffset; lastStyle = (StyleRange) styles.lastElement(); // A font style of SWT.BOLD implies that the last style // represents a java keyword. if (lastStyle.start + lastStyle.length == start) { // Have the white space take on the style before it to // minimize the number of style ranges created and the // number of font style changes during rendering. lastStyle.length += scanner.getLength(); } } token = scanner.nextToken(); } event.styles = new StyleRange[styles.size()]; styles.copyInto(event.styles); }
// ParserListener methods public void noteEvent(Note note) { if (layer >= staves) { return; } // System.out.println(note.getMusicString() + " " + note.getMillisDuration() + " " + // note.getDecimalDuration()); Vector<Chord> currChords = chords[layer]; Iterator<NotePanel> currNote = currNotes[layer]; if (!currNote.hasNext()) { System.err.println("Received noteEvent, but no PostScript notes are left"); return; } if (note.getMillisDuration() > 0) { NotePanel notePanel = currNote.next(); // time the last chord ended long tempTime = 0; for (int i = currChords.size() - 1; i >= 0; --i) { if (!currChords.get(i).isTie()) { tempTime = currChords.get(i).getTime() + currChords.get(i).getDuration(); break; } } if (notePanel.isTie) { Chord chord = new Chord(); // for each note in the last chord, set the next note as a tied note for (int i = 0; i < currChords.lastElement().size(); ++i) { notePanel.setTie(true).setTime(Math.min(tempTime, time - 1)).setTempo(tempo); chord.addNote(notePanel); notePanel = currNote.next(); } currChords.add(chord); } while (notePanel.isRest) { notePanel .setTime(Math.min(tempTime, time - 1)) // hack, in case the rest should be trimmed .setTempo(tempo); tempTime += notePanel.getDuration(); Chord chord = new Chord(notePanel); currChords.add(chord); // System.out.println("REST: " + notePanel.getMusicString() + " " + // notePanel.getDuration()); notePanel = currNote.next(); } notePanel.setNote(note).setTime(time).setTempo(tempo); if (currChords.isEmpty() || currChords.lastElement().getTime() != time) { Chord chord = new Chord(notePanel); currChords.add(chord); } else { currChords.lastElement().addNote(notePanel); } } }
/** * This method takes care of some special generic Maui events. It should be called before the Maui * application handles the event. * * @param mauiApp Reference to the MauiApplication associated with the events * @param eventVector The same event vector that is passed to the Maui app. * @param paramHash Hashtable of HTTP parameters * @param response The HTTPResponse object which will be sent back to the client */ private void processEvent( MauiApplication mauiApp, Vector eventVector, Hashtable paramHash, HTTPRequest request, HTTPResponse response) { boolean passEventToMauiApp = true; try { if (eventVector != null && !eventVector.isEmpty()) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Component events // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - String componentID = (String) eventVector.lastElement(); // If there are parentheses... if (componentID.startsWith("(") && componentID.endsWith(")")) { // ... strip them off! componentID = componentID.substring(1, componentID.length() - 1); } // // Strip off prefix - some wml browsers don't like variables that begin with a digit // if (componentID.startsWith("IDz")) { componentID = componentID.substring(3); } { System.err.println("componentID: " + componentID); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Pass events to Maui application // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Check for a content-type override String contentType = null; { if ((contentType = request.getQueryValue("contentType")) != null) { response.setContentType(contentType); } else { response.setContentType("x-wap.wml"); } } response.setContent(mauiApp.render().getBytes()); } else { response.setContentType("text/vnd.wap.wml"); response.setContent(mauiApp.render().getBytes()); } } catch (Exception e) { response.setContentType(getBaseContentType()); response.setContent((generateExceptionMessage(e)).getBytes()); e.printStackTrace(System.err); } }
private void process_args(String[] args) { Vector source_names = new Vector(); for (int i = 0; i < args.length; i++) { String arg = args[i]; if (isFlag(arg)) process_flag(arg); else source_names.addElement(arg); } _destination_name = (String) source_names.lastElement(); int n_sources = source_names.size() - 1; if (n_sources == 0) throw new NakshException( "The arguments to cp must include a " + "destination file or directory, and at " + "least one source file or directory."); _sources = new Vector(n_sources); for (int i = 0; i < n_sources; i++) { String source_name = (String) source_names.elementAt(i); _sources.addElement(File.create(source_name)); } }
/** * ********************************************************************** Parse the .ini file * indicated by the <code>private String iniFile</code>. */ private void parseFile() { try { BufferedReader fp = new BufferedReader(new InputStreamReader(new FileInputStream(iniFile))); boolean done = false; while (!done) { String thisLine = fp.readLine().trim(); if (thisLine != null) { if (Debug) System.out.println("Read: \"" + thisLine + "\""); if (thisLine.startsWith(";") || thisLine.equalsIgnoreCase("")) { // Do nothing, it's a comment if (Debug) System.out.println("Ignoring comment or blank line..."); } else { int cindx = thisLine.indexOf(";"); if (cindx > 0) thisLine = thisLine.substring(0, cindx).trim(); if (Debug) System.out.println("Comments removed: \"" + thisLine + "\""); if (thisLine.startsWith("[") && thisLine.endsWith("]")) { String sname = thisLine.substring(1, thisLine.length() - 1).trim(); if (Debug) System.out.println("Found Section Name: " + sname); if (sectionNames == null) sectionNames = new Vector(); sectionNames.add(sname); if (sectionProperties == null) sectionProperties = new Vector(); sectionProperties.add(new Vector()); } else if (sectionNames != null && sectionProperties != null) { int eqidx = thisLine.indexOf("="); if (eqidx != -1) { String pair[] = new String[2]; pair[0] = thisLine.substring(0, eqidx).trim(); pair[1] = thisLine.substring(eqidx + 1, thisLine.length()).trim(); if (Debug) System.out.println("pair[0]: \"" + pair[0] + "\" pair[1]: \"" + pair[1] + "\""); // Add the pair to the current property list, which is the // last element in the sectionProperties vector. ((Vector) sectionProperties.lastElement()).add(pair); } } } } else { done = true; } } fp.close(); } catch (FileNotFoundException e) { System.err.println("Could Not Find ini File: \"" + iniFile + "\""); } catch (IOException e) { System.err.println("Could Not Read ini File: \"" + iniFile + "\""); } }
/** Returns the value of the function to the top of the stack. */ public void returnFromFunction() throws ProgramException { // make sure that there's somewhere to return to (old local <> 0) if (stackSegment.getValueAt(Definitions.LOCAL_POINTER_ADDRESS) == 0) throw new ProgramException( "Nowhere to return to in " + getCallStack().getTopFunction() + "." + getCurrentInstruction().getIndexInFunction()); // done in order to clear the method stack's contents workingStackSegment.setStartAddress(getSP()); bus.send(ram, Definitions.LOCAL_POINTER_ADDRESS, ram, Definitions.R13_ADDRESS); // R13 = lcl bus.send( stackSegment, stackSegment.getValueAt(Definitions.LOCAL_POINTER_ADDRESS) - 5, ram, Definitions.R14_ADDRESS); // R14 = return address bus.send( stackSegment, getSP() - 1, stackSegment, ram.getValueAt(Definitions.ARG_POINTER_ADDRESS)); // *arg = return value setSP((short) (ram.getValueAt(Definitions.ARG_POINTER_ADDRESS) + 1)); // SP = arg + 1 bus.send( stackSegment, ram.getValueAt(Definitions.R13_ADDRESS) - 1, ram, Definitions.THAT_POINTER_ADDRESS); // that = *(R13 - 1) bus.send( stackSegment, ram.getValueAt(Definitions.R13_ADDRESS) - 2, ram, Definitions.THIS_POINTER_ADDRESS); // this = *(R13 - 2) bus.send( stackSegment, ram.getValueAt(Definitions.R13_ADDRESS) - 3, ram, Definitions.ARG_POINTER_ADDRESS); // arg = *(R13 - 3) bus.send( stackSegment, ram.getValueAt(Definitions.R13_ADDRESS) - 4, ram, Definitions.LOCAL_POINTER_ADDRESS); // lcl = *(R13 - 4) // removes the top function from the call stack callStack.popFunction(); // check whether there is a "calling frame" if (stackFrames.size() > 0) { // retrieve stack frame address of old function int frameAddress = ((Integer) stackFrames.lastElement()).intValue(); stackFrames.removeElementAt(stackFrames.size() - 1); workingStackSegment.setStartAddress(frameAddress); // disable non relevant range of the local segment - enable only the locals // of the function that we returned to. localSegment.setEnabledRange( Math.max(localSegment.getStartAddress(), Definitions.STACK_START_ADDRESS), frameAddress - 1, true); // enable in the arg segment only the number of args that were sent to the function // that we returned to. argSegment.setEnabledRange( argSegment.getStartAddress(), localSegment.getStartAddress() - 6, true); // enable this, that according to their retrieved pointers thisSegment.setEnabledRange( Math.max(thisSegment.getStartAddress(), Definitions.HEAP_START_ADDRESS), Definitions.HEAP_END_ADDRESS, true); thatSegment.setEnabledRange( Math.max(thatSegment.getStartAddress(), Definitions.HEAP_START_ADDRESS), Definitions.SCREEN_END_ADDRESS, true); } /* else { error("Nowhere to return to"); } */ // Allow return if we previously had "function" even with no call - // For the SimpleFunction test short returnAddress = ram.getValueAt(Definitions.R14_ADDRESS); if (returnAddress == VMProgram.BUILTIN_FUNCTION_ADDRESS) { staticSegment.setEnabledRange(0, -1, true); // empty static segment builtInFunctionsRunner.returnToBuiltInFunction(popValue(METHOD_STACK)); } else if (returnAddress >= 0 && returnAddress < program.getSize()) { // sets the static segment range if (stackFrames.size() > 0) { setStaticRange(callStack.getTopFunction()); } else { staticSegment.setStartAddress(Definitions.VAR_START_ADDRESS); staticSegment.setEnabledRange( Definitions.VAR_START_ADDRESS, Definitions.VAR_END_ADDRESS - 1, true); } program.setPC((short) (returnAddress - 1)); // set previousPC correctly program.setPC(returnAddress); // pc = *sp } else { error("Illegal return address"); } }