Issue #642 change font changer to FontDialog

Former-commit-id: 8b71b3058b [formerly 8f4c3b9d9769bf34e7c4744dd80b603d445b6270]
Former-commit-id: f1301645e7
This commit is contained in:
Matt Nash 2012-05-21 10:39:03 -05:00
parent 35713ca625
commit bfd11e6a96
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.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.preference.FontFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.resource.StringConverter;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.FontData;
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.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.IWorkbenchPreferencePage;
@ -109,14 +113,51 @@ public class CollaborationAlertWordsPreferencePage extends
this.addField(colorEditor);
colorEditor.loadDefault();
final FontFieldChangeEditor fontEditor = new FontFieldChangeEditor(
"fonts", "Font", getFieldEditorParent());
this.addField(fontEditor);
Composite fontComp = new Composite(getFieldEditorParent(), SWT.NONE);
GridLayout layout = new GridLayout(3, false);
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",
"Sound File", getFieldEditorParent());
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);
buttonComp.setLayout(new GridLayout(3, false));
data = new GridData(SWT.FILL, SWT.FILL, true, true);
@ -132,10 +173,9 @@ public class CollaborationAlertWordsPreferencePage extends
AlertWord word = new AlertWord(stringEditor
.getStringValue(), colorEditor.getColorSelector()
.getColorValue());
word.setFont(fontLabel.getText());
int index = viewer.getTable().getSelectionIndex();
word.setSoundPath(fileEditor.getStringValue());
word.setFont(fontEditor
.getFontValue(getFieldEditorParent()));
((List<AlertWord>) viewer.getInput()).set(index, word);
viewer.refresh();
}
@ -153,9 +193,7 @@ public class CollaborationAlertWordsPreferencePage extends
AlertWord word = new AlertWord(stringEditor
.getStringValue(), colorEditor.getColorSelector()
.getColorValue());
word.setSoundPath(fileEditor.getStringValue());
word.setFont(fontEditor
.getFontValue(getFieldEditorParent()));
word.setFont(fontLabel.getText());
word.setSoundPath(fileEditor.getStringValue());
((List<AlertWord>) viewer.getInput()).add(word);
viewer.refresh();
@ -191,27 +229,12 @@ public class CollaborationAlertWordsPreferencePage extends
new RGB(word.getRed(), word.getGreen(), word
.getBlue()));
stringEditor.setStringValue(word.getText());
fontEditor.setFontValue(word.getFont(), getFieldEditorParent());
fontLabel.setText(word.getFont());
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() {
List<AlertWord> words = (List<AlertWord>) viewer.getInput();
CollaborationUtils.saveAlertWords(words);
@ -220,6 +243,7 @@ public class CollaborationAlertWordsPreferencePage extends
CollaborationConnection connection = CollaborationDataManager
.getInstance().getCollaborationConnection(false);
if (connection != null && connection.isConnected()) {
// refresh any open chats or sessions
connection.getEventPublisher().post(wrapper);
}
return true;

View file

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