Commit 8ce057cf authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Added style support for Ttcn3SourceViewerControl and converted to singelton


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 15bf6201
......@@ -9,11 +9,10 @@ package org.eclipse.titan.designer.editors.controls;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.IInformationControlExtension2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusListener;
......@@ -35,14 +34,31 @@ import org.eclipse.swt.widgets.Shell;
* @author Miklos Magyari
*
*/
public class Ttcn3SourceViewControl implements IInformationControl {
private Shell myshell;
private SourceViewer viewer;
public class Ttcn3SourceViewControl implements IInformationControl, IInformationControlExtension2 {
private static Ttcn3SourceViewControl instance = null;
private static Shell myshell;
private static StyledText viewer;
private int maxWidth = SWT.DEFAULT;
private int maxHeight = SWT.DEFAULT;
public Ttcn3SourceViewControl(Shell parent) {
public static Ttcn3SourceViewControl getInstance() {
if (instance == null) {
instance = new Ttcn3SourceViewControl();
}
return instance;
}
private Ttcn3SourceViewControl() {
}
public void createControl(Shell parent) {
if (myshell != null) {
return;
}
myshell = new Shell(parent, SWT.ON_TOP | SWT.TOOL | SWT.LEFT_TO_RIGHT | SWT.RESIZE);
Composite composite = myshell;
GridLayout layout = new GridLayout(1, false);
......@@ -55,15 +71,13 @@ public class Ttcn3SourceViewControl implements IInformationControl {
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
composite.setLayoutData(gridData);
viewer = new SourceViewer(composite, null, SWT.V_SCROLL | SWT.H_SCROLL);
viewer = new StyledText(composite, SWT.V_SCROLL | SWT.H_SCROLL);
viewer.setEditable(false);
Font textFont= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
StyledText styledText = viewer.getTextWidget();
styledText.setFont(textFont);
StyledText st = viewer.getTextWidget();
Font textFont= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
gridData = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
st.setLayoutData(gridData);
st.addKeyListener(new KeyListener() {
viewer.setLayoutData(gridData);
viewer.setFont(textFont);
viewer.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.character == 0x1B)
......@@ -78,11 +92,17 @@ public class Ttcn3SourceViewControl implements IInformationControl {
@Override
public void setInformation(String information) {
if (information == null) {
viewer.setInput(null);
viewer.setText(null);
return;
}
IDocument doc = new Document(information);
viewer.setInput(doc);
viewer.setText(information);
// StyleRange range = new StyleRange();
// range.start = 0;
// range.length = 4;
// range.fontStyle = SWT.BOLD;
// range.foreground = viewer.getDisplay().getSystemColor(SWT.COLOR_GREEN);
// viewer.setStyleRange(range);
}
@Override
......@@ -126,8 +146,9 @@ public class Ttcn3SourceViewControl implements IInformationControl {
@Override
public void dispose() {
// TODO Auto-generated method stub
instance = null;
myshell.dispose();
myshell = null;
}
@Override
......@@ -165,4 +186,10 @@ public class Ttcn3SourceViewControl implements IInformationControl {
// TODO Auto-generated method stub
}
@Override
public void setInput(Object input) {
// TODO Auto-generated method stub
}
}
......@@ -146,7 +146,8 @@ public class PeekDeclaration extends AbstractHandler implements IEditorActionDel
IEditorInput input = targetEditor.getEditorInput();
IDocument document = provider.getDocument(input);
Ttcn3SourceViewControl con = new Ttcn3SourceViewControl(shell);
Ttcn3SourceViewControl con = Ttcn3SourceViewControl.getInstance();
con.createControl(shell);
Control control = targetEditor.getAdapter(Control.class);
if (control instanceof StyledText) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment