001: package net.refractions.udig.internal.ui;
002:
003: import net.refractions.udig.ui.UIUtilities;
004: import net.refractions.udig.ui.preferences.PreferenceConstants;
005:
006: import org.eclipse.jface.dialogs.IDialogConstants;
007: import org.eclipse.jface.dialogs.IconAndMessageDialog;
008: import org.eclipse.jface.preference.IPreferenceStore;
009: import org.eclipse.jface.resource.JFaceResources;
010: import org.eclipse.swt.SWT;
011: import org.eclipse.swt.accessibility.AccessibleAdapter;
012: import org.eclipse.swt.accessibility.AccessibleEvent;
013: import org.eclipse.swt.custom.StyledText;
014: import org.eclipse.swt.graphics.Image;
015: import org.eclipse.swt.layout.GridData;
016: import org.eclipse.swt.layout.GridLayout;
017: import org.eclipse.swt.widgets.Button;
018: import org.eclipse.swt.widgets.Composite;
019: import org.eclipse.swt.widgets.Control;
020: import org.eclipse.swt.widgets.Event;
021: import org.eclipse.swt.widgets.Label;
022: import org.eclipse.swt.widgets.Link;
023: import org.eclipse.swt.widgets.Listener;
024: import org.eclipse.swt.widgets.Shell;
025:
026: public class LinuxAdvancedDialog extends IconAndMessageDialog {
027:
028: private StyledText styledMessage;
029: private Link linkedMessage;
030: private String url = "http://jira.codehaus.org/browse/UDIG-1110";
031:
032: public LinuxAdvancedDialog(Shell parentShell) {
033: super (parentShell);
034: setShellStyle(getShellStyle() | SWT.RESIZE);
035: this .message = "Some Linux users have experienced issues with map display being slow or strange artifacts on some versions of Linux. "
036: + "This is a bug with SWT. For more information please see JIRA bug "
037: + "<a href=\""
038: + url
039: + "\">UDIG-1110</a>. There is a "
040: + "link there to <a href=\"https://bugs.eclipse.org/bugs/show_bug.cgi?id=163069\">the SWT bug</a>. Please vote for it!\n\n"
041: + "A workaround is available by disabling advanced graphics. You may do so now, or you may "
042: + "toggle this later under preferences.\n\n"
043: + "Advanced graphics are used in the interface itself, such as the zoom tool for example.";
044: }
045:
046: @Override
047: protected Image getImage() {
048: return getWarningImage();
049: }
050:
051: protected Control createMessageArea(Composite composite) {
052: // create composite
053: // create image
054: Image image = getImage();
055: if (image != null) {
056: imageLabel = new Label(composite, SWT.NULL);
057: image.setBackground(imageLabel.getBackground());
058: imageLabel.setImage(image);
059: addAccessibleListeners(imageLabel, image);
060: imageLabel.setLayoutData(new GridData(
061: GridData.HORIZONTAL_ALIGN_CENTER
062: | GridData.VERTICAL_ALIGN_BEGINNING));
063: }
064: // create message
065: if (message != null) {
066: linkedMessage = new Link(composite, getMessageLabelStyle());
067: // styledMessage = new StyledText(composite, getLinMessageLabelStyle());
068: linkedMessage.setText(message);
069: linkedMessage.setToolTipText("Open in web browser: " + url);
070: GridData data = new GridData(GridData.GRAB_HORIZONTAL
071: | GridData.HORIZONTAL_ALIGN_FILL
072: | GridData.VERTICAL_ALIGN_BEGINNING);
073: data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
074: linkedMessage.setLayoutData(data);
075: linkedMessage.addListener(SWT.Selection, new Listener() {
076:
077: public void handleEvent(Event event) {
078: UIUtilities.openLink(event.text);
079: }
080:
081: });
082: }
083: return composite;
084: }
085:
086: private void addAccessibleListeners(Label label, final Image image) {
087: label.getAccessible().addAccessibleListener(
088: new AccessibleAdapter() {
089: public void getName(AccessibleEvent event) {
090: final String accessibleMessage = getAccessibleMessageFor(image);
091: if (accessibleMessage == null) {
092: return;
093: }
094: event.result = accessibleMessage;
095: }
096: });
097: }
098:
099: private String getAccessibleMessageFor(Image image) {
100: if (image.equals(getErrorImage())) {
101: return JFaceResources.getString("error");//$NON-NLS-1$
102: }
103:
104: if (image.equals(getWarningImage())) {
105: return JFaceResources.getString("warning");//$NON-NLS-1$
106: }
107:
108: if (image.equals(getInfoImage())) {
109: return JFaceResources.getString("info");//$NON-NLS-1$
110: }
111:
112: if (image.equals(getQuestionImage())) {
113: return JFaceResources.getString("question"); //$NON-NLS-1$
114: }
115:
116: return null;
117: }
118:
119: @Override
120: protected Control createDialogArea(Composite parent) {
121:
122: Composite composite = (Composite) super
123: .createDialogArea(parent);
124: ((GridLayout) composite.getLayout()).numColumns = 2;
125: ((GridLayout) composite.getLayout()).makeColumnsEqualWidth = false;
126:
127: createMessageArea(composite);
128:
129: return composite;
130: }
131:
132: protected void createButtonsForButtonBar(Composite parent) {
133: // create OK and Cancel buttons by default
134: Button b = createButton(parent, IDialogConstants.OK_ID,
135: "Disable Advanced Graphics", true);
136: createButton(parent, IDialogConstants.CANCEL_ID, "Do Nothing",
137: false);
138: b.setFocus();
139: }
140:
141: protected void configureShell(Shell newShell) {
142: newShell.setText("Possible Linux Issue");
143: newShell.setImage(UiPlugin.getDefault()
144: .create("icon32.gif").createImage()); //$NON-NLS-1$
145: }
146:
147: protected void okPressed() {
148: IPreferenceStore store = UiPlugin.getDefault()
149: .getPreferenceStore();
150: boolean useAdvancedGraphics = store
151: .getBoolean(net.refractions.udig.ui.preferences.PreferenceConstants.P_ADVANCED_GRAPHICS);
152:
153: if (useAdvancedGraphics) {
154: store.setValue(PreferenceConstants.P_ADVANCED_GRAPHICS,
155: false);
156: }
157:
158: super.okPressed();
159: }
160:
161: }
|