1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-13 12:05:21 +02:00

bug 205260: [terminal] The terminal does not take the font from the preferences

https://bugs.eclipse.org/bugs/show_bug.cgi?id=205260
This commit is contained in:
Michael Scharf 2007-10-13 01:36:50 +00:00
parent 839cf0e907
commit 0114f92c25
7 changed files with 78 additions and 71 deletions

View file

@ -11,7 +11,7 @@
* Helmut Haigermoser and Ted Williams. * Helmut Haigermoser and Ted Williams.
* *
* Contributors: * Contributors:
* Michael Scharf (Wind River) - split into core, view and connector plugins * Michael Scharf (Wind River) - split into core, view and connector plugins
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Martin Oberhuber (Wind River) - fixed copyright headers and beautified
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.emulator; package org.eclipse.tm.internal.terminal.emulator;
@ -43,7 +43,7 @@ import org.eclipse.tm.terminal.model.Style;
* use of screen-oriented applications, such as vi, Emacs, and any GNU * use of screen-oriented applications, such as vi, Emacs, and any GNU
* readline-enabled application (Bash, bc, ncftp, etc.). * readline-enabled application (Bash, bc, ncftp, etc.).
* <p> * <p>
* *
* @author Fran Litterio <francis.litterio@windriver.com> * @author Fran Litterio <francis.litterio@windriver.com>
* @author Chris Thew <chris.thew@windriver.com> * @author Chris Thew <chris.thew@windriver.com>
*/ */
@ -70,7 +70,7 @@ public class VT100Emulator implements ControlListener {
/** /**
* This field holds the current state of the Finite TerminalState Automaton (FSA) * This field holds the current state of the Finite TerminalState Automaton (FSA)
* that recognizes ANSI escape sequences. * that recognizes ANSI escape sequences.
* *
* @see #processNewText() * @see #processNewText()
*/ */
private int ansiState = ANSISTATE_INITIAL; private int ansiState = ANSISTATE_INITIAL;
@ -79,7 +79,7 @@ public class VT100Emulator implements ControlListener {
* This field holds a reference to the {@link TerminalControl} object that * This field holds a reference to the {@link TerminalControl} object that
* instantiates this class. * instantiates this class.
*/ */
private ITerminalControlForText terminal; private final ITerminalControlForText terminal;
/** /**
* This field holds a reference to the StyledText widget that is used to * This field holds a reference to the StyledText widget that is used to
@ -104,13 +104,13 @@ public class VT100Emulator implements ControlListener {
* parsing the escape sequence "\e[20;10H", this array holds the strings * parsing the escape sequence "\e[20;10H", this array holds the strings
* "20" and "10". * "20" and "10".
*/ */
private StringBuffer[] ansiParameters = new StringBuffer[16]; private final StringBuffer[] ansiParameters = new StringBuffer[16];
/** /**
* This field holds the OS-specific command found in an escape sequence of * This field holds the OS-specific command found in an escape sequence of
* the form "\e]...\u0007". * the form "\e]...\u0007".
*/ */
private StringBuffer ansiOsCommand = new StringBuffer(128); private final StringBuffer ansiOsCommand = new StringBuffer(128);
/** /**
* This field holds the index of the next unused element of the array stored * This field holds the index of the next unused element of the array stored
@ -119,7 +119,7 @@ public class VT100Emulator implements ControlListener {
private int nextAnsiParameter = 0; private int nextAnsiParameter = 0;
final Reader fReader; final Reader fReader;
boolean fCrAfterNewLine; boolean fCrAfterNewLine;
/** /**
* The constructor. * The constructor.
@ -147,7 +147,7 @@ public class VT100Emulator implements ControlListener {
text=new VT100BackendTraceDecorator(new VT100EmulatorBackend(data),System.out); text=new VT100BackendTraceDecorator(new VT100EmulatorBackend(data),System.out);
else else
text=new VT100EmulatorBackend(data); text=new VT100EmulatorBackend(data);
// text.setDimensions(24, 80); // text.setDimensions(24, 80);
Style style=Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$ //$NON-NLS-2$ Style style=Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$ //$NON-NLS-2$
text.setDefaultStyle(style); text.setDefaultStyle(style);
@ -181,7 +181,7 @@ public class VT100Emulator implements ControlListener {
/** /**
* This method is required by interface ControlListener. It allows us to * This method is required by interface ControlListener. It allows us to
* know when the StyledText widget is resized. * know when the StyledText widget is resized.
*/ */
public void controlResized(ControlEvent event) { public void controlResized(ControlEvent event) {
Logger.log("entered"); //$NON-NLS-1$ Logger.log("entered"); //$NON-NLS-1$
@ -189,7 +189,7 @@ public class VT100Emulator implements ControlListener {
} }
/** /**
* This method erases all text from the Terminal view. * This method erases all text from the Terminal view.
*/ */
public void clearTerminal() { public void clearTerminal() {
Logger.log("entered"); //$NON-NLS-1$ Logger.log("entered"); //$NON-NLS-1$
@ -209,14 +209,14 @@ public class VT100Emulator implements ControlListener {
} }
// /** // /**
// * This method executes in the Display thread to process data received from // * This method executes in the Display thread to process data received from
// * the remote host by class {@link org.eclipse.tm.internal.terminal.telnet.TelnetConnection} and // * the remote host by class {@link org.eclipse.tm.internal.terminal.telnet.TelnetConnection} and
// * other implementors of {@link ITerminalConnector}, like the // * other implementors of {@link ITerminalConnector}, like the
// * SerialPortHandler. // * SerialPortHandler.
// * <p> // * <p>
// * These connectors write text to the terminal's buffer through // * These connectors write text to the terminal's buffer through
// * {@link TerminalControl#writeToTerminal(String)} and then have // * {@link TerminalControl#writeToTerminal(String)} and then have
// * this run method executed in the display thread. This method // * this run method executed in the display thread. This method
// * must not execute at the same time as methods // * must not execute at the same time as methods
// * {@link #setNewText(StringBuffer)} and {@link #clearTerminal()}. // * {@link #setNewText(StringBuffer)} and {@link #clearTerminal()}.
// * <p> // * <p>
// * IMPORTANT: This method must be called in strict alternation with method // * IMPORTANT: This method must be called in strict alternation with method
@ -256,7 +256,7 @@ public class VT100Emulator implements ControlListener {
/** /**
* This method scans the newly received text, processing ANSI control * This method scans the newly received text, processing ANSI control
* characters and escape sequences and displaying normal text. * characters and escape sequences and displaying normal text.
* @throws IOException * @throws IOException
*/ */
private void processNewText() throws IOException { private void processNewText() throws IOException {
Logger.log("entered"); //$NON-NLS-1$ Logger.log("entered"); //$NON-NLS-1$
@ -342,7 +342,7 @@ public class VT100Emulator implements ControlListener {
ansiState = ANSISTATE_INITIAL; ansiState = ANSISTATE_INITIAL;
moveCursor(savedCursorLine, savedCursorColumn); moveCursor(savedCursorLine, savedCursorColumn);
break; break;
case 'c': case 'c':
// Reset the terminal // Reset the terminal
ansiState = ANSISTATE_INITIAL; ansiState = ANSISTATE_INITIAL;
@ -863,7 +863,7 @@ public class VT100Emulator implements ControlListener {
/** /**
* This method returns one of the numeric ANSI parameters received in the * This method returns one of the numeric ANSI parameters received in the
* most recent escape sequence. * most recent escape sequence.
* *
* @return The <i>parameterIndex</i>th numeric ANSI parameter or -1 if the * @return The <i>parameterIndex</i>th numeric ANSI parameter or -1 if the
* index is out of range. * index is out of range.
*/ */
@ -913,7 +913,7 @@ public class VT100Emulator implements ControlListener {
* append each non-control character individually to the StyledText widget. * append each non-control character individually to the StyledText widget.
* A non-control character is any character that passes the condition in the * A non-control character is any character that passes the condition in the
* below while loop. * below while loop.
* @throws IOException * @throws IOException
*/ */
private void processNonControlCharacters(char character) throws IOException { private void processNonControlCharacters(char character) throws IOException {
StringBuffer buffer=new StringBuffer(); StringBuffer buffer=new StringBuffer();
@ -942,7 +942,7 @@ public class VT100Emulator implements ControlListener {
* view, wrapping text at the right edge of the screen and overwriting text * view, wrapping text at the right edge of the screen and overwriting text
* when the cursor is not at the very end of the screen's text. * when the cursor is not at the very end of the screen's text.
* <p> * <p>
* *
* There are never any ANSI control characters or escape sequences in the * There are never any ANSI control characters or escape sequences in the
* text being displayed by this method (this includes newlines, carriage * text being displayed by this method (this includes newlines, carriage
* returns, and tabs). * returns, and tabs).
@ -987,7 +987,7 @@ public class VT100Emulator implements ControlListener {
* first column of the next line, as if a carriage return (CR) and a NL were * first column of the next line, as if a carriage return (CR) and a NL were
* written. * written.
* <p> * <p>
* *
* UNIX terminals typically display a NL character as a CR followed by a NL * UNIX terminals typically display a NL character as a CR followed by a NL
* because the terminal device typically has the ONLCR attribute bit set * because the terminal device typically has the ONLCR attribute bit set
* (see the termios(4) man page for details), which causes the terminal * (see the termios(4) man page for details), which causes the terminal
@ -1018,7 +1018,7 @@ public class VT100Emulator implements ControlListener {
* the edges of the view window (i.e., the view window does not become * the edges of the view window (i.e., the view window does not become
* larger to accommodate its contents becoming larger). * larger to accommodate its contents becoming larger).
* <p> * <p>
* *
* This method must be called immediately before each time text is written * This method must be called immediately before each time text is written
* to the terminal so that we can properly line wrap text. Because it is * to the terminal so that we can properly line wrap text. Because it is
* called so frequently, it must be fast when there is no resizing to be * called so frequently, it must be fast when there is no resizing to be
@ -1055,7 +1055,7 @@ public class VT100Emulator implements ControlListener {
* This method returns the relative line number of the line containing the * This method returns the relative line number of the line containing the
* cursor. The returned line number is relative to the topmost visible line, * cursor. The returned line number is relative to the topmost visible line,
* which has relative line number 0. * which has relative line number 0.
* *
* @return The relative line number of the line containing the cursor. * @return The relative line number of the line containing the cursor.
*/ */
private int relativeCursorLine() { private int relativeCursorLine() {
@ -1127,7 +1127,7 @@ public class VT100Emulator implements ControlListener {
*/ */
private int fNextChar=-1; private int fNextChar=-1;
private char getNextChar() throws IOException { private char getNextChar() throws IOException {
int c=-1; int c=-1;
if(fNextChar!=-1) { if(fNextChar!=-1) {
c= fNextChar; c= fNextChar;
fNextChar=-1; fNextChar=-1;
@ -1154,7 +1154,7 @@ public class VT100Emulator implements ControlListener {
*/ */
void pushBackChar(char c) { void pushBackChar(char c) {
//assert fNextChar!=-1: "Already a character waiting:"+fNextChar; //$NON-NLS-1$ //assert fNextChar!=-1: "Already a character waiting:"+fNextChar; //$NON-NLS-1$
fNextChar=c; fNextChar=c;
} }
private int getCursorColumn() { private int getCursorColumn() {
return text.getCursorColumn(); return text.getCursorColumn();

View file

@ -458,7 +458,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
} }
// Tell the TerminalControl singleton that the font has changed. // Tell the TerminalControl singleton that the font has changed.
fCtlText.onFontChange();
getTerminalText().fontChanged(); getTerminalText().fontChanged();
} }
public Font getFont() { public Font getFont() {

View file

@ -1,11 +1,11 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others. * Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Michael Scharf (Wind River) - initial API and implementation * Michael Scharf (Wind River) - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.textcanvas; package org.eclipse.tm.internal.terminal.textcanvas;
@ -19,4 +19,5 @@ public interface ILinelRenderer {
int getCellWidth(); int getCellWidth();
int getCellHeight(); int getCellHeight();
void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int colFirst, int colLast); void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int colFirst, int colLast);
void onFontChange();
} }

View file

@ -1,11 +1,11 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others. * Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Michael Scharf (Wind River) - initial API and implementation * Michael Scharf (Wind River) - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.textcanvas; package org.eclipse.tm.internal.terminal.textcanvas;
@ -13,7 +13,6 @@ package org.eclipse.tm.internal.terminal.textcanvas;
/** /**
*/ */
public interface ITextCanvasModelListener { public interface ITextCanvasModelListener {
void cellSizeChanged();
void rangeChanged(int col, int line, int width, int height); void rangeChanged(int col, int line, int width, int height);
void dimensionsChanged(int cols, int rows); void dimensionsChanged(int cols, int rows);
/** /**

View file

@ -1,11 +1,11 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others. * Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Michael Scharf (Wind River) - initial API and implementation * Michael Scharf (Wind River) - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.textcanvas; package org.eclipse.tm.internal.terminal.textcanvas;
@ -23,11 +23,12 @@ import org.eclipse.tm.terminal.model.Style;
import org.eclipse.tm.terminal.model.StyleColor; import org.eclipse.tm.terminal.model.StyleColor;
public class StyleMap { public class StyleMap {
String fFontName=JFaceResources.TEXT_FONT; // TODO propagate the name of the fonf in the FontRegistry
String fFontName="terminal.views.view.font.definition"; //$NON-NLS-1$
Map fColorMap=new HashMap(); Map fColorMap=new HashMap();
Map fFontMap=new HashMap(); Map fFontMap=new HashMap();
private Point fCharSize; private Point fCharSize;
private Style fDefaultStyle; private final Style fDefaultStyle;
StyleMap() { StyleMap() {
Display display=Display.getCurrent(); Display display=Display.getCurrent();
fColorMap.put(StyleColor.getStyleColor("white"), new Color(display,255,255,255)); //$NON-NLS-1$ fColorMap.put(StyleColor.getStyleColor("white"), new Color(display,255,255,255)); //$NON-NLS-1$
@ -49,11 +50,7 @@ public class StyleMap {
fColorMap.put(StyleColor.getStyleColor("MAGENTA"), new Color(display,255,255,0)); //$NON-NLS-1$ fColorMap.put(StyleColor.getStyleColor("MAGENTA"), new Color(display,255,255,0)); //$NON-NLS-1$
fColorMap.put(StyleColor.getStyleColor("GRAY"), new Color(display,128,128,128)); //$NON-NLS-1$ fColorMap.put(StyleColor.getStyleColor("GRAY"), new Color(display,128,128,128)); //$NON-NLS-1$
fDefaultStyle=Style.getStyle(StyleColor.getStyleColor("black"),StyleColor.getStyleColor("white")); //$NON-NLS-1$ //$NON-NLS-2$ fDefaultStyle=Style.getStyle(StyleColor.getStyleColor("black"),StyleColor.getStyleColor("white")); //$NON-NLS-1$ //$NON-NLS-2$
GC gc = new GC (display); updateFont();
gc.setFont(getFont());
fCharSize = gc.textExtent ("W"); //$NON-NLS-1$
gc.dispose ();
} }
public Color getColor(StyleColor colorName) { public Color getColor(StyleColor colorName) {
return (Color) fColorMap.get(colorName); return (Color) fColorMap.get(colorName);
@ -89,14 +86,14 @@ public class StyleMap {
return JFaceResources.getFontRegistry().getBold(fFontName); return JFaceResources.getFontRegistry().getBold(fFontName);
} else if(style.isUnderline()) { } else if(style.isUnderline()) {
return JFaceResources.getFontRegistry().getItalic(fFontName); return JFaceResources.getFontRegistry().getItalic(fFontName);
} }
return JFaceResources.getFontRegistry().get(fFontName); return JFaceResources.getFontRegistry().get(fFontName);
} }
public Font getFont() { public Font getFont() {
return JFaceResources.getFontRegistry().get(fFontName); return JFaceResources.getFontRegistry().get(fFontName);
} }
public int getFontWidth() { public int getFontWidth() {
return fCharSize.x; return fCharSize.x;
@ -104,4 +101,11 @@ public class StyleMap {
public int getFontHeight() { public int getFontHeight() {
return fCharSize.y; return fCharSize.y;
} }
public void updateFont() {
Display display=Display.getCurrent();
GC gc = new GC (display);
gc.setFont(getFont());
fCharSize = gc.textExtent ("W"); //$NON-NLS-1$
gc.dispose ();
}
} }

View file

@ -52,13 +52,6 @@ public class TextCanvas extends GridCanvas {
setCellHeight(fCellRenderer.getCellHeight()); setCellHeight(fCellRenderer.getCellHeight());
fCellCanvasModel=model; fCellCanvasModel=model;
fCellCanvasModel.addCellCanvasModelListener(new ITextCanvasModelListener(){ fCellCanvasModel.addCellCanvasModelListener(new ITextCanvasModelListener(){
public void cellSizeChanged() {
setCellWidth(fCellRenderer.getCellWidth());
setCellHeight(fCellRenderer.getCellHeight());
calculateGrid();
}
public void rangeChanged(int col, int line, int width, int height) { public void rangeChanged(int col, int line, int width, int height) {
repaintRange(col,line,width,height); repaintRange(col,line,width,height);
} }
@ -300,5 +293,12 @@ public class TextCanvas extends GridCanvas {
fResizeListener=listener; fResizeListener=listener;
} }
public void onFontChange() {
fCellRenderer.onFontChange();
setCellWidth(fCellRenderer.getCellWidth());
setCellHeight(fCellRenderer.getCellHeight());
calculateGrid();
}
} }

View file

@ -1,11 +1,11 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others. * Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Michael Scharf (Wind River) - initial API and implementation * Michael Scharf (Wind River) - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.textcanvas; package org.eclipse.tm.internal.terminal.textcanvas;
@ -82,13 +82,13 @@ public class TextLineRenderer implements ILinelRenderer {
} }
} }
} }
private void fillBackground(GC gc, int x, int y, int width, int height) { private void fillBackground(GC gc, int x, int y, int width, int height) {
Color bg=gc.getBackground(); Color bg=gc.getBackground();
gc.setBackground(getBackgroundColor()); gc.setBackground(getBackgroundColor());
gc.fillRectangle (x,y,width,height); gc.fillRectangle (x,y,width,height);
gc.setBackground(bg); gc.setBackground(bg);
} }
private Color getBackgroundColor() { private Color getBackgroundColor() {
@ -98,7 +98,7 @@ public class TextLineRenderer implements ILinelRenderer {
if(!model.isCursorOn()) if(!model.isCursorOn())
return; return;
int cursorLine=model.getCursorLine(); int cursorLine=model.getCursorLine();
if(row==cursorLine) { if(row==cursorLine) {
int cursorColumn=model.getCursorColumn(); int cursorColumn=model.getCursorColumn();
if(cursorColumn<getTerminalText().getWidth()) { if(cursorColumn<getTerminalText().getWidth()) {
@ -136,4 +136,7 @@ public class TextLineRenderer implements ILinelRenderer {
ITerminalTextDataReadOnly getTerminalText() { ITerminalTextDataReadOnly getTerminalText() {
return fModel.getTerminalText(); return fModel.getTerminalText();
} }
public void onFontChange() {
fStyleMap.updateFont();
}
} }