mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-02 22:55:26 +02:00
Bug 265352 - [terminal][api] Terminal widget should allow setting fonts programmatically
This commit is contained in:
parent
49248a4e7f
commit
40ade66af4
6 changed files with 73 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2012 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -45,7 +45,19 @@ public interface ITerminalViewControl {
|
|||
String getEncoding();
|
||||
|
||||
boolean isEmpty();
|
||||
/**
|
||||
* Sets the Terminal font
|
||||
* @deprecated use {@link #setFont(String)} in order to support bold and italic variants of the given font
|
||||
* @param font
|
||||
*/
|
||||
void setFont(Font font);
|
||||
/**
|
||||
* Sets the font for the Terminal, using a JFace symbolic font name, such
|
||||
* that bold and italic variants can be leveraged.
|
||||
* @since 3.2
|
||||
* @param fontName
|
||||
*/
|
||||
void setFont(String fontName);
|
||||
void setInvertedColors(boolean invert);
|
||||
Font getFont();
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2011 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2003, 2012 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -30,6 +30,7 @@
|
|||
* Pawel Piech (Wind River) - [333613] "Job found still running" after shutdown
|
||||
* Martin Oberhuber (Wind River) - [348700] Terminal unusable after disconnect
|
||||
* Simon Bernard (Sierra Wireless) - [351424] [terminal] Terminal does not support del and insert key
|
||||
* Martin Oberhuber (Wind River) - [265352][api] Allow setting fonts programmatically
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.emulator;
|
||||
|
||||
|
@ -556,6 +557,21 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
setupHelp(fWndParent, TerminalPlugin.HELP_VIEW);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.control.ITerminalViewControl#setFont(java.lang.String)
|
||||
*/
|
||||
public void setFont(String fontName) {
|
||||
Font font=JFaceResources.getFont(fontName);
|
||||
getCtlText().setFont(font);
|
||||
if(fCommandInputField!=null) {
|
||||
fCommandInputField.setFont(font);
|
||||
}
|
||||
// Tell the TerminalControl singleton that the font has changed.
|
||||
fCtlText.updateFont(fontName);
|
||||
getTerminalText().fontChanged();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#onFontChanged()
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2012 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Michael Scharf (Wind River) - initial API and implementation
|
||||
* Anton Leherbauer (Wind River) - [294468] Fix scroller and text line rendering
|
||||
* Martin Oberhuber (Wind River) - [265352][api] Allow setting fonts programmatically
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||
|
||||
|
@ -21,7 +22,16 @@ public interface ILinelRenderer {
|
|||
int getCellWidth();
|
||||
int getCellHeight();
|
||||
void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int colFirst, int colLast);
|
||||
/**
|
||||
* Update for a font change from the global JFace Registry.
|
||||
*/
|
||||
void onFontChange();
|
||||
/**
|
||||
* Set a new font
|
||||
* @param fontName Jface name of the new font
|
||||
* @since 3.2
|
||||
*/
|
||||
void updateFont(String fontName);
|
||||
void setInvertedColors(boolean invert);
|
||||
Color getDefaultBackgroundColor();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2012 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -12,6 +12,7 @@
|
|||
* Michael Scharf (Wind River) - [206328] Terminal does not draw correctly with proportional fonts
|
||||
* Martin Oberhuber (Wind River) - [247700] Terminal uses ugly fonts in JEE package
|
||||
* Martin Oberhuber (Wind River) - [335358] Fix Terminal color definition
|
||||
* Martin Oberhuber (Wind River) - [265352][api] Allow setting fonts programmatically
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||
|
||||
|
@ -26,6 +27,7 @@ import org.eclipse.swt.graphics.GC;
|
|||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.tm.internal.terminal.preferences.ITerminalConstants;
|
||||
import org.eclipse.tm.terminal.model.Style;
|
||||
import org.eclipse.tm.terminal.model.StyleColor;
|
||||
|
||||
|
@ -42,9 +44,7 @@ public class StyleMap {
|
|||
private static final String RED = "red"; //$NON-NLS-1$
|
||||
|
||||
private static final String PREFIX = "org.eclipse.tm.internal."; //$NON-NLS-1$
|
||||
// TODO propagate the name of the font in the FontRegistry
|
||||
private static final String fDefaultFontName="terminal.views.view.font.definition"; //$NON-NLS-1$
|
||||
String fFontName=fDefaultFontName;
|
||||
String fFontName=ITerminalConstants.FONT_DEFINITION;
|
||||
Map fColorMapForeground=new HashMap();
|
||||
Map fColorMapBackground=new HashMap();
|
||||
Map fColorMapIntense=new HashMap();
|
||||
|
@ -194,13 +194,19 @@ public class StyleMap {
|
|||
return fCharSize.y;
|
||||
}
|
||||
public void updateFont() {
|
||||
updateFont(ITerminalConstants.FONT_DEFINITION);
|
||||
}
|
||||
/**
|
||||
* Update the StyleMap for a new font name.
|
||||
* The font name must be a valid name in the Jface font registry.
|
||||
* @param fontName Jface name of the new font to use.
|
||||
* @since 3.2
|
||||
*/
|
||||
public void updateFont(String fontName) {
|
||||
Display display=Display.getCurrent();
|
||||
GC gc = new GC (display);
|
||||
if (JFaceResources.getFontRegistry().hasValueFor(fDefaultFontName)) {
|
||||
fFontName = fDefaultFontName;
|
||||
} else if (JFaceResources.getFontRegistry().hasValueFor("REMOTE_COMMANDS_VIEW_FONT")) { //$NON-NLS-1$
|
||||
//try RSE Shell View Font
|
||||
fFontName = "REMOTE_COMMANDS_VIEW_FONT"; //$NON-NLS-1$
|
||||
if (JFaceResources.getFontRegistry().hasValueFor(fontName)) {
|
||||
fFontName = fontName;
|
||||
} else {
|
||||
//fall back to "basic jface text font"
|
||||
fFontName = "org.eclipse.jface.textfont"; //$NON-NLS-1$
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2012 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -15,6 +15,7 @@
|
|||
* Anton Leherbauer (Wind River) - [219589] Copy an entire line selection
|
||||
* Anton Leherbauer (Wind River) - [196465] Resizing Terminal changes Scroller location
|
||||
* Anton Leherbauer (Wind River) - [324608] Terminal has strange scrolling behaviour
|
||||
* Martin Oberhuber (Wind River) - [265352][api] Allow setting fonts programmatically
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||
|
||||
|
@ -373,6 +374,9 @@ public class TextCanvas extends GridCanvas {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify about a change of the global Font Preference.
|
||||
*/
|
||||
public void onFontChange() {
|
||||
fCellRenderer.onFontChange();
|
||||
setCellWidth(fCellRenderer.getCellWidth());
|
||||
|
@ -380,6 +384,13 @@ public class TextCanvas extends GridCanvas {
|
|||
calculateGrid();
|
||||
}
|
||||
|
||||
public void updateFont(String fontName) {
|
||||
fCellRenderer.updateFont(fontName);
|
||||
setCellWidth(fCellRenderer.getCellWidth());
|
||||
setCellHeight(fCellRenderer.getCellHeight());
|
||||
calculateGrid();
|
||||
}
|
||||
|
||||
public void setInvertedColors(boolean invert) {
|
||||
fCellRenderer.setInvertedColors(invert);
|
||||
redraw();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2012 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -10,6 +10,7 @@
|
|||
* Michael Scharf (Wind River) - [205260] Terminal does not take the font from the preferences
|
||||
* Michael Scharf (Wind River) - [206328] Terminal does not draw correctly with proportional fonts
|
||||
* Anton Leherbauer (Wind River) - [294468] Fix scroller and text line rendering
|
||||
* Martin Oberhuber (Wind River) - [265352][api] Allow setting fonts programmatically
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||
|
||||
|
@ -157,6 +158,9 @@ public class TextLineRenderer implements ILinelRenderer {
|
|||
public void onFontChange() {
|
||||
fStyleMap.updateFont();
|
||||
}
|
||||
public void updateFont(String fontName) {
|
||||
fStyleMap.updateFont(fontName);
|
||||
}
|
||||
public void setInvertedColors(boolean invert) {
|
||||
fStyleMap.setInvertedColors(invert);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue