Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 57425 Details for
Bug 171519
RIM source color support only highlights tags
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Patch for the bug
patch-171519.txt (text/plain), 98.92 KB, created by
Zsolt Török
on 2007-01-24 07:48:37 EST
(
hide
)
Description:
Patch for the bug
Filename:
MIME Type:
Creator:
Zsolt Török
Created:
2007-01-24 07:48:37 EST
Size:
98.92 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ohf.h3et.instanceeditor.ui >Index: src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyledTextColorPicker.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.ohf/plugins/org.eclipse.ohf.h3et.instanceeditor.ui/src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyledTextColorPicker.java,v >retrieving revision 1.1 >diff -u -r1.1 MessageInstanceStyledTextColorPicker.java >--- src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyledTextColorPicker.java 22 Jan 2007 14:07:07 -0000 1.1 >+++ src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyledTextColorPicker.java 24 Jan 2007 12:48:12 -0000 >@@ -1,634 +1,916 @@ >-/******************************************************************************* >- * Crown Copyright (c) 2006, 2007, Copyright (c) 2006, 2007 Jiva Medical. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Jiva Medical - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.ohf.h3et.instanceeditor.ui.preferences; >- >-import org.eclipse.jface.preference.IPreferenceStore; >-import org.eclipse.jface.resource.JFaceResources; >-import org.eclipse.jface.text.TextAttribute; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.accessibility.ACC; >-import org.eclipse.swt.accessibility.AccessibleAdapter; >-import org.eclipse.swt.accessibility.AccessibleEvent; >-import org.eclipse.swt.custom.StyledText; >-import org.eclipse.swt.events.KeyEvent; >-import org.eclipse.swt.events.KeyListener; >-import org.eclipse.swt.events.MouseEvent; >-import org.eclipse.swt.events.MouseListener; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; >-import org.eclipse.swt.events.TraverseEvent; >-import org.eclipse.swt.events.TraverseListener; >-import org.eclipse.swt.graphics.Color; >-import org.eclipse.swt.graphics.Font; >-import org.eclipse.swt.graphics.GC; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.graphics.ImageData; >-import org.eclipse.swt.graphics.PaletteData; >-import org.eclipse.swt.graphics.Point; >-import org.eclipse.swt.graphics.RGB; >-import org.eclipse.swt.layout.GridData; >-import org.eclipse.swt.layout.GridLayout; >-import org.eclipse.swt.widgets.Button; >-import org.eclipse.swt.widgets.ColorDialog; >-import org.eclipse.swt.widgets.Combo; >-import org.eclipse.swt.widgets.Composite; >-import org.eclipse.swt.widgets.Control; >-import org.eclipse.swt.widgets.Group; >-import org.eclipse.swt.widgets.Label; >-import org.eclipse.wst.sse.ui.internal.SSEUIMessages; >-import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper; >-import org.eclipse.wst.sse.ui.internal.preferences.ui.StyledTextColorPicker; >-import org.eclipse.wst.sse.ui.internal.util.EditorUtility; >- >-/** >- * @author zsolt >- * >- */ >-public class MessageInstanceStyledTextColorPicker extends StyledTextColorPicker { >- >- boolean foregroundPickerEnabled = true; >- >- boolean backgroundPickerEnabled = true; >- >- Button rimFgColorButton; >- >- Button rimBgColorButton; >- >- private IPreferenceStore fPreferenceStore; >- >- private Button chooseFgColorButton; >- >- private Button chooseBgColorButton; >- >- public MessageInstanceStyledTextColorPicker(Composite parent, int style) { >- super(parent, style); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.wst.sse.ui.internal.preferences.ui.StyledTextColorPicker#createControls(org.eclipse.swt.widgets.Composite) >- */ >- @Override >- protected void createControls(Composite parent) { >- >- Composite styleRow = createComposite(parent, 3); >- // row 1 - content type label, combo box, restore defaults >- createLabel(styleRow, SSEUIMessages.Content_type__UI_); //$NON-NLS-1$ = "Content type:" >- // Contexts combo box >- fStyleCombo = createCombo(styleRow, new String[0], -1); >- fClearStyle = createPushButton(styleRow, >- SSEUIMessages.Restore_Default_UI_); //$NON-NLS-1$ = "Restore Default" >- >- Composite styleRow2 = createComposite(parent, 2); >- Group foregroundGroup = createGroup(styleRow2, SWT.SHADOW_IN, 1); >- foregroundGroup.setText(SSEUIMessages.Foreground_UI_); //$NON-NLS-1$ = "Foreground" >- Group backgroundGroup = createGroup(styleRow2, SWT.SHADOW_IN, 1); >- backgroundGroup.setText(SSEUIMessages.Background_UI_); //$NON-NLS-1$ = "Background" >- >- rimFgColorButton = new Button(foregroundGroup, SWT.RADIO); >- rimFgColorButton.setText("RIM color"); >- chooseFgColorButton = new Button(foregroundGroup, SWT.RADIO); >- chooseFgColorButton.setText("Choose color"); >-// fForegroundLabel = createLabel(foregroundGroup, SSEUIMessages.Foreground_UI_); //$NON-NLS-1$ = "Foreground" >- fForeground = createPushButton(foregroundGroup, ""); //$NON-NLS-1$ >- setAccessible(fForeground, foregroundGroup.getText()); >- fForeground.getAccessible().addAccessibleControlListener(foregroundAccListener); >- Point buttonSize = computeImageSize(fForeground); >- ((GridData) fForeground.getLayoutData()).widthHint = buttonSize.x; >- ((GridData) fForeground.getLayoutData()).heightHint = buttonSize.y; >- >- >- rimBgColorButton = new Button(backgroundGroup, SWT.RADIO); >- rimBgColorButton.setText("RIM color"); >- chooseBgColorButton = new Button(backgroundGroup, SWT.RADIO); >- chooseBgColorButton.setText("Choose color"); >-// fBackgroundLabel = createLabel(backgroundGroup, SSEUIMessages.Background_UI_); //$NON-NLS-1$ = "Background" >- fBackground = createPushButton(backgroundGroup, ""); //$NON-NLS-1$ >- setAccessible(fBackground, backgroundGroup.getText()); >- fBackground.getAccessible().addAccessibleControlListener(backgroundAccListener); >- buttonSize = computeImageSize(fBackground); >- ((GridData) fBackground.getLayoutData()).widthHint = buttonSize.x; >- ((GridData) fBackground.getLayoutData()).heightHint = buttonSize.y; >- >- fForeground.setEnabled(false); >- fBackground.setEnabled(false); >- fClearStyle.setEnabled(false); >- >-// fForegroundLabel.setEnabled(false); >-// fBackgroundLabel.setEnabled(false); >- >- Composite sample = createComposite(parent, 1); >- createLabel(sample, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:" >- // BUG141089 - make sure text is left-aligned >- fText = new StyledText(sample, SWT.LEFT_TO_RIGHT | SWT.MULTI >- | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.READ_ONLY); >- GridData data = new GridData(GridData.FILL_BOTH); >- fText.setLayoutData(data); >- fText.setEditable(false); >- fText.setBackground(fDefaultBackground); >- fText.setFont(JFaceResources.getTextFont()); >- fText.addKeyListener(getTextKeyListener()); >- fText.addSelectionListener(getTextSelectionListener()); >- fText.addMouseListener(getTextMouseListener()); >- fText.addTraverseListener(getTraverseListener()); // defect 220377 - >- // Provide tab >- // traversal for >- // fText widget >- setAccessible(fText, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:" >- fForeground.addSelectionListener(getSelectionListener()); >- rimFgColorButton.addSelectionListener(getSelectionListener()); >- fBackground.addSelectionListener(getSelectionListener()); >- rimBgColorButton.addSelectionListener(getSelectionListener()); >- fClearStyle.addSelectionListener(getSelectionListener()); >- fStyleCombo.addSelectionListener(comboListener); >- } >- >- /** >- * Determines size of color button copied from >- * org.eclipse.jdt.internal.ui.preferences.ColorEditor 1 modification - >- * added 14 to final height >- */ >- private Point computeImageSize(Control window) { >- GC gc = new GC(window); >- Font f = JFaceResources.getFontRegistry().get( >- JFaceResources.DEFAULT_FONT); >- gc.setFont(f); >- int height = gc.getFontMetrics().getHeight(); >- gc.dispose(); >- Point p = new Point(height * 3 - 6, height + 14); >- return p; >- } >- >- /** >- * 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 >- */ >- private Button createCheckBox(Composite group, String label) { >- Button button = new Button(group, SWT.CHECK | SWT.CENTER); >- if (label != null) >- button.setText(label); >- GridData data = new GridData(GridData.FILL_BOTH); >- data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END; >- // data.verticalAlignment = GridData.VERTICAL_ALIGN_FILL; >- button.setLayoutData(data); >- return button; >- } >- >- private Combo createCombo(Composite parent, String[] labels, >- int selectedItem) { >- Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY); >- combo.setItems(labels); >- if (selectedItem >= 0) >- combo.select(selectedItem); >- GridData data = new GridData(GridData.FILL_HORIZONTAL); >- data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_FILL; >- combo.setLayoutData(data); >- return combo; >- } >- >- private Group createGroup(Composite parent, int style, int numColumns) { >- Group group = new Group(parent, style); >- GridLayout layout = new GridLayout(); >- layout.numColumns = numColumns; >- layout.horizontalSpacing = 5; >- layout.makeColumnsEqualWidth = false; >- group.setLayout(layout); >- // GridData >- GridData data = new GridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL); >- data.grabExcessVerticalSpace = false; >- data.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; >- group.setLayoutData(data); >- return group; >- } >- >- private Composite createComposite(Composite parent, int numColumns) { >- return createComposite(parent, SWT.NULL, numColumns); >- } >- >- /** >- * Creates composite control and sets the default layout data. >- */ >- private Composite createComposite(Composite parent, int style, int numColumns) { >- Composite composite = new Composite(parent, SWT.NULL); >- // GridLayout >- GridLayout layout = new GridLayout(); >- layout.numColumns = numColumns; >- layout.horizontalSpacing = 5; >- layout.makeColumnsEqualWidth = false; >- composite.setLayout(layout); >- // GridData >- GridData data = new GridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); >- data.grabExcessVerticalSpace = false; >- data.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; >- composite.setLayoutData(data); >- return composite; >- } >- >- /** >- * Utility method that creates a label instance and sets the default layout >- * data. >- */ >- private Label createLabel(Composite parent, String text) { >- Label label = new Label(parent, SWT.LEFT); >- label.setText(text); >- GridData data = new GridData(); >- data.horizontalAlignment = GridData.FILL; >- label.setLayoutData(data); >- return label; >- } >- >- private Button createPushButton(Composite parent, String label) { >- Button button = new Button(parent, SWT.PUSH); >- button.setText(label); >- GridData data = new GridData(GridData.FILL_BOTH); >- // data.horizontalAlignment = GridData.FILL; >- data.grabExcessHorizontalSpace = true; >- button.setLayoutData(data); >- return button; >- } >- >- private SelectionListener getSelectionListener() { >- return new SelectionListener() { >- >- public void widgetDefaultSelected(SelectionEvent e) { >- widgetSelected(e); >- } >- >- public void widgetSelected(SelectionEvent e) { >- String namedStyle = getStyleName(fStyleCombo.getItem(fStyleCombo.getSelectionIndex())); >- if (namedStyle == null) >- return; >- if (e.widget == fForeground) { >- // get current (newly old) style >- String prefString = getPreferenceStore().getString(getPreferenceKey(namedStyle)); >- String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); >- if (stylePrefs != null) { >- String oldValue = stylePrefs[0]; >- // open color dialog to get new color >- String newValue = changeColor(oldValue); >- >- if (!newValue.equals(oldValue)) { >- stylePrefs[0] = newValue; >- String newPrefString = ColorHelper.packStylePreferences(stylePrefs); >- getPreferenceStore().setValue(getPreferenceKey(namedStyle), newPrefString); >- refresh(); >- } >- } >- } else if (e.widget == fBackground) { >- // get current (newly old) style >- String prefString = getPreferenceStore().getString(getPreferenceKey(namedStyle)); >- String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); >- if (stylePrefs != null) { >- String oldValue = stylePrefs[1]; >- // open color dialog to get new color >- String newValue = changeColor(oldValue); >- >- if (!newValue.equals(oldValue)) { >- stylePrefs[1] = newValue; >- String newPrefString = ColorHelper.packStylePreferences(stylePrefs); >- getPreferenceStore().setValue(getPreferenceKey(namedStyle), newPrefString); >- refresh(); >- } >- } >- } else if (e.widget == fClearStyle) { >- getPreferenceStore().setToDefault(getPreferenceKey(namedStyle)); >- refresh(); >- } else if (e.widget == rimFgColorButton) { >- Button button = (Button) e.widget; >- if (button.getSelection()) { >- setForegroundPickerEnabled(false); >- getPreferenceStore().setValue(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_FOREGROUND, true); >- } else { >- setForegroundPickerEnabled(true); >- getPreferenceStore().setValue(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_FOREGROUND, false); >- } >- } else if (e.widget == rimBgColorButton) { >- Button button = (Button) e.widget; >- if (button.getSelection()) { >- setBackgroundPickerEnabled(false); >- getPreferenceStore().setValue(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_BACKGROUND, true); >- } else { >- setBackgroundPickerEnabled(true); >- getPreferenceStore().setValue(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_BACKGROUND, false); >- } >- } >- } >- }; >- } >- >- private KeyListener getTextKeyListener() { >- return new KeyListener() { >- public void keyPressed(KeyEvent e) { >- if (e.widget instanceof StyledText) { >- int x = ((StyledText) e.widget).getCaretOffset(); >- selectColorAtOffset(x); >- } >- } >- >- public void keyReleased(KeyEvent e) { >- if (e.widget instanceof StyledText) { >- int x = ((StyledText) e.widget).getCaretOffset(); >- selectColorAtOffset(x); >- } >- } >- }; >- } >- >- private MouseListener getTextMouseListener() { >- return new MouseListener() { >- public void mouseDoubleClick(MouseEvent e) { >- } >- >- public void mouseDown(MouseEvent e) { >- } >- >- public void mouseUp(MouseEvent e) { >- if (e.widget instanceof StyledText) { >- int x = ((StyledText) e.widget).getCaretOffset(); >- selectColorAtOffset(x); >- } >- } >- }; >- } >- >- private SelectionListener getTextSelectionListener() { >- return new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- selectColorAtOffset(e.x); >- if (e.widget instanceof StyledText) { >- ((StyledText) e.widget).setSelection(e.x); >- } >- } >- >- // Commented out when moving to RC2 to remove "unused" error/warning >- // public void widgetDoubleSelected(SelectionEvent e) { >- // selectColorAtOffset(e.x); >- // if (e.widget instanceof StyledText) { >- // ((StyledText) e.widget).setSelection(e.x); >- // } >- // } >- >- public void widgetSelected(SelectionEvent e) { >- selectColorAtOffset(e.x); >- if (e.widget instanceof StyledText) { >- ((StyledText) e.widget).setSelection(e.x); >- } >- } >- }; >- } >- >- // defect 220377 - Provide tab traversal for fText widget >- private TraverseListener getTraverseListener() { >- return new TraverseListener() { >- /** >- * @see org.eclipse.swt.events.TraverseListener#keyTraversed(TraverseEvent) >- */ >- public void keyTraversed(TraverseEvent e) { >- if (e.widget instanceof StyledText) { >- if ((e.detail == SWT.TRAVERSE_TAB_NEXT) >- || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) >- e.doit = true; >- } >- } >- }; >- } >- >- /** >- * Specifically set the reporting name of a control for accessibility >- */ >- private void setAccessible(Control control, String name) { >- if (control == null) >- return; >- final String n = name; >- control.getAccessible().addAccessibleListener(new AccessibleAdapter() { >- public void getName(AccessibleEvent e) { >- if (e.childID == ACC.CHILDID_SELF) >- e.result = n; >- } >- }); >- } >- >- private void selectColorAtOffset(int offset) { >- String namedStyle = getNamedStyleAtOffset(offset); >- if (namedStyle == null) { >- fStyleCombo.deselectAll(); >- activate(null); >- return; >- } >- String description = (String) getDescriptions().get(namedStyle); >- if (description == null) >- return; >- int itemCount = fStyleCombo.getItemCount(); >- for (int i = 0; i < itemCount; i++) { >- if (fStyleCombo.getItem(i).equals(description)) { >- fStyleCombo.select(i); >- break; >- } >- } >- activate(namedStyle); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.wst.sse.ui.internal.preferences.ui.StyledTextColorPicker#releasePickerResources() >- */ >- @Override >- public void releasePickerResources() { >- if (fForeground != null && !fForeground.isDisposed() >- && fForeground.getImage() != null) >- fForeground.getImage().dispose(); >- if (fBackground != null && !fBackground.isDisposed() >- && fBackground.getImage() != null) >- fBackground.getImage().dispose(); >- } >- >- public void refresh() { >- fText.setRedraw(false); >- int selectedIndex = fStyleCombo.getSelectionIndex(); >- String description = selectedIndex >= 0 ? fStyleCombo.getItem(selectedIndex) : null; >- activate(getStyleName(description)); >- // update Font >- fText.setFont(JFaceResources.getTextFont()); >- // reapplyStyles >- applyStyles(); >- fText.setRedraw(true); >- } >- >- private String getStyleName(String description) { >- if (description == null) >- return null; >- String styleName = null; >- java.util.Enumeration keys = getDescriptions().keys(); >- while (keys.hasMoreElements()) { >- String test = keys.nextElement().toString(); >- if (getDescriptions().get(test).equals(description)) { >- styleName = test; >- break; >- } >- } >- return styleName; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.wst.sse.ui.internal.preferences.ui.StyledTextColorPicker#setPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) >- */ >- @Override >- public void setPreferenceStore(IPreferenceStore store) { >- // TODO Auto-generated method stub >- // super.setPreferenceStore(store); >- fPreferenceStore = store; >- } >- >- private IPreferenceStore getPreferenceStore() { >- return fPreferenceStore; >- } >- >- protected TextAttribute getAttribute(String namedStyle) { >- TextAttribute ta = new TextAttribute(getDefaultForeground(), getDefaultBackground(), SWT.NORMAL); >- >- if (namedStyle != null && getPreferenceStore() != null) { >- String prefString = getPreferenceStore().getString(getPreferenceKey(namedStyle)); >- String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); >- if (stylePrefs != null) { >- RGB foreground = ColorHelper.toRGB(stylePrefs[0]); >- RGB background = ColorHelper.toRGB(stylePrefs[1]); >- >- int fontModifier = SWT.NORMAL; >- boolean bold = Boolean.valueOf(stylePrefs[2]).booleanValue(); >- if (bold) >- fontModifier = fontModifier | SWT.BOLD; >- >- if (showItalic) { >- boolean italic = Boolean.valueOf(stylePrefs[3]).booleanValue(); >- if (italic) >- fontModifier = fontModifier | SWT.ITALIC; >- } >- >- ta = new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, fontModifier); >- } >- } >- return ta; >- } >- >- /** >- * @deprecated just key key (no need for generator) >- */ >- private String getPreferenceKey(String key) { >- String newKey = key; >- // if (fGeneratorKey != null) { >- // newKey = PreferenceKeyGenerator.generateKey(key, fGeneratorKey); >- // } >- return newKey; >- } >- >- private RGB changeColor(RGB startValue) { >- ColorDialog colorDlg = new ColorDialog(getShell()); >- if (startValue != null) >- colorDlg.setRGB(startValue); >- if (colorDlg.getText() == null || colorDlg.getText().length() == 0) >- colorDlg.setText(SSEUIMessages.StyledTextColorPicker_0); >- colorDlg.open(); >- RGB newRGB = colorDlg.getRGB(); >- if (newRGB != null) >- return newRGB; >- return startValue; >- } >- >- private String changeColor(String rgb) { >- String changedColor = "null"; //$NON-NLS-1$ >- >- RGB newColor = changeColor(ColorHelper.toRGB(rgb)); >- // null check to see if using default value >- if (newColor != null) >- changedColor = ColorHelper.toRGBString(newColor); >- return changedColor; >- } >- >- // activate controls based on the given local color type >- protected void activate(String namedStyle) { >- if (namedStyle == null) { >- fForeground.setEnabled(isForegroundPickerEnabled()); >- fBackground.setEnabled(isBackgroundPickerEnabled()); >- fClearStyle.setEnabled(false); >- } >- else { >- fForeground.setEnabled(isForegroundPickerEnabled()); >- fBackground.setEnabled(isBackgroundPickerEnabled()); >- fClearStyle.setEnabled(true); >- >- } >- TextAttribute attribute = getAttribute(namedStyle); >- Color color = attribute.getForeground(); >- if (color == null) { >- color = fDefaultForeground; >- } >- if (fForeground.getSize().x > 0 && fForeground.getSize().y > 0 && (fForeground.getImage() == null || fForeground.getImage().getImageData() == null || fForeground.getImage().getImageData().getRGBs() == null || fForeground.getImage().getImageData().getRGBs().length < 1 || !fForeground.getImage().getImageData().getRGBs()[0].equals(color.getRGB()))) { >- if (fForeground.getImage() != null) >- fForeground.getImage().dispose(); >- Image foreground = new Image(getDisplay(), new ImageData(fForeground.getSize().x - 20, fForeground.getSize().y - 10, 1, new PaletteData(new RGB[]{color.getRGB()}))); >- fForeground.setImage(foreground); >- } >- color = attribute.getBackground(); >- if (color == null) { >- color = fDefaultBackground; >- } >- if (fBackground.getSize().x > 0 && fBackground.getSize().y > 0 && (fBackground.getImage() == null || fBackground.getImage().getImageData() == null || fBackground.getImage().getImageData().getRGBs() == null || fBackground.getImage().getImageData().getRGBs().length < 1 || !fBackground.getImage().getImageData().getRGBs()[0].equals(color.getRGB()))) { >- if (fBackground.getImage() != null) >- fBackground.getImage().dispose(); >- Image background = new Image(getDisplay(), new ImageData(fBackground.getSize().x - 20, fBackground.getSize().y - 10, 1, new PaletteData(new RGB[]{color.getRGB()}))); >- fBackground.setImage(background); >- } >- } >- >- /** >- * @return the backgroundPickerEnabled >- */ >- public boolean isBackgroundPickerEnabled() { >- return backgroundPickerEnabled; >- } >- >- /** >- * @param backgroundPickerEnabled the backgroundPickerEnabled to set >- */ >- public void setBackgroundPickerEnabled(boolean backgroundPickerEnabled) { >- this.backgroundPickerEnabled = backgroundPickerEnabled; >- rimBgColorButton.setSelection(!backgroundPickerEnabled); >- chooseBgColorButton.setSelection(backgroundPickerEnabled); >- fBackground.setEnabled(backgroundPickerEnabled); >- } >- >- /** >- * @return the foregroundPickerEnabled >- */ >- public boolean isForegroundPickerEnabled() { >- return foregroundPickerEnabled; >- } >- >- /** >- * @param foregroundPickerEnabled the foregroundPickerEnabled to set >- */ >- public void setForegroundPickerEnabled(boolean foregroundPickerEnabled) { >- this.foregroundPickerEnabled = foregroundPickerEnabled; >- rimFgColorButton.setSelection(!foregroundPickerEnabled); >- chooseFgColorButton.setSelection(foregroundPickerEnabled); >- fForeground.setEnabled(foregroundPickerEnabled); >- >- } >-} >+/** >+ * >+ */ >+package org.eclipse.ohf.h3et.instanceeditor.ui.preferences; >+ >+import java.io.CharArrayReader; >+import java.text.Collator; >+import java.util.Dictionary; >+import java.util.List; >+ >+import org.eclipse.jface.preference.ColorSelector; >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.jface.resource.JFaceResources; >+import org.eclipse.jface.text.TextAttribute; >+import org.eclipse.jface.util.IPropertyChangeListener; >+import org.eclipse.jface.util.PropertyChangeEvent; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.accessibility.ACC; >+import org.eclipse.swt.accessibility.AccessibleAdapter; >+import org.eclipse.swt.accessibility.AccessibleControlAdapter; >+import org.eclipse.swt.accessibility.AccessibleControlEvent; >+import org.eclipse.swt.accessibility.AccessibleControlListener; >+import org.eclipse.swt.accessibility.AccessibleEvent; >+import org.eclipse.swt.custom.StyleRange; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.KeyListener; >+import org.eclipse.swt.events.MouseEvent; >+import org.eclipse.swt.events.MouseListener; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.events.TraverseEvent; >+import org.eclipse.swt.events.TraverseListener; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.RGB; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Group; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser; >+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; >+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; >+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; >+import org.eclipse.wst.sse.core.internal.util.Debug; >+import org.eclipse.wst.sse.ui.internal.SSEUIMessages; >+import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper; >+import org.eclipse.wst.sse.ui.internal.util.EditorUtility; >+ >+/** >+ * Custom color picker used in {@link MessageInstanceStylePage}. Provides UI >+ * for changing background and foreground color, selecting custom color or RIM >+ * color, setting font style. >+ * >+ * @author Zsolt Török >+ */ >+public class MessageInstanceStyledTextColorPicker extends Composite { >+ >+ /** >+ * Class constructor specifying the parent and the style of the color picker >+ * to create. >+ * >+ * @param parent >+ * the parent <code>Composite</code> >+ * @param style >+ * the style >+ */ >+ public MessageInstanceStyledTextColorPicker(Composite parent, int style) { >+ super(parent, style); >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 1; >+ setLayout(layout); >+ createControls(this); >+ } >+ >+ protected class DescriptionSorter extends org.eclipse.wst.sse.ui.internal.util.Sorter { >+ Collator collator = Collator.getInstance(); >+ >+ public boolean compare(Object elementOne, Object elementTwo) { >+ /** >+ * Returns true if elementTwo is 'greater than' elementOne This is >+ * the 'ordering' method of the sort operation. Each subclass >+ * overides this method with the particular implementation of the >+ * 'greater than' concept for the objects being sorted. >+ */ >+ return (collator.compare(elementOne.toString(), elementTwo.toString())) < 0; >+ } >+ } >+ >+ protected AccessibleControlListener backgroundAccListener = new AccessibleControlAdapter() { >+ /** >+ * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getValue(AccessibleControlEvent) >+ */ >+ public void getValue(AccessibleControlEvent e) { >+ if (e.childID == ACC.CHILDID_SELF) { >+ e.result = backgroundColorSelector.getColorValue().toString(); >+ } >+ } >+ }; >+ >+ protected SelectionListener buttonListener = new SelectionListener() { >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ widgetSelected(e); >+ } >+ >+ public void widgetSelected(SelectionEvent e) { >+ String namedStyle = getStyleName(styleCombo.getItem(styleCombo.getSelectionIndex())); >+ if (namedStyle == null) >+ return; >+ if (e.widget == fBold) { >+ // get current (newly old) style >+ String prefString = getPreferenceStore().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); >+ getPreferenceStore().setValue(namedStyle, newPrefString); >+ refresh(); >+ } >+ } >+ } else if (e.widget == clearStyleButton) { >+ getPreferenceStore().setToDefault(namedStyle); >+ refresh(); >+ } >+ } >+ }; >+ >+ protected SelectionListener comboBoxListener = new SelectionListener() { >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ widgetSelected(e); >+ } >+ >+ public void widgetSelected(SelectionEvent e) { >+ int selectedIndex = styleCombo.getSelectionIndex(); >+ String description = selectedIndex >= 0 ? styleCombo.getItem(selectedIndex) : null; >+ activate(getStyleName(description)); >+ } >+ }; >+ protected ColorSelector backgroundColorSelector; >+ protected Button fBold; >+ protected Button clearStyleButton; >+ // Dictionary mapping the ITextRegion types above to color names, which >+ // are, in turn, attributes >+ protected Dictionary contextStyleMap = null; >+ protected Color defaultBackgroundColor = getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); >+ >+ protected Color defaultForegroundColor = getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND); >+ // Dictionary mapping the ITextRegion types above to display strings, for >+ // use in the combo box >+ protected Dictionary descriptions = null; >+ protected ColorSelector foregroundColorSelector; >+ >+ protected String input = ""; //$NON-NLS-1$ >+ private IStructuredDocumentRegion nodes = null; >+ protected AccessibleControlListener foregroundAccListener = new AccessibleControlAdapter() { >+ /** >+ * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getValue(AccessibleControlEvent) >+ */ >+ public void getValue(AccessibleControlEvent e) { >+ if (e.childID == ACC.CHILDID_SELF) { >+ e.result = foregroundColorSelector.getColorValue().toString(); >+ } >+ } >+ }; >+ >+ // A RegionParser, which will turn the input into >+ // IStructuredDocumentRegion(s) and Regions >+ protected RegionParser parser = null; >+ >+ private IPreferenceStore preferenceStore; >+ protected Combo styleCombo = null; >+ // The list of supported ITextRegion types [Strings] >+ protected List styleList = null; >+ >+ // controls in picker >+ protected StyledText styledText = null; >+ >+ boolean fgPickerEnabled = true; >+ >+ boolean bgPickerEnabled = true; >+ >+ Button rimFgColorButton; >+ >+ Button rimBgColorButton; >+ >+ private Button chooseFgColorButton; >+ >+ private Button chooseBgColorButton; >+ >+ /** >+ * Activate controls based on the given color type. >+ * >+ * @param namedStyle >+ */ >+ // activate controls based on the given local color type >+ protected void activate(String namedStyle) { >+ if (namedStyle == null) { >+ foregroundColorSelector.setEnabled(false); >+ backgroundColorSelector.setEnabled(false); >+ clearStyleButton.setEnabled(false); >+ fBold.setEnabled(false); >+ } else { >+ foregroundColorSelector.setEnabled(isForegroundPickerEnabled()); >+ backgroundColorSelector.setEnabled(isBackgroundPickerEnabled()); >+ clearStyleButton.setEnabled(true); >+ fBold.setEnabled(true); >+ } >+ TextAttribute attribute = getAttribute(namedStyle); >+ Color color = attribute.getForeground(); >+ if (color == null) { >+ color = defaultForegroundColor; >+ } >+ foregroundColorSelector.setColorValue(color.getRGB()); >+ >+ color = attribute.getBackground(); >+ if (color == null) { >+ color = defaultBackgroundColor; >+ } >+ backgroundColorSelector.setColorValue(color.getRGB()); >+ >+ String namedStyleFg = namedStyle + "ForegroundRIM"; >+ String namedStyleBg = namedStyle + "BackgroundRIM"; >+ >+ boolean fgRIM = getPreferenceStore().getBoolean(namedStyleFg); >+ setForegroundPickerEnabled(!fgRIM); >+ boolean bgRIM = getPreferenceStore().getBoolean(namedStyleBg); >+ setBackgroundPickerEnabled(!bgRIM); >+ >+ fBold.setSelection((attribute.getStyle() & SWT.BOLD) != 0); >+ } >+ >+ protected void applyStyles() { >+ if (styledText == null || styledText.isDisposed() || input == null || input.length() == 0) >+ return; >+ IStructuredDocumentRegion node = nodes; >+ while (node != null) { >+ ITextRegionList regions = node.getRegions(); >+ for (int i = 0; i < regions.size(); i++) { >+ ITextRegion currentRegion = regions.get(i); >+ // lookup the local coloring type and apply it >+ String namedStyle = (String) getContextStyleMap().get(currentRegion.getType()); >+ if (namedStyle == null) >+ continue; >+ TextAttribute attribute = getAttribute(namedStyle); >+ if (attribute == null) >+ continue; >+ StyleRange style = new StyleRange(node.getStartOffset(currentRegion), currentRegion.getLength(), attribute >+ .getForeground(), attribute.getBackground(), attribute.getStyle()); >+ styledText.setStyleRange(style); >+ } >+ node = node.getNext(); >+ } >+ } >+ >+ protected void close() { >+ } >+ >+ /** >+ * Creates a 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 >+ */ >+ private Button createCheckBox(Composite group, String label) { >+ Button button = new Button(group, SWT.CHECK | SWT.CENTER); >+ if (label != null) >+ button.setText(label); >+ GridData data = new GridData(GridData.FILL_BOTH); >+ data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END; >+ button.setLayoutData(data); >+ return button; >+ } >+ >+ /** >+ * Creates a combo box instance and sets the default layout data. >+ * >+ * @param parent >+ * @param labels >+ * @param selectedItem >+ * @return >+ */ >+ private Combo createCombo(Composite parent, String[] labels, int selectedItem) { >+ Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY); >+ combo.setItems(labels); >+ if (selectedItem >= 0) >+ combo.select(selectedItem); >+ GridData data = new GridData(GridData.FILL_HORIZONTAL); >+ data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_FILL; >+ combo.setLayoutData(data); >+ return combo; >+ } >+ >+ /** >+ * Creates composite control and sets the default layout data. >+ */ >+ private Composite createComposite(Composite parent, int numColumns) { >+ Composite composite = new Composite(parent, SWT.NULL); >+ // GridLayout >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = numColumns; >+ layout.horizontalSpacing = 5; >+ layout.makeColumnsEqualWidth = false; >+ composite.setLayout(layout); >+ // GridData >+ GridData data = new GridData(GridData.FILL_VERTICAL & GridData.FILL_HORIZONTAL); >+ data.grabExcessVerticalSpace = false; >+ data.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; >+ composite.setLayoutData(data); >+ return composite; >+ } >+ >+ /** >+ * Creates the controls in the color picker. >+ * >+ * @param parent >+ */ >+ protected void createControls(Composite parent) { >+ Composite row1 = createComposite(parent, 3); >+ // row 1 - content type label, combo box, restore defaults >+ createLabel(row1, SSEUIMessages.Content_type__UI_); //$NON-NLS-1$ = "Content type:" >+ // Contexts combo box >+ styleCombo = createCombo(row1, new String[0], -1); >+ clearStyleButton = createPushButton(row1, SSEUIMessages.Restore_Default_UI_); //$NON-NLS-1$ = "Restore Default" >+ >+ Composite row2 = createComposite(parent, 3); >+ Group foregroundGroup = createGroup(row2, SWT.SHADOW_IN, 1); >+ foregroundGroup.setText(SSEUIMessages.Foreground_UI_); //$NON-NLS-1$ = "Foreground" >+ Group backgroundGroup = createGroup(row2, SWT.SHADOW_IN, 1); >+ backgroundGroup.setText(SSEUIMessages.Background_UI_); //$NON-NLS-1$ = "Background" >+ Group fontGroup = createGroup(row2, SWT.SHADOW_IN, 1); >+ fontGroup.setText("Font:"); >+ >+ rimFgColorButton = new Button(foregroundGroup, SWT.RADIO); >+ rimFgColorButton.setText("RIM color"); >+ chooseFgColorButton = new Button(foregroundGroup, SWT.RADIO); >+ chooseFgColorButton.setText("Choose color"); >+ >+ foregroundColorSelector = new ColorSelector(foregroundGroup); >+ foregroundColorSelector.getButton().setLayoutData(new GridData()); >+ setAccessible(foregroundColorSelector.getButton(), foregroundGroup.getText()); >+ foregroundColorSelector.getButton().getAccessible().addAccessibleControlListener(foregroundAccListener); >+ ((GridData) foregroundColorSelector.getButton().getLayoutData()).minimumWidth = 20; >+ >+ rimBgColorButton = new Button(backgroundGroup, SWT.RADIO); >+ rimBgColorButton.setText("RIM color"); >+ chooseBgColorButton = new Button(backgroundGroup, SWT.RADIO); >+ chooseBgColorButton.setText("Choose color"); >+ >+ backgroundColorSelector = new ColorSelector(backgroundGroup); >+ backgroundColorSelector.getButton().setLayoutData(new GridData()); >+ setAccessible(backgroundColorSelector.getButton(), foregroundGroup.getText()); >+ backgroundColorSelector.getButton().getAccessible().addAccessibleControlListener(backgroundAccListener); // defect >+ ((GridData) backgroundColorSelector.getButton().getLayoutData()).minimumWidth = 20; >+ >+ foregroundColorSelector.setEnabled(false); >+ backgroundColorSelector.setEnabled(false); >+ clearStyleButton.setEnabled(false); >+ >+ fBold = createCheckBox(fontGroup, SSEUIMessages.Bold_UI_); >+ fBold.setEnabled(false); >+ >+ Composite sample = createComposite(parent, 1); >+ createLabel(sample, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:" >+ styledText = new StyledText(sample, SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER >+ | SWT.READ_ONLY); >+ GridData data = new GridData(GridData.FILL_BOTH); >+ styledText.setLayoutData(data); >+ styledText.setEditable(false); >+ styledText.setBackground(defaultBackgroundColor); >+ styledText.setFont(JFaceResources.getTextFont()); >+ styledText.addKeyListener(getTextKeyListener()); >+ styledText.addSelectionListener(getTextSelectionListener()); >+ styledText.addMouseListener(getTextMouseListener()); >+ styledText.addTraverseListener(getTraverseListener()); >+ setAccessible(styledText, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:" >+ >+ foregroundColorSelector.addListener(new IPropertyChangeListener() { >+ public void propertyChange(PropertyChangeEvent event) { >+ if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) { >+ // get current (newly old) style >+ String namedStyle = getStyleName(styleCombo.getItem(styleCombo.getSelectionIndex())); >+ String prefString = getPreferenceStore().getString(namedStyle); >+ String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); >+ if (stylePrefs != null) { >+ String oldValue = stylePrefs[0]; >+ String newValue = "null"; //$NON-NLS-1$ >+ Object newValueObject = event.getNewValue(); >+ if (newValueObject instanceof RGB) { >+ newValue = ColorHelper.toRGBString((RGB) newValueObject); >+ } >+ >+ if (!newValue.equals(oldValue)) { >+ stylePrefs[0] = newValue; >+ String newPrefString = ColorHelper.packStylePreferences(stylePrefs); >+ getPreferenceStore().setValue(namedStyle, newPrefString); >+ refresh(); >+ } >+ } >+ } >+ } >+ }); >+ backgroundColorSelector.addListener(new IPropertyChangeListener() { >+ public void propertyChange(PropertyChangeEvent event) { >+ if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) { >+ // get current (newly old) style >+ String namedStyle = getStyleName(styleCombo.getItem(styleCombo.getSelectionIndex())); >+ String prefString = getPreferenceStore().getString(namedStyle); >+ String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); >+ if (stylePrefs != null) { >+ String oldValue = stylePrefs[1]; >+ >+ String newValue = "null"; //$NON-NLS-1$ >+ Object newValueObject = event.getNewValue(); >+ if (newValueObject instanceof RGB) { >+ newValue = ColorHelper.toRGBString((RGB) newValueObject); >+ } >+ >+ if (!newValue.equals(oldValue)) { >+ stylePrefs[1] = newValue; >+ String newPrefString = ColorHelper.packStylePreferences(stylePrefs); >+ getPreferenceStore().setValue(namedStyle, newPrefString); >+ refresh(); >+ } >+ } >+ } >+ } >+ }); >+ >+ rimFgColorButton.addSelectionListener(getSelectionListener()); >+ rimBgColorButton.addSelectionListener(getSelectionListener()); >+ clearStyleButton.addSelectionListener(getSelectionListener()); >+ styleCombo.addSelectionListener(comboBoxListener); >+ fBold.addSelectionListener(buttonListener); >+ } >+ >+ /** >+ * Utility method that creates a label instance and sets the default layout >+ * data. >+ */ >+ private Label createLabel(Composite parent, String text) { >+ Label label = new Label(parent, SWT.LEFT); >+ label.setText(text); >+ GridData data = new GridData(); >+ data.horizontalAlignment = GridData.FILL; >+ label.setLayoutData(data); >+ return label; >+ } >+ >+ private Group createGroup(Composite parent, int style, int numColumns) { >+ Group group = new Group(parent, style); >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = numColumns; >+ layout.horizontalSpacing = 5; >+ layout.makeColumnsEqualWidth = false; >+ group.setLayout(layout); >+ GridData data = new GridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL); >+ data.grabExcessVerticalSpace = false; >+ data.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; >+ group.setLayoutData(data); >+ return group; >+ } >+ >+ private Button createPushButton(Composite parent, String label) { >+ Button button = new Button(parent, SWT.PUSH); >+ button.setText(label); >+ GridData data = new GridData(GridData.FILL_BOTH); >+ button.setLayoutData(data); >+ return button; >+ } >+ >+ protected TextAttribute getAttribute(String namedStyle) { >+ TextAttribute ta = new TextAttribute(getDefaultForeground(), getDefaultBackground(), SWT.NORMAL); >+ >+ if (namedStyle != null && getPreferenceStore() != null) { >+ String prefString = getPreferenceStore().getString(namedStyle); >+ String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); >+ if (stylePrefs != null) { >+ RGB foreground = ColorHelper.toRGB(stylePrefs[0]); >+ RGB background = ColorHelper.toRGB(stylePrefs[1]); >+ >+ int fontModifier = SWT.NORMAL; >+ boolean bold = Boolean.valueOf(stylePrefs[2]).booleanValue(); >+ if (bold) >+ fontModifier = fontModifier | SWT.BOLD; >+ >+ ta = new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, >+ (background != null) ? EditorUtility.getColor(background) : null, fontModifier); >+ } >+ } >+ return ta; >+ } >+ >+ /** >+ * @return java.util.Dictionary >+ */ >+ public Dictionary getContextStyleMap() { >+ return contextStyleMap; >+ } >+ >+ /** >+ * @return org.eclipse.swt.graphics.Color >+ */ >+ public Color getDefaultBackground() { >+ return defaultBackgroundColor; >+ } >+ >+ /** >+ * @return org.eclipse.swt.graphics.Color >+ */ >+ public Color getDefaultForeground() { >+ return defaultForegroundColor; >+ } >+ >+ /** >+ * @return java.util.Dictionary >+ */ >+ public Dictionary getDescriptions() { >+ return descriptions; >+ } >+ >+ public Font getFont() { >+ return styledText.getFont(); >+ } >+ >+ protected String getNamedStyleAtOffset(int offset) { >+ // ensure the offset is clean >+ if (offset >= input.length()) >+ return getNamedStyleAtOffset(input.length() - 1); >+ else if (offset < 0) >+ return getNamedStyleAtOffset(0); >+ // find the ITextRegion at this offset >+ if (nodes == null) >+ return null; >+ IStructuredDocumentRegion aNode = nodes; >+ while (aNode != null && !aNode.containsOffset(offset)) >+ aNode = aNode.getNext(); >+ if (aNode != null) { >+ // find the ITextRegion's Context at this offset >+ ITextRegion interest = aNode.getRegionAtCharacterOffset(offset); >+ if (interest == null) >+ return null; >+ if (offset > aNode.getTextEndOffset(interest)) >+ return null; >+ String regionContext = interest.getType(); >+ if (regionContext == null) >+ return null; >+ // find the named style (internal/selectable name) for that >+ // context >+ String namedStyle = (String) getContextStyleMap().get(regionContext); >+ if (namedStyle != null) { >+ return namedStyle; >+ } >+ } >+ return null; >+ } >+ >+ public RegionParser getParser() { >+ return parser; >+ } >+ >+ private IPreferenceStore getPreferenceStore() { >+ return preferenceStore; >+ } >+ >+ /** >+ * @return String[] >+ */ >+ public List getStyleList() { >+ return styleList; >+ } >+ >+ private String getStyleName(String description) { >+ if (description == null) >+ return null; >+ String styleName = null; >+ java.util.Enumeration keys = getDescriptions().keys(); >+ while (keys.hasMoreElements()) { >+ String test = keys.nextElement().toString(); >+ if (getDescriptions().get(test).equals(description)) { >+ styleName = test; >+ break; >+ } >+ } >+ return styleName; >+ } >+ >+ public String getText() { >+ return input; >+ } >+ >+ private SelectionListener getSelectionListener() { >+ return new SelectionListener() { >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ widgetSelected(e); >+ } >+ >+ public void widgetSelected(SelectionEvent e) { >+ String namedStyle = getStyleName(styleCombo.getItem(styleCombo.getSelectionIndex())); >+ if (namedStyle == null) >+ return; >+ if (e.widget == fBold) { >+ // get current (newly old) style >+ String prefString = getPreferenceStore().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); >+ getPreferenceStore().setValue(namedStyle, newPrefString); >+ refresh(); >+ } >+ } >+ } else if (e.widget == clearStyleButton) { >+ getPreferenceStore().setToDefault(namedStyle); >+ refresh(); >+ >+ } else if (e.widget == rimFgColorButton) { >+ Button button = (Button) e.widget; >+ String namedStyleFg = namedStyle + "ForegroundRIM"; >+ if (button.getSelection()) { >+ setForegroundPickerEnabled(false); >+ getPreferenceStore().setValue(namedStyleFg, true); >+ } else { >+ setForegroundPickerEnabled(true); >+ getPreferenceStore().setValue(namedStyleFg, false); >+ } >+ } else if (e.widget == rimBgColorButton) { >+ Button button = (Button) e.widget; >+ String namedStyleBg = namedStyle + "BackgroundRIM"; >+ if (button.getSelection()) { >+ setBackgroundPickerEnabled(false); >+ getPreferenceStore().setValue(namedStyleBg, true); >+ } else { >+ setBackgroundPickerEnabled(true); >+ getPreferenceStore().setValue(namedStyleBg, false); >+ } >+ } >+ } >+ }; >+ } >+ >+ private KeyListener getTextKeyListener() { >+ return new KeyListener() { >+ public void keyPressed(KeyEvent e) { >+ if (e.widget instanceof StyledText) { >+ int x = ((StyledText) e.widget).getCaretOffset(); >+ selectColorAtOffset(x); >+ } >+ } >+ >+ public void keyReleased(KeyEvent e) { >+ if (e.widget instanceof StyledText) { >+ int x = ((StyledText) e.widget).getCaretOffset(); >+ selectColorAtOffset(x); >+ } >+ } >+ }; >+ } >+ >+ private MouseListener getTextMouseListener() { >+ return new MouseListener() { >+ public void mouseDoubleClick(MouseEvent e) { >+ } >+ >+ public void mouseDown(MouseEvent e) { >+ } >+ >+ public void mouseUp(MouseEvent e) { >+ if (e.widget instanceof StyledText) { >+ int x = ((StyledText) e.widget).getCaretOffset(); >+ selectColorAtOffset(x); >+ } >+ } >+ }; >+ } >+ >+ private SelectionListener getTextSelectionListener() { >+ return new SelectionListener() { >+ public void widgetDefaultSelected(SelectionEvent e) { >+ selectColorAtOffset(e.x); >+ if (e.widget instanceof StyledText) { >+ ((StyledText) e.widget).setSelection(e.x); >+ } >+ } >+ >+ public void widgetSelected(SelectionEvent e) { >+ selectColorAtOffset(e.x); >+ if (e.widget instanceof StyledText) { >+ ((StyledText) e.widget).setSelection(e.x); >+ } >+ } >+ }; >+ } >+ >+ private TraverseListener getTraverseListener() { >+ return new TraverseListener() { >+ /** >+ * @see org.eclipse.swt.events.TraverseListener#keyTraversed(TraverseEvent) >+ */ >+ public void keyTraversed(TraverseEvent e) { >+ if (e.widget instanceof StyledText) { >+ if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) >+ e.doit = true; >+ } >+ } >+ }; >+ } >+ >+ /** >+ * Refreshes the GUI after a color change. >+ */ >+ public void refresh() { >+ styledText.setRedraw(false); >+ int selectedIndex = styleCombo.getSelectionIndex(); >+ String description = selectedIndex >= 0 ? styleCombo.getItem(selectedIndex) : null; >+ activate(getStyleName(description)); >+ // update Font >+ styledText.setFont(JFaceResources.getTextFont()); >+ // reapplyStyles >+ applyStyles(); >+ styledText.setRedraw(true); >+ } >+ >+ private void selectColorAtOffset(int offset) { >+ String namedStyle = getNamedStyleAtOffset(offset); >+ if (namedStyle == null) { >+ styleCombo.deselectAll(); >+ activate(null); >+ return; >+ } >+ String description = (String) getDescriptions().get(namedStyle); >+ if (description == null) >+ return; >+ int itemCount = styleCombo.getItemCount(); >+ for (int i = 0; i < itemCount; i++) { >+ if (styleCombo.getItem(i).equals(description)) { >+ styleCombo.select(i); >+ break; >+ } >+ } >+ activate(namedStyle); >+ } >+ >+ /** >+ * Specifically set the reporting name of a control for accessibility >+ */ >+ private void setAccessible(Control control, String name) { >+ if (control == null) >+ return; >+ final String n = name; >+ control.getAccessible().addAccessibleListener(new AccessibleAdapter() { >+ public void getName(AccessibleEvent e) { >+ if (e.childID == ACC.CHILDID_SELF) >+ e.result = n; >+ } >+ }); >+ } >+ >+ /** >+ * @param newContextStyleMap >+ * java.util.Dictionary >+ */ >+ public void setContextStyleMap(Dictionary newContextStyleMap) { >+ contextStyleMap = newContextStyleMap; >+ } >+ >+ /** >+ * @param newDefaultBackground >+ * org.eclipse.swt.graphics.Color >+ */ >+ public void setDefaultBackground(Color newDefaultBackground) { >+ defaultBackgroundColor = newDefaultBackground; >+ } >+ >+ /** >+ * @param newDefaultForeground >+ * org.eclipse.swt.graphics.Color >+ */ >+ public void setDefaultForeground(Color newDefaultForeground) { >+ defaultForegroundColor = newDefaultForeground; >+ } >+ >+ /** >+ * @param newDescriptions >+ * java.util.Dictionary >+ */ >+ public void setDescriptions(Dictionary newDescriptions) { >+ descriptions = newDescriptions; >+ updateStyleList(); >+ } >+ >+ public void setFont(Font font) { >+ styledText.setFont(font); >+ styledText.redraw(); >+ } >+ >+ /** >+ * @param newParser >+ */ >+ public void setParser(RegionParser newParser) { >+ parser = newParser; >+ } >+ >+ public void setPreferenceStore(IPreferenceStore store) { >+ preferenceStore = store; >+ } >+ >+ /** >+ * @param newStyleList >+ * String[] >+ */ >+ public void setStyleList(List newStyleList) { >+ styleList = newStyleList; >+ updateStyleList(); >+ } >+ >+ /** >+ * Sets the sample text. >+ * >+ * @param s >+ * the sample text >+ */ >+ public void setText(String s) { >+ input = s; >+ getParser().reset(new CharArrayReader(input.toCharArray())); >+ nodes = getParser().getDocumentRegions(); >+ if (Debug.displayInfo) >+ System.out.println("Length of input: " //$NON-NLS-1$ >+ //$NON-NLS-1$ >+ + s.length() + ", " //$NON-NLS-1$ >+ + getParser().getRegions().size() + " regions."); //$NON-NLS-1$ >+ if (styledText != null) >+ styledText.setText(s); >+ applyStyles(); >+ } >+ >+ private void updateStyleList() { >+ if (styleList == null || descriptions == null) >+ return; >+ String[] descriptions = new String[styleList.size()]; >+ for (int i = 0; i < styleList.size(); i++) { >+ if (styleList.get(i) != null) >+ descriptions[i] = (String) getDescriptions().get(styleList.get(i)); >+ else >+ descriptions[i] = (String) styleList.get(i); >+ } >+ Object[] sortedObjects = new DescriptionSorter().sort(descriptions); >+ String[] sortedDescriptions = new String[descriptions.length]; >+ for (int i = 0; i < descriptions.length; i++) { >+ sortedDescriptions[i] = sortedObjects[i].toString(); >+ } >+ styleCombo.setItems(sortedDescriptions); >+ styleCombo.select(0); >+ } >+ >+ /** >+ * Returns the enabled state of the background color picker. >+ * >+ * @return the enabled state of the picker >+ */ >+ public boolean isBackgroundPickerEnabled() { >+ return bgPickerEnabled; >+ } >+ >+ /** >+ * Sets the enabled state of the background color picker. >+ * >+ * @param pickerEnabled >+ * the new enabled state of the background color picker >+ */ >+ public void setBackgroundPickerEnabled(boolean pickerEnabled) { >+ this.bgPickerEnabled = pickerEnabled; >+ rimBgColorButton.setSelection(!pickerEnabled); >+ chooseBgColorButton.setSelection(pickerEnabled); >+ backgroundColorSelector.setEnabled(pickerEnabled); >+ } >+ >+ /** >+ * Returns the enabled state of the foreground color picker. >+ * >+ * @return the enabled state of the foreground color picker >+ */ >+ public boolean isForegroundPickerEnabled() { >+ return fgPickerEnabled; >+ } >+ >+ /** >+ * Sets the enabled state of the foreground color picker. >+ * >+ * @param pickerEnabled >+ * the new enabled state of the background color picker >+ */ >+ public void setForegroundPickerEnabled(boolean pickerEnabled) { >+ this.fgPickerEnabled = pickerEnabled; >+ rimFgColorButton.setSelection(!pickerEnabled); >+ chooseFgColorButton.setSelection(pickerEnabled); >+ foregroundColorSelector.setEnabled(pickerEnabled); >+ >+ } >+ >+} >Index: src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStylePage.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.ohf/plugins/org.eclipse.ohf.h3et.instanceeditor.ui/src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStylePage.java,v >retrieving revision 1.1 >diff -u -r1.1 MessageInstanceStylePage.java >--- src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStylePage.java 22 Jan 2007 14:07:07 -0000 1.1 >+++ src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStylePage.java 24 Jan 2007 12:48:11 -0000 >@@ -8,11 +8,8 @@ > * Contributors: > * Jiva Medical - initial API and implementation > *******************************************************************************/ >-/** >- * >- */ >-package org.eclipse.ohf.h3et.instanceeditor.ui.preferences; >- >+package org.eclipse.ohf.h3et.instanceeditor.ui.preferences; >+ > import java.util.ArrayList; > import java.util.Dictionary; > import java.util.Hashtable; >@@ -30,14 +27,16 @@ > import org.eclipse.wst.xml.ui.internal.preferences.XMLColorPage; > import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; > >- > /** >- * @author zsolt >- * >+ * Preference page for message instance source coloring. >+ * >+ * @author Zsolt Török > */ > public class MessageInstanceStylePage extends XMLColorPage { >- >- /* (non-Javadoc) >+ >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.wst.xml.ui.internal.preferences.XMLColorPage#getSampleText() > */ > @Override >@@ -45,35 +44,30 @@ > return "<?xml version=\"1.0\"?>\n<?customProcessingInstruction\n\tXML processor specific\n\tcontent ?>\n<colors>\n\t<!-- begin color definitions -->\n\t<color name=\"plaintext\" foreground=\"#000000\"\n\t\tbackground=\"#D4D0C8\"/>\n\t<color name=\"bold\" foreground=\"#000000\"\n\t\tbackground=\"#B3ACA0\">\n\t<![CDATA[<123456789>]]>\n\tNormal text content.\n\t<color name=\"inverse\" foreground=\"#F0F0F0\"\n\t\tbackground=\"#D4D0C8\"/>\n\n</colors>\n"; > } > >- protected MessageInstanceStyledTextColorPicker fPicker = null; >+ protected MessageInstanceStyledTextColorPicker customPicker = null; > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractColorPage#createContentsForPicker(org.eclipse.swt.widgets.Composite) > */ > @Override > protected void createContentsForPicker(Composite parent) { > // create the color picker >- fPicker = new MessageInstanceStyledTextColorPicker(parent, SWT.NULL); >+ customPicker = new MessageInstanceStyledTextColorPicker(parent, SWT.NULL); > GridData data = new GridData(GridData.FILL_BOTH); >- fPicker.setLayoutData(data); >+ customPicker.setLayoutData(data); > >- fPicker.setPreferenceStore(fOverlayStore); >- setupPicker(fPicker); >+ customPicker.setPreferenceStore(fOverlayStore); >+ setupPicker(customPicker); > >- fPicker.setText(getSampleText()); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractColorPage#getPicker() >- */ >- @Override >- public MessageInstanceStyledTextColorPicker getPicker() { >- return fPicker; >+ customPicker.setText(getSampleText()); > } > > protected void setupPicker(MessageInstanceStyledTextColorPicker picker) { > IModelManager mmanager = StructuredModelManager.getModelManager(); >- picker.setParser(mmanager.createStructuredDocumentFor("org.ohf.h3et.instanceeditor.ui.contenttype.messageinstance").getParser()); >+ picker.setParser(mmanager.createStructuredDocumentFor("org.ohf.h3et.instanceeditor.ui.contenttype.messageinstance") >+ .getParser()); > > // create descriptions for hilighting types > Dictionary descriptions = new Hashtable(); >@@ -89,59 +83,114 @@ > picker.setContextStyleMap(contextStyleMap); > picker.setDescriptions(descriptions); > picker.setStyleList(styleList); >- >- boolean useRIMFg = getPreferenceStore().getBoolean(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_FOREGROUND); >- picker.setForegroundPickerEnabled(!useRIMFg); > >- boolean useRIMBg = getPreferenceStore().getBoolean(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_BACKGROUND); >- picker.setBackgroundPickerEnabled(!useRIMBg); >+ // boolean useRIMFg = >+ // getPreferenceStore().getBoolean(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_FOREGROUND); >+ // picker.setForegroundPickerEnabled(!useRIMFg); >+ // >+ // boolean useRIMBg = >+ // getPreferenceStore().getBoolean(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_BACKGROUND); >+ // picker.setBackgroundPickerEnabled(!useRIMBg); > >- >- // updatePickerFont(picker); >+ // updatePickerFont(picker); > } >- >+ > /** > * Set up all the style preference keys in the overlay store > */ > protected OverlayKey[] createOverlayStoreKeys() { >- ArrayList overlayKeys = new ArrayList(); >- >+ ArrayList<OverlayKey> overlayKeys = new ArrayList<OverlayKey>(); >+ > ArrayList styleList = new ArrayList(); > initStyleList(styleList); > Iterator i = styleList.iterator(); > while (i.hasNext()) { >- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, (String)i.next())); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, (String) i.next())); > } >- >- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_BACKGROUND)); >- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_FOREGROUND)); >+ >+ // RIM-based source coloring preferences >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.CDATA_BORDER_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.CDATA_TEXT_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.COMMENT_BORDER_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.COMMENT_TEXT_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.DECL_BORDER_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.CDATA_BORDER_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.CDATA_TEXT_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.COMMENT_BORDER_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.COMMENT_TEXT_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.DECL_BORDER_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.PI_BORDER_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.PI_CONTENT_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.TAG_ATTRIBUTE_EQUALS_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.TAG_ATTRIBUTE_NAME_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.TAG_ATTRIBUTE_VALUE_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.TAG_BORDER_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.TAG_NAME_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.XML_CONTENT_BACKGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.PI_BORDER_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.PI_CONTENT_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.TAG_ATTRIBUTE_EQUALS_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.TAG_ATTRIBUTE_NAME_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.TAG_ATTRIBUTE_VALUE_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.TAG_BORDER_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.TAG_NAME_FOREGROUND_RIM)); >+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, >+ MessageInstanceStyleConstants.XML_CONTENT_FOREGROUND_RIM)); > > OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; > overlayKeys.toArray(keys); > return keys; > } >- >+ > @Override > protected IPreferenceStore doGetPreferenceStore() { >- // TODO Auto-generated method stub > return Activator.getDefault().getPreferenceStore(); > } > > @Override > protected void savePreferences() { >- // TODO Auto-generated method stub > Activator.getDefault().savePluginPreferences(); > } > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractColorPage#performDefaults() > */ > @Override > protected void performDefaults() { > fOverlayStore.loadDefaults(); >- fPicker.refresh(); } >+ customPicker.refresh(); >+ } > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.wst.xml.ui.internal.preferences.XMLColorPage#initStyleList(java.util.ArrayList) > */ > @Override >@@ -152,4 +201,51 @@ > list.add(IStyleConstantsXML.PI_BORDER); > list.add(IStyleConstantsXML.PI_CONTENT); > } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractColorPage#setVisible(boolean) >+ */ >+ @Override >+ public void setVisible(boolean visible) { >+ boolean doShrink = false; >+ // limiter, for the really huge fonts >+ if (visible) { >+ getCustomPicker().refresh(); >+ int x = Math.min(getControl().getShell().getSize().x, getControl().getDisplay().getClientArea().width * 9 / 10); >+ int y = Math.min(getControl().getShell().getSize().y, getControl().getDisplay().getClientArea().height * 9 / 10); >+ boolean shrinkWidth = (x != getControl().getShell().getSize().x); >+ boolean shrinkHeight = (y != getControl().getShell().getSize().y); >+ doShrink = shrinkWidth || shrinkHeight; >+ if (doShrink) { >+ if (shrinkHeight && !shrinkWidth) >+ getShell().setBounds(getShell().getLocation().x, 0, getShell().getSize().x, >+ getControl().getDisplay().getClientArea().height); >+ else if (!shrinkHeight && shrinkWidth) >+ getShell().setBounds(0, getShell().getLocation().y, getControl().getDisplay().getClientArea().width, >+ getShell().getSize().y); >+ else >+ getShell().setBounds(0, 0, getControl().getDisplay().getClientArea().width, >+ getControl().getDisplay().getClientArea().height); >+ } >+ } >+ if (doShrink) { >+ getControl().getShell().redraw(); >+ getControl().getShell().update(); >+ } >+ >+ getControl().setVisible(visible); >+ } >+ >+ /** >+ * Returns the custom color picker implementation use in this preference >+ * page. >+ * >+ * @return the customized {@link MessageInstanceStyledTextColorPicker} >+ */ >+ public MessageInstanceStyledTextColorPicker getCustomPicker() { >+ return customPicker; >+ } >+ > } >Index: src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyleConstants.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.ohf/plugins/org.eclipse.ohf.h3et.instanceeditor.ui/src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyleConstants.java,v >retrieving revision 1.1 >diff -u -r1.1 MessageInstanceStyleConstants.java >--- src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyleConstants.java 22 Jan 2007 14:07:08 -0000 1.1 >+++ src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyleConstants.java 24 Jan 2007 12:48:11 -0000 >@@ -1,20 +1,52 @@ >-/******************************************************************************* >- * Crown Copyright (c) 2006, 2007, Copyright (c) 2006, 2007 Jiva Medical. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Jiva Medical - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.ohf.h3et.instanceeditor.ui.preferences; >- >-/** >- * @author zsolt >- * >- */ >-public class MessageInstanceStyleConstants { >- public static final String USE_RIM_COLOR_FOR_FOREGROUND = "USE_RIM_COLOR_FOR_FOREGROUND"; >- public static final String USE_RIM_COLOR_FOR_BACKGROUND = "USE_RIM_COLOR_FOR_BACKGROUND"; >-} >+/******************************************************************************* >+ * Crown Copyright (c) 2006, 2007, Copyright (c) 2006, 2007 Jiva Medical. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Jiva Medical - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ohf.h3et.instanceeditor.ui.preferences; >+ >+/** >+ * Preference constants used by the Message Instance Editor for coloring the >+ * source view. Either custom color or RIM color can be chosen for every kind of >+ * XML region. For example: if TAG_ATTRIBUTE_NAME_FOREGROUND_RIM = >+ * <code>false</code> a custom foreground color can be specified in the >+ * preferences for the attribute names. >+ * >+ * @author Zsolt Török >+ */ >+public class MessageInstanceStyleConstants { >+ public static final String CDATA_BORDER_BACKGROUND_RIM = "cdataBorderBackgroundRIM";//$NON-NLS-1$ >+ public static final String CDATA_TEXT_BACKGROUND_RIM = "cdataTextBackgroundRIM";//$NON-NLS-1$ >+ public static final String COMMENT_BORDER_BACKGROUND_RIM = "commentBorderBackgroundRIM";//$NON-NLS-1$ >+ public static final String COMMENT_TEXT_BACKGROUND_RIM = "commentTextBackgroundRIM";//$NON-NLS-1$ >+ public static final String DECL_BORDER_BACKGROUND_RIM = "declBoderBackgroundRIM";//$NON-NLS-1$ >+ >+ public static final String CDATA_BORDER_FOREGROUND_RIM = "cdataBorderForegroundRIM";//$NON-NLS-1$ >+ public static final String CDATA_TEXT_FOREGROUND_RIM = "cdataTextForegroundRIM";//$NON-NLS-1$ >+ public static final String COMMENT_BORDER_FOREGROUND_RIM = "commentBorderForegroundRIM";//$NON-NLS-1$ >+ public static final String COMMENT_TEXT_FOREGROUND_RIM = "commentTextForegroundRIM";//$NON-NLS-1$ >+ public static final String DECL_BORDER_FOREGROUND_RIM = "declBoderForegroundRIM";//$NON-NLS-1$ >+ >+ public static final String PI_BORDER_BACKGROUND_RIM = "piBorderBackgroundRIM";//$NON-NLS-1$ >+ public static final String PI_CONTENT_BACKGROUND_RIM = "piContentBackgroundRIM";//$NON-NLS-1$ >+ public static final String TAG_ATTRIBUTE_EQUALS_BACKGROUND_RIM = "tagAttributeEqualsBackgroundRIM"; //$NON-NLS-1$ >+ public static final String TAG_ATTRIBUTE_NAME_BACKGROUND_RIM = "tagAttributeNameBackgroundRIM";//$NON-NLS-1$ >+ public static final String TAG_ATTRIBUTE_VALUE_BACKGROUND_RIM = "tagAttributeValueBackgroundRIM";//$NON-NLS-1$ >+ public static final String TAG_BORDER_BACKGROUND_RIM = "tagBorderBackgroundRIM";//$NON-NLS-1$ >+ public static final String TAG_NAME_BACKGROUND_RIM = "tagNameBackgroundRIM";//$NON-NLS-1$ >+ public static final String XML_CONTENT_BACKGROUND_RIM = "xmlContentBackgroundRIM";//$NON-NLS-1$ >+ >+ public static final String PI_BORDER_FOREGROUND_RIM = "piBorderForegroundRIM";//$NON-NLS-1$ >+ public static final String PI_CONTENT_FOREGROUND_RIM = "piContentForegroundRIM";//$NON-NLS-1$ >+ public static final String TAG_ATTRIBUTE_EQUALS_FOREGROUND_RIM = "tagAttributeEqualsForegroundRIM"; //$NON-NLS-1$ >+ public static final String TAG_ATTRIBUTE_NAME_FOREGROUND_RIM = "tagAttributeNameForegroundRIM";//$NON-NLS-1$ >+ public static final String TAG_ATTRIBUTE_VALUE_FOREGROUND_RIM = "tagAttributeValueForegroundRIM";//$NON-NLS-1$ >+ public static final String TAG_BORDER_FOREGROUND_RIM = "tagBorderForegroundRIM";//$NON-NLS-1$ >+ public static final String TAG_NAME_FOREGROUND_RIM = "tagNameForegroundRIM";//$NON-NLS-1$ >+ public static final String XML_CONTENT_FOREGROUND_RIM = "xmlContentForegroundRIM";//$NON-NLS-1$ >+} >Index: src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyleInitializer.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.ohf/plugins/org.eclipse.ohf.h3et.instanceeditor.ui/src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyleInitializer.java,v >retrieving revision 1.1 >diff -u -r1.1 MessageInstanceStyleInitializer.java >--- src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyleInitializer.java 22 Jan 2007 14:07:07 -0000 1.1 >+++ src/org/eclipse/ohf/h3et/instanceeditor/ui/preferences/MessageInstanceStyleInitializer.java 24 Jan 2007 12:48:11 -0000 >@@ -16,74 +16,99 @@ > import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper; > import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; > >- > /** >- * @author zsolt >- * >+ * Sets the default values for Message Instance Editor Style preferences. >+ * >+ * @author Zsolt Török > */ >-public class MessageInstanceStyleInitializer extends >- AbstractPreferenceInitializer { >+public class MessageInstanceStyleInitializer extends AbstractPreferenceInitializer { > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() > */ > @Override > public void initializeDefaultPreferences() { > IPreferenceStore store = Activator.getDefault().getPreferenceStore(); >- >- // HTML Style Preferences >- String NOBACKGROUNDBOLD = " | null | false"; //$NON-NLS-1$ >+ >+ String NOBACKGROUNDBOLD = " | null | false"; //$NON-NLS-1$ > String styleValue = ColorHelper.getColorString(127, 0, 127) + NOBACKGROUNDBOLD; > store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, styleValue); >- >- styleValue = ColorHelper.getColorString(42, 0, 255) + NOBACKGROUNDBOLD; >+ >+ styleValue = ColorHelper.getColorString(42, 0, 255) + NOBACKGROUNDBOLD; > store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, styleValue); >- >- styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ >- store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS, styleValue); // specified value is black; leaving as widget default >- >- styleValue = ColorHelper.getColorString(63, 95, 191) + NOBACKGROUNDBOLD; >+ >+ styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ >+ store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS, styleValue); >+ >+ styleValue = ColorHelper.getColorString(63, 95, 191) + NOBACKGROUNDBOLD; > store.setDefault(IStyleConstantsXML.COMMENT_BORDER, styleValue); > store.setDefault(IStyleConstantsXML.COMMENT_TEXT, styleValue); >- >- styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; >+ >+ styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; > store.setDefault(IStyleConstantsXML.DECL_BORDER, styleValue); > >- styleValue = ColorHelper.getColorString(0, 0, 128) + NOBACKGROUNDBOLD; >+ styleValue = ColorHelper.getColorString(0, 0, 128) + NOBACKGROUNDBOLD; > store.setDefault(IStyleConstantsXML.DOCTYPE_NAME, styleValue); > store.setDefault(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF, styleValue); >- >- styleValue = ColorHelper.getColorString(128, 128, 128) + NOBACKGROUNDBOLD; >+ >+ styleValue = ColorHelper.getColorString(128, 128, 128) + NOBACKGROUNDBOLD; > store.setDefault(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID, styleValue); > >- styleValue = ColorHelper.getColorString(63, 127, 95) + NOBACKGROUNDBOLD; >+ styleValue = ColorHelper.getColorString(63, 127, 95) + NOBACKGROUNDBOLD; > store.setDefault(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF, styleValue); > >- styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ >- store.setDefault(IStyleConstantsXML.XML_CONTENT, styleValue); // specified value is black; leaving as widget default >- >- styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; >- store.setDefault(IStyleConstantsXML.TAG_BORDER, styleValue); >+ styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ >+ store.setDefault(IStyleConstantsXML.XML_CONTENT, styleValue); > >- styleValue = ColorHelper.getColorString(63, 127, 127) + NOBACKGROUNDBOLD; >+ styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; >+ store.setDefault(IStyleConstantsXML.TAG_BORDER, styleValue); >+ >+ styleValue = ColorHelper.getColorString(63, 127, 127) + NOBACKGROUNDBOLD; > store.setDefault(IStyleConstantsXML.TAG_NAME, styleValue); >- >- styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; >+ >+ styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; > store.setDefault(IStyleConstantsXML.PI_BORDER, styleValue); >- >- styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ >- store.setDefault(IStyleConstantsXML.PI_CONTENT, styleValue); // specified value is black; leaving as widget default > >- styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; >- store.setDefault(IStyleConstantsXML.CDATA_BORDER, styleValue); >+ styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ >+ store.setDefault(IStyleConstantsXML.PI_CONTENT, styleValue); > >- styleValue = ColorHelper.getColorString(0, 0, 0) + NOBACKGROUNDBOLD; >+ styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; >+ store.setDefault(IStyleConstantsXML.CDATA_BORDER, styleValue); >+ >+ styleValue = ColorHelper.getColorString(0, 0, 0) + NOBACKGROUNDBOLD; > store.setDefault(IStyleConstantsXML.CDATA_TEXT, styleValue); >- >- store.setDefault(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_BACKGROUND, false); >- >- store.setDefault(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_FOREGROUND, false); >- >+ >+ // RIM source coloring preferences >+ store.setDefault(MessageInstanceStyleConstants.CDATA_BORDER_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.CDATA_TEXT_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.COMMENT_BORDER_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.COMMENT_TEXT_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.DECL_BORDER_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.PI_BORDER_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.PI_CONTENT_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.TAG_ATTRIBUTE_EQUALS_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.TAG_ATTRIBUTE_NAME_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.TAG_ATTRIBUTE_VALUE_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.TAG_BORDER_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.TAG_NAME_BACKGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.XML_CONTENT_BACKGROUND_RIM, false); >+ >+ store.setDefault(MessageInstanceStyleConstants.CDATA_BORDER_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.CDATA_TEXT_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.COMMENT_BORDER_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.COMMENT_TEXT_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.DECL_BORDER_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.PI_BORDER_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.PI_CONTENT_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.TAG_ATTRIBUTE_EQUALS_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.TAG_ATTRIBUTE_NAME_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.TAG_ATTRIBUTE_VALUE_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.TAG_BORDER_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.TAG_NAME_FOREGROUND_RIM, false); >+ store.setDefault(MessageInstanceStyleConstants.XML_CONTENT_FOREGROUND_RIM, false); >+ > } > > } >Index: src/org/eclipse/ohf/h3et/instanceeditor/ui/MessageInstanceLineStyleProvider.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.ohf/plugins/org.eclipse.ohf.h3et.instanceeditor.ui/src/org/eclipse/ohf/h3et/instanceeditor/ui/MessageInstanceLineStyleProvider.java,v >retrieving revision 1.1 >diff -u -r1.1 MessageInstanceLineStyleProvider.java >--- src/org/eclipse/ohf/h3et/instanceeditor/ui/MessageInstanceLineStyleProvider.java 22 Jan 2007 14:07:05 -0000 1.1 >+++ src/org/eclipse/ohf/h3et/instanceeditor/ui/MessageInstanceLineStyleProvider.java 24 Jan 2007 12:48:11 -0000 >@@ -56,8 +56,13 @@ > import org.w3c.dom.Document; > import org.w3c.dom.Node; > >-public class MessageInstanceLineStyleProvider extends LineStyleProviderForXML >-implements LineStyleProvider { >+/** >+ * Provides syntax coloring in the Source tab of the Message Instance Editor. >+ * >+ * @author Zsolt Török >+ * >+ */ >+public class MessageInstanceLineStyleProvider extends LineStyleProviderForXML implements LineStyleProvider { > > private ISourceViewer sourceViewer; > >@@ -65,98 +70,209 @@ > > private int start = 0; > >- private boolean rimForeground; >- >- private boolean rimBackground; >- >- private static Map<RIMClassCategorization,Color> colors = new HashMap<RIMClassCategorization,Color>(); >+ private static Map<RIMClassCategorization, Color> colors = new HashMap<RIMClassCategorization, Color>(); > >+ /** >+ * Class constructor specifying the <code>ISourceViewer</code> to use. >+ */ > public MessageInstanceLineStyleProvider(ISourceViewer sourceViewer) { > this.sourceViewer = sourceViewer; > } > >+ /** >+ * Provides the formatting information for a particular region of the >+ * document. >+ * >+ * @param region >+ * the region to be formatted >+ */ > protected TextAttribute getAttributeFor(ITextRegion region) { > if (region == null) { > return super.getAttributeFor(region); > } > >- TextAttribute result = null; >- >- rimForeground = getColorPreferences().getBoolean(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_FOREGROUND); >- rimBackground = getColorPreferences().getBoolean(MessageInstanceStyleConstants.USE_RIM_COLOR_FOR_BACKGROUND); >- >- if (rimForeground || rimBackground) { >- Color rimColor = getRIMColorFor(region); >- TextAttribute attribute = super.getAttributeFor(region); >- if (rimForeground) { >- result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >- } else if (rimBackground) { >- result = new TextAttribute(attribute.getForeground(), rimColor, attribute.getStyle()); >- } else if (rimForeground && rimBackground) { >- result = new TextAttribute(rimColor, rimColor, attribute.getStyle()); >- } >- >- return result; >+ String type = region.getType(); >+ TextAttribute attribute = super.getAttributeFor(region); >+ TextAttribute result = attribute; >+ Color rimColor = getRIMColorFor(region); >+ if (type == DOMRegionContext.XML_CONTENT) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.XML_CONTENT_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.XML_CONTENT_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if ((type == DOMRegionContext.XML_TAG_OPEN) || (type == DOMRegionContext.XML_END_TAG_OPEN) >+ || (type == DOMRegionContext.XML_TAG_CLOSE) || (type == DOMRegionContext.XML_EMPTY_TAG_CLOSE)) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_BORDER_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_BORDER_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if ((type == DOMRegionContext.XML_CDATA_OPEN) || (type == DOMRegionContext.XML_CDATA_CLOSE)) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.CDATA_BORDER_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.CDATA_BORDER_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if (type == DOMRegionContext.XML_CDATA_TEXT) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.CDATA_TEXT_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.CDATA_TEXT_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if (type == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_ATTRIBUTE_NAME_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_ATTRIBUTE_NAME_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if (type == DOMRegionContext.XML_DOCTYPE_DECLARATION) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_NAME_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_NAME_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if (type == DOMRegionContext.XML_TAG_NAME) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_NAME_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_NAME_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if ((type == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_ATTRIBUTE_VALUE_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_ATTRIBUTE_VALUE_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if (type == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_ATTRIBUTE_EQUALS_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_ATTRIBUTE_EQUALS_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if ((type == DOMRegionContext.XML_COMMENT_OPEN) || (type == DOMRegionContext.XML_COMMENT_CLOSE)) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.COMMENT_BORDER_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.COMMENT_BORDER_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if (type == DOMRegionContext.XML_COMMENT_TEXT) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.COMMENT_TEXT_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.COMMENT_TEXT_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if (type == DOMRegionContext.XML_DOCTYPE_NAME) { >+ // return (TextAttribute) >+ // getTextAttributes().get(IStyleConstantsXML.DOCTYPE_NAME); >+ } else if (type == DOMRegionContext.XML_PI_CONTENT) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.PI_CONTENT_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.PI_CONTENT_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if ((type == DOMRegionContext.XML_PI_OPEN) || (type == DOMRegionContext.XML_PI_CLOSE)) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.PI_BORDER_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.PI_BORDER_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if ((type == DOMRegionContext.XML_DECLARATION_OPEN) || (type == DOMRegionContext.XML_DECLARATION_CLOSE)) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.DECL_BORDER_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.DECL_BORDER_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if (type == DOMRegionContext.UNDEFINED) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.CDATA_TEXT_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.CDATA_TEXT_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if (type == DOMRegionContext.WHITE_SPACE) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.XML_CONTENT_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.XML_CONTENT_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else if ((type == DOMRegionContext.XML_CHAR_REFERENCE) || (type == DOMRegionContext.XML_ENTITY_REFERENCE) >+ || (type == DOMRegionContext.XML_PE_REFERENCE)) { >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_ATTRIBUTE_VALUE_FOREGROUND_RIM)) >+ result = new TextAttribute(rimColor, attribute.getBackground(), attribute.getStyle()); >+ if (getColorPreferences().getBoolean(MessageInstanceStyleConstants.TAG_ATTRIBUTE_VALUE_BACKGROUND_RIM)) >+ result = new TextAttribute(result.getForeground(), rimColor, attribute.getStyle()); >+ } else { >+ result = super.getAttributeFor(region); > } >- >- return super.getAttributeFor(region); >+ return result; > } > >- /* (non-Javadoc) >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.wst.xml.ui.internal.style.LineStyleProviderForXML#getColorPreferences() > */ > @Override > protected IPreferenceStore getColorPreferences() { >- // TODO Auto-generated method stub > return Activator.getDefault().getPreferenceStore(); > } > >- private Color getColorConstants(RIMClassCategorization rimAncestor) { >- Color result = colors.get(rimAncestor); >+ /** >+ * Returns the <code>Color</code> for the given RIM class from the plug-in >+ * preferences. >+ * >+ * @param rimClass >+ * the RIM class >+ * @return the Color for the specified RIM class >+ */ >+ private Color getColorConstants(RIMClassCategorization rimClass) { >+ Color result = colors.get(rimClass); > if (result != null) > return result; > >- if (rimAncestor == null) { >- result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), PreferenceConstants.DEFAULT_COLOR_FIELD_KEY)); >+ if (rimClass == null) { >+ result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), >+ PreferenceConstants.DEFAULT_COLOR_FIELD_KEY)); > colors.put(null, result); > return result; > } > >- switch (rimAncestor) { >+ switch (rimClass) { > case ACT: > result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), PreferenceConstants.ACT_COLOR_FIELD_KEY)); >- colors.put(rimAncestor, result); >+ colors.put(rimClass, result); > return result; > case ENTITY: >- result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), PreferenceConstants.ENTITY_COLOR_FIELD_KEY)); >- colors.put(rimAncestor, result); >+ result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), >+ PreferenceConstants.ENTITY_COLOR_FIELD_KEY)); >+ colors.put(rimClass, result); > return result; > case ACT_RELATIONSHIP: >- result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), PreferenceConstants.ACTRELATIONSHIP_COLOR_FIELD_KEY)); >- colors.put(rimAncestor, result); >+ result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), >+ PreferenceConstants.ACTRELATIONSHIP_COLOR_FIELD_KEY)); >+ colors.put(rimClass, result); > return result; > case PARTICIPATION: >- result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), PreferenceConstants.PARTICIPATION_COLOR_FIELD_KEY)); >- colors.put(rimAncestor, result); >+ result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), >+ PreferenceConstants.PARTICIPATION_COLOR_FIELD_KEY)); >+ colors.put(rimClass, result); > return result; > case ROLE: >- result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), PreferenceConstants.ROLE_COLOR_FIELD_KEY)); >- colors.put(rimAncestor, result); >+ result = new Color(null, PreferenceConverter >+ .getColor(getColorPreferences(), PreferenceConstants.ROLE_COLOR_FIELD_KEY)); >+ colors.put(rimClass, result); > return result; > case INFRASTRUCTURE: >- result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), PreferenceConstants.INFRASTRUCTURE_COLOR_FIELD_KEY)); >- colors.put(rimAncestor, result); >+ result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), >+ PreferenceConstants.INFRASTRUCTURE_COLOR_FIELD_KEY)); >+ colors.put(rimClass, result); > return result; > default: > result = colors.get(null); >- if (result == null) { >- result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), PreferenceConstants.DEFAULT_COLOR_FIELD_KEY)); >- colors.put(null, result); >- } >- return result; >+ if (result == null) { >+ result = new Color(null, PreferenceConverter.getColor(getColorPreferences(), >+ PreferenceConstants.DEFAULT_COLOR_FIELD_KEY)); >+ colors.put(null, result); >+ } >+ return result; > } > } > >+ /** >+ * Returns the <code>IEditorContext</code> for a specific DOM >+ * <code>Document</code>. >+ * >+ * @param file >+ * the file containing the document. >+ * @param doc >+ * the document >+ * @return the editor context for the document >+ * @throws H3ETException >+ */ > private IEditorContext getEditorContext(IFile file, Document doc) throws H3ETException { > if (editorContext != null) > return editorContext; >@@ -170,35 +286,42 @@ > locator = SimpleMIFLocator.createLocator(file, projectConfiguration.getModelPath()); > fragmentProvider = new FileFragmentProvider(file, projectConfiguration.getFragmentPath()); > vocabProvider = new InstanceVocabProvider(file, projectConfiguration.getVocabPath()); >- editorContext = ContextFactory.createContext(doc.getDocumentElement(), >- locator, fragmentProvider, vocabProvider); >+ editorContext = ContextFactory.createContext(doc.getDocumentElement(), locator, fragmentProvider, vocabProvider); > > return editorContext; > } > > private Document getDOMDocument() { >- IStructuredModel model=null; >+ IStructuredModel model = null; > model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); > > Document wstXMLdocument = ((IDOMModel) model).getDocument(); > model.releaseFromRead(); >- model=null; >+ model = null; > > return wstXMLdocument; > } >- >- private Color getRIMColorFor(ITextRegion region){ >- String type = region.getType(); >- IStructuredDocumentRegion flatRegion = ((IStructuredDocument) sourceViewer.getDocument()).getRegionAtCharacterOffset(region.getStart()); >+ >+ /** >+ * Returns the <code>Color</code> for a text region, if it's the child of >+ * an element, which has RIM class information. >+ * >+ * @param region >+ * the text region >+ * @return the color of the text region >+ */ >+ private Color getRIMColorFor(ITextRegion region) { >+ IStructuredDocumentRegion flatRegion = ((IStructuredDocument) sourceViewer.getDocument()) >+ .getRegionAtCharacterOffset(region.getStart()); > IStructuredDocument parentDocument = flatRegion.getParentDocument(); > IStructuredDocumentRegion[] regionList = parentDocument.getStructuredDocumentRegions(); >- >- int i=0; >- >+ >+ int i = 0; >+ > while (i < regionList.length) { > IStructuredDocumentRegion sdreg = regionList[i]; > ITextRegionList regs = sdreg.getRegions(); >- >+ > int j = 0; > while (j < regs.size()) { > if (regs.get(j).equals(region)) { >@@ -208,13 +331,12 @@ > } > i++; > } >- >+ > IndexedRegion treeNode = ContentAssistUtils.getNodeAt((StructuredTextViewer) sourceViewer, start); > if (treeNode == null) > return null; > Node node = (Node) treeNode; > >- > IEditorContext context; > > try { >@@ -223,24 +345,21 @@ > IStructuredModel model = modelManager.getExistingModelForRead(getDocument()); > > String modelBase = model.getBaseLocation(); >- >+ > model.releaseFromRead(); > Path modelPath = new Path(modelBase); > IWorkspace workspace = ResourcesPlugin.getWorkspace(); > IWorkspaceRoot workspaceRoot = workspace.getRoot(); > IPath workspaceRootPath = workspaceRoot.getLocation(); > IFile file = workspaceRoot.getFileForLocation(workspaceRootPath.append(modelPath)); >- >+ > context = getEditorContext(file, getDOMDocument()); > IInstanceModelQuery queryService = context.getQueryService(); > >- if (type == DOMRegionContext.XML_TAG_NAME) { >- if (node instanceof ElementImpl) { >- RIMClassCategorization rimAncestor = queryService.getRIMAncestorType((ElementImpl) node); >- if (rimAncestor != null) { >-// return new TextAttribute(getColorConstants(rimAncestor)); >- return getColorConstants(rimAncestor); >- } >+ if (node instanceof ElementImpl) { >+ RIMClassCategorization rimAncestor = queryService.getRIMAncestorType((ElementImpl) node); >+ if (rimAncestor != null) { >+ return getColorConstants(rimAncestor); > } > } > >@@ -248,6 +367,6 @@ > // TODO Auto-generated catch block > e.printStackTrace(); > } >- return null; >+ return null; > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 171519
: 57425