use of org.eclipse.jface.preference.ColorSelector in project netxms by netxms.
the class WidgetHelper method createLabeledColorSelector.
/**
* Create pair of label and color selector, with label above
*
* @param parent Parent composite
* @param labelText Label's text
* @param layoutData Layout data for label/input pair. If null, default GridData will be assigned.
* @return Created Text object
*/
public static ColorSelector createLabeledColorSelector(final Composite parent, final String labelText, Object layoutData) {
Composite group = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.verticalSpacing = INNER_SPACING;
layout.horizontalSpacing = 0;
layout.marginTop = 0;
layout.marginBottom = 0;
layout.marginWidth = 0;
layout.marginHeight = 0;
group.setLayout(layout);
if (layoutData != DEFAULT_LAYOUT_DATA) {
group.setLayoutData(layoutData);
} else {
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
group.setLayoutData(gridData);
}
Label label = new Label(group, SWT.NONE);
label.setText(labelText);
ColorSelector cs = new ColorSelector(group);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
cs.getButton().setLayoutData(gridData);
return cs;
}
use of org.eclipse.jface.preference.ColorSelector in project netxms by netxms.
the class LabelProperties method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
config = (LabelConfig) getElement().getAdapter(LabelConfig.class);
Composite dialogArea = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
dialogArea.setLayout(layout);
title = new LabeledText(dialogArea, SWT.NONE, SWT.BORDER | SWT.MULTI);
title.setLabel(Messages.get().LabelProperties_Title);
title.setText(config.getTitle());
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 2;
title.setLayoutData(gd);
Composite fgArea = new Composite(dialogArea, SWT.NONE);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
fgArea.setLayoutData(gd);
RowLayout areaLayout = new RowLayout();
areaLayout.type = SWT.HORIZONTAL;
areaLayout.marginBottom = 0;
areaLayout.marginTop = 0;
areaLayout.marginLeft = 0;
areaLayout.marginRight = 0;
fgArea.setLayout(areaLayout);
new Label(fgArea, SWT.NONE).setText(Messages.get().LabelProperties_TextColor);
foreground = new ColorSelector(fgArea);
foreground.setColorValue(ColorConverter.rgbFromInt(config.getForegroundColorAsInt()));
Composite bgArea = new Composite(dialogArea, SWT.NONE);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
bgArea.setLayoutData(gd);
areaLayout = new RowLayout();
areaLayout.type = SWT.HORIZONTAL;
areaLayout.marginBottom = 0;
areaLayout.marginTop = 0;
areaLayout.marginLeft = 0;
areaLayout.marginRight = 0;
bgArea.setLayout(areaLayout);
new Label(bgArea, SWT.NONE).setText(Messages.get().LabelProperties_BgColor);
background = new ColorSelector(bgArea);
background.setColorValue(ColorConverter.rgbFromInt(config.getBackgroundColorAsInt()));
return dialogArea;
}
use of org.eclipse.jface.preference.ColorSelector in project netxms by netxms.
the class MapLinkGeneral method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
object = (LinkEditor) getElement().getAdapter(LinkEditor.class);
Composite dialogArea = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
dialogArea.setLayout(layout);
name = new LabeledText(dialogArea, SWT.NONE);
name.setLabel(Messages.get().MapLinkGeneral_Name);
name.setText(object.getName());
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 2;
name.setLayoutData(gd);
connector1 = new LabeledText(dialogArea, SWT.NONE);
connector1.setLabel(Messages.get().MapLinkGeneral_NameConn1);
connector1.setText(object.getConnectorName1());
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 2;
connector1.setLayoutData(gd);
connector2 = new LabeledText(dialogArea, SWT.NONE);
connector2.setLabel(Messages.get().MapLinkGeneral_NameConn2);
connector2.setText(object.getConnectorName2());
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 2;
connector2.setLayoutData(gd);
final Group colorGroup = new Group(dialogArea, SWT.NONE);
colorGroup.setText(Messages.get().MapLinkGeneral_Color);
layout = new GridLayout();
colorGroup.setLayout(layout);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 2;
colorGroup.setLayoutData(gd);
final SelectionListener listener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
color.setEnabled(radioColorCustom.getSelection());
list.setEnabled(radioColorObject.getSelection());
add.setEnabled(radioColorObject.getSelection());
remove.setEnabled(radioColorObject.getSelection());
checkUseThresholds.setEnabled(radioColorObject.getSelection());
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
};
radioColorDefault = new Button(colorGroup, SWT.RADIO);
radioColorDefault.setText(Messages.get().MapLinkGeneral_DefColor);
radioColorDefault.setSelection((object.getColor() < 0) && (object.getStatusObject().size() == 0));
radioColorDefault.addSelectionListener(listener);
radioColorObject = new Button(colorGroup, SWT.RADIO);
radioColorObject.setText(Messages.get().MapLinkGeneral_BasedOnObjStatus);
radioColorObject.setSelection(object.getStatusObject().size() != 0);
radioColorObject.addSelectionListener(listener);
final Composite nodeSelectionGroup = new Composite(colorGroup, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 2;
nodeSelectionGroup.setLayout(layout);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 2;
nodeSelectionGroup.setLayoutData(gd);
list = new List(nodeSelectionGroup, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalSpan = 2;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalIndent = 20;
list.setLayoutData(gd);
if (object.getStatusObject() != null) {
for (int i = 0; i < object.getStatusObject().size(); i++) {
final AbstractObject obj = ((NXCSession) ConsoleSharedData.getSession()).findObjectById(object.getStatusObject().get(i));
// $NON-NLS-1$ //$NON-NLS-2$
list.add((obj != null) ? obj.getObjectName() : ("<" + Long.toString(object.getStatusObject().get(i)) + ">"));
}
}
list.setEnabled(radioColorObject.getSelection());
add = new Button(nodeSelectionGroup, SWT.PUSH);
add.setText(Messages.get().MapLinkGeneral_Add);
gd = new GridData();
gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT;
gd.verticalAlignment = SWT.TOP;
add.setLayoutData(gd);
add.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
addObject();
}
});
add.setEnabled(radioColorObject.getSelection());
remove = new Button(nodeSelectionGroup, SWT.PUSH);
remove.setText(Messages.get().MapLinkGeneral_Delete);
gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT;
gd.verticalAlignment = SWT.TOP;
remove.setLayoutData(gd);
remove.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
removeObject();
}
});
remove.setEnabled(radioColorObject.getSelection());
checkUseThresholds = new Button(nodeSelectionGroup, SWT.CHECK);
checkUseThresholds.setText("Use active thresholds");
checkUseThresholds.setEnabled(radioColorObject.getSelection());
checkUseThresholds.setSelection(object.isUseActiveThresholds());
gd = new GridData();
gd.horizontalIndent = 17;
checkUseThresholds.setLayoutData(gd);
radioColorCustom = new Button(colorGroup, SWT.RADIO);
radioColorCustom.setText(Messages.get().MapLinkGeneral_CustomColor);
radioColorCustom.setSelection((object.getColor() >= 0) && (object.getStatusObject().size() == 0));
radioColorCustom.addSelectionListener(listener);
color = new ColorSelector(colorGroup);
if (radioColorCustom.getSelection())
color.setColorValue(ColorConverter.rgbFromInt(object.getColor()));
else
color.setEnabled(false);
gd = new GridData();
gd.horizontalIndent = 20;
color.getButton().setLayoutData(gd);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
routingAlgorithm = WidgetHelper.createLabeledCombo(dialogArea, SWT.READ_ONLY, Messages.get().MapLinkGeneral_RoutingAlg, gd);
routingAlgorithm.add(Messages.get().MapLinkGeneral_MapDefault);
routingAlgorithm.add(Messages.get().MapLinkGeneral_Direct);
routingAlgorithm.add(Messages.get().MapLinkGeneral_Manhattan);
routingAlgorithm.add(Messages.get().MapLinkGeneral_BendPoints);
routingAlgorithm.select(object.getRoutingAlgorithm());
return dialogArea;
}
use of org.eclipse.jface.preference.ColorSelector in project netxms by netxms.
the class PerfTab method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite dialogArea = (Composite) super.createContents(parent);
dci = editor.getObjectAsItem();
try {
settings = PerfTabGraphSettings.createFromXml(dci.getPerfTabSettings());
} catch (Exception e) {
// Create default empty settings
settings = new PerfTabGraphSettings();
}
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.numColumns = 4;
dialogArea.setLayout(layout);
checkShow = new Button(dialogArea, SWT.CHECK);
checkShow.setText(Messages.get().PerfTab_ShowOnPerfTab);
checkShow.setSelection(settings.isEnabled());
GridData gd = new GridData();
gd.horizontalSpan = layout.numColumns;
checkShow.setLayoutData(gd);
title = new LabeledText(dialogArea, SWT.NONE);
title.setLabel(Messages.get().PerfTab_Title);
title.setText(settings.getTitle());
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
title.setLayoutData(gd);
Composite colors = new Composite(dialogArea, SWT.NONE);
colors.setLayout(new RowLayout(SWT.VERTICAL));
new Label(colors, SWT.NONE).setText(Messages.get().PerfTab_Color);
color = new ColorSelector(colors);
color.setColorValue(ColorConverter.rgbFromInt(settings.getColorAsInt()));
type = WidgetHelper.createLabeledCombo(dialogArea, SWT.READ_ONLY, Messages.get().PerfTab_Type, new GridData(SWT.LEFT, SWT.CENTER, false, false));
type.add(Messages.get().PerfTab_Line);
type.add(Messages.get().PerfTab_Area);
type.select(settings.getType());
orderNumber = WidgetHelper.createLabeledSpinner(dialogArea, SWT.BORDER, Messages.get().PerfTab_Order, 0, 65535, new GridData(SWT.LEFT, SWT.CENTER, false, false));
orderNumber.setSelection(settings.getOrder());
groupName = new LabeledText(dialogArea, SWT.NONE);
groupName.setLabel("Group");
groupName.setText(settings.getGroupName());
gd = new GridData();
gd.horizontalSpan = layout.numColumns;
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
groupName.setLayoutData(gd);
name = new LabeledText(dialogArea, SWT.NONE);
name.setLabel(Messages.get().PerfTab_NameInLegend);
name.setText(settings.getName());
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.horizontalSpan = layout.numColumns;
name.setLayoutData(gd);
Group timeGroup = new Group(dialogArea, SWT.NONE);
timeGroup.setText(Messages.get().PerfTab_TeimePeriod);
GridLayout timeGroupLayout = new GridLayout();
timeGroupLayout.marginWidth = WidgetHelper.OUTER_SPACING;
timeGroupLayout.marginHeight = WidgetHelper.OUTER_SPACING;
timeGroupLayout.horizontalSpacing = 16;
timeGroupLayout.makeColumnsEqualWidth = true;
timeGroupLayout.numColumns = 1;
timeGroup.setLayout(timeGroupLayout);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = timeGroupLayout.numColumns;
timeGroup.setLayoutData(gd);
Composite timeRangeArea = new Composite(timeGroup, SWT.NONE);
timeGroupLayout = new GridLayout();
timeGroupLayout.numColumns = 2;
timeGroupLayout.marginWidth = 0;
timeGroupLayout.marginHeight = 0;
timeGroupLayout.horizontalSpacing = WidgetHelper.DIALOG_SPACING;
timeRangeArea.setLayout(timeGroupLayout);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
timeRangeArea.setLayoutData(gd);
timeRange = WidgetHelper.createLabeledSpinner(timeRangeArea, SWT.BORDER, Messages.get().PerfTab_TimeInterval, 1, 10000, WidgetHelper.DEFAULT_LAYOUT_DATA);
timeRange.setSelection(settings.getTimeRange());
timeUnits = WidgetHelper.createLabeledCombo(timeRangeArea, SWT.READ_ONLY, Messages.get().PerfTab_TimeUnits, WidgetHelper.DEFAULT_LAYOUT_DATA);
timeUnits.add(Messages.get().PerfTab_Minutes);
timeUnits.add(Messages.get().PerfTab_Hours);
timeUnits.add(Messages.get().PerfTab_Days);
timeUnits.select(settings.getTimeUnits());
Group optionsGroup = new Group(dialogArea, SWT.NONE);
optionsGroup.setText(Messages.get().PerfTab_Options);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 3;
gd.verticalSpan = 2;
optionsGroup.setLayoutData(gd);
GridLayout optionsLayout = new GridLayout();
optionsGroup.setLayout(optionsLayout);
checkShowThresholds = new Button(optionsGroup, SWT.CHECK);
checkShowThresholds.setText(Messages.get().PerfTab_ShowThresholds);
checkShowThresholds.setSelection(settings.isShowThresholds());
gd = new GridData();
gd.horizontalSpan = layout.numColumns;
checkShowThresholds.setLayoutData(gd);
checkLogScale = new Button(optionsGroup, SWT.CHECK);
checkLogScale.setText(Messages.get().PerfTab_LogarithmicScale);
checkLogScale.setSelection(settings.isLogScaleEnabled());
gd = new GridData();
gd.horizontalSpan = layout.numColumns;
checkLogScale.setLayoutData(gd);
checkStacked = new Button(optionsGroup, SWT.CHECK);
checkStacked.setText("&Stacked");
checkStacked.setSelection(settings.isStacked());
gd = new GridData();
gd.horizontalSpan = layout.numColumns;
checkStacked.setLayoutData(gd);
checkShowLegendAlways = new Button(optionsGroup, SWT.CHECK);
checkShowLegendAlways.setText("Always show &legend");
checkShowLegendAlways.setSelection(settings.isShowLegendAlways());
gd = new GridData();
gd.horizontalSpan = layout.numColumns;
checkShowLegendAlways.setLayoutData(gd);
checkExtendedLegend = new Button(optionsGroup, SWT.CHECK);
checkExtendedLegend.setText("&Extended legend");
checkExtendedLegend.setSelection(settings.isExtendedLegend());
gd = new GridData();
gd.horizontalSpan = layout.numColumns;
checkExtendedLegend.setLayoutData(gd);
checkInvertValues = new Button(optionsGroup, SWT.CHECK);
checkInvertValues.setText("&Inverted values");
checkInvertValues.setSelection(settings.isInvertedValues());
gd = new GridData();
gd.horizontalSpan = layout.numColumns;
checkInvertValues.setLayoutData(gd);
yAxisRange = new YAxisRangeEditor(dialogArea, SWT.NONE);
gd = new GridData();
gd.horizontalSpan = layout.numColumns;
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
yAxisRange.setLayoutData(gd);
yAxisRange.setSelection(settings.isAutoScale(), settings.modifyYBase(), settings.getMinYScaleValue(), settings.getMaxYScaleValue());
return dialogArea;
}
use of org.eclipse.jface.preference.ColorSelector in project webtools.sourceediting by eclipse.
the class HTMLSyntaxColoringPage method createContents.
protected Control createContents(final Composite parent) {
initializeDialogUnits(parent);
fDefaultForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
fDefaultBackground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
Composite pageComponent = createComposite(parent, 2);
PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.HTML_PREFWEBX_STYLES_HELPID);
Link link = new Link(pageComponent, SWT.WRAP);
link.setText(SSEUIMessages.SyntaxColoring_Link);
link.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
}
});
GridData linkData = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1);
// only expand further if anyone else requires it
linkData.widthHint = 150;
link.setLayoutData(linkData);
new Label(pageComponent, SWT.NONE).setLayoutData(new GridData());
new Label(pageComponent, SWT.NONE).setLayoutData(new GridData());
SashForm editor = new SashForm(pageComponent, SWT.VERTICAL);
GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData2.horizontalSpan = 2;
editor.setLayoutData(gridData2);
SashForm top = new SashForm(editor, SWT.HORIZONTAL);
Composite styleEditor = createComposite(top, 1);
((GridLayout) styleEditor.getLayout()).marginRight = 5;
((GridLayout) styleEditor.getLayout()).marginLeft = 0;
createLabel(styleEditor, HTMLUIMessages.SyntaxColoringPage_0);
fStylesViewer = createStylesViewer(styleEditor);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.horizontalIndent = 0;
Iterator iterator = fStyleToDescriptionMap.values().iterator();
while (iterator.hasNext()) {
gridData.widthHint = Math.max(gridData.widthHint, convertWidthInCharsToPixels(iterator.next().toString().length()));
}
gridData.heightHint = convertHeightInCharsToPixels(5);
fStylesViewer.getControl().setLayoutData(gridData);
Composite editingComposite = createComposite(top, 1);
((GridLayout) styleEditor.getLayout()).marginLeft = 5;
// $NON-NLS-1$
createLabel(editingComposite, "");
Button enabler = createCheckbox(editingComposite, HTMLUIMessages.SyntaxColoringPage_2);
enabler.setEnabled(false);
enabler.setSelection(true);
Composite editControls = createComposite(editingComposite, 2);
((GridLayout) editControls.getLayout()).marginLeft = 20;
fForegroundLabel = createLabel(editControls, SSEUIMessages.Foreground_UI_);
((GridData) fForegroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
fForegroundLabel.setEnabled(false);
fForegroundColorEditor = new ColorSelector(editControls);
Button fForegroundColor = fForegroundColorEditor.getButton();
GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
fForegroundColor.setLayoutData(gd);
fForegroundColorEditor.setEnabled(false);
fForegroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() {
public void getName(final AccessibleEvent e) {
e.result = SSEUIMessages.Foreground_Color_Selector_Button;
}
});
fBackgroundLabel = createLabel(editControls, SSEUIMessages.Background_UI_);
((GridData) fBackgroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER;
fBackgroundLabel.setEnabled(false);
fBackgroundColorEditor = new ColorSelector(editControls);
Button fBackgroundColor = fBackgroundColorEditor.getButton();
gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
fBackgroundColor.setLayoutData(gd);
fBackgroundColorEditor.setEnabled(false);
fBackgroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() {
public void getName(final AccessibleEvent e) {
e.result = SSEUIMessages.Background_Color_Selector_Button;
}
});
fBold = createCheckbox(editControls, HTMLUIMessages.SyntaxColoringPage_3);
fBold.setEnabled(false);
((GridData) fBold.getLayoutData()).horizontalSpan = 2;
fItalic = createCheckbox(editControls, HTMLUIMessages.SyntaxColoringPage_4);
fItalic.setEnabled(false);
((GridData) fItalic.getLayoutData()).horizontalSpan = 2;
fStrike = createCheckbox(editControls, HTMLUIMessages.SyntaxColoringPage_5);
fStrike.setEnabled(false);
((GridData) fStrike.getLayoutData()).horizontalSpan = 2;
fUnderline = createCheckbox(editControls, HTMLUIMessages.SyntaxColoringPage_6);
fUnderline.setEnabled(false);
((GridData) fUnderline.getLayoutData()).horizontalSpan = 2;
fClearStyle = new Button(editingComposite, SWT.PUSH);
// $NON-NLS-1$ = "Restore Default"
fClearStyle.setText(SSEUIMessages.Restore_Default_UI_);
fClearStyle.setLayoutData(new GridData(SWT.BEGINNING));
((GridData) fClearStyle.getLayoutData()).horizontalIndent = 20;
fClearStyle.setEnabled(false);
Composite sampleArea = createComposite(editor, 1);
((GridLayout) sampleArea.getLayout()).marginLeft = 5;
((GridLayout) sampleArea.getLayout()).marginTop = 5;
// $NON-NLS-1$ = "&Sample text:"
createLabel(sampleArea, SSEUIMessages.Sample_text__UI_);
fPreviewViewer = new SourceViewer(sampleArea, null, SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
fText = fPreviewViewer.getTextWidget();
GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData3.widthHint = convertWidthInCharsToPixels(20);
gridData3.heightHint = convertHeightInCharsToPixels(5);
gridData3.horizontalSpan = 2;
fText.setLayoutData(gridData3);
fText.setEditable(false);
// $NON-NLS-1$
fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
fText.addKeyListener(getTextKeyListener());
fText.addSelectionListener(getTextSelectionListener());
fText.addMouseListener(getTextMouseListener());
fText.addTraverseListener(getTraverseListener());
setAccessible(fText, SSEUIMessages.Sample_text__UI_);
fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForHTML.ContentTypeID_HTML);
fDocument.set(getExampleText());
initializeSourcePreviewColors(fPreviewViewer);
fPreviewViewer.setDocument(fDocument);
top.setWeights(new int[] { 1, 1 });
editor.setWeights(new int[] { 1, 1 });
PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.HTML_PREFWEBX_STYLES_HELPID);
fStylesViewer.setInput(getStylePreferenceKeys());
applyStyles();
fStylesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (!event.getSelection().isEmpty()) {
Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
String namedStyle = o.toString();
activate(namedStyle);
if (namedStyle == null)
return;
}
}
});
fForegroundColorEditor.addListener(new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
String namedStyle = o.toString();
String prefString = getOverlayStore().getString(namedStyle);
String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
if (stylePrefs != null) {
String oldValue = stylePrefs[0];
// open color dialog to get new color
String newValue = ColorHelper.toRGBString(fForegroundColorEditor.getColorValue());
if (!newValue.equals(oldValue)) {
stylePrefs[0] = newValue;
String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
getOverlayStore().setValue(namedStyle, newPrefString);
applyStyles();
fText.redraw();
}
}
}
}
});
fBackgroundColorEditor.addListener(new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) {
Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
String namedStyle = o.toString();
String prefString = getOverlayStore().getString(namedStyle);
String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
if (stylePrefs != null) {
String oldValue = stylePrefs[1];
// open color dialog to get new color
String newValue = ColorHelper.toRGBString(fBackgroundColorEditor.getColorValue());
if (!newValue.equals(oldValue)) {
stylePrefs[1] = newValue;
String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
getOverlayStore().setValue(namedStyle, newPrefString);
applyStyles();
fText.redraw();
activate(namedStyle);
}
}
}
}
});
fBold.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
// get current (newly old) style
Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
String namedStyle = o.toString();
String prefString = getOverlayStore().getString(namedStyle);
String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
if (stylePrefs != null) {
String oldValue = stylePrefs[2];
String newValue = String.valueOf(fBold.getSelection());
if (!newValue.equals(oldValue)) {
stylePrefs[2] = newValue;
String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
getOverlayStore().setValue(namedStyle, newPrefString);
applyStyles();
fText.redraw();
}
}
}
});
fItalic.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
// get current (newly old) style
Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
String namedStyle = o.toString();
String prefString = getOverlayStore().getString(namedStyle);
String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
if (stylePrefs != null) {
String oldValue = stylePrefs[3];
String newValue = String.valueOf(fItalic.getSelection());
if (!newValue.equals(oldValue)) {
stylePrefs[3] = newValue;
String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
getOverlayStore().setValue(namedStyle, newPrefString);
applyStyles();
fText.redraw();
}
}
}
});
fStrike.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
// get current (newly old) style
Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
String namedStyle = o.toString();
String prefString = getOverlayStore().getString(namedStyle);
String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
if (stylePrefs != null) {
String oldValue = stylePrefs[4];
String newValue = String.valueOf(fStrike.getSelection());
if (!newValue.equals(oldValue)) {
stylePrefs[4] = newValue;
String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
getOverlayStore().setValue(namedStyle, newPrefString);
applyStyles();
fText.redraw();
}
}
}
});
fUnderline.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
// get current (newly old) style
Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement();
String namedStyle = o.toString();
String prefString = getOverlayStore().getString(namedStyle);
String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
if (stylePrefs != null) {
String oldValue = stylePrefs[5];
String newValue = String.valueOf(fUnderline.getSelection());
if (!newValue.equals(oldValue)) {
stylePrefs[5] = newValue;
String newPrefString = ColorHelper.packStylePreferences(stylePrefs);
getOverlayStore().setValue(namedStyle, newPrefString);
applyStyles();
fText.redraw();
}
}
}
});
fClearStyle.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (fStylesViewer.getSelection().isEmpty())
return;
String namedStyle = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement().toString();
getOverlayStore().setToDefault(namedStyle);
applyStyles();
fText.redraw();
activate(namedStyle);
}
});
return pageComponent;
}
Aggregations