mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Initial commit of CDT code from QNX
This commit is contained in:
parent
58eca28a21
commit
3170ee99a0
6 changed files with 1022 additions and 0 deletions
|
@ -0,0 +1,545 @@
|
|||
package org.eclipse.cdt.utils.ui.controls;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.swt.custom.CCombo;
|
||||
import org.eclipse.swt.events.*;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.graphics.FontData;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
import org.eclipse.swt.widgets.List;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.layout.*;
|
||||
import org.eclipse.jface.viewers.CellEditor;
|
||||
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
||||
import org.eclipse.jface.viewers.ColumnWeightData;
|
||||
import org.eclipse.jface.viewers.TableLayout;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.swt.SWT;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class ControlFactory {
|
||||
|
||||
private static HyperlinkHandler defaultHyperlinkHandler = new HyperlinkHandler();
|
||||
|
||||
public static void dispose() {
|
||||
defaultHyperlinkHandler.dispose();
|
||||
}
|
||||
|
||||
public static Control setParentColors(Control control) {
|
||||
Composite parent = control.getParent();
|
||||
control.setBackground(parent.getBackground());
|
||||
control.setForeground(parent.getForeground());
|
||||
return control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates composite control and sets the default layout data.
|
||||
*
|
||||
* @param parent the parent of the new composite
|
||||
* @param numColumns the number of columns for the new composite
|
||||
* @return the newly-created coposite
|
||||
*/
|
||||
public static Composite createComposite(Composite parent, int numColumns) {
|
||||
Composite composite = new Composite(parent, SWT.NULL);
|
||||
|
||||
//GridLayout
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = numColumns;
|
||||
layout.makeColumnsEqualWidth = true;
|
||||
composite.setLayout(layout);
|
||||
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
return composite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates thick separator.
|
||||
*
|
||||
* @param parent the parent of the new composite
|
||||
* @param color the separator color
|
||||
* @return preferedThickness - the prefered thickness of separator (or 2 if SWT.DEFAULT)
|
||||
*/
|
||||
public static Composite createCompositeSeparator(Composite parent, Color color, int preferedHeight) {
|
||||
Composite separator = createComposite(parent, 1);
|
||||
GridData gd = (GridData)separator.getLayoutData();
|
||||
gd.heightHint = ((SWT.DEFAULT == preferedHeight) ? 2 : preferedHeight);
|
||||
separator.setLayoutData(gd);
|
||||
separator.setBackground(color);
|
||||
return separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates thick separator.
|
||||
*
|
||||
* @param parent the parent of the new composite
|
||||
* @param color the separator color
|
||||
* @return preferedThickness - the prefered thickness of separator (or 2 if SWT.DEFAULT)
|
||||
*/
|
||||
public static Label createSeparator(Composite parent, int nCols) {
|
||||
Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.horizontalSpan = nCols;
|
||||
separator.setLayoutData(data);
|
||||
return separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that creates a label instance
|
||||
* and sets the default layout data.
|
||||
*
|
||||
* @param parent the parent for the new label
|
||||
* @param text the text for the new label
|
||||
* @return the new label
|
||||
*/
|
||||
public static Label createLabel(Composite parent, String text) {
|
||||
Label label = new Label(parent, SWT.LEFT );
|
||||
label.setText(text);
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.horizontalSpan = 1;
|
||||
label.setLayoutData(data);
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that creates a label instance
|
||||
* and sets the default layout data and sets the
|
||||
* font attributes to be SWT.BOLD.
|
||||
*
|
||||
* @param parent the parent for the new label
|
||||
* @param text the text for the new label
|
||||
* @return the new label
|
||||
*/
|
||||
public static Label createBoldLabel(Composite parent, String text) {
|
||||
Label label = createLabel( parent, text );
|
||||
FontData[] fd = label.getFont().getFontData();
|
||||
fd[0].setStyle( SWT.BOLD );
|
||||
Font font = new Font( Display.getCurrent(), fd[0] );
|
||||
label.setFont( font );
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an new Wrapped label
|
||||
*
|
||||
*
|
||||
* @param parent parent object
|
||||
* @param text the label text
|
||||
* @param widthHint - recommended widget width
|
||||
* @param heightHint - recommended widget height
|
||||
* @return the new label
|
||||
*/
|
||||
public static Text createWrappedLabel(Composite parent, String text, int widthHint, int heightHint) {
|
||||
|
||||
Text wlabel = new Text(parent, SWT.WRAP | SWT.MULTI | SWT.READ_ONLY);
|
||||
wlabel.setText(text);
|
||||
GridData data = new GridData(GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
|
||||
data.heightHint = heightHint;
|
||||
data.widthHint = widthHint;
|
||||
wlabel.setLayoutData(data);
|
||||
wlabel.setBackground(parent.getBackground());
|
||||
wlabel.setForeground(parent.getForeground());
|
||||
return wlabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that creates a HyperLinkLabel instance
|
||||
* and sets the default layout data.
|
||||
*
|
||||
* @param parent the parent for the new label
|
||||
* @param text the text for the new label
|
||||
* @param TypedListener click event listener
|
||||
* @return the new label
|
||||
*/
|
||||
public static Label createHyperlinkLabel(Composite parent, String text, IHyperlinkListener listener,
|
||||
HyperlinkHandler hyperlinkHandler) {
|
||||
Label label = createLabel(parent, text);
|
||||
turnIntoHyperlink(label, listener,
|
||||
(null == hyperlinkHandler) ? defaultHyperlinkHandler : hyperlinkHandler);
|
||||
return label;
|
||||
}
|
||||
|
||||
public static void turnIntoHyperlink(Control control, IHyperlinkListener listener,
|
||||
HyperlinkHandler hyperlinkHandler) {
|
||||
hyperlinkHandler.registerHyperlink(control, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an new checkbox instance and sets the default
|
||||
* layout data.
|
||||
*
|
||||
* @param group the composite in which to create the checkbox
|
||||
* @param label the string to set into the checkbox
|
||||
* @return the new checkbox
|
||||
*/
|
||||
public static Button createCheckBox(Composite group, String label) {
|
||||
Button button = new Button(group, SWT.CHECK | SWT.LEFT);
|
||||
button.setText(label);
|
||||
GridData data = new GridData();
|
||||
button.setLayoutData(data);
|
||||
button.setBackground(group.getBackground());
|
||||
button.setForeground(group.getForeground());
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an new checkbox instance and sets the default
|
||||
* layout data.
|
||||
*
|
||||
* @param group the composite in which to create the checkbox
|
||||
* @param label the string to set into the checkbox
|
||||
* @return the new checkbox
|
||||
*/
|
||||
public static Button createCheckBoxEx(Composite group, String label, int style) {
|
||||
Button button = new Button(group, SWT.CHECK | style);
|
||||
button.setText(label);
|
||||
GridData data = new GridData();
|
||||
button.setLayoutData(data);
|
||||
button.setBackground(group.getBackground());
|
||||
button.setForeground(group.getForeground());
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an new radiobutton instance and sets the default
|
||||
* layout data.
|
||||
*
|
||||
* @param group the composite in which to create the radiobutton
|
||||
* @param label the string to set into the radiobutton
|
||||
* @param value the string to identify radiobutton
|
||||
* @return the new checkbox
|
||||
*/
|
||||
public static Button createRadioButton(Composite group, String label, String value, SelectionListener listener) {
|
||||
Button button = new Button(group, SWT.RADIO | SWT.LEFT);
|
||||
button.setText(label);
|
||||
button.setData((null == value) ? label : value);
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.horizontalAlignment = GridData.FILL;
|
||||
data.verticalAlignment = GridData.BEGINNING;
|
||||
button.setLayoutData(data);
|
||||
if(null != listener)
|
||||
button.addSelectionListener(listener);
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that creates a push button instance
|
||||
* and sets the default layout data.
|
||||
*
|
||||
* @param parent the parent for the new button
|
||||
* @param label the label for the new button
|
||||
* @return the newly-created button
|
||||
*/
|
||||
public static Button createPushButton(Composite parent, String label) {
|
||||
Button button = new Button(parent, SWT.PUSH);
|
||||
button.setText(label);
|
||||
// button.addSelectionListener(this);
|
||||
GridData data = new GridData();
|
||||
data.horizontalAlignment = GridData.FILL;
|
||||
button.setLayoutData(data);
|
||||
return button;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a text field specific for this application
|
||||
*
|
||||
* @param parent the parent of the new text field
|
||||
* @return the new text field
|
||||
*/
|
||||
public static Text createTextField(Composite parent) {
|
||||
return createTextField(parent, SWT.SINGLE | SWT.BORDER);
|
||||
}
|
||||
|
||||
public static Text createTextField(Composite parent, int style) {
|
||||
Text text = new Text(parent, style);
|
||||
GridData data = new GridData();
|
||||
data.horizontalAlignment = GridData.FILL;
|
||||
data.grabExcessHorizontalSpace = true;
|
||||
data.verticalAlignment = GridData.CENTER;
|
||||
data.grabExcessVerticalSpace = false;
|
||||
text.setLayoutData(data);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a group box
|
||||
*
|
||||
* @param parent the parent of the new control
|
||||
* @param label the group box label
|
||||
* @param nColumns - number of layout columns
|
||||
* @return the new group box
|
||||
*/
|
||||
public static Group createGroup(Composite parent, String label, int nColumns) {
|
||||
Group group = new Group(parent, SWT.NONE);
|
||||
group.setText(label);
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = nColumns;
|
||||
group.setLayout(layout);
|
||||
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a List box
|
||||
*
|
||||
* @param parent the parent of the new control
|
||||
* @param label the group box label
|
||||
* @param nColumns - number of layout columns
|
||||
* @return the new group box
|
||||
*/
|
||||
public static List createList(Composite parent, String strdata, String selData) {
|
||||
List list = new List(parent, SWT.SINGLE);
|
||||
GridData data = new GridData();
|
||||
list.setLayoutData(data);
|
||||
StringTokenizer st = new StringTokenizer(strdata, ",");
|
||||
while(st.hasMoreTokens())
|
||||
list.add(st.nextToken());
|
||||
if(selData == null) {
|
||||
if(list.getItemCount() > 0)
|
||||
list.select(0);
|
||||
}
|
||||
else
|
||||
selectList(list, selData);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create this group's list viewer.
|
||||
*/
|
||||
public static TableViewer createTableViewer(Composite parent, String[] opt_list,
|
||||
int width, int height, int style) {
|
||||
TableViewer listViewer = new TableViewer(parent, SWT.BORDER | style);
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
|
||||
data.widthHint = width;
|
||||
data.heightHint = height;
|
||||
listViewer.getTable().setLayoutData(data);
|
||||
if(null != opt_list)
|
||||
listViewer.add(opt_list);
|
||||
return listViewer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create this group's list viewer.
|
||||
*/
|
||||
public static TableViewer createTableViewer(Composite parent,
|
||||
int width, int height, int style, String[] columns, int[] colWidths) {
|
||||
TableViewer listViewer = createTableViewer(parent, null, width, height, style);
|
||||
|
||||
Table table= listViewer.getTable();
|
||||
|
||||
table.setHeaderVisible(true);
|
||||
table.setLinesVisible(true);
|
||||
|
||||
TableLayout tableLayout= new TableLayout();
|
||||
/*
|
||||
TableColumn column= table.getColumn(0);
|
||||
column.setText(columns[0]);
|
||||
tableLayout.addColumnData(new ColumnWeightData(colWidths[0], false));
|
||||
*/
|
||||
TableColumn column;
|
||||
for(int i = 0; i < columns.length; ++i) {
|
||||
column= new TableColumn(table, SWT.NULL);
|
||||
column.setText(columns[i]);
|
||||
tableLayout.addColumnData(new ColumnWeightData(colWidths[i], true));
|
||||
|
||||
}
|
||||
|
||||
table.setLayout(tableLayout);
|
||||
|
||||
return listViewer;
|
||||
}
|
||||
|
||||
public static void deactivateCellEditor(TableViewer viewer) {
|
||||
if(null == viewer)
|
||||
return;
|
||||
CellEditor[] es = viewer.getCellEditors();
|
||||
TableItem[] items = viewer.getTable().getSelection();
|
||||
if(items.length >= 0) {
|
||||
for(int i = 0; i < es.length; ++i) {
|
||||
CellEditor e = es[i];
|
||||
if(e.isActivated()) {
|
||||
if(e.isValueValid()) {
|
||||
Object[] properties = viewer.getColumnProperties();
|
||||
Object value = e.getValue();
|
||||
viewer.cancelEditing();
|
||||
viewer.getCellModifier().modify(items[0],(String)properties[i], value);
|
||||
} else
|
||||
viewer.cancelEditing();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this group's list viewer.
|
||||
*/
|
||||
public static CheckboxTableViewer createListViewer(Composite parent, String[] opt_list,
|
||||
int width, int height, int style) {
|
||||
|
||||
Table table = new Table(parent, SWT.BORDER);
|
||||
CheckboxTableViewer listViewer = new CheckboxTableViewer(table);
|
||||
GridData data = new GridData(style);
|
||||
data.widthHint = width;
|
||||
data.heightHint = height;
|
||||
listViewer.getTable().setLayoutData(data);
|
||||
if(null != opt_list)
|
||||
listViewer.add(opt_list);
|
||||
// listViewer.setLabelProvider(listLabelProvider);
|
||||
// listViewer.addCheckStateListener(this);
|
||||
return listViewer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static CheckboxTableViewer createListViewer(Composite parent,
|
||||
int width, int height, int style, String[] columns, int[] colWidths) {
|
||||
CheckboxTableViewer listViewer = createListViewer(parent, null,
|
||||
width, height, style);
|
||||
|
||||
Table table= listViewer.getTable();
|
||||
|
||||
table.setHeaderVisible(true);
|
||||
table.setLinesVisible(true);
|
||||
|
||||
TableLayout tableLayout= new TableLayout();
|
||||
table.setLayout(tableLayout);
|
||||
|
||||
TableColumn column= table.getColumn(0);
|
||||
column.setText(columns[0]);
|
||||
tableLayout.addColumnData(new ColumnWeightData(colWidths[0], false));
|
||||
|
||||
for(int i = 1; i < columns.length; ++i) {
|
||||
column= new TableColumn(table, SWT.NULL);
|
||||
column.setText(columns[i]);
|
||||
tableLayout.addColumnData(new ColumnWeightData(colWidths[i], false));
|
||||
|
||||
}
|
||||
|
||||
return listViewer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a selection combo
|
||||
*
|
||||
* @param parent the parent of the new text field
|
||||
* @param string of comma separated tokens to fill selection list
|
||||
* @return the new combo
|
||||
*/
|
||||
public static CCombo createSelectCombo(Composite parent, String strdata, String selData) {
|
||||
return createSelectCombo(parent, strdata, selData,
|
||||
SWT.READ_ONLY | SWT.BORDER);
|
||||
}
|
||||
|
||||
public static CCombo createSelectCombo(Composite parent, String strdata, String selData, int style) {
|
||||
CCombo combo = new CCombo(parent, style);
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
combo.setLayoutData(data);
|
||||
StringTokenizer st = new StringTokenizer(strdata, ",");
|
||||
while(st.hasMoreTokens())
|
||||
combo.add(st.nextToken());
|
||||
if(selData == null || selData.length() == 0) {
|
||||
if(combo.getItemCount() > 0)
|
||||
combo.select(0);
|
||||
}
|
||||
else
|
||||
selectCombo(combo, selData);
|
||||
return combo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a selection combo
|
||||
*
|
||||
* @param parent the parent of the new text field
|
||||
* @param array of elements + selected element
|
||||
* @return the new combo
|
||||
*/
|
||||
public static CCombo createSelectCombo(Composite parent, String[] strdata, String selData) {
|
||||
return createSelectCombo(parent, strdata, selData, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
|
||||
}
|
||||
|
||||
public static CCombo createSelectCombo(Composite parent, String[] strdata, String selData, int style) {
|
||||
CCombo combo = new CCombo(parent, style);
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
combo.setLayoutData(data);
|
||||
for(int i = 0; i < strdata.length; ++i) {
|
||||
combo.add(strdata[i]);
|
||||
}
|
||||
if(selData == null)
|
||||
combo.select(0);
|
||||
else
|
||||
selectCombo(combo, selData);
|
||||
return combo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a dialog shell, child to the top level workbench shell.
|
||||
*
|
||||
* @return The new Shell useable for a dialog.
|
||||
*
|
||||
*/
|
||||
public static Shell createDialogShell() {
|
||||
Shell parent = PlatformUI.getWorkbench()
|
||||
.getActiveWorkbenchWindow()
|
||||
.getShell();
|
||||
return new Shell( parent, SWT.DIALOG_TRIM );
|
||||
}
|
||||
|
||||
|
||||
public static void selectCombo(CCombo combo, String selData) {
|
||||
int n_sel = combo.indexOf(selData);
|
||||
if(0 > n_sel)
|
||||
n_sel = 0;
|
||||
combo.select(n_sel);
|
||||
}
|
||||
|
||||
|
||||
public static void selectList(List list, String selData) {
|
||||
int n_sel = list.indexOf(selData);
|
||||
if(0 > n_sel)
|
||||
n_sel = 0;
|
||||
list.select(n_sel);
|
||||
}
|
||||
|
||||
public static Composite insertSpace(Composite parent, int nSpan, int height) {
|
||||
Composite space = ControlFactory.createCompositeSeparator(parent, parent.getBackground(),
|
||||
(SWT.DEFAULT != height ? height : 5));
|
||||
((GridData)space.getLayoutData()).horizontalSpan = nSpan;
|
||||
return space;
|
||||
}
|
||||
|
||||
public static MessageBox createDialog( String title, String message, int style ) {
|
||||
MessageBox box = new MessageBox( createDialogShell(), style | SWT.APPLICATION_MODAL );
|
||||
box.setText( title );
|
||||
box.setMessage( message );
|
||||
return box;
|
||||
}
|
||||
|
||||
public static MessageBox createYesNoDialog( String title, String message ) {
|
||||
return createDialog( title, message, SWT.YES | SWT.NO | SWT.ICON_QUESTION );
|
||||
}
|
||||
|
||||
public static MessageBox createOkDialog( String title, String message ) {
|
||||
return createDialog( title, message, SWT.OK | SWT.ICON_INFORMATION );
|
||||
}
|
||||
|
||||
public static MessageBox createOkCancelDialog( String title, String message ) {
|
||||
return createDialog( title, message, SWT.OK | SWT.CANCEL | SWT.ICON_INFORMATION );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,176 @@
|
|||
package org.eclipse.cdt.utils.ui.controls;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.swt.widgets.*;
|
||||
import org.eclipse.swt.events.*;
|
||||
import org.eclipse.swt.graphics.*;
|
||||
import java.util.*;
|
||||
import org.eclipse.swt.*;
|
||||
|
||||
public class HyperlinkHandler implements MouseListener, MouseTrackListener, PaintListener {
|
||||
public static final int UNDERLINE_NEVER = 1;
|
||||
public static final int UNDERLINE_ROLLOVER = 2;
|
||||
public static final int UNDERLINE_ALWAYS = 3;
|
||||
|
||||
private Cursor hyperlinkCursor;
|
||||
private Cursor busyCursor;
|
||||
private boolean hyperlinkCursorUsed=true;
|
||||
private int hyperlinkUnderlineMode=UNDERLINE_ALWAYS;
|
||||
private Color background;
|
||||
private Color foreground;
|
||||
private Color activeBackground;
|
||||
private Color activeForeground;
|
||||
private Hashtable hyperlinkListeners;
|
||||
private Control lastLink;
|
||||
|
||||
public HyperlinkHandler() {
|
||||
hyperlinkListeners = new Hashtable();
|
||||
hyperlinkCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
|
||||
busyCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_WAIT);
|
||||
}
|
||||
public void dispose() {
|
||||
hyperlinkCursor.dispose();
|
||||
busyCursor.dispose();
|
||||
}
|
||||
public org.eclipse.swt.graphics.Color getActiveBackground() {
|
||||
return activeBackground;
|
||||
}
|
||||
public org.eclipse.swt.graphics.Color getActiveForeground() {
|
||||
return activeForeground;
|
||||
}
|
||||
public org.eclipse.swt.graphics.Color getBackground() {
|
||||
return background;
|
||||
}
|
||||
public org.eclipse.swt.graphics.Cursor getBusyCursor() {
|
||||
return busyCursor;
|
||||
}
|
||||
public org.eclipse.swt.graphics.Color getForeground() {
|
||||
return foreground;
|
||||
}
|
||||
public org.eclipse.swt.graphics.Cursor getHyperlinkCursor() {
|
||||
return hyperlinkCursor;
|
||||
}
|
||||
public int getHyperlinkUnderlineMode() {
|
||||
return hyperlinkUnderlineMode;
|
||||
}
|
||||
public org.eclipse.swt.widgets.Control getLastLink() {
|
||||
return lastLink;
|
||||
}
|
||||
public boolean isHyperlinkCursorUsed() {
|
||||
return hyperlinkCursorUsed;
|
||||
}
|
||||
public void mouseDoubleClick(MouseEvent e) {
|
||||
}
|
||||
public void mouseDown(MouseEvent e) {
|
||||
if (e.button == 1)
|
||||
return;
|
||||
lastLink = (Control)e.widget;
|
||||
}
|
||||
public void mouseEnter(MouseEvent e) {
|
||||
Control control = (Control) e.widget;
|
||||
if (isHyperlinkCursorUsed())
|
||||
control.setCursor(hyperlinkCursor);
|
||||
if (activeBackground != null)
|
||||
control.setBackground(activeBackground);
|
||||
if (activeForeground != null)
|
||||
control.setForeground(activeForeground);
|
||||
if (hyperlinkUnderlineMode==UNDERLINE_ROLLOVER) underline(control, true);
|
||||
|
||||
IHyperlinkListener action =
|
||||
(IHyperlinkListener) hyperlinkListeners.get(control);
|
||||
if (action != null)
|
||||
action.linkEntered(control);
|
||||
}
|
||||
public void mouseExit(MouseEvent e) {
|
||||
Control control = (Control) e.widget;
|
||||
if (isHyperlinkCursorUsed())
|
||||
control.setCursor(null);
|
||||
if (hyperlinkUnderlineMode==UNDERLINE_ROLLOVER)
|
||||
underline(control, false);
|
||||
if (background != null)
|
||||
control.setBackground(background);
|
||||
if (foreground != null)
|
||||
control.setForeground(foreground);
|
||||
IHyperlinkListener action =
|
||||
(IHyperlinkListener) hyperlinkListeners.get(control);
|
||||
if (action != null)
|
||||
action.linkExited(control);
|
||||
}
|
||||
public void mouseHover(MouseEvent e) {
|
||||
}
|
||||
public void mouseUp(MouseEvent e) {
|
||||
if (e.button != 1)
|
||||
return;
|
||||
IHyperlinkListener action =
|
||||
(IHyperlinkListener) hyperlinkListeners.get(e.widget);
|
||||
if (action != null) {
|
||||
Control c = (Control) e.widget;
|
||||
c.setCursor(busyCursor);
|
||||
action.linkActivated(c);
|
||||
if (!c.isDisposed())
|
||||
c.setCursor(isHyperlinkCursorUsed()?hyperlinkCursor:null);
|
||||
}
|
||||
}
|
||||
public void paintControl(PaintEvent e) {
|
||||
Control label = (Control) e.widget;
|
||||
if (hyperlinkUnderlineMode == UNDERLINE_ALWAYS)
|
||||
HyperlinkHandler.underline(label, true);
|
||||
}
|
||||
public void registerHyperlink(Control control, IHyperlinkListener listener) {
|
||||
if (background != null)
|
||||
control.setBackground(background);
|
||||
if (foreground != null)
|
||||
control.setForeground(foreground);
|
||||
control.addMouseListener(this);
|
||||
control.addMouseTrackListener(this);
|
||||
if (hyperlinkUnderlineMode == UNDERLINE_ALWAYS)
|
||||
control.addPaintListener(this);
|
||||
hyperlinkListeners.put(control, listener);
|
||||
removeDisposedLinks();
|
||||
}
|
||||
private void removeDisposedLinks() {
|
||||
for (Enumeration keys = hyperlinkListeners.keys(); keys.hasMoreElements();) {
|
||||
Control control = (Control)keys.nextElement();
|
||||
if (control.isDisposed()) {
|
||||
hyperlinkListeners.remove(control);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void reset() {
|
||||
hyperlinkListeners.clear();
|
||||
}
|
||||
public void setActiveBackground(org.eclipse.swt.graphics.Color newActiveBackground) {
|
||||
activeBackground = newActiveBackground;
|
||||
}
|
||||
public void setActiveForeground(org.eclipse.swt.graphics.Color newActiveForeground) {
|
||||
activeForeground = newActiveForeground;
|
||||
}
|
||||
public void setBackground(org.eclipse.swt.graphics.Color newBackground) {
|
||||
background = newBackground;
|
||||
}
|
||||
public void setForeground(org.eclipse.swt.graphics.Color newForeground) {
|
||||
foreground = newForeground;
|
||||
}
|
||||
public void setHyperlinkCursorUsed(boolean newHyperlinkCursorUsed) {
|
||||
hyperlinkCursorUsed = newHyperlinkCursorUsed;
|
||||
}
|
||||
public void setHyperlinkUnderlineMode(int newHyperlinkUnderlineMode) {
|
||||
hyperlinkUnderlineMode = newHyperlinkUnderlineMode;
|
||||
}
|
||||
public static void underline(Control control, boolean inside) {
|
||||
if (!(control instanceof Label))
|
||||
return;
|
||||
Composite parent = control.getParent();
|
||||
Rectangle bounds = control.getBounds();
|
||||
GC gc = new GC(parent);
|
||||
Color color = inside? control.getForeground() : control.getBackground();
|
||||
gc.setForeground(color);
|
||||
int y = bounds.y + bounds.height;
|
||||
gc.drawLine(bounds.x, y, bounds.x+bounds.width, y);
|
||||
gc.dispose();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.eclipse.cdt.utils.ui.controls;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
public interface IHyperlinkListener {
|
||||
|
||||
public void linkActivated(Control linkLabel);
|
||||
public void linkEntered(Control linkLabel);
|
||||
public void linkExited(Control linkLabel);
|
||||
}
|
|
@ -0,0 +1,227 @@
|
|||
package org.eclipse.cdt.utils.ui.controls;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import org.eclipse.swt.*;
|
||||
import org.eclipse.swt.events.*;
|
||||
import org.eclipse.swt.layout.*;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
|
||||
/**
|
||||
* A field editor for an enumeration type preference.
|
||||
* The choices are presented as a list of radio buttons.
|
||||
*/
|
||||
public class RadioButtonsArea extends Composite {
|
||||
|
||||
/**
|
||||
* List of radio button entries of the form [label,value].
|
||||
*/
|
||||
private String[][] labelsAndValues;
|
||||
|
||||
/**
|
||||
* Number of columns into which to arrange the radio buttons.
|
||||
*/
|
||||
private int numColumns;
|
||||
|
||||
/**
|
||||
* Indent used for the first column of the radion button matrix.
|
||||
*/
|
||||
private int indent = 0;
|
||||
|
||||
/**
|
||||
* The current value, or <code>null</code> if none.
|
||||
*/
|
||||
protected String value = null;
|
||||
|
||||
private SelectionListener listener;
|
||||
|
||||
private ArrayList externalListeners = new ArrayList();
|
||||
|
||||
private Composite area = null;
|
||||
/**
|
||||
* The radio buttons, or <code>null</code> if none
|
||||
* (before creation and after disposal).
|
||||
*/
|
||||
private Button[] radioButtons;
|
||||
|
||||
|
||||
public RadioButtonsArea(Composite parent, String labelText, int numColumns, String[][] labelAndValues) {
|
||||
super(parent, SWT.NULL);
|
||||
Assert.isTrue(checkArray(labelAndValues));
|
||||
this.labelsAndValues = labelAndValues;
|
||||
this.numColumns = numColumns;
|
||||
createControl(parent, labelText);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
for( int i = 0; i < radioButtons.length; i++ ) {
|
||||
radioButtons[i].setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether given <code>String[][]</code> is of "type"
|
||||
* <code>String[][2]</code>.
|
||||
*
|
||||
* @return <code>true</code> if it is ok, and <code>false</code> otherwise
|
||||
*/
|
||||
private boolean checkArray(String[][] table) {
|
||||
if (table == null)
|
||||
return false;
|
||||
for (int i = 0; i < table.length; i++) {
|
||||
String[] array = table[i];
|
||||
if (array == null || array.length != 2)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void fireSelectionEvent(SelectionEvent event) {
|
||||
for(Iterator i = externalListeners.iterator(); i.hasNext(); ) {
|
||||
SelectionListener s = (SelectionListener)i.next();
|
||||
s.widgetSelected(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create control area
|
||||
*
|
||||
* @return nothing
|
||||
*/
|
||||
protected void createControl(Composite parent, String labelText) {
|
||||
GridLayout gl = new GridLayout();
|
||||
this.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
gl.marginWidth = 0;
|
||||
gl.horizontalSpacing = 0;
|
||||
this.setLayout(gl);
|
||||
|
||||
if(null != labelText) { // Create group box
|
||||
area = ControlFactory.createGroup(this, labelText, numColumns);
|
||||
} else {
|
||||
area = this;
|
||||
}
|
||||
|
||||
radioButtons = new Button[labelsAndValues.length];
|
||||
listener = new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
value = (String) (event.widget.getData());
|
||||
fireSelectionEvent(event); // Infor any external listener
|
||||
}
|
||||
};
|
||||
|
||||
for (int i = 0; i < labelsAndValues.length; i++) {
|
||||
radioButtons[i] = ControlFactory.createRadioButton(area,
|
||||
labelsAndValues[i][0],
|
||||
labelsAndValues[i][1],
|
||||
listener);
|
||||
}
|
||||
|
||||
area.addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent event) {
|
||||
radioButtons = null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the indent used for the first column of the radion button matrix.
|
||||
*
|
||||
* @param indent the indent (in pixels)
|
||||
*/
|
||||
public void setIndent(int indent) {
|
||||
if(null == area)
|
||||
return;
|
||||
if (indent < 0)
|
||||
indent = 0;
|
||||
for(int i = 0; i < radioButtons.length; ++i) {
|
||||
((GridData)(radioButtons[i].getLayoutData())).horizontalIndent = indent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the radio button that conforms to the given value.
|
||||
*
|
||||
* @param selectedValue the selected value
|
||||
*/
|
||||
public void setSelectValue(String selectedValue) {
|
||||
this.value = selectedValue;
|
||||
if (radioButtons == null)
|
||||
return;
|
||||
|
||||
if (this.value != null) {
|
||||
boolean found = false;
|
||||
for (int i = 0; i < radioButtons.length; i++) {
|
||||
Button radio = radioButtons[i];
|
||||
boolean selection = false;
|
||||
if (((String) radio.getData()).equals(this.value)) {
|
||||
selection = true;
|
||||
found = true;
|
||||
}
|
||||
radio.setSelection(selection);
|
||||
}
|
||||
if (found)
|
||||
return;
|
||||
}
|
||||
|
||||
// We weren't able to find the value. So we select the first
|
||||
// radio button as a default.
|
||||
if (radioButtons.length > 0) {
|
||||
radioButtons[0].setSelection(true);
|
||||
this.value = (String) radioButtons[0].getData();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public void setSelectedButton(int index) {
|
||||
Button b;
|
||||
|
||||
if((index < 0) || (index >= radioButtons.length))
|
||||
return;
|
||||
|
||||
for(int i = 0; i < radioButtons.length; ++i) {
|
||||
b = radioButtons[i];
|
||||
boolean selected = b.getSelection();
|
||||
if(i == index) {
|
||||
if(selected)
|
||||
return;
|
||||
} else {
|
||||
if(selected)
|
||||
b.setSelection(false);
|
||||
}
|
||||
}
|
||||
|
||||
b = radioButtons[index];
|
||||
b.setSelection(true);
|
||||
}
|
||||
|
||||
public String getSelectedValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getSeletedIndex() {
|
||||
if (radioButtons == null)
|
||||
return -1;
|
||||
|
||||
if (value != null) {
|
||||
for (int i = 0; i < radioButtons.length; i++) {
|
||||
if (((String) radioButtons[i].getData()).equals(this.value))
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void addSelectionListener(SelectionListener s) {
|
||||
if(externalListeners.contains(s))
|
||||
return;
|
||||
externalListeners.add(s);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package org.eclipse.cdt.utils.ui.controls;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Layout;
|
||||
|
||||
public class TabFolderLayout extends Layout {
|
||||
|
||||
protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) {
|
||||
if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT)
|
||||
return new Point(wHint, hHint);
|
||||
|
||||
Control [] children = composite.getChildren ();
|
||||
int count = children.length;
|
||||
int maxWidth = 0, maxHeight = 0;
|
||||
for (int i=0; i<count; i++) {
|
||||
Control child = children [i];
|
||||
Point pt = child.computeSize (SWT.DEFAULT, SWT.DEFAULT, flushCache);
|
||||
maxWidth = Math.max (maxWidth, pt.x);
|
||||
maxHeight = Math.max (maxHeight, pt.y);
|
||||
}
|
||||
|
||||
if (wHint != SWT.DEFAULT)
|
||||
maxWidth= wHint;
|
||||
if (hHint != SWT.DEFAULT)
|
||||
maxHeight= hHint;
|
||||
|
||||
return new Point(maxWidth, maxHeight);
|
||||
|
||||
}
|
||||
protected void layout (Composite composite, boolean flushCache) {
|
||||
Rectangle rect= composite.getClientArea();
|
||||
|
||||
Control[] children = composite.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
children[i].setBounds(rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.eclipse.cdt.utils.ui.swt;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
public interface IValidation {
|
||||
public void setComplete(boolean complete);
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue