Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2026 George Lindholm
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html.
*
* Contributors:
* See git history
*******************************************************************************/

package org.eclipse.mylyn.internal.commons.ui;

import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;

/**
* Some utility methods for working with fonts.
*
* @since 4.11
*/
public class FontUtils {
private static final Point POINT_ZERO = new Point(0, 0);

/**
* Returns the font metrics for the font of the given control.
*
* @param control
* @return
*/
public static FontMetrics getFontMetrics(final Control control) {
final GC gc = new GC(control);
try {
return gc.getFontMetrics();
} finally {
gc.dispose();
}
}

/**
* Returns the pixel width and height of the given string when rendered in the font of the given control.
* @param control
* @param string
* @return
*/
public static Point getStringPixels(final Control control, final String string) {
final GC gc = new GC(control);
try {
if (string == null || string.isEmpty()) {
return POINT_ZERO;
}
return gc.stringExtent(string);
} finally {
gc.dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Tasktop Technologies - initial API and implementation
* See git history
*******************************************************************************/

package org.eclipse.mylyn.commons.workbench.forms;
Expand All @@ -22,6 +23,7 @@

import org.eclipse.jface.window.Window;
import org.eclipse.mylyn.commons.ui.CommonImages;
import org.eclipse.mylyn.internal.commons.ui.FontUtils;
import org.eclipse.mylyn.internal.commons.workbench.Messages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
Expand Down Expand Up @@ -104,10 +106,8 @@ private void initialize(int style) {
setLayout(gridLayout);

dateText = new Text(this, style);
GridData dateTextGridData = new GridData(SWT.FILL, SWT.FILL, false, false);
dateTextGridData.heightHint = 5;
dateTextGridData.grabExcessHorizontalSpace = true;
dateTextGridData.verticalAlignment = SWT.FILL;
GridData dateTextGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
dateTextGridData.widthHint = FontUtils.getStringPixels(dateText, Messages.DatePicker_Sample_Due_Date).x + 5;

dateText.setLayoutData(dateTextGridData);
dateText.setText(initialText);
Expand Down Expand Up @@ -186,8 +186,8 @@ public void widgetSelected(SelectionEvent arg0) {
dialog.open();
}
});

updateClearControlVisibility();
pack();
setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
}

Expand Down Expand Up @@ -316,5 +316,4 @@ public void setEnabled(boolean enabled) {
clearControl.setEnabled(enabled);
super.setEnabled(enabled);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
*
* Bahadir Yagan - initial API and implementation
* Tasktop Technologies - improvements
* See git history
*******************************************************************************/

package org.eclipse.mylyn.commons.workbench.forms;

import java.text.DateFormat;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
Expand Down Expand Up @@ -150,15 +154,22 @@ public void linkActivated(HyperlinkEvent e) {
*/
private void createTimeList(Composite composite) {

DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
Calendar tempCalendar = Calendar.getInstance();
tempCalendar.set(Calendar.MINUTE, 0);
tempCalendar.set(Calendar.SECOND, 0);
DateTimeFormatter timeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
String[] times = new String[24];
int maxLen = 0;
for (int x = 0; x < 24; x++) {
tempCalendar.set(Calendar.HOUR_OF_DAY, x);
String timeString = dateFormat.format(tempCalendar.getTime());
times[x] = timeString;
times[x] = LocalTime.of(x, 0).format(timeFormatter);
if (times[x].length() > maxLen) {
maxLen = times[x].length();
}
}

// Right-justify by padding shorter strings with leading spaces
for (int i = 0; i < times.length; i++) {
int padding = maxLen - times[i].length();
if (padding > 0) {
times[i] = " ".repeat(padding) + times[i]; //$NON-NLS-1$
}
}

ListViewer listViewer = new ListViewer(composite);
Expand All @@ -168,6 +179,9 @@ private void createTimeList(Composite composite) {

timeList = listViewer.getList();

// Use a monospace font so that leading spaces produce consistent alignment
timeList.setFont(JFaceResources.getTextFont());

listViewer.addSelectionChangedListener(event -> {
date.set(Calendar.HOUR_OF_DAY, timeList.getSelectionIndex());
date.set(Calendar.MINUTE, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
*
* Tasktop Technologies - initial API and implementation
* See git history
*******************************************************************************/

package org.eclipse.mylyn.internal.commons.workbench;
Expand Down Expand Up @@ -45,6 +46,8 @@ public static void reloadMessages() {

public static String DatePickerPanel_Today;

public static String DatePicker_Sample_Due_Date;

public static String TextControl_FindToolTip;

public static String TextControl_AccessibleListenerFindButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#
# Contributors:
# Tasktop Technologies - initial API and implementation
# See git history
###############################################################################
WorkbenchUtil_Browser_Initialization_Failed=Browser initialization failed.
WorkbenchUtil_Invalid_URL_Error=Invalid URL specified: ''{0}''.
Expand All @@ -19,6 +20,7 @@ AbstractFilteredTree_Find=Find

DatePicker_Choose_Date=Choose Date
DatePicker_Clear=Clear
DatePicker_Sample_Due_Date=May 30, 2026, 12:00 p.m.

DateSelectionDialog_Date_Selection=Date Selection

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* IBM Corporation - initial API and implementation
* Tasktop Technologies - adapted for Mylyn
* See git history
*******************************************************************************/

package org.eclipse.mylyn.internal.context.ui.views;
Expand All @@ -25,6 +26,7 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.context.ui.InterestFilter;
import org.eclipse.mylyn.internal.commons.ui.FontUtils;
import org.eclipse.mylyn.internal.context.ui.ContextUiPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
Expand All @@ -38,7 +40,6 @@
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
Expand All @@ -57,7 +58,7 @@
* @author Mik Kersten
*/
public class QuickContextPopupDialog extends PopupDialog
implements IInformationControl, IInformationControlExtension, IInformationControlExtension2, DisposeListener {
implements IInformationControl, IInformationControlExtension, IInformationControlExtension2, DisposeListener {

public static final String ID_VIEWER = "org.eclipse.mylyn.context.ui.navigator.context.quick"; //$NON-NLS-1$

Expand Down Expand Up @@ -341,10 +342,7 @@ private void createUIWidgetFilterText(Composite parent) {
// Create the widget
fFilterText = new Text(parent, SWT.NONE);
// Set the font
GC gc = new GC(parent);
gc.setFont(parent.getFont());
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
FontMetrics fontMetrics = FontUtils.getFontMetrics(parent);
// Create the layout
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1);
Expand All @@ -371,12 +369,9 @@ public void keyPressed(KeyEvent e) {
if (e.keyCode == 0x0D) {
// Return key was pressed
gotoSelectedElement();
} else if (e.keyCode == SWT.ARROW_DOWN) {
} else if (e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_UP) {
// Down key was pressed
commonViewer.getTree().setFocus();
} else if (e.keyCode == SWT.ARROW_UP) {
// Up key was pressed
commonViewer.getTree().setFocus();
} else if (e.character == 0x1B) {
// Escape key was pressed
dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
* See git history
*******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui;
Expand Down Expand Up @@ -61,6 +62,8 @@ public static void reloadMessages() {

public static String ScheduleDatePicker_Clear;

public static String ScheduleDatePicker_Sample_Date;

public static String ScheduleTaskMenuContributor_Cannot_schedule_completed_tasks;

public static String ScheduleTaskMenuContributor_Choose_Date_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
* See git history
*******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui;
Expand All @@ -20,6 +21,7 @@
import org.eclipse.jface.action.MenuManager;
import org.eclipse.mylyn.commons.ui.CommonImages;
import org.eclipse.mylyn.commons.workbench.forms.DatePicker;
import org.eclipse.mylyn.internal.commons.ui.FontUtils;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.core.DateRange;
import org.eclipse.mylyn.tasks.core.IRepositoryElement;
Expand Down Expand Up @@ -72,6 +74,7 @@ public ScheduleDatePicker(Composite parent, AbstractTask task, int style) {
}

initialize((style & SWT.FLAT) > 0 ? SWT.FLAT : 0);

contributor = new ScheduleTaskMenuContributor() {

@Override
Expand All @@ -95,7 +98,6 @@ protected void setScheduledDate(DateRange dateRange) {
}

private void initialize(int style) {

GridLayout gridLayout = new GridLayout(3, false);
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
Expand All @@ -105,10 +107,9 @@ private void initialize(int style) {

scheduledDateText = new Text(this, style);
scheduledDateText.setEditable(false);
GridData dateTextGridData = new GridData(SWT.FILL, SWT.FILL, false, false);
dateTextGridData.heightHint = 5;
dateTextGridData.grabExcessHorizontalSpace = true;
dateTextGridData.verticalAlignment = SWT.FILL;
GridData dateTextGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
dateTextGridData.widthHint = FontUtils.getStringPixels(scheduledDateText,
Messages.ScheduleDatePicker_Sample_Date).x + 5;

scheduledDateText.setLayoutData(dateTextGridData);
scheduledDateText.setText(initialText);
Expand Down Expand Up @@ -160,13 +161,13 @@ public void widgetSelected(SelectionEvent arg0) {
});

updateDateText();
pack();
}

private void updateClearControlVisibility() {
if (clearControl != null && clearControl.getLayoutData() instanceof GridData) {
GridData gd = (GridData) clearControl.getLayoutData();
gd.exclude = scheduledDate == null;
clearControl.setVisible(scheduledDate != null);
clearControl.getParent().layout();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
* See git history
*******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui.editors;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void widgetSelected(SelectionEvent e) {

});

GridDataFactory.fillDefaults().hint(120, SWT.DEFAULT).grab(false, false).applyTo(datePicker);
GridDataFactory.fillDefaults().hint(120, SWT.DEFAULT).grab(true, false).applyTo(datePicker);
datePicker.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
toolkit.adapt(datePicker, false, false);

Expand Down
Loading
Loading