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

Apply from 3.0.3: [247700] Terminal uses ugly fonts in JEE package

This commit is contained in:
Martin Oberhuber 2009-02-18 18:11:56 +00:00
parent 4999018e4f
commit 7dd15dcf0e
2 changed files with 79 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2008 IBM Corporation and others. * Copyright (c) 2002, 2009 IBM Corporation 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
@ -19,6 +19,7 @@
* Martin Oberhuber (Wind River) - [227571] RSE Terminal should honor Encoding set on the IHost * Martin Oberhuber (Wind River) - [227571] RSE Terminal should honor Encoding set on the IHost
* Michael Scharf (Wind River) - [236203] [rseterminal] Potentially UI blocking code in TerminalViewTab.createTabItem * Michael Scharf (Wind River) - [236203] [rseterminal] Potentially UI blocking code in TerminalViewTab.createTabItem
* Anna Dushistova (MontaVista) - [244437] [rseterminal] Possible race condition when multiple Terminals are launched after each other * Anna Dushistova (MontaVista) - [244437] [rseterminal] Possible race condition when multiple Terminals are launched after each other
* Martin Oberhuber (Wind River) - [247700] Terminal uses ugly fonts in JEE package
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.terminals.ui.views; package org.eclipse.rse.internal.terminals.ui.views;
@ -29,6 +30,9 @@ import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator; import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.events.ISystemResourceChangeEvents; import org.eclipse.rse.core.events.ISystemResourceChangeEvents;
import org.eclipse.rse.core.events.SystemResourceChangeEvent; import org.eclipse.rse.core.events.SystemResourceChangeEvent;
@ -45,6 +49,7 @@ import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MenuEvent; import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener; import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
@ -61,6 +66,8 @@ import org.eclipse.tm.internal.terminal.control.actions.TerminalActionPaste;
import org.eclipse.tm.internal.terminal.control.actions.TerminalActionSelectAll; import org.eclipse.tm.internal.terminal.control.actions.TerminalActionSelectAll;
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.themes.IThemeManager;
/** /**
* This is the desktop view wrapper of the System View viewer. * This is the desktop view wrapper of the System View viewer.
@ -71,6 +78,8 @@ public class TerminalViewTab extends Composite {
private final CTabFolder tabFolder; private final CTabFolder tabFolder;
private IPropertyChangeListener propertyChangeListener;
private Menu menu; private Menu menu;
private boolean fMenuAboutToShow; private boolean fMenuAboutToShow;
@ -123,6 +132,11 @@ public class TerminalViewTab extends Composite {
} }
public void dispose() { public void dispose() {
if (propertyChangeListener != null) {
IThemeManager mgr = PlatformUI.getWorkbench().getThemeManager();
mgr.removePropertyChangeListener(propertyChangeListener);
propertyChangeListener = null;
}
if (!tabFolder.isDisposed()) { if (!tabFolder.isDisposed()) {
tabFolder.dispose(); tabFolder.dispose();
} }
@ -183,6 +197,47 @@ public class TerminalViewTab extends Composite {
} }
} }
public void propertyChange(PropertyChangeEvent e) {
// for now always update
if (tabFolder!=null) {
CTabItem[] items = tabFolder.getItems();
for (int i=0; i<items.length; i++) {
Object control = items[i].getData(DATA_KEY_CONTROL);
if (control instanceof ITerminalViewControl) {
updateTheme((ITerminalViewControl) control);
}
}
}
}
public void updateTheme(final ITerminalViewControl control) {
if (control != null) {
IThemeManager mgr = PlatformUI.getWorkbench().getThemeManager();
Font font;
FontRegistry fr = mgr.getCurrentTheme().getFontRegistry();
if (fr.hasValueFor("terminal.views.view.font.definition")) { //$NON-NLS-1$
//Terminal View font if available
font = fr.get("terminal.views.view.font.definition"); //$NON-NLS-1$
} else if (fr.hasValueFor("REMOTE_COMMANDS_VIEW_FONT")) { //$NON-NLS-1$
//fallback: "Remote Shell Font"
font = fr.get("REMOTE_COMMANDS_VIEW_FONT"); //$NON-NLS-1$
} else {
//fallback: "Basic Text Font"
font = fr.get("org.eclipse.jface.textfont"); //$NON-NLS-1$
}
control.setFont(font);
if (propertyChangeListener == null) {
final TerminalViewTab myself = this;
propertyChangeListener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
myself.propertyChange(event);
}
};
mgr.addPropertyChangeListener(propertyChangeListener);
}
}
}
public CTabItem createTabItem(IAdaptable root, public CTabItem createTabItem(IAdaptable root,
final String initialWorkingDirCmd) { final String initialWorkingDirCmd) {
final CTabItem item = new CTabItem(tabFolder, SWT.CLOSE); final CTabItem item = new CTabItem(tabFolder, SWT.CLOSE);
@ -250,6 +305,7 @@ public class TerminalViewTab extends Composite {
} }
terminalControl.setConnector(connector); terminalControl.setConnector(connector);
item.setData(DATA_KEY_CONTROL, terminalControl); item.setData(DATA_KEY_CONTROL, terminalControl);
updateTheme(terminalControl);
terminalControl.connectTerminal(); terminalControl.connectTerminal();
} }
item.setControl(c); item.setControl(c);

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2009 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
@ -10,6 +10,7 @@
* Michael Scharf (Wind River) - [205260] Terminal does not take the font from the preferences * Michael Scharf (Wind River) - [205260] Terminal does not take the font from the preferences
* Michael Scharf (Wind River) - [209746] There are cases where some colors not displayed correctly * Michael Scharf (Wind River) - [209746] There are cases where some colors not displayed correctly
* Michael Scharf (Wind River) - [206328] Terminal does not draw correctly with proportional fonts * 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
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.textcanvas; package org.eclipse.tm.internal.terminal.textcanvas;
@ -41,7 +42,8 @@ public class StyleMap {
private static final String PREFIX = "org.eclipse.tm.internal."; //$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 // TODO propagate the name of the font in the FontRegistry
String fFontName="terminal.views.view.font.definition"; //$NON-NLS-1$ private static final String fDefaultFontName="terminal.views.view.font.definition"; //$NON-NLS-1$
String fFontName=fDefaultFontName;
Map fColorMapForeground=new HashMap(); Map fColorMapForeground=new HashMap();
Map fColorMapBackground=new HashMap(); Map fColorMapBackground=new HashMap();
Map fFontMap=new HashMap(); Map fFontMap=new HashMap();
@ -169,6 +171,15 @@ public class StyleMap {
public void updateFont() { public void updateFont() {
Display display=Display.getCurrent(); Display display=Display.getCurrent();
GC gc = new GC (display); 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$
} else {
//fall back to "basic jface text font"
fFontName = "org.eclipse.jface.textfont"; //$NON-NLS-1$
}
gc.setFont(getFont()); gc.setFont(getFont());
fCharSize = gc.textExtent ("W"); //$NON-NLS-1$ fCharSize = gc.textExtent ("W"); //$NON-NLS-1$
fProportional=false; fProportional=false;
@ -184,11 +195,19 @@ public class StyleMap {
measureChar(gc, c,false); measureChar(gc, c,false);
} }
if(fProportional) { if(fProportional) {
fCharSize.x-=3; fCharSize.x-=2; //works better on small fonts
} }
for (int i = 0; i < fOffsets.length; i++) { for (int i = 0; i < fOffsets.length; i++) {
fOffsets[i]=(fCharSize.x-fOffsets[i])/2; fOffsets[i]=(fCharSize.x-fOffsets[i])/2;
} }
if(!fProportional) {
//measure font in boldface, too, and if wider then treat like proportional
gc.setFont(getFont(fDefaultStyle.setBold(true)));
Point charSizeBold = gc.textExtent("W"); //$NON-NLS-1$
if (fCharSize.x != charSizeBold.x) {
fProportional=true;
}
}
gc.dispose (); gc.dispose ();
} }
/** /**