Java Code Examples for org.eclipse.swt.custom.StyledText#setLayoutData()

The following examples show how to use org.eclipse.swt.custom.StyledText#setLayoutData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogUploadDesign.java    From ldparteditor with MIT License 6 votes vote down vote up
/**
 * Create contents of the dialog.
 *
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite cmp_container = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = (GridLayout) cmp_container.getLayout();
    gridLayout.verticalSpacing = 10;
    gridLayout.horizontalSpacing = 10;

    Label lbl_specify = new Label(cmp_container, SWT.NONE);
    lbl_specify.setText(I18n.E3D_LogUploadData);

    Label lbl_separator = new Label(cmp_container, SWT.SEPARATOR | SWT.HORIZONTAL);
    lbl_separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    final StyledText styledText = new StyledText(cmp_container, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
    styledText.setText(source);
    styledText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(2, 1).create());

    cmp_container.pack();
    return cmp_container;
}
 
Example 2
Source File: BibtexEditor.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
private void createAbstractText(Composite composite) {
	GridData gridData = new GridData();
	gridData.horizontalAlignment = SWT.FILL;
	gridData.grabExcessHorizontalSpace = true;
	gridData.verticalAlignment = SWT.FILL;
	gridData.grabExcessVerticalSpace = true;
	gridData.verticalSpan = 1;
	gridData.horizontalSpan = 2;
	
	StyledText text = new StyledText(composite, SWT.V_SCROLL | SWT.READ_ONLY | SWT.WRAP);
	text.setEditable(false);
	text.setLayoutData(gridData);
	if (document.getAbstract() != null) {
		text.setText(document.getAbstract());
	}
}
 
Example 3
Source File: RenameInformationPopup.java    From typescript.java with MIT License 6 votes vote down vote up
private void createContent(Composite parent) {
	Display display= parent.getDisplay();
	Color foreground= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
	Color background= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
	addMoveSupport(fPopup, parent);

	StyledText hint= new StyledText(fPopup, SWT.READ_ONLY | SWT.SINGLE);
	hint.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
	String enterKeyName= getEnterBinding();
	String hintTemplate= RefactoringMessages.RenameInformationPopup_EnterNewName;
	hint.setText(NLS.bind(hintTemplate, enterKeyName));
	hint.setForeground(foreground);
	hint.setStyleRange(new StyleRange(hintTemplate.indexOf("{0}"), enterKeyName.length(), null, null, SWT.BOLD)); //$NON-NLS-1$
	hint.setEnabled(false); // text must not be selectable
	addMoveSupport(fPopup, hint);

	addLink(parent);
	addViewMenu(parent);

	recursiveSetBackgroundColor(parent, background);

}
 
Example 4
Source File: HoverInfoWithSpellingAnnotation.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void createAnnotationInformation(Composite parent, final Annotation annotation) {
    Composite composite= new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    GridLayout layout= new GridLayout(2, false);
    layout.marginHeight= 2;
    layout.marginWidth= 2;
    layout.horizontalSpacing= 0;
    composite.setLayout(layout);

    final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS);
    GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    gridData.widthHint= 17;
    gridData.heightHint= 16;
    canvas.setLayoutData(gridData);
    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setFont(null);
            fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16));
        }
    });

    StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
    GridData data= new GridData(SWT.FILL, SWT.FILL, true, true);
    text.setLayoutData(data);
    text.setText(annotation.getText());
}
 
Example 5
Source File: ScrolledTextEx.java    From SWET with MIT License 6 votes vote down vote up
private StyledText createStyledText() {
	styledText = new StyledText(shell,
			SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); // SWT.WRAP
	GridData gridData = new GridData();
	styledText.setFont(
			new Font(shell.getDisplay(), "Source Code Pro Light", 10, SWT.NORMAL));
	gridData.horizontalAlignment = GridData.FILL;
	gridData.grabExcessHorizontalSpace = true;
	gridData.verticalAlignment = GridData.FILL;
	gridData.grabExcessVerticalSpace = true;
	styledText.setLayoutData(gridData);
	styledText.addLineStyleListener(lineStyler);
	styledText.setEditable(false);
	styledText
			.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
	return styledText;
}
 
Example 6
Source File: ExportJavaViewer.java    From http4e with Apache License 2.0 6 votes vote down vote up
void createStyledText(Composite parent){
      text = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
//      text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
      GridData spec = new GridData();
      spec.heightHint = HEIGHT;
      spec.widthHint = WEIGHT;
      spec.horizontalAlignment = GridData.FILL;
      spec.grabExcessHorizontalSpace = true;
      spec.verticalAlignment = GridData.FILL;
      spec.grabExcessVerticalSpace = true;
      text.setLayoutData(spec);
      text.addLineStyleListener(lineStyler);
      text.setEditable(false);
      Color bg = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
      text.setBackground(bg);
   }
 
Example 7
Source File: DetailsView.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void insert(Composite parent, int numberOfRow) {
	for (int i = 0; i < params.length; i++) {
		String param = params[i];
		
		new Label(parent, SWT.NONE).setText("");
						
		StyledText lbl = new StyledText(parent, SWT.FULL_SELECTION | SWT.READ_ONLY | SWT.WRAP);
		lbl.setAlwaysShowScrollBars(false);
		lbl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		if( param.matches("^[a-zA-Z0-9]+:\\/\\/.*$") ) {
			lbl.setFont(SWTResourceManager.getFont("Segoe UI", 7, SWT.UNDERLINE_LINK));
			lbl.setForeground(SWTResourceManager.getColor(SWT.COLOR_LINK_FOREGROUND));
			lbl.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
			lbl.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseDown(MouseEvent e) {
					eventManager.invoke(l -> l.onOpenInBrowserRequest(param));
				}
			});
		}else {
			lbl.setFont(SWTResourceManager.getFont("Segoe UI", 7, SWT.NORMAL));
		}
		lbl.setText(param);
		
		if (numberOfRow % 2 == 0) {
			lbl.setBackground(SWTResourceManager.getColor(206, 234, 255));
		}
	}
}
 
Example 8
Source File: PersonalAnamnesisComposite.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public PersonalAnamnesisComposite(Composite parent, int style){
	super(parent, style);
	setLayout(new GridLayout(1, false));
	textOberservation =
		new StyledText(this, SWT.NONE | SWT.WRAP | SWT.MULTI | SWT.V_SCROLL);
	textOberservation.setAlwaysShowScrollBars(true); //if false horizontal scrollbar blinks on typing
	GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
	gd.widthHint = 100;
	gd.heightHint = 100;
	textOberservation.setLayoutData(gd);
	initDataBindings();
}
 
Example 9
Source File: RunClientDialog.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
/**
 * Create contents of the dialog.
 *
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    setMessage("Runtime client running information");
    setTitle("Initalize Runtime Server");
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    logStyledText = new StyledText(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
    logStyledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    logStyledText.setText("Checking for all bundles start...");
    return area;
}
 
Example 10
Source File: SourceCodeView.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Basic source code viewer...
 * @param content
 */
private void createSourceContent(Composite content) {
	
	JavaLineStyler lineStyler = new JavaLineStyler();
	
	StyledText text = new StyledText(content, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
	GridData spec = new GridData();
	spec.horizontalAlignment = GridData.FILL;
	spec.grabExcessHorizontalSpace = true;
	spec.verticalAlignment = GridData.FILL;
	spec.grabExcessVerticalSpace = true;
	text.setLayoutData(spec);
	text.addLineStyleListener(lineStyler);
	// Use a monospaced font, which is not as easy as it might be.
	// http://stackoverflow.com/questions/221568/swt-os-agnostic-way-to-get-monospaced-font
	text.setFont(JFaceResources.getTextFont());
	text.setEditable(false);
	
	// Providing that they run this from a debug session:
	try {
		File   dir = BundleUtils.getBundleLocation("org.eclipse.dawnsci.plotting.examples");
		String loc = "/src/"+getClass().getName().replace('.', '/')+".java";
		File   src = new File(dir, loc);
		text.setText(readFile(src).toString());
		
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 11
Source File: EvalExpressionAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
    GridData gd = new GridData(GridData.FILL_BOTH);
    StyledText text = new StyledText(parent,
            SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL);
    text.setLayoutData(gd);

    text.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));

    text.setText(this.text);

    return text;
}
 
Example 12
Source File: GroovyEditorDocumentationDialogTray.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void createFunctionDocumentaion(final Composite parent) {
    final Composite docComposite = new Composite(parent, SWT.NONE);
    docComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    docComposite.setLayout(new GridLayout(1, true));

    final Label docTitle = new Label(docComposite, SWT.NONE);
    docTitle.setText(Messages.functionDocTitle);

    documenationText = new StyledText(docComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    documenationText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 90).create());
    documenationText.setEditable(false);
    fPresenter = new HTMLTextPresenter(false);
}
 
Example 13
Source File: GetActiveKeyDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
	Composite tparent = (Composite) super.createDialogArea(parent);

	GridLayout layout = new GridLayout();
	layout.marginWidth = 10;
	layout.marginTop = 10;
	tparent.setLayout(layout);

	GridDataFactory.fillDefaults().grab(true, true).applyTo(tparent);

	Composite compNav = new Composite(tparent, SWT.NONE);
	GridLayout navLayout = new GridLayout();
	compNav.setLayout(navLayout);

	createNavigation(compNav);

	Group groupActivekey = new Group(tparent, SWT.NONE);
	groupActivekey.setText(Messages.getString("license.GetActiveKeyDialog.activekey"));
	GridDataFactory.fillDefaults().grab(true, true).applyTo(groupActivekey);
	GridLayout layoutGroup = new GridLayout(2, false);
	layoutGroup.marginWidth = 5;
	layoutGroup.marginHeight = 20;
	groupActivekey.setLayout(layoutGroup);

	StyledText text = new StyledText(groupActivekey, SWT.WRAP | SWT.READ_ONLY);
	text.setBackground(text.getParent().getBackground());
	text.setText(Messages.getString("license.GetActiveKeyDialog.activemessage"));
	GridData dataText = new GridData();
	dataText.horizontalSpan = 2;
	dataText.widthHint = 470;
	text.setLayoutData(dataText);
	int start = Messages.getString("license.GetActiveKeyDialog.activemessage").indexOf(
			Messages.getString("license.GetActiveKeyDialog.ts"));
	int length = Messages.getString("license.GetActiveKeyDialog.ts").length();
	StyleRange styleRange = new StyleRange();
	styleRange.start = start;
	styleRange.length = length;
	styleRange.fontStyle = SWT.BOLD;
	styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
	text.setStyleRange(styleRange);

	Label label = new Label(groupActivekey, SWT.WRAP | SWT.NONE);
	label.setText(Messages.getString("license.GetActiveKeyDialog.activemessage1"));
	GridDataFactory.fillDefaults().span(2, 1).applyTo(label);

	textActivekey = new Text(groupActivekey, SWT.MULTI | SWT.WRAP);
	textActivekey.setEditable(false);
	textActivekey.setText(activekey);
	textActivekey.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
	GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 150).applyTo(textActivekey);

	Button btnCopy = new Button(groupActivekey, SWT.NONE);
	GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.END).applyTo(btnCopy);
	btnCopy.setImage(Activator.getImageDescriptor("images/help/copy.png").createImage());
	btnCopy.setToolTipText(Messages.getString("license.GetActiveKeyDialog.copytoclipboard"));
	btnCopy.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent event) {
			Clipboard cb = new Clipboard(Display.getCurrent());
			String textData = textActivekey.getText();
			TextTransfer textTransfer = TextTransfer.getInstance();
			cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
		}
	});

	return tparent;
}
 
Example 14
Source File: AbstractPTWidget.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Build the description panel
 *
 * @param parent parent composite
 */
private void buildDescriptionPanel(final Composite parent) {
	descriptionLabel = new StyledText(parent, SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
	descriptionLabel.setText("");
	descriptionLabel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1));
}
 
Example 15
Source File: ProgressReporterPanel.java    From BiglyBT with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Below the panel, taking up the entire width of the window, is the detail section
 */
private void createDetailSection(IProgressReport pReport) {
	Label separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
	separator.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

	detailSection = new TwistieSection(this, TwistieLabel.NONE);
	detailSection.setTitle(MessageText.getString("label.details"));
	Composite sectionContent = detailSection.getContent();

	detailSectionData = new GridData(SWT.FILL, SWT.FILL, true, true);
	detailSection.setLayoutData(detailSectionData);

	GridLayout sectionLayout = new GridLayout();
	sectionLayout.marginHeight = 0;
	sectionLayout.marginWidth = 0;
	sectionContent.setLayout(sectionLayout);
	detailSection.setEnabled(false);

	detailListWidget = new StyledText(sectionContent, SWT.BORDER | SWT.V_SCROLL
			| SWT.WRAP);
	detailListWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

	/*
	 * Add a default message instead of an empty box if there is no history;
	 * remove this later when a real detail message arrive
	 */

	IMessage[] messages = pReporter.getMessageHistory();
	/*
	 * Show error messages in red; otherwise use default color
	 */
	for (int i = 0; i < messages.length; i++) {
		if (messages[i].getType() == MSG_TYPE_ERROR) {
			appendToDetail(formatForDisplay(messages[i].getValue()), true);
		} else {
			appendToDetail(formatForDisplay(messages[i].getValue()), false);
		}
	}

	resizeDetailSection();

	/*
	 * Force a layout when ever the section is collapsed or expanded
	 */
	detailSection.addTwistieListener(new ITwistieListener() {
		@Override
		public void isCollapsed(boolean value) {
			resizeDetailSection();
			layout(true, true);
		}

	});

}
 
