mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added new utility class - PixelConverter
This commit is contained in:
parent
9d8f0a4a52
commit
963d4de52b
3 changed files with 75 additions and 31 deletions
|
@ -1,3 +1,8 @@
|
|||
2002-12-19 Mikhail Khodjaiants
|
||||
Added new utility class - PixelConverter
|
||||
* PixelCoverter.java
|
||||
* AttachSourceLocationBlock.java
|
||||
|
||||
2002-12-18 Mikhail Khodjaiants
|
||||
Implementing the "Source Lookup" property page.
|
||||
* SourceLookupBlock.java: common control block.
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package org.eclipse.cdt.debug.internal.ui;
|
||||
|
||||
/**********************************************************************
|
||||
Copyright (c) 2000, 2002 IBM Corp. and others.
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Common Public License v0.5
|
||||
which accompanies this distribution, and is available at
|
||||
http://www.eclipse.org/legal/cpl-v05.html
|
||||
|
||||
Contributors:
|
||||
IBM Corporation - Initial implementation
|
||||
**********************************************************************/
|
||||
|
||||
import org.eclipse.swt.graphics.FontMetrics;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
|
||||
public class PixelConverter
|
||||
{
|
||||
private FontMetrics fFontMetrics;
|
||||
|
||||
public PixelConverter( Control control )
|
||||
{
|
||||
GC gc = new GC( control );
|
||||
gc.setFont( control.getFont() );
|
||||
fFontMetrics = gc.getFontMetrics();
|
||||
gc.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.dialogs.DialogPage#convertHeightInCharsToPixels(int)
|
||||
*/
|
||||
public int convertHeightInCharsToPixels( int chars )
|
||||
{
|
||||
return Dialog.convertHeightInCharsToPixels( fFontMetrics, chars );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.dialogs.DialogPage#convertHorizontalDLUsToPixels(int)
|
||||
*/
|
||||
public int convertHorizontalDLUsToPixels( int dlus )
|
||||
{
|
||||
return Dialog.convertHorizontalDLUsToPixels( fFontMetrics, dlus );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.dialogs.DialogPage#convertVerticalDLUsToPixels(int)
|
||||
*/
|
||||
public int convertVerticalDLUsToPixels( int dlus )
|
||||
{
|
||||
return Dialog.convertVerticalDLUsToPixels( fFontMetrics, dlus );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.dialogs.DialogPage#convertWidthInCharsToPixels(int)
|
||||
*/
|
||||
public int convertWidthInCharsToPixels( int chars )
|
||||
{
|
||||
return Dialog.convertWidthInCharsToPixels( fFontMetrics, chars );
|
||||
}
|
||||
}
|
|
@ -5,15 +5,14 @@
|
|||
*/
|
||||
package org.eclipse.cdt.debug.ui.sourcelookup;
|
||||
|
||||
import org.eclipse.cdt.debug.internal.ui.PixelConverter;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.resource.JFaceResources;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.FontMetrics;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
|
@ -52,7 +51,6 @@ public class AttachSourceLocationBlock
|
|||
fControl.setLayout( new GridLayout() );
|
||||
fControl.setLayoutData( new GridData( GridData.FILL_BOTH ) );
|
||||
fControl.setFont( JFaceResources.getDialogFont() );
|
||||
initializeDialogUnits( fControl );
|
||||
|
||||
createLocationControls( fControl );
|
||||
createAssociationControls( fControl );
|
||||
|
@ -84,17 +82,18 @@ public class AttachSourceLocationBlock
|
|||
|
||||
protected void createLocationControls( Composite parent )
|
||||
{
|
||||
PixelConverter converter = new PixelConverter( parent );
|
||||
Label label = new Label( parent, SWT.NONE );
|
||||
label.setText( "Select location directory:" );
|
||||
label.setLayoutData( new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL ) );
|
||||
Composite composite = new Composite( parent, SWT.NONE );
|
||||
composite.setLayout( new GridLayout( 2, false ) );
|
||||
GridData data = new GridData( GridData.FILL_BOTH );
|
||||
data.widthHint = Dialog.convertWidthInCharsToPixels( fFontMetrics, 70 );
|
||||
data.widthHint = converter.convertWidthInCharsToPixels( 70 );
|
||||
composite.setLayoutData( data );
|
||||
fLocationText = new Text( composite, SWT.SINGLE | SWT.BORDER );
|
||||
fLocationText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL ) );
|
||||
Button button = createButton( composite, "&Browse..." );
|
||||
Button button = createButton( composite, "&Browse...", converter );
|
||||
button.addSelectionListener( new SelectionAdapter()
|
||||
{
|
||||
/* (non-Javadoc)
|
||||
|
@ -149,42 +148,19 @@ public class AttachSourceLocationBlock
|
|||
fAssociationText.setText( "" );
|
||||
}
|
||||
|
||||
protected Button createButton( Composite parent, String label )
|
||||
protected Button createButton( Composite parent, String label, PixelConverter pc )
|
||||
{
|
||||
Button button = new Button( parent, SWT.PUSH );
|
||||
button.setText( label );
|
||||
GridData data = new GridData( GridData.END );
|
||||
data.heightHint = convertVerticalDLUsToPixels( IDialogConstants.BUTTON_HEIGHT );
|
||||
int widthHint = convertHorizontalDLUsToPixels( IDialogConstants.BUTTON_WIDTH );
|
||||
data.heightHint = pc.convertVerticalDLUsToPixels( IDialogConstants.BUTTON_HEIGHT );
|
||||
int widthHint = pc.convertHorizontalDLUsToPixels( IDialogConstants.BUTTON_WIDTH );
|
||||
data.widthHint = Math.max( widthHint, button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true ).x );
|
||||
button.setLayoutData( data );
|
||||
button.setFont( parent.getFont() );
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
protected int convertVerticalDLUsToPixels( int dlus )
|
||||
{
|
||||
if ( fFontMetrics == null )
|
||||
return 0;
|
||||
return Dialog.convertVerticalDLUsToPixels( fFontMetrics, dlus );
|
||||
}
|
||||
|
||||
protected int convertHorizontalDLUsToPixels( int dlus )
|
||||
{
|
||||
if ( fFontMetrics == null )
|
||||
return 0;
|
||||
return Dialog.convertHorizontalDLUsToPixels( fFontMetrics, dlus );
|
||||
}
|
||||
|
||||
protected void initializeDialogUnits( Control control )
|
||||
{
|
||||
// Compute and store a font metric
|
||||
GC gc = new GC( control );
|
||||
gc.setFont( control.getFont() );
|
||||
fFontMetrics = gc.getFontMetrics();
|
||||
gc.dispose();
|
||||
}
|
||||
|
||||
public String getLocationPath()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue