Issue #642 change font changer to FontDialog

Former-commit-id: bfd11e6a96 [formerly f1301645e7] [formerly 8b71b3058b [formerly 8f4c3b9d9769bf34e7c4744dd80b603d445b6270]]
Former-commit-id: 8b71b3058b
Former-commit-id: a438a35943
This commit is contained in:
Matt Nash 2012-05-21 10:39:03 -05:00
parent ada80acb0a
commit 62ecdebb9c
2 changed files with 49 additions and 29 deletions

View file

@ -24,18 +24,22 @@ import java.util.List;
import org.eclipse.jface.preference.ColorFieldEditor; import org.eclipse.jface.preference.ColorFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor; import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.preference.FontFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor; import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.resource.StringConverter;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.IWorkbenchPreferencePage;
@ -109,14 +113,51 @@ public class CollaborationAlertWordsPreferencePage extends
this.addField(colorEditor); this.addField(colorEditor);
colorEditor.loadDefault(); colorEditor.loadDefault();
final FontFieldChangeEditor fontEditor = new FontFieldChangeEditor( Composite fontComp = new Composite(getFieldEditorParent(), SWT.NONE);
"fonts", "Font", getFieldEditorParent()); GridLayout layout = new GridLayout(3, false);
this.addField(fontEditor); layout.marginHeight = 0;
layout.marginWidth = 0;
fontComp.setLayout(layout);
data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.horizontalSpan = 3;
fontComp.setLayoutData(data);
Label fontName = new Label(fontComp, SWT.NONE);
fontName.setText("Font");
data = new GridData(SWT.FILL, SWT.NONE, true, false);
fontName.setLayoutData(data);
final Label fontLabel = new Label(fontComp, SWT.NONE);
fontLabel.setText(StringConverter.asString(Display.getCurrent()
.getSystemFont().getFontData()[0]));
data = new GridData(SWT.FILL, SWT.NONE, true, true);
fontLabel.setLayoutData(data);
Button fontButton = new Button(fontComp, SWT.PUSH);
fontButton.setText("Change...");
data = new GridData(SWT.FILL, SWT.NONE, true, true);
final FileFieldEditor fileEditor = new FileFieldEditor("fileeditor", final FileFieldEditor fileEditor = new FileFieldEditor("fileeditor",
"Sound File", getFieldEditorParent()); "Sound File", getFieldEditorParent());
this.addField(fileEditor); this.addField(fileEditor);
fontButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FontDialog dialog = new FontDialog(Display.getCurrent()
.getActiveShell());
dialog.setFontList(StringConverter.asFontDataArray(fontLabel
.getText()));
FontData data = dialog.open();
if (data != null) {
fontLabel.setText(StringConverter.asString(data));
}
}
});
data = new GridData(SWT.NONE, SWT.NONE, false, true);
fontButton.setLayoutData(data);
Composite buttonComp = new Composite(getFieldEditorParent(), SWT.NONE); Composite buttonComp = new Composite(getFieldEditorParent(), SWT.NONE);
buttonComp.setLayout(new GridLayout(3, false)); buttonComp.setLayout(new GridLayout(3, false));
data = new GridData(SWT.FILL, SWT.FILL, true, true); data = new GridData(SWT.FILL, SWT.FILL, true, true);
@ -132,10 +173,9 @@ public class CollaborationAlertWordsPreferencePage extends
AlertWord word = new AlertWord(stringEditor AlertWord word = new AlertWord(stringEditor
.getStringValue(), colorEditor.getColorSelector() .getStringValue(), colorEditor.getColorSelector()
.getColorValue()); .getColorValue());
word.setFont(fontLabel.getText());
int index = viewer.getTable().getSelectionIndex(); int index = viewer.getTable().getSelectionIndex();
word.setSoundPath(fileEditor.getStringValue()); word.setSoundPath(fileEditor.getStringValue());
word.setFont(fontEditor
.getFontValue(getFieldEditorParent()));
((List<AlertWord>) viewer.getInput()).set(index, word); ((List<AlertWord>) viewer.getInput()).set(index, word);
viewer.refresh(); viewer.refresh();
} }
@ -153,9 +193,7 @@ public class CollaborationAlertWordsPreferencePage extends
AlertWord word = new AlertWord(stringEditor AlertWord word = new AlertWord(stringEditor
.getStringValue(), colorEditor.getColorSelector() .getStringValue(), colorEditor.getColorSelector()
.getColorValue()); .getColorValue());
word.setSoundPath(fileEditor.getStringValue()); word.setFont(fontLabel.getText());
word.setFont(fontEditor
.getFontValue(getFieldEditorParent()));
word.setSoundPath(fileEditor.getStringValue()); word.setSoundPath(fileEditor.getStringValue());
((List<AlertWord>) viewer.getInput()).add(word); ((List<AlertWord>) viewer.getInput()).add(word);
viewer.refresh(); viewer.refresh();
@ -191,27 +229,12 @@ public class CollaborationAlertWordsPreferencePage extends
new RGB(word.getRed(), word.getGreen(), word new RGB(word.getRed(), word.getGreen(), word
.getBlue())); .getBlue()));
stringEditor.setStringValue(word.getText()); stringEditor.setStringValue(word.getText());
fontEditor.setFontValue(word.getFont(), getFieldEditorParent()); fontLabel.setText(word.getFont());
fileEditor.setStringValue(word.getSoundPath()); fileEditor.setStringValue(word.getSoundPath());
} }
}); });
} }
private class FontFieldChangeEditor extends FontFieldEditor {
public FontFieldChangeEditor(String name, String text, Composite parent) {
super(name, text, parent);
}
public String getFontValue(Composite parent) {
return getValueControl(parent).getText();
}
public void setFontValue(String string, Composite parent) {
getValueControl(parent).setText(string);
doLoad();
}
}
public boolean performOk() { public boolean performOk() {
List<AlertWord> words = (List<AlertWord>) viewer.getInput(); List<AlertWord> words = (List<AlertWord>) viewer.getInput();
CollaborationUtils.saveAlertWords(words); CollaborationUtils.saveAlertWords(words);
@ -220,6 +243,7 @@ public class CollaborationAlertWordsPreferencePage extends
CollaborationConnection connection = CollaborationDataManager CollaborationConnection connection = CollaborationDataManager
.getInstance().getCollaborationConnection(false); .getInstance().getCollaborationConnection(false);
if (connection != null && connection.isConnected()) { if (connection != null && connection.isConnected()) {
// refresh any open chats or sessions
connection.getEventPublisher().post(wrapper); connection.getEventPublisher().post(wrapper);
} }
return true; return true;

View file

@ -354,13 +354,9 @@ public abstract class AbstractSessionView extends ViewPart {
if (!myUser.equals(userId)) { if (!myUser.equals(userId)) {
executeSightsSounds(keyword); executeSightsSounds(keyword);
} }
System.out.println("index before : " + index);
// need to handle all instances of the keyword within // need to handle all instances of the keyword within
// the chat // the chat
index = lowerCase.indexOf(text, text.length() + index); index = lowerCase.indexOf(text, text.length() + index);
System.out.println("index after : " + index);
System.out.println("messagesText.getCharCount() : "
+ messagesText.getCharCount());
} }
} }
} }