Example 16
Source File: CTabItemWithHexViewer.java    From Flashtool with GNU General Public License v3.0 4 votes vote down vote up
private void createEditor(){		
	CTabItem tabItem = new CTabItem(parent, style);
	tabItem.setText(name);
	
	Composite composite = new Composite(parent, SWT.NONE);
	tabItem.setControl(composite);
	FormLayout fl_composite = new FormLayout();
	fl_composite.marginWidth = 0;
	fl_composite.marginHeight = 0;
	composite.setLayout(fl_composite);
	
	counter = new StyledText(composite, SWT.BORDER | SWT.READ_ONLY);
	//counter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	FormData fd_counter = new FormData();
	fd_counter.top=new FormAttachment(0, 0);
	fd_counter.bottom=new FormAttachment(100, 0);
	fd_counter.left=new FormAttachment(0, 0);
	counter.setLayoutData(fd_counter);
	counter.setFont(SWTResourceManager.getFont("Courier New", 10, SWT.NORMAL));
	addListeners(counter);

	hexContent = new StyledText(composite, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL);
	FormData fd_hexContent = new FormData();
	fd_hexContent.top=new FormAttachment(0, 0);
	fd_hexContent.bottom=new FormAttachment(100, 0);
	fd_hexContent.left=new FormAttachment(counter, 0);
	fd_hexContent.width=400;
	hexContent.setLayoutData(fd_hexContent);
	hexContent.setFont(SWTResourceManager.getFont("Courier New", 10, SWT.NORMAL));
	addListeners(hexContent);

	binContent = new StyledText(composite, SWT.BORDER | SWT.READ_ONLY );
	FormData fd_binContent = new FormData();
	fd_binContent.top=new FormAttachment(0, 0);
	fd_binContent.bottom=new FormAttachment(100, 0);
	fd_binContent.left=new FormAttachment(hexContent, 0);
	fd_binContent.right=new FormAttachment(100, 0);
	binContent.setLayoutData(fd_binContent);
	//binContent.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, true, 1, 1));
	binContent.setFont(SWTResourceManager.getFont("Courier New", 10, SWT.NORMAL));
	addListeners(binContent);

	parent.setSelection(tabItem);

}
 
Example 17
Source File: ExecutionStatisticsDialog.java    From tlaplus with MIT License 4 votes vote down vote up
@Override
  protected Control createCustomArea(Composite parent) {
final Composite c = new Composite(parent, SWT.BORDER);
c.setLayout(new GridLayout());
c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

//NOTE: Take care of ExecutionStatisticsCollector.md when updating!!!
final String txt = String.format("%s"
		+ "* Total number of cores and cores assigned to TLC\n"
		+ "* Heap and off-heap memory allocated to TLC\n"
		+ "* TLC's version (git commit SHA)\n"
		+ "* If breadth-first search, depth-first search or simulation mode is active\n"
		+ "* TLC's implementation for the sets of seen and unseen states\n"
		+ "* If TLC has been launched from the TLA Toolbox\n"
		+ "* Name, version, and architecture of your operating system\n"
		+ "* Vendor, version, and architecture of your Java virtual machine\n"
		+ "* The current date and time\n"
		+ "* An installation identifier which allows us to group execution statistics\n\n"
		+ "The execution statistics do not contain personal information. If you wish to revoke\n"
		+ "your consent to share execution statistics at a later point, please chose \n"
		+ "\"Never Share Execution Statistics\" below by re-opening this dialog via\n"
		+ "Help > Opt In/Out Execution Statistics accessible from the Toolbox's main menu.", prettyPrintSelection2(esc));

final StyledText st = new StyledText(c, SWT.SHADOW_NONE | SWT.WRAP);
st.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

st.setEnabled(true);
st.setEditable(false);
st.setText(txt);

final StyleRange[] ranges = new StyleRange[3];
ranges[0] = new StyleRange(txt.indexOf("(TLC) execution statistics"), "(TLC) execution statistics".length(), null, null);
ranges[0].underline = true;
ranges[0].underlineStyle = SWT.UNDERLINE_LINK;
ranges[0].data = "https://exec-stats.tlapl.us";

ranges[1] = new StyleRange(txt.indexOf("publicly available"), "publicly available".length(), null, null);
ranges[1].underline = true;
ranges[1].underlineStyle = SWT.UNDERLINE_LINK;
ranges[1].data = "https://exec-stats.tlapl.us/tlaplus.csv";
		
ranges[2] = new StyleRange(txt.indexOf("git commit SHA"), "git commit SHA".length(), null, null);
ranges[2].underline = true;
ranges[2].underlineStyle = SWT.UNDERLINE_LINK;
ranges[2].data = "https://git-scm.com/book/en/v2/Git-Internals-Git-Objects";

st.setStyleRanges(ranges);
st.addMouseListener(new MouseAdapter() {
	@Override
	public void mouseUp(final MouseEvent event) {
              final int offset = st.getOffsetAtPoint(new Point(event.x, event.y));
              if (offset < 0 || offset >= st.getCharCount()) {
              	return;
              }
		final StyleRange style = st.getStyleRangeAtOffset(offset);
              if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK && style.data instanceof String) {
                  try {
				PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL((String) style.data));
			} catch (PartInitException | MalformedURLException notExpectedToHappen) {
				notExpectedToHappen.printStackTrace();
			}
              }
	}
});
	
      return c;
  }
 
