1 11 package org.eclipse.ui.internal.console; 12 13 import org.eclipse.jface.text.ITypedRegion; 14 import org.eclipse.swt.custom.StyleRange; 15 import org.eclipse.swt.graphics.Color; 16 import org.eclipse.ui.console.ConsolePlugin; 17 import org.eclipse.ui.console.IOConsoleInputStream; 18 import org.eclipse.ui.console.IOConsoleOutputStream; 19 20 25 public class IOConsolePartition implements ITypedRegion { 26 public static final String OUTPUT_PARTITION_TYPE = ConsolePlugin.getUniqueIdentifier() + ".io_console_output_partition_type"; public static final String INPUT_PARTITION_TYPE = ConsolePlugin.getUniqueIdentifier() + ".io_console_input_partition_type"; 29 32 private StringBuffer buffer; 33 private String type; 34 private int offset; 35 39 private boolean readOnly; 40 41 44 private IOConsoleOutputStream outputStream; 45 private IOConsoleInputStream inputStream; 46 private int length; 47 48 51 public IOConsolePartition(IOConsoleOutputStream outputStream, int length) { 52 this.outputStream = outputStream; 53 this.length = length; 54 this.type = OUTPUT_PARTITION_TYPE; 55 this.readOnly = true; 56 } 57 58 61 public IOConsolePartition(IOConsoleInputStream inputStream, String text) { 62 this.inputStream = inputStream; 63 buffer = new StringBuffer (text); 64 length = text.length(); 65 this.type = INPUT_PARTITION_TYPE; 66 this.readOnly = false; 67 } 68 69 74 public void insert(String s, int insertOffset) { 75 buffer.insert(insertOffset, s); 76 length += s.length(); 77 } 78 79 84 public void delete(int delOffset, int delLength) { 85 buffer.delete(delOffset, delOffset+delLength); 86 length -= delLength; 87 } 88 89 93 public String getType() { 94 return type; 95 } 96 97 101 public int getLength() { 102 return length; 103 } 104 105 109 public int getOffset() { 110 return offset; 111 } 112 113 117 public void setOffset(int offset) { 118 this.offset = offset; 119 } 120 121 126 public void setLength(int length) { 127 this.length = length; 128 } 129 130 134 public String getString() { 135 return buffer != null ? buffer.toString() : ""; } 137 138 142 public StyleRange getStyleRange(int rangeOffset, int rangeLength) { 143 return new StyleRange(rangeOffset, rangeLength, getColor(), null, getFontStyle()); 144 } 145 146 private int getFontStyle() { 147 if (type.equals(INPUT_PARTITION_TYPE)) { 148 return inputStream.getFontStyle(); 149 } 150 return outputStream.getFontStyle(); 151 } 152 153 public Color getColor() { 154 if (type.equals(INPUT_PARTITION_TYPE)) { 155 return inputStream.getColor(); 156 } 157 return outputStream.getColor(); 158 } 159 160 public boolean isReadOnly() { 161 return readOnly; 162 } 163 164 public void setReadOnly() { 165 readOnly = true; 166 } 167 168 public void clearBuffer() { 169 buffer = null; 170 } 171 172 IOConsoleOutputStream getStream() { 173 return outputStream; 174 } 175 } 176 | Popular Tags |