use of org.eclipse.swt.graphics.FontMetrics in project dbeaver by serge-rider.
the class HexStatusLine method initialize.
private void initialize(boolean withSeparator) {
GridLayout statusLayout = new GridLayout();
statusLayout.numColumns = withSeparator ? 6 : 5;
statusLayout.marginHeight = 0;
setLayout(statusLayout);
if (withSeparator) {
GridData separator1GridData = new GridData();
separator1GridData.grabExcessVerticalSpace = true;
separator1GridData.verticalAlignment = SWT.FILL;
Label separator1 = new Label(this, SWT.SEPARATOR);
separator1.setLayoutData(separator1GridData);
}
GC gc = new GC(this);
FontMetrics fontMetrics = gc.getFontMetrics();
position = new Label(this, SWT.SHADOW_NONE);
GridData gridData1 = new GridData(/*SWT.DEFAULT*/
(11 + 10 + 12 + 3 + 10 + 12) * fontMetrics.getAverageCharWidth(), SWT.DEFAULT);
position.setLayoutData(gridData1);
GridData separator23GridData = new GridData();
separator23GridData.grabExcessVerticalSpace = true;
separator23GridData.verticalAlignment = SWT.FILL;
Label separator2 = new Label(this, SWT.SEPARATOR);
separator2.setLayoutData(separator23GridData);
value = new Label(this, SWT.SHADOW_NONE);
GridData gridData2 = new GridData(/*SWT.DEFAULT*/
(7 + 3 + 9 + 2 + 9 + 8 + 6) * fontMetrics.getAverageCharWidth(), SWT.DEFAULT);
value.setLayoutData(gridData2);
// From Eclipse 3.1's GridData javadoc:
// NOTE: Do not reuse GridData objects. Every control in a Composite that is managed by a
// GridLayout must have a unique GridData
GridData separator3GridData = new GridData();
separator3GridData.grabExcessVerticalSpace = true;
separator3GridData.verticalAlignment = SWT.FILL;
Label separator3 = new Label(this, SWT.SEPARATOR);
separator3.setLayoutData(separator3GridData);
insertMode = new Label(this, SWT.SHADOW_NONE);
GridData gridData3 = new GridData(/*SWT.DEFAULT*/
(TEXT_OVERWRITE.length() + 2) * fontMetrics.getAverageCharWidth(), SWT.DEFAULT);
insertMode.setLayoutData(gridData3);
gc.dispose();
}
use of org.eclipse.swt.graphics.FontMetrics in project translationstudio8 by heartsome.
the class TextPainterWithPadding method setFont.
public void setFont(Font font) {
TextLayout layout = new TextLayout(Display.getDefault());
try {
if (font != null) {
this.font = font;
Font boldFont = getFont(SWT.BOLD), italicFont = getFont(SWT.ITALIC), boldItalicFont = getFont(SWT.BOLD | SWT.ITALIC);
layout.setText(" ");
layout.setFont(font);
layout.setStyle(new TextStyle(font, null, null), 0, 0);
layout.setStyle(new TextStyle(boldFont, null, null), 1, 1);
layout.setStyle(new TextStyle(italicFont, null, null), 2, 2);
layout.setStyle(new TextStyle(boldItalicFont, null, null), 3, 3);
FontMetrics metrics = layout.getLineMetrics(0);
ascent = metrics.getAscent() + metrics.getLeading();
descent = metrics.getDescent();
boldFont.dispose();
italicFont.dispose();
boldItalicFont.dispose();
boldFont = italicFont = boldItalicFont = null;
}
layout.dispose();
layout = new TextLayout(Display.getDefault());
layout.setFont(this.font);
StringBuffer tabBuffer = new StringBuffer(tabSize);
for (int i = 0; i < tabSize; i++) {
tabBuffer.append(' ');
}
layout.setText(tabBuffer.toString());
tabWidth = layout.getBounds().width;
layout.dispose();
} finally {
if (layout != null && !layout.isDisposed()) {
layout.dispose();
}
}
}
use of org.eclipse.swt.graphics.FontMetrics in project cubrid-manager by CUBRID.
the class VolumeFolderInfoEditor method alignText.
/**
* align the text
*
* @param str String
* @param pg org.eclipse.swt.graphics.GC
* @param valueY int
* @param start int
* @param end int
* @param mode int
*/
private void alignText(String str, org.eclipse.swt.graphics.GC pg, int valueY, int start, int end, int mode) {
// FIXME extract to utility class
FontMetrics fm = pg.getFontMetrics();
int wString = str.length() * fm.getAverageCharWidth();
int x = start;
switch(mode) {
case 0:
if ((end - start - wString) > 0) {
x = start + (end - start - wString) / 2;
}
break;
case 1:
break;
case 2:
if ((end - start - wString) > 0) {
x = start + (end - start - wString);
}
break;
default:
break;
}
pg.drawString(str, x, valueY);
}
use of org.eclipse.swt.graphics.FontMetrics in project dbeaver by serge-rider.
the class GoToDialog method createTextPanel.
/**
* This method initializes textComposite
*/
private void createTextPanel() {
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
textComposite = new Composite(dialogShell, SWT.NONE);
textComposite.setLayout(gridLayout);
createRadixPanel();
text = new Text(textComposite, SWT.BORDER | SWT.SINGLE);
text.setTextLimit(30);
int columns = 35;
GC gc = new GC(text);
FontMetrics fm = gc.getFontMetrics();
int width = columns * fm.getAverageCharWidth();
gc.dispose();
text.setLayoutData(new GridData(width, SWT.DEFAULT));
text.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
String newText = text.getText();
int radix = 10;
Matcher numberMatcher;
if (hexRadioButton.getSelection()) {
numberMatcher = patternHexDigits.matcher(newText);
radix = 16;
} else {
numberMatcher = patternDecDigits.matcher(newText);
}
tempResult = -1;
if (numberMatcher.matches())
tempResult = Long.parseLong(newText, radix);
if (tempResult >= 0L && tempResult <= limit) {
showButton.setEnabled(true);
gotoButton.setEnabled(true);
//$NON-NLS-1$
label2.setText("");
} else {
showButton.setEnabled(false);
gotoButton.setEnabled(false);
if (//$NON-NLS-1$
"".equals(newText))
//$NON-NLS-1$
label2.setText("");
else if (tempResult < 0)
label2.setText(CoreMessages.dialog_go_to_label_not_number);
else
label2.setText(CoreMessages.dialog_go_to_label_out_of_range);
}
}
});
FormData formData = new FormData();
formData.top = new FormAttachment(label);
textComposite.setLayoutData(formData);
}
use of org.eclipse.swt.graphics.FontMetrics in project cubrid-manager by CUBRID.
the class ChartSettingDlg method createSeriesItem.
/**
* Create Series tab item
*
*/
private void createSeriesItem() {
seriesItem.setText(Messages.tabItemSeriesTtl);
Composite tabComp = new Composite(folder, SWT.NONE);
tabComp.setLayout(new GridLayout());
tabComp.setLayoutData(new GridData(GridData.FILL_BOTH));
seriesItem.setControl(tabComp);
Group group = new Group(tabComp, SWT.NONE);
group.setLayout(new GridLayout(2, false));
group.setLayoutData(new GridData(GridData.FILL_BOTH));
final List seriesSelectionList = new List(group, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
group.setText(Messages.seriesGroupTxt);
GridData gd = new GridData(GridData.FILL_BOTH);
GC gc = new GC(folder.getParent());
gc.setFont(folder.getParent().getFont());
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
gd.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 15);
seriesSelectionList.setLayoutData(gd);
for (Map.Entry<String, ShowSetting> entry : settingMap.entrySet()) {
String key = entry.getKey();
seriesSelectionList.add(key);
}
Composite optionsComp = new Composite(group, SWT.NONE);
optionsComp.setLayout(new GridLayout());
optionsComp.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
Composite checkComposite = new Composite(optionsComp, SWT.NONE);
checkComposite.setLayout(new GridLayout());
checkComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
Composite colorComposite = new Composite(optionsComp, SWT.NONE);
GridLayout colorlayout = new GridLayout(2, false);
colorComposite.setLayout(colorlayout);
colorComposite.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false));
final Button checkBtn = new Button(checkComposite, SWT.CHECK);
checkBtn.setText(Messages.seriesCheckBtnLbl);
checkBtn.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));
Label colorlbl = new Label(colorComposite, SWT.LEFT);
colorlbl.setText(Messages.seriesColorLbl);
colorlbl.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false));
final ColorSelector seriesColorEditor = new ColorSelector(colorComposite);
Button foregroundColorButton = seriesColorEditor.getButton();
foregroundColorButton.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));
Composite widthComposite = new Composite(optionsComp, SWT.NONE);
widthComposite.setLayout(new GridLayout());
widthComposite.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false));
final Label widthLbl = new Label(widthComposite, SWT.LEFT);
widthScale = new Scale(widthComposite, SWT.HORIZONTAL);
widthScale.setMinimum(1);
widthScale.setMaximum(5);
widthScale.setIncrement(1);
widthScale.setPageIncrement(1);
widthScale.setSelection(2);
float width = ((float) widthScale.getSelection()) / 2;
widthLbl.setText(Messages.bind(Messages.seriesWidthLbl, width));
seriesSelectionList.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent ex) {
widgetSelected(ex);
}
public void widgetSelected(SelectionEvent ex) {
int i = seriesSelectionList.getSelectionIndex();
if (i == -1) {
return;
}
if (seriesSelectionList.getSelectionCount() == 1) {
String[] selection = seriesSelectionList.getSelection();
for (Map.Entry<String, ShowSetting> entry : settingMap.entrySet()) {
String key = entry.getKey();
ShowSetting showSetting = entry.getValue();
if (key.equals(selection[0])) {
checkBtn.setSelection(showSetting.isChecked());
seriesColorEditor.setColorValue(showSetting.getSeriesRgb());
int widthInScale = (int) showSetting.getWidth() * 2;
widthScale.setSelection(widthInScale);
break;
}
}
} else {
checkBtn.setSelection(false);
Color colorBtnBg = seriesColorEditor.getButton().getBackground();
seriesColorEditor.setColorValue(new RGB(colorBtnBg.getRed(), colorBtnBg.getGreen(), colorBtnBg.getBlue()));
// default value
widthScale.setSelection(2);
}
float width = ((float) widthScale.getSelection()) / 2;
widthLbl.setText(Messages.bind(Messages.seriesWidthLbl, width));
}
});
foregroundColorButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent ex) {
widgetSelected(ex);
}
public void widgetSelected(SelectionEvent ex) {
int i = seriesSelectionList.getSelectionIndex();
if (i == -1) {
return;
}
RGB rgb = seriesColorEditor.getColorValue();
float width = ((float) widthScale.getSelection()) / 2;
boolean isChecked = checkBtn.getSelection();
String[] selection = seriesSelectionList.getSelection();
updateValueInSettingMap(rgb, width, isChecked, selection);
}
});
checkBtn.addSelectionListener(new SelectionAdapter() {
/**
* Sent when selection occurs in the control.
*
* @param event an event containing information about the selection
*/
public void widgetSelected(SelectionEvent event) {
widgetDefaultSelected(event);
}
/**
* Sent when default selection occurs in the control.
*
* @param event an event containing information about the default
* selection
*/
public void widgetDefaultSelected(SelectionEvent event) {
int i = seriesSelectionList.getSelectionIndex();
if (i == -1) {
return;
}
RGB rgb = seriesColorEditor.getColorValue();
float width = ((float) widthScale.getSelection()) / 2;
boolean isChecked = checkBtn.getSelection();
String[] selection = seriesSelectionList.getSelection();
updateValueInSettingMap(rgb, width, isChecked, selection);
}
});
widthScale.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
int i = seriesSelectionList.getSelectionIndex();
if (i == -1) {
return;
}
float width = ((float) widthScale.getSelection()) / 2;
widthLbl.setText(Messages.bind(Messages.seriesWidthLbl, width));
RGB rgb = seriesColorEditor.getColorValue();
boolean isChecked = checkBtn.getSelection();
String[] selection = seriesSelectionList.getSelection();
updateValueInSettingMap(rgb, width, isChecked, selection);
}
});
if (seriesSelectionList.getItemCount() > 0) {
seriesSelectionList.select(0);
String[] selectedKey = seriesSelectionList.getSelection();
ShowSetting setting = settingMap.get(selectedKey[0]);
checkBtn.setSelection(setting.isChecked());
seriesColorEditor.setColorValue(setting.getSeriesRgb());
widthLbl.setText(Messages.bind(Messages.seriesWidthLbl, setting.getWidth()));
int widthInScale = (int) setting.getWidth() * 2;
widthScale.setSelection(widthInScale);
}
}
Aggregations