Example 18
Source File: IllegalBinaryStateDialog.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a control with some message and with link to the Binaries preference page.
 *
 * @param parent
 *            the parent composite.
 * @param dialog
 *            the container dialog that has to be closed.
 * @param binary
 *            the binary with the illegal state.
 *
 * @return a control with error message and link that can be reused in dialogs.
 */
public static Control createCustomAreaWithLink(final Composite parent, final Dialog dialog, final Binary binary) {
	final String binaryLabel = binary.getLabel();
	final String prefix = "The requested operation cannot be performed due to invalid '" + binaryLabel
			+ "' settings. Check your '" + binaryLabel
			+ "' configuration and preferences under the corresponding ";
	final String link = "preference page";
	final String suffix = ".";
	final String text = prefix + link + suffix;

	final Composite control = new Composite(parent, NONE);
	control.setLayout(GridLayoutFactory.fillDefaults().create());
	final GridData gridData = GridDataFactory.fillDefaults().align(LEFT, TOP).grab(true, true).create();
	control.setLayoutData(gridData);

	final StyleRange style = new StyleRange();
	style.underline = true;
	style.underlineStyle = UNDERLINE_LINK;

	final StyledText styledText = new StyledText(control, MULTI | READ_ONLY | WRAP);
	styledText.setWordWrap(true);
	styledText.setJustify(true);
	styledText.setText(text);
	final GridData textGridData = GridDataFactory.fillDefaults().align(FILL, FILL).grab(true, true).create();
	textGridData.widthHint = TEXT_WIDTH_HINT;
	textGridData.heightHint = TEXT_HEIGHT_HINT;
	styledText.setLayoutData(textGridData);

	styledText.setEditable(false);
	styledText.setBackground(UIUtils.getSystemColor(COLOR_WIDGET_BACKGROUND));
	final int[] ranges = { text.indexOf(link), link.length() };
	final StyleRange[] styles = { style };
	styledText.setStyleRanges(ranges, styles);

	styledText.addMouseListener(new MouseAdapter() {

		@Override
		public void mouseDown(final MouseEvent event) {
			try {
				final int offset = styledText.getOffsetAtPoint(new Point(event.x, event.y));
				final StyleRange actualStyle = offset >= 0 ? styledText.getStyleRangeAtOffset(offset) : null;
				if (null != actualStyle && actualStyle.underline
						&& UNDERLINE_LINK == actualStyle.underlineStyle) {

					dialog.close();
					final PreferenceDialog preferenceDialog = createPreferenceDialogOn(
							UIUtils.getShell(),
							BinariesPreferencePage.ID,
							FILTER_IDS,
							null);

					if (null != preferenceDialog) {
						preferenceDialog.open();
					}

				}
			} catch (final IllegalArgumentException e) {
				// We are not over the actual text.
			}
		}

	});

	return control;
}
 
