001: /*
002: * ListRegistersBuffer.java
003: *
004: * Copyright (C) 2002 Peter Graves
005: * $Id: ListRegistersBuffer.java,v 1.2 2002/10/11 16:29:37 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.util.Arrays;
025:
026: public final class ListRegistersBuffer extends Buffer {
027: public ListRegistersBuffer() {
028: supportsUndo = false;
029: type = TYPE_OUTPUT;
030: mode = ListRegistersMode.getMode();
031: formatter = mode.getFormatter(this );
032: lineSeparator = System.getProperty("line.separator");
033: readOnly = true;
034: setTransient(true);
035: setProperty(Property.VERTICAL_RULE, 0);
036: setProperty(Property.SHOW_LINE_NUMBERS, false);
037: setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
038: setProperty(Property.HIGHLIGHT_BRACKETS, false);
039: setInitialized(true);
040: }
041:
042: public int load() {
043: if (!isLoaded()) {
044: loadInternal();
045: if (!isLoaded())
046: Debug.bug();
047: }
048: return LOAD_COMPLETED;
049: }
050:
051: public void reload() {
052: for (EditorIterator it = new EditorIterator(); it.hasNext();) {
053: Editor ed = it.nextEditor();
054: if (ed.getBuffer() == this ) {
055: ed.setWaitCursor();
056: ed.saveView();
057: }
058: }
059: empty();
060: loadInternal();
061: for (EditorIterator it = new EditorIterator(); it.hasNext();) {
062: Editor ed = it.nextEditor();
063: if (ed.getBuffer() == this ) {
064: View view = ed.getView(this );
065: if (view != null) {
066: Line dotLine = getLine(view.getDotLineNumber());
067: if (dotLine == null)
068: dotLine = getFirstLine();
069: if (dotLine != null) {
070: ed.setDot(dotLine, 0);
071: ed.moveCaretToDotCol();
072: }
073: Line topLine = getLine(view.getTopLineNumber());
074: if (topLine == null)
075: topLine = dotLine;
076: ed.setTopLine(topLine);
077: } else {
078: ed.setDot(getFirstLine(), 0);
079: ed.moveCaretToDotCol();
080: ed.setTopLine(getFirstLine());
081: }
082: ed.setUpdateFlag(REPAINT);
083: ed.setDefaultCursor();
084: ed.updateDisplay();
085: }
086: }
087: }
088:
089: private void loadInternal() {
090: String[] names = null;
091: File directory = Directories.getRegistersDirectory();
092: if (directory != null)
093: names = directory.list();
094: try {
095: lockWrite();
096: } catch (InterruptedException e) {
097: Log.debug(e);
098: return;
099: }
100: try {
101: if (names != null && names.length > 0) {
102: Arrays.sort(names);
103: final int MAX_LINES = 100;
104: for (int i = 0; i < names.length; i++) {
105: final String name = names[i];
106: FastStringBuffer sb = new FastStringBuffer();
107: sb.append("Register ");
108: sb.append(name);
109: String text = Registers.getText(name, MAX_LINES);
110: if (text == null || text.length() == 0)
111: continue;
112: int lineCount = Utilities.countLines(text);
113: appendLine(new ListRegistersLine(sb.toString(),
114: name));
115: append(text);
116: if (lineCount == MAX_LINES)
117: appendLine(new ListRegistersLine("[...]", name));
118: }
119: } else
120: appendLine(new ListRegistersLine("No registers in use",
121: null));
122: renumber();
123: setLoaded(true);
124: } finally {
125: unlockWrite();
126: }
127: }
128:
129: public String getFileNameForDisplay() {
130: return "listRegisters";
131: }
132:
133: public String toString() {
134: return "listRegisters";
135: }
136: }
|