X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Ftooltip%2FEditableTextTooltipProvider2.java;fp=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Ftooltip%2FEditableTextTooltipProvider2.java;h=d81f0085568a3378bdeb1ffe544c2a51977a7fa0;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=3b68fac08c396dde588f0353c048411cb94af739;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/EditableTextTooltipProvider2.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/EditableTextTooltipProvider2.java index 3b68fac08..d81f00855 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/EditableTextTooltipProvider2.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/EditableTextTooltipProvider2.java @@ -1,114 +1,114 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g2d.tooltip; - - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.simantics.g2d.element.IElement; - -public abstract class EditableTextTooltipProvider2 implements FocusableTooltipProvider { - - private Shell shell; - private Text text; - - @Override - public void showTooltip(final IElement element, final int x, final int y) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - if (shell != null) { - shell.dispose(); - shell = null; - } - shell = new Shell(Display.getCurrent().getActiveShell(),SWT.NO_TRIM); - shell.setLayout(new FillLayout()); - Composite composite = new Composite(shell, SWT.BORDER); - composite.setLayout(new FillLayout(SWT.VERTICAL)); - Label label = new Label(composite,SWT.NONE); - label.setText("Press 'F9' to focus"); - text = new Text(composite, SWT.SINGLE); - text.setText(getTooltipText(element)); - text.addKeyListener(new KeyAdapter() { - @Override - public void keyReleased(KeyEvent e) { - if (e.keyCode == SWT.CR) { - setText(element, text.getText()); - shell.dispose(); - shell = null; - } - } - }); - shell.pack(); - shell.setVisible(true); - shell.setLocation(x, y-32); - - } - }); - - } - - @Override - public void hideTooltip(IElement element) { - if (shell == null) - return; - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - shell.dispose(); - shell = null; - - } - }); - } - - public void focus() { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - if (!shell.isDisposed()) - shell.forceFocus(); - } - }); - } - boolean has_focus = false; - - @Override - public boolean hasFocus() { - - Display.getDefault().syncExec(new Runnable() { - - @Override - public void run() { - if(shell != null && !shell.isDisposed()) - has_focus = shell.isFocusControl() || text.isFocusControl(); - - else - has_focus = false; - - } - }); - return has_focus; - } - - public abstract String getTooltipText(IElement element); - - public abstract void setText(IElement element, String text); - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g2d.tooltip; + + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.simantics.g2d.element.IElement; + +public abstract class EditableTextTooltipProvider2 implements FocusableTooltipProvider { + + private Shell shell; + private Text text; + + @Override + public void showTooltip(final IElement element, final int x, final int y) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + if (shell != null) { + shell.dispose(); + shell = null; + } + shell = new Shell(Display.getCurrent().getActiveShell(),SWT.NO_TRIM); + shell.setLayout(new FillLayout()); + Composite composite = new Composite(shell, SWT.BORDER); + composite.setLayout(new FillLayout(SWT.VERTICAL)); + Label label = new Label(composite,SWT.NONE); + label.setText("Press 'F9' to focus"); + text = new Text(composite, SWT.SINGLE); + text.setText(getTooltipText(element)); + text.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + if (e.keyCode == SWT.CR) { + setText(element, text.getText()); + shell.dispose(); + shell = null; + } + } + }); + shell.pack(); + shell.setVisible(true); + shell.setLocation(x, y-32); + + } + }); + + } + + @Override + public void hideTooltip(IElement element) { + if (shell == null) + return; + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + shell.dispose(); + shell = null; + + } + }); + } + + public void focus() { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + if (!shell.isDisposed()) + shell.forceFocus(); + } + }); + } + boolean has_focus = false; + + @Override + public boolean hasFocus() { + + Display.getDefault().syncExec(new Runnable() { + + @Override + public void run() { + if(shell != null && !shell.isDisposed()) + has_focus = shell.isFocusControl() || text.isFocusControl(); + + else + has_focus = false; + + } + }); + return has_focus; + } + + public abstract String getTooltipText(IElement element); + + public abstract void setText(IElement element, String text); + +}