Example 19
Source File: TmMatchEditDialog.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create contents of the dialog.
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
	Composite container = (Composite) super.createDialogArea(parent);
	container.setLayout(new GridLayout(1, false));

	Group srcGroup = new Group(container, SWT.NONE);
	srcGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	srcGroup.setLayout(new GridLayout(1, false));
	String srcGroupTile = Messages.getString("dialog.TmMatchEditDialog.component.src");
	srcGroupTile = MessageFormat.format(srcGroupTile, fuzzyResult.getTu().getSource().getLangCode());
	srcGroup.setText(srcGroupTile);

	srcSegmentViewer = new SegmentViewer(srcGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL, null);
	StyledText srcTextControl = srcSegmentViewer.getTextWidget();
	srcTextControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	srcTextControl.setLineSpacing(Constants.SEGMENT_LINE_SPACING);
	srcTextControl.setLeftMargin(Constants.SEGMENT_LEFT_MARGIN);
	srcTextControl.setRightMargin(Constants.SEGMENT_RIGHT_MARGIN);
	srcTextControl.setTopMargin(Constants.SEGMENT_TOP_MARGIN);
	srcTextControl.setBottomMargin(Constants.SEGMENT_TOP_MARGIN);
	srcTextControl.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));

	Group targetGroup = new Group(container, SWT.NONE);
	targetGroup.setLayout(new GridLayout(1, false));
	targetGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	String tgtGroupTile = Messages.getString("dialog.TmMatchEditDialog.component.tgt");
	tgtGroupTile = MessageFormat.format(tgtGroupTile, fuzzyResult.getTu().getSource().getLangCode());
	targetGroup.setText(tgtGroupTile);

	tgtSegmentViewer = new SegmentViewer(targetGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL, null);
	StyledText tgtTextControl = tgtSegmentViewer.getTextWidget();
	tgtTextControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	tgtTextControl.setLineSpacing(Constants.SEGMENT_LINE_SPACING);
	tgtTextControl.setLeftMargin(Constants.SEGMENT_LEFT_MARGIN);
	tgtTextControl.setRightMargin(Constants.SEGMENT_RIGHT_MARGIN);
	tgtTextControl.setTopMargin(Constants.SEGMENT_TOP_MARGIN);
	tgtTextControl.setBottomMargin(Constants.SEGMENT_TOP_MARGIN);
	tgtTextControl.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));

	net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(srcSegmentViewer);
	net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(tgtSegmentViewer);

	TmMatchEditorBodyMenu srcMenu = new TmMatchEditorBodyMenu(srcSegmentViewer);
	srcSegmentViewer.getTextWidget().setMenu(srcMenu.getBodyMenu());

	TmMatchEditorBodyMenu tgtMenu = new TmMatchEditorBodyMenu(tgtSegmentViewer);
	tgtSegmentViewer.getTextWidget().setMenu(tgtMenu.getBodyMenu());

	loadData();

	return container;
}
 
Example 20
Source File: TmfRawEventViewer.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create the text area and add listeners
 */
private void createTextArea(int style) {
    fScrolledComposite = new ScrolledComposite(this, style);
    fScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    fTextArea = new Composite(fScrolledComposite, SWT.NONE);
    fTextArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    fScrolledComposite.setContent(fTextArea);
    fScrolledComposite.setExpandHorizontal(true);
    fScrolledComposite.setExpandVertical(true);
    fScrolledComposite.setAlwaysShowScrollBars(true);
    fScrolledComposite.setMinSize(fTextArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    fScrolledComposite.addControlListener(this);

    GridLayout textAreaGridLayout = new GridLayout();
    textAreaGridLayout.marginHeight = 0;
    textAreaGridLayout.marginWidth = 0;
    fTextArea.setLayout(textAreaGridLayout);

    fStyledText = new StyledText(fTextArea, SWT.READ_ONLY);
    fStyledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    initializeFonts();
    initializeColors();
    PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(this);

    fStyledText.addCaretListener(this);
    fStyledText.addMouseMoveListener(this);
    fStyledText.addMouseTrackListener(this);
    fStyledText.addMouseWheelListener(this);
    /* disable mouse scroll of horizontal scroll bar */
    fStyledText.addListener(SWT.MouseWheel, event -> event.doit = false);
    fStyledText.addKeyListener(this);

    fTextArea.setBackground(fStyledText.getBackground());
    fTextArea.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            fTextArea.setFocus();
        }
    });
}