mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Bug 559474: Format all TM.terminal code to CDT standard
This is applying the per-project code formatting rules that would be applied on save in the JDT editor See also Bug 540373 Change-Id: Id04c972c3b3cb0a6ed1ab8581185359b7cf43f91
This commit is contained in:
parent
213770265a
commit
c58c28b9cc
243 changed files with 8230 additions and 7835 deletions
|
@ -114,7 +114,8 @@ public class Activator extends AbstractUIPlugin {
|
|||
if (exception instanceof CoreException) {
|
||||
log(((CoreException) exception).getStatus());
|
||||
} else {
|
||||
log(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), exception.getLocalizedMessage(), exception));
|
||||
log(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), exception.getLocalizedMessage(),
|
||||
exception));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -246,13 +246,10 @@ public class SerialSettingsPage extends AbstractSettingsPage {
|
|||
settings.setStopBits(StopBits.fromStringIndex(stopBitsCombo.getSelectionIndex()));
|
||||
|
||||
dialogSettings.put(SerialSettings.PORT_NAME_ATTR, portCombo.getText());
|
||||
dialogSettings.put(SerialSettings.BAUD_RATE_ATTR,
|
||||
BaudRate.getStrings()[baudRateCombo.getSelectionIndex()]);
|
||||
dialogSettings.put(SerialSettings.BYTE_SIZE_ATTR,
|
||||
ByteSize.getStrings()[byteSizeCombo.getSelectionIndex()]);
|
||||
dialogSettings.put(SerialSettings.BAUD_RATE_ATTR, BaudRate.getStrings()[baudRateCombo.getSelectionIndex()]);
|
||||
dialogSettings.put(SerialSettings.BYTE_SIZE_ATTR, ByteSize.getStrings()[byteSizeCombo.getSelectionIndex()]);
|
||||
dialogSettings.put(SerialSettings.PARITY_ATTR, Parity.getStrings()[parityCombo.getSelectionIndex()]);
|
||||
dialogSettings.put(SerialSettings.STOP_BITS_ATTR,
|
||||
StopBits.getStrings()[stopBitsCombo.getSelectionIndex()]);
|
||||
dialogSettings.put(SerialSettings.STOP_BITS_ATTR, StopBits.getStrings()[stopBitsCombo.getSelectionIndex()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -66,7 +66,8 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration
|
|||
setEncoding("UTF-8"); //$NON-NLS-1$
|
||||
} else {
|
||||
String encoding = WorkbenchEncoding.getWorkbenchDefaultEncoding();
|
||||
if (encoding != null && !"".equals(encoding)) setEncoding(encoding); //$NON-NLS-1$
|
||||
if (encoding != null && !"".equals(encoding)) //$NON-NLS-1$
|
||||
setEncoding(encoding);
|
||||
}
|
||||
|
||||
// Fill the rest of the panel with a label to be able to
|
||||
|
@ -90,10 +91,12 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration
|
|||
*/
|
||||
@Override
|
||||
public void setupData(Map<String, Object> data) {
|
||||
if (data == null) return;
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
String value = (String)data.get(ITerminalsConnectorConstants.PROP_ENCODING);
|
||||
if (value != null) setEncoding(value);
|
||||
String value = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING);
|
||||
if (value != null)
|
||||
setEncoding(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -102,7 +105,8 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration
|
|||
@Override
|
||||
public void extractData(Map<String, Object> data) {
|
||||
// set the terminal connector id for local terminal
|
||||
data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.terminal.connector.local.LocalConnector"); //$NON-NLS-1$
|
||||
data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID,
|
||||
"org.eclipse.tm.terminal.connector.local.LocalConnector"); //$NON-NLS-1$
|
||||
|
||||
// Store the encoding
|
||||
data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
|
||||
|
@ -110,8 +114,8 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration
|
|||
Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
|
||||
if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) {
|
||||
// if we have a IResource selection use the location for working directory
|
||||
if (resource instanceof org.eclipse.core.resources.IResource){
|
||||
String dir = ((org.eclipse.core.resources.IResource)resource).getProject().getLocation().toString();
|
||||
if (resource instanceof org.eclipse.core.resources.IResource) {
|
||||
String dir = ((org.eclipse.core.resources.IResource) resource).getProject().getLocation().toString();
|
||||
data.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, dir);
|
||||
}
|
||||
}
|
||||
|
@ -121,21 +125,21 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration
|
|||
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected void fillSettingsForHost(String host){
|
||||
protected void fillSettingsForHost(String host) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean)
|
||||
*/
|
||||
@Override
|
||||
protected void saveSettingsForHost(boolean add){
|
||||
protected void saveSettingsForHost(boolean add) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid()
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(){
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -184,11 +188,12 @@ public class LocalWizardConfigurationPanel extends AbstractExtendedConfiguration
|
|||
|
||||
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
|
||||
Object element = ((IStructuredSelection) selection).getFirstElement();
|
||||
if (element instanceof org.eclipse.core.resources.IResource){
|
||||
return ((org.eclipse.core.resources.IResource)element);
|
||||
if (element instanceof org.eclipse.core.resources.IResource) {
|
||||
return ((org.eclipse.core.resources.IResource) element);
|
||||
}
|
||||
if (element instanceof IAdaptable) {
|
||||
return (org.eclipse.core.resources.IResource) ((IAdaptable) element).getAdapter(org.eclipse.core.resources.IResource.class);
|
||||
return (org.eclipse.core.resources.IResource) ((IAdaptable) element)
|
||||
.getAdapter(org.eclipse.core.resources.IResource.class);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -104,7 +104,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
} else {
|
||||
encoding = WorkbenchEncoding.getWorkbenchDefaultEncoding();
|
||||
}
|
||||
if (encoding != null && !"".equals(encoding)) properties.put(ITerminalsConnectorConstants.PROP_ENCODING, encoding); //$NON-NLS-1$
|
||||
if (encoding != null && !"".equals(encoding)) //$NON-NLS-1$
|
||||
properties.put(ITerminalsConnectorConstants.PROP_ENCODING, encoding);
|
||||
}
|
||||
|
||||
// For local terminals, force a new terminal tab each time it is launched,
|
||||
|
@ -115,9 +116,11 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
|
||||
// Initialize the local terminal working directory.
|
||||
// By default, start the local terminal in the users home directory
|
||||
String initialCwd = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD);
|
||||
String initialCwd = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences()
|
||||
.getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_INITIAL_CWD);
|
||||
String cwd = null;
|
||||
if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd) || "".equals(initialCwd.trim())) { //$NON-NLS-1$
|
||||
if (initialCwd == null || IPreferenceKeys.PREF_INITIAL_CWD_USER_HOME.equals(initialCwd)
|
||||
|| "".equals(initialCwd.trim())) { //$NON-NLS-1$
|
||||
cwd = System.getProperty("user.home"); //$NON-NLS-1$
|
||||
} else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_HOME.equals(initialCwd)) {
|
||||
String eclipseHomeLocation = System.getProperty("eclipse.home.location"); //$NON-NLS-1$
|
||||
|
@ -126,7 +129,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
URI uri = URIUtil.fromString(eclipseHomeLocation);
|
||||
File f = URIUtil.toFile(uri);
|
||||
cwd = f.getAbsolutePath();
|
||||
} catch (URISyntaxException ex) { /* ignored on purpose */ }
|
||||
} catch (URISyntaxException ex) {
|
||||
/* ignored on purpose */ }
|
||||
}
|
||||
} else if (IPreferenceKeys.PREF_INITIAL_CWD_ECLIPSE_WS.equals(initialCwd)) {
|
||||
Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
|
||||
|
@ -134,7 +138,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null
|
||||
&& org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null
|
||||
&& org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() != null) {
|
||||
cwd = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
|
||||
cwd = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation()
|
||||
.toOSString();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -161,28 +166,39 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
// If the current selection resolved to an folder, default the working directory
|
||||
// to that folder and update the terminal title
|
||||
ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
|
||||
if ((service != null && service.getSelection() != null) || properties.containsKey(ITerminalsConnectorConstants.PROP_SELECTION)) {
|
||||
ISelection selection = (ISelection)properties.get(ITerminalsConnectorConstants.PROP_SELECTION);
|
||||
if (selection == null) selection = service.getSelection();
|
||||
if ((service != null && service.getSelection() != null)
|
||||
|| properties.containsKey(ITerminalsConnectorConstants.PROP_SELECTION)) {
|
||||
ISelection selection = (ISelection) properties.get(ITerminalsConnectorConstants.PROP_SELECTION);
|
||||
if (selection == null)
|
||||
selection = service.getSelection();
|
||||
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
|
||||
String dir = null;
|
||||
Iterator<?> iter = ((IStructuredSelection)selection).iterator();
|
||||
Iterator<?> iter = ((IStructuredSelection) selection).iterator();
|
||||
while (iter.hasNext()) {
|
||||
Object element = iter.next();
|
||||
|
||||
Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
|
||||
if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) {
|
||||
if (bundle != null && bundle.getState() != Bundle.UNINSTALLED
|
||||
&& bundle.getState() != Bundle.STOPPING) {
|
||||
// If the element is not an IResource, try to adapt to IResource
|
||||
if (!(element instanceof org.eclipse.core.resources.IResource)) {
|
||||
Object adapted = element instanceof IAdaptable ? ((IAdaptable)element).getAdapter(org.eclipse.core.resources.IResource.class) : null;
|
||||
if (adapted == null) adapted = Platform.getAdapterManager().getAdapter(element, org.eclipse.core.resources.IResource.class);
|
||||
if (adapted != null) element = adapted;
|
||||
Object adapted = element instanceof IAdaptable
|
||||
? ((IAdaptable) element).getAdapter(org.eclipse.core.resources.IResource.class)
|
||||
: null;
|
||||
if (adapted == null)
|
||||
adapted = Platform.getAdapterManager().getAdapter(element,
|
||||
org.eclipse.core.resources.IResource.class);
|
||||
if (adapted != null)
|
||||
element = adapted;
|
||||
}
|
||||
|
||||
if (element instanceof org.eclipse.core.resources.IResource && ((org.eclipse.core.resources.IResource)element).exists()) {
|
||||
IPath location = ((org.eclipse.core.resources.IResource)element).getLocation();
|
||||
if (location == null) continue;
|
||||
if (location.toFile().isFile()) location = location.removeLastSegments(1);
|
||||
if (element instanceof org.eclipse.core.resources.IResource
|
||||
&& ((org.eclipse.core.resources.IResource) element).exists()) {
|
||||
IPath location = ((org.eclipse.core.resources.IResource) element).getLocation();
|
||||
if (location == null)
|
||||
continue;
|
||||
if (location.toFile().isFile())
|
||||
location = location.removeLastSegments(1);
|
||||
if (location.toFile().isDirectory() && location.toFile().canRead()) {
|
||||
dir = location.toFile().getAbsolutePath();
|
||||
break;
|
||||
|
@ -190,7 +206,7 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
}
|
||||
|
||||
if (element instanceof IPath || element instanceof File) {
|
||||
File f = element instanceof IPath ? ((IPath)element).toFile() : (File)element;
|
||||
File f = element instanceof IPath ? ((IPath) element).toFile() : (File) element;
|
||||
if (f.isDirectory() && f.canRead()) {
|
||||
dir = f.getAbsolutePath();
|
||||
break;
|
||||
|
@ -225,14 +241,16 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
private String getTerminalTitle(Map<String, Object> properties) {
|
||||
// Try to see if the user set a title explicitly via the properties map.
|
||||
String title = getDefaultTerminalTitle(properties);
|
||||
if (title != null) return title;
|
||||
if (title != null)
|
||||
return title;
|
||||
|
||||
try {
|
||||
String hostname = InetAddress.getLocalHost().getHostName();
|
||||
if (hostname != null && !"".equals(hostname.trim())) { //$NON-NLS-1$
|
||||
return hostname;
|
||||
}
|
||||
} catch (UnknownHostException e) { /* ignored on purpose */ }
|
||||
} catch (UnknownHostException e) {
|
||||
/* ignored on purpose */ }
|
||||
|
||||
return "Local"; //$NON-NLS-1$
|
||||
}
|
||||
|
@ -264,7 +282,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
}
|
||||
}
|
||||
if (shell == null) {
|
||||
shell = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX);
|
||||
shell = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences()
|
||||
.getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX);
|
||||
if (shell == null || "".equals(shell)) { //$NON-NLS-1$
|
||||
if (System.getenv("SHELL") != null && !"".equals(System.getenv("SHELL").trim())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
shell = System.getenv("SHELL").trim(); //$NON-NLS-1$
|
||||
|
@ -285,8 +304,9 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
Assert.isNotNull(properties);
|
||||
|
||||
// Check for the terminal connector id
|
||||
String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
|
||||
if (connectorId == null) connectorId = "org.eclipse.tm.terminal.connector.local.LocalConnector"; //$NON-NLS-1$
|
||||
String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
|
||||
if (connectorId == null)
|
||||
connectorId = "org.eclipse.tm.terminal.connector.local.LocalConnector"; //$NON-NLS-1$
|
||||
|
||||
// Extract the process properties using defaults
|
||||
String image;
|
||||
|
@ -295,16 +315,18 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
File defaultShell = defaultShell();
|
||||
image = defaultShell.isAbsolute() ? defaultShell.getAbsolutePath() : defaultShell.getPath();
|
||||
} else {
|
||||
image = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH);
|
||||
image = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH);
|
||||
}
|
||||
|
||||
String arguments = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS);
|
||||
String arguments = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS);
|
||||
if (arguments == null && !Platform.OS_WIN32.equals(Platform.getOS())) {
|
||||
arguments = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences().getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS);
|
||||
arguments = org.eclipse.tm.terminal.view.ui.activator.UIPlugin.getScopedPreferences()
|
||||
.getString(IPreferenceKeys.PREF_LOCAL_TERMINAL_DEFAULT_SHELL_UNIX_ARGS);
|
||||
}
|
||||
|
||||
// Determine if a PTY will be used
|
||||
boolean isUsingPTY = (properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ) == null && PTY.isSupported(PTY.Mode.TERMINAL))
|
||||
boolean isUsingPTY = (properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ) == null
|
||||
&& PTY.isSupported(PTY.Mode.TERMINAL))
|
||||
|| properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ) instanceof PTY;
|
||||
|
||||
boolean localEcho = false;
|
||||
|
@ -315,7 +337,7 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
localEcho = !isUsingPTY;
|
||||
}
|
||||
} else {
|
||||
localEcho = ((Boolean)properties.get(ITerminalsConnectorConstants.PROP_LOCAL_ECHO)).booleanValue();
|
||||
localEcho = ((Boolean) properties.get(ITerminalsConnectorConstants.PROP_LOCAL_ECHO)).booleanValue();
|
||||
}
|
||||
|
||||
String lineSeparator = null;
|
||||
|
@ -323,28 +345,32 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
|| !(properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR) instanceof String)) {
|
||||
// No line separator will be set if a PTY is used
|
||||
if (!isUsingPTY) {
|
||||
lineSeparator = Platform.OS_WIN32.equals(Platform.getOS()) ? ILineSeparatorConstants.LINE_SEPARATOR_CRLF : ILineSeparatorConstants.LINE_SEPARATOR_LF;
|
||||
lineSeparator = Platform.OS_WIN32.equals(Platform.getOS()) ? ILineSeparatorConstants.LINE_SEPARATOR_CRLF
|
||||
: ILineSeparatorConstants.LINE_SEPARATOR_LF;
|
||||
}
|
||||
} else {
|
||||
lineSeparator = (String)properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR);
|
||||
lineSeparator = (String) properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR);
|
||||
}
|
||||
|
||||
Process process = (Process)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ);
|
||||
PTY pty = (PTY)properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ);
|
||||
ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS);
|
||||
ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS);
|
||||
String workingDir = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR);
|
||||
Process process = (Process) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ);
|
||||
PTY pty = (PTY) properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ);
|
||||
ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[]) properties
|
||||
.get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS);
|
||||
ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[]) properties
|
||||
.get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS);
|
||||
String workingDir = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR);
|
||||
|
||||
String[] envp = null;
|
||||
if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) &&
|
||||
properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) != null &&
|
||||
properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) instanceof String[]){
|
||||
envp = (String[])properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT);
|
||||
if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT)
|
||||
&& properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) != null
|
||||
&& properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) instanceof String[]) {
|
||||
envp = (String[]) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT);
|
||||
}
|
||||
|
||||
// Set the ECLIPSE_HOME and ECLIPSE_WORKSPACE environment variables
|
||||
List<String> envpList = new ArrayList<String>();
|
||||
if (envp != null) envpList.addAll(Arrays.asList(envp));
|
||||
if (envp != null)
|
||||
envpList.addAll(Arrays.asList(envp));
|
||||
|
||||
// ECLIPSE_HOME
|
||||
String eclipseHomeLocation = System.getProperty("eclipse.home.location"); //$NON-NLS-1$
|
||||
|
@ -353,7 +379,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
URI uri = URIUtil.fromString(eclipseHomeLocation);
|
||||
File f = URIUtil.toFile(uri);
|
||||
envpList.add("ECLIPSE_HOME=" + f.getAbsolutePath()); //$NON-NLS-1$
|
||||
} catch (URISyntaxException e) { /* ignored on purpose */ }
|
||||
} catch (URISyntaxException e) {
|
||||
/* ignored on purpose */ }
|
||||
}
|
||||
|
||||
// ECLIPSE_WORKSPACE
|
||||
|
@ -362,7 +389,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null
|
||||
&& org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null
|
||||
&& org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() != null) {
|
||||
envpList.add("ECLIPSE_WORKSPACE=" + org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); //$NON-NLS-1$
|
||||
envpList.add("ECLIPSE_WORKSPACE=" + org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() //$NON-NLS-1$
|
||||
.getLocation().toOSString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,7 +417,8 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
|
|||
|
||||
if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT)) {
|
||||
Object value = properties.get(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT);
|
||||
processSettings.setMergeWithNativeEnvironment(value instanceof Boolean ? ((Boolean)value).booleanValue() : false);
|
||||
processSettings
|
||||
.setMergeWithNativeEnvironment(value instanceof Boolean ? ((Boolean) value).booleanValue() : false);
|
||||
}
|
||||
|
||||
// And save the settings to the store
|
||||
|
|
|
@ -46,10 +46,12 @@ public class LocalLauncherHandler extends AbstractHandler {
|
|||
if (!(selection instanceof IStructuredSelection)) {
|
||||
IEditorInput input = HandlerUtil.getActiveEditorInput(event);
|
||||
if (input instanceof IPathEditorInput) {
|
||||
IPath path = ((IPathEditorInput)input).getPath();
|
||||
IPath path = ((IPathEditorInput) input).getPath();
|
||||
if (path != null) {
|
||||
if (path.toFile().isFile()) path = path.removeLastSegments(1);
|
||||
if (path.toFile().isDirectory() && path.toFile().canRead()) selection = new StructuredSelection(path);
|
||||
if (path.toFile().isFile())
|
||||
path = path.removeLastSegments(1);
|
||||
if (path.toFile().isDirectory() && path.toFile().canRead())
|
||||
selection = new StructuredSelection(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ public class ProcessConnector extends AbstractStreamsConnector {
|
|||
pty = new PTY(PTY.Mode.TERMINAL);
|
||||
|
||||
// Initialize the terminal size
|
||||
VT100Emulator text = ((VT100TerminalControl)control).getTerminalText();
|
||||
VT100Emulator text = ((VT100TerminalControl) control).getTerminalText();
|
||||
text.fontChanged();
|
||||
} catch (IOException e) {
|
||||
// PTY not supported
|
||||
|
@ -129,13 +129,13 @@ public class ProcessConnector extends AbstractStreamsConnector {
|
|||
command.append(arguments.trim());
|
||||
}
|
||||
|
||||
File workingDir =null;
|
||||
if (settings.getWorkingDir()!=null){
|
||||
File workingDir = null;
|
||||
if (settings.getWorkingDir() != null) {
|
||||
workingDir = new File(settings.getWorkingDir());
|
||||
}
|
||||
|
||||
String[] envp = null;
|
||||
if (settings.getEnvironment()!=null){
|
||||
if (settings.getEnvironment() != null) {
|
||||
envp = settings.getEnvironment();
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,8 @@ public class ProcessConnector extends AbstractStreamsConnector {
|
|||
}
|
||||
|
||||
// Execute the process
|
||||
process = ProcessFactory.getFactory().exec(argv.toArray(new String[argv.size()]), envp, workingDir, pty);
|
||||
process = ProcessFactory.getFactory().exec(argv.toArray(new String[argv.size()]), envp, workingDir,
|
||||
pty);
|
||||
} else {
|
||||
// No PTY -> just execute via the standard Java Runtime implementation.
|
||||
process = Runtime.getRuntime().exec(command.toString(), envp, workingDir);
|
||||
|
@ -177,11 +178,9 @@ public class ProcessConnector extends AbstractStreamsConnector {
|
|||
lineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
if ("\r".equals(lineSeparator)) { //$NON-NLS-1$
|
||||
lineSeparator = ILineSeparatorConstants.LINE_SEPARATOR_CR;
|
||||
}
|
||||
else if ("\n".equals(lineSeparator)) { //$NON-NLS-1$
|
||||
} else if ("\n".equals(lineSeparator)) { //$NON-NLS-1$
|
||||
lineSeparator = ILineSeparatorConstants.LINE_SEPARATOR_LF;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lineSeparator = ILineSeparatorConstants.LINE_SEPARATOR_CRLF;
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +195,8 @@ public class ProcessConnector extends AbstractStreamsConnector {
|
|||
control.setVT100LineWrapping(true);
|
||||
|
||||
// connect the streams
|
||||
connectStreams(control, process.getOutputStream(), process.getInputStream(), (pty == null ? process.getErrorStream() : null), settings.isLocalEcho(), lineSeparator);
|
||||
connectStreams(control, process.getOutputStream(), process.getInputStream(),
|
||||
(pty == null ? process.getErrorStream() : null), settings.isLocalEcho(), lineSeparator);
|
||||
|
||||
// Set the terminal control state to CONNECTED
|
||||
control.setState(TerminalState.CONNECTED);
|
||||
|
@ -209,7 +209,8 @@ public class ProcessConnector extends AbstractStreamsConnector {
|
|||
disconnect();
|
||||
// Lookup the tab item
|
||||
CTabItem item = ConsoleManager.getInstance().findConsole(control);
|
||||
if (item != null) item.dispose();
|
||||
if (item != null)
|
||||
item.dispose();
|
||||
// Get the error message from the exception
|
||||
String msg = e.getLocalizedMessage() != null ? e.getLocalizedMessage() : ""; //$NON-NLS-1$
|
||||
Assert.isNotNull(msg);
|
||||
|
@ -252,7 +253,10 @@ public class ProcessConnector extends AbstractStreamsConnector {
|
|||
|
||||
if (!isWindows) {
|
||||
// Destroy the process first, except on windows (Bug 465674)
|
||||
if (process != null) { process.destroy(); process = null; }
|
||||
if (process != null) {
|
||||
process.destroy();
|
||||
process = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Dispose the streams
|
||||
|
@ -260,7 +264,10 @@ public class ProcessConnector extends AbstractStreamsConnector {
|
|||
|
||||
if (isWindows) {
|
||||
// On Windows destroy the process after closing streams
|
||||
if (process != null) { process.destroy(); process = null; }
|
||||
if (process != null) {
|
||||
process.destroy();
|
||||
process = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the terminal control state to CLOSED.
|
||||
|
|
|
@ -72,26 +72,29 @@ public class ProcessLauncherDelegate extends AbstractLauncherDelegate {
|
|||
Assert.isNotNull(properties);
|
||||
|
||||
// Check for the terminal connector id
|
||||
String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
|
||||
if (connectorId == null) connectorId = "org.eclipse.tm.terminal.connector.process.ProcessConnector"; //$NON-NLS-1$
|
||||
String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
|
||||
if (connectorId == null)
|
||||
connectorId = "org.eclipse.tm.terminal.connector.process.ProcessConnector"; //$NON-NLS-1$
|
||||
|
||||
// Extract the process properties
|
||||
String image = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH);
|
||||
String arguments = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS);
|
||||
Process process = (Process)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ);
|
||||
PTY pty = (PTY)properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ);
|
||||
String image = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH);
|
||||
String arguments = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS);
|
||||
Process process = (Process) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ);
|
||||
PTY pty = (PTY) properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ);
|
||||
Object value = properties.get(ITerminalsConnectorConstants.PROP_LOCAL_ECHO);
|
||||
boolean localEcho = value instanceof Boolean ? ((Boolean)value).booleanValue() : false;
|
||||
String lineSeparator = (String)properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR);
|
||||
ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS);
|
||||
ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS);
|
||||
String workingDir = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR);
|
||||
boolean localEcho = value instanceof Boolean ? ((Boolean) value).booleanValue() : false;
|
||||
String lineSeparator = (String) properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR);
|
||||
ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[]) properties
|
||||
.get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS);
|
||||
ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[]) properties
|
||||
.get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS);
|
||||
String workingDir = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR);
|
||||
|
||||
String[] envp = null;
|
||||
if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) &&
|
||||
properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) != null &&
|
||||
properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) instanceof String[]){
|
||||
envp = (String[])properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT);
|
||||
if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT)
|
||||
&& properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) != null
|
||||
&& properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) instanceof String[]) {
|
||||
envp = (String[]) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT);
|
||||
}
|
||||
|
||||
Assert.isTrue(image != null || process != null);
|
||||
|
@ -114,7 +117,8 @@ public class ProcessLauncherDelegate extends AbstractLauncherDelegate {
|
|||
|
||||
if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT)) {
|
||||
value = properties.get(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT);
|
||||
processSettings.setMergeWithNativeEnvironment(value instanceof Boolean ? ((Boolean)value).booleanValue() : false);
|
||||
processSettings
|
||||
.setMergeWithNativeEnvironment(value instanceof Boolean ? ((Boolean) value).booleanValue() : false);
|
||||
}
|
||||
|
||||
// And save the settings to the store
|
||||
|
|
|
@ -13,7 +13,6 @@ package org.eclipse.tm.terminal.connector.process;
|
|||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* Process monitor implementation.
|
||||
*/
|
||||
|
@ -27,7 +26,6 @@ public class ProcessMonitor {
|
|||
// Flag to mark the monitor disposed
|
||||
private boolean disposed;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -50,7 +48,8 @@ public class ProcessMonitor {
|
|||
// Set the disposed status
|
||||
disposed = true;
|
||||
// Not initialized -> return immediately
|
||||
if (thread == null) return;
|
||||
if (thread == null)
|
||||
return;
|
||||
|
||||
// Copy the reference
|
||||
final Thread oldThread = thread;
|
||||
|
@ -65,7 +64,8 @@ public class ProcessMonitor {
|
|||
*/
|
||||
public void startMonitoring() {
|
||||
// If already initialized -> return immediately
|
||||
if (thread != null) return;
|
||||
if (thread != null)
|
||||
return;
|
||||
|
||||
// Create a new runnable which is constantly reading from the stream
|
||||
Runnable runnable = new Runnable() {
|
||||
|
@ -91,7 +91,8 @@ public class ProcessMonitor {
|
|||
*/
|
||||
public void monitorProcess() {
|
||||
// If already disposed -> return immediately
|
||||
if (disposed) return;
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
try {
|
||||
// Wait for the monitored process to terminate
|
||||
|
|
|
@ -113,7 +113,8 @@ public class ProcessSettings {
|
|||
public void setPTY(PTY pty) {
|
||||
this.pty = pty;
|
||||
// If the PTY is set to "null", the local echo will be set to "true"
|
||||
if (pty == null) setLocalEcho(true);
|
||||
if (pty == null)
|
||||
setLocalEcho(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -265,15 +266,18 @@ public class ProcessSettings {
|
|||
image = store.get("Path", null);//$NON-NLS-1$
|
||||
arguments = store.get("Arguments", null); //$NON-NLS-1$
|
||||
localEcho = Boolean.parseBoolean(store.get("LocalEcho", Boolean.FALSE.toString())); //$NON-NLS-1$
|
||||
mergeWithNativeEnvironment = Boolean.parseBoolean(store.get("MergeWithNativeEnvironment", Boolean.FALSE.toString())); //$NON-NLS-1$
|
||||
mergeWithNativeEnvironment = Boolean
|
||||
.parseBoolean(store.get("MergeWithNativeEnvironment", Boolean.FALSE.toString())); //$NON-NLS-1$
|
||||
lineSeparator = store.get("LineSeparator", null); //$NON-NLS-1$
|
||||
workingDir = store.get("WorkingDir", null); //$NON-NLS-1$
|
||||
if (store instanceof SettingsStore) {
|
||||
process = (Process)((SettingsStore)store).getSettings().get("Process"); //$NON-NLS-1$
|
||||
pty = (PTY)((SettingsStore)store).getSettings().get("PTY"); //$NON-NLS-1$
|
||||
stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[])((SettingsStore)store).getSettings().get("StdOutListeners"); //$NON-NLS-1$
|
||||
stderrListeners = (ITerminalServiceOutputStreamMonitorListener[])((SettingsStore)store).getSettings().get("StdErrListeners"); //$NON-NLS-1$
|
||||
environment = (String[])((SettingsStore)store).getSettings().get("Environment"); //$NON-NLS-1$
|
||||
process = (Process) ((SettingsStore) store).getSettings().get("Process"); //$NON-NLS-1$
|
||||
pty = (PTY) ((SettingsStore) store).getSettings().get("PTY"); //$NON-NLS-1$
|
||||
stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[]) ((SettingsStore) store).getSettings()
|
||||
.get("StdOutListeners"); //$NON-NLS-1$
|
||||
stderrListeners = (ITerminalServiceOutputStreamMonitorListener[]) ((SettingsStore) store).getSettings()
|
||||
.get("StdErrListeners"); //$NON-NLS-1$
|
||||
environment = (String[]) ((SettingsStore) store).getSettings().get("Environment"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,11 +295,11 @@ public class ProcessSettings {
|
|||
store.put("LineSeparator", lineSeparator); //$NON-NLS-1$
|
||||
store.put("WorkingDir", workingDir); //$NON-NLS-1$
|
||||
if (store instanceof SettingsStore) {
|
||||
((SettingsStore)store).getSettings().put("Process", process); //$NON-NLS-1$
|
||||
((SettingsStore)store).getSettings().put("PTY", pty); //$NON-NLS-1$
|
||||
((SettingsStore)store).getSettings().put("StdOutListeners", stdoutListeners); //$NON-NLS-1$
|
||||
((SettingsStore)store).getSettings().put("StdErrListeners", stderrListeners); //$NON-NLS-1$
|
||||
((SettingsStore)store).getSettings().put("Environment", environment); //$NON-NLS-1$
|
||||
((SettingsStore) store).getSettings().put("Process", process); //$NON-NLS-1$
|
||||
((SettingsStore) store).getSettings().put("PTY", pty); //$NON-NLS-1$
|
||||
((SettingsStore) store).getSettings().put("StdOutListeners", stdoutListeners); //$NON-NLS-1$
|
||||
((SettingsStore) store).getSettings().put("StdErrListeners", stderrListeners); //$NON-NLS-1$
|
||||
((SettingsStore) store).getSettings().put("Environment", environment); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,8 @@ public class ProcessSettingsPage extends AbstractSettingsPage {
|
|||
// The entry fields shall be properly aligned
|
||||
Composite panel = new Composite(composite, SWT.NONE);
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
layout.marginWidth = 0; layout.marginHeight = 0;
|
||||
layout.marginWidth = 0;
|
||||
layout.marginHeight = 0;
|
||||
panel.setLayout(layout);
|
||||
panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
|
@ -80,7 +81,8 @@ public class ProcessSettingsPage extends AbstractSettingsPage {
|
|||
// Text field and browse button are aligned it their own panel
|
||||
Composite innerPanel = new Composite(panel, SWT.NONE);
|
||||
layout = new GridLayout(2, false);
|
||||
layout.marginWidth = 0; layout.marginHeight = 0;
|
||||
layout.marginWidth = 0;
|
||||
layout.marginHeight = 0;
|
||||
innerPanel.setLayout(layout);
|
||||
innerPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
|
@ -127,7 +129,8 @@ public class ProcessSettingsPage extends AbstractSettingsPage {
|
|||
*/
|
||||
protected void onBrowseButtonSelected(SelectionEvent e) {
|
||||
// Determine the shell
|
||||
Shell shell = e != null ? e.widget.getDisplay().getActiveShell() : PlatformUI.getWorkbench().getDisplay().getActiveShell();
|
||||
Shell shell = e != null ? e.widget.getDisplay().getActiveShell()
|
||||
: PlatformUI.getWorkbench().getDisplay().getActiveShell();
|
||||
|
||||
// create a standard file dialog
|
||||
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
|
||||
|
@ -141,7 +144,8 @@ public class ProcessSettingsPage extends AbstractSettingsPage {
|
|||
IPath filePath = new Path(selectedFile);
|
||||
// If the selected file points to an directory, use the directory as is
|
||||
IPath filterPath = filePath.toFile().isDirectory() ? filePath : filePath.removeLastSegments(1);
|
||||
String filterFileName = filePath.toFile().isDirectory() || !filePath.toFile().exists() ? null : filePath.lastSegment();
|
||||
String filterFileName = filePath.toFile().isDirectory() || !filePath.toFile().exists() ? null
|
||||
: filePath.lastSegment();
|
||||
|
||||
if (!filterPath.isEmpty()) {
|
||||
dialog.setFilterPath(filterPath.toString());
|
||||
|
@ -152,7 +156,8 @@ public class ProcessSettingsPage extends AbstractSettingsPage {
|
|||
} else {
|
||||
Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
|
||||
if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) {
|
||||
dialog.setFilterPath(org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
|
||||
dialog.setFilterPath(
|
||||
org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ package org.eclipse.tm.terminal.connector.process.help;
|
|||
|
||||
import org.eclipse.tm.terminal.connector.process.activator.UIPlugin;
|
||||
|
||||
|
||||
/**
|
||||
* Context help id definitions.
|
||||
*/
|
||||
|
|
|
@ -103,7 +103,8 @@ public class ArgumentParser {
|
|||
* string. Allows escaping.
|
||||
*/
|
||||
iterator.next(); // Skip quote
|
||||
quoted_reader: while ((iterator.current() != CharacterIterator.DONE) && (iterator.current() != '"')) {
|
||||
quoted_reader: while ((iterator.current() != CharacterIterator.DONE)
|
||||
&& (iterator.current() != '"')) {
|
||||
char innerChar = iterator.current();
|
||||
switch (innerChar) {
|
||||
case '\\':
|
||||
|
|
|
@ -79,15 +79,15 @@ public class RemoteConnectionManager extends Job {
|
|||
remoteConnection = connType.getConnection(connector.getRemoteSettings().getConnectionName());
|
||||
}
|
||||
if (remoteConnection == null) {
|
||||
return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(),
|
||||
NLS.bind(Messages.RemoteConnectionManager_0, connector.getRemoteSettings().getConnectionName()));
|
||||
return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), NLS
|
||||
.bind(Messages.RemoteConnectionManager_0, connector.getRemoteSettings().getConnectionName()));
|
||||
}
|
||||
|
||||
if (!remoteConnection.isOpen()) {
|
||||
remoteConnection.open(monitor);
|
||||
if (!remoteConnection.isOpen()) {
|
||||
return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(),
|
||||
NLS.bind(Messages.RemoteConnectionManager_1, connector.getRemoteSettings().getConnectionName()));
|
||||
return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), NLS.bind(
|
||||
Messages.RemoteConnectionManager_1, connector.getRemoteSettings().getConnectionName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,8 @@ public class RemoteConnectionManager extends Job {
|
|||
String terminalShellCommand = prefs.get(IRemoteTerminalConstants.PREF_TERMINAL_SHELL_COMMAND, ""); //$NON-NLS-1$
|
||||
if ("".equals(terminalShellCommand) //$NON-NLS-1$
|
||||
&& remoteConnection.hasService(IRemoteCommandShellService.class)) {
|
||||
IRemoteCommandShellService cmdShellSvc = remoteConnection.getService(IRemoteCommandShellService.class);
|
||||
IRemoteCommandShellService cmdShellSvc = remoteConnection
|
||||
.getService(IRemoteCommandShellService.class);
|
||||
synchronized (this) {
|
||||
remoteProcess = cmdShellSvc.getCommandShell(IRemoteProcessBuilder.ALLOCATE_PTY);
|
||||
}
|
||||
|
@ -117,7 +118,8 @@ public class RemoteConnectionManager extends Job {
|
|||
.getProcessBuilder(new ArgumentParser(terminalShellCommand).getTokenList());
|
||||
remoteProcess = processBuilder.start(IRemoteProcessBuilder.ALLOCATE_PTY);
|
||||
} else {
|
||||
return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), Messages.RemoteConnectionManager_2);
|
||||
return new Status(IStatus.ERROR, Activator.getUniqueIdentifier(),
|
||||
Messages.RemoteConnectionManager_2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@ public class RemoteSettingsPage extends AbstractSettingsPage {
|
|||
if (fTerminalSettings != null && fRemoteConnectionWidget != null && !fRemoteConnectionWidget.isDisposed()) {
|
||||
if (fRemoteConnectionWidget.getConnection() != null) {
|
||||
if (fRemoteConnectionWidget.getConnection().getConnectionType() != null) {
|
||||
fTerminalSettings.setConnectionTypeId(fRemoteConnectionWidget.getConnection().getConnectionType().getId());
|
||||
fTerminalSettings
|
||||
.setConnectionTypeId(fRemoteConnectionWidget.getConnection().getConnectionType().getId());
|
||||
}
|
||||
fTerminalSettings.setConnectionName(fRemoteConnectionWidget.getConnection().getName());
|
||||
}
|
||||
|
@ -50,7 +51,8 @@ public class RemoteSettingsPage extends AbstractSettingsPage {
|
|||
@Override
|
||||
public void loadSettings() {
|
||||
if (fTerminalSettings != null && fRemoteConnectionWidget != null && !fRemoteConnectionWidget.isDisposed()) {
|
||||
fRemoteConnectionWidget.setConnection(fTerminalSettings.getConnectionTypeId(), fTerminalSettings.getConnectionName());
|
||||
fRemoteConnectionWidget.setConnection(fTerminalSettings.getConnectionTypeId(),
|
||||
fTerminalSettings.getConnectionName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,8 @@ public class RemoteLauncherDelegate extends AbstractLauncherDelegate {
|
|||
private String getTerminalTitle(Map<String, Object> properties) {
|
||||
// Try to see if the user set a title explicitly via the properties map.
|
||||
String title = getDefaultTerminalTitle(properties);
|
||||
if (title != null) return title;
|
||||
if (title != null)
|
||||
return title;
|
||||
|
||||
String connection = (String) properties.get(IRemoteSettings.CONNECTION_NAME);
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ public class RemoteMementoHandler implements IMementoHandler {
|
|||
// Do not write the terminal title to the memento -> needs to
|
||||
// be recreated at the time of restoration.
|
||||
memento.putString(IRemoteSettings.CONNECTION_NAME, (String) properties.get(IRemoteSettings.CONNECTION_NAME));
|
||||
memento.putString(IRemoteSettings.CONNECTION_TYPE_ID, (String) properties.get(IRemoteSettings.CONNECTION_TYPE_ID));
|
||||
memento.putString(IRemoteSettings.CONNECTION_TYPE_ID,
|
||||
(String) properties.get(IRemoteSettings.CONNECTION_TYPE_ID));
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_ENCODING,
|
||||
(String) properties.get(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
}
|
||||
|
@ -55,6 +56,7 @@ public class RemoteMementoHandler implements IMementoHandler {
|
|||
// Restore the terminal properties from the memento
|
||||
properties.put(IRemoteSettings.CONNECTION_NAME, memento.getString(IRemoteSettings.CONNECTION_NAME));
|
||||
properties.put(IRemoteSettings.CONNECTION_TYPE_ID, memento.getString(IRemoteSettings.CONNECTION_TYPE_ID));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_ENCODING, memento.getString(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_ENCODING,
|
||||
memento.getString(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ public class UIPlugin extends AbstractUIPlugin {
|
|||
* IJschService service is available.
|
||||
*/
|
||||
public IJSchService getJSchService() {
|
||||
return (IJSchService)tracker.getService();
|
||||
return (IJSchService) tracker.getService();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.terminal.connector.ssh.connector;
|
||||
|
||||
|
||||
/**
|
||||
* Defines the constants used by the terminal.ssh Plugin
|
||||
*/
|
||||
|
|
|
@ -57,101 +57,102 @@ public class KeyboardInteractiveDialog extends TrayDialog {
|
|||
* @param prompt the titles for textfields
|
||||
* @param echo '*' should be used or not
|
||||
*/
|
||||
public KeyboardInteractiveDialog(Shell parentShell,
|
||||
String connectionId,
|
||||
String destination,
|
||||
String name,
|
||||
String instruction,
|
||||
String[] prompt,
|
||||
boolean[] echo){
|
||||
public KeyboardInteractiveDialog(Shell parentShell, String connectionId, String destination, String name,
|
||||
String instruction, String[] prompt, boolean[] echo) {
|
||||
super(parentShell);
|
||||
this.domain=connectionId;
|
||||
this.destination=destination;
|
||||
this.name=name;
|
||||
this.instruction=instruction;
|
||||
this.prompt=prompt;
|
||||
this.echo=echo;
|
||||
this.message=NLS.bind(SshMessages.KeyboardInteractiveDialog_message, new String[] { destination+(name!=null && name.length()>0 ? ": "+name : "") }); //NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$
|
||||
this.domain = connectionId;
|
||||
this.destination = destination;
|
||||
this.name = name;
|
||||
this.instruction = instruction;
|
||||
this.prompt = prompt;
|
||||
this.echo = echo;
|
||||
this.message = NLS.bind(SshMessages.KeyboardInteractiveDialog_message,
|
||||
new String[] { destination + (name != null && name.length() > 0 ? ": " + name : "") }); //NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Window#configureShell
|
||||
*/
|
||||
@Override
|
||||
protected void configureShell(Shell newShell) {
|
||||
protected void configureShell(Shell newShell) {
|
||||
super.configureShell(newShell);
|
||||
newShell.setText(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Window#create
|
||||
*/
|
||||
@Override
|
||||
public void create() {
|
||||
public void create() {
|
||||
super.create();
|
||||
if(texts.length>0){
|
||||
if (texts.length > 0) {
|
||||
texts[0].setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Dialog#createDialogArea
|
||||
*/
|
||||
@Override
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
Composite main=new Composite(parent, SWT.NONE);
|
||||
GridLayout layout=new GridLayout();
|
||||
layout.numColumns=3;
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
Composite main = new Composite(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = 3;
|
||||
main.setLayout(layout);
|
||||
main.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
|
||||
// set F1 help
|
||||
PlatformUI.getWorkbench().getHelpSystem().setHelp(main, ISshConstants.HELP_KEYBOARD_INTERACTIVE_DIALOG);
|
||||
|
||||
if (message!=null) {
|
||||
Label messageLabel=new Label(main, SWT.WRAP);
|
||||
if (message != null) {
|
||||
Label messageLabel = new Label(main, SWT.WRAP);
|
||||
messageLabel.setText(message);
|
||||
GridData data=new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.horizontalSpan=3;
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.horizontalSpan = 3;
|
||||
messageLabel.setLayoutData(data);
|
||||
}
|
||||
if(domain!=null){
|
||||
if (domain != null) {
|
||||
Label label = new Label(main, SWT.WRAP);
|
||||
label.setText(NLS.bind(SshMessages.KeyboardInteractiveDialog_labelConnection, new String[] { domain }));
|
||||
GridData data=new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.horizontalSpan=3;
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.horizontalSpan = 3;
|
||||
label.setLayoutData(data);
|
||||
}
|
||||
if (instruction!=null && instruction.length()>0) {
|
||||
Label messageLabel=new Label(main, SWT.WRAP);
|
||||
if (instruction != null && instruction.length() > 0) {
|
||||
Label messageLabel = new Label(main, SWT.WRAP);
|
||||
messageLabel.setText(instruction);
|
||||
GridData data=new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.horizontalSpan=3;
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.horizontalSpan = 3;
|
||||
messageLabel.setLayoutData(data);
|
||||
}
|
||||
createPasswordFields(main);
|
||||
return main;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the widgets that represent the entry area.
|
||||
*
|
||||
* @param parent the parent of the widgets
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
protected void createPasswordFields(Composite parent) {
|
||||
texts=new Text[prompt.length];
|
||||
protected void createPasswordFields(Composite parent) {
|
||||
texts = new Text[prompt.length];
|
||||
|
||||
for(int i=0; i<prompt.length; i++){
|
||||
for (int i = 0; i < prompt.length; i++) {
|
||||
new Label(parent, SWT.NONE).setText(prompt[i]);
|
||||
texts[i]=new Text(parent, SWT.BORDER);
|
||||
GridData data=new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
|
||||
texts[i] = new Text(parent, SWT.BORDER);
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
|
||||
texts[i].setLayoutData(data);
|
||||
|
||||
if(!echo[i]){
|
||||
if (!echo[i]) {
|
||||
texts[i].setEchoChar('*');
|
||||
}
|
||||
new Label(parent, SWT.NONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entered values, or null
|
||||
* if the user cancelled.
|
||||
|
@ -161,6 +162,7 @@ protected void createPasswordFields(Composite parent) {
|
|||
public String[] getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies that the ok button of this dialog has been pressed.
|
||||
* <p>
|
||||
|
@ -170,13 +172,14 @@ protected void createPasswordFields(Composite parent) {
|
|||
* </p>
|
||||
*/
|
||||
@Override
|
||||
protected void okPressed() {
|
||||
result=new String[prompt.length];
|
||||
for(int i=0; i<texts.length; i++){
|
||||
result[i]=texts[i].getText();
|
||||
protected void okPressed() {
|
||||
result = new String[prompt.length];
|
||||
for (int i = 0; i < texts.length; i++) {
|
||||
result[i] = texts[i].getText();
|
||||
}
|
||||
super.okPressed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies that the cancel button of this dialog has been pressed.
|
||||
* <p>
|
||||
|
@ -186,8 +189,8 @@ protected void okPressed() {
|
|||
* </p>
|
||||
*/
|
||||
@Override
|
||||
protected void cancelPressed() {
|
||||
result=null;
|
||||
protected void cancelPressed() {
|
||||
result = null;
|
||||
super.cancelPressed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,8 +54,9 @@ public class SshConnection extends Thread {
|
|||
private final SshConnector fConn;
|
||||
private Session fSession;
|
||||
private boolean fDisconnectHasBeenCalled;
|
||||
protected SshConnection(SshConnector conn,ITerminalControl control) {
|
||||
super("SshConnection-"+fgNo++); //$NON-NLS-1$
|
||||
|
||||
protected SshConnection(SshConnector conn, ITerminalControl control) {
|
||||
super("SshConnection-" + fgNo++); //$NON-NLS-1$
|
||||
fControl = control;
|
||||
fConn = conn;
|
||||
fControl.setState(TerminalState.CONNECTING);
|
||||
|
@ -72,7 +73,8 @@ public class SshConnection extends Thread {
|
|||
* the Jsch config (for instance, in order to switch off strict
|
||||
* host key checking or in order to add specific ciphers).
|
||||
*/
|
||||
protected Session createSession(String username, String password, String hostname, int port, UserInfo wrapperUI, IProgressMonitor monitor) throws JSchException {
|
||||
protected Session createSession(String username, String password, String hostname, int port, UserInfo wrapperUI,
|
||||
IProgressMonitor monitor) throws JSchException {
|
||||
IJSchService service = UIPlugin.getDefault().getJSchService();
|
||||
if (service == null)
|
||||
return null;
|
||||
|
@ -107,10 +109,9 @@ public class SshConnection extends Thread {
|
|||
String password = fConn.getSshSettings().getPassword();
|
||||
port = fConn.getSshSettings().getPort();
|
||||
|
||||
UserInfo ui=new MyUserInfo(null, user, password);
|
||||
UserInfo ui = new MyUserInfo(null, user, password);
|
||||
|
||||
Session session = createSession(user, password, host, port,
|
||||
ui, new NullProgressMonitor());
|
||||
Session session = createSession(user, password, host, port, ui, new NullProgressMonitor());
|
||||
synchronized (this) {
|
||||
fSession = session;
|
||||
}
|
||||
|
@ -130,9 +131,9 @@ public class SshConnection extends Thread {
|
|||
|
||||
session.connect(nTimeout); // making connection with timeout.
|
||||
// if we got disconnected, do not continue
|
||||
if(!isSessionConnected())
|
||||
if (!isSessionConnected())
|
||||
return;
|
||||
ChannelShell channel=(ChannelShell) session.openChannel("shell"); //$NON-NLS-1$
|
||||
ChannelShell channel = (ChannelShell) session.openChannel("shell"); //$NON-NLS-1$
|
||||
channel.setPtyType("xterm"); //$NON-NLS-1$
|
||||
// TERM=xterm implies VT100 line wrapping mode
|
||||
fControl.setVT100LineWrapping(true);
|
||||
|
@ -195,18 +196,19 @@ public class SshConnection extends Thread {
|
|||
void disconnect() {
|
||||
interrupt();
|
||||
synchronized (this) {
|
||||
fDisconnectHasBeenCalled=true;
|
||||
if(fSession!=null) {
|
||||
fDisconnectHasBeenCalled = true;
|
||||
if (fSession != null) {
|
||||
try {
|
||||
fSession.disconnect();
|
||||
} catch (Exception e) {
|
||||
// Ignore NPE due to bug in JSch if disconnecting
|
||||
// while not yet authenticated
|
||||
}
|
||||
fSession=null;
|
||||
fSession = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the data from the ssh connection and display it in the terminal.
|
||||
* @param in
|
||||
|
@ -214,17 +216,17 @@ public class SshConnection extends Thread {
|
|||
*/
|
||||
private void readDataForever(InputStream in) throws IOException {
|
||||
// read the data
|
||||
byte bytes[]=new byte[32*1024];
|
||||
byte bytes[] = new byte[32 * 1024];
|
||||
int n;
|
||||
// read until the thread gets interrupted....
|
||||
while( (n=in.read(bytes))!=-1) {
|
||||
fControl.getRemoteToTerminalOutputStream().write(bytes,0,n);
|
||||
while ((n = in.read(bytes)) != -1) {
|
||||
fControl.getRemoteToTerminalOutputStream().write(bytes, 0, n);
|
||||
}
|
||||
}
|
||||
|
||||
protected static Display getStandardDisplay() {
|
||||
Display display = Display.getCurrent();
|
||||
if( display==null ) {
|
||||
if (display == null) {
|
||||
display = Display.getDefault();
|
||||
}
|
||||
return display;
|
||||
|
@ -242,10 +244,12 @@ public class SshConnection extends Thread {
|
|||
fUser = user;
|
||||
fPassword = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return fPassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean promptYesNo(final String str) {
|
||||
//need to switch to UI thread for prompting
|
||||
|
@ -267,6 +271,7 @@ public class SshConnection extends Thread {
|
|||
});
|
||||
return retval[0];
|
||||
}
|
||||
|
||||
private String promptSecret(final String message) {
|
||||
final String[] retval = new String[1];
|
||||
getStandardDisplay().syncExec(new Runnable() {
|
||||
|
@ -287,24 +292,28 @@ public class SshConnection extends Thread {
|
|||
});
|
||||
return retval[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassphrase() {
|
||||
return fPassphrase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean promptPassphrase(String message) {
|
||||
fPassphrase = promptSecret(message);
|
||||
return (fPassphrase!=null);
|
||||
return (fPassphrase != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean promptPassword(final String message) {
|
||||
String _password = promptSecret(message);
|
||||
if (_password!=null) {
|
||||
fPassword=_password;
|
||||
if (_password != null) {
|
||||
fPassword = _password;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(final String message) {
|
||||
Display.getDefault().syncExec(new Runnable() {
|
||||
|
@ -321,17 +330,17 @@ public class SshConnection extends Thread {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] promptKeyboardInteractive(final String destination,
|
||||
final String name, final String instruction,
|
||||
final String[] prompt, final boolean[] echo)
|
||||
{
|
||||
public String[] promptKeyboardInteractive(final String destination, final String name, final String instruction,
|
||||
final String[] prompt, final boolean[] echo) {
|
||||
if (prompt.length == 0) {
|
||||
// No need to prompt, just return an empty String array
|
||||
return new String[0];
|
||||
}
|
||||
try{
|
||||
if (fAttemptCount == 0 && fPassword != null && prompt.length == 1 && prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$
|
||||
try {
|
||||
if (fAttemptCount == 0 && fPassword != null && prompt.length == 1
|
||||
&& prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$
|
||||
// Return the provided password the first time but always prompt on subsequent tries
|
||||
fAttemptCount++;
|
||||
return new String[] { fPassword };
|
||||
|
@ -341,7 +350,8 @@ public class SshConnection extends Thread {
|
|||
@Override
|
||||
public void run() {
|
||||
if (isSessionConnected()) {
|
||||
KeyboardInteractiveDialog dialog = new KeyboardInteractiveDialog(null, fConnectionId, destination, name, instruction, prompt, echo);
|
||||
KeyboardInteractiveDialog dialog = new KeyboardInteractiveDialog(null, fConnectionId,
|
||||
destination, name, instruction, prompt, echo);
|
||||
dialog.open();
|
||||
finResult[0] = dialog.getResult();
|
||||
} else {
|
||||
|
@ -349,7 +359,7 @@ public class SshConnection extends Thread {
|
|||
}
|
||||
}
|
||||
});
|
||||
String[] result=finResult[0];
|
||||
String[] result = finResult[0];
|
||||
if (result == null)
|
||||
return null; // cancelled
|
||||
if (result.length == 1 && prompt.length == 1 && prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$
|
||||
|
@ -357,8 +367,7 @@ public class SshConnection extends Thread {
|
|||
}
|
||||
fAttemptCount++;
|
||||
return result;
|
||||
}
|
||||
catch(OperationCanceledException e){
|
||||
} catch (OperationCanceledException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,22 +36,27 @@ public class SshConnector extends TerminalConnectorImpl {
|
|||
private final SshSettings fSettings;
|
||||
private int fWidth;
|
||||
private int fHeight;
|
||||
|
||||
public SshConnector() {
|
||||
this(new SshSettings());
|
||||
}
|
||||
|
||||
public SshConnector(SshSettings settings) {
|
||||
fSettings=settings;
|
||||
fSettings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() throws Exception {
|
||||
fJsch=new JSch();
|
||||
fJsch = new JSch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ITerminalControl control) {
|
||||
super.connect(control);
|
||||
fConnection = new SshConnection(this,control);
|
||||
fConnection = new SshConnection(this, control);
|
||||
fConnection.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void doDisconnect() {
|
||||
fConnection.disconnect();
|
||||
|
@ -71,28 +76,34 @@ public class SshConnector extends TerminalConnectorImpl {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTerminalSize(int newWidth, int newHeight) {
|
||||
if(fChannel!=null && (newWidth!=fWidth || newHeight!=fHeight)) {
|
||||
if (fChannel != null && (newWidth != fWidth || newHeight != fHeight)) {
|
||||
//avoid excessive communications due to change size requests by caching previous size
|
||||
fChannel.setPtySize(newWidth, newHeight, 8*newWidth, 8*newHeight);
|
||||
fWidth=newWidth;
|
||||
fHeight=newHeight;
|
||||
fChannel.setPtySize(newWidth, newHeight, 8 * newWidth, 8 * newHeight);
|
||||
fWidth = newWidth;
|
||||
fHeight = newHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return fInputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getTerminalToRemoteStream() {
|
||||
return fOutputStream;
|
||||
}
|
||||
|
||||
void setInputStream(InputStream inputStream) {
|
||||
fInputStream = inputStream;
|
||||
}
|
||||
|
||||
void setOutputStream(OutputStream outputStream) {
|
||||
fOutputStream = outputStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the SSH Settings.
|
||||
*
|
||||
|
@ -102,31 +113,38 @@ public class SshConnector extends TerminalConnectorImpl {
|
|||
public ISshSettings getSshSettings() {
|
||||
return fSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultSettings() {
|
||||
fSettings.load(new NullSettingsStore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSettingsSummary() {
|
||||
return fSettings.getSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(ISettingsStore store) {
|
||||
fSettings.load(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ISettingsStore store) {
|
||||
fSettings.save(store);
|
||||
}
|
||||
|
||||
protected JSch getJsch() {
|
||||
return fJsch;
|
||||
}
|
||||
|
||||
ChannelShell getChannel() {
|
||||
return fChannel;
|
||||
}
|
||||
|
||||
void setChannel(ChannelShell channel) {
|
||||
fChannel = channel;
|
||||
fWidth=-1;
|
||||
fHeight=-1;
|
||||
fWidth = -1;
|
||||
fHeight = -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,4 +96,4 @@ public class SshMessages extends NLS {
|
|||
|
||||
// </Copied from org.eclipse.team.cvs.core / Policy>
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public class SshSettings implements ISshSettings {
|
|||
protected String fPort;
|
||||
protected String fTimeout;
|
||||
protected String fKeepalive;
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return fHost;
|
||||
|
@ -36,8 +37,8 @@ public class SshSettings implements ISshSettings {
|
|||
|
||||
@Override
|
||||
public String getSummary() {
|
||||
String settings = getUser()+'@'+getHost();
|
||||
if(getPort()!=ISshSettings.DEFAULT_SSH_PORT) {
|
||||
String settings = getUser() + '@' + getHost();
|
||||
if (getPort() != ISshSettings.DEFAULT_SSH_PORT) {
|
||||
settings += ":" + getPort(); //$NON-NLS-1$
|
||||
}
|
||||
return settings;
|
||||
|
@ -68,7 +69,6 @@ public class SshSettings implements ISshSettings {
|
|||
store.put("Keepalive", fKeepalive);//$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
try {
|
||||
|
@ -77,6 +77,7 @@ public class SshSettings implements ISshSettings {
|
|||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
public String getTimeoutString() {
|
||||
return fTimeout;
|
||||
}
|
||||
|
@ -93,6 +94,7 @@ public class SshSettings implements ISshSettings {
|
|||
return 300;
|
||||
}
|
||||
}
|
||||
|
||||
public String getKeepaliveString() {
|
||||
return fKeepalive;
|
||||
}
|
||||
|
@ -109,6 +111,7 @@ public class SshSettings implements ISshSettings {
|
|||
public void setUser(String user) {
|
||||
fUser = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
try {
|
||||
|
|
|
@ -37,8 +37,9 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
private Text fPassword;
|
||||
|
||||
public SshSettingsPage(SshSettings settings) {
|
||||
fTerminalSettings=settings;
|
||||
fTerminalSettings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveSettings() {
|
||||
fTerminalSettings.setHost(fHostText.getText());
|
||||
|
@ -51,20 +52,22 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
|
||||
@Override
|
||||
public void loadSettings() {
|
||||
if(fTerminalSettings!=null) {
|
||||
fHostText.setText(get(fTerminalSettings.getHost(),""));//$NON-NLS-1$
|
||||
fTimeout.setText(get(fTerminalSettings.getTimeoutString(),"0"));//$NON-NLS-1$
|
||||
fKeepalive.setText(get(fTerminalSettings.getKeepaliveString(),"300"));//$NON-NLS-1$
|
||||
fUser.setText(get(fTerminalSettings.getUser(),""));//$NON-NLS-1$
|
||||
if (fTerminalSettings != null) {
|
||||
fHostText.setText(get(fTerminalSettings.getHost(), ""));//$NON-NLS-1$
|
||||
fTimeout.setText(get(fTerminalSettings.getTimeoutString(), "0"));//$NON-NLS-1$
|
||||
fKeepalive.setText(get(fTerminalSettings.getKeepaliveString(), "300"));//$NON-NLS-1$
|
||||
fUser.setText(get(fTerminalSettings.getUser(), ""));//$NON-NLS-1$
|
||||
fPort.setText(get(fTerminalSettings.getPortString(), String.valueOf(ISshSettings.DEFAULT_SSH_PORT)));
|
||||
fPassword.setText(get(fTerminalSettings.getPassword(),""));//$NON-NLS-1$
|
||||
fPassword.setText(get(fTerminalSettings.getPassword(), ""));//$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
String get(String value, String def) {
|
||||
if(value==null || value.length()==0)
|
||||
if (value == null || value.length() == 0)
|
||||
return def;
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateSettings() {
|
||||
String message = null;
|
||||
|
@ -75,7 +78,10 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
String m = "Please enter a host IP or name."; //$NON-NLS-1$
|
||||
int mt = IMessageProvider.INFORMATION;
|
||||
updateControlDecoration(fHostText, m, mt);
|
||||
if (mt > messageType) { message = m; messageType = mt; }
|
||||
if (mt > messageType) {
|
||||
message = m;
|
||||
messageType = mt;
|
||||
}
|
||||
|
||||
valid = false;
|
||||
} else {
|
||||
|
@ -85,7 +91,10 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
String m = "Please enter a username."; //$NON-NLS-1$
|
||||
int mt = IMessageProvider.INFORMATION;
|
||||
updateControlDecoration(fUser, m, mt);
|
||||
if (mt > messageType) { message = m; messageType = mt; }
|
||||
if (mt > messageType) {
|
||||
message = m;
|
||||
messageType = mt;
|
||||
}
|
||||
|
||||
valid = false;
|
||||
} else {
|
||||
|
@ -97,7 +106,10 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
String m = "Invalid network port. Must be between 0 and 65535."; //$NON-NLS-1$
|
||||
int mt = IMessageProvider.ERROR;
|
||||
updateControlDecoration(fPort, m, mt);
|
||||
if (mt > messageType) { message = m; messageType = mt; }
|
||||
if (mt > messageType) {
|
||||
message = m;
|
||||
messageType = mt;
|
||||
}
|
||||
|
||||
valid = false;
|
||||
} else {
|
||||
|
@ -108,7 +120,10 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
String m = "Invalid timeout. Must be greater than 0."; //$NON-NLS-1$
|
||||
int mt = IMessageProvider.ERROR;
|
||||
updateControlDecoration(fTimeout, m, mt);
|
||||
if (mt > messageType) { message = m; messageType = mt; }
|
||||
if (mt > messageType) {
|
||||
message = m;
|
||||
messageType = mt;
|
||||
}
|
||||
|
||||
valid = false;
|
||||
} else {
|
||||
|
@ -119,7 +134,10 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
String m = "Invalid keep alive. Must be greater than 0."; //$NON-NLS-1$
|
||||
int mt = IMessageProvider.ERROR;
|
||||
updateControlDecoration(fKeepalive, m, mt);
|
||||
if (mt > messageType) { message = m; messageType = mt; }
|
||||
if (mt > messageType) {
|
||||
message = m;
|
||||
messageType = mt;
|
||||
}
|
||||
|
||||
valid = false;
|
||||
} else {
|
||||
|
@ -132,6 +150,7 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
setMessage(message, messageType);
|
||||
return valid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createControl(Composite parent) {
|
||||
Composite composite = new Composite(parent, SWT.NONE);
|
||||
|
@ -144,13 +163,14 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
|
||||
fHostText = createTextField(composite, SshMessages.HOST);
|
||||
fUser = createTextField(composite, SshMessages.USER);
|
||||
fPassword = createTextField(composite, SshMessages.PASSWORD,SWT.PASSWORD);
|
||||
fPassword = createTextField(composite, SshMessages.PASSWORD, SWT.PASSWORD);
|
||||
fTimeout = createTextField(composite, SshMessages.TIMEOUT);
|
||||
fKeepalive = createTextField(composite, SshMessages.KEEPALIVE);
|
||||
fKeepalive.setToolTipText(SshMessages.KEEPALIVE_Tooltip);
|
||||
fPort = createTextField(composite, SshMessages.PORT);
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
private Text createTextField(Composite composite, String labelTxt, int textOptions) {
|
||||
GridData gridData;
|
||||
// Add label
|
||||
|
@ -159,7 +179,7 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
|
||||
// Add control
|
||||
gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
final Text text= new Text(composite, SWT.BORDER | textOptions);
|
||||
final Text text = new Text(composite, SWT.BORDER | textOptions);
|
||||
text.setLayoutData(gridData);
|
||||
text.addModifyListener(new ModifyListener() {
|
||||
@Override
|
||||
|
@ -170,6 +190,7 @@ public class SshSettingsPage extends AbstractSettingsPage {
|
|||
createControlDecoration(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
private Text createTextField(Composite composite, String labelTxt) {
|
||||
return createTextField(composite, labelTxt, 0);
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ public class UserValidationDialog extends TrayDialog {
|
|||
this.domain = location;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Window#configureShell
|
||||
*/
|
||||
|
@ -77,6 +78,7 @@ public class UserValidationDialog extends TrayDialog {
|
|||
// set F1 help
|
||||
PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, ISshConstants.HELP_USER_VALIDATION_DIALOG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Window#create
|
||||
*/
|
||||
|
@ -142,7 +144,8 @@ public class UserValidationDialog extends TrayDialog {
|
|||
if (isUsernameMutable) {
|
||||
label.setText(NLS.bind(SshMessages.UserValidationDialog_labelUser, new String[] { domain }));
|
||||
} else {
|
||||
label.setText(NLS.bind(SshMessages.UserValidationDialog_labelPassword, (new Object[]{defaultUsername, domain})));
|
||||
label.setText(NLS.bind(SshMessages.UserValidationDialog_labelPassword,
|
||||
(new Object[] { defaultUsername, domain })));
|
||||
}
|
||||
data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
|
||||
data.horizontalSpan = 2;
|
||||
|
@ -152,7 +155,7 @@ public class UserValidationDialog extends TrayDialog {
|
|||
createUsernameFields(main);
|
||||
createPasswordFields(main);
|
||||
|
||||
if(domain != null) {
|
||||
if (domain != null) {
|
||||
allowCachingButton = new Button(main, SWT.CHECK);
|
||||
allowCachingButton.setText(SshMessages.UserValidationDialog_6);
|
||||
data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
|
||||
|
@ -175,7 +178,8 @@ public class UserValidationDialog extends TrayDialog {
|
|||
warningComposite.setLayoutData(data);
|
||||
Label warningLabel = new Label(warningComposite, SWT.NONE);
|
||||
warningLabel.setImage(getImage(DLG_IMG_MESSAGE_WARNING));
|
||||
warningLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING));
|
||||
warningLabel.setLayoutData(
|
||||
new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING));
|
||||
Label warningText = new Label(warningComposite, SWT.WRAP);
|
||||
warningText.setText(SshMessages.UserValidationDialog_7);
|
||||
data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
|
@ -202,6 +206,7 @@ public class UserValidationDialog extends TrayDialog {
|
|||
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
|
||||
passwordField.setLayoutData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the three widgets that represent the user name entry area.
|
||||
*
|
||||
|
@ -261,6 +266,7 @@ public class UserValidationDialog extends TrayDialog {
|
|||
|
||||
super.okPressed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not the username field should be mutable.
|
||||
* This method must be called before create(), otherwise it
|
||||
|
@ -277,7 +283,7 @@ public class UserValidationDialog extends TrayDialog {
|
|||
*/
|
||||
@Override
|
||||
public boolean close() {
|
||||
if(keyLockImage != null) {
|
||||
if (keyLockImage != null) {
|
||||
keyLockImage.dispose();
|
||||
}
|
||||
return super.close();
|
||||
|
|
|
@ -75,7 +75,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
panel.setLayoutData(data);
|
||||
|
||||
// Create the host selection combo
|
||||
if (isWithoutSelection()) createHostsUI(panel, true);
|
||||
if (isWithoutSelection())
|
||||
createHostsUI(panel, true);
|
||||
|
||||
SshConnector conn = new SshConnector();
|
||||
sshSettings = (SshSettings) conn.getSshSettings();
|
||||
|
@ -84,7 +85,7 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
|
||||
sshSettingsPage = new SshSettingsPage(sshSettings);
|
||||
if (sshSettingsPage instanceof AbstractSettingsPage) {
|
||||
((AbstractSettingsPage)sshSettingsPage).setHasControlDecoration(true);
|
||||
((AbstractSettingsPage) sshSettingsPage).setHasControlDecoration(true);
|
||||
}
|
||||
sshSettingsPage.createControl(panel);
|
||||
|
||||
|
@ -92,7 +93,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
sshSettingsPage.addListener(new ISettingsPage.Listener() {
|
||||
@Override
|
||||
public void onSettingsPageChanged(Control control) {
|
||||
if (getContainer() != null) getContainer().validate();
|
||||
if (getContainer() != null)
|
||||
getContainer().validate();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -110,31 +112,39 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
*/
|
||||
@Override
|
||||
public void setupData(Map<String, Object> data) {
|
||||
if (data == null || sshSettings == null || sshSettingsPage == null) return;
|
||||
if (data == null || sshSettings == null || sshSettingsPage == null)
|
||||
return;
|
||||
|
||||
String value = (String)data.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
if (value != null) sshSettings.setHost(value);
|
||||
String value = (String) data.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
if (value != null)
|
||||
sshSettings.setHost(value);
|
||||
|
||||
Object v = data.get(ITerminalsConnectorConstants.PROP_IP_PORT);
|
||||
value = v != null ? v.toString() : null;
|
||||
if (value != null) sshSettings.setPort(value);
|
||||
if (value != null)
|
||||
sshSettings.setPort(value);
|
||||
|
||||
v = data.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
|
||||
value = v != null ? v.toString() : null;
|
||||
if (value != null) sshSettings.setTimeout(value);
|
||||
if (value != null)
|
||||
sshSettings.setTimeout(value);
|
||||
|
||||
v = data.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
|
||||
value = v != null ? v.toString() : null;
|
||||
if (value != null) sshSettings.setKeepalive(value);
|
||||
if (value != null)
|
||||
sshSettings.setKeepalive(value);
|
||||
|
||||
value = (String)data.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
|
||||
if (value != null) sshSettings.setPassword(value);
|
||||
value = (String) data.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
|
||||
if (value != null)
|
||||
sshSettings.setPassword(value);
|
||||
|
||||
value = (String)data.get(ITerminalsConnectorConstants.PROP_SSH_USER);
|
||||
if (value != null) sshSettings.setUser(value);
|
||||
value = (String) data.get(ITerminalsConnectorConstants.PROP_SSH_USER);
|
||||
if (value != null)
|
||||
sshSettings.setUser(value);
|
||||
|
||||
value = (String)data.get(ITerminalsConnectorConstants.PROP_ENCODING);
|
||||
if (value != null) setEncoding(value);
|
||||
value = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING);
|
||||
if (value != null)
|
||||
setEncoding(value);
|
||||
|
||||
sshSettingsPage.loadSettings();
|
||||
}
|
||||
|
@ -151,7 +161,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
ITerminalContextPropertiesProvider provider = TerminalContextPropertiesProviderFactory.getProvider(element);
|
||||
if (provider != null) {
|
||||
Object user = provider.getProperty(element, IContextPropertiesConstants.PROP_DEFAULT_USER);
|
||||
if (user instanceof String) return ((String) user).trim();
|
||||
if (user instanceof String)
|
||||
return ((String) user).trim();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,13 +174,15 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
*/
|
||||
@Override
|
||||
public void extractData(Map<String, Object> data) {
|
||||
if (data == null) return;
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
// set the terminal connector id for ssh
|
||||
data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.terminal.connector.ssh.SshConnector"); //$NON-NLS-1$
|
||||
data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID,
|
||||
"org.eclipse.tm.terminal.connector.ssh.SshConnector"); //$NON-NLS-1$
|
||||
|
||||
sshSettingsPage.saveSettings();
|
||||
data.put(ITerminalsConnectorConstants.PROP_IP_HOST,sshSettings.getHost());
|
||||
data.put(ITerminalsConnectorConstants.PROP_IP_HOST, sshSettings.getHost());
|
||||
data.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.valueOf(sshSettings.getPort()));
|
||||
data.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.valueOf(sshSettings.getTimeout()));
|
||||
data.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, Integer.valueOf(sshSettings.getKeepalive()));
|
||||
|
@ -185,8 +198,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
protected void fillSettingsForHost(String host) {
|
||||
boolean saveUser = true;
|
||||
boolean savePassword = false;
|
||||
if (host != null && host.length() != 0){
|
||||
if (hostSettingsMap.containsKey(host)){
|
||||
if (host != null && host.length() != 0) {
|
||||
if (hostSettingsMap.containsKey(host)) {
|
||||
Map<String, String> hostSettings = hostSettingsMap.get(host);
|
||||
if (hostSettings.get(ITerminalsConnectorConstants.PROP_IP_HOST) != null) {
|
||||
sshSettings.setHost(hostSettings.get(ITerminalsConnectorConstants.PROP_IP_HOST));
|
||||
|
@ -206,7 +219,7 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
if (hostSettings.get(SAVE_PASSWORD) != null) {
|
||||
savePassword = new Boolean(hostSettings.get(SAVE_PASSWORD)).booleanValue();
|
||||
}
|
||||
if (!savePassword){
|
||||
if (!savePassword) {
|
||||
sshSettings.setPassword(""); //$NON-NLS-1$
|
||||
} else {
|
||||
String password = accessSecurePassword(sshSettings.getHost());
|
||||
|
@ -218,7 +231,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
String encoding = hostSettings.get(ITerminalsConnectorConstants.PROP_ENCODING);
|
||||
if (encoding == null || "null".equals(encoding)) { //$NON-NLS-1$
|
||||
String defaultEncoding = getSelectionEncoding();
|
||||
encoding = defaultEncoding != null && !"".equals(defaultEncoding.trim()) ? defaultEncoding.trim() : "ISO-8859-1"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
encoding = defaultEncoding != null && !"".equals(defaultEncoding.trim()) ? defaultEncoding.trim() //$NON-NLS-1$
|
||||
: "ISO-8859-1"; //$NON-NLS-1$
|
||||
}
|
||||
setEncoding(encoding);
|
||||
} else {
|
||||
|
@ -252,20 +266,20 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
boolean savePassword = passwordButton.getSelection();
|
||||
String host = getHostFromSettings();
|
||||
if (host != null && host.length() != 0) {
|
||||
if (hostSettingsMap.containsKey(host)){
|
||||
if (hostSettingsMap.containsKey(host)) {
|
||||
Map<String, String> hostSettings = hostSettingsMap.get(host);
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, sshSettings.getHost());
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(sshSettings.getPort()));
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(sshSettings.getTimeout()));
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, Integer.toString(sshSettings.getKeepalive()));
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE,
|
||||
Integer.toString(sshSettings.getKeepalive()));
|
||||
if (saveUser) {
|
||||
if (sshSettings.getUser() != null) {
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_USER, sshSettings.getUser());
|
||||
} else {
|
||||
hostSettings.remove(ITerminalsConnectorConstants.PROP_SSH_USER);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
hostSettings.remove(ITerminalsConnectorConstants.PROP_SSH_USER);
|
||||
}
|
||||
|
||||
|
@ -280,18 +294,20 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
hostSettings.put(SAVE_USER, Boolean.toString(saveUser));
|
||||
hostSettings.put(SAVE_PASSWORD, Boolean.toString(savePassword));
|
||||
|
||||
if (savePassword && sshSettings.getPassword() != null && sshSettings.getPassword().length() != 0){
|
||||
if (savePassword && sshSettings.getPassword() != null && sshSettings.getPassword().length() != 0) {
|
||||
saveSecurePassword(host, sshSettings.getPassword());
|
||||
}
|
||||
|
||||
// maybe unchecked the password button - so try to remove a saved password - if any
|
||||
if (!savePassword) removeSecurePassword(host);
|
||||
if (!savePassword)
|
||||
removeSecurePassword(host);
|
||||
} else if (add) {
|
||||
Map<String, String> hostSettings = new HashMap<String, String>();
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, sshSettings.getHost());
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(sshSettings.getPort()));
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(sshSettings.getTimeout()));
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, Integer.toString(sshSettings.getKeepalive()));
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE,
|
||||
Integer.toString(sshSettings.getKeepalive()));
|
||||
if (saveUser) {
|
||||
if (sshSettings.getUser() != null) {
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_SSH_USER, sshSettings.getUser());
|
||||
|
@ -302,7 +318,7 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
hostSettings.put(SAVE_PASSWORD, Boolean.toString(savePassword));
|
||||
hostSettingsMap.put(host, hostSettings);
|
||||
|
||||
if (savePassword && sshSettings.getPassword() != null && sshSettings.getPassword().length() != 0){
|
||||
if (savePassword && sshSettings.getPassword() != null && sshSettings.getPassword().length() != 0) {
|
||||
saveSecurePassword(host, sshSettings.getPassword());
|
||||
}
|
||||
}
|
||||
|
@ -328,8 +344,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
if (node != null) {
|
||||
try {
|
||||
node.put("password", password, true); //$NON-NLS-1$
|
||||
}
|
||||
catch (StorageException ex) { /* ignored on purpose */ }
|
||||
} catch (StorageException ex) {
|
||||
/* ignored on purpose */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -353,8 +369,8 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
String password = null;
|
||||
try {
|
||||
password = node.get("password", null); //$NON-NLS-1$
|
||||
}
|
||||
catch (StorageException ex) { /* ignored on purpose */ }
|
||||
} catch (StorageException ex) {
|
||||
/* ignored on purpose */ }
|
||||
|
||||
return password;
|
||||
}
|
||||
|
@ -385,7 +401,7 @@ public class SshWizardConfigurationPanel extends AbstractExtendedConfigurationPa
|
|||
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid()
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(){
|
||||
public boolean isValid() {
|
||||
return isEncodingValid() && sshSettingsPage.validateSettings();
|
||||
}
|
||||
|
||||
|
|
|
@ -95,21 +95,23 @@ public class SshLauncherDelegate extends AbstractLauncherDelegate {
|
|||
private String getTerminalTitle(Map<String, Object> properties) {
|
||||
// Try to see if the user set a title explicitly via the properties map.
|
||||
String title = getDefaultTerminalTitle(properties);
|
||||
if (title != null) return title;
|
||||
if (title != null)
|
||||
return title;
|
||||
|
||||
//No title,try to calculate the title
|
||||
String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
String user = (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_USER);
|
||||
String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
String user = (String) properties.get(ITerminalsConnectorConstants.PROP_SSH_USER);
|
||||
Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT);
|
||||
String port = value != null ? value.toString() : null;
|
||||
|
||||
if (host != null && user!= null) {
|
||||
if (host != null && user != null) {
|
||||
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
String date = format.format(new Date(System.currentTimeMillis()));
|
||||
if (port != null && Integer.valueOf(port).intValue() != ISshSettings.DEFAULT_SSH_PORT) {
|
||||
return NLS.bind(Messages.SshLauncherDelegate_terminalTitle_port, new String[]{user, host, port, date});
|
||||
return NLS.bind(Messages.SshLauncherDelegate_terminalTitle_port,
|
||||
new String[] { user, host, port, date });
|
||||
}
|
||||
return NLS.bind(Messages.SshLauncherDelegate_terminalTitle, new String[]{user, host, date});
|
||||
return NLS.bind(Messages.SshLauncherDelegate_terminalTitle, new String[] { user, host, date });
|
||||
}
|
||||
|
||||
return Messages.SshLauncherDelegate_terminalTitle_default;
|
||||
|
@ -134,24 +136,26 @@ public class SshLauncherDelegate extends AbstractLauncherDelegate {
|
|||
Assert.isNotNull(properties);
|
||||
|
||||
// Check for the terminal connector id
|
||||
String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
|
||||
if (connectorId == null) connectorId = "org.eclipse.tm.terminal.connector.ssh.SshConnector"; //$NON-NLS-1$
|
||||
String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
|
||||
if (connectorId == null)
|
||||
connectorId = "org.eclipse.tm.terminal.connector.ssh.SshConnector"; //$NON-NLS-1$
|
||||
|
||||
// Extract the ssh properties
|
||||
String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT);
|
||||
String port = value != null ? value.toString() : null;
|
||||
value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
|
||||
String timeout = value != null ? value.toString() : null;
|
||||
value = properties.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
|
||||
String keepAlive = value != null ? value.toString() : null;
|
||||
String password = (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
|
||||
String user = (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_USER);
|
||||
String password = (String) properties.get(ITerminalsConnectorConstants.PROP_SSH_PASSWORD);
|
||||
String user = (String) properties.get(ITerminalsConnectorConstants.PROP_SSH_USER);
|
||||
|
||||
int portOffset = 0;
|
||||
if (properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET) instanceof Integer) {
|
||||
portOffset = ((Integer)properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue();
|
||||
if (portOffset < 0) portOffset = 0;
|
||||
portOffset = ((Integer) properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue();
|
||||
if (portOffset < 0)
|
||||
portOffset = 0;
|
||||
}
|
||||
|
||||
// The real port to connect to is port + portOffset
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.eclipse.ui.IMemento;
|
|||
*/
|
||||
public class SshMementoHandler implements IMementoHandler {
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.terminal.view.ui.interfaces.IMementoHandler#saveState(org.eclipse.ui.IMemento, java.util.Map)
|
||||
*/
|
||||
|
@ -37,15 +36,21 @@ public class SshMementoHandler implements IMementoHandler {
|
|||
|
||||
// Do not write the terminal title to the memento -> needs to
|
||||
// be recreated at the time of restoration.
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_IP_HOST, (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST));
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_IP_HOST,
|
||||
(String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST));
|
||||
Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT);
|
||||
memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT, value instanceof Integer ? ((Integer)value).intValue() : -1);
|
||||
memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT,
|
||||
value instanceof Integer ? ((Integer) value).intValue() : -1);
|
||||
value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
|
||||
memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT, value instanceof Integer ? ((Integer)value).intValue() : -1);
|
||||
memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT,
|
||||
value instanceof Integer ? ((Integer) value).intValue() : -1);
|
||||
value = properties.get(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE);
|
||||
memento.putInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, value instanceof Integer ? ((Integer)value).intValue() : -1);
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_SSH_USER, (String)properties.get(ITerminalsConnectorConstants.PROP_SSH_USER));
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_ENCODING, (String)properties.get(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
memento.putInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE,
|
||||
value instanceof Integer ? ((Integer) value).intValue() : -1);
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_SSH_USER,
|
||||
(String) properties.get(ITerminalsConnectorConstants.PROP_SSH_USER));
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_ENCODING,
|
||||
(String) properties.get(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
|
||||
// The password is stored within the Eclipse secure preferences -> no need to store it to the memento
|
||||
//
|
||||
|
@ -84,26 +89,33 @@ public class SshMementoHandler implements IMementoHandler {
|
|||
Assert.isNotNull(properties);
|
||||
|
||||
// Restore the terminal properties from the memento
|
||||
properties.put(ITerminalsConnectorConstants.PROP_IP_HOST, memento.getString(ITerminalsConnectorConstants.PROP_IP_HOST));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_IP_PORT, memento.getInteger(ITerminalsConnectorConstants.PROP_IP_PORT));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_TIMEOUT, memento.getInteger(ITerminalsConnectorConstants.PROP_TIMEOUT));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE, memento.getInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_SSH_USER, memento.getString(ITerminalsConnectorConstants.PROP_SSH_USER));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_ENCODING, memento.getString(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_IP_HOST,
|
||||
memento.getString(ITerminalsConnectorConstants.PROP_IP_HOST));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_IP_PORT,
|
||||
memento.getInteger(ITerminalsConnectorConstants.PROP_IP_PORT));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_TIMEOUT,
|
||||
memento.getInteger(ITerminalsConnectorConstants.PROP_TIMEOUT));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE,
|
||||
memento.getInteger(ITerminalsConnectorConstants.PROP_SSH_KEEP_ALIVE));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_SSH_USER,
|
||||
memento.getString(ITerminalsConnectorConstants.PROP_SSH_USER));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_ENCODING,
|
||||
memento.getString(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
|
||||
// The password is stored within the Eclipse secure preferences -> restore it from there
|
||||
// To access the secure storage, we need the preference instance
|
||||
String password = null;
|
||||
ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
|
||||
if (preferences != null && (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST) != null) {
|
||||
if (preferences != null && (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST) != null) {
|
||||
// Construct the secure preferences node key
|
||||
String nodeKey = "/Target Explorer SSH Password/" + (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST); //$NON-NLS-1$
|
||||
String nodeKey = "/Target Explorer SSH Password/" //$NON-NLS-1$
|
||||
+ (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
ISecurePreferences node = preferences.node(nodeKey);
|
||||
if (node != null) {
|
||||
try {
|
||||
password = node.get("password", null); //$NON-NLS-1$
|
||||
}
|
||||
catch (StorageException ex) { /* ignored on purpose */ }
|
||||
} catch (StorageException ex) {
|
||||
/* ignored on purpose */ }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,13 +30,19 @@ public interface ITelnetSettings {
|
|||
static final String EOL_CRLF = "CR+LF"; //$NON-NLS-1$
|
||||
|
||||
String getHost();
|
||||
|
||||
int getNetworkPort();
|
||||
|
||||
int getTimeout();
|
||||
|
||||
/**
|
||||
* @since 4.2
|
||||
*/
|
||||
String getEndOfLine();
|
||||
|
||||
String getSummary();
|
||||
|
||||
void load(ISettingsStore store);
|
||||
|
||||
void save(ISettingsStore store);
|
||||
}
|
||||
|
|
|
@ -28,11 +28,9 @@ public class NetworkPortMap {
|
|||
public static final String PROP_VALUETGTCONS = "1232"; //$NON-NLS-1$
|
||||
public static final String PROP_VALUETELNET = "23"; //$NON-NLS-1$
|
||||
|
||||
String[][] fPortMap=new String[][] {
|
||||
String[][] fPortMap = new String[][] {
|
||||
// portName, port
|
||||
{PROP_NAMETGTCONS, PROP_VALUETGTCONS},
|
||||
{PROP_NAMETELNET, PROP_VALUETELNET}
|
||||
};
|
||||
{ PROP_NAMETGTCONS, PROP_VALUETGTCONS }, { PROP_NAMETELNET, PROP_VALUETELNET } };
|
||||
|
||||
public String getDefaultNetworkPort() {
|
||||
return PROP_VALUETELNET;
|
||||
|
@ -40,7 +38,7 @@ public class NetworkPortMap {
|
|||
|
||||
public String findPortName(String strPort) {
|
||||
for (int i = 0; i < fPortMap.length; i++) {
|
||||
if(fPortMap[i][1].equals(strPort))
|
||||
if (fPortMap[i][1].equals(strPort))
|
||||
return fPortMap[i][0];
|
||||
}
|
||||
return null;
|
||||
|
@ -48,14 +46,14 @@ public class NetworkPortMap {
|
|||
|
||||
public String findPort(String strPortName) {
|
||||
for (int i = 0; i < fPortMap.length; i++) {
|
||||
if(fPortMap[i][0].equals(strPortName))
|
||||
if (fPortMap[i][0].equals(strPortName))
|
||||
return fPortMap[i][1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> getNameTable() {
|
||||
List<String> names=new ArrayList<String>();
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (int i = 0; i < fPortMap.length; i++) {
|
||||
names.add(fPortMap[i][0]);
|
||||
}
|
||||
|
|
|
@ -22,55 +22,54 @@ package org.eclipse.tm.terminal.connector.telnet.connector;
|
|||
* interface. The meanings of these constants are defined in the various TELNET RFCs
|
||||
* (RFC 854 to RFC 861, and others).
|
||||
*/
|
||||
interface TelnetCodes
|
||||
{
|
||||
interface TelnetCodes {
|
||||
/** Command code: Subnegotiation End. */
|
||||
static final byte TELNET_SE = (byte)240;
|
||||
static final byte TELNET_SE = (byte) 240;
|
||||
|
||||
/** Command code: No-op. */
|
||||
static final byte TELNET_NOP = (byte)241;
|
||||
static final byte TELNET_NOP = (byte) 241;
|
||||
|
||||
/** Command code: Data Mark. */
|
||||
static final byte TELNET_DM = (byte)242;
|
||||
static final byte TELNET_DM = (byte) 242;
|
||||
|
||||
/** Command code: Break. */
|
||||
static final byte TELNET_BREAK = (byte)243;
|
||||
static final byte TELNET_BREAK = (byte) 243;
|
||||
|
||||
/** Command code: Interrupt Process. */
|
||||
static final byte TELNET_IP = (byte)244;
|
||||
static final byte TELNET_IP = (byte) 244;
|
||||
|
||||
/** Command code: Abort Output. */
|
||||
static final byte TELNET_AO = (byte)245;
|
||||
static final byte TELNET_AO = (byte) 245;
|
||||
|
||||
/** Command code: Are You There. */
|
||||
static final byte TELNET_AYT = (byte)246;
|
||||
static final byte TELNET_AYT = (byte) 246;
|
||||
|
||||
/** Command code: Erase Character. */
|
||||
static final byte TELNET_EC = (byte)247;
|
||||
static final byte TELNET_EC = (byte) 247;
|
||||
|
||||
/** Command code: Erase Line. */
|
||||
static final byte TELNET_EL = (byte)248;
|
||||
static final byte TELNET_EL = (byte) 248;
|
||||
|
||||
/** Command code: Go Ahead. */
|
||||
static final byte TELNET_GA = (byte)249;
|
||||
static final byte TELNET_GA = (byte) 249;
|
||||
|
||||
/** Command code: Subnegotiation Begin. */
|
||||
static final byte TELNET_SB = (byte)250;
|
||||
static final byte TELNET_SB = (byte) 250;
|
||||
|
||||
/** Command code: Will. */
|
||||
static final byte TELNET_WILL = (byte)251;
|
||||
static final byte TELNET_WILL = (byte) 251;
|
||||
|
||||
/** Command code: Won't. */
|
||||
static final byte TELNET_WONT = (byte)252;
|
||||
static final byte TELNET_WONT = (byte) 252;
|
||||
|
||||
/** Command code: Do. */
|
||||
static final byte TELNET_DO = (byte)253;
|
||||
static final byte TELNET_DO = (byte) 253;
|
||||
|
||||
/** Command code: Don't. */
|
||||
static final byte TELNET_DONT = (byte)254;
|
||||
static final byte TELNET_DONT = (byte) 254;
|
||||
|
||||
/** Command code: Interpret As Command. */
|
||||
static final byte TELNET_IAC = (byte)255;
|
||||
static final byte TELNET_IAC = (byte) 255;
|
||||
|
||||
/** Command code: IS. */
|
||||
static final byte TELNET_IS = 0;
|
||||
|
@ -78,7 +77,6 @@ interface TelnetCodes
|
|||
/** Command code: SEND. */
|
||||
static final byte TELNET_SEND = 1;
|
||||
|
||||
|
||||
/** Option code: Transmit Binary option. */
|
||||
static final byte TELNET_OPTION_TRANSMIT_BINARY = 0;
|
||||
|
||||
|
|
|
@ -32,11 +32,13 @@ import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
|
|||
class TelnetConnectWorker extends Thread {
|
||||
private final ITerminalControl fControl;
|
||||
private final TelnetConnector fConn;
|
||||
protected TelnetConnectWorker(TelnetConnector conn,ITerminalControl control) {
|
||||
|
||||
protected TelnetConnectWorker(TelnetConnector conn, ITerminalControl control) {
|
||||
fControl = control;
|
||||
fConn = conn;
|
||||
fControl.setState(TerminalState.CONNECTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Retry the connect with after a little pause in case the
|
||||
|
@ -48,14 +50,18 @@ class TelnetConnectWorker extends Thread {
|
|||
|
||||
while (remaining >= 0) {
|
||||
// Pause before we re-try if the remaining tries are less than the initial value
|
||||
if (remaining < 10) try { Thread.sleep(500); } catch (InterruptedException e) { /* ignored on purpose */ }
|
||||
if (remaining < 10)
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
/* ignored on purpose */ }
|
||||
|
||||
try {
|
||||
int nTimeout = fConn.getTelnetSettings().getTimeout() * 1000;
|
||||
String strHost = fConn.getTelnetSettings().getHost();
|
||||
int nPort = fConn.getTelnetSettings().getNetworkPort();
|
||||
InetSocketAddress address = new InetSocketAddress(strHost, nPort);
|
||||
Socket socket=new Socket();
|
||||
Socket socket = new Socket();
|
||||
|
||||
socket.connect(address, nTimeout);
|
||||
|
||||
|
@ -74,7 +80,7 @@ class TelnetConnectWorker extends Thread {
|
|||
|
||||
fConn.setSocket(socket);
|
||||
|
||||
TelnetConnection connection=new TelnetConnection(fConn, socket);
|
||||
TelnetConnection connection = new TelnetConnection(fConn, socket);
|
||||
socket.setKeepAlive(true);
|
||||
fConn.setTelnetConnection(connection);
|
||||
connection.start();
|
||||
|
@ -85,21 +91,22 @@ class TelnetConnectWorker extends Thread {
|
|||
// the DNS will fix itself
|
||||
remaining = 0;
|
||||
//Construct error message and signal failed
|
||||
String txt="Unknown host: " + ex.getMessage(); //$NON-NLS-1$
|
||||
connectFailed(txt,"Unknown host: " + ex.getMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String txt = "Unknown host: " + ex.getMessage(); //$NON-NLS-1$
|
||||
connectFailed(txt, "Unknown host: " + ex.getMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} catch (SocketTimeoutException socketTimeoutException) {
|
||||
// Time out occurred. No re-try in this case either. Time out can
|
||||
// be increased by the user. Multiplying the timeout with the remaining
|
||||
// counter is not desired.
|
||||
remaining = 0;
|
||||
// Construct error message and signal failed
|
||||
connectFailed(socketTimeoutException.getMessage(), "Connection Error!\n" + socketTimeoutException.getMessage()); //$NON-NLS-1$
|
||||
connectFailed(socketTimeoutException.getMessage(),
|
||||
"Connection Error!\n" + socketTimeoutException.getMessage()); //$NON-NLS-1$
|
||||
} catch (ConnectException connectException) {
|
||||
// In case of a ConnectException, do a re-try. The server could have been
|
||||
// simply not ready yet and the worker would give up to early. If the terminal
|
||||
// control is already closed (disconnected), don't print "Connection refused" errors
|
||||
if (remaining == 0 && TerminalState.CLOSED != fControl.getState()) {
|
||||
connectFailed(connectException.getMessage(),"Connection refused!"); //$NON-NLS-1$
|
||||
connectFailed(connectException.getMessage(), "Connection refused!"); //$NON-NLS-1$
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
// Any other exception on connect. No re-try in this case either
|
||||
|
@ -107,7 +114,7 @@ class TelnetConnectWorker extends Thread {
|
|||
// Log the exception
|
||||
Logger.logException(exception);
|
||||
// And signal failed
|
||||
connectFailed(exception.getMessage(),""); //$NON-NLS-1$
|
||||
connectFailed(exception.getMessage(), ""); //$NON-NLS-1$
|
||||
} finally {
|
||||
remaining--;
|
||||
}
|
||||
|
|
|
@ -335,7 +335,8 @@ public class TelnetConnection extends Thread implements TelnetCodes {
|
|||
// A "socket closed" exception is normal here. It's caused by the
|
||||
// user clicking the disconnect button on the Terminal view toolbar.
|
||||
|
||||
if (message != null && !message.equalsIgnoreCase("Socket closed") && !message.equalsIgnoreCase("Connection reset")) //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if (message != null && !message.equalsIgnoreCase("Socket closed") //$NON-NLS-1$
|
||||
&& !message.equalsIgnoreCase("Connection reset")) //$NON-NLS-1$
|
||||
{
|
||||
Logger.logException(ex);
|
||||
}
|
||||
|
@ -345,8 +346,14 @@ public class TelnetConnection extends Thread implements TelnetCodes {
|
|||
} finally {
|
||||
// Tell the ITerminalControl object that the connection is closed.
|
||||
terminalControl.setState(TerminalState.CLOSED);
|
||||
try { inputStream.close(); } catch(IOException ioe) { /*ignore*/ }
|
||||
try { outputStream.close(); } catch(IOException ioe) { /*ignore*/ }
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException ioe) {
|
||||
/*ignore*/ }
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException ioe) {
|
||||
/*ignore*/ }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,19 +73,22 @@ public class TelnetConnector extends TerminalConnectorImpl {
|
|||
public TelnetConnector() {
|
||||
this(new TelnetSettings());
|
||||
}
|
||||
|
||||
public TelnetConnector(TelnetSettings settings) {
|
||||
fSettings=settings;
|
||||
fSettings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ITerminalControl control) {
|
||||
super.connect(control);
|
||||
fWidth=-1;
|
||||
fHeight=-1;
|
||||
fWidth = -1;
|
||||
fHeight = -1;
|
||||
// TERM=xterm implies VT100 line wrapping mode
|
||||
control.setVT100LineWrapping(true);
|
||||
TelnetConnectWorker worker = new TelnetConnectWorker(this,control);
|
||||
TelnetConnectWorker worker = new TelnetConnectWorker(this, control);
|
||||
worker.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDisconnect() {
|
||||
if (getSocket() != null) {
|
||||
|
@ -113,31 +116,37 @@ public class TelnetConnector extends TerminalConnectorImpl {
|
|||
}
|
||||
cleanSocket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocalEcho() {
|
||||
if(fTelnetConnection==null)
|
||||
if (fTelnetConnection == null)
|
||||
return false;
|
||||
return fTelnetConnection.localEcho();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTerminalSize(int newWidth, int newHeight) {
|
||||
if(fTelnetConnection!=null && (newWidth!=fWidth || newHeight!=fHeight)) {
|
||||
if (fTelnetConnection != null && (newWidth != fWidth || newHeight != fHeight)) {
|
||||
//avoid excessive communications due to change size requests by caching previous size
|
||||
fTelnetConnection.setTerminalSize(newWidth, newHeight);
|
||||
fWidth=newWidth;
|
||||
fHeight=newHeight;
|
||||
fWidth = newWidth;
|
||||
fHeight = newHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return fInputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getTerminalToRemoteStream() {
|
||||
return fOutputStream;
|
||||
}
|
||||
|
||||
private void setInputStream(InputStream inputStream) {
|
||||
fInputStream = inputStream;
|
||||
}
|
||||
|
||||
private void setOutputStream(OutputStream outputStream) {
|
||||
if (outputStream == null) {
|
||||
fOutputStream = null;
|
||||
|
@ -146,6 +155,7 @@ public class TelnetConnector extends TerminalConnectorImpl {
|
|||
// translate CR to telnet end-of-line sequence - RFC 854
|
||||
fOutputStream = new TelnetOutputStream(outputStream, fSettings.getEndOfLine());
|
||||
}
|
||||
|
||||
Socket getSocket() {
|
||||
return fSocket;
|
||||
}
|
||||
|
@ -154,13 +164,13 @@ public class TelnetConnector extends TerminalConnectorImpl {
|
|||
* sets the socket to null
|
||||
*/
|
||||
void cleanSocket() {
|
||||
fSocket=null;
|
||||
fSocket = null;
|
||||
setInputStream(null);
|
||||
setOutputStream(null);
|
||||
}
|
||||
|
||||
void setSocket(Socket socket) throws IOException {
|
||||
if(socket==null) {
|
||||
if (socket == null) {
|
||||
cleanSocket();
|
||||
} else {
|
||||
fSocket = socket;
|
||||
|
@ -169,33 +179,42 @@ public class TelnetConnector extends TerminalConnectorImpl {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public void setTelnetConnection(TelnetConnection connection) {
|
||||
fTelnetConnection=connection;
|
||||
fTelnetConnection = connection;
|
||||
}
|
||||
|
||||
public void displayTextInTerminal(String text) {
|
||||
fControl.displayTextInTerminal(text);
|
||||
}
|
||||
public OutputStream getRemoteToTerminalOutputStream () {
|
||||
|
||||
public OutputStream getRemoteToTerminalOutputStream() {
|
||||
return fControl.getRemoteToTerminalOutputStream();
|
||||
}
|
||||
|
||||
public void setState(TerminalState state) {
|
||||
fControl.setState(state);
|
||||
}
|
||||
|
||||
public ITelnetSettings getTelnetSettings() {
|
||||
return fSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultSettings() {
|
||||
fSettings.load(new NullSettingsStore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSettingsSummary() {
|
||||
return fSettings.getSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(ISettingsStore store) {
|
||||
fSettings.load(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ISettingsStore store) {
|
||||
fSettings.save(store);
|
||||
|
|
|
@ -28,4 +28,4 @@ public class TelnetMessages extends NLS {
|
|||
*/
|
||||
public static String END_OF_LINE;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,16 +43,13 @@ import org.eclipse.tm.internal.terminal.provisional.api.Logger;
|
|||
*
|
||||
* @author Fran Litterio (francis.litterio@windriver.com)
|
||||
*/
|
||||
class TelnetOption implements TelnetCodes
|
||||
{
|
||||
class TelnetOption implements TelnetCodes {
|
||||
/**
|
||||
* This array of Strings maps an integer TELNET option code value to the symbolic
|
||||
* name of the option. Array elements of the form "?" represent unassigned option
|
||||
* values.
|
||||
*/
|
||||
protected static final String[] optionNames =
|
||||
{
|
||||
"BINARY", // 0 //$NON-NLS-1$
|
||||
protected static final String[] optionNames = { "BINARY", // 0 //$NON-NLS-1$
|
||||
"ECHO", // 1 //$NON-NLS-1$
|
||||
"RECONNECTION", // 2 //$NON-NLS-1$
|
||||
"SUPPRESS GO AHEAD", // 3 //$NON-NLS-1$
|
||||
|
@ -251,8 +248,7 @@ class TelnetOption implements TelnetCodes
|
|||
* @param local Whether this option is for the local or remote endpoint.
|
||||
* @param outputStream A stream used to negotiate with the remote endpoint.
|
||||
*/
|
||||
TelnetOption(byte option, boolean desired, boolean local,
|
||||
OutputStream outputStream) {
|
||||
TelnetOption(byte option, boolean desired, boolean local, OutputStream outputStream) {
|
||||
this.option = option;
|
||||
this.desired = desired;
|
||||
this.local = local;
|
||||
|
@ -333,12 +329,10 @@ class TelnetOption implements TelnetCodes
|
|||
public void negotiate() {
|
||||
if (negotiationState == NEGOTIATION_NOT_STARTED && desired) {
|
||||
if (local) {
|
||||
Logger
|
||||
.log("Starting negotiation for local option " + optionName()); //$NON-NLS-1$
|
||||
Logger.log("Starting negotiation for local option " + optionName()); //$NON-NLS-1$
|
||||
sendWill();
|
||||
} else {
|
||||
Logger
|
||||
.log("Starting negotiation for remote option " + optionName()); //$NON-NLS-1$
|
||||
Logger.log("Starting negotiation for remote option " + optionName()); //$NON-NLS-1$
|
||||
sendDo();
|
||||
}
|
||||
|
||||
|
@ -352,8 +346,7 @@ class TelnetOption implements TelnetCodes
|
|||
*/
|
||||
public void handleWill() {
|
||||
if (negotiationState == NEGOTIATION_DONE && ignoreNegotiation()) {
|
||||
Logger
|
||||
.log("Ignoring superfluous WILL command from remote endpoint."); //$NON-NLS-1$
|
||||
Logger.log("Ignoring superfluous WILL command from remote endpoint."); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -403,8 +396,7 @@ class TelnetOption implements TelnetCodes
|
|||
*/
|
||||
public void handleWont() {
|
||||
if (negotiationState == NEGOTIATION_DONE && ignoreNegotiation()) {
|
||||
Logger
|
||||
.log("Ignoring superfluous WONT command from remote endpoint."); //$NON-NLS-1$
|
||||
Logger.log("Ignoring superfluous WONT command from remote endpoint."); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -481,8 +473,7 @@ class TelnetOption implements TelnetCodes
|
|||
*/
|
||||
public void handleDont() {
|
||||
if (negotiationState == NEGOTIATION_DONE && ignoreNegotiation()) {
|
||||
Logger
|
||||
.log("Ignoring superfluous DONT command from remote endpoint."); //$NON-NLS-1$
|
||||
Logger.log("Ignoring superfluous DONT command from remote endpoint."); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -520,8 +511,7 @@ class TelnetOption implements TelnetCodes
|
|||
case TELNET_OPTION_TERMINAL_TYPE:
|
||||
if (subnegotiationData[1] != TELNET_SEND) {
|
||||
// This should never happen!
|
||||
Logger
|
||||
.log("Invalid TERMINAL-TYPE subnegotiation command from remote endpoint: " + //$NON-NLS-1$
|
||||
Logger.log("Invalid TERMINAL-TYPE subnegotiation command from remote endpoint: " + //$NON-NLS-1$
|
||||
(subnegotiationData[1] & 0xff));
|
||||
break;
|
||||
}
|
||||
|
@ -531,8 +521,7 @@ class TelnetOption implements TelnetCodes
|
|||
//
|
||||
// IAC SB TERMINAL-TYPE IS x t e r m IAC SE
|
||||
|
||||
byte[] terminalTypeData = { TELNET_IAC, TELNET_SB,
|
||||
TELNET_OPTION_TERMINAL_TYPE, TELNET_IS, (byte) 'x',
|
||||
byte[] terminalTypeData = { TELNET_IAC, TELNET_SB, TELNET_OPTION_TERMINAL_TYPE, TELNET_IS, (byte) 'x',
|
||||
(byte) 't', (byte) 'e', (byte) 'r', (byte) 'm', TELNET_IAC, TELNET_SE };
|
||||
|
||||
try {
|
||||
|
@ -545,8 +534,7 @@ class TelnetOption implements TelnetCodes
|
|||
|
||||
default:
|
||||
// This should never happen!
|
||||
Logger
|
||||
.log("SHOULD NOT BE REACHED: Called for option " + optionName()); //$NON-NLS-1$
|
||||
Logger.log("SHOULD NOT BE REACHED: Called for option " + optionName()); //$NON-NLS-1$
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -567,8 +555,7 @@ class TelnetOption implements TelnetCodes
|
|||
// IAC SB NAWS <width-highbyte> <width-lowbyte> <height-highbyte>
|
||||
// <height-lowbyte> IAC SE
|
||||
|
||||
final byte[] NAWSData = { TELNET_IAC, TELNET_SB, TELNET_OPTION_NAWS, 0,
|
||||
0, 0, 0, TELNET_IAC, TELNET_SE };
|
||||
final byte[] NAWSData = { TELNET_IAC, TELNET_SB, TELNET_OPTION_NAWS, 0, 0, 0, 0, TELNET_IAC, TELNET_SE };
|
||||
int width = ((Integer) subnegotiationData[0]).intValue();
|
||||
int height = ((Integer) subnegotiationData[1]).intValue();
|
||||
|
||||
|
@ -577,15 +564,14 @@ class TelnetOption implements TelnetCodes
|
|||
NAWSData[5] = (byte) ((height >>> 8) & 0xff); // High order byte of height.
|
||||
NAWSData[6] = (byte) (height & 0xff); // Low order byte of height.
|
||||
|
||||
Logger
|
||||
.log("sending terminal size to remote endpoint: width = " + width + //$NON-NLS-1$
|
||||
Logger.log("sending terminal size to remote endpoint: width = " + width + //$NON-NLS-1$
|
||||
", height = " + height + "."); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
// Send the NAWS data in a new thread. The current thread is the display
|
||||
// thread, and calls to write() can block, but blocking the display thread
|
||||
// is _bad_ (it hangs the GUI).
|
||||
|
||||
Thread t=new Thread() {
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
@ -602,8 +588,7 @@ class TelnetOption implements TelnetCodes
|
|||
|
||||
default:
|
||||
// This should never happen!
|
||||
Logger
|
||||
.log("SHOULD NOT BE REACHED: Called for option " + optionName()); //$NON-NLS-1$
|
||||
Logger.log("SHOULD NOT BE REACHED: Called for option " + optionName()); //$NON-NLS-1$
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ public class TelnetSettings implements ITelnetSettings {
|
|||
protected String fNetworkPort;
|
||||
protected String fTimeout;
|
||||
protected String fEndOfLine = EOL_CRNUL;
|
||||
private final TelnetProperties fProperties=new TelnetProperties();
|
||||
private final TelnetProperties fProperties = new TelnetProperties();
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return fHost;
|
||||
|
@ -64,7 +65,7 @@ public class TelnetSettings implements ITelnetSettings {
|
|||
public void load(ISettingsStore store) {
|
||||
fHost = store.get("Host", fProperties.getDefaultHost());//$NON-NLS-1$
|
||||
fNetworkPort = store.get("NetworkPort", fProperties.getDefaultNetworkPort());//$NON-NLS-1$
|
||||
fTimeout = store.get("Timeout","10");//$NON-NLS-1$ //$NON-NLS-2$
|
||||
fTimeout = store.get("Timeout", "10");//$NON-NLS-1$ //$NON-NLS-2$
|
||||
fEndOfLine = store.get("EndOfLine", EOL_CRNUL);//$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
@ -79,6 +80,7 @@ public class TelnetSettings implements ITelnetSettings {
|
|||
public TelnetProperties getProperties() {
|
||||
return fProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
try {
|
||||
|
@ -87,6 +89,7 @@ public class TelnetSettings implements ITelnetSettings {
|
|||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
public String getTimeoutString() {
|
||||
return fTimeout;
|
||||
}
|
||||
|
|
|
@ -48,8 +48,9 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
private final TelnetSettings fTerminalSettings;
|
||||
|
||||
public TelnetSettingsPage(TelnetSettings settings) {
|
||||
fTerminalSettings=settings;
|
||||
fTerminalSettings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveSettings() {
|
||||
fTerminalSettings.setHost(fHostText.getText());
|
||||
|
@ -60,30 +61,33 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
|
||||
@Override
|
||||
public void loadSettings() {
|
||||
if(fTerminalSettings!=null) {
|
||||
if (fTerminalSettings != null) {
|
||||
setHost(fTerminalSettings.getHost());
|
||||
setTimeout(fTerminalSettings.getTimeoutString());
|
||||
setNetworkPort(fTerminalSettings.getNetworkPortString());
|
||||
setEndOfLine(fTerminalSettings.getEndOfLine());
|
||||
}
|
||||
}
|
||||
|
||||
private void setHost(String strHost) {
|
||||
if(strHost==null)
|
||||
strHost=""; //$NON-NLS-1$
|
||||
if (strHost == null)
|
||||
strHost = ""; //$NON-NLS-1$
|
||||
fHostText.setText(strHost);
|
||||
|
||||
}
|
||||
|
||||
private void setTimeout(String timeout) {
|
||||
if(timeout==null || timeout.length()==0)
|
||||
timeout="5"; //$NON-NLS-1$
|
||||
if (timeout == null || timeout.length() == 0)
|
||||
timeout = "5"; //$NON-NLS-1$
|
||||
fTimeout.setText(timeout);
|
||||
|
||||
}
|
||||
|
||||
private void setNetworkPort(String strNetworkPort) {
|
||||
if (strNetworkPort!=null) {
|
||||
if (strNetworkPort != null) {
|
||||
String strPortName = getNetworkPortMap().findPortName(strNetworkPort);
|
||||
if(strPortName==null) {
|
||||
strPortName=strNetworkPort; //fallback to verbatim port if not found
|
||||
if (strPortName == null) {
|
||||
strPortName = strNetworkPort; //fallback to verbatim port if not found
|
||||
}
|
||||
int nIndex = fNetworkPortCombo.indexOf(strPortName);
|
||||
|
||||
|
@ -94,21 +98,26 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getNetworkPort() {
|
||||
String portText = fNetworkPortCombo.getText().trim();
|
||||
String mappedPort = getNetworkPortMap().findPort(portText);
|
||||
return mappedPort!=null ? mappedPort : portText;
|
||||
return mappedPort != null ? mappedPort : portText;
|
||||
}
|
||||
|
||||
private NetworkPortMap getNetworkPortMap() {
|
||||
return fTerminalSettings.getProperties().getNetworkPortMap();
|
||||
}
|
||||
|
||||
private void setEndOfLine(String eol) {
|
||||
int idx = fEndOfLineCombo.indexOf(eol);
|
||||
fEndOfLineCombo.select(idx >= 0 ? idx : 0);
|
||||
}
|
||||
|
||||
private String getEndOfLine() {
|
||||
return fEndOfLineCombo.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateSettings() {
|
||||
String message = null;
|
||||
|
@ -119,7 +128,10 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
String m = "Please enter a host IP or name."; //$NON-NLS-1$
|
||||
int mt = IMessageProvider.INFORMATION;
|
||||
updateControlDecoration(fHostText, m, mt);
|
||||
if (mt > messageType) { message = m; messageType = mt; }
|
||||
if (mt > messageType) {
|
||||
message = m;
|
||||
messageType = mt;
|
||||
}
|
||||
|
||||
valid = false;
|
||||
} else {
|
||||
|
@ -132,7 +144,10 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
String m = "Invalid network port. Must be between 0 and 65535."; //$NON-NLS-1$
|
||||
int mt = IMessageProvider.ERROR;
|
||||
updateControlDecoration(fNetworkPortCombo, m, mt);
|
||||
if (mt > messageType) { message = m; messageType = mt; }
|
||||
if (mt > messageType) {
|
||||
message = m;
|
||||
messageType = mt;
|
||||
}
|
||||
|
||||
valid = false;
|
||||
} else {
|
||||
|
@ -144,7 +159,10 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
String m = "Invalid timeout. Must be greater than 0."; //$NON-NLS-1$
|
||||
int mt = IMessageProvider.ERROR;
|
||||
updateControlDecoration(fTimeout, m, mt);
|
||||
if (mt > messageType) { message = m; messageType = mt; }
|
||||
if (mt > messageType) {
|
||||
message = m;
|
||||
messageType = mt;
|
||||
}
|
||||
|
||||
valid = false;
|
||||
} else {
|
||||
|
@ -236,6 +254,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
|
|||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
private void loadCombo(Combo ctlCombo, List<String> table) {
|
||||
for (Iterator<String> iter = table.iterator(); iter.hasNext();) {
|
||||
String label = iter.next();
|
||||
|
|
|
@ -59,7 +59,8 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
|
|||
panel.setLayoutData(data);
|
||||
|
||||
// Create the host selection combo
|
||||
if (isWithoutSelection()) createHostsUI(panel, true);
|
||||
if (isWithoutSelection())
|
||||
createHostsUI(panel, true);
|
||||
|
||||
TelnetConnector conn = new TelnetConnector();
|
||||
telnetSettings = (TelnetSettings) conn.getTelnetSettings();
|
||||
|
@ -69,7 +70,7 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
|
|||
|
||||
telnetSettingsPage = new TelnetSettingsPage(telnetSettings);
|
||||
if (telnetSettingsPage instanceof AbstractSettingsPage) {
|
||||
((AbstractSettingsPage)telnetSettingsPage).setHasControlDecoration(true);
|
||||
((AbstractSettingsPage) telnetSettingsPage).setHasControlDecoration(true);
|
||||
}
|
||||
telnetSettingsPage.createControl(panel);
|
||||
|
||||
|
@ -78,7 +79,8 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
|
|||
|
||||
@Override
|
||||
public void onSettingsPageChanged(Control control) {
|
||||
if (getContainer() != null) getContainer().validate();
|
||||
if (getContainer() != null)
|
||||
getContainer().validate();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -93,25 +95,31 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
|
|||
*/
|
||||
@Override
|
||||
public void setupData(Map<String, Object> data) {
|
||||
if (data == null || telnetSettings == null || telnetSettingsPage == null) return;
|
||||
if (data == null || telnetSettings == null || telnetSettingsPage == null)
|
||||
return;
|
||||
|
||||
String value = (String)data.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
if (value != null) telnetSettings.setHost(value);
|
||||
String value = (String) data.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
if (value != null)
|
||||
telnetSettings.setHost(value);
|
||||
|
||||
Object v = data.get(ITerminalsConnectorConstants.PROP_IP_PORT);
|
||||
value = v != null ? v.toString() : null;
|
||||
if (value != null) telnetSettings.setNetworkPort(value);
|
||||
if (value != null)
|
||||
telnetSettings.setNetworkPort(value);
|
||||
|
||||
v = data.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
|
||||
value = v != null ? v.toString() : null;
|
||||
if (value != null) telnetSettings.setTimeout(value);
|
||||
if (value != null)
|
||||
telnetSettings.setTimeout(value);
|
||||
|
||||
v = data.get(ITerminalsConnectorConstants.PROP_TELNET_EOL);
|
||||
value = v != null ? v.toString() : null;
|
||||
if (value != null) telnetSettings.setEndOfLine(value);
|
||||
if (value != null)
|
||||
telnetSettings.setEndOfLine(value);
|
||||
|
||||
value = (String)data.get(ITerminalsConnectorConstants.PROP_ENCODING);
|
||||
if (value != null) setEncoding(value);
|
||||
value = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING);
|
||||
if (value != null)
|
||||
setEncoding(value);
|
||||
|
||||
telnetSettingsPage.loadSettings();
|
||||
}
|
||||
|
@ -121,13 +129,15 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
|
|||
*/
|
||||
@Override
|
||||
public void extractData(Map<String, Object> data) {
|
||||
if (data == null) return;
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
// set the terminal connector id for ssh
|
||||
data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.terminal.connector.telnet.TelnetConnector"); //$NON-NLS-1$
|
||||
data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID,
|
||||
"org.eclipse.tm.terminal.connector.telnet.TelnetConnector"); //$NON-NLS-1$
|
||||
|
||||
telnetSettingsPage.saveSettings();
|
||||
data.put(ITerminalsConnectorConstants.PROP_IP_HOST,telnetSettings.getHost());
|
||||
data.put(ITerminalsConnectorConstants.PROP_IP_HOST, telnetSettings.getHost());
|
||||
data.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.valueOf(telnetSettings.getNetworkPort()));
|
||||
data.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.valueOf(telnetSettings.getTimeout()));
|
||||
data.put(ITerminalsConnectorConstants.PROP_TELNET_EOL, telnetSettings.getEndOfLine());
|
||||
|
@ -138,9 +148,9 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
|
|||
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected void fillSettingsForHost(String host){
|
||||
if (host != null && host.length() != 0){
|
||||
if (hostSettingsMap.containsKey(host)){
|
||||
protected void fillSettingsForHost(String host) {
|
||||
if (host != null && host.length() != 0) {
|
||||
if (hostSettingsMap.containsKey(host)) {
|
||||
Map<String, String> hostSettings = hostSettingsMap.get(host);
|
||||
if (hostSettings.get(ITerminalsConnectorConstants.PROP_IP_HOST) != null) {
|
||||
telnetSettings.setHost(hostSettings.get(ITerminalsConnectorConstants.PROP_IP_HOST));
|
||||
|
@ -171,18 +181,20 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
|
|||
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean)
|
||||
*/
|
||||
@Override
|
||||
protected void saveSettingsForHost(boolean add){
|
||||
protected void saveSettingsForHost(boolean add) {
|
||||
String host = getHostFromSettings();
|
||||
if(host != null && host.length() != 0) {
|
||||
if (host != null && host.length() != 0) {
|
||||
Map<String, String> hostSettings = hostSettingsMap.get(host);
|
||||
if (hostSettings == null && !add) {
|
||||
hostSettings=new HashMap<String, String>();
|
||||
hostSettings = new HashMap<String, String>();
|
||||
hostSettingsMap.put(host, hostSettings);
|
||||
}
|
||||
if (hostSettings != null) {
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, telnetSettings.getHost());
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(telnetSettings.getNetworkPort()));
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(telnetSettings.getTimeout()));
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT,
|
||||
Integer.toString(telnetSettings.getNetworkPort()));
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT,
|
||||
Integer.toString(telnetSettings.getTimeout()));
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_TELNET_EOL, telnetSettings.getEndOfLine());
|
||||
if (getEncoding() != null) {
|
||||
hostSettings.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
|
||||
|
@ -195,7 +207,7 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
|
|||
* @see org.eclipse.tm.terminal.view.ui.panels.AbstractConfigurationPanel#isValid()
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(){
|
||||
public boolean isValid() {
|
||||
return isEncodingValid() && telnetSettingsPage.validateSettings();
|
||||
}
|
||||
|
||||
|
|
|
@ -94,15 +94,16 @@ public class TelnetLauncherDelegate extends AbstractLauncherDelegate {
|
|||
private String getTerminalTitle(Map<String, Object> properties) {
|
||||
// Try to see if the user set a title explicitly via the properties map.
|
||||
String title = getDefaultTerminalTitle(properties);
|
||||
if (title != null) return title;
|
||||
if (title != null)
|
||||
return title;
|
||||
|
||||
//No title,try to calculate the title
|
||||
String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
|
||||
if (host != null) {
|
||||
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
String date = format.format(new Date(System.currentTimeMillis()));
|
||||
return NLS.bind(Messages.TelnetLauncherDelegate_terminalTitle, new String[]{host, date});
|
||||
return NLS.bind(Messages.TelnetLauncherDelegate_terminalTitle, new String[] { host, date });
|
||||
}
|
||||
|
||||
return Messages.TelnetLauncherDelegate_terminalTitle_default;
|
||||
|
@ -127,21 +128,23 @@ public class TelnetLauncherDelegate extends AbstractLauncherDelegate {
|
|||
Assert.isNotNull(properties);
|
||||
|
||||
// Check for the terminal connector id
|
||||
String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
|
||||
if (connectorId == null) connectorId = "org.eclipse.tm.terminal.connector.telnet.TelnetConnector"; //$NON-NLS-1$
|
||||
String connectorId = (String) properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
|
||||
if (connectorId == null)
|
||||
connectorId = "org.eclipse.tm.terminal.connector.telnet.TelnetConnector"; //$NON-NLS-1$
|
||||
|
||||
// Extract the telnet properties
|
||||
String host = (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
String host = (String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST);
|
||||
Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT);
|
||||
String port = value != null ? value.toString() : null;
|
||||
value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
|
||||
String timeout = value != null ? value.toString() : null;
|
||||
String endOfLine = (String)properties.get(ITerminalsConnectorConstants.PROP_TELNET_EOL);
|
||||
String endOfLine = (String) properties.get(ITerminalsConnectorConstants.PROP_TELNET_EOL);
|
||||
|
||||
int portOffset = 0;
|
||||
if (properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET) instanceof Integer) {
|
||||
portOffset = ((Integer)properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue();
|
||||
if (portOffset < 0) portOffset = 0;
|
||||
portOffset = ((Integer) properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET)).intValue();
|
||||
if (portOffset < 0)
|
||||
portOffset = 0;
|
||||
}
|
||||
|
||||
// The real port to connect to is port + portOffset
|
||||
|
|
|
@ -33,12 +33,16 @@ public class TelnetMementoHandler implements IMementoHandler {
|
|||
|
||||
// Do not write the terminal title to the memento -> needs to
|
||||
// be recreated at the time of restoration.
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_IP_HOST, (String)properties.get(ITerminalsConnectorConstants.PROP_IP_HOST));
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_IP_HOST,
|
||||
(String) properties.get(ITerminalsConnectorConstants.PROP_IP_HOST));
|
||||
Object value = properties.get(ITerminalsConnectorConstants.PROP_IP_PORT);
|
||||
memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT, value instanceof Integer ? ((Integer)value).intValue() : -1);
|
||||
memento.putInteger(ITerminalsConnectorConstants.PROP_IP_PORT,
|
||||
value instanceof Integer ? ((Integer) value).intValue() : -1);
|
||||
value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
|
||||
memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT, value instanceof Integer ? ((Integer)value).intValue() : -1);
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_ENCODING, (String)properties.get(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
memento.putInteger(ITerminalsConnectorConstants.PROP_TIMEOUT,
|
||||
value instanceof Integer ? ((Integer) value).intValue() : -1);
|
||||
memento.putString(ITerminalsConnectorConstants.PROP_ENCODING,
|
||||
(String) properties.get(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -50,9 +54,13 @@ public class TelnetMementoHandler implements IMementoHandler {
|
|||
Assert.isNotNull(properties);
|
||||
|
||||
// Restore the terminal properties from the memento
|
||||
properties.put(ITerminalsConnectorConstants.PROP_IP_HOST, memento.getString(ITerminalsConnectorConstants.PROP_IP_HOST));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_IP_PORT, memento.getInteger(ITerminalsConnectorConstants.PROP_IP_PORT));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_TIMEOUT, memento.getInteger(ITerminalsConnectorConstants.PROP_TIMEOUT));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_ENCODING, memento.getString(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_IP_HOST,
|
||||
memento.getString(ITerminalsConnectorConstants.PROP_IP_HOST));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_IP_PORT,
|
||||
memento.getInteger(ITerminalsConnectorConstants.PROP_IP_PORT));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_TIMEOUT,
|
||||
memento.getInteger(ITerminalsConnectorConstants.PROP_TIMEOUT));
|
||||
properties.put(ITerminalsConnectorConstants.PROP_ENCODING,
|
||||
memento.getString(ITerminalsConnectorConstants.PROP_ENCODING));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ public class TerminalConnector implements ITerminalConnector {
|
|||
*/
|
||||
TerminalConnectorImpl makeConnector() throws Exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* The factory for creating impl instances.
|
||||
*/
|
||||
|
@ -95,6 +96,7 @@ public class TerminalConnector implements ITerminalConnector {
|
|||
* This keeps the value until the connector is created.
|
||||
*/
|
||||
private ISettingsStore fStore;
|
||||
|
||||
/**
|
||||
* Constructor for the terminal connector.
|
||||
*
|
||||
|
@ -104,119 +106,138 @@ public class TerminalConnector implements ITerminalConnector {
|
|||
* this ID.
|
||||
* @param name translatable name to display the connector in the UI.
|
||||
*/
|
||||
public TerminalConnector(TerminalConnector.Factory terminalConnectorFactory, String id, String name, boolean hidden) {
|
||||
public TerminalConnector(TerminalConnector.Factory terminalConnectorFactory, String id, String name,
|
||||
boolean hidden) {
|
||||
fTerminalConnectorFactory = terminalConnectorFactory;
|
||||
fId = id;
|
||||
fName = name;
|
||||
fHidden = hidden;
|
||||
}
|
||||
|
||||
public String getInitializationErrorMessage() {
|
||||
getConnectorImpl();
|
||||
if(fException!=null)
|
||||
if (fException != null)
|
||||
return fException.getLocalizedMessage();
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return fId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return fName;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return fHidden;
|
||||
}
|
||||
|
||||
private TerminalConnectorImpl getConnectorImpl() {
|
||||
if(!isInitialized()) {
|
||||
if (!isInitialized()) {
|
||||
try {
|
||||
fConnector=fTerminalConnectorFactory.makeConnector();
|
||||
fConnector = fTerminalConnectorFactory.makeConnector();
|
||||
fConnector.initialize();
|
||||
} catch (Exception e) {
|
||||
fException=e;
|
||||
fConnector=new TerminalConnectorImpl(){
|
||||
fException = e;
|
||||
fConnector = new TerminalConnectorImpl() {
|
||||
public void connect(ITerminalControl control) {
|
||||
// super.connect(control);
|
||||
control.setState(TerminalState.CLOSED);
|
||||
control.setMsg(getInitializationErrorMessage());
|
||||
}
|
||||
|
||||
public OutputStream getTerminalToRemoteStream() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSettingsSummary() {
|
||||
return null;
|
||||
}};
|
||||
}
|
||||
};
|
||||
// that's the place where we log the exception
|
||||
Logger.logException(e);
|
||||
}
|
||||
if(fConnector!=null && fStore!=null)
|
||||
if (fConnector != null && fStore != null)
|
||||
fConnector.load(fStore);
|
||||
}
|
||||
return fConnector;
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return fConnector!=null || fException!=null;
|
||||
return fConnector != null || fException != null;
|
||||
}
|
||||
|
||||
public void connect(ITerminalControl control) {
|
||||
getConnectorImpl().connect(control);
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
getConnectorImpl().disconnect();
|
||||
}
|
||||
|
||||
public OutputStream getTerminalToRemoteStream() {
|
||||
return getConnectorImpl().getTerminalToRemoteStream();
|
||||
}
|
||||
|
||||
public String getSettingsSummary() {
|
||||
if(fConnector!=null)
|
||||
if (fConnector != null)
|
||||
return getConnectorImpl().getSettingsSummary();
|
||||
else
|
||||
return TerminalMessages.NotInitialized;
|
||||
}
|
||||
|
||||
public boolean isLocalEcho() {
|
||||
return getConnectorImpl().isLocalEcho();
|
||||
}
|
||||
|
||||
public void load(ISettingsStore store) {
|
||||
if(fConnector==null) {
|
||||
fStore=store;
|
||||
if (fConnector == null) {
|
||||
fStore = store;
|
||||
} else {
|
||||
getConnectorImpl().load(store);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultSettings() {
|
||||
getConnectorImpl().setDefaultSettings();
|
||||
}
|
||||
|
||||
public void save(ISettingsStore store) {
|
||||
// no need to save the settings: it cannot have changed
|
||||
// because we are not initialized....
|
||||
if(fConnector!=null)
|
||||
if (fConnector != null)
|
||||
getConnectorImpl().save(store);
|
||||
}
|
||||
|
||||
public void setTerminalSize(int newWidth, int newHeight) {
|
||||
// we assume that setTerminalSize is called also after
|
||||
// the terminal has been initialized. Else we would have to cache
|
||||
// the values....
|
||||
if(fConnector!=null) {
|
||||
if (fConnector != null) {
|
||||
fConnector.setTerminalSize(newWidth, newHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getAdapter(Class adapter) {
|
||||
TerminalConnectorImpl connector=null;
|
||||
if(isInitialized())
|
||||
connector=getConnectorImpl();
|
||||
TerminalConnectorImpl connector = null;
|
||||
if (isInitialized())
|
||||
connector = getConnectorImpl();
|
||||
// if we cannot create the connector then we cannot adapt...
|
||||
if(connector!=null) {
|
||||
if (connector != null) {
|
||||
// maybe the connector is adaptable
|
||||
if(connector instanceof IAdaptable) {
|
||||
Object result =((IAdaptable)connector).getAdapter(adapter);
|
||||
if (connector instanceof IAdaptable) {
|
||||
Object result = ((IAdaptable) connector).getAdapter(adapter);
|
||||
// Not sure if the next block is needed....
|
||||
if(result==null)
|
||||
if (result == null)
|
||||
//defer to the platform
|
||||
result= Platform.getAdapterManager().getAdapter(connector, adapter);
|
||||
if(result!=null)
|
||||
result = Platform.getAdapterManager().getAdapter(connector, adapter);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
// maybe the real adapter is what we need....
|
||||
if(adapter.isInstance(connector))
|
||||
if (adapter.isInstance(connector))
|
||||
return connector;
|
||||
}
|
||||
// maybe we have to be adapted....
|
||||
|
|
|
@ -29,19 +29,22 @@ public class TerminalToRemoteInjectionOutputStream extends FilterOutputStream {
|
|||
*/
|
||||
static abstract public class Interceptor {
|
||||
protected OutputStream fOriginal;
|
||||
|
||||
/**
|
||||
* @param original the injection into the original stream begins
|
||||
* @throws IOException
|
||||
*/
|
||||
public void begin(OutputStream original) throws IOException {
|
||||
fOriginal=original;
|
||||
fOriginal = original;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b a byte was written to the {@link TerminalToRemoteInjectionOutputStream}.
|
||||
* @throws IOException
|
||||
*/
|
||||
public void write(int b) throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b bytes written to the {@link TerminalToRemoteInjectionOutputStream}.
|
||||
* @param off the start offset in the data.
|
||||
|
@ -50,78 +53,95 @@ public class TerminalToRemoteInjectionOutputStream extends FilterOutputStream {
|
|||
*/
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* The injection into the normal stream ends.
|
||||
* @throws IOException
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
}
|
||||
}
|
||||
|
||||
static public class BufferInterceptor extends Interceptor {
|
||||
private final ByteArrayOutputStream fBuffer=new ByteArrayOutputStream();
|
||||
private final ByteArrayOutputStream fBuffer = new ByteArrayOutputStream();
|
||||
|
||||
public void close() throws IOException {
|
||||
fOriginal.write(fBuffer.toByteArray());
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
fBuffer.write(b, off, len);
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
fBuffer.write(b);
|
||||
}
|
||||
}
|
||||
|
||||
private class TerminalFilterOutputStream extends OutputStream {
|
||||
final private Object fLock=TerminalToRemoteInjectionOutputStream.this;
|
||||
final private Object fLock = TerminalToRemoteInjectionOutputStream.this;
|
||||
|
||||
public void close() throws IOException {
|
||||
synchronized(fLock) {
|
||||
if(fInjection==this) {
|
||||
synchronized (fLock) {
|
||||
if (fInjection == this) {
|
||||
flush();
|
||||
ungrabOutput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
synchronized(fLock) {
|
||||
synchronized (fLock) {
|
||||
checkStream();
|
||||
out.write(b, off, len);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(byte[] b) throws IOException {
|
||||
synchronized(fLock) {
|
||||
synchronized (fLock) {
|
||||
checkStream();
|
||||
out.write(b);
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
synchronized(fLock) {
|
||||
synchronized (fLock) {
|
||||
checkStream();
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
synchronized(fLock) {
|
||||
synchronized (fLock) {
|
||||
checkStream();
|
||||
out.write(b);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStream() throws IOException {
|
||||
if(fInjection!=this)
|
||||
if (fInjection != this)
|
||||
throw new IOException("Stream is closed"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
private Interceptor fInterceptor;
|
||||
private TerminalFilterOutputStream fInjection;
|
||||
|
||||
public TerminalToRemoteInjectionOutputStream(OutputStream out) {
|
||||
super(out);
|
||||
}
|
||||
|
||||
synchronized protected void ungrabOutput() throws IOException {
|
||||
if(fInterceptor!=null) {
|
||||
if (fInterceptor != null) {
|
||||
fInterceptor.close();
|
||||
fInterceptor=null;
|
||||
fInjection=null;
|
||||
fInterceptor = null;
|
||||
fInjection = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* There can only be one injection stream active at a time. You must call close on the
|
||||
* returned output stream to end the injection.
|
||||
|
@ -130,14 +150,15 @@ public class TerminalToRemoteInjectionOutputStream extends FilterOutputStream {
|
|||
* @throws IOException
|
||||
*/
|
||||
public synchronized OutputStream grabOutput(Interceptor interceptor) throws IOException {
|
||||
if(fInjection!=null) {
|
||||
if (fInjection != null) {
|
||||
throw new IOException("Buffer in use"); //$NON-NLS-1$
|
||||
}
|
||||
fInterceptor=interceptor;
|
||||
fInterceptor = interceptor;
|
||||
fInterceptor.begin(out);
|
||||
fInjection=new TerminalFilterOutputStream();
|
||||
fInjection = new TerminalFilterOutputStream();
|
||||
return fInjection;
|
||||
}
|
||||
|
||||
/** See {@link #grabOutput(TerminalToRemoteInjectionOutputStream.Interceptor)}.
|
||||
* @return injection output stream
|
||||
* @throws IOException
|
||||
|
@ -145,25 +166,29 @@ public class TerminalToRemoteInjectionOutputStream extends FilterOutputStream {
|
|||
public synchronized OutputStream grabOutput() throws IOException {
|
||||
return grabOutput(new BufferInterceptor());
|
||||
}
|
||||
|
||||
synchronized public void close() throws IOException {
|
||||
if(fInjection!=null) {
|
||||
if (fInjection != null) {
|
||||
fInjection.close();
|
||||
}
|
||||
super.close();
|
||||
}
|
||||
|
||||
synchronized public void flush() throws IOException {
|
||||
if(fInterceptor!=null)
|
||||
if (fInterceptor != null)
|
||||
fInterceptor.flush();
|
||||
out.flush();
|
||||
}
|
||||
|
||||
synchronized public void write(byte[] b, int off, int len) throws IOException {
|
||||
if(fInterceptor!=null)
|
||||
if (fInterceptor != null)
|
||||
fInterceptor.write(b, off, len);
|
||||
else
|
||||
out.write(b, off, len);
|
||||
}
|
||||
|
||||
synchronized public void write(int b) throws IOException {
|
||||
if(fInterceptor!=null)
|
||||
if (fInterceptor != null)
|
||||
fInterceptor.write(b);
|
||||
else
|
||||
out.write(b);
|
||||
|
|
|
@ -41,8 +41,6 @@ import org.eclipse.swt.widgets.Sash;
|
|||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Manages the Command History for the command line input
|
||||
* of the terminal control.
|
||||
|
@ -60,16 +58,16 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
private class FieldAssist implements IContentProposalProvider {
|
||||
|
||||
public IContentProposal[] getProposals(String contents, int position) {
|
||||
String prefix=contents.substring(0, position);
|
||||
List<Proposal> result=new ArrayList<Proposal>();
|
||||
String prefix = contents.substring(0, position);
|
||||
List<Proposal> result = new ArrayList<Proposal>();
|
||||
// show an entry only once
|
||||
Set<String> seen=new HashSet<String>();
|
||||
Set<String> seen = new HashSet<String>();
|
||||
for (Iterator<String> iterator = fHistory.iterator(); iterator.hasNext();) {
|
||||
String history = iterator.next();
|
||||
if(history.startsWith(prefix) && !seen.contains(history)) {
|
||||
if (history.startsWith(prefix) && !seen.contains(history)) {
|
||||
// the content is the rest of the history item
|
||||
String content=history.substring(prefix.length());
|
||||
result.add(new Proposal(content,history));
|
||||
String content = history.substring(prefix.length());
|
||||
result.add(new Proposal(content, history));
|
||||
// don't add this proposal again
|
||||
seen.add(history);
|
||||
}
|
||||
|
@ -78,14 +76,17 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Proposal implements IContentProposal {
|
||||
|
||||
private final String fContent;
|
||||
private final String fLabel;
|
||||
|
||||
Proposal(String content, String label) {
|
||||
fContent= content;
|
||||
fLabel= label;
|
||||
fContent = content;
|
||||
fLabel = label;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return fContent;
|
||||
}
|
||||
|
@ -103,7 +104,7 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
}
|
||||
}
|
||||
|
||||
final List<String> fHistory=new ArrayList<String>();
|
||||
final List<String> fHistory = new ArrayList<String>();
|
||||
/**
|
||||
* Keeps a modifiable history while in history editing mode
|
||||
*/
|
||||
|
@ -111,7 +112,7 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
/**
|
||||
* The current position in the edit history
|
||||
*/
|
||||
private int fEditHistoryPos=0;
|
||||
private int fEditHistoryPos = 0;
|
||||
/**
|
||||
* The limit of the history.
|
||||
*/
|
||||
|
@ -122,9 +123,11 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
private Text fInputField;
|
||||
private Sash fSash;
|
||||
private Composite fPanel;
|
||||
|
||||
public CommandInputFieldWithHistory(int maxHistorySize) {
|
||||
fMaxSize=maxHistorySize;
|
||||
fMaxSize = maxHistorySize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a line to the history.
|
||||
* @param line The line to be added to the history.
|
||||
|
@ -132,16 +135,17 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
protected void pushLine(String line) {
|
||||
endHistoryMode();
|
||||
// anything to remember?
|
||||
if(line==null || line.trim().length()==0)
|
||||
if (line == null || line.trim().length() == 0)
|
||||
return;
|
||||
fHistory.add(0,line);
|
||||
fHistory.add(0, line);
|
||||
// ignore if the same as last
|
||||
if(fHistory.size()>1 && line.equals(fHistory.get(1)))
|
||||
if (fHistory.size() > 1 && line.equals(fHistory.get(1)))
|
||||
fHistory.remove(0);
|
||||
// limit the history size.
|
||||
if(fHistory.size()>=fMaxSize)
|
||||
fHistory.remove(fHistory.size()-1);
|
||||
if (fHistory.size() >= fMaxSize)
|
||||
fHistory.remove(fHistory.size() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the history
|
||||
* @param history or null
|
||||
|
@ -149,34 +153,36 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
public void setHistory(String history) {
|
||||
endHistoryMode();
|
||||
fHistory.clear();
|
||||
if(history==null)
|
||||
if (history == null)
|
||||
return;
|
||||
// add history entries separated by '\n'
|
||||
// fHistory.addAll(Arrays.asList(history.split("\n"))); //$NON-NLS-1$
|
||||
//<J2ME CDC-1.1 Foundation-1.1 variant>
|
||||
StringTokenizer tok=new StringTokenizer(history,"\n"); //$NON-NLS-1$
|
||||
while(tok.hasMoreElements())
|
||||
StringTokenizer tok = new StringTokenizer(history, "\n"); //$NON-NLS-1$
|
||||
while (tok.hasMoreElements())
|
||||
fHistory.add((String) tok.nextElement());
|
||||
//</J2ME CDC-1.1 Foundation-1.1 variant>
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current content of the history buffer and new line separated list
|
||||
*/
|
||||
public String getHistory() {
|
||||
StringBuffer buff=new StringBuffer();
|
||||
boolean sep=false;
|
||||
StringBuffer buff = new StringBuffer();
|
||||
boolean sep = false;
|
||||
for (Iterator<String> iterator = fHistory.iterator(); iterator.hasNext();) {
|
||||
String line=iterator.next();
|
||||
if(line.length()>0) {
|
||||
if(sep)
|
||||
String line = iterator.next();
|
||||
if (line.length() > 0) {
|
||||
if (sep)
|
||||
buff.append("\n"); //$NON-NLS-1$
|
||||
else
|
||||
sep=true;
|
||||
sep = true;
|
||||
buff.append(line);
|
||||
}
|
||||
}
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param currLine Line of text to be moved in history
|
||||
* @param count (+1 or -1) for forward and backward movement. -1 goes back
|
||||
|
@ -184,22 +190,23 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
* if the limit is reached.
|
||||
*/
|
||||
public String move(String currLine, int count) {
|
||||
if(!inHistoryMode()) {
|
||||
fEditedHistory=new ArrayList<Object>(fHistory.size()+1);
|
||||
if (!inHistoryMode()) {
|
||||
fEditedHistory = new ArrayList<Object>(fHistory.size() + 1);
|
||||
fEditedHistory.add(currLine);
|
||||
fEditedHistory.addAll(fHistory);
|
||||
fEditHistoryPos=0;
|
||||
fEditHistoryPos = 0;
|
||||
}
|
||||
fEditedHistory.set(fEditHistoryPos,currLine);
|
||||
if(fEditHistoryPos+count>=fEditedHistory.size())
|
||||
fEditedHistory.set(fEditHistoryPos, currLine);
|
||||
if (fEditHistoryPos + count >= fEditedHistory.size())
|
||||
return null;
|
||||
if(fEditHistoryPos+count<0)
|
||||
if (fEditHistoryPos + count < 0)
|
||||
return null;
|
||||
fEditHistoryPos+=count;
|
||||
fEditHistoryPos += count;
|
||||
return (String) fEditedHistory.get(fEditHistoryPos);
|
||||
}
|
||||
|
||||
private boolean inHistoryMode() {
|
||||
return fEditedHistory!=null;
|
||||
return fEditedHistory != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,41 +214,43 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
* @return the string to be shown in the command line
|
||||
*/
|
||||
protected String escape() {
|
||||
if(!inHistoryMode())
|
||||
if (!inHistoryMode())
|
||||
return null;
|
||||
String line= (String) fEditedHistory.get(0);
|
||||
String line = (String) fEditedHistory.get(0);
|
||||
endHistoryMode();
|
||||
return line;
|
||||
}
|
||||
|
||||
/**
|
||||
* End history editing
|
||||
*/
|
||||
private void endHistoryMode() {
|
||||
fEditedHistory=null;
|
||||
fEditHistoryPos=0;
|
||||
fEditedHistory = null;
|
||||
fEditHistoryPos = 0;
|
||||
}
|
||||
public void createControl(final Composite parent,final ITerminalViewControl terminal) {
|
||||
// fSash = new Sash(parent,SWT.HORIZONTAL|SWT.SMOOTH);
|
||||
fSash = new Sash(parent,SWT.HORIZONTAL);
|
||||
|
||||
public void createControl(final Composite parent, final ITerminalViewControl terminal) {
|
||||
// fSash = new Sash(parent,SWT.HORIZONTAL|SWT.SMOOTH);
|
||||
fSash = new Sash(parent, SWT.HORIZONTAL);
|
||||
final GridData gd_sash = new GridData(SWT.FILL, SWT.CENTER, true, false);
|
||||
gd_sash.heightHint=5;
|
||||
gd_sash.heightHint = 5;
|
||||
fSash.setLayoutData(gd_sash);
|
||||
fSash.addListener (SWT.Selection, new Listener () {
|
||||
public void handleEvent (Event e) {
|
||||
fSash.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
if (e.detail == SWT.DRAG) {
|
||||
// don't redraw during drag, it causes paint errors - bug 220971
|
||||
return;
|
||||
}
|
||||
// no idea why this is needed
|
||||
GridData gdata = (GridData) fInputField.getLayoutData();
|
||||
Rectangle sashRect = fSash.getBounds ();
|
||||
Rectangle containerRect = parent.getClientArea ();
|
||||
Rectangle sashRect = fSash.getBounds();
|
||||
Rectangle containerRect = parent.getClientArea();
|
||||
|
||||
int h=fInputField.getLineHeight();
|
||||
int h = fInputField.getLineHeight();
|
||||
// make sure the input filed height is a multiple of the line height
|
||||
gdata.heightHint = Math.max(((containerRect.height-e.y-sashRect.height)/h)*h,h);
|
||||
gdata.heightHint = Math.max(((containerRect.height - e.y - sashRect.height) / h) * h, h);
|
||||
// do not show less then one line
|
||||
e.y=Math.min(e.y,containerRect.height-h);
|
||||
e.y = Math.min(e.y, containerRect.height - h);
|
||||
fInputField.setLayoutData(gdata);
|
||||
parent.layout();
|
||||
// else the content assist icon will be replicated
|
||||
|
@ -250,17 +259,20 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
});
|
||||
fPanel = new Composite(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.marginWidth = 0; layout.marginHeight = 0; layout.marginTop = 0; layout.marginBottom = 2;
|
||||
layout.marginWidth = 0;
|
||||
layout.marginHeight = 0;
|
||||
layout.marginTop = 0;
|
||||
layout.marginBottom = 2;
|
||||
fPanel.setLayout(layout);
|
||||
fPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
fInputField=new Text(fPanel, SWT.MULTI|SWT.BORDER|SWT.WRAP|SWT.V_SCROLL);
|
||||
GridData data=new GridData(SWT.FILL, SWT.FILL, true, false);
|
||||
boolean installDecoration=true;
|
||||
if(installDecoration) {
|
||||
fInputField = new Text(fPanel, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
|
||||
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
|
||||
boolean installDecoration = true;
|
||||
if (installDecoration) {
|
||||
// The ContentAssistCommandAdapter says: "The client is responsible for
|
||||
// ensuring that adequate space is reserved for the decoration."
|
||||
// TODO: what is the "adequate space"???
|
||||
data.horizontalIndent=6;
|
||||
data.horizontalIndent = 6;
|
||||
}
|
||||
fInputField.setLayoutData(data);
|
||||
fInputField.setFont(terminal.getFont());
|
||||
|
@ -268,57 +280,56 @@ public class CommandInputFieldWithHistory implements ICommandInputField {
|
|||
// Else the ENTER key is sent *first* to the input field
|
||||
// and then to the field assist popup.
|
||||
// (https://bugs.eclipse.org/bugs/show_bug.cgi?id=211659)
|
||||
new ContentAssistCommandAdapter(
|
||||
fInputField,
|
||||
new TextContentAdapter(),
|
||||
new FieldAssist(),
|
||||
null,
|
||||
null,
|
||||
new ContentAssistCommandAdapter(fInputField, new TextContentAdapter(), new FieldAssist(), null, null,
|
||||
installDecoration);
|
||||
fInputField.addKeyListener(new KeyListener(){
|
||||
fInputField.addKeyListener(new KeyListener() {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
// if the field assist has handled the key already then
|
||||
// ignore it (https://bugs.eclipse.org/bugs/show_bug.cgi?id=211659)
|
||||
if(!e.doit)
|
||||
if (!e.doit)
|
||||
return;
|
||||
if(e.character==SWT.CR || e.character==SWT.LF) {
|
||||
e.doit=false;
|
||||
String line=fInputField.getText();
|
||||
if(!terminal.pasteString(line+'\r'))
|
||||
if (e.character == SWT.CR || e.character == SWT.LF) {
|
||||
e.doit = false;
|
||||
String line = fInputField.getText();
|
||||
if (!terminal.pasteString(line + '\r'))
|
||||
return;
|
||||
pushLine(line);
|
||||
setCommand("");//$NON-NLS-1$
|
||||
} else if(e.keyCode==SWT.ARROW_UP || e.keyCode==SWT.PAGE_UP) {
|
||||
e.doit=false;
|
||||
setCommand(move(fInputField.getText(),1));
|
||||
} else if(e.keyCode==SWT.ARROW_DOWN || e.keyCode==SWT.PAGE_DOWN) {
|
||||
e.doit=false;
|
||||
setCommand(move(fInputField.getText(),-1));
|
||||
} else if(e.keyCode==SWT.ESC) {
|
||||
e.doit=false;
|
||||
} else if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.PAGE_UP) {
|
||||
e.doit = false;
|
||||
setCommand(move(fInputField.getText(), 1));
|
||||
} else if (e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.PAGE_DOWN) {
|
||||
e.doit = false;
|
||||
setCommand(move(fInputField.getText(), -1));
|
||||
} else if (e.keyCode == SWT.ESC) {
|
||||
e.doit = false;
|
||||
setCommand(escape());
|
||||
}
|
||||
}
|
||||
|
||||
private void setCommand(String line) {
|
||||
if(line==null)
|
||||
if (line == null)
|
||||
return;
|
||||
fInputField.setText(line);
|
||||
fInputField.setSelection(fInputField.getCharCount());
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setFont(Font font) {
|
||||
fInputField.setFont(font);
|
||||
fInputField.getParent().layout(true);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
fSash.dispose();
|
||||
fSash=null;
|
||||
fSash = null;
|
||||
fPanel.dispose();
|
||||
fPanel=null;
|
||||
fPanel = null;
|
||||
fInputField.dispose();
|
||||
fInputField=null;
|
||||
fInputField = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public interface ICommandInputField {
|
|||
void createControl(Composite parent, ITerminalViewControl terminal);
|
||||
|
||||
void dispose();
|
||||
|
||||
/**
|
||||
* Sets the font of a control created with {@link #createControl(Composite, ITerminalViewControl)}
|
||||
* @param control
|
||||
|
|
|
@ -26,6 +26,7 @@ public interface ITerminalMouseListener {
|
|||
* @param button see {@link org.eclipse.swt.events.MouseEvent#button} for the meaning of the button values
|
||||
*/
|
||||
void mouseDoubleClick(ITerminalTextDataReadOnly terminalText, int line, int column, int button);
|
||||
|
||||
/**
|
||||
* Invoked when a mouse button is pushed down inside the terminal control.<br>
|
||||
* <br>
|
||||
|
@ -34,6 +35,7 @@ public interface ITerminalMouseListener {
|
|||
* @param button see {@link org.eclipse.swt.events.MouseEvent#button} for the meaning of the button values
|
||||
*/
|
||||
void mouseDown(ITerminalTextDataReadOnly terminalText, int line, int column, int button);
|
||||
|
||||
/**
|
||||
* Invoked when a mouse button is released inside the terminal control.<br>
|
||||
* <br>
|
||||
|
|
|
@ -51,12 +51,14 @@ public interface ITerminalViewControl {
|
|||
String getEncoding();
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
/**
|
||||
* Sets the Terminal font
|
||||
* @deprecated use {@link #setFont(String)} in order to support bold and italic variants of the given font
|
||||
* @param font
|
||||
*/
|
||||
void setFont(Font font);
|
||||
|
||||
/**
|
||||
* Sets the font for the Terminal, using a JFace symbolic font name, such
|
||||
* that bold and italic variants can be leveraged.
|
||||
|
@ -64,36 +66,58 @@ public interface ITerminalViewControl {
|
|||
* @param fontName
|
||||
*/
|
||||
void setFont(String fontName);
|
||||
|
||||
void setInvertedColors(boolean invert);
|
||||
|
||||
Font getFont();
|
||||
|
||||
/**
|
||||
* @return the text control
|
||||
*/
|
||||
Control getControl();
|
||||
|
||||
/**
|
||||
* @return the root of all controls
|
||||
*/
|
||||
Control getRootControl();
|
||||
|
||||
boolean isDisposed();
|
||||
|
||||
void selectAll();
|
||||
|
||||
void clearTerminal();
|
||||
|
||||
void copy();
|
||||
|
||||
void paste();
|
||||
|
||||
String getSelection();
|
||||
|
||||
TerminalState getState();
|
||||
|
||||
Clipboard getClipboard();
|
||||
|
||||
void disconnectTerminal();
|
||||
|
||||
void disposeTerminal();
|
||||
|
||||
String getSettingsSummary();
|
||||
|
||||
ITerminalConnector[] getConnectors();
|
||||
|
||||
void setFocus();
|
||||
|
||||
ITerminalConnector getTerminalConnector();
|
||||
|
||||
void setConnector(ITerminalConnector connector);
|
||||
|
||||
void connectTerminal();
|
||||
|
||||
/**
|
||||
* @param write a single character to terminal
|
||||
*/
|
||||
void sendKey(char arg0);
|
||||
|
||||
/**
|
||||
* @param string write string to terminal
|
||||
*/
|
||||
|
@ -105,6 +129,7 @@ public interface ITerminalViewControl {
|
|||
* @param inputField null means no input field is shown
|
||||
*/
|
||||
void setCommandInputField(ICommandInputField inputField);
|
||||
|
||||
/**
|
||||
* @return null or the current input field
|
||||
*/
|
||||
|
@ -121,13 +146,16 @@ public interface ITerminalViewControl {
|
|||
* in the terminal view. -1 means unlimited.
|
||||
*/
|
||||
public void setBufferLineLimit(int bufferLineLimit);
|
||||
|
||||
boolean isScrollLock();
|
||||
|
||||
void setScrollLock(boolean on);
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
*/
|
||||
void addMouseListener(ITerminalMouseListener listener);
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
*/
|
||||
|
|
|
@ -23,7 +23,8 @@ public class TerminalViewControlFactory {
|
|||
* @param wndParent The Window parent to embed the Terminal in.
|
||||
* @param connectors Provided connectors.
|
||||
*/
|
||||
public static ITerminalViewControl makeControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors) {
|
||||
public static ITerminalViewControl makeControl(ITerminalListener target, Composite wndParent,
|
||||
ITerminalConnector[] connectors) {
|
||||
return makeControl(target, wndParent, connectors, false);
|
||||
}
|
||||
|
||||
|
@ -37,7 +38,8 @@ public class TerminalViewControlFactory {
|
|||
* Otherwise, clients need to maintain settings themselves.
|
||||
* @since 3.2
|
||||
*/
|
||||
public static ITerminalViewControl makeControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors, boolean useCommonPrefs) {
|
||||
public static ITerminalViewControl makeControl(ITerminalListener target, Composite wndParent,
|
||||
ITerminalConnector[] connectors, boolean useCommonPrefs) {
|
||||
return new VT100TerminalControl(target, wndParent, connectors, useCommonPrefs);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,13 +32,11 @@ public abstract class AbstractTerminalAction extends Action {
|
|||
this(null, strId, 0);
|
||||
}
|
||||
|
||||
public AbstractTerminalAction(ITerminalViewControl target,
|
||||
String strId) {
|
||||
public AbstractTerminalAction(ITerminalViewControl target, String strId) {
|
||||
this(target, strId, 0);
|
||||
}
|
||||
|
||||
public AbstractTerminalAction(ITerminalViewControl target,
|
||||
String strId, int style) {
|
||||
public AbstractTerminalAction(ITerminalViewControl target, String strId, int style) {
|
||||
super("", style); //$NON-NLS-1$
|
||||
|
||||
fTarget = target;
|
||||
|
@ -48,27 +46,20 @@ public abstract class AbstractTerminalAction extends Action {
|
|||
|
||||
abstract public void run();
|
||||
|
||||
protected void setupAction(String strText, String strToolTip,
|
||||
String strImage, String strEnabledImage, String strDisabledImage,
|
||||
boolean bEnabled) {
|
||||
setupAction(strText, strToolTip, strImage, strEnabledImage,
|
||||
strDisabledImage, bEnabled, TerminalPlugin.getDefault()
|
||||
.getImageRegistry());
|
||||
protected void setupAction(String strText, String strToolTip, String strImage, String strEnabledImage,
|
||||
String strDisabledImage, boolean bEnabled) {
|
||||
setupAction(strText, strToolTip, strImage, strEnabledImage, strDisabledImage, bEnabled,
|
||||
TerminalPlugin.getDefault().getImageRegistry());
|
||||
}
|
||||
|
||||
protected void setupAction(String strText, String strToolTip,
|
||||
String strHoverImage, String strEnabledImage,
|
||||
String strDisabledImage, boolean bEnabled,
|
||||
ImageRegistry imageRegistry) {
|
||||
setupAction(strText, strToolTip, imageRegistry
|
||||
.getDescriptor(strHoverImage), imageRegistry
|
||||
.getDescriptor(strEnabledImage), imageRegistry
|
||||
.getDescriptor(strDisabledImage), bEnabled);
|
||||
protected void setupAction(String strText, String strToolTip, String strHoverImage, String strEnabledImage,
|
||||
String strDisabledImage, boolean bEnabled, ImageRegistry imageRegistry) {
|
||||
setupAction(strText, strToolTip, imageRegistry.getDescriptor(strHoverImage),
|
||||
imageRegistry.getDescriptor(strEnabledImage), imageRegistry.getDescriptor(strDisabledImage), bEnabled);
|
||||
}
|
||||
|
||||
protected void setupAction(String strText, String strToolTip,
|
||||
ImageDescriptor hoverImage, ImageDescriptor enabledImage,
|
||||
ImageDescriptor disabledImage, boolean bEnabled) {
|
||||
protected void setupAction(String strText, String strToolTip, ImageDescriptor hoverImage,
|
||||
ImageDescriptor enabledImage, ImageDescriptor disabledImage, boolean bEnabled) {
|
||||
setText(strText);
|
||||
setToolTipText(strToolTip);
|
||||
setEnabled(bEnabled);
|
||||
|
|
|
@ -23,8 +23,7 @@ import org.eclipse.osgi.util.NLS;
|
|||
|
||||
public class ActionMessages extends NLS {
|
||||
static {
|
||||
NLS.initializeMessages(ActionMessages.class.getName(),
|
||||
ActionMessages.class);
|
||||
NLS.initializeMessages(ActionMessages.class.getName(), ActionMessages.class);
|
||||
}
|
||||
|
||||
public static String COPY;
|
||||
|
|
|
@ -23,7 +23,7 @@ public interface ImageConsts {
|
|||
public final static String IMAGE_DIR_ROOT = "icons/"; //$NON-NLS-1$
|
||||
public final static String IMAGE_DIR_LOCALTOOL = IMAGE_DIR_ROOT + "clcl16/"; // basic colors - size 16x16 //$NON-NLS-1$
|
||||
public final static String IMAGE_DIR_DLCL = IMAGE_DIR_ROOT + "dlcl16/"; // disabled - size 16x16 //$NON-NLS-1$
|
||||
public final static String IMAGE_DIR_ELCL = IMAGE_DIR_ROOT+ "elcl16/"; // enabled - size 16x16 //$NON-NLS-1$
|
||||
public final static String IMAGE_DIR_ELCL = IMAGE_DIR_ROOT + "elcl16/"; // enabled - size 16x16 //$NON-NLS-1$
|
||||
|
||||
public static final String IMAGE_CLCL_CLEAR_ALL = "ImageClclClearAll"; //$NON-NLS-1$
|
||||
|
||||
|
|
|
@ -26,19 +26,15 @@ public class TerminalActionClearAll extends AbstractTerminalAction {
|
|||
public TerminalActionClearAll() {
|
||||
super(TerminalActionClearAll.class.getName());
|
||||
|
||||
setupAction(ActionMessages.CLEARALL, ActionMessages.CLEARALL,
|
||||
ImageConsts.IMAGE_CLCL_CLEAR_ALL,
|
||||
ImageConsts.IMAGE_ELCL_CLEAR_ALL,
|
||||
ImageConsts.IMAGE_DLCL_CLEAR_ALL, false);
|
||||
setupAction(ActionMessages.CLEARALL, ActionMessages.CLEARALL, ImageConsts.IMAGE_CLCL_CLEAR_ALL,
|
||||
ImageConsts.IMAGE_ELCL_CLEAR_ALL, ImageConsts.IMAGE_DLCL_CLEAR_ALL, false);
|
||||
}
|
||||
|
||||
public TerminalActionClearAll(ITerminalViewControl target) {
|
||||
super(target, TerminalActionClearAll.class.getName());
|
||||
|
||||
setupAction(ActionMessages.CLEARALL, ActionMessages.CLEARALL,
|
||||
ImageConsts.IMAGE_CLCL_CLEAR_ALL,
|
||||
ImageConsts.IMAGE_ELCL_CLEAR_ALL,
|
||||
ImageConsts.IMAGE_DLCL_CLEAR_ALL, false);
|
||||
setupAction(ActionMessages.CLEARALL, ActionMessages.CLEARALL, ImageConsts.IMAGE_CLCL_CLEAR_ALL,
|
||||
ImageConsts.IMAGE_ELCL_CLEAR_ALL, ImageConsts.IMAGE_DLCL_CLEAR_ALL, false);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
|
@ -29,20 +29,18 @@ public class TerminalActionCopy extends AbstractTerminalAction {
|
|||
super(TerminalActionCopy.class.getName());
|
||||
setActionDefinitionId("org.eclipse.tm.terminal.copy"); //$NON-NLS-1$
|
||||
ISharedImages si = PlatformUI.getWorkbench().getSharedImages();
|
||||
setupAction(ActionMessages.COPY, ActionMessages.COPY, si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY), si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY), si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED), true);
|
||||
setupAction(ActionMessages.COPY, ActionMessages.COPY, si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED), true);
|
||||
}
|
||||
|
||||
public TerminalActionCopy(ITerminalViewControl target) {
|
||||
super(target, TerminalActionCopy.class.getName());
|
||||
setActionDefinitionId("org.eclipse.tm.terminal.copy"); //$NON-NLS-1$
|
||||
ISharedImages si = PlatformUI.getWorkbench().getSharedImages();
|
||||
setupAction(ActionMessages.COPY, ActionMessages.COPY, si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY), si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY), si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED), true);
|
||||
setupAction(ActionMessages.COPY, ActionMessages.COPY, si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED), true);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
|
@ -27,19 +27,17 @@ public class TerminalActionCut extends AbstractTerminalAction {
|
|||
public TerminalActionCut() {
|
||||
super(TerminalActionCut.class.getName());
|
||||
ISharedImages si = PlatformUI.getWorkbench().getSharedImages();
|
||||
setupAction(ActionMessages.CUT, ActionMessages.CUT, si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_CUT), si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_CUT), si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED), true);
|
||||
setupAction(ActionMessages.CUT, ActionMessages.CUT, si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED), true);
|
||||
}
|
||||
|
||||
public TerminalActionCut(ITerminalViewControl target) {
|
||||
super(target, TerminalActionCut.class.getName());
|
||||
ISharedImages si = PlatformUI.getWorkbench().getSharedImages();
|
||||
setupAction(ActionMessages.CUT, ActionMessages.CUT, si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_CUT), si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_CUT), si
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED), true);
|
||||
setupAction(ActionMessages.CUT, ActionMessages.CUT, si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED), true);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
|
@ -33,22 +33,18 @@ public class TerminalActionPaste extends AbstractTerminalAction {
|
|||
super(TerminalActionPaste.class.getName());
|
||||
setActionDefinitionId("org.eclipse.tm.terminal.paste"); //$NON-NLS-1$
|
||||
ISharedImages si = PlatformUI.getWorkbench().getSharedImages();
|
||||
setupAction(ActionMessages.PASTE, ActionMessages.PASTE,
|
||||
setupAction(ActionMessages.PASTE, ActionMessages.PASTE, si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED),
|
||||
false);
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED), false);
|
||||
}
|
||||
|
||||
public TerminalActionPaste(ITerminalViewControl target) {
|
||||
super(target, TerminalActionPaste.class.getName());
|
||||
setActionDefinitionId("org.eclipse.tm.terminal.paste"); //$NON-NLS-1$
|
||||
ISharedImages si = PlatformUI.getWorkbench().getSharedImages();
|
||||
setupAction(ActionMessages.PASTE, ActionMessages.PASTE,
|
||||
setupAction(ActionMessages.PASTE, ActionMessages.PASTE, si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE),
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED),
|
||||
false);
|
||||
si.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED), false);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
@ -62,8 +58,7 @@ public class TerminalActionPaste extends AbstractTerminalAction {
|
|||
ITerminalViewControl target = getTarget();
|
||||
boolean bEnabled = target != null && target.getClipboard() != null && !target.getClipboard().isDisposed();
|
||||
if (bEnabled) {
|
||||
String strText = (String) target.getClipboard().getContents(
|
||||
TextTransfer.getInstance());
|
||||
String strText = (String) target.getClipboard().getContents(TextTransfer.getInstance());
|
||||
bEnabled = ((strText != null) && (!strText.equals("")) && (target.getState() == TerminalState.CONNECTED));//$NON-NLS-1$
|
||||
}
|
||||
setEnabled(bEnabled);
|
||||
|
|
|
@ -27,15 +27,13 @@ public class TerminalActionSelectAll extends AbstractTerminalAction {
|
|||
public TerminalActionSelectAll() {
|
||||
super(TerminalActionSelectAll.class.getName());
|
||||
|
||||
setupAction(ActionMessages.SELECTALL, ActionMessages.SELECTALL,
|
||||
(ImageDescriptor) null, null, null, false);
|
||||
setupAction(ActionMessages.SELECTALL, ActionMessages.SELECTALL, (ImageDescriptor) null, null, null, false);
|
||||
}
|
||||
|
||||
public TerminalActionSelectAll(ITerminalViewControl target) {
|
||||
super(target, TerminalActionSelectAll.class.getName());
|
||||
|
||||
setupAction(ActionMessages.SELECTALL, ActionMessages.SELECTALL,
|
||||
(ImageDescriptor) null, null, null, false);
|
||||
setupAction(ActionMessages.SELECTALL, ActionMessages.SELECTALL, (ImageDescriptor) null, null, null, false);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
|
@ -25,7 +25,9 @@ import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
|
|||
public interface ITerminalControlForText {
|
||||
|
||||
TerminalState getState();
|
||||
|
||||
void setState(TerminalState state);
|
||||
|
||||
void setTerminalTitle(String title);
|
||||
|
||||
ITerminalConnector getTerminalConnector();
|
||||
|
|
|
@ -39,6 +39,7 @@ public class TerminalPlugin extends AbstractUIPlugin {
|
|||
*/
|
||||
public TerminalPlugin() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance.
|
||||
*/
|
||||
|
@ -76,17 +77,21 @@ public class TerminalPlugin extends AbstractUIPlugin {
|
|||
protected void initializeImageRegistry(ImageRegistry imageRegistry) {
|
||||
try {
|
||||
// Local toolbars
|
||||
putImageInRegistry(imageRegistry, ImageConsts.IMAGE_CLCL_CLEAR_ALL, ImageConsts.IMAGE_DIR_LOCALTOOL + "clear_co.gif"); //$NON-NLS-1$
|
||||
putImageInRegistry(imageRegistry, ImageConsts.IMAGE_CLCL_CLEAR_ALL,
|
||||
ImageConsts.IMAGE_DIR_LOCALTOOL + "clear_co.gif"); //$NON-NLS-1$
|
||||
// Enabled local toolbars
|
||||
putImageInRegistry(imageRegistry, ImageConsts.IMAGE_ELCL_CLEAR_ALL, ImageConsts.IMAGE_DIR_ELCL + "clear_co.gif"); //$NON-NLS-1$
|
||||
putImageInRegistry(imageRegistry, ImageConsts.IMAGE_ELCL_CLEAR_ALL,
|
||||
ImageConsts.IMAGE_DIR_ELCL + "clear_co.gif"); //$NON-NLS-1$
|
||||
// Disabled local toolbars
|
||||
putImageInRegistry(imageRegistry, ImageConsts.IMAGE_DLCL_CLEAR_ALL, ImageConsts.IMAGE_DIR_DLCL + "clear_co.gif"); //$NON-NLS-1$
|
||||
putImageInRegistry(imageRegistry, ImageConsts.IMAGE_DLCL_CLEAR_ALL,
|
||||
ImageConsts.IMAGE_DIR_DLCL + "clear_co.gif"); //$NON-NLS-1$
|
||||
} catch (MalformedURLException malformedURLException) {
|
||||
malformedURLException.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void putImageInRegistry(ImageRegistry imageRegistry, String strKey, String relativePath) throws MalformedURLException {
|
||||
protected void putImageInRegistry(ImageRegistry imageRegistry, String strKey, String relativePath)
|
||||
throws MalformedURLException {
|
||||
URL url = TerminalPlugin.getDefault().getBundle().getEntry(relativePath);
|
||||
ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url);
|
||||
imageRegistry.put(strKey, imageDescriptor);
|
||||
|
|
|
@ -33,7 +33,7 @@ class EditActionAccelerators {
|
|||
|
||||
private void addAccelerator(String commandId) {
|
||||
TriggerSequence[] bindings = bindingsFor(commandId);
|
||||
for (int i=0; i<bindings.length; ++i) {
|
||||
for (int i = 0; i < bindings.length; ++i) {
|
||||
if (bindings[i] instanceof KeySequence) {
|
||||
KeyStroke[] keyStrokes = ((KeySequence) bindings[i]).getKeyStrokes();
|
||||
if (keyStrokes.length != 0) {
|
||||
|
|
|
@ -23,7 +23,7 @@ public class LoggingOutputStream extends FilterOutputStream {
|
|||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
if(Logger.isLogEnabled())
|
||||
if (Logger.isLogEnabled())
|
||||
Logger.log("Received " + len + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Logger.encode(new String(b, 0, len)) + "'"); //$NON-NLS-1$
|
||||
|
||||
|
@ -33,15 +33,15 @@ public class LoggingOutputStream extends FilterOutputStream {
|
|||
if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
|
||||
for (int i = 0 ; i < len ; i++) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
super.write(b[off + i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
if(Logger.isLogEnabled())
|
||||
if (Logger.isLogEnabled())
|
||||
Logger.log("Received " + 1 + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Logger.encode(new String(new byte[]{(byte)b}, 0, 1)) + "'"); //$NON-NLS-1$
|
||||
Logger.encode(new String(new byte[] { (byte) b }, 0, 1)) + "'"); //$NON-NLS-1$
|
||||
super.write(b);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,13 +20,14 @@ import org.eclipse.tm.terminal.model.Style;
|
|||
public class VT100BackendTraceDecorator implements IVT100EmulatorBackend {
|
||||
final IVT100EmulatorBackend fBackend;
|
||||
final PrintStream fWriter;
|
||||
|
||||
public VT100BackendTraceDecorator(IVT100EmulatorBackend backend, PrintStream out) {
|
||||
fBackend = backend;
|
||||
fWriter=out;
|
||||
fWriter = out;
|
||||
}
|
||||
|
||||
public void appendString(String buffer) {
|
||||
fWriter.println("appendString(\""+buffer+"\")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("appendString(\"" + buffer + "\")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.appendString(buffer);
|
||||
}
|
||||
|
||||
|
@ -36,12 +37,12 @@ public class VT100BackendTraceDecorator implements IVT100EmulatorBackend {
|
|||
}
|
||||
|
||||
public void deleteCharacters(int n) {
|
||||
fWriter.println("deleteCharacters("+n+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("deleteCharacters(" + n + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.deleteCharacters(n);
|
||||
}
|
||||
|
||||
public void deleteLines(int n) {
|
||||
fWriter.println("deleteLines("+n+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("deleteLines(" + n + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.deleteLines(n);
|
||||
}
|
||||
|
||||
|
@ -100,12 +101,12 @@ public class VT100BackendTraceDecorator implements IVT100EmulatorBackend {
|
|||
}
|
||||
|
||||
public void insertCharacters(int charactersToInsert) {
|
||||
fWriter.println("insertCharacters("+charactersToInsert+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("insertCharacters(" + charactersToInsert + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.insertCharacters(charactersToInsert);
|
||||
}
|
||||
|
||||
public void insertLines(int n) {
|
||||
fWriter.println("insertLines("+n+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("insertLines(" + n + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.insertLines(n);
|
||||
}
|
||||
|
||||
|
@ -115,37 +116,37 @@ public class VT100BackendTraceDecorator implements IVT100EmulatorBackend {
|
|||
}
|
||||
|
||||
public void setCursor(int targetLine, int targetColumn) {
|
||||
fWriter.println("setCursor("+targetLine+", "+targetColumn+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
fWriter.println("setCursor(" + targetLine + ", " + targetColumn + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
fBackend.setCursor(targetLine, targetColumn);
|
||||
}
|
||||
|
||||
public void setCursorColumn(int targetColumn) {
|
||||
fWriter.println("setCursorColumn("+targetColumn+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("setCursorColumn(" + targetColumn + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.setCursorColumn(targetColumn);
|
||||
}
|
||||
|
||||
public void setCursorLine(int targetLine) {
|
||||
fWriter.println("setCursorLine("+targetLine+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("setCursorLine(" + targetLine + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.setCursorLine(targetLine);
|
||||
}
|
||||
|
||||
public void setDefaultStyle(Style defaultStyle) {
|
||||
fWriter.println("setDefaultStyle("+defaultStyle+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("setDefaultStyle(" + defaultStyle + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.setDefaultStyle(defaultStyle);
|
||||
}
|
||||
|
||||
public void setDimensions(int lines, int cols) {
|
||||
fWriter.println("setDimensions("+lines+","+cols+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
fWriter.println("setDimensions(" + lines + "," + cols + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
fBackend.setDimensions(lines, cols);
|
||||
}
|
||||
|
||||
public void setStyle(Style style) {
|
||||
fWriter.println("setStyle("+style+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("setStyle(" + style + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.setStyle(style);
|
||||
}
|
||||
|
||||
public void setVT100LineWrapping(boolean enable) {
|
||||
fWriter.println("setVT100LineWrapping("+enable+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("setVT100LineWrapping(" + enable + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.setVT100LineWrapping(enable);
|
||||
}
|
||||
|
||||
|
@ -154,22 +155,22 @@ public class VT100BackendTraceDecorator implements IVT100EmulatorBackend {
|
|||
}
|
||||
|
||||
public void setInsertMode(boolean enable) {
|
||||
fWriter.println("setInsertMode("+enable+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("setInsertMode(" + enable + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.setInsertMode(enable);
|
||||
}
|
||||
|
||||
public void setScrollRegion(int top, int bottom) {
|
||||
fWriter.println("setScrollRegion("+top+','+bottom+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("setScrollRegion(" + top + ',' + bottom + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.setScrollRegion(top, bottom);
|
||||
}
|
||||
|
||||
public void scrollUp(int lines) {
|
||||
fWriter.println("scrollUp("+lines+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("scrollUp(" + lines + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.scrollUp(lines);
|
||||
}
|
||||
|
||||
public void scrollDown(int lines) {
|
||||
fWriter.println("scrollDown("+lines+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fWriter.println("scrollDown(" + lines + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fBackend.scrollDown(lines);
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,6 @@ public class VT100Emulator implements ControlListener {
|
|||
*/
|
||||
private static final int ANSISTATE_EXPECTING_CHARSET_DESIGNATION = 5;
|
||||
|
||||
|
||||
/**
|
||||
* This field holds the current state of the Finite TerminalState Automaton (FSA)
|
||||
* that recognizes ANSI escape sequences.
|
||||
|
@ -140,6 +139,7 @@ public class VT100Emulator implements ControlListener {
|
|||
Reader fReader;
|
||||
|
||||
boolean fCrAfterNewLine;
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
|
@ -154,13 +154,13 @@ public class VT100Emulator implements ControlListener {
|
|||
ansiParameters[i] = new StringBuffer();
|
||||
}
|
||||
setInputStreamReader(reader);
|
||||
if(TerminalPlugin.isOptionEnabled(Logger.TRACE_DEBUG_LOG_VT100BACKEND))
|
||||
text=new VT100BackendTraceDecorator(new VT100EmulatorBackend(data),System.out);
|
||||
if (TerminalPlugin.isOptionEnabled(Logger.TRACE_DEBUG_LOG_VT100BACKEND))
|
||||
text = new VT100BackendTraceDecorator(new VT100EmulatorBackend(data), System.out);
|
||||
else
|
||||
text=new VT100EmulatorBackend(data);
|
||||
text = new VT100EmulatorBackend(data);
|
||||
|
||||
// text.setDimensions(24, 80);
|
||||
Style style=Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// text.setDimensions(24, 80);
|
||||
Style style = Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
text.setDefaultStyle(style);
|
||||
text.setStyle(style);
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ public class VT100Emulator implements ControlListener {
|
|||
fReader = reader;
|
||||
}
|
||||
|
||||
public void setDimensions(int lines,int cols) {
|
||||
public void setDimensions(int lines, int cols) {
|
||||
text.setDimensions(lines, cols);
|
||||
ITerminalConnector telnetConnection = getConnector();
|
||||
if (telnetConnection != null) {
|
||||
|
@ -236,22 +236,23 @@ public class VT100Emulator implements ControlListener {
|
|||
if (text != null)
|
||||
adjustTerminalDimensions();
|
||||
}
|
||||
// /**
|
||||
// * This method executes in the Display thread to process data received from
|
||||
// * the remote host by class {@link org.eclipse.tm.internal.terminal.telnet.TelnetConnection} and
|
||||
// * other implementors of {@link ITerminalConnector}, like the
|
||||
// * SerialPortHandler.
|
||||
// * <p>
|
||||
// * These connectors write text to the terminal's buffer through
|
||||
// * {@link TerminalControl#writeToTerminal(String)} and then have
|
||||
// * this run method executed in the display thread. This method
|
||||
// * must not execute at the same time as methods
|
||||
// * {@link #setNewText(StringBuffer)} and {@link #clearTerminal()}.
|
||||
// * <p>
|
||||
// * IMPORTANT: This method must be called in strict alternation with method
|
||||
// * {@link #setNewText(StringBuffer)}.
|
||||
// * <p>
|
||||
// */
|
||||
|
||||
// /**
|
||||
// * This method executes in the Display thread to process data received from
|
||||
// * the remote host by class {@link org.eclipse.tm.internal.terminal.telnet.TelnetConnection} and
|
||||
// * other implementors of {@link ITerminalConnector}, like the
|
||||
// * SerialPortHandler.
|
||||
// * <p>
|
||||
// * These connectors write text to the terminal's buffer through
|
||||
// * {@link TerminalControl#writeToTerminal(String)} and then have
|
||||
// * this run method executed in the display thread. This method
|
||||
// * must not execute at the same time as methods
|
||||
// * {@link #setNewText(StringBuffer)} and {@link #clearTerminal()}.
|
||||
// * <p>
|
||||
// * IMPORTANT: This method must be called in strict alternation with method
|
||||
// * {@link #setNewText(StringBuffer)}.
|
||||
// * <p>
|
||||
// */
|
||||
public void processText() {
|
||||
try {
|
||||
// Find the width and height of the terminal, and resize it to display an
|
||||
|
@ -275,6 +276,7 @@ public class VT100Emulator implements ControlListener {
|
|||
Logger.logException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method scans the newly received text, processing ANSI control
|
||||
* characters and escape sequences and displaying normal text.
|
||||
|
@ -283,7 +285,6 @@ public class VT100Emulator implements ControlListener {
|
|||
private void processNewText() throws IOException {
|
||||
Logger.log("entered"); //$NON-NLS-1$
|
||||
|
||||
|
||||
// Scan the newly received text.
|
||||
|
||||
while (hasNextChar()) {
|
||||
|
@ -309,7 +310,7 @@ public class VT100Emulator implements ControlListener {
|
|||
|
||||
case '\n':
|
||||
processNewline(); // Newline (Control-J)
|
||||
if(fCrAfterNewLine)
|
||||
if (fCrAfterNewLine)
|
||||
processCarriageReturn(); // Carriage Return (Control-M)
|
||||
break;
|
||||
|
||||
|
@ -382,8 +383,7 @@ public class VT100Emulator implements ControlListener {
|
|||
break;
|
||||
|
||||
default:
|
||||
Logger
|
||||
.log("Unsupported escape sequence: escape '" + character + "'"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Logger.log("Unsupported escape sequence: escape '" + character + "'"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
ansiState = ANSISTATE_INITIAL;
|
||||
break;
|
||||
}
|
||||
|
@ -448,6 +448,7 @@ public class VT100Emulator implements ControlListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resetTerminal() {
|
||||
text.eraseAll();
|
||||
text.setCursor(0, 0);
|
||||
|
@ -456,6 +457,7 @@ public class VT100Emulator implements ControlListener {
|
|||
text.setInsertMode(false);
|
||||
terminal.enableApplicationCursorKeys(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when we have parsed an OS Command escape sequence.
|
||||
* The only one we support is "\e]0;...\u0007", which sets the terminal
|
||||
|
@ -463,8 +465,7 @@ public class VT100Emulator implements ControlListener {
|
|||
*/
|
||||
private void processAnsiOsCommand() {
|
||||
if (ansiOsCommand.charAt(0) != '0' || ansiOsCommand.charAt(1) != ';') {
|
||||
Logger
|
||||
.log("Ignoring unsupported ANSI OSC sequence: '" + ansiOsCommand + "'"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Logger.log("Ignoring unsupported ANSI OSC sequence: '" + ansiOsCommand + "'"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return;
|
||||
}
|
||||
terminal.setTerminalTitle(ansiOsCommand.substring(2));
|
||||
|
@ -838,15 +839,14 @@ public class VT100Emulator implements ControlListener {
|
|||
|
||||
ansiParameters[0].append('0');
|
||||
}
|
||||
Style style=text.getStyle();
|
||||
Style style = text.getStyle();
|
||||
// There are a non-zero number of ANSI parameters. Process each one in
|
||||
// order.
|
||||
|
||||
int totalParameters = ansiParameters.length;
|
||||
int parameterIndex = 0;
|
||||
|
||||
while (parameterIndex < totalParameters
|
||||
&& ansiParameters[parameterIndex].length() > 0) {
|
||||
while (parameterIndex < totalParameters && ansiParameters[parameterIndex].length() > 0) {
|
||||
int ansiParameter = getAnsiParameter(parameterIndex);
|
||||
|
||||
switch (ansiParameter) {
|
||||
|
@ -964,8 +964,7 @@ public class VT100Emulator implements ControlListener {
|
|||
break;
|
||||
|
||||
default:
|
||||
Logger
|
||||
.log("Unsupported graphics rendition parameter: " + ansiParameter); //$NON-NLS-1$
|
||||
Logger.log("Unsupported graphics rendition parameter: " + ansiParameter); //$NON-NLS-1$
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1025,7 +1024,7 @@ public class VT100Emulator implements ControlListener {
|
|||
top = getAnsiParameter(0);
|
||||
bottom = getAnsiParameter(1);
|
||||
}
|
||||
text.setScrollRegion(top-1, bottom-1);
|
||||
text.setScrollRegion(top - 1, bottom - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1128,6 +1127,7 @@ public class VT100Emulator implements ControlListener {
|
|||
ansiParameters[nextAnsiParameter].append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method processes a contiguous sequence of non-control characters.
|
||||
* This is a performance optimization, so that we don't have to insert or
|
||||
|
@ -1137,15 +1137,14 @@ public class VT100Emulator implements ControlListener {
|
|||
* @throws IOException
|
||||
*/
|
||||
private void processNonControlCharacters(char character) throws IOException {
|
||||
StringBuffer buffer=new StringBuffer();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(character);
|
||||
// Identify a contiguous sequence of non-control characters, starting at
|
||||
// firstNonControlCharacterIndex in newText.
|
||||
while(hasNextChar()) {
|
||||
character=getNextChar();
|
||||
if(character == '\u0000' || character == '\b' || character == '\t'
|
||||
|| character == '\u0007' || character == '\n'
|
||||
|| character == '\r' || character == '\u001b') {
|
||||
while (hasNextChar()) {
|
||||
character = getNextChar();
|
||||
if (character == '\u0000' || character == '\b' || character == '\t' || character == '\u0007'
|
||||
|| character == '\n' || character == '\r' || character == '\u001b') {
|
||||
pushBackChar(character);
|
||||
break;
|
||||
}
|
||||
|
@ -1173,7 +1172,6 @@ public class VT100Emulator implements ControlListener {
|
|||
text.appendString(buffer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process a BEL (Control-G) character.
|
||||
*/
|
||||
|
@ -1251,8 +1249,8 @@ public class VT100Emulator implements ControlListener {
|
|||
// to make it display an integral number of lines of text.
|
||||
|
||||
// TODO
|
||||
// if(text.getColumns()!=80 && text.getLines()!=80)
|
||||
// text.setDimensions(24, 80);
|
||||
// if(text.getColumns()!=80 && text.getLines()!=80)
|
||||
// text.setDimensions(24, 80);
|
||||
// If we are in a TELNET connection and we know the dimensions of the terminal,
|
||||
// we give the size information to the TELNET connection object so it can
|
||||
// communicate it to the TELNET server. If we are in a serial connection,
|
||||
|
@ -1267,7 +1265,7 @@ public class VT100Emulator implements ControlListener {
|
|||
}
|
||||
|
||||
private ITerminalConnector getConnector() {
|
||||
if(terminal.getTerminalConnector()!=null)
|
||||
if (terminal.getTerminalConnector() != null)
|
||||
return terminal.getTerminalConnector();
|
||||
return null;
|
||||
}
|
||||
|
@ -1291,7 +1289,7 @@ public class VT100Emulator implements ControlListener {
|
|||
* contain any text to move the cursor to any column in that line.
|
||||
*/
|
||||
private void moveCursor(int targetLine, int targetColumn) {
|
||||
text.setCursor(targetLine,targetColumn);
|
||||
text.setCursor(targetLine, targetColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1330,42 +1328,43 @@ public class VT100Emulator implements ControlListener {
|
|||
private void moveCursorBackward(int columnsToMove) {
|
||||
moveCursor(relativeCursorLine(), getCursorColumn() - columnsToMove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the state of the terminal text (foreground color, background color,
|
||||
* font style and other internal state). It essentially makes it ready for new input.
|
||||
*/
|
||||
public void resetState() {
|
||||
ansiState=ANSISTATE_INITIAL;
|
||||
ansiState = ANSISTATE_INITIAL;
|
||||
text.setStyle(text.getDefaultStyle());
|
||||
text.setScrollRegion(-1, -1);
|
||||
text.setInsertMode(false);
|
||||
}
|
||||
|
||||
// public OutputStream getOutputStream() {
|
||||
// return fTerminalInputStream.getOutputStream();
|
||||
// }
|
||||
// public OutputStream getOutputStream() {
|
||||
// return fTerminalInputStream.getOutputStream();
|
||||
// }
|
||||
|
||||
/**
|
||||
* Buffer for {@link #pushBackChar(char)}.
|
||||
*/
|
||||
private int fNextChar=-1;
|
||||
private int fNextChar = -1;
|
||||
|
||||
private char getNextChar() throws IOException {
|
||||
int c=-1;
|
||||
if(fNextChar!=-1) {
|
||||
c= fNextChar;
|
||||
fNextChar=-1;
|
||||
int c = -1;
|
||||
if (fNextChar != -1) {
|
||||
c = fNextChar;
|
||||
fNextChar = -1;
|
||||
} else {
|
||||
c = fReader.read();
|
||||
}
|
||||
// TODO: better end of file handling
|
||||
if(c==-1)
|
||||
c=0;
|
||||
return (char)c;
|
||||
if (c == -1)
|
||||
c = 0;
|
||||
return (char) c;
|
||||
}
|
||||
|
||||
private boolean hasNextChar() throws IOException {
|
||||
if(fNextChar>=0)
|
||||
if (fNextChar >= 0)
|
||||
return true;
|
||||
return fReader.ready();
|
||||
}
|
||||
|
@ -1378,20 +1377,25 @@ public class VT100Emulator implements ControlListener {
|
|||
*/
|
||||
void pushBackChar(char c) {
|
||||
//assert fNextChar!=-1: "Already a character waiting:"+fNextChar; //$NON-NLS-1$
|
||||
fNextChar=c;
|
||||
fNextChar = c;
|
||||
}
|
||||
|
||||
private int getCursorColumn() {
|
||||
return text.getCursorColumn();
|
||||
}
|
||||
|
||||
public boolean isCrAfterNewLine() {
|
||||
return fCrAfterNewLine;
|
||||
}
|
||||
|
||||
public void setCrAfterNewLine(boolean crAfterNewLine) {
|
||||
fCrAfterNewLine = crAfterNewLine;
|
||||
}
|
||||
|
||||
void setVT100LineWrapping(boolean enable) {
|
||||
text.setVT100LineWrapping(enable);
|
||||
}
|
||||
|
||||
boolean isVT100LineWrapping() {
|
||||
return text.isVT100LineWrapping();
|
||||
}
|
||||
|
|
|
@ -26,22 +26,27 @@ import org.eclipse.tm.terminal.model.Style;
|
|||
public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
||||
|
||||
private static class ScrollRegion {
|
||||
static final ScrollRegion FULL_WINDOW = new ScrollRegion(0, Integer.MAX_VALUE-1);
|
||||
static final ScrollRegion FULL_WINDOW = new ScrollRegion(0, Integer.MAX_VALUE - 1);
|
||||
private final int fTop;
|
||||
private final int fBottom;
|
||||
|
||||
ScrollRegion(int top, int bottom) {
|
||||
fTop = top;
|
||||
fBottom = bottom;
|
||||
}
|
||||
|
||||
boolean contains(int line) {
|
||||
return line >= fTop && line <= fBottom;
|
||||
}
|
||||
|
||||
int getTopLine() {
|
||||
return fTop;
|
||||
}
|
||||
|
||||
int getBottomLine() {
|
||||
return fBottom;
|
||||
}
|
||||
|
||||
int getHeight() {
|
||||
return fBottom - fTop + 1;
|
||||
}
|
||||
|
@ -91,7 +96,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
private ScrollRegion fScrollRegion = ScrollRegion.FULL_WINDOW;
|
||||
|
||||
public VT100EmulatorBackend(ITerminalTextData terminal) {
|
||||
fTerminal=terminal;
|
||||
fTerminal = terminal;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -100,7 +105,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
public void clearAll() {
|
||||
synchronized (fTerminal) {
|
||||
// clear the history
|
||||
int n=fTerminal.getHeight();
|
||||
int n = fTerminal.getHeight();
|
||||
for (int line = 0; line < n; line++) {
|
||||
fTerminal.cleanLine(line);
|
||||
}
|
||||
|
@ -109,34 +114,35 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
setCursor(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#setDimensions(int, int)
|
||||
*/
|
||||
public void setDimensions(int lines, int cols) {
|
||||
synchronized (fTerminal) {
|
||||
if(lines==fLines && cols==fColumns)
|
||||
if (lines == fLines && cols == fColumns)
|
||||
return; // nothing to do
|
||||
// relative cursor line
|
||||
int cl=getCursorLine();
|
||||
int cc=getCursorColumn();
|
||||
int height=fTerminal.getHeight();
|
||||
int cl = getCursorLine();
|
||||
int cc = getCursorColumn();
|
||||
int height = fTerminal.getHeight();
|
||||
// absolute cursor line
|
||||
int acl=cl+height-fLines;
|
||||
int newLines=Math.max(lines,height);
|
||||
if(lines<fLines) {
|
||||
if(height==fLines) {
|
||||
int acl = cl + height - fLines;
|
||||
int newLines = Math.max(lines, height);
|
||||
if (lines < fLines) {
|
||||
if (height == fLines) {
|
||||
// if the terminal has no history, then resize by
|
||||
// setting the size to the new size
|
||||
// TODO We are assuming that cursor line points at end of text
|
||||
newLines=Math.max(lines, cl+1);
|
||||
newLines = Math.max(lines, cl + 1);
|
||||
}
|
||||
}
|
||||
fLines=lines;
|
||||
fColumns=cols;
|
||||
fLines = lines;
|
||||
fColumns = cols;
|
||||
// make the terminal at least as high as we need lines
|
||||
fTerminal.setDimensions(newLines, fColumns);
|
||||
// compute relative cursor line
|
||||
cl=acl-(newLines-fLines);
|
||||
cl = acl - (newLines - fLines);
|
||||
setCursor(cl, cc);
|
||||
}
|
||||
}
|
||||
|
@ -148,24 +154,25 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
*/
|
||||
public int toAbsoluteLine(int line) {
|
||||
synchronized (fTerminal) {
|
||||
return fTerminal.getHeight()-fLines+line;
|
||||
return fTerminal.getHeight() - fLines + line;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#insertCharacters(int)
|
||||
*/
|
||||
public void insertCharacters(int charactersToInsert) {
|
||||
synchronized (fTerminal) {
|
||||
int line=toAbsoluteLine(fCursorLine);
|
||||
int n=charactersToInsert;
|
||||
for (int col = fColumns-1; col >=fCursorColumn+n; col--) {
|
||||
char c=fTerminal.getChar(line, col-n);
|
||||
Style style=fTerminal.getStyle(line, col-n);
|
||||
fTerminal.setChar(line, col,c, style);
|
||||
int line = toAbsoluteLine(fCursorLine);
|
||||
int n = charactersToInsert;
|
||||
for (int col = fColumns - 1; col >= fCursorColumn + n; col--) {
|
||||
char c = fTerminal.getChar(line, col - n);
|
||||
Style style = fTerminal.getStyle(line, col - n);
|
||||
fTerminal.setChar(line, col, c, style);
|
||||
}
|
||||
int last=Math.min(fCursorColumn+n, fColumns);
|
||||
for (int col = fCursorColumn; col <last; col++) {
|
||||
fTerminal.setChar(line, col,'\000', null);
|
||||
int last = Math.min(fCursorColumn + n, fColumns);
|
||||
for (int col = fCursorColumn; col < last; col++) {
|
||||
fTerminal.setChar(line, col, '\000', null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,12 +183,13 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
public void eraseToEndOfScreen() {
|
||||
synchronized (fTerminal) {
|
||||
eraseLineToEnd();
|
||||
for (int line = toAbsoluteLine(fCursorLine+1); line < toAbsoluteLine(fLines); line++) {
|
||||
for (int line = toAbsoluteLine(fCursorLine + 1); line < toAbsoluteLine(fLines); line++) {
|
||||
fTerminal.cleanLine(line);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#eraseToCursor()
|
||||
*/
|
||||
|
@ -193,6 +201,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
eraseLineToCursor();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#eraseAll()
|
||||
*/
|
||||
|
@ -203,6 +212,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#eraseLine()
|
||||
*/
|
||||
|
@ -211,23 +221,25 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
fTerminal.cleanLine(toAbsoluteLine(fCursorLine));
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#eraseLineToEnd()
|
||||
*/
|
||||
public void eraseLineToEnd() {
|
||||
synchronized (fTerminal) {
|
||||
int line=toAbsoluteLine(fCursorLine);
|
||||
int line = toAbsoluteLine(fCursorLine);
|
||||
for (int col = fCursorColumn; col < fColumns; col++) {
|
||||
fTerminal.setChar(line, col, '\000', null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#eraseLineToCursor()
|
||||
*/
|
||||
public void eraseLineToCursor() {
|
||||
synchronized (fTerminal) {
|
||||
int line=toAbsoluteLine(fCursorLine);
|
||||
int line = toAbsoluteLine(fCursorLine);
|
||||
for (int col = 0; col <= fCursorColumn; col++) {
|
||||
fTerminal.setChar(line, col, '\000', null);
|
||||
}
|
||||
|
@ -239,44 +251,47 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
*/
|
||||
public void insertLines(int n) {
|
||||
synchronized (fTerminal) {
|
||||
if(!isCusorInScrollingRegion())
|
||||
if (!isCusorInScrollingRegion())
|
||||
return;
|
||||
assert n>0;
|
||||
int line=toAbsoluteLine(fCursorLine);
|
||||
int nLines=Math.min(fTerminal.getHeight()-line, fScrollRegion.getBottomLine()-fCursorLine+1);
|
||||
assert n > 0;
|
||||
int line = toAbsoluteLine(fCursorLine);
|
||||
int nLines = Math.min(fTerminal.getHeight() - line, fScrollRegion.getBottomLine() - fCursorLine + 1);
|
||||
fTerminal.scroll(line, nLines, n);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#deleteCharacters(int)
|
||||
*/
|
||||
public void deleteCharacters(int n) {
|
||||
synchronized (fTerminal) {
|
||||
int line=toAbsoluteLine(fCursorLine);
|
||||
for (int col = fCursorColumn+n; col < fColumns; col++) {
|
||||
char c=fTerminal.getChar(line, col);
|
||||
Style style=fTerminal.getStyle(line, col);
|
||||
fTerminal.setChar(line, col-n,c, style);
|
||||
int line = toAbsoluteLine(fCursorLine);
|
||||
for (int col = fCursorColumn + n; col < fColumns; col++) {
|
||||
char c = fTerminal.getChar(line, col);
|
||||
Style style = fTerminal.getStyle(line, col);
|
||||
fTerminal.setChar(line, col - n, c, style);
|
||||
}
|
||||
int first=Math.max(fCursorColumn, fColumns-n);
|
||||
for (int col = first; col <fColumns; col++) {
|
||||
fTerminal.setChar(line, col,'\000', null);
|
||||
int first = Math.max(fCursorColumn, fColumns - n);
|
||||
for (int col = first; col < fColumns; col++) {
|
||||
fTerminal.setChar(line, col, '\000', null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#deleteLines(int)
|
||||
*/
|
||||
public void deleteLines(int n) {
|
||||
synchronized (fTerminal) {
|
||||
if(!isCusorInScrollingRegion())
|
||||
if (!isCusorInScrollingRegion())
|
||||
return;
|
||||
assert n>0;
|
||||
int line=toAbsoluteLine(fCursorLine);
|
||||
int nLines=Math.min(fTerminal.getHeight()-line, fScrollRegion.getBottomLine()-fCursorLine+1);
|
||||
assert n > 0;
|
||||
int line = toAbsoluteLine(fCursorLine);
|
||||
int nLines = Math.min(fTerminal.getHeight() - line, fScrollRegion.getBottomLine() - fCursorLine + 1);
|
||||
fTerminal.scroll(line, nLines, -n);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCusorInScrollingRegion() {
|
||||
return fScrollRegion.contains(fCursorLine);
|
||||
}
|
||||
|
@ -304,39 +319,41 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
*/
|
||||
public Style getStyle() {
|
||||
synchronized (fTerminal) {
|
||||
if(fStyle==null)
|
||||
if (fStyle == null)
|
||||
return fDefaultStyle;
|
||||
return fStyle;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#setStyle(org.eclipse.tm.terminal.model.Style)
|
||||
*/
|
||||
public void setStyle(Style style) {
|
||||
synchronized (fTerminal) {
|
||||
fStyle=style;
|
||||
fStyle = style;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#appendString(java.lang.String)
|
||||
*/
|
||||
public void appendString(String buffer) {
|
||||
synchronized (fTerminal) {
|
||||
char[] chars=buffer.toCharArray();
|
||||
char[] chars = buffer.toCharArray();
|
||||
if (fInsertMode)
|
||||
insertCharacters(chars.length);
|
||||
int line=toAbsoluteLine(fCursorLine);
|
||||
int i=0;
|
||||
int line = toAbsoluteLine(fCursorLine);
|
||||
int i = 0;
|
||||
while (i < chars.length) {
|
||||
if(fWrapPending) {
|
||||
if (fWrapPending) {
|
||||
line = doLineWrap();
|
||||
}
|
||||
int n=Math.min(fColumns-fCursorColumn,chars.length-i);
|
||||
int n = Math.min(fColumns - fCursorColumn, chars.length - i);
|
||||
fTerminal.setChars(line, fCursorColumn, chars, i, n, fStyle);
|
||||
int col=fCursorColumn+n;
|
||||
i+=n;
|
||||
int col = fCursorColumn + n;
|
||||
i += n;
|
||||
// wrap needed?
|
||||
if(col == fColumns) {
|
||||
if (col == fColumns) {
|
||||
if (fVT100LineWrapping) {
|
||||
// deferred line wrapping (eat_newline_glitch)
|
||||
setCursorColumn(col - 1);
|
||||
|
@ -353,10 +370,10 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
|
||||
private int doLineWrap() {
|
||||
int line;
|
||||
line=toAbsoluteLine(fCursorLine);
|
||||
line = toAbsoluteLine(fCursorLine);
|
||||
fTerminal.setWrappedLine(line);
|
||||
doNewline();
|
||||
line=toAbsoluteLine(fCursorLine);
|
||||
line = toAbsoluteLine(fCursorLine);
|
||||
setCursorColumn(0);
|
||||
return line;
|
||||
}
|
||||
|
@ -367,15 +384,16 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
private void doNewline() {
|
||||
if (fCursorLine == fScrollRegion.getBottomLine())
|
||||
scrollUp(1);
|
||||
else if (fCursorLine+1>=fLines) {
|
||||
int h=fTerminal.getHeight();
|
||||
else if (fCursorLine + 1 >= fLines) {
|
||||
int h = fTerminal.getHeight();
|
||||
fTerminal.addLine();
|
||||
if(h!=fTerminal.getHeight())
|
||||
setCursorLine(fCursorLine+1);
|
||||
if (h != fTerminal.getHeight())
|
||||
setCursorLine(fCursorLine + 1);
|
||||
} else {
|
||||
setCursorLine(fCursorLine+1);
|
||||
setCursorLine(fCursorLine + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#processNewline()
|
||||
*/
|
||||
|
@ -384,6 +402,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
doNewline();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#getCursorLine()
|
||||
*/
|
||||
|
@ -392,6 +411,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
return fCursorLine;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#getCursorColumn()
|
||||
*/
|
||||
|
@ -400,6 +420,7 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
return fCursorColumn;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.emulator.IVT100EmulatorBackend#setCursor(int, int)
|
||||
*/
|
||||
|
@ -415,11 +436,11 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
*/
|
||||
public void setCursorColumn(int targetColumn) {
|
||||
synchronized (fTerminal) {
|
||||
if(targetColumn<0)
|
||||
targetColumn=0;
|
||||
else if(targetColumn>=fColumns)
|
||||
targetColumn=fColumns-1;
|
||||
fCursorColumn=targetColumn;
|
||||
if (targetColumn < 0)
|
||||
targetColumn = 0;
|
||||
else if (targetColumn >= fColumns)
|
||||
targetColumn = fColumns - 1;
|
||||
fCursorColumn = targetColumn;
|
||||
fWrapPending = false;
|
||||
// We make the assumption that nobody is changing the
|
||||
// terminal cursor except this class!
|
||||
|
@ -433,11 +454,11 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
*/
|
||||
public void setCursorLine(int targetLine) {
|
||||
synchronized (fTerminal) {
|
||||
if(targetLine<0)
|
||||
targetLine=0;
|
||||
else if(targetLine>=fLines)
|
||||
targetLine=fLines-1;
|
||||
fCursorLine=targetLine;
|
||||
if (targetLine < 0)
|
||||
targetLine = 0;
|
||||
else if (targetLine >= fLines)
|
||||
targetLine = fLines - 1;
|
||||
fCursorLine = targetLine;
|
||||
// We make the assumption that nobody is changing the
|
||||
// terminal cursor except this class!
|
||||
// This assumption gives a huge performance improvement
|
||||
|
@ -483,19 +504,19 @@ public class VT100EmulatorBackend implements IVT100EmulatorBackend {
|
|||
}
|
||||
|
||||
public void scrollUp(int n) {
|
||||
assert n>0;
|
||||
assert n > 0;
|
||||
synchronized (fTerminal) {
|
||||
int line = toAbsoluteLine(fScrollRegion.getTopLine());
|
||||
int nLines = Math.min(fTerminal.getHeight()-line, fScrollRegion.getHeight());
|
||||
int nLines = Math.min(fTerminal.getHeight() - line, fScrollRegion.getHeight());
|
||||
fTerminal.scroll(line, nLines, -n);
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollDown(int n) {
|
||||
assert n>0;
|
||||
assert n > 0;
|
||||
synchronized (fTerminal) {
|
||||
int line = toAbsoluteLine(fScrollRegion.getTopLine());
|
||||
int nLines = Math.min(fTerminal.getHeight()-line, fScrollRegion.getHeight());
|
||||
int nLines = Math.min(fTerminal.getHeight() - line, fScrollRegion.getHeight());
|
||||
fTerminal.scroll(line, nLines, n);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,8 +125,7 @@ import org.eclipse.ui.keys.IBindingService;
|
|||
*
|
||||
* @author Chris Thew <chris.thew@windriver.com>
|
||||
*/
|
||||
public class VT100TerminalControl implements ITerminalControlForText, ITerminalControl, ITerminalViewControl
|
||||
{
|
||||
public class VT100TerminalControl implements ITerminalControlForText, ITerminalControl, ITerminalViewControl {
|
||||
protected final static String[] LINE_DELIMITERS = { "\n" }; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
|
@ -166,10 +165,10 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
/**
|
||||
* Listens to changes in the preferences
|
||||
*/
|
||||
private final IPropertyChangeListener fPreferenceListener=new IPropertyChangeListener() {
|
||||
private final IPropertyChangeListener fPreferenceListener = new IPropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
if(event.getProperty().equals(ITerminalConstants.PREF_BUFFERLINES)
|
||||
if (event.getProperty().equals(ITerminalConstants.PREF_BUFFERLINES)
|
||||
|| event.getProperty().equals(ITerminalConstants.PREF_INVERT_COLORS)) {
|
||||
updatePreferences();
|
||||
}
|
||||
|
@ -205,13 +204,14 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
* Otherwise, clients need to maintain settings themselves.
|
||||
* @since 3.2
|
||||
*/
|
||||
public VT100TerminalControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors, boolean useCommonPrefs) {
|
||||
fConnectors=connectors;
|
||||
public VT100TerminalControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors,
|
||||
boolean useCommonPrefs) {
|
||||
fConnectors = connectors;
|
||||
fUseCommonPrefs = useCommonPrefs;
|
||||
fTerminalListener=target;
|
||||
fTerminalModel=TerminalTextDataFactory.makeTerminalTextData();
|
||||
fTerminalListener = target;
|
||||
fTerminalModel = TerminalTextDataFactory.makeTerminalTextData();
|
||||
fTerminalModel.setMaxHeight(1000);
|
||||
fInputStream=new PipedInputStream(8*1024);
|
||||
fInputStream = new PipedInputStream(8 * 1024);
|
||||
fTerminalText = new VT100Emulator(fTerminalModel, this, null);
|
||||
try {
|
||||
// Use Default Encoding as start, until setEncoding() is called
|
||||
|
@ -275,15 +275,15 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
@Override
|
||||
public void paste() {
|
||||
paste(DND.CLIPBOARD);
|
||||
// TODO paste in another thread.... to avoid blocking
|
||||
// new Thread() {
|
||||
// public void run() {
|
||||
// for (int i = 0; i < strText.length(); i++) {
|
||||
// sendChar(strText.charAt(i), false);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }.start();
|
||||
// TODO paste in another thread.... to avoid blocking
|
||||
// new Thread() {
|
||||
// public void run() {
|
||||
// for (int i = 0; i < strText.length(); i++) {
|
||||
// sendChar(strText.charAt(i), false);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }.start();
|
||||
}
|
||||
|
||||
private void paste(int clipboardType) {
|
||||
|
@ -297,7 +297,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
*/
|
||||
@Override
|
||||
public boolean pasteString(String strText) {
|
||||
if(!isConnected())
|
||||
if (!isConnected())
|
||||
return false;
|
||||
if (strText == null)
|
||||
return false;
|
||||
|
@ -319,7 +319,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
public void selectAll() {
|
||||
getCtlText().selectAll();
|
||||
if (fTerminalListener instanceof ITerminalListener2) {
|
||||
((ITerminalListener2)fTerminalListener).setTerminalSelectionChanged();
|
||||
((ITerminalListener2) fTerminalListener).setTerminalSelectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -351,7 +351,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
getTerminalText().clearTerminal();
|
||||
getCtlText().clearSelection();
|
||||
if (fTerminalListener instanceof ITerminalListener2) {
|
||||
((ITerminalListener2)fTerminalListener).setTerminalSelectionChanged();
|
||||
((ITerminalListener2) fTerminalListener).setTerminalSelectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -368,9 +368,9 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
*/
|
||||
@Override
|
||||
public String getSelection() {
|
||||
String txt= fCtlText.getSelectionText();
|
||||
if(txt==null)
|
||||
txt=""; //$NON-NLS-1$
|
||||
String txt = fCtlText.getSelectionText();
|
||||
if (txt == null)
|
||||
txt = ""; //$NON-NLS-1$
|
||||
return txt;
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
*/
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return fState==TerminalState.CONNECTED;
|
||||
return fState == TerminalState.CONNECTED;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -412,7 +412,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
@Override
|
||||
public void disposeTerminal() {
|
||||
Logger.log("entered."); //$NON-NLS-1$
|
||||
if(fUseCommonPrefs) {
|
||||
if (fUseCommonPrefs) {
|
||||
TerminalPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPreferenceListener);
|
||||
JFaceResources.getFontRegistry().removeListener(fFontListener);
|
||||
}
|
||||
|
@ -424,14 +424,12 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
@Override
|
||||
public void connectTerminal() {
|
||||
Logger.log("entered."); //$NON-NLS-1$
|
||||
if(getTerminalConnector()==null)
|
||||
if (getTerminalConnector() == null)
|
||||
return;
|
||||
fTerminalText.resetState();
|
||||
fApplicationCursorKeys = false;
|
||||
if(fConnector.getInitializationErrorMessage()!=null) {
|
||||
showErrorMessage(NLS.bind(
|
||||
TerminalMessages.CannotConnectTo,
|
||||
fConnector.getName(),
|
||||
if (fConnector.getInitializationErrorMessage() != null) {
|
||||
showErrorMessage(NLS.bind(TerminalMessages.CannotConnectTo, fConnector.getName(),
|
||||
fConnector.getInitializationErrorMessage()));
|
||||
// we cannot connect because the connector was not initialized
|
||||
return;
|
||||
|
@ -446,6 +444,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
public ITerminalConnector getTerminalConnector() {
|
||||
return fConnector;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl#disconnectTerminal()
|
||||
*/
|
||||
|
@ -454,27 +453,29 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
Logger.log("entered."); //$NON-NLS-1$
|
||||
|
||||
//Disconnect the remote side first
|
||||
if (getState()!=TerminalState.CLOSED) {
|
||||
if(getTerminalConnector()!=null) {
|
||||
if (getState() != TerminalState.CLOSED) {
|
||||
if (getTerminalConnector() != null) {
|
||||
getTerminalConnector().disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
//Ensure that a new Job can be started; then clean up old Job.
|
||||
Job job;
|
||||
synchronized(this) {
|
||||
synchronized (this) {
|
||||
job = fJob;
|
||||
fJob = null;
|
||||
}
|
||||
if (job!=null) {
|
||||
if (job != null) {
|
||||
job.cancel();
|
||||
// Join job to avoid leaving job running after workbench shutdown (333613).
|
||||
// Interrupt to be fast enough; cannot close fInputStream since it is re-used (bug 348700).
|
||||
Thread t = job.getThread();
|
||||
if(t!=null) t.interrupt();
|
||||
if (t != null)
|
||||
t.interrupt();
|
||||
try {
|
||||
job.join();
|
||||
} catch (InterruptedException e) {}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
fPollingTextCanvasModel.stopPolling();
|
||||
}
|
||||
|
@ -486,7 +487,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
do {
|
||||
if (!fDisplay.readAndDispatch())
|
||||
fDisplay.sleep();
|
||||
} while (getState()==TerminalState.CONNECTING);
|
||||
} while (getState() == TerminalState.CONNECTING);
|
||||
|
||||
if (getCtlText().isDisposed()) {
|
||||
disconnectTerminal();
|
||||
|
@ -506,23 +507,23 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
}
|
||||
|
||||
private synchronized void startReaderJob() {
|
||||
if(fJob==null) {
|
||||
fJob=new Job("Terminal data reader") { //$NON-NLS-1$
|
||||
if (fJob == null) {
|
||||
fJob = new Job("Terminal data reader") { //$NON-NLS-1$
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
IStatus status=Status.OK_STATUS;
|
||||
IStatus status = Status.OK_STATUS;
|
||||
try {
|
||||
while(true) {
|
||||
while(fInputStream.available()==0 && !monitor.isCanceled()) {
|
||||
while (true) {
|
||||
while (fInputStream.available() == 0 && !monitor.isCanceled()) {
|
||||
try {
|
||||
fInputStream.waitForAvailable(500);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
if(monitor.isCanceled()) {
|
||||
if (monitor.isCanceled()) {
|
||||
//Do not disconnect terminal here because another reader job may already be running
|
||||
status=Status.CANCEL_STATUS;
|
||||
status = Status.CANCEL_STATUS;
|
||||
break;
|
||||
}
|
||||
try {
|
||||
|
@ -530,7 +531,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
fTerminalText.processText();
|
||||
} catch (Exception e) {
|
||||
disconnectTerminal();
|
||||
status=new Status(IStatus.ERROR,TerminalPlugin.PLUGIN_ID,e.getLocalizedMessage(),e);
|
||||
status = new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, e.getLocalizedMessage(),
|
||||
e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -538,8 +540,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
// clean the job: start a new one when the connection gets restarted
|
||||
// Bug 208145: make sure we do not clean an other job that's already started (since it would become a Zombie)
|
||||
synchronized (VT100TerminalControl.this) {
|
||||
if (fJob==this) {
|
||||
fJob=null;
|
||||
if (fJob == this) {
|
||||
fJob = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -576,8 +578,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
} catch (SocketException socketException) {
|
||||
displayTextInTerminal(socketException.getMessage());
|
||||
|
||||
String strMsg = TerminalMessages.SocketError
|
||||
+ "!\n" + socketException.getMessage(); //$NON-NLS-1$
|
||||
String strMsg = TerminalMessages.SocketError + "!\n" + socketException.getMessage(); //$NON-NLS-1$
|
||||
showErrorMessage(strMsg);
|
||||
|
||||
Logger.logException(socketException);
|
||||
|
@ -601,7 +602,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
try {
|
||||
int byteToSend = chKey;
|
||||
OutputStream os = getOutputStream();
|
||||
if (os==null) {
|
||||
if (os == null) {
|
||||
// Bug 207785: NPE when trying to send char while no longer connected
|
||||
Logger.log("NOT sending '" + byteToSend + "' because no longer connected"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} else {
|
||||
|
@ -619,7 +620,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
byte[] bytesToSend = String.valueOf(chKey).getBytes(fEncoding);
|
||||
StringBuilder b = new StringBuilder("sending ESC"); //$NON-NLS-1$
|
||||
for (int i = 0; i < bytesToSend.length; i++) {
|
||||
if (i != 0) b.append(" +"); //$NON-NLS-1$
|
||||
if (i != 0)
|
||||
b.append(" +"); //$NON-NLS-1$
|
||||
b.append(" '" + bytesToSend[i] + "'"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
Logger.log(b.toString());
|
||||
|
@ -629,7 +631,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
byte[] bytesToSend = String.valueOf(chKey).getBytes(fEncoding);
|
||||
StringBuilder b = new StringBuilder("sending"); //$NON-NLS-1$
|
||||
for (int i = 0; i < bytesToSend.length; i++) {
|
||||
if (i != 0) b.append(" +"); //$NON-NLS-1$
|
||||
if (i != 0)
|
||||
b.append(" +"); //$NON-NLS-1$
|
||||
b.append(" '" + bytesToSend[i] + "'"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
Logger.log(b.toString());
|
||||
|
@ -642,8 +645,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
|
||||
displayTextInTerminal(socketException.getMessage());
|
||||
|
||||
String strMsg = TerminalMessages.SocketError
|
||||
+ "!\n" + socketException.getMessage(); //$NON-NLS-1$
|
||||
String strMsg = TerminalMessages.SocketError + "!\n" + socketException.getMessage(); //$NON-NLS-1$
|
||||
|
||||
showErrorMessage(strMsg);
|
||||
Logger.logException(socketException);
|
||||
|
@ -703,8 +705,10 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
* @see org.eclipse.tm.internal.terminal.control.ITerminalViewControl#updatePreferences()
|
||||
*/
|
||||
private void updatePreferences() {
|
||||
int bufferLineLimit = Platform.getPreferencesService().getInt(TerminalPlugin.PLUGIN_ID, ITerminalConstants.PREF_BUFFERLINES, 0, null);
|
||||
boolean invert = Platform.getPreferencesService().getBoolean(TerminalPlugin.PLUGIN_ID, ITerminalConstants.PREF_INVERT_COLORS, false, null);
|
||||
int bufferLineLimit = Platform.getPreferencesService().getInt(TerminalPlugin.PLUGIN_ID,
|
||||
ITerminalConstants.PREF_BUFFERLINES, 0, null);
|
||||
boolean invert = Platform.getPreferencesService().getBoolean(TerminalPlugin.PLUGIN_ID,
|
||||
ITerminalConstants.PREF_INVERT_COLORS, false, null);
|
||||
setBufferLineLimit(bufferLineLimit);
|
||||
setInvertedColors(invert);
|
||||
}
|
||||
|
@ -720,9 +724,9 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
*/
|
||||
@Override
|
||||
public void setFont(String fontName) {
|
||||
Font font=JFaceResources.getFont(fontName);
|
||||
Font font = JFaceResources.getFont(fontName);
|
||||
getCtlText().setFont(font);
|
||||
if(fCommandInputField!=null) {
|
||||
if (fCommandInputField != null) {
|
||||
fCommandInputField.setFont(font);
|
||||
}
|
||||
// Tell the TerminalControl singleton that the font has changed.
|
||||
|
@ -737,7 +741,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
@Deprecated
|
||||
public void setFont(Font font) {
|
||||
getCtlText().setFont(font);
|
||||
if(fCommandInputField!=null) {
|
||||
if (fCommandInputField != null) {
|
||||
fCommandInputField.setFont(font);
|
||||
}
|
||||
|
||||
|
@ -745,29 +749,36 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
fCtlText.onFontChange();
|
||||
getTerminalText().fontChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Font getFont() {
|
||||
return getCtlText().getFont();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Control getControl() {
|
||||
return fCtlText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Control getRootControl() {
|
||||
return fWndParent;
|
||||
}
|
||||
|
||||
protected void setupControls(Composite parent) {
|
||||
fWndParent=new Composite(parent,SWT.NONE);
|
||||
GridLayout layout=new GridLayout();
|
||||
layout.marginWidth=0; layout.marginHeight=0; layout.verticalSpacing=0;
|
||||
fWndParent = new Composite(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.marginWidth = 0;
|
||||
layout.marginHeight = 0;
|
||||
layout.verticalSpacing = 0;
|
||||
fWndParent.setLayout(layout);
|
||||
|
||||
ITerminalTextDataSnapshot snapshot=fTerminalModel.makeSnapshot();
|
||||
ITerminalTextDataSnapshot snapshot = fTerminalModel.makeSnapshot();
|
||||
// TODO how to get the initial size correctly!
|
||||
snapshot.updateSnapshot(false);
|
||||
fPollingTextCanvasModel=new PollingTextCanvasModel(snapshot);
|
||||
fCtlText=new TextCanvas(fWndParent,fPollingTextCanvasModel,SWT.NONE,new TextLineRenderer(fCtlText,fPollingTextCanvasModel));
|
||||
fPollingTextCanvasModel = new PollingTextCanvasModel(snapshot);
|
||||
fCtlText = new TextCanvas(fWndParent, fPollingTextCanvasModel, SWT.NONE,
|
||||
new TextLineRenderer(fCtlText, fPollingTextCanvasModel));
|
||||
|
||||
fCtlText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
fCtlText.addResizeHandler(new TextCanvas.ResizeListener() {
|
||||
|
@ -819,8 +830,9 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
*/
|
||||
@Override
|
||||
public void displayTextInTerminal(String text) {
|
||||
writeToTerminal("\r\n"+text+"\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
writeToTerminal("\r\n" + text + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
private void writeToTerminal(String text) {
|
||||
try {
|
||||
getRemoteToTerminalOutputStream().write(text.getBytes(fEncoding));
|
||||
|
@ -835,19 +847,20 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
|
||||
@Override
|
||||
public OutputStream getRemoteToTerminalOutputStream() {
|
||||
if(Logger.isLogEnabled()) {
|
||||
if (Logger.isLogEnabled()) {
|
||||
return new LoggingOutputStream(fInputStream.getOutputStream());
|
||||
} else {
|
||||
return fInputStream.getOutputStream();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isLogCharEnabled() {
|
||||
return TerminalPlugin.isOptionEnabled(Logger.TRACE_DEBUG_LOG_CHAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() {
|
||||
if(getTerminalConnector()!=null)
|
||||
if (getTerminalConnector() != null)
|
||||
return getTerminalConnector().getTerminalToRemoteStream();
|
||||
return null;
|
||||
}
|
||||
|
@ -877,6 +890,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
public VT100Emulator getTerminalText() {
|
||||
return fTerminalText;
|
||||
}
|
||||
|
||||
protected class TerminalMouseTrackListener implements MouseTrackListener {
|
||||
private IContextActivation terminalContextActivation = null;
|
||||
private IContextActivation editContextActivation = null;
|
||||
|
@ -898,7 +912,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
if (getState() == TerminalState.CONNECTED)
|
||||
captureKeyEvents(true);
|
||||
|
||||
IContextService contextService = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class);
|
||||
IContextService contextService = (IContextService) PlatformUI.getWorkbench()
|
||||
.getAdapter(IContextService.class);
|
||||
editContextActivation = contextService.activateContext("org.eclipse.tm.terminal.EditContext"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
@ -910,14 +925,17 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
|
||||
// Restore the command context to its previous value.
|
||||
|
||||
IContextService contextService = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class);
|
||||
IContextService contextService = (IContextService) PlatformUI.getWorkbench()
|
||||
.getAdapter(IContextService.class);
|
||||
contextService.deactivateContext(editContextActivation);
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
protected void captureKeyEvents(boolean capture) {
|
||||
IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
|
||||
IContextService contextService = (IContextService) PlatformUI.getWorkbench().getAdapter(IContextService.class);
|
||||
IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench()
|
||||
.getAdapter(IBindingService.class);
|
||||
IContextService contextService = (IContextService) PlatformUI.getWorkbench()
|
||||
.getAdapter(IContextService.class);
|
||||
|
||||
boolean enableKeyFilter = !capture;
|
||||
if (bindingService.isKeyFilterEnabled() != enableKeyFilter)
|
||||
|
@ -943,7 +961,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
@Override
|
||||
public void keyPressed(KeyEvent event) {
|
||||
//TODO next 2 lines are probably obsolete now
|
||||
if (getState()==TerminalState.CONNECTING)
|
||||
if (getState() == TerminalState.CONNECTING)
|
||||
return;
|
||||
|
||||
//TODO we should no longer handle copy & paste specially.
|
||||
|
@ -981,7 +999,7 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
boolean altKeyPressed = (event.stateMask & SWT.ALT) != 0 && !ctrlKeyPressed;
|
||||
|
||||
//if (!isConnected()) {
|
||||
if (fState==TerminalState.CLOSED) {
|
||||
if (fState == TerminalState.CLOSED) {
|
||||
// Pressing ENTER while not connected causes us to connect.
|
||||
if (character == '\r' && isConnectOnEnterIfClosed()) {
|
||||
connectTerminal();
|
||||
|
@ -1203,12 +1221,9 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
//
|
||||
// o The character is the DELETE character.
|
||||
|
||||
if (getTerminalConnector() == null
|
||||
|| getTerminalConnector().isLocalEcho() == false || altKeyPressed
|
||||
|| (character >= '\u0001' && character < '\t')
|
||||
|| (character > '\t' && character < '\r')
|
||||
|| (character > '\r' && character <= '\u001f')
|
||||
|| character == '\u007f') {
|
||||
if (getTerminalConnector() == null || getTerminalConnector().isLocalEcho() == false || altKeyPressed
|
||||
|| (character >= '\u0001' && character < '\t') || (character > '\t' && character < '\r')
|
||||
|| (character > '\r' && character <= '\u001f') || character == '\u007f') {
|
||||
// No local echoing.
|
||||
return;
|
||||
}
|
||||
|
@ -1232,13 +1247,15 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
*/
|
||||
@SuppressWarnings("cast")
|
||||
private void processKeyBinding(KeyEvent event, int accelerator) {
|
||||
IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
|
||||
IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench()
|
||||
.getAdapter(IBindingService.class);
|
||||
KeyStroke keyStroke = SWTKeySupport.convertAcceleratorToKeyStroke(accelerator);
|
||||
Binding binding = bindingService.getPerfectMatch(KeySequence.getInstance(keyStroke));
|
||||
if (binding != null) {
|
||||
ParameterizedCommand cmd = binding.getParameterizedCommand();
|
||||
if (cmd != null) {
|
||||
IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class);
|
||||
IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench()
|
||||
.getAdapter(IHandlerService.class);
|
||||
Event cmdEvent = new Event();
|
||||
cmdEvent.type = SWT.KeyDown;
|
||||
cmdEvent.display = event.display;
|
||||
|
@ -1252,9 +1269,9 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
Field f1 = event.getClass().getField("keyLocation"); //$NON-NLS-1$
|
||||
Field f2 = cmdEvent.getClass().getField("keyLocation"); //$NON-NLS-1$
|
||||
f2.set(cmdEvent, f1.get(event));
|
||||
} catch(NoSuchFieldException nsfe) {
|
||||
} catch (NoSuchFieldException nsfe) {
|
||||
/* ignore, this is Eclipse 3.5 or earlier */
|
||||
} catch(Throwable t) {
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
cmdEvent.stateMask = event.stateMask;
|
||||
|
@ -1262,8 +1279,8 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
try {
|
||||
handlerService.executeCommand(cmd, cmdEvent);
|
||||
} catch (ExecutionException e) {
|
||||
TerminalPlugin.getDefault().getLog().log(
|
||||
new Status(IStatus.ERROR,TerminalPlugin.PLUGIN_ID,e.getLocalizedMessage(),e));
|
||||
TerminalPlugin.getDefault().getLog()
|
||||
.log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, e.getLocalizedMessage(), e));
|
||||
} catch (Exception e) {
|
||||
// ignore other exceptions from cmd execution
|
||||
}
|
||||
|
@ -1278,22 +1295,20 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
fTerminalListener.setTerminalTitle(title);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerminalState getState() {
|
||||
return fState;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setState(TerminalState state) {
|
||||
fState=state;
|
||||
fState = state;
|
||||
fTerminalListener.setState(state);
|
||||
// enable the (blinking) cursor if the terminal is connected
|
||||
runAsyncInDisplayThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(fCtlText!=null && !fCtlText.isDisposed()) {
|
||||
if (fCtlText != null && !fCtlText.isDisposed()) {
|
||||
if (isConnected()) {
|
||||
fCtlText.setCursorEnabled(true);
|
||||
} else {
|
||||
|
@ -1305,29 +1320,32 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param runnable run in display thread
|
||||
*/
|
||||
private void runAsyncInDisplayThread(Runnable runnable) {
|
||||
if(Display.findDisplay(Thread.currentThread())!=null)
|
||||
if (Display.findDisplay(Thread.currentThread()) != null)
|
||||
runnable.run();
|
||||
else if(PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench().getDisplay() != null && !PlatformUI.getWorkbench().getDisplay().isDisposed())
|
||||
else if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench().getDisplay() != null
|
||||
&& !PlatformUI.getWorkbench().getDisplay().isDisposed())
|
||||
PlatformUI.getWorkbench().getDisplay().asyncExec(runnable);
|
||||
// else should not happen and we ignore it...
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSettingsSummary() {
|
||||
if(getTerminalConnector()!=null)
|
||||
if (getTerminalConnector() != null)
|
||||
return getTerminalConnector().getSettingsSummary();
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnector(ITerminalConnector connector) {
|
||||
fConnector=connector;
|
||||
fConnector = connector;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICommandInputField getCommandInputField() {
|
||||
return fCommandInputField;
|
||||
|
@ -1335,12 +1353,12 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
|
||||
@Override
|
||||
public void setCommandInputField(ICommandInputField inputField) {
|
||||
if(fCommandInputField!=null)
|
||||
if (fCommandInputField != null)
|
||||
fCommandInputField.dispose();
|
||||
fCommandInputField=inputField;
|
||||
if(fCommandInputField!=null)
|
||||
fCommandInputField = inputField;
|
||||
if (fCommandInputField != null)
|
||||
fCommandInputField.createControl(fWndParent, this);
|
||||
if(fWndParent.isVisible())
|
||||
if (fWndParent.isVisible())
|
||||
fWndParent.layout(true);
|
||||
}
|
||||
|
||||
|
@ -1351,10 +1369,10 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
|
|||
|
||||
@Override
|
||||
public void setBufferLineLimit(int bufferLineLimit) {
|
||||
if(bufferLineLimit<=0)
|
||||
if (bufferLineLimit <= 0)
|
||||
return;
|
||||
synchronized (fTerminalModel) {
|
||||
if(fTerminalModel.getHeight()>bufferLineLimit)
|
||||
if (fTerminalModel.getHeight() > bufferLineLimit)
|
||||
fTerminalModel.setDimensions(bufferLineLimit, fTerminalModel.getWidth());
|
||||
fTerminalModel.setMaxHeight(bufferLineLimit);
|
||||
}
|
||||
|
|
|
@ -66,19 +66,21 @@ public interface ISnapshotChanges {
|
|||
boolean hasLineChanged(int line);
|
||||
|
||||
void markDimensionsChanged();
|
||||
|
||||
boolean hasDimensionsChanged();
|
||||
|
||||
void markCursorChanged();
|
||||
|
||||
/**
|
||||
* @return true if the terminal data has changed
|
||||
*/
|
||||
boolean hasTerminalChanged();
|
||||
|
||||
/**
|
||||
* mark the terminal as changed
|
||||
*/
|
||||
void setTerminalChanged();
|
||||
|
||||
|
||||
void copyChangedLines(ITerminalTextData dest, ITerminalTextData source);
|
||||
|
||||
/**
|
||||
|
@ -86,7 +88,9 @@ public interface ISnapshotChanges {
|
|||
* @param size number of lines to follow
|
||||
*/
|
||||
void setInterestWindow(int startLine, int size);
|
||||
|
||||
int getInterestWindowStartLine();
|
||||
|
||||
int getInterestWindowSize();
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ package org.eclipse.tm.internal.terminal.model;
|
|||
|
||||
import org.eclipse.tm.terminal.model.ITerminalTextData;
|
||||
|
||||
|
||||
/**
|
||||
* Collects the changes of the {@link ITerminalTextData}
|
||||
*
|
||||
|
@ -54,17 +53,19 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
|
||||
public SnapshotChanges(int nLines) {
|
||||
setChangedLinesLength(nLines);
|
||||
fFirstChangedLine=Integer.MAX_VALUE;
|
||||
fLastChangedLine=-1;
|
||||
fFirstChangedLine = Integer.MAX_VALUE;
|
||||
fLastChangedLine = -1;
|
||||
}
|
||||
|
||||
public SnapshotChanges(int windowStart, int windowSize) {
|
||||
setChangedLinesLength(windowStart+windowSize);
|
||||
fFirstChangedLine=Integer.MAX_VALUE;
|
||||
fLastChangedLine=-1;
|
||||
fInterestWindowStartLine=windowStart;
|
||||
fInterestWindowSize=windowSize;
|
||||
setChangedLinesLength(windowStart + windowSize);
|
||||
fFirstChangedLine = Integer.MAX_VALUE;
|
||||
fLastChangedLine = -1;
|
||||
fInterestWindowStartLine = windowStart;
|
||||
fInterestWindowSize = windowSize;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used in asserts to throw an {@link RuntimeException}.
|
||||
* This is useful for tests.
|
||||
|
@ -73,6 +74,7 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
private boolean throwRuntimeException() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param line
|
||||
* @param size
|
||||
|
@ -82,12 +84,13 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
* It used to be package protected, and it is public only for Unit Tests.
|
||||
*/
|
||||
public boolean isInInterestWindow(int line, int size) {
|
||||
if(fInterestWindowSize<=0)
|
||||
if (fInterestWindowSize <= 0)
|
||||
return true;
|
||||
if(line+size<=fInterestWindowStartLine || line>=fInterestWindowStartLine+fInterestWindowSize)
|
||||
if (line + size <= fInterestWindowStartLine || line >= fInterestWindowStartLine + fInterestWindowSize)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param line
|
||||
* @return true if the line is within the interest window
|
||||
|
@ -96,12 +99,13 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
* It used to be package protected, and it is public only for Unit Tests.
|
||||
*/
|
||||
public boolean isInInterestWindow(int line) {
|
||||
if(fInterestWindowSize<=0)
|
||||
if (fInterestWindowSize <= 0)
|
||||
return true;
|
||||
if(line<fInterestWindowStartLine || line>=fInterestWindowStartLine+fInterestWindowSize)
|
||||
if (line < fInterestWindowStartLine || line >= fInterestWindowStartLine + fInterestWindowSize)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param line
|
||||
* @return the line within the window
|
||||
|
@ -110,12 +114,13 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
* It used to be package protected, and it is public only for Unit Tests.
|
||||
*/
|
||||
public int fitLineToWindow(int line) {
|
||||
if(fInterestWindowSize<=0)
|
||||
if (fInterestWindowSize <= 0)
|
||||
return line;
|
||||
if(line<fInterestWindowStartLine)
|
||||
if (line < fInterestWindowStartLine)
|
||||
return fInterestWindowStartLine;
|
||||
return line;
|
||||
}
|
||||
|
||||
/**
|
||||
* The result is only defined if {@link #isInInterestWindow(int, int)} returns true!
|
||||
* @param line the line <b>before</b> {@link #fitLineToWindow(int)} has been called!
|
||||
|
@ -129,99 +134,110 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
* move the window correctly!
|
||||
*/
|
||||
public int fitSizeToWindow(int line, int size) {
|
||||
if(fInterestWindowSize<=0)
|
||||
if (fInterestWindowSize <= 0)
|
||||
return size;
|
||||
if(line<fInterestWindowStartLine) {
|
||||
size-=fInterestWindowStartLine-line;
|
||||
line=fInterestWindowStartLine;
|
||||
if (line < fInterestWindowStartLine) {
|
||||
size -= fInterestWindowStartLine - line;
|
||||
line = fInterestWindowStartLine;
|
||||
}
|
||||
if(line+size>fInterestWindowStartLine+fInterestWindowSize)
|
||||
size=fInterestWindowStartLine+fInterestWindowSize-line;
|
||||
if (line + size > fInterestWindowStartLine + fInterestWindowSize)
|
||||
size = fInterestWindowStartLine + fInterestWindowSize - line;
|
||||
return size;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#markLineChanged(int)
|
||||
*/
|
||||
public void markLineChanged(int line) {
|
||||
if(!isInInterestWindow(line))
|
||||
if (!isInInterestWindow(line))
|
||||
return;
|
||||
line=fitLineToWindow(line);
|
||||
if(line<fFirstChangedLine)
|
||||
fFirstChangedLine=line;
|
||||
if(line>fLastChangedLine)
|
||||
fLastChangedLine=line;
|
||||
line = fitLineToWindow(line);
|
||||
if (line < fFirstChangedLine)
|
||||
fFirstChangedLine = line;
|
||||
if (line > fLastChangedLine)
|
||||
fLastChangedLine = line;
|
||||
// in case the terminal got resized we expand
|
||||
// don't remember the changed line because
|
||||
// there is nothing to copy
|
||||
if(line<getChangedLineLength()) {
|
||||
setChangedLine(line,true);
|
||||
if (line < getChangedLineLength()) {
|
||||
setChangedLine(line, true);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#markLinesChanged(int, int)
|
||||
*/
|
||||
public void markLinesChanged(int line, int n) {
|
||||
if(n<=0 || !isInInterestWindow(line,n))
|
||||
if (n <= 0 || !isInInterestWindow(line, n))
|
||||
return;
|
||||
// do not exceed the bounds of fChangedLines
|
||||
// the terminal might have been resized and
|
||||
// we can only keep changes for the size of the
|
||||
// previous terminal
|
||||
n=fitSizeToWindow(line, n);
|
||||
line=fitLineToWindow(line);
|
||||
int m=Math.min(line+n, getChangedLineLength());
|
||||
n = fitSizeToWindow(line, n);
|
||||
line = fitLineToWindow(line);
|
||||
int m = Math.min(line + n, getChangedLineLength());
|
||||
for (int i = line; i < m; i++) {
|
||||
setChangedLine(i,true);
|
||||
setChangedLine(i, true);
|
||||
}
|
||||
// this sets fFirstChangedLine as well
|
||||
markLineChanged(line);
|
||||
// this sets fLastChangedLine as well
|
||||
markLineChanged(line+n-1);
|
||||
markLineChanged(line + n - 1);
|
||||
}
|
||||
|
||||
public void markCursorChanged() {
|
||||
fCursorHasChanged=true;
|
||||
fCursorHasChanged = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#convertScrollingIntoChanges()
|
||||
*/
|
||||
public void convertScrollingIntoChanges() {
|
||||
markLinesChanged(fScrollWindowStartLine,fScrollWindowSize);
|
||||
fScrollWindowStartLine=0;
|
||||
fScrollWindowSize=0;
|
||||
fScrollWindowShift=0;
|
||||
markLinesChanged(fScrollWindowStartLine, fScrollWindowSize);
|
||||
fScrollWindowStartLine = 0;
|
||||
fScrollWindowSize = 0;
|
||||
fScrollWindowShift = 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#hasChanged()
|
||||
*/
|
||||
public boolean hasChanged() {
|
||||
if(fFirstChangedLine!=Integer.MAX_VALUE || fLastChangedLine>0 || fScrollWindowShift!=0 ||fDimensionsChanged || fCursorHasChanged)
|
||||
if (fFirstChangedLine != Integer.MAX_VALUE || fLastChangedLine > 0 || fScrollWindowShift != 0
|
||||
|| fDimensionsChanged || fCursorHasChanged)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void markDimensionsChanged() {
|
||||
fDimensionsChanged=true;
|
||||
fDimensionsChanged = true;
|
||||
}
|
||||
|
||||
public boolean hasDimensionsChanged() {
|
||||
return fDimensionsChanged;
|
||||
}
|
||||
|
||||
public boolean hasTerminalChanged() {
|
||||
return fTerminalHasChanged;
|
||||
}
|
||||
|
||||
public void setTerminalChanged() {
|
||||
fTerminalHasChanged=true;
|
||||
fTerminalHasChanged = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#scroll(int, int, int)
|
||||
*/
|
||||
public void scroll(int startLine, int size, int shift) {
|
||||
size=fitSizeToWindow(startLine, size);
|
||||
startLine=fitLineToWindow(startLine);
|
||||
size = fitSizeToWindow(startLine, size);
|
||||
startLine = fitLineToWindow(startLine);
|
||||
// let's track only negative shifts
|
||||
if(fScrollDontTrack) {
|
||||
if (fScrollDontTrack) {
|
||||
// we are in a state where we cannot track scrolling
|
||||
// so let's simply mark the scrolled lines as changed
|
||||
markLinesChanged(startLine, size);
|
||||
} else if(shift>=0) {
|
||||
} else if (shift >= 0) {
|
||||
// we cannot handle positive scroll
|
||||
// forget about clever caching of scroll events
|
||||
doNotTrackScrollingAnymore();
|
||||
|
@ -229,12 +245,12 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
markLinesChanged(startLine, size);
|
||||
} else {
|
||||
// we have already scrolled
|
||||
if(fScrollWindowShift<0) {
|
||||
if (fScrollWindowShift < 0) {
|
||||
// we have already scrolled
|
||||
if(fScrollWindowStartLine==startLine && fScrollWindowSize==size) {
|
||||
if (fScrollWindowStartLine == startLine && fScrollWindowSize == size) {
|
||||
// we are scrolling the same region again?
|
||||
fScrollWindowShift+=shift;
|
||||
scrollChangesLinesWithNegativeShift(startLine,size,shift);
|
||||
fScrollWindowShift += shift;
|
||||
scrollChangesLinesWithNegativeShift(startLine, size, shift);
|
||||
} else {
|
||||
// mark all lines in the old scroll region as changed
|
||||
doNotTrackScrollingAnymore();
|
||||
|
@ -243,28 +259,30 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
}
|
||||
} else {
|
||||
// first scroll in this change -- we just notify it
|
||||
fScrollWindowStartLine=startLine;
|
||||
fScrollWindowSize=size;
|
||||
fScrollWindowShift=shift;
|
||||
scrollChangesLinesWithNegativeShift(startLine,size,shift);
|
||||
fScrollWindowStartLine = startLine;
|
||||
fScrollWindowSize = size;
|
||||
fScrollWindowShift = shift;
|
||||
scrollChangesLinesWithNegativeShift(startLine, size, shift);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Some incompatible scrolling occurred. We cannot do the
|
||||
* scroll optimization anymore...
|
||||
*/
|
||||
private void doNotTrackScrollingAnymore() {
|
||||
if(fScrollWindowSize>0) {
|
||||
if (fScrollWindowSize > 0) {
|
||||
// convert the current scrolling into changes
|
||||
markLinesChanged(fScrollWindowStartLine, fScrollWindowSize);
|
||||
fScrollWindowStartLine=0;
|
||||
fScrollWindowSize=0;
|
||||
fScrollWindowShift=0;
|
||||
fScrollWindowStartLine = 0;
|
||||
fScrollWindowSize = 0;
|
||||
fScrollWindowShift = 0;
|
||||
}
|
||||
// don't be clever on scrolling anymore
|
||||
fScrollDontTrack=true;
|
||||
fScrollDontTrack = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls the changed lines data
|
||||
*
|
||||
|
@ -273,75 +291,82 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
* @param shift must be negative!
|
||||
*/
|
||||
private void scrollChangesLinesWithNegativeShift(int line, int n, int shift) {
|
||||
assert shift <0 || throwRuntimeException();
|
||||
assert shift < 0 || throwRuntimeException();
|
||||
// scroll the region
|
||||
// don't run out of bounds!
|
||||
int m=Math.min(line+n+shift,getChangedLineLength()+shift);
|
||||
int m = Math.min(line + n + shift, getChangedLineLength() + shift);
|
||||
for (int i = line; i < m; i++) {
|
||||
setChangedLine(i, hasLineChanged(i-shift));
|
||||
setChangedLine(i, hasLineChanged(i - shift));
|
||||
// move the first changed line up.
|
||||
// We don't have to move the maximum down,
|
||||
// because with a shift scroll, the max is moved
|
||||
// my the next loop in this method
|
||||
if(i<fFirstChangedLine && hasLineChanged(i)) {
|
||||
fFirstChangedLine=i;
|
||||
if (i < fFirstChangedLine && hasLineChanged(i)) {
|
||||
fFirstChangedLine = i;
|
||||
}
|
||||
}
|
||||
// mark the "opened" lines as changed
|
||||
for (int i = Math.max(0,line+n+shift); i < line+n; i++) {
|
||||
for (int i = Math.max(0, line + n + shift); i < line + n; i++) {
|
||||
markLineChanged(i);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#setAllChanged(int)
|
||||
*/
|
||||
public void setAllChanged(int height) {
|
||||
fScrollWindowStartLine=0;
|
||||
fScrollWindowSize=0;
|
||||
fScrollWindowShift=0;
|
||||
fFirstChangedLine=fitLineToWindow(0);
|
||||
fLastChangedLine=fFirstChangedLine+fitSizeToWindow(0, height)-1;
|
||||
fScrollWindowStartLine = 0;
|
||||
fScrollWindowSize = 0;
|
||||
fScrollWindowShift = 0;
|
||||
fFirstChangedLine = fitLineToWindow(0);
|
||||
fLastChangedLine = fFirstChangedLine + fitSizeToWindow(0, height) - 1;
|
||||
// no need to keep an array of changes anymore
|
||||
setChangedLinesLength(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#getFirstChangedLine()
|
||||
*/
|
||||
public int getFirstChangedLine() {
|
||||
return fFirstChangedLine;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#getLastChangedLine()
|
||||
*/
|
||||
public int getLastChangedLine() {
|
||||
return fLastChangedLine;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#getScrollWindowStartLine()
|
||||
*/
|
||||
public int getScrollWindowStartLine() {
|
||||
return fScrollWindowStartLine;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#getScrollWindowSize()
|
||||
*/
|
||||
public int getScrollWindowSize() {
|
||||
return fScrollWindowSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#getScrollWindowShift()
|
||||
*/
|
||||
public int getScrollWindowShift() {
|
||||
return fScrollWindowShift;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#copyChangedLines(org.eclipse.tm.terminal.model.ITerminalTextData, org.eclipse.tm.terminal.model.ITerminalTextData)
|
||||
*/
|
||||
public void copyChangedLines(ITerminalTextData dest, ITerminalTextData source) {
|
||||
int n=Math.min(fLastChangedLine+1,source.getHeight());
|
||||
for (int i = fFirstChangedLine; i < n ; i++) {
|
||||
if(hasLineChanged(i))
|
||||
dest.copyLine(source,i,i);
|
||||
int n = Math.min(fLastChangedLine + 1, source.getHeight());
|
||||
for (int i = fFirstChangedLine; i < n; i++) {
|
||||
if (hasLineChanged(i))
|
||||
dest.copyLine(source, i, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,25 +379,25 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
}
|
||||
|
||||
public void setInterestWindow(int startLine, int size) {
|
||||
int oldStartLine=fInterestWindowStartLine;
|
||||
int oldSize=fInterestWindowSize;
|
||||
fInterestWindowStartLine=startLine;
|
||||
fInterestWindowSize=size;
|
||||
if(oldSize>0) {
|
||||
int shift=oldStartLine-startLine;
|
||||
if(shift==0) {
|
||||
if(size>oldSize) {
|
||||
int oldStartLine = fInterestWindowStartLine;
|
||||
int oldSize = fInterestWindowSize;
|
||||
fInterestWindowStartLine = startLine;
|
||||
fInterestWindowSize = size;
|
||||
if (oldSize > 0) {
|
||||
int shift = oldStartLine - startLine;
|
||||
if (shift == 0) {
|
||||
if (size > oldSize) {
|
||||
// add lines to the end
|
||||
markLinesChanged(oldStartLine+oldSize, size-oldSize);
|
||||
markLinesChanged(oldStartLine + oldSize, size - oldSize);
|
||||
}
|
||||
// else no lines within the window have changed
|
||||
|
||||
} else if(Math.abs(shift)<size) {
|
||||
if(shift<0) {
|
||||
} else if (Math.abs(shift) < size) {
|
||||
if (shift < 0) {
|
||||
// we can scroll
|
||||
scroll(startLine, oldSize, shift);
|
||||
// mark the lines at the end as new
|
||||
for (int i = oldStartLine+oldSize; i < startLine+size; i++) {
|
||||
for (int i = oldStartLine + oldSize; i < startLine + size; i++) {
|
||||
markLineChanged(i);
|
||||
}
|
||||
} else {
|
||||
|
@ -386,11 +411,12 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ISnapshotChanges#hasLineChanged(int)
|
||||
*/
|
||||
public boolean hasLineChanged(int line) {
|
||||
if(line<fChangedLines.length)
|
||||
if (line < fChangedLines.length)
|
||||
return fChangedLines[line];
|
||||
// since the height of the terminal could
|
||||
// have changed but we have tracked only changes
|
||||
|
@ -398,13 +424,16 @@ public class SnapshotChanges implements ISnapshotChanges {
|
|||
// the the range of the previous height has changed
|
||||
return isInInterestWindow(line);
|
||||
}
|
||||
|
||||
int getChangedLineLength() {
|
||||
return fChangedLines.length;
|
||||
}
|
||||
void setChangedLine(int line,boolean changed){
|
||||
fChangedLines[line]=changed;
|
||||
|
||||
void setChangedLine(int line, boolean changed) {
|
||||
fChangedLines[line] = changed;
|
||||
}
|
||||
|
||||
void setChangedLinesLength(int length) {
|
||||
fChangedLines=new boolean[length];
|
||||
fChangedLines = new boolean[length];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,84 +23,111 @@ import org.eclipse.tm.terminal.model.Style;
|
|||
*/
|
||||
public class SynchronizedTerminalTextData implements ITerminalTextData {
|
||||
final ITerminalTextData fData;
|
||||
|
||||
public SynchronizedTerminalTextData(ITerminalTextData data) {
|
||||
fData=data;
|
||||
fData = data;
|
||||
}
|
||||
|
||||
synchronized public void addLine() {
|
||||
fData.addLine();
|
||||
}
|
||||
|
||||
synchronized public void cleanLine(int line) {
|
||||
fData.cleanLine(line);
|
||||
}
|
||||
|
||||
synchronized public void copy(ITerminalTextData source) {
|
||||
fData.copy(source);
|
||||
}
|
||||
|
||||
synchronized public void copyLine(ITerminalTextData source, int sourceLine, int destLine) {
|
||||
fData.copyLine(source, sourceLine, destLine);
|
||||
}
|
||||
|
||||
synchronized public void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine, int length) {
|
||||
fData.copyRange(source, sourceStartLine, destStartLine, length);
|
||||
}
|
||||
|
||||
synchronized public char getChar(int line, int column) {
|
||||
return fData.getChar(line, column);
|
||||
}
|
||||
|
||||
synchronized public char[] getChars(int line) {
|
||||
return fData.getChars(line);
|
||||
}
|
||||
|
||||
synchronized public int getCursorColumn() {
|
||||
return fData.getCursorColumn();
|
||||
}
|
||||
|
||||
synchronized public int getCursorLine() {
|
||||
return fData.getCursorLine();
|
||||
}
|
||||
|
||||
synchronized public int getHeight() {
|
||||
return fData.getHeight();
|
||||
}
|
||||
|
||||
synchronized public LineSegment[] getLineSegments(int line, int startCol, int numberOfCols) {
|
||||
return fData.getLineSegments(line, startCol, numberOfCols);
|
||||
}
|
||||
|
||||
synchronized public int getMaxHeight() {
|
||||
return fData.getMaxHeight();
|
||||
}
|
||||
|
||||
synchronized public Style getStyle(int line, int column) {
|
||||
return fData.getStyle(line, column);
|
||||
}
|
||||
|
||||
synchronized public Style[] getStyles(int line) {
|
||||
return fData.getStyles(line);
|
||||
}
|
||||
|
||||
synchronized public int getWidth() {
|
||||
return fData.getWidth();
|
||||
}
|
||||
|
||||
synchronized public ITerminalTextDataSnapshot makeSnapshot() {
|
||||
return fData.makeSnapshot();
|
||||
}
|
||||
|
||||
synchronized public void scroll(int startLine, int size, int shift) {
|
||||
fData.scroll(startLine, size, shift);
|
||||
}
|
||||
|
||||
synchronized public void setChar(int line, int column, char c, Style style) {
|
||||
fData.setChar(line, column, c, style);
|
||||
}
|
||||
|
||||
synchronized public void setChars(int line, int column, char[] chars, int start, int len, Style style) {
|
||||
fData.setChars(line, column, chars, start, len, style);
|
||||
}
|
||||
|
||||
synchronized public void setChars(int line, int column, char[] chars, Style style) {
|
||||
fData.setChars(line, column, chars, style);
|
||||
}
|
||||
|
||||
synchronized public void setCursorColumn(int column) {
|
||||
fData.setCursorColumn(column);
|
||||
}
|
||||
|
||||
synchronized public void setCursorLine(int line) {
|
||||
fData.setCursorLine(line);
|
||||
}
|
||||
|
||||
synchronized public void setDimensions(int height, int width) {
|
||||
fData.setDimensions(height, width);
|
||||
}
|
||||
|
||||
synchronized public void setMaxHeight(int height) {
|
||||
fData.setMaxHeight(height);
|
||||
}
|
||||
|
||||
synchronized public boolean isWrappedLine(int line) {
|
||||
return fData.isWrappedLine(line);
|
||||
}
|
||||
|
||||
synchronized public void setWrappedLine(int line) {
|
||||
fData.setWrappedLine(line);
|
||||
}
|
||||
|
|
|
@ -33,9 +33,10 @@ public class TerminalTextData implements ITerminalTextData {
|
|||
/**
|
||||
* A list of active snapshots
|
||||
*/
|
||||
public TerminalTextDataSnapshot[] fSnapshots=new TerminalTextDataSnapshot[0];
|
||||
public TerminalTextDataSnapshot[] fSnapshots = new TerminalTextDataSnapshot[0];
|
||||
private int fCursorColumn;
|
||||
private int fCursorLine;
|
||||
|
||||
/**
|
||||
* Debug helper method -- use as "New Detail Formatter.." in the
|
||||
* debugger variables view:
|
||||
|
@ -46,13 +47,13 @@ public class TerminalTextData implements ITerminalTextData {
|
|||
* @return a string representation of the content
|
||||
*/
|
||||
static public String toMultiLineText(ITerminalTextDataReadOnly term, int start, int len) {
|
||||
if(len<0)
|
||||
len=term.getHeight();
|
||||
StringBuffer buff=new StringBuffer();
|
||||
int width=term.getWidth();
|
||||
int n=Math.min(len,term.getHeight()-start);
|
||||
if (len < 0)
|
||||
len = term.getHeight();
|
||||
StringBuffer buff = new StringBuffer();
|
||||
int width = term.getWidth();
|
||||
int n = Math.min(len, term.getHeight() - start);
|
||||
for (int line = start; line < n; line++) {
|
||||
if(line>0)
|
||||
if (line > 0)
|
||||
buff.append("\n"); //$NON-NLS-1$
|
||||
for (int column = 0; column < width; column++) {
|
||||
buff.append(term.getChar(line, column));
|
||||
|
@ -83,71 +84,86 @@ public class TerminalTextData implements ITerminalTextData {
|
|||
public TerminalTextData() {
|
||||
this(new TerminalTextDataFastScroll());
|
||||
|
||||
// this(new TerminalTextDataStore());
|
||||
// this(new TerminalTextDataStore());
|
||||
}
|
||||
|
||||
public TerminalTextData(ITerminalTextData data) {
|
||||
fData=data;
|
||||
fData = data;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return fData.getWidth();
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
// no need for an extra variable
|
||||
return fData.getHeight();
|
||||
}
|
||||
|
||||
public void setDimensions(int height, int width) {
|
||||
int h=getHeight();
|
||||
int w=getWidth();
|
||||
if(w==width && h==height)
|
||||
int h = getHeight();
|
||||
int w = getWidth();
|
||||
if (w == width && h == height)
|
||||
return;
|
||||
fData.setDimensions(height, width);
|
||||
sendDimensionsChanged(h, w, height, width);
|
||||
}
|
||||
|
||||
private void sendDimensionsChanged(int oldHeight, int oldWidth, int newHeight, int newWidth) {
|
||||
// determine what has changed
|
||||
if(oldWidth==newWidth) {
|
||||
if(oldHeight<newHeight)
|
||||
sendLinesChangedToSnapshot(oldHeight, newHeight-oldHeight);
|
||||
if (oldWidth == newWidth) {
|
||||
if (oldHeight < newHeight)
|
||||
sendLinesChangedToSnapshot(oldHeight, newHeight - oldHeight);
|
||||
else
|
||||
sendLinesChangedToSnapshot(newHeight,oldHeight-newHeight);
|
||||
sendLinesChangedToSnapshot(newHeight, oldHeight - newHeight);
|
||||
} else {
|
||||
sendLinesChangedToSnapshot(0, oldHeight);
|
||||
}
|
||||
sendDimensionsChanged();
|
||||
}
|
||||
|
||||
public LineSegment[] getLineSegments(int line, int column, int len) {
|
||||
return fData.getLineSegments(line, column, len);
|
||||
}
|
||||
|
||||
public char getChar(int line, int column) {
|
||||
return fData.getChar(line, column);
|
||||
}
|
||||
|
||||
public Style getStyle(int line, int column) {
|
||||
return fData.getStyle(line, column);
|
||||
}
|
||||
|
||||
public void setChar(int line, int column, char c, Style style) {
|
||||
fData.setChar(line, column, c, style);
|
||||
sendLineChangedToSnapshots(line);
|
||||
}
|
||||
|
||||
public void setChars(int line, int column, char[] chars, Style style) {
|
||||
fData.setChars(line, column, chars, style);
|
||||
sendLineChangedToSnapshots(line);
|
||||
}
|
||||
|
||||
public void setChars(int line, int column, char[] chars, int start, int len, Style style) {
|
||||
fData.setChars(line, column, chars, start, len, style);
|
||||
sendLineChangedToSnapshots(line);
|
||||
}
|
||||
|
||||
public void scroll(int startLine, int size, int shift) {
|
||||
fData.scroll(startLine, size, shift);
|
||||
sendScrolledToSnapshots(startLine, size, shift);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return fData.toString();
|
||||
}
|
||||
|
||||
private void sendDimensionsChanged() {
|
||||
for (int i = 0; i < fSnapshots.length; i++) {
|
||||
fSnapshots[i].markDimensionsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param line notifies snapshots that line line has changed
|
||||
*/
|
||||
|
@ -156,12 +172,13 @@ public class TerminalTextData implements ITerminalTextData {
|
|||
fSnapshots[i].markLineChanged(line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify snapshots that multiple lines have changed
|
||||
* @param line changed line
|
||||
* @param n number of changed lines
|
||||
*/
|
||||
protected void sendLinesChangedToSnapshot(int line,int n) {
|
||||
protected void sendLinesChangedToSnapshot(int line, int n) {
|
||||
for (int i = 0; i < fSnapshots.length; i++) {
|
||||
fSnapshots[i].markLinesChanged(line, n);
|
||||
}
|
||||
|
@ -173,47 +190,50 @@ public class TerminalTextData implements ITerminalTextData {
|
|||
* @param size size of scrolled region (number of lines)
|
||||
* @param shift delta by which the region is scrolled
|
||||
*/
|
||||
protected void sendScrolledToSnapshots(int startLine,int size, int shift) {
|
||||
protected void sendScrolledToSnapshots(int startLine, int size, int shift) {
|
||||
for (int i = 0; i < fSnapshots.length; i++) {
|
||||
fSnapshots[i].scroll(startLine, size, shift);
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendCursorChanged() {
|
||||
for (int i = 0; i < fSnapshots.length; i++) {
|
||||
fSnapshots[i].markCursorChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the snapshot from the @observer@ list
|
||||
* @param snapshot A snapshot of a terminal model
|
||||
*/
|
||||
protected void removeSnapshot(TerminalTextDataSnapshot snapshot) {
|
||||
// poor mans approach to modify the array
|
||||
List<TerminalTextDataSnapshot> list=new ArrayList<TerminalTextDataSnapshot>();
|
||||
List<TerminalTextDataSnapshot> list = new ArrayList<TerminalTextDataSnapshot>();
|
||||
list.addAll(Arrays.asList(fSnapshots));
|
||||
list.remove(snapshot);
|
||||
fSnapshots=list.toArray(new TerminalTextDataSnapshot[list.size()]);
|
||||
fSnapshots = list.toArray(new TerminalTextDataSnapshot[list.size()]);
|
||||
}
|
||||
|
||||
public ITerminalTextDataSnapshot makeSnapshot() {
|
||||
// poor mans approach to modify the array
|
||||
TerminalTextDataSnapshot snapshot=new TerminalTextDataSnapshot(this);
|
||||
TerminalTextDataSnapshot snapshot = new TerminalTextDataSnapshot(this);
|
||||
snapshot.markDimensionsChanged();
|
||||
List<TerminalTextDataSnapshot> list=new ArrayList<TerminalTextDataSnapshot>();
|
||||
List<TerminalTextDataSnapshot> list = new ArrayList<TerminalTextDataSnapshot>();
|
||||
list.addAll(Arrays.asList(fSnapshots));
|
||||
list.add(snapshot);
|
||||
fSnapshots=list.toArray(new TerminalTextDataSnapshot[list.size()]);
|
||||
fSnapshots = list.toArray(new TerminalTextDataSnapshot[list.size()]);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
public void addLine() {
|
||||
int oldHeight=getHeight();
|
||||
int oldHeight = getHeight();
|
||||
fData.addLine();
|
||||
// was is an append or a scroll?
|
||||
int newHeight=getHeight();
|
||||
if(newHeight>oldHeight) {
|
||||
int newHeight = getHeight();
|
||||
if (newHeight > oldHeight) {
|
||||
//the line was appended
|
||||
sendLinesChangedToSnapshot(oldHeight, 1);
|
||||
int width=getWidth();
|
||||
int width = getWidth();
|
||||
sendDimensionsChanged(oldHeight, width, newHeight, width);
|
||||
|
||||
} else {
|
||||
|
@ -225,44 +245,54 @@ public class TerminalTextData implements ITerminalTextData {
|
|||
|
||||
public void copy(ITerminalTextData source) {
|
||||
fData.copy(source);
|
||||
fCursorLine=source.getCursorLine();
|
||||
fCursorColumn=source.getCursorColumn();
|
||||
fCursorLine = source.getCursorLine();
|
||||
fCursorColumn = source.getCursorColumn();
|
||||
}
|
||||
|
||||
public void copyLine(ITerminalTextData source, int sourceLine, int destLine) {
|
||||
fData.copyLine(source, sourceLine, destLine);
|
||||
}
|
||||
|
||||
public void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine, int length) {
|
||||
fData.copyRange(source, sourceStartLine, destStartLine, length);
|
||||
}
|
||||
|
||||
public char[] getChars(int line) {
|
||||
return fData.getChars(line);
|
||||
}
|
||||
|
||||
public Style[] getStyles(int line) {
|
||||
return fData.getStyles(line);
|
||||
}
|
||||
|
||||
public int getMaxHeight() {
|
||||
return fData.getMaxHeight();
|
||||
}
|
||||
|
||||
public void setMaxHeight(int height) {
|
||||
fData.setMaxHeight(height);
|
||||
}
|
||||
|
||||
public void cleanLine(int line) {
|
||||
fData.cleanLine(line);
|
||||
sendLineChangedToSnapshots(line);
|
||||
}
|
||||
|
||||
public int getCursorColumn() {
|
||||
return fCursorColumn;
|
||||
}
|
||||
|
||||
public int getCursorLine() {
|
||||
return fCursorLine;
|
||||
}
|
||||
|
||||
public void setCursorColumn(int column) {
|
||||
fCursorColumn=column;
|
||||
fCursorColumn = column;
|
||||
sendCursorChanged();
|
||||
}
|
||||
|
||||
public void setCursorLine(int line) {
|
||||
fCursorLine=line;
|
||||
fCursorLine = line;
|
||||
sendCursorChanged();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,19 +31,23 @@ public class TerminalTextDataFastScroll implements ITerminalTextData {
|
|||
* The offset into the array.
|
||||
*/
|
||||
int fOffset;
|
||||
public TerminalTextDataFastScroll(ITerminalTextData data,int maxHeight) {
|
||||
fMaxHeight=maxHeight;
|
||||
fData=data;
|
||||
|
||||
public TerminalTextDataFastScroll(ITerminalTextData data, int maxHeight) {
|
||||
fMaxHeight = maxHeight;
|
||||
fData = data;
|
||||
fData.setDimensions(maxHeight, fData.getWidth());
|
||||
if(maxHeight>2)
|
||||
if (maxHeight > 2)
|
||||
assert shiftOffset(-2) || throwRuntimeException();
|
||||
}
|
||||
|
||||
public TerminalTextDataFastScroll(int maxHeight) {
|
||||
this(new TerminalTextDataStore(),maxHeight);
|
||||
this(new TerminalTextDataStore(), maxHeight);
|
||||
}
|
||||
|
||||
public TerminalTextDataFastScroll() {
|
||||
this(new TerminalTextDataStore(),1);
|
||||
this(new TerminalTextDataStore(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used in asserts to throw an {@link RuntimeException}.
|
||||
* This is useful for tests.
|
||||
|
@ -52,23 +56,26 @@ public class TerminalTextDataFastScroll implements ITerminalTextData {
|
|||
private boolean throwRuntimeException() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param line
|
||||
* @return the actual line number in {@link #fData}
|
||||
*/
|
||||
int getPositionOfLine(int line) {
|
||||
return (line+fOffset)%fMaxHeight;
|
||||
return (line + fOffset) % fMaxHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves offset by delta. This does <b>not</b> move the data!
|
||||
* @param delta
|
||||
*/
|
||||
void moveOffset(int delta) {
|
||||
assert Math.abs(delta)<fMaxHeight || throwRuntimeException();
|
||||
fOffset=(fMaxHeight+fOffset+delta)%fMaxHeight;
|
||||
assert Math.abs(delta) < fMaxHeight || throwRuntimeException();
|
||||
fOffset = (fMaxHeight + fOffset + delta) % fMaxHeight;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method to shift the offset for testing (if assert ==true)
|
||||
* @param shift TODO
|
||||
|
@ -78,20 +85,22 @@ public class TerminalTextDataFastScroll implements ITerminalTextData {
|
|||
moveOffset(shift);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addLine() {
|
||||
if(getHeight()<fMaxHeight) {
|
||||
setDimensions(getHeight()+1, getWidth());
|
||||
if (getHeight() < fMaxHeight) {
|
||||
setDimensions(getHeight() + 1, getWidth());
|
||||
} else {
|
||||
scroll(0,getHeight(),-1);
|
||||
scroll(0, getHeight(), -1);
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanLine(int line) {
|
||||
fData.cleanLine(getPositionOfLine(line));
|
||||
}
|
||||
|
||||
public void copy(ITerminalTextData source) {
|
||||
int n=source.getHeight();
|
||||
setDimensions(source.getHeight(),source.getWidth());
|
||||
int n = source.getHeight();
|
||||
setDimensions(source.getHeight(), source.getWidth());
|
||||
for (int i = 0; i < n; i++) {
|
||||
fData.copyLine(source, i, getPositionOfLine(i));
|
||||
}
|
||||
|
@ -102,19 +111,19 @@ public class TerminalTextDataFastScroll implements ITerminalTextData {
|
|||
}
|
||||
|
||||
public void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine, int length) {
|
||||
assert (destStartLine>=0 && destStartLine+length<=fHeight) || throwRuntimeException();
|
||||
assert (destStartLine >= 0 && destStartLine + length <= fHeight) || throwRuntimeException();
|
||||
for (int i = 0; i < length; i++) {
|
||||
fData.copyLine(source, i+sourceStartLine, getPositionOfLine(i+destStartLine));
|
||||
fData.copyLine(source, i + sourceStartLine, getPositionOfLine(i + destStartLine));
|
||||
}
|
||||
}
|
||||
|
||||
public char getChar(int line, int column) {
|
||||
assert (line>=0 && line<fHeight) || throwRuntimeException();
|
||||
assert (line >= 0 && line < fHeight) || throwRuntimeException();
|
||||
return fData.getChar(getPositionOfLine(line), column);
|
||||
}
|
||||
|
||||
public char[] getChars(int line) {
|
||||
assert (line>=0 && line<fHeight) || throwRuntimeException();
|
||||
assert (line >= 0 && line < fHeight) || throwRuntimeException();
|
||||
return fData.getChars(getPositionOfLine(line));
|
||||
}
|
||||
|
||||
|
@ -123,7 +132,7 @@ public class TerminalTextDataFastScroll implements ITerminalTextData {
|
|||
}
|
||||
|
||||
public LineSegment[] getLineSegments(int line, int startCol, int numberOfCols) {
|
||||
assert (line>=0 && line<fHeight) || throwRuntimeException();
|
||||
assert (line >= 0 && line < fHeight) || throwRuntimeException();
|
||||
return fData.getLineSegments(getPositionOfLine(line), startCol, numberOfCols);
|
||||
}
|
||||
|
||||
|
@ -132,12 +141,12 @@ public class TerminalTextDataFastScroll implements ITerminalTextData {
|
|||
}
|
||||
|
||||
public Style getStyle(int line, int column) {
|
||||
assert (line>=0 && line<fHeight) || throwRuntimeException();
|
||||
assert (line >= 0 && line < fHeight) || throwRuntimeException();
|
||||
return fData.getStyle(getPositionOfLine(line), column);
|
||||
}
|
||||
|
||||
public Style[] getStyles(int line) {
|
||||
assert (line>=0 && line<fHeight) || throwRuntimeException();
|
||||
assert (line >= 0 && line < fHeight) || throwRuntimeException();
|
||||
return fData.getStyles(getPositionOfLine(line));
|
||||
}
|
||||
|
||||
|
@ -148,111 +157,119 @@ public class TerminalTextDataFastScroll implements ITerminalTextData {
|
|||
public ITerminalTextDataSnapshot makeSnapshot() {
|
||||
return fData.makeSnapshot();
|
||||
}
|
||||
|
||||
private void cleanLines(int line, int len) {
|
||||
for (int i = line; i < line+len; i++) {
|
||||
for (int i = line; i < line + len; i++) {
|
||||
fData.cleanLine(getPositionOfLine(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void scroll(int startLine, int size, int shift) {
|
||||
assert (startLine>=0 && startLine+size<=fHeight) || throwRuntimeException();
|
||||
if(shift>=fMaxHeight || -shift>=fMaxHeight) {
|
||||
cleanLines(startLine, fMaxHeight-startLine);
|
||||
assert (startLine >= 0 && startLine + size <= fHeight) || throwRuntimeException();
|
||||
if (shift >= fMaxHeight || -shift >= fMaxHeight) {
|
||||
cleanLines(startLine, fMaxHeight - startLine);
|
||||
return;
|
||||
}
|
||||
if(size==fHeight) {
|
||||
if (size == fHeight) {
|
||||
// This is the case this class is optimized for!
|
||||
moveOffset(-shift);
|
||||
// we only have to clean the lines that appear by the move
|
||||
if(shift<0) {
|
||||
cleanLines(Math.max(startLine, startLine+size+shift),Math.min(-shift, getHeight()-startLine));
|
||||
if (shift < 0) {
|
||||
cleanLines(Math.max(startLine, startLine + size + shift), Math.min(-shift, getHeight() - startLine));
|
||||
} else {
|
||||
cleanLines(startLine, Math.min(shift, getHeight()-startLine));
|
||||
cleanLines(startLine, Math.min(shift, getHeight() - startLine));
|
||||
}
|
||||
} else {
|
||||
// we have to copy the lines.
|
||||
if(shift<0) {
|
||||
if (shift < 0) {
|
||||
// move the region up
|
||||
// shift is negative!!
|
||||
for (int i = startLine; i < startLine+size+shift; i++) {
|
||||
fData.copyLine(fData, getPositionOfLine(i-shift), getPositionOfLine(i));
|
||||
for (int i = startLine; i < startLine + size + shift; i++) {
|
||||
fData.copyLine(fData, getPositionOfLine(i - shift), getPositionOfLine(i));
|
||||
}
|
||||
// then clean the opened lines
|
||||
cleanLines(Math.max(0, startLine+size+shift),Math.min(-shift, getHeight()-startLine));
|
||||
cleanLines(Math.max(0, startLine + size + shift), Math.min(-shift, getHeight() - startLine));
|
||||
} else {
|
||||
for (int i = startLine+size-1; i >=startLine && i-shift>=0; i--) {
|
||||
fData.copyLine(fData, getPositionOfLine(i-shift), getPositionOfLine(i));
|
||||
for (int i = startLine + size - 1; i >= startLine && i - shift >= 0; i--) {
|
||||
fData.copyLine(fData, getPositionOfLine(i - shift), getPositionOfLine(i));
|
||||
}
|
||||
cleanLines(startLine, Math.min(shift, getHeight()-startLine));
|
||||
cleanLines(startLine, Math.min(shift, getHeight() - startLine));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setChar(int line, int column, char c, Style style) {
|
||||
assert (line>=0 && line<fHeight) || throwRuntimeException();
|
||||
assert (line >= 0 && line < fHeight) || throwRuntimeException();
|
||||
fData.setChar(getPositionOfLine(line), column, c, style);
|
||||
}
|
||||
|
||||
public void setChars(int line, int column, char[] chars, int start, int len, Style style) {
|
||||
assert (line>=0 && line<fHeight) || throwRuntimeException();
|
||||
assert (line >= 0 && line < fHeight) || throwRuntimeException();
|
||||
fData.setChars(getPositionOfLine(line), column, chars, start, len, style);
|
||||
}
|
||||
|
||||
public void setChars(int line, int column, char[] chars, Style style) {
|
||||
assert (line>=0 && line<fHeight) || throwRuntimeException();
|
||||
assert (line >= 0 && line < fHeight) || throwRuntimeException();
|
||||
fData.setChars(getPositionOfLine(line), column, chars, style);
|
||||
}
|
||||
|
||||
public void setDimensions(int height, int width) {
|
||||
assert height>=0 || throwRuntimeException();
|
||||
assert width>=0 || throwRuntimeException();
|
||||
if(height > fMaxHeight)
|
||||
assert height >= 0 || throwRuntimeException();
|
||||
assert width >= 0 || throwRuntimeException();
|
||||
if (height > fMaxHeight)
|
||||
setMaxHeight(height);
|
||||
fHeight=height;
|
||||
if(width!=fData.getWidth())
|
||||
fHeight = height;
|
||||
if (width != fData.getWidth())
|
||||
fData.setDimensions(fMaxHeight, width);
|
||||
}
|
||||
|
||||
public void setMaxHeight(int maxHeight) {
|
||||
assert maxHeight>=fHeight || throwRuntimeException();
|
||||
assert maxHeight >= fHeight || throwRuntimeException();
|
||||
// move everything to offset0
|
||||
int start=getPositionOfLine(0);
|
||||
if(start!=0) {
|
||||
int start = getPositionOfLine(0);
|
||||
if (start != 0) {
|
||||
// invent a more efficient algorithm....
|
||||
ITerminalTextData buffer=new TerminalTextDataStore();
|
||||
ITerminalTextData buffer = new TerminalTextDataStore();
|
||||
// create a buffer with the expected height
|
||||
buffer.setDimensions(maxHeight, getWidth());
|
||||
int n=Math.min(fMaxHeight-start,maxHeight);
|
||||
int n = Math.min(fMaxHeight - start, maxHeight);
|
||||
// copy the first part
|
||||
buffer.copyRange(fData, start, 0, n);
|
||||
// copy the second part
|
||||
if(n<maxHeight)
|
||||
buffer.copyRange(fData, 0, n, Math.min(fMaxHeight-n,maxHeight-n));
|
||||
if (n < maxHeight)
|
||||
buffer.copyRange(fData, 0, n, Math.min(fMaxHeight - n, maxHeight - n));
|
||||
// copy the buffer back to our data
|
||||
fData.copy(buffer);
|
||||
shiftOffset(-start);
|
||||
} else {
|
||||
fData.setDimensions(maxHeight, fData.getWidth());
|
||||
}
|
||||
fMaxHeight=maxHeight;
|
||||
fMaxHeight = maxHeight;
|
||||
}
|
||||
|
||||
public int getCursorColumn() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public int getCursorLine() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void setCursorColumn(int column) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void setCursorLine(int line) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean isWrappedLine(int line) {
|
||||
assert (line>=0 && line<fHeight) || throwRuntimeException();
|
||||
assert (line >= 0 && line < fHeight) || throwRuntimeException();
|
||||
return fData.isWrappedLine(getPositionOfLine(line));
|
||||
}
|
||||
|
||||
public void setWrappedLine(int line) {
|
||||
assert (line>=0 && line<fHeight) || throwRuntimeException();
|
||||
assert (line >= 0 && line < fHeight) || throwRuntimeException();
|
||||
fData.setWrappedLine(getPositionOfLine(line));
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
// snapshot does not need internal synchronisation
|
||||
final TerminalTextDataWindow fSnapshot;
|
||||
// this variable is synchronized on fTerminal!
|
||||
private SnapshotOutOfDateListener[] fListener=new SnapshotOutOfDateListener[0];
|
||||
private SnapshotOutOfDateListener[] fListener = new SnapshotOutOfDateListener[0];
|
||||
// this variable is synchronized on fTerminal!
|
||||
private boolean fListenersNeedNotify;
|
||||
private int fInterestWindowSize;
|
||||
|
@ -60,9 +60,10 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
fCurrentChanges.setTerminalChanged();
|
||||
fFutureChanges = new SnapshotChanges(fTerminal.getHeight());
|
||||
fFutureChanges.markLinesChanged(0, fTerminal.getHeight());
|
||||
fListenersNeedNotify=true;
|
||||
fInterestWindowSize=-1;
|
||||
fListenersNeedNotify = true;
|
||||
fInterestWindowSize = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used in asserts to throw an {@link RuntimeException}.
|
||||
* This is useful for tests.
|
||||
|
@ -82,6 +83,7 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
return fFutureChanges.hasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ITerminalTextDataSnapshot#snapshot()
|
||||
*/
|
||||
|
@ -89,12 +91,12 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
// make sure terminal does not change while we make the snapshot
|
||||
synchronized (fTerminal) {
|
||||
// let's make the future changes current
|
||||
fCurrentChanges=fFutureChanges;
|
||||
fFutureChanges=new SnapshotChanges(fTerminal.getHeight());
|
||||
fCurrentChanges = fFutureChanges;
|
||||
fFutureChanges = new SnapshotChanges(fTerminal.getHeight());
|
||||
fFutureChanges.setInterestWindow(fInterestWindowStartLine, fInterestWindowSize);
|
||||
// and update the snapshot
|
||||
if(fSnapshot.getHeight()!=fTerminal.getHeight()||fSnapshot.getWidth()!=fTerminal.getWidth()) {
|
||||
if(fInterestWindowSize==-1)
|
||||
if (fSnapshot.getHeight() != fTerminal.getHeight() || fSnapshot.getWidth() != fTerminal.getWidth()) {
|
||||
if (fInterestWindowSize == -1)
|
||||
fSnapshot.setWindow(0, fTerminal.getHeight());
|
||||
// if the dimensions have changed, we need a full copy
|
||||
fSnapshot.copy(fTerminal);
|
||||
|
@ -102,17 +104,17 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
fCurrentChanges.setAllChanged(fTerminal.getHeight());
|
||||
} else {
|
||||
// first we do the scroll on the copy
|
||||
int start=fCurrentChanges.getScrollWindowStartLine();
|
||||
int lines=Math.min(fCurrentChanges.getScrollWindowSize(), fSnapshot.getHeight()-start);
|
||||
int start = fCurrentChanges.getScrollWindowStartLine();
|
||||
int lines = Math.min(fCurrentChanges.getScrollWindowSize(), fSnapshot.getHeight() - start);
|
||||
fSnapshot.scroll(start, lines, fCurrentChanges.getScrollWindowShift());
|
||||
// and then create the snapshot of the changed lines
|
||||
fCurrentChanges.copyChangedLines(fSnapshot, fTerminal);
|
||||
}
|
||||
fListenersNeedNotify=true;
|
||||
fListenersNeedNotify = true;
|
||||
fSnapshot.setCursorLine(fTerminal.getCursorLine());
|
||||
fSnapshot.setCursorColumn(fTerminal.getCursorColumn());
|
||||
}
|
||||
if(!detectScrolling) {
|
||||
if (!detectScrolling) {
|
||||
// let's pretend there was no scrolling and
|
||||
// convert the scrolling into line changes
|
||||
fCurrentChanges.convertScrollingIntoChanges();
|
||||
|
@ -138,12 +140,14 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
public int getWidth() {
|
||||
return fSnapshot.getWidth();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ITerminalTextDataSnapshot#getFirstChangedLine()
|
||||
*/
|
||||
public int getFirstChangedLine() {
|
||||
return fCurrentChanges.getFirstChangedLine();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ITerminalTextDataSnapshot#getLastChangedLine()
|
||||
*/
|
||||
|
@ -154,9 +158,11 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
public boolean hasLineChanged(int line) {
|
||||
return fCurrentChanges.hasLineChanged(line);
|
||||
}
|
||||
|
||||
public boolean hasDimensionsChanged() {
|
||||
return fCurrentChanges.hasDimensionsChanged();
|
||||
}
|
||||
|
||||
public boolean hasTerminalChanged() {
|
||||
return fCurrentChanges.hasTerminalChanged();
|
||||
}
|
||||
|
@ -167,12 +173,14 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
public int getScrollWindowStartLine() {
|
||||
return fCurrentChanges.getScrollWindowStartLine();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ITerminalTextDataSnapshot#getScrollChangeN()
|
||||
*/
|
||||
public int getScrollWindowSize() {
|
||||
return fCurrentChanges.getScrollWindowSize();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.model.ITerminalTextDataSnapshot#getScrollChangeShift()
|
||||
*/
|
||||
|
@ -190,13 +198,14 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
fFutureChanges.setTerminalChanged();
|
||||
notifyListers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Announces a change of n lines beginning with line line
|
||||
* @param line
|
||||
* @param n
|
||||
*/
|
||||
void markLinesChanged(int line,int n) {
|
||||
fFutureChanges.markLinesChanged(line,n);
|
||||
void markLinesChanged(int line, int n) {
|
||||
fFutureChanges.markLinesChanged(line, n);
|
||||
fFutureChanges.setTerminalChanged();
|
||||
notifyListers();
|
||||
}
|
||||
|
@ -206,6 +215,7 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
fFutureChanges.setTerminalChanged();
|
||||
notifyListers();
|
||||
}
|
||||
|
||||
void markCursorChanged() {
|
||||
fFutureChanges.markCursorChanged();
|
||||
fFutureChanges.setTerminalChanged();
|
||||
|
@ -218,86 +228,87 @@ class TerminalTextDataSnapshot implements ITerminalTextDataSnapshot {
|
|||
* @param shift
|
||||
*/
|
||||
void scroll(int startLine, int size, int shift) {
|
||||
fFutureChanges.scroll(startLine,size,shift);
|
||||
fFutureChanges.scroll(startLine, size, shift);
|
||||
fFutureChanges.setTerminalChanged();
|
||||
notifyListers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies listeners about the change
|
||||
*/
|
||||
private void notifyListers() {
|
||||
// this code has to be called from a block synchronized on fTerminal
|
||||
synchronized (fTerminal) {
|
||||
if(fListenersNeedNotify) {
|
||||
if (fListenersNeedNotify) {
|
||||
for (int i = 0; i < fListener.length; i++) {
|
||||
fListener[i].snapshotOutOfDate(this);
|
||||
}
|
||||
fListenersNeedNotify=false;
|
||||
fListenersNeedNotify = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ITerminalTextDataSnapshot makeSnapshot() {
|
||||
return fSnapshot.makeSnapshot();
|
||||
}
|
||||
|
||||
synchronized public void addListener(SnapshotOutOfDateListener listener) {
|
||||
List<SnapshotOutOfDateListener> list=new ArrayList<SnapshotOutOfDateListener>();
|
||||
List<SnapshotOutOfDateListener> list = new ArrayList<SnapshotOutOfDateListener>();
|
||||
list.addAll(Arrays.asList(fListener));
|
||||
list.add(listener);
|
||||
fListener=list.toArray(new SnapshotOutOfDateListener[list.size()]);
|
||||
fListener = list.toArray(new SnapshotOutOfDateListener[list.size()]);
|
||||
}
|
||||
|
||||
synchronized public void removeListener(SnapshotOutOfDateListener listener) {
|
||||
List<SnapshotOutOfDateListener> list=new ArrayList<SnapshotOutOfDateListener>();
|
||||
List<SnapshotOutOfDateListener> list = new ArrayList<SnapshotOutOfDateListener>();
|
||||
list.addAll(Arrays.asList(fListener));
|
||||
list.remove(listener);
|
||||
fListener=list.toArray(new SnapshotOutOfDateListener[list.size()]);
|
||||
fListener = list.toArray(new SnapshotOutOfDateListener[list.size()]);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return fSnapshot.toString();
|
||||
}
|
||||
|
||||
|
||||
public int getInterestWindowSize() {
|
||||
return fInterestWindowSize;
|
||||
}
|
||||
|
||||
|
||||
public int getInterestWindowStartLine() {
|
||||
return fInterestWindowStartLine;
|
||||
}
|
||||
|
||||
public void setInterestWindow(int startLine, int size) {
|
||||
assert startLine>=0 || throwRuntimeException();
|
||||
assert size>=0 || throwRuntimeException();
|
||||
fInterestWindowStartLine=startLine;
|
||||
fInterestWindowSize=size;
|
||||
assert startLine >= 0 || throwRuntimeException();
|
||||
assert size >= 0 || throwRuntimeException();
|
||||
fInterestWindowStartLine = startLine;
|
||||
fInterestWindowSize = size;
|
||||
fSnapshot.setWindow(startLine, size);
|
||||
fFutureChanges.setInterestWindow(startLine, size);
|
||||
notifyListers();
|
||||
}
|
||||
|
||||
|
||||
public char[] getChars(int line) {
|
||||
return fSnapshot.getChars(line);
|
||||
}
|
||||
|
||||
|
||||
public Style[] getStyles(int line) {
|
||||
return fSnapshot.getStyles(line);
|
||||
}
|
||||
|
||||
public int getCursorColumn() {
|
||||
return fSnapshot.getCursorColumn();
|
||||
}
|
||||
|
||||
public int getCursorLine() {
|
||||
return fSnapshot.getCursorLine();
|
||||
}
|
||||
|
||||
public ITerminalTextData getTerminalTextData() {
|
||||
return fTerminal;
|
||||
}
|
||||
|
||||
public boolean isWrappedLine(int line) {
|
||||
return fSnapshot.isWrappedLine(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -36,10 +36,11 @@ public class TerminalTextDataStore implements ITerminalTextData {
|
|||
final private BitSet fWrappedLines = new BitSet();
|
||||
|
||||
public TerminalTextDataStore() {
|
||||
fChars=new char[0][];
|
||||
fStyle=new Style[0][];
|
||||
fWidth=0;
|
||||
fChars = new char[0][];
|
||||
fStyle = new Style[0][];
|
||||
fWidth = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used in asserts to throw an {@link RuntimeException}.
|
||||
* This is useful for tests.
|
||||
|
@ -49,43 +50,45 @@ public class TerminalTextDataStore implements ITerminalTextData {
|
|||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#getWidth()
|
||||
*/
|
||||
public int getWidth() {
|
||||
return fWidth;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#getHeight()
|
||||
*/
|
||||
public int getHeight() {
|
||||
return fHeight;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#setDimensions(int, int)
|
||||
*/
|
||||
public void setDimensions(int height, int width) {
|
||||
assert height>=0 || throwRuntimeException();
|
||||
assert width>=0 || throwRuntimeException();
|
||||
assert height >= 0 || throwRuntimeException();
|
||||
assert width >= 0 || throwRuntimeException();
|
||||
// just extend the region
|
||||
if(height>fChars.length) {
|
||||
int h=4*height/3;
|
||||
if(fMaxHeight>0 && h>fMaxHeight)
|
||||
h=fMaxHeight;
|
||||
fStyle=(Style[][]) resizeArray(fStyle, height);
|
||||
fChars=(char[][]) resizeArray(fChars, height);
|
||||
if (height > fChars.length) {
|
||||
int h = 4 * height / 3;
|
||||
if (fMaxHeight > 0 && h > fMaxHeight)
|
||||
h = fMaxHeight;
|
||||
fStyle = (Style[][]) resizeArray(fStyle, height);
|
||||
fChars = (char[][]) resizeArray(fChars, height);
|
||||
}
|
||||
// clean the new lines
|
||||
if(height>fHeight) {
|
||||
if (height > fHeight) {
|
||||
for (int i = fHeight; i < height; i++) {
|
||||
cleanLine(i);
|
||||
}
|
||||
}
|
||||
// set dimensions after successful resize!
|
||||
fWidth=width;
|
||||
fHeight=height;
|
||||
fWidth = width;
|
||||
fHeight = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reallocates an array with a new size, and copies the contents of the old
|
||||
* array to the new array.
|
||||
|
@ -96,7 +99,7 @@ public class TerminalTextDataStore implements ITerminalTextData {
|
|||
*/
|
||||
private Object resizeArray(Object origArray, int newSize) {
|
||||
int oldSize = Array.getLength(origArray);
|
||||
if(oldSize==newSize)
|
||||
if (oldSize == newSize)
|
||||
return origArray;
|
||||
Class<?> elementType = origArray.getClass().getComponentType();
|
||||
Object newArray = Array.newInstance(elementType, newSize);
|
||||
|
@ -106,74 +109,75 @@ public class TerminalTextDataStore implements ITerminalTextData {
|
|||
return newArray;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#getLineSegments(int, int, int)
|
||||
*/
|
||||
public LineSegment[] getLineSegments(int line, int column, int len) {
|
||||
// get the styles and chars for this line
|
||||
Style[] styles=fStyle[line];
|
||||
char[] chars=fChars[line];
|
||||
int col=column;
|
||||
int n=column+len;
|
||||
Style[] styles = fStyle[line];
|
||||
char[] chars = fChars[line];
|
||||
int col = column;
|
||||
int n = column + len;
|
||||
|
||||
// expand the line if needed....
|
||||
if(styles==null)
|
||||
styles=new Style[n];
|
||||
else if(styles.length<n)
|
||||
styles=(Style[]) resizeArray(styles, n);
|
||||
if (styles == null)
|
||||
styles = new Style[n];
|
||||
else if (styles.length < n)
|
||||
styles = (Style[]) resizeArray(styles, n);
|
||||
|
||||
if(chars==null)
|
||||
chars=new char[n];
|
||||
else if(chars.length<n)
|
||||
chars=(char[]) resizeArray(chars, n);
|
||||
if (chars == null)
|
||||
chars = new char[n];
|
||||
else if (chars.length < n)
|
||||
chars = (char[]) resizeArray(chars, n);
|
||||
|
||||
// and create the line segments
|
||||
Style style=styles[column];
|
||||
List<LineSegment> segments=new ArrayList<LineSegment>();
|
||||
Style style = styles[column];
|
||||
List<LineSegment> segments = new ArrayList<LineSegment>();
|
||||
for (int i = column; i < n; i++) {
|
||||
if(styles[i]!=style) {
|
||||
segments.add(new LineSegment(col,new String(chars,col,i-col),style));
|
||||
style=styles[i];
|
||||
col=i;
|
||||
if (styles[i] != style) {
|
||||
segments.add(new LineSegment(col, new String(chars, col, i - col), style));
|
||||
style = styles[i];
|
||||
col = i;
|
||||
}
|
||||
}
|
||||
if(col < n) {
|
||||
segments.add(new LineSegment(col,new String(chars,col,n-col),style));
|
||||
if (col < n) {
|
||||
segments.add(new LineSegment(col, new String(chars, col, n - col), style));
|
||||
}
|
||||
return segments.toArray(new LineSegment[segments.size()]);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#getChar(int, int)
|
||||
*/
|
||||
public char getChar(int line, int column) {
|
||||
assert column<fWidth || throwRuntimeException();
|
||||
if(fChars[line]==null||column>=fChars[line].length)
|
||||
assert column < fWidth || throwRuntimeException();
|
||||
if (fChars[line] == null || column >= fChars[line].length)
|
||||
return 0;
|
||||
return fChars[line][column];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#getStyle(int, int)
|
||||
*/
|
||||
public Style getStyle(int line, int column) {
|
||||
assert column<fWidth || throwRuntimeException();
|
||||
if(fStyle[line]==null || column>=fStyle[line].length)
|
||||
assert column < fWidth || throwRuntimeException();
|
||||
if (fStyle[line] == null || column >= fStyle[line].length)
|
||||
return null;
|
||||
return fStyle[line][column];
|
||||
}
|
||||
|
||||
void ensureLineLength(int iLine, int length) {
|
||||
if(length>fWidth)
|
||||
if (length > fWidth)
|
||||
throw new RuntimeException();
|
||||
if(fChars[iLine]==null) {
|
||||
fChars[iLine]=new char[length];
|
||||
} else if(fChars[iLine].length<length) {
|
||||
fChars[iLine]=(char[]) resizeArray(fChars[iLine],length);
|
||||
if (fChars[iLine] == null) {
|
||||
fChars[iLine] = new char[length];
|
||||
} else if (fChars[iLine].length < length) {
|
||||
fChars[iLine] = (char[]) resizeArray(fChars[iLine], length);
|
||||
}
|
||||
if(fStyle[iLine]==null) {
|
||||
fStyle[iLine]=new Style[length];
|
||||
} else if(fStyle[iLine].length<length) {
|
||||
fStyle[iLine]=(Style[]) resizeArray(fStyle[iLine],length);
|
||||
if (fStyle[iLine] == null) {
|
||||
fStyle[iLine] = new Style[length];
|
||||
} else if (fStyle[iLine].length < length) {
|
||||
fStyle[iLine] = (Style[]) resizeArray(fStyle[iLine], length);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,58 +185,62 @@ public class TerminalTextDataStore implements ITerminalTextData {
|
|||
* @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#setChar(int, int, char, org.eclipse.tm.internal.terminal.text.Style)
|
||||
*/
|
||||
public void setChar(int line, int column, char c, Style style) {
|
||||
ensureLineLength(line,column+1);
|
||||
fChars[line][column]=c;
|
||||
fStyle[line][column]=style;
|
||||
ensureLineLength(line, column + 1);
|
||||
fChars[line][column] = c;
|
||||
fStyle[line][column] = style;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#setChars(int, int, char[], org.eclipse.tm.internal.terminal.text.Style)
|
||||
*/
|
||||
public void setChars(int line, int column, char[] chars, Style style) {
|
||||
setChars(line,column,chars,0,chars.length,style);
|
||||
setChars(line, column, chars, 0, chars.length, style);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#setChars(int, int, char[], int, int, org.eclipse.tm.internal.terminal.text.Style)
|
||||
*/
|
||||
public void setChars(int line, int column, char[] chars, int start, int len, Style style) {
|
||||
ensureLineLength(line,column+len);
|
||||
ensureLineLength(line, column + len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
fChars[line][column+i]=chars[i+start];
|
||||
fStyle[line][column+i]=style;
|
||||
fChars[line][column + i] = chars[i + start];
|
||||
fStyle[line][column + i] = style;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.internal.terminal.text.ITerminalTextData#scroll(int, int, int)
|
||||
*/
|
||||
public void scroll(int startLine, int size, int shift) {
|
||||
assert startLine+size <= getHeight() || throwRuntimeException();
|
||||
if(shift<0) {
|
||||
assert startLine + size <= getHeight() || throwRuntimeException();
|
||||
if (shift < 0) {
|
||||
// move the region up
|
||||
// shift is negative!!
|
||||
for (int i = startLine; i < startLine+size+shift; i++) {
|
||||
fChars[i]=fChars[i-shift];
|
||||
fStyle[i]=fStyle[i-shift];
|
||||
fWrappedLines.set(i, fWrappedLines.get(i-shift));
|
||||
for (int i = startLine; i < startLine + size + shift; i++) {
|
||||
fChars[i] = fChars[i - shift];
|
||||
fStyle[i] = fStyle[i - shift];
|
||||
fWrappedLines.set(i, fWrappedLines.get(i - shift));
|
||||
}
|
||||
// then clean the opened lines
|
||||
cleanLines(Math.max(startLine, startLine+size+shift),Math.min(-shift, getHeight()-startLine));
|
||||
// cleanLines(Math.max(0, startLine+size+shift),Math.min(-shift, getHeight()-startLine));
|
||||
cleanLines(Math.max(startLine, startLine + size + shift), Math.min(-shift, getHeight() - startLine));
|
||||
// cleanLines(Math.max(0, startLine+size+shift),Math.min(-shift, getHeight()-startLine));
|
||||
} else {
|
||||
for (int i = startLine+size-1; i >=startLine && i-shift>=0; i--) {
|
||||
fChars[i]=fChars[i-shift];
|
||||
fStyle[i]=fStyle[i-shift];
|
||||
fWrappedLines.set(i, fWrappedLines.get(i-shift));
|
||||
for (int i = startLine + size - 1; i >= startLine && i - shift >= 0; i--) {
|
||||
fChars[i] = fChars[i - shift];
|
||||
fStyle[i] = fStyle[i - shift];
|
||||
fWrappedLines.set(i, fWrappedLines.get(i - shift));
|
||||
}
|
||||
cleanLines(startLine, Math.min(shift, getHeight()-startLine));
|
||||
cleanLines(startLine, Math.min(shift, getHeight() - startLine));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the lines with new empty data
|
||||
* @param line
|
||||
* @param len
|
||||
*/
|
||||
private void cleanLines(int line, int len) {
|
||||
for (int i = line; i < line+len; i++) {
|
||||
for (int i = line; i < line + len; i++) {
|
||||
cleanLine(i);
|
||||
}
|
||||
}
|
||||
|
@ -242,9 +250,9 @@ public class TerminalTextDataStore implements ITerminalTextData {
|
|||
* Lines are separated by '\n'. No style information is returned.
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer buff=new StringBuffer();
|
||||
StringBuffer buff = new StringBuffer();
|
||||
for (int line = 0; line < getHeight(); line++) {
|
||||
if(line>0)
|
||||
if (line > 0)
|
||||
buff.append("\n"); //$NON-NLS-1$
|
||||
for (int column = 0; column < fWidth; column++) {
|
||||
buff.append(getChar(line, column));
|
||||
|
@ -253,65 +261,65 @@ public class TerminalTextDataStore implements ITerminalTextData {
|
|||
return buff.toString();
|
||||
}
|
||||
|
||||
|
||||
public ITerminalTextDataSnapshot makeSnapshot() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void addLine() {
|
||||
if(fMaxHeight>0 && getHeight()<fMaxHeight) {
|
||||
setDimensions(getHeight()+1, getWidth());
|
||||
if (fMaxHeight > 0 && getHeight() < fMaxHeight) {
|
||||
setDimensions(getHeight() + 1, getWidth());
|
||||
} else {
|
||||
scroll(0,getHeight(),-1);
|
||||
scroll(0, getHeight(), -1);
|
||||
}
|
||||
}
|
||||
|
||||
public void copy(ITerminalTextData source) {
|
||||
fWidth=source.getWidth();
|
||||
int n=source.getHeight();
|
||||
if(getHeight()!=n) {
|
||||
fChars=new char[n][];
|
||||
fStyle=new Style[n][];
|
||||
fWidth = source.getWidth();
|
||||
int n = source.getHeight();
|
||||
if (getHeight() != n) {
|
||||
fChars = new char[n][];
|
||||
fStyle = new Style[n][];
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
copyLine(source, i, i);
|
||||
}
|
||||
fHeight=n;
|
||||
fCursorLine=source.getCursorLine();
|
||||
fCursorColumn=source.getCursorColumn();
|
||||
fHeight = n;
|
||||
fCursorLine = source.getCursorLine();
|
||||
fCursorColumn = source.getCursorColumn();
|
||||
}
|
||||
public void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine,int length) {
|
||||
|
||||
public void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine, int length) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
copyLine(source, i+sourceStartLine, i+destStartLine);
|
||||
copyLine(source, i + sourceStartLine, i + destStartLine);
|
||||
}
|
||||
}
|
||||
|
||||
public void copyLine(ITerminalTextData source, int sourceLine, int destLine) {
|
||||
fChars[destLine]=source.getChars(sourceLine);
|
||||
fStyle[destLine]=source.getStyles(sourceLine);
|
||||
fChars[destLine] = source.getChars(sourceLine);
|
||||
fStyle[destLine] = source.getStyles(sourceLine);
|
||||
fWrappedLines.set(destLine, source.isWrappedLine(sourceLine));
|
||||
}
|
||||
|
||||
public char[] getChars(int line) {
|
||||
if(fChars[line]==null)
|
||||
if (fChars[line] == null)
|
||||
return null;
|
||||
return fChars[line].clone();
|
||||
}
|
||||
|
||||
public Style[] getStyles(int line) {
|
||||
if(fStyle[line]==null)
|
||||
if (fStyle[line] == null)
|
||||
return null;
|
||||
return fStyle[line].clone();
|
||||
}
|
||||
|
||||
public void setLine(int line, char[] chars, Style[] styles) {
|
||||
fChars[line]=chars.clone();
|
||||
fStyle[line]=styles.clone();
|
||||
fChars[line] = chars.clone();
|
||||
fStyle[line] = styles.clone();
|
||||
fWrappedLines.clear(line);
|
||||
}
|
||||
|
||||
public void setMaxHeight(int height) {
|
||||
fMaxHeight=height;
|
||||
fMaxHeight = height;
|
||||
}
|
||||
|
||||
public int getMaxHeight() {
|
||||
|
@ -319,25 +327,31 @@ public class TerminalTextDataStore implements ITerminalTextData {
|
|||
}
|
||||
|
||||
public void cleanLine(int line) {
|
||||
fChars[line]=null;
|
||||
fStyle[line]=null;
|
||||
fChars[line] = null;
|
||||
fStyle[line] = null;
|
||||
fWrappedLines.clear(line);
|
||||
}
|
||||
|
||||
public int getCursorColumn() {
|
||||
return fCursorColumn;
|
||||
}
|
||||
|
||||
public int getCursorLine() {
|
||||
return fCursorLine;
|
||||
}
|
||||
|
||||
public void setCursorColumn(int column) {
|
||||
fCursorColumn=column;
|
||||
fCursorColumn = column;
|
||||
}
|
||||
|
||||
public void setCursorLine(int line) {
|
||||
fCursorLine=line;
|
||||
fCursorLine = line;
|
||||
}
|
||||
|
||||
public boolean isWrappedLine(int line) {
|
||||
return fWrappedLines.get(line);
|
||||
}
|
||||
|
||||
public void setWrappedLine(int line) {
|
||||
fWrappedLines.set(line);
|
||||
}
|
||||
|
|
|
@ -28,12 +28,15 @@ public class TerminalTextDataWindow implements ITerminalTextData {
|
|||
int fWindowSize;
|
||||
int fHeight;
|
||||
int fMaxHeight;
|
||||
|
||||
public TerminalTextDataWindow(ITerminalTextData data) {
|
||||
fData=data;
|
||||
fData = data;
|
||||
}
|
||||
|
||||
public TerminalTextDataWindow() {
|
||||
this(new TerminalTextDataStore());
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used in asserts to throw an {@link RuntimeException}.
|
||||
* This is useful for tests.
|
||||
|
@ -42,23 +45,25 @@ public class TerminalTextDataWindow implements ITerminalTextData {
|
|||
private boolean throwRuntimeException() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param line
|
||||
* @return true if the line is within the window
|
||||
*/
|
||||
boolean isInWindow(int line) {
|
||||
return line>=fWindowStartLine && line<fWindowStartLine+fWindowSize;
|
||||
return line >= fWindowStartLine && line < fWindowStartLine + fWindowSize;
|
||||
}
|
||||
|
||||
public char getChar(int line, int column) {
|
||||
if(!isInWindow(line))
|
||||
if (!isInWindow(line))
|
||||
return 0;
|
||||
return fData.getChar(line-fWindowStartLine, column);
|
||||
return fData.getChar(line - fWindowStartLine, column);
|
||||
}
|
||||
|
||||
public char[] getChars(int line) {
|
||||
if(!isInWindow(line))
|
||||
if (!isInWindow(line))
|
||||
return null;
|
||||
return fData.getChars(line-fWindowStartLine);
|
||||
return fData.getChars(line - fWindowStartLine);
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
|
@ -66,9 +71,9 @@ public class TerminalTextDataWindow implements ITerminalTextData {
|
|||
}
|
||||
|
||||
public LineSegment[] getLineSegments(int line, int startCol, int numberOfCols) {
|
||||
if(!isInWindow(line))
|
||||
return new LineSegment[]{new LineSegment(startCol,new String(new char[numberOfCols]),null)};
|
||||
return fData.getLineSegments(line-fWindowStartLine, startCol, numberOfCols);
|
||||
if (!isInWindow(line))
|
||||
return new LineSegment[] { new LineSegment(startCol, new String(new char[numberOfCols]), null) };
|
||||
return fData.getLineSegments(line - fWindowStartLine, startCol, numberOfCols);
|
||||
}
|
||||
|
||||
public int getMaxHeight() {
|
||||
|
@ -76,15 +81,15 @@ public class TerminalTextDataWindow implements ITerminalTextData {
|
|||
}
|
||||
|
||||
public Style getStyle(int line, int column) {
|
||||
if(!isInWindow(line))
|
||||
if (!isInWindow(line))
|
||||
return null;
|
||||
return fData.getStyle(line-fWindowStartLine, column);
|
||||
return fData.getStyle(line - fWindowStartLine, column);
|
||||
}
|
||||
|
||||
public Style[] getStyles(int line) {
|
||||
if(!isInWindow(line))
|
||||
if (!isInWindow(line))
|
||||
return null;
|
||||
return fData.getStyles(line-fWindowStartLine);
|
||||
return fData.getStyles(line - fWindowStartLine);
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
|
@ -94,114 +99,135 @@ public class TerminalTextDataWindow implements ITerminalTextData {
|
|||
public ITerminalTextDataSnapshot makeSnapshot() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void addLine() {
|
||||
if(fMaxHeight>0 && getHeight()<fMaxHeight) {
|
||||
setDimensions(getHeight()+1, getWidth());
|
||||
if (fMaxHeight > 0 && getHeight() < fMaxHeight) {
|
||||
setDimensions(getHeight() + 1, getWidth());
|
||||
} else {
|
||||
scroll(0,getHeight(),-1);
|
||||
scroll(0, getHeight(), -1);
|
||||
}
|
||||
}
|
||||
|
||||
public void copy(ITerminalTextData source) {
|
||||
// we inherit the dimensions of the source
|
||||
setDimensions(source.getHeight(), source.getWidth());
|
||||
int n=Math.min(fWindowSize, source.getHeight()-fWindowStartLine);
|
||||
if(n>0)
|
||||
int n = Math.min(fWindowSize, source.getHeight() - fWindowStartLine);
|
||||
if (n > 0)
|
||||
fData.copyRange(source, fWindowStartLine, 0, n);
|
||||
}
|
||||
|
||||
public void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine, int length) {
|
||||
int n=length;
|
||||
int dStart=destStartLine-fWindowStartLine;
|
||||
int sStart=sourceStartLine;
|
||||
int n = length;
|
||||
int dStart = destStartLine - fWindowStartLine;
|
||||
int sStart = sourceStartLine;
|
||||
// if start outside our range, cut the length to copy
|
||||
if(dStart<0) {
|
||||
n+=dStart;
|
||||
sStart-=dStart;
|
||||
dStart=0;
|
||||
if (dStart < 0) {
|
||||
n += dStart;
|
||||
sStart -= dStart;
|
||||
dStart = 0;
|
||||
}
|
||||
// do not exceed the window size
|
||||
n=Math.min(n,fWindowSize);
|
||||
if(n>0)
|
||||
n = Math.min(n, fWindowSize);
|
||||
if (n > 0)
|
||||
fData.copyRange(source, sStart, dStart, n);
|
||||
|
||||
}
|
||||
|
||||
public void copyLine(ITerminalTextData source, int sourceLine, int destLine) {
|
||||
if(isInWindow(destLine))
|
||||
fData.copyLine(source, sourceLine, destLine-fWindowStartLine);
|
||||
if (isInWindow(destLine))
|
||||
fData.copyLine(source, sourceLine, destLine - fWindowStartLine);
|
||||
}
|
||||
|
||||
public void scroll(int startLine, int size, int shift) {
|
||||
assert (startLine>=0 && startLine+size<=fHeight) || throwRuntimeException();
|
||||
int n=size;
|
||||
int start=startLine-fWindowStartLine;
|
||||
assert (startLine >= 0 && startLine + size <= fHeight) || throwRuntimeException();
|
||||
int n = size;
|
||||
int start = startLine - fWindowStartLine;
|
||||
// if start outside our range, cut the length to copy
|
||||
if(start<0) {
|
||||
n+=start;
|
||||
start=0;
|
||||
if (start < 0) {
|
||||
n += start;
|
||||
start = 0;
|
||||
}
|
||||
n=Math.min(n,fWindowSize-start);
|
||||
n = Math.min(n, fWindowSize - start);
|
||||
// do not exceed the window size
|
||||
if(n>0)
|
||||
if (n > 0)
|
||||
fData.scroll(start, n, shift);
|
||||
}
|
||||
|
||||
public void setChar(int line, int column, char c, Style style) {
|
||||
if(!isInWindow(line))
|
||||
if (!isInWindow(line))
|
||||
return;
|
||||
fData.setChar(line-fWindowStartLine, column, c, style);
|
||||
fData.setChar(line - fWindowStartLine, column, c, style);
|
||||
}
|
||||
|
||||
public void setChars(int line, int column, char[] chars, int start, int len, Style style) {
|
||||
if(!isInWindow(line))
|
||||
if (!isInWindow(line))
|
||||
return;
|
||||
fData.setChars(line-fWindowStartLine, column, chars, start, len, style);
|
||||
fData.setChars(line - fWindowStartLine, column, chars, start, len, style);
|
||||
}
|
||||
|
||||
public void setChars(int line, int column, char[] chars, Style style) {
|
||||
if(!isInWindow(line))
|
||||
if (!isInWindow(line))
|
||||
return;
|
||||
fData.setChars(line-fWindowStartLine, column, chars, style);
|
||||
fData.setChars(line - fWindowStartLine, column, chars, style);
|
||||
}
|
||||
|
||||
public void setDimensions(int height, int width) {
|
||||
assert height>=0 || throwRuntimeException();
|
||||
assert height >= 0 || throwRuntimeException();
|
||||
fData.setDimensions(fWindowSize, width);
|
||||
fHeight=height;
|
||||
fHeight = height;
|
||||
}
|
||||
|
||||
public void setMaxHeight(int height) {
|
||||
fMaxHeight=height;
|
||||
fMaxHeight = height;
|
||||
}
|
||||
|
||||
public void setWindow(int startLine, int size) {
|
||||
fWindowStartLine=startLine;
|
||||
fWindowSize=size;
|
||||
fWindowStartLine = startLine;
|
||||
fWindowSize = size;
|
||||
fData.setDimensions(fWindowSize, getWidth());
|
||||
}
|
||||
|
||||
public int getWindowStartLine() {
|
||||
return fWindowStartLine;
|
||||
}
|
||||
|
||||
public int getWindowSize() {
|
||||
return fWindowSize;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
fHeight = height;
|
||||
}
|
||||
|
||||
public void cleanLine(int line) {
|
||||
if(isInWindow(line))
|
||||
fData.cleanLine(line-fWindowStartLine);
|
||||
if (isInWindow(line))
|
||||
fData.cleanLine(line - fWindowStartLine);
|
||||
}
|
||||
|
||||
public int getCursorColumn() {
|
||||
return fData.getCursorColumn();
|
||||
}
|
||||
|
||||
public int getCursorLine() {
|
||||
return fData.getCursorLine();
|
||||
}
|
||||
|
||||
public void setCursorColumn(int column) {
|
||||
fData.setCursorColumn(column);
|
||||
}
|
||||
|
||||
public void setCursorLine(int line) {
|
||||
fData.setCursorLine(line);
|
||||
}
|
||||
|
||||
public boolean isWrappedLine(int line) {
|
||||
if(isInWindow(line))
|
||||
if (isInWindow(line))
|
||||
return fData.isWrappedLine(line - fWindowStartLine);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setWrappedLine(int line) {
|
||||
if(isInWindow(line))
|
||||
if (isInWindow(line))
|
||||
fData.setWrappedLine(line - fWindowStartLine);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,7 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
|
|||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
* @noreference This class is not intended to be referenced by clients.
|
||||
*/
|
||||
public class TerminalPreferencePage extends FieldEditorPreferencePage implements
|
||||
IWorkbenchPreferencePage {
|
||||
public class TerminalPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
|
||||
protected BooleanFieldEditor fInvertColors;
|
||||
|
||||
protected IntegerFieldEditor fEditorBufferSize;
|
||||
|
@ -44,16 +43,20 @@ public class TerminalPreferencePage extends FieldEditorPreferencePage implements
|
|||
public TerminalPreferencePage() {
|
||||
super(GRID);
|
||||
}
|
||||
|
||||
protected void createFieldEditors() {
|
||||
setupPage();
|
||||
}
|
||||
|
||||
public void init(IWorkbench workbench) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
protected void setupPage() {
|
||||
setupData();
|
||||
setupEditors();
|
||||
}
|
||||
|
||||
protected void setupData() {
|
||||
TerminalPlugin plugin;
|
||||
IPreferenceStore preferenceStore;
|
||||
|
@ -62,12 +65,12 @@ public class TerminalPreferencePage extends FieldEditorPreferencePage implements
|
|||
preferenceStore = plugin.getPreferenceStore();
|
||||
setPreferenceStore(preferenceStore);
|
||||
}
|
||||
|
||||
protected void setupEditors() {
|
||||
fInvertColors = new BooleanFieldEditor(
|
||||
ITerminalConstants.PREF_INVERT_COLORS, TerminalMessages.INVERT_COLORS,
|
||||
fInvertColors = new BooleanFieldEditor(ITerminalConstants.PREF_INVERT_COLORS, TerminalMessages.INVERT_COLORS,
|
||||
getFieldEditorParent());
|
||||
fEditorBufferSize = new IntegerFieldEditor(ITerminalConstants.PREF_BUFFERLINES, TerminalMessages.BUFFERLINES,
|
||||
getFieldEditorParent());
|
||||
fEditorBufferSize = new IntegerFieldEditor(ITerminalConstants.PREF_BUFFERLINES,
|
||||
TerminalMessages.BUFFERLINES, getFieldEditorParent());
|
||||
|
||||
fEditorBufferSize.setValidRange(0, Integer.MAX_VALUE);
|
||||
|
||||
|
|
|
@ -61,8 +61,9 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro
|
|||
Object[] list = listeners.getListeners();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
Object l = list[i];
|
||||
if (!(l instanceof Listener)) continue;
|
||||
((Listener)l).onSettingsPageChanged(control);
|
||||
if (!(l instanceof Listener))
|
||||
continue;
|
||||
((Listener) l).onSettingsPageChanged(control);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +121,8 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro
|
|||
*/
|
||||
protected final ControlDecoration createControlDecoration(Control control) {
|
||||
Assert.isNotNull(control);
|
||||
if (!hasDecoration) return null;
|
||||
if (!hasDecoration)
|
||||
return null;
|
||||
ControlDecoration controlDecoration = new ControlDecoration(control, getControlDecorationPosition());
|
||||
controlDecoration.setShowOnlyOnFocus(false);
|
||||
control.setData("controlDecoration", controlDecoration); //$NON-NLS-1$
|
||||
|
@ -149,7 +151,7 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro
|
|||
protected final void updateControlDecoration(Control control, String message, int messageType) {
|
||||
Assert.isNotNull(control);
|
||||
|
||||
ControlDecoration controlDecoration = (ControlDecoration)control.getData("controlDecoration"); //$NON-NLS-1$
|
||||
ControlDecoration controlDecoration = (ControlDecoration) control.getData("controlDecoration"); //$NON-NLS-1$
|
||||
if (controlDecoration != null) {
|
||||
// The description is the same as the message
|
||||
controlDecoration.setDescriptionText(message);
|
||||
|
@ -173,8 +175,7 @@ public abstract class AbstractSettingsPage implements ISettingsPage, IMessagePro
|
|||
|
||||
if (message == null || messageType == IMessageProvider.NONE) {
|
||||
controlDecoration.hide();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
controlDecoration.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,47 +80,63 @@ public final class Logger {
|
|||
*/
|
||||
public static final String encode(String message) {
|
||||
boolean encoded = false;
|
||||
StringBuffer buf = new StringBuffer(message.length()+32);
|
||||
for (int i=0; i<message.length(); i++) {
|
||||
char c=message.charAt(i);
|
||||
switch(c) {
|
||||
StringBuffer buf = new StringBuffer(message.length() + 32);
|
||||
for (int i = 0; i < message.length(); i++) {
|
||||
char c = message.charAt(i);
|
||||
switch (c) {
|
||||
case '\\':
|
||||
case '\'':
|
||||
buf.append('\\'); buf.append(c); encoded=true;
|
||||
buf.append('\\');
|
||||
buf.append(c);
|
||||
encoded = true;
|
||||
break;
|
||||
case '\r':
|
||||
buf.append('\\'); buf.append('r'); encoded=true;
|
||||
buf.append('\\');
|
||||
buf.append('r');
|
||||
encoded = true;
|
||||
break;
|
||||
case '\n':
|
||||
buf.append('\\'); buf.append('n'); encoded=true;
|
||||
buf.append('\\');
|
||||
buf.append('n');
|
||||
encoded = true;
|
||||
break;
|
||||
case '\t':
|
||||
buf.append('\\'); buf.append('t'); encoded=true;
|
||||
buf.append('\\');
|
||||
buf.append('t');
|
||||
encoded = true;
|
||||
break;
|
||||
case '\f':
|
||||
buf.append('\\'); buf.append('f'); encoded=true;
|
||||
buf.append('\\');
|
||||
buf.append('f');
|
||||
encoded = true;
|
||||
break;
|
||||
case '\b':
|
||||
buf.append('\\'); buf.append('b'); encoded=true;
|
||||
buf.append('\\');
|
||||
buf.append('b');
|
||||
encoded = true;
|
||||
break;
|
||||
default:
|
||||
if (c <= '\u000f') {
|
||||
buf.append('\\'); buf.append('x'); buf.append('0');
|
||||
buf.append('\\');
|
||||
buf.append('x');
|
||||
buf.append('0');
|
||||
buf.append(Integer.toHexString(c));
|
||||
encoded=true;
|
||||
} else if (c>=' ' && c<'\u007f') {
|
||||
encoded = true;
|
||||
} else if (c >= ' ' && c < '\u007f') {
|
||||
buf.append(c);
|
||||
} else if (c <= '\u00ff') {
|
||||
buf.append('\\'); buf.append('x');
|
||||
buf.append('\\');
|
||||
buf.append('x');
|
||||
buf.append(Integer.toHexString(c));
|
||||
encoded=true;
|
||||
encoded = true;
|
||||
} else {
|
||||
buf.append('\\'); buf.append('u');
|
||||
if (c<='\u0fff') {
|
||||
buf.append('\\');
|
||||
buf.append('u');
|
||||
if (c <= '\u0fff') {
|
||||
buf.append('0');
|
||||
}
|
||||
buf.append(Integer.toHexString(c));
|
||||
encoded=true;
|
||||
encoded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +151,7 @@ public final class Logger {
|
|||
* @return true if logging is enabled.
|
||||
*/
|
||||
public static final boolean isLogEnabled() {
|
||||
return (logStream!=null);
|
||||
return (logStream != null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,14 +184,15 @@ public final class Logger {
|
|||
public static final void logException(Exception ex) {
|
||||
// log in eclipse error log
|
||||
if (TerminalPlugin.getDefault() != null) {
|
||||
TerminalPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex));
|
||||
TerminalPlugin.getDefault().getLog()
|
||||
.log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex));
|
||||
} else {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// Additional Tracing for debug purposes:
|
||||
// Read my own stack to get the class name, method name, and line number
|
||||
// of where this method was called
|
||||
if(logStream!=null) {
|
||||
if (logStream != null) {
|
||||
StackTraceElement caller = new Throwable().getStackTrace()[1];
|
||||
int lineNumber = caller.getLineNumber();
|
||||
String className = caller.getClassName();
|
||||
|
@ -188,8 +205,7 @@ public final class Logger {
|
|||
tmpStream = logStream;
|
||||
}
|
||||
|
||||
tmpStream.println(className
|
||||
+ "." + methodName + ":" + lineNumber + ": " + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
tmpStream.println(className + "." + methodName + ":" + lineNumber + ": " + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
"Caught exception: " + ex); //$NON-NLS-1$
|
||||
ex.printStackTrace(tmpStream);
|
||||
}
|
||||
|
|
|
@ -41,19 +41,20 @@ import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnect
|
|||
public class TerminalConnectorExtension {
|
||||
static private ITerminalConnector makeConnector(final IConfigurationElement config) {
|
||||
String id = config.getAttribute("id"); //$NON-NLS-1$
|
||||
if(id==null || id.length()==0)
|
||||
id=config.getAttribute("class"); //$NON-NLS-1$
|
||||
String name= config.getAttribute("name"); //$NON-NLS-1$
|
||||
if(name==null || name.length()==0) {
|
||||
name=id;
|
||||
if (id == null || id.length() == 0)
|
||||
id = config.getAttribute("class"); //$NON-NLS-1$
|
||||
String name = config.getAttribute("name"); //$NON-NLS-1$
|
||||
if (name == null || name.length() == 0) {
|
||||
name = id;
|
||||
}
|
||||
String hidden = config.getAttribute("hidden"); //$NON-NLS-1$
|
||||
boolean isHidden = hidden != null ? new Boolean(hidden).booleanValue() : false;
|
||||
TerminalConnector.Factory factory=new TerminalConnector.Factory(){
|
||||
TerminalConnector.Factory factory = new TerminalConnector.Factory() {
|
||||
public TerminalConnectorImpl makeConnector() throws Exception {
|
||||
return (TerminalConnectorImpl)config.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
}};
|
||||
return new TerminalConnector(factory,id,name, isHidden);
|
||||
return (TerminalConnectorImpl) config.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
}
|
||||
};
|
||||
return new TerminalConnector(factory, id, name, isHidden);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,14 +69,16 @@ public class TerminalConnectorExtension {
|
|||
* @since org.eclipse.tm.terminal 2.0
|
||||
*/
|
||||
public static ITerminalConnector makeTerminalConnector(String id) {
|
||||
IConfigurationElement[] config = RegistryFactory.getRegistry().getConfigurationElementsFor("org.eclipse.tm.terminal.control.connectors"); //$NON-NLS-1$
|
||||
IConfigurationElement[] config = RegistryFactory.getRegistry()
|
||||
.getConfigurationElementsFor("org.eclipse.tm.terminal.control.connectors"); //$NON-NLS-1$
|
||||
for (int i = 0; i < config.length; i++) {
|
||||
if(id.equals(config[i].getAttribute("id"))) { //$NON-NLS-1$
|
||||
if (id.equals(config[i].getAttribute("id"))) { //$NON-NLS-1$
|
||||
return makeConnector(config[i]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of available terminal connectors (connection types).
|
||||
*
|
||||
|
@ -89,8 +92,9 @@ public class TerminalConnectorExtension {
|
|||
* @since org.eclipse.tm.terminal 2.0 return value is ITerminalConnector[]
|
||||
*/
|
||||
public static ITerminalConnector[] makeTerminalConnectors() {
|
||||
IConfigurationElement[] config = RegistryFactory.getRegistry().getConfigurationElementsFor("org.eclipse.tm.terminal.control.connectors"); //$NON-NLS-1$
|
||||
List<ITerminalConnector> result=new ArrayList<ITerminalConnector>();
|
||||
IConfigurationElement[] config = RegistryFactory.getRegistry()
|
||||
.getConfigurationElementsFor("org.eclipse.tm.terminal.control.connectors"); //$NON-NLS-1$
|
||||
List<ITerminalConnector> result = new ArrayList<ITerminalConnector>();
|
||||
for (int i = 0; i < config.length; i++) {
|
||||
result.add(makeConnector(config[i]));
|
||||
}
|
||||
|
|
|
@ -30,17 +30,17 @@ public class TerminalState {
|
|||
/**
|
||||
* The terminal is not connected.
|
||||
*/
|
||||
public final static TerminalState CLOSED=new TerminalState("CLOSED"); //$NON-NLS-1$
|
||||
public final static TerminalState CLOSED = new TerminalState("CLOSED"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The terminal is about to connect.
|
||||
*/
|
||||
public final static TerminalState CONNECTING=new TerminalState("CONNECTING..."); //$NON-NLS-1$
|
||||
public final static TerminalState CONNECTING = new TerminalState("CONNECTING..."); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The terminal is connected.
|
||||
*/
|
||||
public final static TerminalState CONNECTED=new TerminalState("CONNECTED"); //$NON-NLS-1$
|
||||
public final static TerminalState CONNECTED = new TerminalState("CONNECTED"); //$NON-NLS-1$
|
||||
|
||||
private final String fState;
|
||||
|
||||
|
|
|
@ -32,13 +32,13 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
|||
private final ITerminalTextDataSnapshot fSnapshot;
|
||||
private int fLines;
|
||||
|
||||
private int fSelectionStartLine=-1;
|
||||
private int fSelectionStartLine = -1;
|
||||
private int fSeletionEndLine;
|
||||
private int fSelectionStartCoumn;
|
||||
private int fSelectionEndColumn;
|
||||
private ITerminalTextDataSnapshot fSelectionSnapshot;
|
||||
private String fCurrentSelection=""; //$NON-NLS-1$
|
||||
private final Point fSelectionAnchor=new Point(0,0);
|
||||
private String fCurrentSelection = ""; //$NON-NLS-1$
|
||||
private final Point fSelectionAnchor = new Point(0, 0);
|
||||
/**
|
||||
* do not update while update is running
|
||||
*/
|
||||
|
@ -46,9 +46,10 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
|||
private int fCols;
|
||||
|
||||
public AbstractTextCanvasModel(ITerminalTextDataSnapshot snapshot) {
|
||||
fSnapshot=snapshot;
|
||||
fLines=fSnapshot.getHeight();
|
||||
fSnapshot = snapshot;
|
||||
fLines = fSnapshot.getHeight();
|
||||
}
|
||||
|
||||
public void addCellCanvasModelListener(ITextCanvasModelListener listener) {
|
||||
fListeners.add(listener);
|
||||
}
|
||||
|
@ -63,13 +64,15 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
|||
listener.rangeChanged(x, y, width, height);
|
||||
}
|
||||
}
|
||||
protected void fireDimensionsChanged( int width,int height) {
|
||||
|
||||
protected void fireDimensionsChanged(int width, int height) {
|
||||
for (Iterator<ITextCanvasModelListener> iter = fListeners.iterator(); iter.hasNext();) {
|
||||
ITextCanvasModelListener listener = iter.next();
|
||||
listener.dimensionsChanged(width,height);
|
||||
listener.dimensionsChanged(width, height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void fireTerminalDataChanged() {
|
||||
for (Iterator<ITextCanvasModelListener> iter = fListeners.iterator(); iter.hasNext();) {
|
||||
ITextCanvasModelListener listener = iter.next();
|
||||
|
@ -81,36 +84,39 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
|||
public ITerminalTextDataReadOnly getTerminalText() {
|
||||
return fSnapshot;
|
||||
}
|
||||
|
||||
protected ITerminalTextDataSnapshot getSnapshot() {
|
||||
return fSnapshot;
|
||||
}
|
||||
|
||||
protected void updateSnapshot() {
|
||||
if(!fInUpdate && fSnapshot.isOutOfDate()) {
|
||||
fInUpdate=true;
|
||||
if (!fInUpdate && fSnapshot.isOutOfDate()) {
|
||||
fInUpdate = true;
|
||||
try {
|
||||
fSnapshot.updateSnapshot(false);
|
||||
if(fSnapshot.hasTerminalChanged())
|
||||
if (fSnapshot.hasTerminalChanged())
|
||||
fireTerminalDataChanged();
|
||||
// TODO why does hasDimensionsChanged not work??????
|
||||
// if(fSnapshot.hasDimensionsChanged())
|
||||
// fireDimensionsChanged();
|
||||
if(fLines!=fSnapshot.getHeight() || fCols!=fSnapshot.getWidth()) {
|
||||
fireDimensionsChanged(fSnapshot.getWidth(),fSnapshot.getHeight());
|
||||
fLines=fSnapshot.getHeight();
|
||||
fCols=fSnapshot.getWidth();
|
||||
if (fLines != fSnapshot.getHeight() || fCols != fSnapshot.getWidth()) {
|
||||
fireDimensionsChanged(fSnapshot.getWidth(), fSnapshot.getHeight());
|
||||
fLines = fSnapshot.getHeight();
|
||||
fCols = fSnapshot.getWidth();
|
||||
}
|
||||
int y=fSnapshot.getFirstChangedLine();
|
||||
int y = fSnapshot.getFirstChangedLine();
|
||||
// has any line changed?
|
||||
if(y<Integer.MAX_VALUE) {
|
||||
int height=fSnapshot.getLastChangedLine()-y+1;
|
||||
if (y < Integer.MAX_VALUE) {
|
||||
int height = fSnapshot.getLastChangedLine() - y + 1;
|
||||
fireCellRangeChanged(0, y, fSnapshot.getWidth(), height);
|
||||
}
|
||||
|
||||
} finally {
|
||||
fInUpdate=false;
|
||||
fInUpdate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* must be called from the UI thread
|
||||
*/
|
||||
|
@ -121,7 +127,6 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
|||
updateCursor();
|
||||
}
|
||||
|
||||
|
||||
public int getCursorColumn() {
|
||||
return fCursorColumn;
|
||||
}
|
||||
|
@ -133,53 +138,54 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
|||
public boolean isCursorOn() {
|
||||
return fShowCursor && fCursorIsEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* should be called regularly to draw an update of the
|
||||
* blinking cursor
|
||||
*/
|
||||
protected void updateCursor() {
|
||||
if(!fCursorIsEnabled)
|
||||
if (!fCursorIsEnabled)
|
||||
return;
|
||||
int cursorLine=getSnapshot().getCursorLine();
|
||||
int cursorColumn=getSnapshot().getCursorColumn();
|
||||
int cursorLine = getSnapshot().getCursorLine();
|
||||
int cursorColumn = getSnapshot().getCursorColumn();
|
||||
// if cursor at the end put it to the end of the
|
||||
// last line...
|
||||
if(cursorLine>=getSnapshot().getHeight()) {
|
||||
cursorLine=getSnapshot().getHeight()-1;
|
||||
cursorColumn=getSnapshot().getWidth()-1;
|
||||
if (cursorLine >= getSnapshot().getHeight()) {
|
||||
cursorLine = getSnapshot().getHeight() - 1;
|
||||
cursorColumn = getSnapshot().getWidth() - 1;
|
||||
}
|
||||
// has the cursor moved?
|
||||
if(fCursorLine!=cursorLine || fCursorColumn!=cursorColumn) {
|
||||
if (fCursorLine != cursorLine || fCursorColumn != cursorColumn) {
|
||||
// hide the old cursor!
|
||||
fShowCursor=false;
|
||||
fShowCursor = false;
|
||||
// clean the previous cursor
|
||||
// bug 206363: paint also the char to the left and right of the cursor - see also below
|
||||
int col=fCursorColumn;
|
||||
int width=2;
|
||||
if(col>0) {
|
||||
int col = fCursorColumn;
|
||||
int width = 2;
|
||||
if (col > 0) {
|
||||
col--;
|
||||
width++;
|
||||
}
|
||||
fireCellRangeChanged(col, fCursorLine, width, 1);
|
||||
// the cursor is shown when it moves!
|
||||
fShowCursor=true;
|
||||
fCursorTime=System.currentTimeMillis();
|
||||
fCursorLine=cursorLine;
|
||||
fCursorColumn=cursorColumn;
|
||||
fShowCursor = true;
|
||||
fCursorTime = System.currentTimeMillis();
|
||||
fCursorLine = cursorLine;
|
||||
fCursorColumn = cursorColumn;
|
||||
// and draw the new cursor
|
||||
fireCellRangeChanged(fCursorColumn, fCursorLine, 1, 1);
|
||||
} else {
|
||||
long t=System.currentTimeMillis();
|
||||
long t = System.currentTimeMillis();
|
||||
// TODO make the cursor blink time customisable
|
||||
if(t-fCursorTime>500) {
|
||||
fShowCursor=!fShowCursor;
|
||||
fCursorTime=t;
|
||||
if (t - fCursorTime > 500) {
|
||||
fShowCursor = !fShowCursor;
|
||||
fCursorTime = t;
|
||||
// on some windows machines, there is some left
|
||||
// over when updating the cursor .
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=206363
|
||||
int col=fCursorColumn;
|
||||
int width=2;
|
||||
if(col>0) {
|
||||
int col = fCursorColumn;
|
||||
int width = 2;
|
||||
if (col > 0) {
|
||||
col--;
|
||||
width++;
|
||||
}
|
||||
|
@ -187,25 +193,29 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setVisibleRectangle(int startLine, int startCol, int height, int width) {
|
||||
fSnapshot.setInterestWindow(Math.max(0,startLine), Math.max(1,height));
|
||||
fSnapshot.setInterestWindow(Math.max(0, startLine), Math.max(1, height));
|
||||
update();
|
||||
}
|
||||
|
||||
protected void showCursor(boolean show) {
|
||||
fShowCursor=true;
|
||||
fShowCursor = true;
|
||||
}
|
||||
|
||||
public void setCursorEnabled(boolean visible) {
|
||||
fCursorTime=System.currentTimeMillis();
|
||||
fShowCursor=visible;
|
||||
fCursorIsEnabled=visible;
|
||||
fCursorTime = System.currentTimeMillis();
|
||||
fShowCursor = visible;
|
||||
fCursorIsEnabled = visible;
|
||||
fireCellRangeChanged(fCursorColumn, fCursorLine, 1, 1);
|
||||
}
|
||||
|
||||
public boolean isCursorEnabled() {
|
||||
return fCursorIsEnabled;
|
||||
}
|
||||
|
||||
public Point getSelectionEnd() {
|
||||
if(fSelectionStartLine<0)
|
||||
if (fSelectionStartLine < 0)
|
||||
return null;
|
||||
else
|
||||
return new Point(fSelectionEndColumn, fSeletionEndLine);
|
||||
|
@ -215,57 +225,60 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
|||
if (fSelectionStartLine < 0)
|
||||
return null;
|
||||
else
|
||||
return new Point(fSelectionStartCoumn,fSelectionStartLine);
|
||||
return new Point(fSelectionStartCoumn, fSelectionStartLine);
|
||||
}
|
||||
|
||||
public Point getSelectionAnchor() {
|
||||
if(fSelectionStartLine<0)
|
||||
if (fSelectionStartLine < 0)
|
||||
return null;
|
||||
return new Point(fSelectionAnchor.x,fSelectionAnchor.y);
|
||||
return new Point(fSelectionAnchor.x, fSelectionAnchor.y);
|
||||
}
|
||||
|
||||
public void setSelectionAnchor(Point anchor) {
|
||||
fSelectionAnchor.x=anchor.x;
|
||||
fSelectionAnchor.y=anchor.y;
|
||||
fSelectionAnchor.x = anchor.x;
|
||||
fSelectionAnchor.y = anchor.y;
|
||||
}
|
||||
|
||||
public void setSelection(int startLine, int endLine, int startColumn, int endColumn) {
|
||||
// System.err.println(startLine+","+endLine+","+startColumn+","+endColumn);
|
||||
// System.err.println(startLine+","+endLine+","+startColumn+","+endColumn);
|
||||
doSetSelection(startLine, endLine, startColumn, endColumn);
|
||||
fCurrentSelection=extractSelectedText();
|
||||
fCurrentSelection = extractSelectedText();
|
||||
}
|
||||
|
||||
private void doSetSelection(int startLine, int endLine, int startColumn, int endColumn) {
|
||||
assert(startLine<0 || startLine<=endLine);
|
||||
if(startLine>=0) {
|
||||
if(fSelectionSnapshot==null) {
|
||||
fSelectionSnapshot=fSnapshot.getTerminalTextData().makeSnapshot();
|
||||
assert (startLine < 0 || startLine <= endLine);
|
||||
if (startLine >= 0) {
|
||||
if (fSelectionSnapshot == null) {
|
||||
fSelectionSnapshot = fSnapshot.getTerminalTextData().makeSnapshot();
|
||||
fSelectionSnapshot.updateSnapshot(true);
|
||||
}
|
||||
} else if(fSelectionSnapshot!=null) {
|
||||
} else if (fSelectionSnapshot != null) {
|
||||
fSelectionSnapshot.detach();
|
||||
fSelectionSnapshot=null;
|
||||
fSelectionSnapshot = null;
|
||||
}
|
||||
int oldStart=fSelectionStartLine;
|
||||
int oldEnd=fSeletionEndLine;
|
||||
int oldStart = fSelectionStartLine;
|
||||
int oldEnd = fSeletionEndLine;
|
||||
fSelectionStartLine = startLine;
|
||||
fSeletionEndLine = endLine;
|
||||
fSelectionStartCoumn = startColumn;
|
||||
fSelectionEndColumn = endColumn;
|
||||
if(fSelectionSnapshot!=null) {
|
||||
if (fSelectionSnapshot != null) {
|
||||
fSelectionSnapshot.setInterestWindow(0, fSelectionSnapshot.getHeight());
|
||||
}
|
||||
int changedStart;
|
||||
int changedEnd;
|
||||
if(oldStart<0) {
|
||||
changedStart=fSelectionStartLine;
|
||||
changedEnd=fSeletionEndLine;
|
||||
} else if(fSelectionStartLine<0) {
|
||||
changedStart=oldStart;
|
||||
changedEnd=oldEnd;
|
||||
if (oldStart < 0) {
|
||||
changedStart = fSelectionStartLine;
|
||||
changedEnd = fSeletionEndLine;
|
||||
} else if (fSelectionStartLine < 0) {
|
||||
changedStart = oldStart;
|
||||
changedEnd = oldEnd;
|
||||
} else {
|
||||
changedStart=Math.min(oldStart, fSelectionStartLine);
|
||||
changedEnd=Math.max(oldEnd, fSeletionEndLine);
|
||||
changedStart = Math.min(oldStart, fSelectionStartLine);
|
||||
changedEnd = Math.max(oldEnd, fSeletionEndLine);
|
||||
}
|
||||
if(changedStart>=0) {
|
||||
fireCellRangeChanged(0, changedStart, fSnapshot.getWidth(), changedEnd-changedStart+1);
|
||||
if (changedStart >= 0) {
|
||||
fireCellRangeChanged(0, changedStart, fSnapshot.getWidth(), changedEnd - changedStart + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,33 +313,35 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
|||
* @return the currently selected text
|
||||
*/
|
||||
private String extractSelectedText() {
|
||||
if(fSelectionStartLine<0 || fSelectionStartCoumn<0 || fSelectionSnapshot==null)
|
||||
if (fSelectionStartLine < 0 || fSelectionStartCoumn < 0 || fSelectionSnapshot == null)
|
||||
return ""; //$NON-NLS-1$
|
||||
StringBuffer buffer=new StringBuffer();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (int line = fSelectionStartLine; line <= fSeletionEndLine; line++) {
|
||||
String text;
|
||||
char[] chars=fSelectionSnapshot.getChars(line);
|
||||
if(chars!=null) {
|
||||
text=new String(chars);
|
||||
if(line==fSeletionEndLine && fSelectionEndColumn >= 0)
|
||||
text=text.substring(0, Math.min(fSelectionEndColumn+1,text.length()));
|
||||
if(line==fSelectionStartLine)
|
||||
text=text.substring(Math.min(fSelectionStartCoumn,text.length()));
|
||||
text=scrubLine(text);
|
||||
char[] chars = fSelectionSnapshot.getChars(line);
|
||||
if (chars != null) {
|
||||
text = new String(chars);
|
||||
if (line == fSeletionEndLine && fSelectionEndColumn >= 0)
|
||||
text = text.substring(0, Math.min(fSelectionEndColumn + 1, text.length()));
|
||||
if (line == fSelectionStartLine)
|
||||
text = text.substring(Math.min(fSelectionStartCoumn, text.length()));
|
||||
text = scrubLine(text);
|
||||
} else {
|
||||
text=""; //$NON-NLS-1$
|
||||
text = ""; //$NON-NLS-1$
|
||||
}
|
||||
buffer.append(text);
|
||||
if(line < fSeletionEndLine && !fSelectionSnapshot.isWrappedLine(line))
|
||||
if (line < fSeletionEndLine && !fSelectionSnapshot.isWrappedLine(line))
|
||||
buffer.append('\n');
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private void updateSelection() {
|
||||
if (fSelectionSnapshot != null && fSelectionSnapshot.isOutOfDate()) {
|
||||
fSelectionSnapshot.updateSnapshot(true);
|
||||
// has the selection moved?
|
||||
if (fSelectionSnapshot != null && fSelectionStartLine >= 0 && fSelectionSnapshot.getScrollWindowSize() > 0) {
|
||||
if (fSelectionSnapshot != null && fSelectionStartLine >= 0
|
||||
&& fSelectionSnapshot.getScrollWindowSize() > 0) {
|
||||
int start = fSelectionStartLine + fSelectionSnapshot.getScrollWindowShift();
|
||||
int end = fSeletionEndLine + fSelectionSnapshot.getScrollWindowShift();
|
||||
if (start < 0)
|
||||
|
@ -338,7 +353,7 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
|||
}
|
||||
// check if the content of the selection has changed. If the content has
|
||||
// changed, clear the selection
|
||||
if (fCurrentSelection.length()>0 && fSelectionSnapshot != null
|
||||
if (fCurrentSelection.length() > 0 && fSelectionSnapshot != null
|
||||
&& fSelectionSnapshot.getFirstChangedLine() <= fSeletionEndLine
|
||||
&& fSelectionSnapshot.getLastChangedLine() >= fSelectionStartLine) {
|
||||
// has the selected text changed?
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
@ -35,13 +34,13 @@ abstract public class GridCanvas extends VirtualCanvas {
|
|||
super(parent, style);
|
||||
addListener(SWT.MouseWheel, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
if(getVerticalBar().isVisible()) {
|
||||
int delta=-fCellHeight;
|
||||
if(event.count<0)
|
||||
delta=-delta;
|
||||
if (getVerticalBar().isVisible()) {
|
||||
int delta = -fCellHeight;
|
||||
if (event.count < 0)
|
||||
delta = -delta;
|
||||
scrollYDelta(delta);
|
||||
}
|
||||
event.doit=false;
|
||||
event.doit = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -51,36 +50,37 @@ abstract public class GridCanvas extends VirtualCanvas {
|
|||
* iterates over all cells in the clipping rectangle and paints them.
|
||||
*/
|
||||
protected void paint(GC gc) {
|
||||
Rectangle clipping=gc.getClipping();
|
||||
if(clipping.width==0 || clipping.height==0)
|
||||
Rectangle clipping = gc.getClipping();
|
||||
if (clipping.width == 0 || clipping.height == 0)
|
||||
return;
|
||||
Rectangle clientArea= getScreenRectInVirtualSpace();
|
||||
Rectangle clientArea = getScreenRectInVirtualSpace();
|
||||
// Beginning coordinates
|
||||
int xOffset=clientArea.x;
|
||||
int yOffset=clientArea.y;
|
||||
int colFirst=virtualXToCell(xOffset+clipping.x);
|
||||
if(colFirst>getCols())
|
||||
colFirst=getCols();
|
||||
int xOffset = clientArea.x;
|
||||
int yOffset = clientArea.y;
|
||||
int colFirst = virtualXToCell(xOffset + clipping.x);
|
||||
if (colFirst > getCols())
|
||||
colFirst = getCols();
|
||||
else if (colFirst < 0) {
|
||||
colFirst = 0;
|
||||
}
|
||||
int rowFirst=virtualYToCell(yOffset+clipping.y);
|
||||
int rowFirst = virtualYToCell(yOffset + clipping.y);
|
||||
// End coordinates
|
||||
int colLast=virtualXToCell(xOffset+clipping.x+clipping.width+fCellWidth);
|
||||
if(colLast>getCols())
|
||||
colLast=getCols();
|
||||
int rowLast=virtualYToCell(yOffset+clipping.y+clipping.height+fCellHeight);
|
||||
if(rowLast>getRows())
|
||||
rowLast=getRows();
|
||||
int colLast = virtualXToCell(xOffset + clipping.x + clipping.width + fCellWidth);
|
||||
if (colLast > getCols())
|
||||
colLast = getCols();
|
||||
int rowLast = virtualYToCell(yOffset + clipping.y + clipping.height + fCellHeight);
|
||||
if (rowLast > getRows())
|
||||
rowLast = getRows();
|
||||
// System.out.println(rowFirst+"->"+rowLast+" "+System.currentTimeMillis());
|
||||
// draw the cells
|
||||
for(int row=rowFirst;row<=rowLast;row++) {
|
||||
int cx=colFirst*fCellWidth-xOffset;
|
||||
int cy=row*fCellHeight-yOffset;
|
||||
drawLine(gc,row,cx,cy,colFirst,colLast);
|
||||
for (int row = rowFirst; row <= rowLast; row++) {
|
||||
int cx = colFirst * fCellWidth - xOffset;
|
||||
int cy = row * fCellHeight - yOffset;
|
||||
drawLine(gc, row, cx, cy, colFirst, colLast);
|
||||
}
|
||||
paintUnoccupiedSpace(gc,clipping);
|
||||
paintUnoccupiedSpace(gc, clipping);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gc
|
||||
* @param row the line to draw
|
||||
|
@ -92,6 +92,7 @@ abstract public class GridCanvas extends VirtualCanvas {
|
|||
abstract void drawLine(GC gc, int row, int x, int y, int colFirst, int colLast);
|
||||
|
||||
abstract protected int getRows();
|
||||
|
||||
abstract protected int getCols();
|
||||
|
||||
protected void setCellWidth(int cellWidth) {
|
||||
|
@ -113,63 +114,64 @@ abstract public class GridCanvas extends VirtualCanvas {
|
|||
}
|
||||
|
||||
int virtualXToCell(int x) {
|
||||
return x/fCellWidth;
|
||||
return x / fCellWidth;
|
||||
}
|
||||
|
||||
int virtualYToCell(int y) {
|
||||
return y/fCellHeight;
|
||||
return y / fCellHeight;
|
||||
}
|
||||
|
||||
protected Point screenPointToCell(int x, int y) {
|
||||
x=screenXtoVirtual(x)/fCellWidth;
|
||||
y=screenYtoVirtual(y)/fCellHeight;
|
||||
return new Point(x,y);
|
||||
x = screenXtoVirtual(x) / fCellWidth;
|
||||
y = screenYtoVirtual(y) / fCellHeight;
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
Point screenPointToCell(Point point) {
|
||||
return screenPointToCell(point.x,point.y);
|
||||
return screenPointToCell(point.x, point.y);
|
||||
}
|
||||
|
||||
protected Point cellToOriginOnScreen(int x, int y) {
|
||||
x=virtualXtoScreen(fCellWidth*x);
|
||||
y=virtualYtoScreen(fCellHeight*y);
|
||||
return new Point(x,y);
|
||||
x = virtualXtoScreen(fCellWidth * x);
|
||||
y = virtualYtoScreen(fCellHeight * y);
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
Point cellToOriginOnScreen(Point cell) {
|
||||
return cellToOriginOnScreen(cell.x,cell.y);
|
||||
return cellToOriginOnScreen(cell.x, cell.y);
|
||||
}
|
||||
|
||||
Rectangle getCellScreenRect(Point cell) {
|
||||
return getCellScreenRect(cell.x,cell.y);
|
||||
return getCellScreenRect(cell.x, cell.y);
|
||||
}
|
||||
|
||||
Rectangle getCellScreenRect(int x, int y) {
|
||||
x=fCellWidth*virtualXtoScreen(x);
|
||||
y=fCellHeight*virtualYtoScreen(y);
|
||||
return new Rectangle(x,y,fCellWidth,fCellHeight);
|
||||
x = fCellWidth * virtualXtoScreen(x);
|
||||
y = fCellHeight * virtualYtoScreen(y);
|
||||
return new Rectangle(x, y, fCellWidth, fCellHeight);
|
||||
}
|
||||
|
||||
protected Rectangle getCellVirtualRect(Point cell) {
|
||||
return getCellVirtualRect(cell.x,cell.y);
|
||||
return getCellVirtualRect(cell.x, cell.y);
|
||||
}
|
||||
|
||||
Rectangle getCellVirtualRect(int x, int y) {
|
||||
x=fCellWidth*x;
|
||||
y=fCellHeight*y;
|
||||
return new Rectangle(x,y,fCellWidth,fCellHeight);
|
||||
x = fCellWidth * x;
|
||||
y = fCellHeight * y;
|
||||
return new Rectangle(x, y, fCellWidth, fCellHeight);
|
||||
}
|
||||
|
||||
protected void viewRectangleChanged(int x, int y, int width, int height) {
|
||||
int cellX=virtualXToCell(x);
|
||||
int cellY=virtualYToCell(y);
|
||||
int cellX = virtualXToCell(x);
|
||||
int cellY = virtualYToCell(y);
|
||||
// End coordinates
|
||||
int xE=virtualXToCell(x+width);
|
||||
// if(xE>getCols())
|
||||
// xE=getCols();
|
||||
int yE=virtualYToCell(y+height);
|
||||
// if(yE>getRows())
|
||||
// yE=getRows();
|
||||
visibleCellRectangleChanged(cellX,cellY,xE-cellX,yE-cellY);
|
||||
int xE = virtualXToCell(x + width);
|
||||
// if(xE>getCols())
|
||||
// xE=getCols();
|
||||
int yE = virtualYToCell(y + height);
|
||||
// if(yE>getRows())
|
||||
// yE=getRows();
|
||||
visibleCellRectangleChanged(cellX, cellY, xE - cellX, yE - cellY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -206,7 +208,7 @@ abstract public class GridCanvas extends VirtualCanvas {
|
|||
}
|
||||
|
||||
protected void scrollY(ScrollBar vBar) {
|
||||
int vSelection = vBar.getSelection ();
|
||||
int vSelection = vBar.getSelection();
|
||||
Rectangle bounds = getVirtualBounds();
|
||||
int y = -vSelection;
|
||||
int cellHeight = getCellHeight();
|
||||
|
@ -219,8 +221,8 @@ abstract public class GridCanvas extends VirtualCanvas {
|
|||
}
|
||||
}
|
||||
int deltaY = y - bounds.y;
|
||||
if(deltaY!=0) {
|
||||
scrollSmart(0,deltaY);
|
||||
if (deltaY != 0) {
|
||||
scrollSmart(0, deltaY);
|
||||
setVirtualOrigin(bounds.x, bounds.y += deltaY);
|
||||
}
|
||||
if (-bounds.y + getRows() * getCellHeight() >= bounds.height) {
|
||||
|
|
|
@ -22,18 +22,24 @@ import org.eclipse.swt.graphics.GC;
|
|||
*/
|
||||
public interface ILinelRenderer {
|
||||
int getCellWidth();
|
||||
|
||||
int getCellHeight();
|
||||
|
||||
void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int colFirst, int colLast);
|
||||
|
||||
/**
|
||||
* Update for a font change from the global JFace Registry.
|
||||
*/
|
||||
void onFontChange();
|
||||
|
||||
/**
|
||||
* Set a new font
|
||||
* @param fontName Jface name of the new font
|
||||
* @since 3.2
|
||||
*/
|
||||
void updateFont(String fontName);
|
||||
|
||||
void setInvertedColors(boolean invert);
|
||||
|
||||
Color getDefaultBackgroundColor();
|
||||
}
|
||||
|
|
|
@ -17,9 +17,11 @@ import org.eclipse.tm.terminal.model.ITerminalTextDataReadOnly;
|
|||
|
||||
public interface ITextCanvasModel {
|
||||
void addCellCanvasModelListener(ITextCanvasModelListener listener);
|
||||
|
||||
void removeCellCanvasModelListener(ITextCanvasModelListener listener);
|
||||
|
||||
ITerminalTextDataReadOnly getTerminalText();
|
||||
|
||||
/**
|
||||
* This is is
|
||||
* @param startLine
|
||||
|
@ -33,6 +35,7 @@ public interface ITextCanvasModel {
|
|||
* @return true when the cursor is shown (used for blinking cursors)
|
||||
*/
|
||||
boolean isCursorOn();
|
||||
|
||||
/**
|
||||
* Show/Hide the cursor.
|
||||
* @param visible
|
||||
|
@ -48,6 +51,7 @@ public interface ITextCanvasModel {
|
|||
* @return the line of the cursor
|
||||
*/
|
||||
int getCursorLine();
|
||||
|
||||
/**
|
||||
* @return the column of the cursor
|
||||
*/
|
||||
|
@ -58,6 +62,7 @@ public interface ITextCanvasModel {
|
|||
* {@link Point#x} is the column and {@link Point#y} is the line.
|
||||
*/
|
||||
Point getSelectionStart();
|
||||
|
||||
/**
|
||||
* @return the end of the selection or null if nothing is selected
|
||||
* {@link Point#x} is the column and {@link Point#y} is the line.
|
||||
|
@ -67,6 +72,7 @@ public interface ITextCanvasModel {
|
|||
Point getSelectionAnchor();
|
||||
|
||||
void setSelectionAnchor(Point anchor);
|
||||
|
||||
/**
|
||||
* Sets the selection. A negative startLine clears the selection.
|
||||
* @param startLine
|
||||
|
|
|
@ -16,7 +16,9 @@ package org.eclipse.tm.internal.terminal.textcanvas;
|
|||
*/
|
||||
public interface ITextCanvasModelListener {
|
||||
void rangeChanged(int col, int line, int width, int height);
|
||||
|
||||
void dimensionsChanged(int cols, int rows);
|
||||
|
||||
/**
|
||||
* Called when any text change happened. Used to scroll to the
|
||||
* end of text in auto scroll mode. This does not get fired
|
||||
|
|
|
@ -62,12 +62,14 @@ public class PipedInputStream extends InputStream {
|
|||
protected int fTakePos = 0;
|
||||
protected int fUsedSlots = 0; // the count
|
||||
private boolean fClosed;
|
||||
|
||||
public BoundedByteBuffer(int capacity) throws IllegalArgumentException {
|
||||
// make sure we don't deadlock on too small capacity
|
||||
if (capacity <= 0)
|
||||
throw new IllegalArgumentException();
|
||||
fBuffer = new byte[capacity];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the bytes available for {@link #read()}
|
||||
* Must be called with a lock on this!
|
||||
|
@ -75,6 +77,7 @@ public class PipedInputStream extends InputStream {
|
|||
public int available() {
|
||||
return fUsedSlots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a single byte to the buffer. Blocks if the buffer is full.
|
||||
* @param b byte to write to the buffer
|
||||
|
@ -93,11 +96,13 @@ public class PipedInputStream extends InputStream {
|
|||
if (fUsedSlots++ == 0) // signal if was empty
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
public int getFreeSlots() {
|
||||
return fBuffer.length - fUsedSlots;
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws InterruptedException {
|
||||
assert len<=getFreeSlots();
|
||||
assert len <= getFreeSlots();
|
||||
while (fUsedSlots == fBuffer.length)
|
||||
// wait until not full
|
||||
wait();
|
||||
|
@ -111,6 +116,7 @@ public class PipedInputStream extends InputStream {
|
|||
if (wasEmpty) // signal if was empty
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a single byte. Blocks until a byte is available.
|
||||
* @return a byte from the buffer
|
||||
|
@ -120,7 +126,7 @@ public class PipedInputStream extends InputStream {
|
|||
*/
|
||||
public int read() throws InterruptedException {
|
||||
while (fUsedSlots == 0) {
|
||||
if(fClosed)
|
||||
if (fClosed)
|
||||
return -1;
|
||||
// wait until not empty
|
||||
wait();
|
||||
|
@ -132,10 +138,11 @@ public class PipedInputStream extends InputStream {
|
|||
notifyAll();
|
||||
return b;
|
||||
}
|
||||
|
||||
public int read(byte[] cbuf, int off, int len) throws InterruptedException {
|
||||
assert len<=available();
|
||||
assert len <= available();
|
||||
while (fUsedSlots == 0) {
|
||||
if(fClosed)
|
||||
if (fClosed)
|
||||
return 0;
|
||||
// wait until not empty
|
||||
wait();
|
||||
|
@ -147,15 +154,17 @@ public class PipedInputStream extends InputStream {
|
|||
fTakePos = (fTakePos + len) % fBuffer.length;
|
||||
boolean wasFull = fUsedSlots == fBuffer.length;
|
||||
fUsedSlots -= len;
|
||||
if(wasFull)
|
||||
if (wasFull)
|
||||
notifyAll();
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
fClosed=true;
|
||||
fClosed = true;
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return fClosed;
|
||||
}
|
||||
|
@ -171,11 +180,11 @@ public class PipedInputStream extends InputStream {
|
|||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
try {
|
||||
synchronized (fQueue) {
|
||||
if(fQueue.isClosed())
|
||||
if (fQueue.isClosed())
|
||||
throw new IOException("Stream is closed!"); //$NON-NLS-1$
|
||||
int written=0;
|
||||
while(written<len) {
|
||||
if(fQueue.getFreeSlots()==0) {
|
||||
int written = 0;
|
||||
while (written < len) {
|
||||
if (fQueue.getFreeSlots() == 0) {
|
||||
// if no slots available, write one byte and block
|
||||
// until free slots are available
|
||||
fQueue.write(b[off + written]);
|
||||
|
@ -183,9 +192,9 @@ public class PipedInputStream extends InputStream {
|
|||
} else {
|
||||
// if slots are available, write as much as
|
||||
// we can in one junk
|
||||
int n=Math.min(fQueue.getFreeSlots(), len-written);
|
||||
int n = Math.min(fQueue.getFreeSlots(), len - written);
|
||||
fQueue.write(b, off + written, n);
|
||||
written+=n;
|
||||
written += n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -196,34 +205,38 @@ public class PipedInputStream extends InputStream {
|
|||
|
||||
public void write(int b) throws IOException {
|
||||
try {
|
||||
synchronized(fQueue) {
|
||||
if(fQueue.isClosed())
|
||||
synchronized (fQueue) {
|
||||
if (fQueue.isClosed())
|
||||
throw new IOException("Stream is closed!"); //$NON-NLS-1$
|
||||
fQueue.write((byte)b);
|
||||
fQueue.write((byte) b);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
synchronized(fQueue) {
|
||||
synchronized (fQueue) {
|
||||
fQueue.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bufferSize the size of the buffer of the output stream
|
||||
*/
|
||||
public PipedInputStream(int bufferSize) {
|
||||
fOutputStream =new PipedOutputStream();
|
||||
fQueue=new BoundedByteBuffer(bufferSize);
|
||||
fOutputStream = new PipedOutputStream();
|
||||
fQueue = new BoundedByteBuffer(bufferSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the output stream used by the backend to write to the terminal.
|
||||
*/
|
||||
public OutputStream getOutputStream() {
|
||||
return fOutputStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until data is available for reading.
|
||||
* @param millis see {@link Object#wait(long)}
|
||||
|
@ -231,20 +244,22 @@ public class PipedInputStream extends InputStream {
|
|||
* for the buffer to become ready
|
||||
*/
|
||||
public void waitForAvailable(long millis) throws InterruptedException {
|
||||
synchronized(fQueue) {
|
||||
if(fQueue.available()==0 && !fQueue.fClosed)
|
||||
synchronized (fQueue) {
|
||||
if (fQueue.available() == 0 && !fQueue.fClosed)
|
||||
fQueue.wait(millis);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called in the Display Thread!
|
||||
* @return number of characters available for reading.
|
||||
*/
|
||||
public int available() {
|
||||
synchronized(fQueue) {
|
||||
synchronized (fQueue) {
|
||||
return fQueue.available();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the next available byte. Check with {@link #available}
|
||||
* if characters are available.
|
||||
|
@ -259,20 +274,21 @@ public class PipedInputStream extends InputStream {
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closing a <tt>PipedInputStream</tt> is the same as closing the output stream.
|
||||
* The stream will allow reading data that's still in the pipe after which it will
|
||||
* throw an <tt>IOException</tt>.
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
synchronized(fQueue) {
|
||||
synchronized (fQueue) {
|
||||
fQueue.close();
|
||||
}
|
||||
}
|
||||
|
||||
public int read(byte[] cbuf, int off, int len) throws IOException {
|
||||
int n=0;
|
||||
if(len==0)
|
||||
int n = 0;
|
||||
if (len == 0)
|
||||
return 0;
|
||||
// read as much as we can using a single synchronized statement
|
||||
try {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* Anton Leherbauer (Wind River) - [420928] Terminal widget leaks memory
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.tm.terminal.model.ITerminalTextDataSnapshot;
|
||||
|
||||
|
@ -28,17 +29,20 @@ public class PollingTextCanvasModel extends AbstractTextCanvasModel {
|
|||
super(snapshot);
|
||||
startPolling();
|
||||
}
|
||||
|
||||
public void setUpdateInterval(int t) {
|
||||
fPollInterval = t;
|
||||
}
|
||||
|
||||
public void stopPolling() {
|
||||
// timerExec only dispatches if the delay is >=0
|
||||
fPollInterval = -1;
|
||||
}
|
||||
|
||||
public void startPolling() {
|
||||
if (fPollInterval < 0) {
|
||||
fPollInterval = DEFAULT_POLL_INTERVAL;
|
||||
Display.getDefault().timerExec(fPollInterval, new Runnable(){
|
||||
Display.getDefault().timerExec(fPollInterval, new Runnable() {
|
||||
public void run() {
|
||||
update();
|
||||
Display.getDefault().timerExec(fPollInterval, this);
|
||||
|
|
|
@ -47,27 +47,30 @@ public class StyleMap {
|
|||
private static final String RED = "red"; //$NON-NLS-1$
|
||||
|
||||
private static final String PREFIX = "org.eclipse.tm.internal."; //$NON-NLS-1$
|
||||
String fFontName=ITerminalConstants.FONT_DEFINITION;
|
||||
Map<StyleColor, Color> fColorMapForeground=new HashMap<StyleColor, Color>();
|
||||
Map<StyleColor, Color> fColorMapBackground=new HashMap<StyleColor, Color>();
|
||||
Map<StyleColor, Color> fColorMapIntense=new HashMap<StyleColor, Color>();
|
||||
String fFontName = ITerminalConstants.FONT_DEFINITION;
|
||||
Map<StyleColor, Color> fColorMapForeground = new HashMap<StyleColor, Color>();
|
||||
Map<StyleColor, Color> fColorMapBackground = new HashMap<StyleColor, Color>();
|
||||
Map<StyleColor, Color> fColorMapIntense = new HashMap<StyleColor, Color>();
|
||||
private Point fCharSize;
|
||||
private final Style fDefaultStyle;
|
||||
private boolean fInvertColors;
|
||||
private boolean fProportional;
|
||||
private final int[] fOffsets=new int[256];
|
||||
private final int[] fOffsets = new int[256];
|
||||
|
||||
StyleMap() {
|
||||
initColors();
|
||||
fDefaultStyle=Style.getStyle(StyleColor.getStyleColor(BLACK),StyleColor.getStyleColor(WHITE));
|
||||
fDefaultStyle = Style.getStyle(StyleColor.getStyleColor(BLACK), StyleColor.getStyleColor(WHITE));
|
||||
updateFont();
|
||||
}
|
||||
|
||||
private void initColors() {
|
||||
initForegroundColors();
|
||||
initBackgroundColors();
|
||||
initIntenseColors();
|
||||
}
|
||||
|
||||
private void initForegroundColors() {
|
||||
if(fInvertColors) {
|
||||
if (fInvertColors) {
|
||||
setColor(fColorMapForeground, WHITE, 0, 0, 0);
|
||||
setColor(fColorMapForeground, WHITE_FOREGROUND, 50, 50, 50);
|
||||
setColor(fColorMapForeground, BLACK, 229, 229, 229);
|
||||
|
@ -86,7 +89,7 @@ public class StyleMap {
|
|||
}
|
||||
|
||||
private void initBackgroundColors() {
|
||||
if(fInvertColors) {
|
||||
if (fInvertColors) {
|
||||
setColor(fColorMapBackground, WHITE, 0, 0, 0);
|
||||
setColor(fColorMapBackground, WHITE_FOREGROUND, 50, 50, 50); // only used when colors are inverse
|
||||
setColor(fColorMapBackground, BLACK, 255, 255, 255);
|
||||
|
@ -105,7 +108,7 @@ public class StyleMap {
|
|||
}
|
||||
|
||||
private void initIntenseColors() {
|
||||
if(fInvertColors) {
|
||||
if (fInvertColors) {
|
||||
setColor(fColorMapIntense, WHITE, 127, 127, 127);
|
||||
setColor(fColorMapIntense, WHITE_FOREGROUND, 0, 0, 0); // only used when colors are inverse
|
||||
setColor(fColorMapIntense, BLACK, 255, 255, 255);
|
||||
|
@ -124,11 +127,11 @@ public class StyleMap {
|
|||
}
|
||||
|
||||
private void setColor(Map<StyleColor, Color> colorMap, String name, int r, int g, int b) {
|
||||
String colorName=PREFIX+r+"-"+g+"-"+b; //$NON-NLS-1$//$NON-NLS-2$
|
||||
Color color=JFaceResources.getColorRegistry().get(colorName);
|
||||
if(color==null) {
|
||||
JFaceResources.getColorRegistry().put(colorName, new RGB(r,g,b));
|
||||
color=JFaceResources.getColorRegistry().get(colorName);
|
||||
String colorName = PREFIX + r + "-" + g + "-" + b; //$NON-NLS-1$//$NON-NLS-2$
|
||||
Color color = JFaceResources.getColorRegistry().get(colorName);
|
||||
if (color == null) {
|
||||
JFaceResources.getColorRegistry().put(colorName, new RGB(r, g, b));
|
||||
color = JFaceResources.getColorRegistry().get(colorName);
|
||||
}
|
||||
colorMap.put(StyleColor.getStyleColor(name), color);
|
||||
colorMap.put(StyleColor.getStyleColor(name.toUpperCase()), color);
|
||||
|
@ -138,47 +141,51 @@ public class StyleMap {
|
|||
style = defaultIfNull(style);
|
||||
Map<StyleColor, Color> map = style.isBold() ? fColorMapIntense : fColorMapForeground;
|
||||
//Map map = fColorMapForeground;
|
||||
if(style.isReverse())
|
||||
return getColor(map ,style.getBackground());
|
||||
if (style.isReverse())
|
||||
return getColor(map, style.getBackground());
|
||||
else
|
||||
return getColor(map ,style.getForground());
|
||||
return getColor(map, style.getForground());
|
||||
}
|
||||
|
||||
public Color getBackgroundColor(Style style) {
|
||||
style = defaultIfNull(style);
|
||||
if(style.isReverse())
|
||||
return getColor(fColorMapBackground,style.getForground());
|
||||
if (style.isReverse())
|
||||
return getColor(fColorMapBackground, style.getForground());
|
||||
else
|
||||
return getColor(fColorMapBackground,style.getBackground());
|
||||
return getColor(fColorMapBackground, style.getBackground());
|
||||
}
|
||||
Color getColor(Map<StyleColor, Color> map,StyleColor color) {
|
||||
Color c=map.get(color);
|
||||
if(c==null) {
|
||||
c=Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
|
||||
|
||||
Color getColor(Map<StyleColor, Color> map, StyleColor color) {
|
||||
Color c = map.get(color);
|
||||
if (c == null) {
|
||||
c = Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private Style defaultIfNull(Style style) {
|
||||
if(style==null)
|
||||
style=fDefaultStyle;
|
||||
if (style == null)
|
||||
style = fDefaultStyle;
|
||||
return style;
|
||||
}
|
||||
|
||||
public void setInvertedColors(boolean invert) {
|
||||
if(invert==fInvertColors)
|
||||
if (invert == fInvertColors)
|
||||
return;
|
||||
fInvertColors=invert;
|
||||
fInvertColors = invert;
|
||||
initColors();
|
||||
}
|
||||
// static Font getBoldFont(Font font) {
|
||||
// FontData fontDatas[] = font.getFontData();
|
||||
// FontData data = fontDatas[0];
|
||||
// return new Font(Display.getCurrent(), data.getName(), data.getHeight(), data.getStyle()|SWT.BOLD);
|
||||
// }
|
||||
// static Font getBoldFont(Font font) {
|
||||
// FontData fontDatas[] = font.getFontData();
|
||||
// FontData data = fontDatas[0];
|
||||
// return new Font(Display.getCurrent(), data.getName(), data.getHeight(), data.getStyle()|SWT.BOLD);
|
||||
// }
|
||||
|
||||
public Font getFont(Style style) {
|
||||
style = defaultIfNull(style);
|
||||
if(style.isBold()) {
|
||||
if (style.isBold()) {
|
||||
return JFaceResources.getFontRegistry().getBold(fFontName);
|
||||
} else if(style.isUnderline()) {
|
||||
} else if (style.isUnderline()) {
|
||||
return JFaceResources.getFontRegistry().getItalic(fFontName);
|
||||
|
||||
}
|
||||
|
@ -189,15 +196,19 @@ public class StyleMap {
|
|||
return JFaceResources.getFontRegistry().get(fFontName);
|
||||
|
||||
}
|
||||
|
||||
public int getFontWidth() {
|
||||
return fCharSize.x;
|
||||
}
|
||||
|
||||
public int getFontHeight() {
|
||||
return fCharSize.y;
|
||||
}
|
||||
|
||||
public void updateFont() {
|
||||
updateFont(ITerminalConstants.FONT_DEFINITION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the StyleMap for a new font name.
|
||||
* The font name must be a valid name in the Jface font registry.
|
||||
|
@ -205,8 +216,8 @@ public class StyleMap {
|
|||
* @since 3.2
|
||||
*/
|
||||
public void updateFont(String fontName) {
|
||||
Display display=Display.getCurrent();
|
||||
GC gc = new GC (display);
|
||||
Display display = Display.getCurrent();
|
||||
GC gc = new GC(display);
|
||||
if (JFaceResources.getFontRegistry().hasValueFor(fontName)) {
|
||||
fFontName = fontName;
|
||||
} else {
|
||||
|
@ -214,35 +225,35 @@ public class StyleMap {
|
|||
fFontName = "org.eclipse.jface.textfont"; //$NON-NLS-1$
|
||||
}
|
||||
gc.setFont(getFont());
|
||||
fCharSize = gc.textExtent ("W"); //$NON-NLS-1$
|
||||
fProportional=false;
|
||||
fCharSize = gc.textExtent("W"); //$NON-NLS-1$
|
||||
fProportional = false;
|
||||
|
||||
for (char c = ' '; c <= '~'; c++) {
|
||||
// consider only the first 128 chars for deciding if a font
|
||||
// is proportional. Collect char width as a side-effect.
|
||||
if(measureChar(gc, c, true))
|
||||
fProportional=true;
|
||||
if (measureChar(gc, c, true))
|
||||
fProportional = true;
|
||||
}
|
||||
if(fProportional) {
|
||||
if (fProportional) {
|
||||
// Widest char minus the padding on the left and right:
|
||||
// Looks much better for small fonts
|
||||
fCharSize.x-=2;
|
||||
fCharSize.x -= 2;
|
||||
// Collect width of the upper characters (for offset calculation)
|
||||
for (char c = '~'+1; c < fOffsets.length; c++) {
|
||||
measureChar(gc, c,false);
|
||||
for (char c = '~' + 1; c < fOffsets.length; c++) {
|
||||
measureChar(gc, c, false);
|
||||
}
|
||||
// Calculate offsets based on each character's width and the bounding box
|
||||
for (int i = ' '; i < fOffsets.length; i++) {
|
||||
fOffsets[i]=(fCharSize.x-fOffsets[i])/2;
|
||||
fOffsets[i] = (fCharSize.x - fOffsets[i]) / 2;
|
||||
}
|
||||
} else {
|
||||
// Non-Proportional: Reset all offsets (eg after font change)
|
||||
for (int i = 0; i < fOffsets.length; i++) {
|
||||
fOffsets[i]=0;
|
||||
fOffsets[i] = 0;
|
||||
}
|
||||
String t = "The quick brown Fox jumps over the Lazy Dog."; //$NON-NLS-1$
|
||||
Point ext=gc.textExtent(t);
|
||||
if(ext.x != fCharSize.x * t.length()) {
|
||||
Point ext = gc.textExtent(t);
|
||||
if (ext.x != fCharSize.x * t.length()) {
|
||||
//Bug 475422: On OSX with Retina display and due to scaling,
|
||||
//a text many be shorter than the sum of its bounding boxes.
|
||||
//Because even with fixed width font, bounding box size
|
||||
|
@ -252,17 +263,18 @@ public class StyleMap {
|
|||
//is painted individually into its proper bounding box, rather
|
||||
//than using an optimization where Strings would be drawn as
|
||||
//a whole. This fixes the "fractional bounding box" problem.
|
||||
fProportional=true;
|
||||
fProportional = true;
|
||||
}
|
||||
//measure font in boldface, too, and if wider then treat like proportional
|
||||
gc.setFont(getFont(fDefaultStyle.setBold(true)));
|
||||
Point charSizeBold = gc.textExtent("W"); //$NON-NLS-1$
|
||||
if (fCharSize.x != charSizeBold.x) {
|
||||
fProportional=true;
|
||||
fProportional = true;
|
||||
}
|
||||
}
|
||||
gc.dispose ();
|
||||
gc.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gc
|
||||
* @param c
|
||||
|
@ -270,28 +282,30 @@ public class StyleMap {
|
|||
* @return true if the the font is proportional
|
||||
*/
|
||||
private boolean measureChar(GC gc, char c, boolean updateMax) {
|
||||
boolean proportional=false;
|
||||
Point ext=gc.textExtent(String.valueOf(c));
|
||||
if(ext.x>0 && ext.y>0 && (fCharSize.x!=ext.x || fCharSize.y!=ext.y)) {
|
||||
proportional=true;
|
||||
if(updateMax) {
|
||||
fCharSize.x=Math.max(fCharSize.x, ext.x);
|
||||
fCharSize.y=Math.max(fCharSize.y, ext.y);
|
||||
boolean proportional = false;
|
||||
Point ext = gc.textExtent(String.valueOf(c));
|
||||
if (ext.x > 0 && ext.y > 0 && (fCharSize.x != ext.x || fCharSize.y != ext.y)) {
|
||||
proportional = true;
|
||||
if (updateMax) {
|
||||
fCharSize.x = Math.max(fCharSize.x, ext.x);
|
||||
fCharSize.y = Math.max(fCharSize.y, ext.y);
|
||||
}
|
||||
}
|
||||
fOffsets[c]=ext.x;
|
||||
fOffsets[c] = ext.x;
|
||||
return proportional;
|
||||
}
|
||||
|
||||
public boolean isFontProportional() {
|
||||
return fProportional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the offset in pixels required to center a given character
|
||||
* @param c the character to measure
|
||||
* @return the offset in x direction to center this character
|
||||
*/
|
||||
public int getCharOffset(char c) {
|
||||
if(c>=fOffsets.length)
|
||||
if (c >= fOffsets.length)
|
||||
return 0;
|
||||
return fOffsets[c];
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -82,8 +81,8 @@ public class TextCanvas extends GridCanvas {
|
|||
// since it allows switching the terminal viewport small/large as needed,
|
||||
// without destroying the backing store. For a complete solution,
|
||||
// Bug 196462 tracks the request for a user-defined fixed-widow-size-mode.
|
||||
private int fMinColumns=80;
|
||||
private int fMinLines=4;
|
||||
private int fMinColumns = 80;
|
||||
private int fMinLines = 4;
|
||||
private boolean fCursorEnabled;
|
||||
private boolean fResizing;
|
||||
|
||||
|
@ -91,23 +90,28 @@ public class TextCanvas extends GridCanvas {
|
|||
* Create a new CellCanvas with the given SWT style bits.
|
||||
* (SWT.H_SCROLL and SWT.V_SCROLL are automatically added).
|
||||
*/
|
||||
public TextCanvas(Composite parent, ITextCanvasModel model, int style,ILinelRenderer cellRenderer) {
|
||||
public TextCanvas(Composite parent, ITextCanvasModel model, int style, ILinelRenderer cellRenderer) {
|
||||
super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
fCellRenderer=cellRenderer;
|
||||
fCellRenderer = cellRenderer;
|
||||
setCellWidth(fCellRenderer.getCellWidth());
|
||||
setCellHeight(fCellRenderer.getCellHeight());
|
||||
fCellCanvasModel=model;
|
||||
fCellCanvasModel.addCellCanvasModelListener(new ITextCanvasModelListener(){
|
||||
fCellCanvasModel = model;
|
||||
fCellCanvasModel.addCellCanvasModelListener(new ITextCanvasModelListener() {
|
||||
public void rangeChanged(int col, int line, int width, int height) {
|
||||
if(isDisposed()) return;
|
||||
repaintRange(col,line,width,height);
|
||||
if (isDisposed())
|
||||
return;
|
||||
repaintRange(col, line, width, height);
|
||||
}
|
||||
|
||||
public void dimensionsChanged(int cols, int rows) {
|
||||
if(isDisposed()) return;
|
||||
if (isDisposed())
|
||||
return;
|
||||
calculateGrid();
|
||||
}
|
||||
|
||||
public void terminalDataChanged() {
|
||||
if(isDisposed()) return;
|
||||
if (isDisposed())
|
||||
return;
|
||||
|
||||
// scroll to end (unless scroll lock is active)
|
||||
if (!fResizing) {
|
||||
|
@ -117,15 +121,17 @@ public class TextCanvas extends GridCanvas {
|
|||
}
|
||||
});
|
||||
// let the cursor blink if the text canvas gets the focus...
|
||||
addFocusListener(new FocusListener(){
|
||||
addFocusListener(new FocusListener() {
|
||||
public void focusGained(FocusEvent e) {
|
||||
fCellCanvasModel.setCursorEnabled(fCursorEnabled);
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
fCellCanvasModel.setCursorEnabled(false);
|
||||
}});
|
||||
}
|
||||
});
|
||||
fMouseListeners = new ArrayList<ITerminalMouseListener>();
|
||||
addMouseListener(new MouseListener(){
|
||||
addMouseListener(new MouseListener() {
|
||||
public void mouseDoubleClick(MouseEvent e) {
|
||||
if (fMouseListeners.size() > 0) {
|
||||
Point pt = screenPointToCell(e.x, e.y);
|
||||
|
@ -136,18 +142,19 @@ public class TextCanvas extends GridCanvas {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseDown(MouseEvent e) {
|
||||
if(e.button==1) { // left button
|
||||
fDraggingStart=screenPointToCell(e.x, e.y);
|
||||
fHasSelection=false;
|
||||
if((e.stateMask&SWT.SHIFT)!=0) {
|
||||
Point anchor=fCellCanvasModel.getSelectionAnchor();
|
||||
if(anchor!=null)
|
||||
fDraggingStart=anchor;
|
||||
if (e.button == 1) { // left button
|
||||
fDraggingStart = screenPointToCell(e.x, e.y);
|
||||
fHasSelection = false;
|
||||
if ((e.stateMask & SWT.SHIFT) != 0) {
|
||||
Point anchor = fCellCanvasModel.getSelectionAnchor();
|
||||
if (anchor != null)
|
||||
fDraggingStart = anchor;
|
||||
} else {
|
||||
fCellCanvasModel.setSelectionAnchor(fDraggingStart);
|
||||
}
|
||||
fDraggingEnd=null;
|
||||
fDraggingEnd = null;
|
||||
}
|
||||
if (fMouseListeners.size() > 0) {
|
||||
Point pt = screenPointToCell(e.x, e.y);
|
||||
|
@ -158,14 +165,15 @@ public class TextCanvas extends GridCanvas {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseUp(MouseEvent e) {
|
||||
if(e.button==1) { // left button
|
||||
if (e.button == 1) { // left button
|
||||
updateHasSelection(e);
|
||||
if(fHasSelection)
|
||||
if (fHasSelection)
|
||||
setSelection(screenPointToCell(e.x, e.y));
|
||||
else
|
||||
fCellCanvasModel.setSelection(-1,-1,-1,-1);
|
||||
fDraggingStart=null;
|
||||
fCellCanvasModel.setSelection(-1, -1, -1, -1);
|
||||
fDraggingStart = null;
|
||||
}
|
||||
if (fMouseListeners.size() > 0) {
|
||||
Point pt = screenPointToCell(e.x, e.y);
|
||||
|
@ -197,15 +205,15 @@ public class TextCanvas extends GridCanvas {
|
|||
* @param e
|
||||
*/
|
||||
private void updateHasSelection(MouseEvent e) {
|
||||
if(fDraggingStart!=null) {
|
||||
Point p=screenPointToCell(e.x, e.y);
|
||||
if(fDraggingStart.x!=p.x||fDraggingStart.y!=p.y)
|
||||
fHasSelection=true;
|
||||
if (fDraggingStart != null) {
|
||||
Point p = screenPointToCell(e.x, e.y);
|
||||
if (fDraggingStart.x != p.x || fDraggingStart.y != p.y)
|
||||
fHasSelection = true;
|
||||
}
|
||||
}
|
||||
|
||||
void setSelection(Point p) {
|
||||
if (fDraggingStart !=null && !p.equals(fDraggingEnd)) {
|
||||
if (fDraggingStart != null && !p.equals(fDraggingEnd)) {
|
||||
fDraggingEnd = p;
|
||||
if (compare(p, fDraggingStart) < 0) {
|
||||
// bug 219589 - make sure selection start coordinates are non-negative
|
||||
|
@ -234,6 +242,7 @@ public class TextCanvas extends GridCanvas {
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public ILinelRenderer getCellRenderer() {
|
||||
return fCellRenderer;
|
||||
}
|
||||
|
@ -255,30 +264,30 @@ public class TextCanvas extends GridCanvas {
|
|||
}
|
||||
|
||||
protected void onResize(boolean init) {
|
||||
if(fResizeListener!=null) {
|
||||
Rectangle bonds=getClientArea();
|
||||
if (fResizeListener != null) {
|
||||
Rectangle bonds = getClientArea();
|
||||
int cellHeight = getCellHeight();
|
||||
int cellWidth = getCellWidth();
|
||||
int lines=bonds.height/cellHeight;
|
||||
int columns=bonds.width/cellWidth;
|
||||
int lines = bonds.height / cellHeight;
|
||||
int columns = bonds.width / cellWidth;
|
||||
// when the view is minimised, its size is set to 0
|
||||
// we don't sent this to the terminal!
|
||||
if((lines>0 && columns>0) || init) {
|
||||
if(columns<fMinColumns) {
|
||||
if(!isHorizontalBarVisble()) {
|
||||
if ((lines > 0 && columns > 0) || init) {
|
||||
if (columns < fMinColumns) {
|
||||
if (!isHorizontalBarVisble()) {
|
||||
setHorizontalBarVisible(true);
|
||||
bonds=getClientArea();
|
||||
lines=bonds.height/cellHeight;
|
||||
bonds = getClientArea();
|
||||
lines = bonds.height / cellHeight;
|
||||
}
|
||||
columns=fMinColumns;
|
||||
} else if(columns>=fMinColumns && isHorizontalBarVisble()) {
|
||||
columns = fMinColumns;
|
||||
} else if (columns >= fMinColumns && isHorizontalBarVisble()) {
|
||||
setHorizontalBarVisible(false);
|
||||
bonds=getClientArea();
|
||||
lines=bonds.height/cellHeight;
|
||||
columns=bonds.width/cellWidth;
|
||||
bonds = getClientArea();
|
||||
lines = bonds.height / cellHeight;
|
||||
columns = bonds.width / cellWidth;
|
||||
}
|
||||
if(lines<fMinLines)
|
||||
lines=fMinLines;
|
||||
if (lines < fMinLines)
|
||||
lines = fMinLines;
|
||||
fResizeListener.sizeChanged(lines, columns);
|
||||
}
|
||||
}
|
||||
|
@ -299,7 +308,7 @@ public class TextCanvas extends GridCanvas {
|
|||
Rectangle virtualBounds = getVirtualBounds();
|
||||
setRedraw(false);
|
||||
try {
|
||||
setVirtualExtend(getCols()*getCellWidth(),getRows()*getCellHeight());
|
||||
setVirtualExtend(getCols() * getCellWidth(), getRows() * getCellHeight());
|
||||
getParent().layout();
|
||||
if (fResizing) {
|
||||
// scroll to end if view port was near last line
|
||||
|
@ -311,21 +320,23 @@ public class TextCanvas extends GridCanvas {
|
|||
setRedraw(true);
|
||||
}
|
||||
}
|
||||
|
||||
void scrollToEnd() {
|
||||
if(!fScrollLock) {
|
||||
int y=-(getRows()*getCellHeight()-getClientArea().height);
|
||||
if (!fScrollLock) {
|
||||
int y = -(getRows() * getCellHeight() - getClientArea().height);
|
||||
if (y > 0) {
|
||||
y = 0;
|
||||
}
|
||||
Rectangle v=getViewRectangle();
|
||||
if(v.y!=-y) {
|
||||
setVirtualOrigin(v.x,y);
|
||||
Rectangle v = getViewRectangle();
|
||||
if (v.y != -y) {
|
||||
setVirtualOrigin(v.x, y);
|
||||
}
|
||||
// make sure the scroll area is correct:
|
||||
scrollY(getVerticalBar());
|
||||
scrollX(getHorizontalBar());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the cursor should be shown on output....
|
||||
|
@ -333,37 +344,46 @@ public class TextCanvas extends GridCanvas {
|
|||
public boolean isScrollLock() {
|
||||
return fScrollLock;
|
||||
}
|
||||
|
||||
/**
|
||||
* If set then if the size changes
|
||||
*/
|
||||
public void setScrollLock(boolean scrollLock) {
|
||||
fScrollLock=scrollLock;
|
||||
fScrollLock = scrollLock;
|
||||
}
|
||||
|
||||
protected void repaintRange(int col, int line, int width, int height) {
|
||||
Point origin=cellToOriginOnScreen(col,line);
|
||||
Rectangle r=new Rectangle(origin.x,origin.y,width*getCellWidth(),height*getCellHeight());
|
||||
Point origin = cellToOriginOnScreen(col, line);
|
||||
Rectangle r = new Rectangle(origin.x, origin.y, width * getCellWidth(), height * getCellHeight());
|
||||
repaint(r);
|
||||
}
|
||||
|
||||
protected void drawLine(GC gc, int line, int x, int y, int colFirst, int colLast) {
|
||||
fCellRenderer.drawLine(fCellCanvasModel, gc,line,x,y,colFirst, colLast);
|
||||
fCellRenderer.drawLine(fCellCanvasModel, gc, line, x, y, colFirst, colLast);
|
||||
}
|
||||
|
||||
protected Color getTerminalBackgroundColor() {
|
||||
return fCellRenderer.getDefaultBackgroundColor();
|
||||
}
|
||||
|
||||
protected void visibleCellRectangleChanged(int x, int y, int width, int height) {
|
||||
fCellCanvasModel.setVisibleRectangle(y,x,height,width);
|
||||
fCellCanvasModel.setVisibleRectangle(y, x, height, width);
|
||||
update();
|
||||
}
|
||||
|
||||
protected int getCols() {
|
||||
return fCellCanvasModel.getTerminalText().getWidth();
|
||||
}
|
||||
|
||||
protected int getRows() {
|
||||
return fCellCanvasModel.getTerminalText().getHeight();
|
||||
}
|
||||
|
||||
public String getSelectionText() {
|
||||
// TODO -- create a hasSelectionMethod!
|
||||
return fCellCanvasModel.getSelectedText();
|
||||
}
|
||||
|
||||
public void copy() {
|
||||
String selectionText = getSelectionText();
|
||||
if (selectionText != null && selectionText.length() > 0) {
|
||||
|
@ -372,16 +392,18 @@ public class TextCanvas extends GridCanvas {
|
|||
clipboard.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void selectAll() {
|
||||
fCellCanvasModel.setSelection(0, fCellCanvasModel.getTerminalText().getHeight(), 0, fCellCanvasModel.getTerminalText().getWidth());
|
||||
fCellCanvasModel.setSelectionAnchor(new Point(0,0));
|
||||
fCellCanvasModel.setSelection(0, fCellCanvasModel.getTerminalText().getHeight(), 0,
|
||||
fCellCanvasModel.getTerminalText().getWidth());
|
||||
fCellCanvasModel.setSelectionAnchor(new Point(0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 4.1
|
||||
*/
|
||||
public void clearSelection() {
|
||||
fCellCanvasModel.setSelection(-1,-1,-1,-1);
|
||||
fCellCanvasModel.setSelection(-1, -1, -1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -403,6 +425,7 @@ public class TextCanvas extends GridCanvas {
|
|||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets notified when the visible size of the terminal changes.
|
||||
* This should update the model!
|
||||
|
@ -411,23 +434,24 @@ public class TextCanvas extends GridCanvas {
|
|||
public interface ResizeListener {
|
||||
void sizeChanged(int lines, int columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param listener this listener gets notified, when the size of
|
||||
* the widget changed. It should change the dimensions of the underlying
|
||||
* terminaldata
|
||||
*/
|
||||
public void addResizeHandler(ResizeListener listener) {
|
||||
if(fResizeListener!=null)
|
||||
if (fResizeListener != null)
|
||||
throw new IllegalArgumentException("There can be at most one listener at the moment!"); //$NON-NLS-1$
|
||||
fResizeListener=listener;
|
||||
fResizeListener = listener;
|
||||
|
||||
// Bug 281328: [terminal] The very first few characters might be missing in
|
||||
// the terminal control if opened and connected programmatically
|
||||
//
|
||||
// In case the terminal had not been visible yet or is too small (less than one
|
||||
// line visible), the terminal should have a minimum size to avoid RuntimeExceptions.
|
||||
Rectangle bonds=getClientArea();
|
||||
if (bonds.height<getCellHeight() || bonds.width<getCellWidth()) {
|
||||
Rectangle bonds = getClientArea();
|
||||
if (bonds.height < getCellHeight() || bonds.width < getCellWidth()) {
|
||||
//Widget not realized yet, or minimized to < 1 item:
|
||||
//Just tell the listener our min size
|
||||
fResizeListener.sizeChanged(getMinLines(), getMinColumns());
|
||||
|
@ -470,8 +494,8 @@ public class TextCanvas extends GridCanvas {
|
|||
* @param enabled enabling means that the cursor blinks
|
||||
*/
|
||||
public void setCursorEnabled(boolean enabled) {
|
||||
if(enabled!=fCursorEnabled) {
|
||||
fCursorEnabled=enabled;
|
||||
if (enabled != fCursorEnabled) {
|
||||
fCursorEnabled = enabled;
|
||||
fCellCanvasModel.setCursorEnabled(fCursorEnabled);
|
||||
}
|
||||
|
||||
|
@ -485,4 +509,3 @@ public class TextCanvas extends GridCanvas {
|
|||
fMouseListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,56 +31,61 @@ import org.eclipse.tm.terminal.model.Style;
|
|||
*/
|
||||
public class TextLineRenderer implements ILinelRenderer {
|
||||
private final ITextCanvasModel fModel;
|
||||
StyleMap fStyleMap=new StyleMap();
|
||||
StyleMap fStyleMap = new StyleMap();
|
||||
|
||||
public TextLineRenderer(TextCanvas c, ITextCanvasModel model) {
|
||||
fModel=model;
|
||||
fModel = model;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.imagicus.thumbs.view.ICellRenderer#getCellWidth()
|
||||
*/
|
||||
public int getCellWidth() {
|
||||
return fStyleMap.getFontWidth();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.imagicus.thumbs.view.ICellRenderer#getCellHeight()
|
||||
*/
|
||||
public int getCellHeight() {
|
||||
return fStyleMap.getFontHeight();
|
||||
}
|
||||
|
||||
public void drawLine(ITextCanvasModel model, GC gc, int line, int x, int y, int colFirst, int colLast) {
|
||||
if(line<0 || line>=getTerminalText().getHeight() || colFirst>=getTerminalText().getWidth() || colFirst-colLast==0) {
|
||||
fillBackground(gc, x, y, getCellWidth()*(colLast-colFirst), getCellHeight());
|
||||
if (line < 0 || line >= getTerminalText().getHeight() || colFirst >= getTerminalText().getWidth()
|
||||
|| colFirst - colLast == 0) {
|
||||
fillBackground(gc, x, y, getCellWidth() * (colLast - colFirst), getCellHeight());
|
||||
} else {
|
||||
colLast=Math.min(colLast, getTerminalText().getWidth());
|
||||
LineSegment[] segments=getTerminalText().getLineSegments(line, colFirst, colLast-colFirst);
|
||||
colLast = Math.min(colLast, getTerminalText().getWidth());
|
||||
LineSegment[] segments = getTerminalText().getLineSegments(line, colFirst, colLast - colFirst);
|
||||
for (int i = 0; i < segments.length; i++) {
|
||||
LineSegment segment=segments[i];
|
||||
Style style=segment.getStyle();
|
||||
LineSegment segment = segments[i];
|
||||
Style style = segment.getStyle();
|
||||
setupGC(gc, style);
|
||||
String text=segment.getText();
|
||||
String text = segment.getText();
|
||||
drawText(gc, x, y, colFirst, segment.getColumn(), text);
|
||||
drawCursor(model, gc, line, x, y, colFirst);
|
||||
}
|
||||
if(fModel.hasLineSelection(line)) {
|
||||
if (fModel.hasLineSelection(line)) {
|
||||
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
|
||||
gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_SELECTION));
|
||||
Point start=model.getSelectionStart();
|
||||
Point end=model.getSelectionEnd();
|
||||
char[] chars=model.getTerminalText().getChars(line);
|
||||
if(chars==null)
|
||||
Point start = model.getSelectionStart();
|
||||
Point end = model.getSelectionEnd();
|
||||
char[] chars = model.getTerminalText().getChars(line);
|
||||
if (chars == null)
|
||||
return;
|
||||
int offset=0;
|
||||
if(start.y==line)
|
||||
offset=start.x;
|
||||
offset=Math.max(offset, colFirst);
|
||||
int offset = 0;
|
||||
if (start.y == line)
|
||||
offset = start.x;
|
||||
offset = Math.max(offset, colFirst);
|
||||
int len;
|
||||
if(end.y==line)
|
||||
len=end.x-offset+1;
|
||||
if (end.y == line)
|
||||
len = end.x - offset + 1;
|
||||
else
|
||||
len=chars.length-offset+1;
|
||||
len=Math.min(len,chars.length-offset);
|
||||
if(len>0) {
|
||||
String text=new String(chars,offset,len);
|
||||
len = chars.length - offset + 1;
|
||||
len = Math.min(len, chars.length - offset);
|
||||
if (len > 0) {
|
||||
String text = new String(chars, offset, len);
|
||||
drawText(gc, x, y, colFirst, offset, text);
|
||||
}
|
||||
}
|
||||
|
@ -88,9 +93,9 @@ public class TextLineRenderer implements ILinelRenderer {
|
|||
}
|
||||
|
||||
private void fillBackground(GC gc, int x, int y, int width, int height) {
|
||||
Color bg=gc.getBackground();
|
||||
Color bg = gc.getBackground();
|
||||
gc.setBackground(getDefaultBackgroundColor());
|
||||
gc.fillRectangle (x,y,width,height);
|
||||
gc.fillRectangle(x, y, width, height);
|
||||
gc.setBackground(bg);
|
||||
|
||||
}
|
||||
|
@ -101,68 +106,74 @@ public class TextLineRenderer implements ILinelRenderer {
|
|||
}
|
||||
|
||||
private void drawCursor(ITextCanvasModel model, GC gc, int row, int x, int y, int colFirst) {
|
||||
if(!model.isCursorOn())
|
||||
if (!model.isCursorOn())
|
||||
return;
|
||||
int cursorLine=model.getCursorLine();
|
||||
int cursorLine = model.getCursorLine();
|
||||
|
||||
if(row==cursorLine) {
|
||||
int cursorColumn=model.getCursorColumn();
|
||||
if(cursorColumn<getTerminalText().getWidth()) {
|
||||
Style style=getTerminalText().getStyle(row, cursorColumn);
|
||||
if(style==null) {
|
||||
if (row == cursorLine) {
|
||||
int cursorColumn = model.getCursorColumn();
|
||||
if (cursorColumn < getTerminalText().getWidth()) {
|
||||
Style style = getTerminalText().getStyle(row, cursorColumn);
|
||||
if (style == null) {
|
||||
// TODO make the cursor color customizable
|
||||
style=Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$//$NON-NLS-2$
|
||||
style = Style.getStyle("BLACK", "WHITE"); //$NON-NLS-1$//$NON-NLS-2$
|
||||
}
|
||||
style=style.setReverse(!style.isReverse());
|
||||
setupGC(gc,style);
|
||||
String text=String.valueOf(getTerminalText().getChar(row, cursorColumn));
|
||||
style = style.setReverse(!style.isReverse());
|
||||
setupGC(gc, style);
|
||||
String text = String.valueOf(getTerminalText().getChar(row, cursorColumn));
|
||||
drawText(gc, x, y, colFirst, cursorColumn, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawText(GC gc, int x, int y, int colFirst, int col, String text) {
|
||||
int offset=(col-colFirst)*getCellWidth();
|
||||
if(fStyleMap.isFontProportional()) {
|
||||
int offset = (col - colFirst) * getCellWidth();
|
||||
if (fStyleMap.isFontProportional()) {
|
||||
// draw the background
|
||||
// TODO why does this not work???????
|
||||
// gc.fillRectangle(x,y,fStyleMap.getFontWidth()*text.length(),fStyleMap.getFontHeight());
|
||||
// gc.fillRectangle(x,y,fStyleMap.getFontWidth()*text.length(),fStyleMap.getFontHeight());
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char c=text.charAt(i);
|
||||
int xx=x+offset+i*fStyleMap.getFontWidth();
|
||||
char c = text.charAt(i);
|
||||
int xx = x + offset + i * fStyleMap.getFontWidth();
|
||||
// TODO why do I have to draw the background character by character??????
|
||||
gc.fillRectangle(xx,y,fStyleMap.getFontWidth(),fStyleMap.getFontHeight());
|
||||
if(c!=' ' && c!='\000') {
|
||||
gc.drawString(String.valueOf(c),fStyleMap.getCharOffset(c)+xx,y,true);
|
||||
gc.fillRectangle(xx, y, fStyleMap.getFontWidth(), fStyleMap.getFontHeight());
|
||||
if (c != ' ' && c != '\000') {
|
||||
gc.drawString(String.valueOf(c), fStyleMap.getCharOffset(c) + xx, y, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
text=text.replace('\000', ' ');
|
||||
gc.drawString(text,x+offset,y,false);
|
||||
text = text.replace('\000', ' ');
|
||||
gc.drawString(text, x + offset, y, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupGC(GC gc, Style style) {
|
||||
Color c=fStyleMap.getForegrondColor(style);
|
||||
if(c!=gc.getForeground()) {
|
||||
Color c = fStyleMap.getForegrondColor(style);
|
||||
if (c != gc.getForeground()) {
|
||||
gc.setForeground(c);
|
||||
}
|
||||
c=fStyleMap.getBackgroundColor(style);
|
||||
if(c!=gc.getBackground()) {
|
||||
c = fStyleMap.getBackgroundColor(style);
|
||||
if (c != gc.getBackground()) {
|
||||
gc.setBackground(c);
|
||||
}
|
||||
Font f=fStyleMap.getFont(style);
|
||||
if(f!=gc.getFont()) {
|
||||
Font f = fStyleMap.getFont(style);
|
||||
if (f != gc.getFont()) {
|
||||
gc.setFont(f);
|
||||
}
|
||||
}
|
||||
|
||||
ITerminalTextDataReadOnly getTerminalText() {
|
||||
return fModel.getTerminalText();
|
||||
}
|
||||
|
||||
public void onFontChange() {
|
||||
fStyleMap.updateFont();
|
||||
}
|
||||
|
||||
public void updateFont(String fontName) {
|
||||
fStyleMap.updateFont(fontName);
|
||||
}
|
||||
|
||||
public void setInvertedColors(boolean invert) {
|
||||
fStyleMap.setInvertedColors(invert);
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.swt.SWT;
|
||||
|
@ -32,7 +31,7 @@ import org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin;
|
|||
*/
|
||||
public abstract class VirtualCanvas extends Canvas {
|
||||
|
||||
private final Rectangle fVirtualBounds = new Rectangle(0,0,0,0);
|
||||
private final Rectangle fVirtualBounds = new Rectangle(0, 0, 0, 0);
|
||||
private Rectangle fClientArea;
|
||||
/**
|
||||
* prevent infinite loop in {@link #updateScrollbars()}
|
||||
|
@ -41,8 +40,8 @@ public abstract class VirtualCanvas extends Canvas {
|
|||
private static boolean fInUpdateScrollbarsLogged;
|
||||
|
||||
public VirtualCanvas(Composite parent, int style) {
|
||||
super(parent, style|SWT.NO_BACKGROUND|SWT.NO_REDRAW_RESIZE);
|
||||
fClientArea=getClientArea();
|
||||
super(parent, style | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE);
|
||||
fClientArea = getClientArea();
|
||||
addListener(SWT.Paint, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
paint(event.gc);
|
||||
|
@ -50,59 +49,62 @@ public abstract class VirtualCanvas extends Canvas {
|
|||
});
|
||||
addListener(SWT.Resize, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
fClientArea=getClientArea();
|
||||
fClientArea = getClientArea();
|
||||
onResize();
|
||||
}
|
||||
});
|
||||
getVerticalBar().addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
scrollY((ScrollBar)e.widget);
|
||||
scrollY((ScrollBar) e.widget);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
getHorizontalBar().addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
scrollX((ScrollBar)e.widget);
|
||||
scrollX((ScrollBar) e.widget);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void onResize() {
|
||||
updateViewRectangle();
|
||||
}
|
||||
|
||||
protected void scrollX(ScrollBar hBar) {
|
||||
int hSelection = hBar.getSelection ();
|
||||
int hSelection = hBar.getSelection();
|
||||
int destX = -hSelection - fVirtualBounds.x;
|
||||
fVirtualBounds.x = -hSelection;
|
||||
scrollSmart(destX, 0);
|
||||
updateViewRectangle();
|
||||
}
|
||||
|
||||
protected void scrollXDelta(int delta) {
|
||||
getHorizontalBar().setSelection(-fVirtualBounds.x+delta);
|
||||
getHorizontalBar().setSelection(-fVirtualBounds.x + delta);
|
||||
scrollX(getHorizontalBar());
|
||||
}
|
||||
|
||||
protected void scrollY(ScrollBar vBar) {
|
||||
int vSelection = vBar.getSelection ();
|
||||
int vSelection = vBar.getSelection();
|
||||
int destY = -vSelection - fVirtualBounds.y;
|
||||
if(destY!=0) {
|
||||
if (destY != 0) {
|
||||
fVirtualBounds.y = -vSelection;
|
||||
scrollSmart(0,destY);
|
||||
scrollSmart(0, destY);
|
||||
updateViewRectangle();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void scrollYDelta(int delta) {
|
||||
getVerticalBar().setSelection(-fVirtualBounds.y+delta);
|
||||
getVerticalBar().setSelection(-fVirtualBounds.y + delta);
|
||||
scrollY(getVerticalBar());
|
||||
}
|
||||
|
||||
|
||||
protected void scrollSmart(int deltaX, int deltaY) {
|
||||
if (deltaX != 0 || deltaY != 0) {
|
||||
Rectangle rect = getBounds();
|
||||
scroll (deltaX, deltaY, 0, 0, rect.width, rect.height, false);
|
||||
scroll(deltaX, deltaY, 0, 0, rect.width, rect.height, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,37 +112,37 @@ public abstract class VirtualCanvas extends Canvas {
|
|||
* @param rect in virtual space
|
||||
*/
|
||||
protected void revealRect(Rectangle rect) {
|
||||
Rectangle visibleRect=getScreenRectInVirtualSpace();
|
||||
Rectangle visibleRect = getScreenRectInVirtualSpace();
|
||||
// scroll the X part
|
||||
int deltaX=0;
|
||||
if(rect.x<visibleRect.x) {
|
||||
deltaX=rect.x-visibleRect.x;
|
||||
} else if(visibleRect.x+visibleRect.width<rect.x+rect.width){
|
||||
deltaX=(rect.x+rect.width)-(visibleRect.x+visibleRect.width);
|
||||
int deltaX = 0;
|
||||
if (rect.x < visibleRect.x) {
|
||||
deltaX = rect.x - visibleRect.x;
|
||||
} else if (visibleRect.x + visibleRect.width < rect.x + rect.width) {
|
||||
deltaX = (rect.x + rect.width) - (visibleRect.x + visibleRect.width);
|
||||
}
|
||||
if(deltaX!=0) {
|
||||
getHorizontalBar().setSelection(-fVirtualBounds.x+deltaX);
|
||||
if (deltaX != 0) {
|
||||
getHorizontalBar().setSelection(-fVirtualBounds.x + deltaX);
|
||||
scrollX(getHorizontalBar());
|
||||
}
|
||||
|
||||
// scroll the Y part
|
||||
int deltaY=0;
|
||||
if(rect.y<visibleRect.y){
|
||||
deltaY=rect.y-visibleRect.y;
|
||||
} else if(visibleRect.y+visibleRect.height<rect.y+rect.height){
|
||||
deltaY=(rect.y+rect.height)-(visibleRect.y+visibleRect.height);
|
||||
int deltaY = 0;
|
||||
if (rect.y < visibleRect.y) {
|
||||
deltaY = rect.y - visibleRect.y;
|
||||
} else if (visibleRect.y + visibleRect.height < rect.y + rect.height) {
|
||||
deltaY = (rect.y + rect.height) - (visibleRect.y + visibleRect.height);
|
||||
|
||||
}
|
||||
if(deltaY!=0) {
|
||||
getVerticalBar().setSelection(-fVirtualBounds.y+deltaY);
|
||||
if (deltaY != 0) {
|
||||
getVerticalBar().setSelection(-fVirtualBounds.y + deltaY);
|
||||
scrollY(getVerticalBar());
|
||||
}
|
||||
}
|
||||
|
||||
protected void repaint(Rectangle r) {
|
||||
if(isDisposed())
|
||||
if (isDisposed())
|
||||
return;
|
||||
if(inClipping(r,fClientArea)) {
|
||||
if (inClipping(r, fClientArea)) {
|
||||
redraw(r.x, r.y, r.width, r.height, true);
|
||||
update();
|
||||
}
|
||||
|
@ -152,58 +154,64 @@ public abstract class VirtualCanvas extends Canvas {
|
|||
* @param gc graphics context to paint in
|
||||
*/
|
||||
abstract protected void paint(GC gc);
|
||||
|
||||
protected Color getTerminalBackgroundColor() {
|
||||
// return getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
|
||||
// return getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
|
||||
return getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
|
||||
}
|
||||
|
||||
protected void paintUnoccupiedSpace(GC gc, Rectangle clipping) {
|
||||
int width=fVirtualBounds.width + fVirtualBounds.x;
|
||||
int height=fVirtualBounds.height + fVirtualBounds.y;
|
||||
int marginWidth = (clipping.x+clipping.width) - width;
|
||||
int marginHeight = (clipping.y+clipping.height) - height;
|
||||
if(marginWidth>0||marginHeight>0){
|
||||
Color bg=getBackground();
|
||||
int width = fVirtualBounds.width + fVirtualBounds.x;
|
||||
int height = fVirtualBounds.height + fVirtualBounds.y;
|
||||
int marginWidth = (clipping.x + clipping.width) - width;
|
||||
int marginHeight = (clipping.y + clipping.height) - height;
|
||||
if (marginWidth > 0 || marginHeight > 0) {
|
||||
Color bg = getBackground();
|
||||
gc.setBackground(getTerminalBackgroundColor());
|
||||
if (marginWidth > 0) {
|
||||
gc.fillRectangle (width, clipping.y, marginWidth, clipping.height);
|
||||
gc.fillRectangle(width, clipping.y, marginWidth, clipping.height);
|
||||
}
|
||||
if (marginHeight > 0) {
|
||||
gc.fillRectangle (clipping.x, height, clipping.width, marginHeight);
|
||||
gc.fillRectangle(clipping.x, height, clipping.width, marginHeight);
|
||||
}
|
||||
gc.setBackground(bg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
protected boolean inClipping(Rectangle clipping, Rectangle r) {
|
||||
// TODO check if this is OK in all cases (the <=!)
|
||||
//
|
||||
if(r.x+r.width<=clipping.x)
|
||||
if (r.x + r.width <= clipping.x)
|
||||
return false;
|
||||
if(clipping.x+clipping.width<=r.x)
|
||||
if (clipping.x + clipping.width <= r.x)
|
||||
return false;
|
||||
if(r.y+r.height<=clipping.y)
|
||||
if (r.y + r.height <= clipping.y)
|
||||
return false;
|
||||
if(clipping.y+clipping.height<=r.y)
|
||||
if (clipping.y + clipping.height <= r.y)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the screen rect in virtual space (starting with (0,0))
|
||||
* of the visible screen. (x,y>=0)
|
||||
*/
|
||||
protected Rectangle getScreenRectInVirtualSpace() {
|
||||
Rectangle r= new Rectangle(fClientArea.x-fVirtualBounds.x,fClientArea.y-fVirtualBounds.y,fClientArea.width,fClientArea.height);
|
||||
Rectangle r = new Rectangle(fClientArea.x - fVirtualBounds.x, fClientArea.y - fVirtualBounds.y,
|
||||
fClientArea.width, fClientArea.height);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rect in virtual space (starting with (0,0))
|
||||
* of the visible screen. (x,y>=0)
|
||||
*/
|
||||
protected Rectangle getRectInVirtualSpace(Rectangle r) {
|
||||
return new Rectangle(r.x-fVirtualBounds.x,r.y-fVirtualBounds.y,r.width,r.height);
|
||||
return new Rectangle(r.x - fVirtualBounds.x, r.y - fVirtualBounds.y, r.width, r.height);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,11 +220,12 @@ public abstract class VirtualCanvas extends Canvas {
|
|||
* @param height height of the display area
|
||||
*/
|
||||
protected void setVirtualExtend(int width, int height) {
|
||||
fVirtualBounds.width=width;
|
||||
fVirtualBounds.height=height;
|
||||
fVirtualBounds.width = width;
|
||||
fVirtualBounds.height = height;
|
||||
updateScrollbars();
|
||||
updateViewRectangle();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the scrolling origin. Also sets the scrollbars.
|
||||
* Does NOT redraw!
|
||||
|
@ -227,54 +236,60 @@ public abstract class VirtualCanvas extends Canvas {
|
|||
*/
|
||||
protected void setVirtualOrigin(int x, int y) {
|
||||
if (fVirtualBounds.x != x || fVirtualBounds.y != y) {
|
||||
fVirtualBounds.x=x;
|
||||
fVirtualBounds.y=y;
|
||||
fVirtualBounds.x = x;
|
||||
fVirtualBounds.y = y;
|
||||
getHorizontalBar().setSelection(-x);
|
||||
getVerticalBar().setSelection(-y);
|
||||
updateViewRectangle();
|
||||
}
|
||||
}
|
||||
|
||||
protected Rectangle getVirtualBounds() {
|
||||
return cloneRectangle(fVirtualBounds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x
|
||||
* @return the virtual coordinate in screen space
|
||||
*/
|
||||
protected int virtualXtoScreen(int x) {
|
||||
return x+fVirtualBounds.x;
|
||||
return x + fVirtualBounds.x;
|
||||
}
|
||||
|
||||
protected int virtualYtoScreen(int y) {
|
||||
return y+fVirtualBounds.y;
|
||||
return y + fVirtualBounds.y;
|
||||
}
|
||||
|
||||
protected int screenXtoVirtual(int x) {
|
||||
return x-fVirtualBounds.x;
|
||||
return x - fVirtualBounds.x;
|
||||
}
|
||||
|
||||
protected int screenYtoVirtual(int y) {
|
||||
return y-fVirtualBounds.y;
|
||||
return y - fVirtualBounds.y;
|
||||
}
|
||||
|
||||
/** called when the viewed part is changing */
|
||||
private final Rectangle fViewRectangle=new Rectangle(0,0,0,0);
|
||||
private final Rectangle fViewRectangle = new Rectangle(0, 0, 0, 0);
|
||||
|
||||
protected void updateViewRectangle() {
|
||||
if(
|
||||
fViewRectangle.x==-fVirtualBounds.x
|
||||
&& fViewRectangle.y==-fVirtualBounds.y
|
||||
&& fViewRectangle.width==fClientArea.width
|
||||
&& fViewRectangle.height==fClientArea.height
|
||||
)
|
||||
if (fViewRectangle.x == -fVirtualBounds.x && fViewRectangle.y == -fVirtualBounds.y
|
||||
&& fViewRectangle.width == fClientArea.width && fViewRectangle.height == fClientArea.height)
|
||||
return;
|
||||
fViewRectangle.x=-fVirtualBounds.x;
|
||||
fViewRectangle.y=-fVirtualBounds.y;
|
||||
fViewRectangle.width=fClientArea.width;
|
||||
fViewRectangle.height=fClientArea.height;
|
||||
viewRectangleChanged(fViewRectangle.x,fViewRectangle.y,fViewRectangle.width,fViewRectangle.height);
|
||||
fViewRectangle.x = -fVirtualBounds.x;
|
||||
fViewRectangle.y = -fVirtualBounds.y;
|
||||
fViewRectangle.width = fClientArea.width;
|
||||
fViewRectangle.height = fClientArea.height;
|
||||
viewRectangleChanged(fViewRectangle.x, fViewRectangle.y, fViewRectangle.width, fViewRectangle.height);
|
||||
}
|
||||
|
||||
protected Rectangle getViewRectangle() {
|
||||
return cloneRectangle(fViewRectangle);
|
||||
}
|
||||
|
||||
private Rectangle cloneRectangle(Rectangle r) {
|
||||
return new Rectangle(r.x,r.y,r.width,r.height);
|
||||
return new Rectangle(r.x, r.y, r.width, r.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the viewed part has changed.
|
||||
* Override when you need this information....
|
||||
|
@ -286,63 +301,69 @@ public abstract class VirtualCanvas extends Canvas {
|
|||
*/
|
||||
protected void viewRectangleChanged(int x, int y, int width, int height) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
private void updateScrollbars() {
|
||||
// don't get into infinite loops....
|
||||
if(!fInUpdateScrollbars) {
|
||||
fInUpdateScrollbars=true;
|
||||
if (!fInUpdateScrollbars) {
|
||||
fInUpdateScrollbars = true;
|
||||
try {
|
||||
doUpdateScrollbar();
|
||||
} finally {
|
||||
fInUpdateScrollbars=false;
|
||||
fInUpdateScrollbars = false;
|
||||
}
|
||||
} else {
|
||||
if(!fInUpdateScrollbarsLogged) {
|
||||
fInUpdateScrollbarsLogged=true;
|
||||
TerminalPlugin.getDefault().getLog().log(new Status(IStatus.WARNING,
|
||||
TerminalPlugin.PLUGIN_ID, IStatus.OK, "Unexpected Recursion in terminal", //$NON-NLS-1$
|
||||
if (!fInUpdateScrollbarsLogged) {
|
||||
fInUpdateScrollbarsLogged = true;
|
||||
TerminalPlugin.getDefault().getLog()
|
||||
.log(new Status(IStatus.WARNING, TerminalPlugin.PLUGIN_ID, IStatus.OK,
|
||||
"Unexpected Recursion in terminal", //$NON-NLS-1$
|
||||
new RuntimeException()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doUpdateScrollbar() {
|
||||
Rectangle clientArea= getClientArea();
|
||||
ScrollBar horizontal= getHorizontalBar();
|
||||
Rectangle clientArea = getClientArea();
|
||||
ScrollBar horizontal = getHorizontalBar();
|
||||
// even if setVisible was called on the scrollbar, isVisible
|
||||
// returns false if its parent is not visible.
|
||||
if(!isVisible() || horizontal.isVisible()) {
|
||||
if (!isVisible() || horizontal.isVisible()) {
|
||||
horizontal.setPageIncrement(clientArea.width - horizontal.getIncrement());
|
||||
int max= fVirtualBounds.width;
|
||||
int max = fVirtualBounds.width;
|
||||
horizontal.setMaximum(max);
|
||||
horizontal.setThumb(clientArea.width);
|
||||
}
|
||||
ScrollBar vertical= getVerticalBar();
|
||||
ScrollBar vertical = getVerticalBar();
|
||||
// even if setVisible was called on the scrollbar, isVisible
|
||||
// returns false if its parent is not visible.
|
||||
if(!isVisible() || vertical.isVisible()) {
|
||||
if (!isVisible() || vertical.isVisible()) {
|
||||
vertical.setPageIncrement(clientArea.height - vertical.getIncrement());
|
||||
int max= fVirtualBounds.height;
|
||||
int max = fVirtualBounds.height;
|
||||
vertical.setMaximum(max);
|
||||
vertical.setThumb(clientArea.height);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isVertialBarVisible() {
|
||||
return getVerticalBar().isVisible();
|
||||
}
|
||||
|
||||
protected void serVerticalBarVisible(boolean showVScrollBar) {
|
||||
ScrollBar vertical= getVerticalBar();
|
||||
ScrollBar vertical = getVerticalBar();
|
||||
vertical.setVisible(showVScrollBar);
|
||||
vertical.setSelection(0);
|
||||
}
|
||||
|
||||
protected boolean isHorizontalBarVisble() {
|
||||
return getHorizontalBar().isVisible();
|
||||
}
|
||||
|
||||
protected void setHorizontalBarVisible(boolean showHScrollBar) {
|
||||
ScrollBar horizontal= getHorizontalBar();
|
||||
ScrollBar horizontal = getHorizontalBar();
|
||||
horizontal.setVisible(showHScrollBar);
|
||||
horizontal.setSelection(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ public interface ITerminalTextData extends ITerminalTextDataReadOnly {
|
|||
void setDimensions(int height, int width);
|
||||
|
||||
void setMaxHeight(int height);
|
||||
|
||||
int getMaxHeight();
|
||||
|
||||
/**
|
||||
|
@ -68,7 +69,6 @@ public interface ITerminalTextData extends ITerminalTextDataReadOnly {
|
|||
*/
|
||||
void setChars(int line, int column, char[] chars, int start, int len, Style style);
|
||||
|
||||
|
||||
/**
|
||||
* Cleans the entire line.
|
||||
* @param line
|
||||
|
@ -116,18 +116,21 @@ public interface ITerminalTextData extends ITerminalTextDataReadOnly {
|
|||
* will be scrolled. Else a line will be added.
|
||||
*/
|
||||
void addLine();
|
||||
|
||||
/**
|
||||
* Copies the entire source into this and changes the size accordingly
|
||||
* @param source
|
||||
*/
|
||||
void copy(ITerminalTextData source);
|
||||
|
||||
/**
|
||||
* Copy a sourceLine from source to this at destLine.
|
||||
* @param source
|
||||
* @param sourceLine
|
||||
* @param destLine
|
||||
*/
|
||||
void copyLine(ITerminalTextData source,int sourceLine, int destLine);
|
||||
void copyLine(ITerminalTextData source, int sourceLine, int destLine);
|
||||
|
||||
/**
|
||||
* Copy <code>length</code> lines from source starting at sourceLine into this starting at
|
||||
* destLine.
|
||||
|
@ -136,9 +139,10 @@ public interface ITerminalTextData extends ITerminalTextDataReadOnly {
|
|||
* @param destStartLine
|
||||
* @param length
|
||||
*/
|
||||
void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine,int length);
|
||||
void copyRange(ITerminalTextData source, int sourceStartLine, int destStartLine, int length);
|
||||
|
||||
void setCursorLine(int line);
|
||||
|
||||
void setCursorColumn(int column);
|
||||
|
||||
/**
|
||||
|
|
|
@ -66,12 +66,14 @@ public interface ITerminalTextDataReadOnly {
|
|||
public ITerminalTextDataSnapshot makeSnapshot();
|
||||
|
||||
char[] getChars(int line);
|
||||
|
||||
Style[] getStyles(int line);
|
||||
|
||||
/**
|
||||
* @return the line in which the cursor is at the moment
|
||||
*/
|
||||
int getCursorLine();
|
||||
|
||||
/**
|
||||
* @return the column at which the cursor is at the moment
|
||||
*/
|
||||
|
|
|
@ -108,7 +108,9 @@ public interface ITerminalTextDataSnapshot extends ITerminalTextDataReadOnly {
|
|||
*/
|
||||
void snapshotOutOfDate(ITerminalTextDataSnapshot snapshot);
|
||||
}
|
||||
|
||||
void addListener(SnapshotOutOfDateListener listener);
|
||||
|
||||
void removeListener(SnapshotOutOfDateListener listener);
|
||||
|
||||
/**
|
||||
|
@ -116,6 +118,7 @@ public interface ITerminalTextDataSnapshot extends ITerminalTextDataReadOnly {
|
|||
* has been called no new snapshot data is collected.
|
||||
*/
|
||||
void detach();
|
||||
|
||||
/**
|
||||
* @return true if the data has changed since the previous snapshot.
|
||||
*/
|
||||
|
@ -129,7 +132,9 @@ public interface ITerminalTextDataSnapshot extends ITerminalTextDataReadOnly {
|
|||
* @param size number of lines to track. A size of -1 means track all.
|
||||
*/
|
||||
void setInterestWindow(int startLine, int size);
|
||||
|
||||
int getInterestWindowStartLine();
|
||||
|
||||
int getInterestWindowSize();
|
||||
|
||||
/**
|
||||
|
@ -195,6 +200,7 @@ public interface ITerminalTextDataSnapshot extends ITerminalTextDataReadOnly {
|
|||
* window of interest)
|
||||
*/
|
||||
boolean hasTerminalChanged();
|
||||
|
||||
/**
|
||||
* If {@link #updateSnapshot(boolean)} was called with <code>true</code>, then this method
|
||||
* returns the top of the scroll region.
|
||||
|
|
|
@ -10,26 +10,30 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.terminal.model;
|
||||
|
||||
|
||||
public class LineSegment {
|
||||
private final String fText;
|
||||
private final int fCol;
|
||||
private final Style fStyle;
|
||||
|
||||
public LineSegment(int col, String text, Style style) {
|
||||
fCol = col;
|
||||
fText = text;
|
||||
fStyle = style;
|
||||
}
|
||||
|
||||
public Style getStyle() {
|
||||
return fStyle;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return fText;
|
||||
}
|
||||
|
||||
public int getColumn() {
|
||||
return fCol;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "LineSegment("+fCol+", \""+fText+"\","+fStyle+")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
return "LineSegment(" + fCol + ", \"" + fText + "\"," + fStyle + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
}
|
||||
}
|
|
@ -28,8 +28,10 @@ public class Style {
|
|||
private final boolean fBlink;
|
||||
private final boolean fUnderline;
|
||||
private final boolean fReverse;
|
||||
private final static Map<Style, Style> fgStyles=new HashMap<Style, Style>();
|
||||
private Style(StyleColor forground, StyleColor background, boolean bold, boolean blink, boolean underline, boolean reverse) {
|
||||
private final static Map<Style, Style> fgStyles = new HashMap<Style, Style>();
|
||||
|
||||
private Style(StyleColor forground, StyleColor background, boolean bold, boolean blink, boolean underline,
|
||||
boolean reverse) {
|
||||
fForground = forground;
|
||||
fBackground = background;
|
||||
fBold = bold;
|
||||
|
@ -37,66 +39,86 @@ public class Style {
|
|||
fUnderline = underline;
|
||||
fReverse = reverse;
|
||||
}
|
||||
public static Style getStyle(StyleColor forground, StyleColor background, boolean bold, boolean blink, boolean underline, boolean reverse) {
|
||||
Style style = new Style(forground,background, bold, blink,underline,reverse);
|
||||
|
||||
public static Style getStyle(StyleColor forground, StyleColor background, boolean bold, boolean blink,
|
||||
boolean underline, boolean reverse) {
|
||||
Style style = new Style(forground, background, bold, blink, underline, reverse);
|
||||
Style cached;
|
||||
synchronized (fgStyles) {
|
||||
cached=fgStyles.get(style);
|
||||
if(cached==null) {
|
||||
cached=style;
|
||||
cached = fgStyles.get(style);
|
||||
if (cached == null) {
|
||||
cached = style;
|
||||
fgStyles.put(cached, cached);
|
||||
}
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
public static Style getStyle(String forground, String background) {
|
||||
return getStyle(StyleColor.getStyleColor(forground), StyleColor.getStyleColor(background),false,false,false,false);
|
||||
return getStyle(StyleColor.getStyleColor(forground), StyleColor.getStyleColor(background), false, false, false,
|
||||
false);
|
||||
}
|
||||
|
||||
public static Style getStyle(StyleColor forground, StyleColor background) {
|
||||
return getStyle(forground, background,false,false,false,false);
|
||||
return getStyle(forground, background, false, false, false, false);
|
||||
}
|
||||
|
||||
public Style setForground(StyleColor forground) {
|
||||
return getStyle(forground,fBackground,fBold,fBlink,fUnderline,fReverse);
|
||||
return getStyle(forground, fBackground, fBold, fBlink, fUnderline, fReverse);
|
||||
}
|
||||
|
||||
public Style setBackground(StyleColor background) {
|
||||
return getStyle(fForground,background,fBold,fBlink,fUnderline,fReverse);
|
||||
return getStyle(fForground, background, fBold, fBlink, fUnderline, fReverse);
|
||||
}
|
||||
|
||||
public Style setForground(String colorName) {
|
||||
return getStyle(StyleColor.getStyleColor(colorName),fBackground,fBold,fBlink,fUnderline,fReverse);
|
||||
return getStyle(StyleColor.getStyleColor(colorName), fBackground, fBold, fBlink, fUnderline, fReverse);
|
||||
}
|
||||
|
||||
public Style setBackground(String colorName) {
|
||||
return getStyle(fForground,StyleColor.getStyleColor(colorName),fBold,fBlink,fUnderline,fReverse);
|
||||
return getStyle(fForground, StyleColor.getStyleColor(colorName), fBold, fBlink, fUnderline, fReverse);
|
||||
}
|
||||
|
||||
public Style setBold(boolean bold) {
|
||||
return getStyle(fForground,fBackground,bold,fBlink,fUnderline,fReverse);
|
||||
return getStyle(fForground, fBackground, bold, fBlink, fUnderline, fReverse);
|
||||
}
|
||||
|
||||
public Style setBlink(boolean blink) {
|
||||
return getStyle(fForground,fBackground,fBold,blink,fUnderline,fReverse);
|
||||
return getStyle(fForground, fBackground, fBold, blink, fUnderline, fReverse);
|
||||
}
|
||||
|
||||
public Style setUnderline(boolean underline) {
|
||||
return getStyle(fForground,fBackground,fBold,fBlink,underline,fReverse);
|
||||
return getStyle(fForground, fBackground, fBold, fBlink, underline, fReverse);
|
||||
}
|
||||
|
||||
public Style setReverse(boolean reverse) {
|
||||
return getStyle(fForground,fBackground,fBold,fBlink,fUnderline,reverse);
|
||||
return getStyle(fForground, fBackground, fBold, fBlink, fUnderline, reverse);
|
||||
}
|
||||
|
||||
public StyleColor getBackground() {
|
||||
return fBackground;
|
||||
}
|
||||
|
||||
public boolean isBlink() {
|
||||
return fBlink;
|
||||
}
|
||||
|
||||
public boolean isBold() {
|
||||
return fBold;
|
||||
}
|
||||
|
||||
public StyleColor getForground() {
|
||||
return fForground;
|
||||
}
|
||||
|
||||
public boolean isReverse() {
|
||||
return fReverse;
|
||||
}
|
||||
|
||||
public boolean isUnderline() {
|
||||
return fUnderline;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
|
@ -108,6 +130,7 @@ public class Style {
|
|||
result = prime * result + (fUnderline ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
@ -131,21 +154,22 @@ public class Style {
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer result=new StringBuffer();
|
||||
StringBuffer result = new StringBuffer();
|
||||
result.append("Style(foreground="); //$NON-NLS-1$
|
||||
result.append(fForground);
|
||||
result.append(", background="); //$NON-NLS-1$
|
||||
result.append(fBackground);
|
||||
if(fBlink)
|
||||
if (fBlink)
|
||||
result.append(", blink"); //$NON-NLS-1$
|
||||
if(fBold)
|
||||
if (fBold)
|
||||
result.append(", bold"); //$NON-NLS-1$
|
||||
if(fBlink)
|
||||
if (fBlink)
|
||||
result.append(", blink"); //$NON-NLS-1$
|
||||
if(fReverse)
|
||||
if (fReverse)
|
||||
result.append(", reverse"); //$NON-NLS-1$
|
||||
if(fUnderline)
|
||||
if (fUnderline)
|
||||
result.append(", underline"); //$NON-NLS-1$
|
||||
result.append(")"); //$NON-NLS-1$
|
||||
return result.toString();
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.util.Map;
|
|||
* Threadsafe.
|
||||
*/
|
||||
public class StyleColor {
|
||||
private final static Map<String, StyleColor> fgStyleColors=new HashMap<String, StyleColor>();
|
||||
private final static Map<String, StyleColor> fgStyleColors = new HashMap<String, StyleColor>();
|
||||
final String fName;
|
||||
|
||||
/**
|
||||
|
@ -30,14 +30,15 @@ public class StyleColor {
|
|||
public static StyleColor getStyleColor(String name) {
|
||||
StyleColor result;
|
||||
synchronized (fgStyleColors) {
|
||||
result=fgStyleColors.get(name);
|
||||
if(result==null) {
|
||||
result=new StyleColor(name);
|
||||
result = fgStyleColors.get(name);
|
||||
if (result == null) {
|
||||
result = new StyleColor(name);
|
||||
fgStyleColors.put(name, result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// nobody except the factory method is allowed to instantiate this class!
|
||||
private StyleColor(String name) {
|
||||
fName = name;
|
||||
|
|
|
@ -43,6 +43,7 @@ public class TerminalConnectorFactoryTest extends TestCase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public static class TerminalControlMock implements ITerminalControl {
|
||||
|
||||
public void setEncoding(String encoding) {
|
||||
|
@ -93,6 +94,7 @@ public class TerminalConnectorFactoryTest extends TestCase {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static class ConnectorMock extends TerminalConnectorImpl {
|
||||
|
||||
public boolean fEcho;
|
||||
|
@ -106,16 +108,19 @@ public class TerminalConnectorFactoryTest extends TestCase {
|
|||
public boolean isLocalEcho() {
|
||||
return fEcho;
|
||||
}
|
||||
|
||||
public void setTerminalSize(int newWidth, int newHeight) {
|
||||
fWidth=newWidth;
|
||||
fHeight=newHeight;
|
||||
fWidth = newWidth;
|
||||
fHeight = newHeight;
|
||||
}
|
||||
|
||||
public void connect(ITerminalControl control) {
|
||||
super.connect(control);
|
||||
fTerminalControl = control;
|
||||
}
|
||||
|
||||
public void doDisconnect() {
|
||||
fDisconnect=true;
|
||||
fDisconnect = true;
|
||||
}
|
||||
|
||||
public OutputStream getTerminalToRemoteStream() {
|
||||
|
@ -127,48 +132,50 @@ public class TerminalConnectorFactoryTest extends TestCase {
|
|||
}
|
||||
|
||||
public void load(ISettingsStore store) {
|
||||
fLoadStore=store;
|
||||
fLoadStore = store;
|
||||
}
|
||||
|
||||
public void save(ISettingsStore store) {
|
||||
fSaveStore=store;
|
||||
fSaveStore = store;
|
||||
}
|
||||
}
|
||||
|
||||
protected TerminalConnector makeTerminalConnector() {
|
||||
return makeTerminalConnector(new ConnectorMock());
|
||||
}
|
||||
|
||||
protected TerminalConnector makeTerminalConnector(final TerminalConnectorImpl mock) {
|
||||
TerminalConnector c=new TerminalConnector(new TerminalConnector.Factory(){
|
||||
TerminalConnector c = new TerminalConnector(new TerminalConnector.Factory() {
|
||||
public TerminalConnectorImpl makeConnector() throws Exception {
|
||||
return mock;
|
||||
}
|
||||
},"xID","xName", false);
|
||||
}, "xID", "xName", false);
|
||||
return c;
|
||||
}
|
||||
|
||||
public void testGetInitializationErrorMessage() {
|
||||
TerminalConnector c=makeTerminalConnector();
|
||||
TerminalConnector c = makeTerminalConnector();
|
||||
c.connect(new TerminalControlMock());
|
||||
assertNull(c.getInitializationErrorMessage());
|
||||
|
||||
c=makeTerminalConnector(new ConnectorMock(){
|
||||
c = makeTerminalConnector(new ConnectorMock() {
|
||||
public void initialize() throws Exception {
|
||||
throw new Exception("FAILED");
|
||||
}});
|
||||
}
|
||||
});
|
||||
c.connect(new TerminalControlMock());
|
||||
assertEquals("FAILED",c.getInitializationErrorMessage());
|
||||
assertEquals("FAILED", c.getInitializationErrorMessage());
|
||||
|
||||
}
|
||||
|
||||
public void testGetIdAndName() {
|
||||
TerminalConnector c=makeTerminalConnector();
|
||||
TerminalConnector c = makeTerminalConnector();
|
||||
assertEquals("xID", c.getId());
|
||||
assertEquals("xName", c.getName());
|
||||
}
|
||||
|
||||
public void testIsInitialized() {
|
||||
TerminalConnector c=makeTerminalConnector();
|
||||
TerminalConnector c = makeTerminalConnector();
|
||||
assertFalse(c.isInitialized());
|
||||
c.getId();
|
||||
assertFalse(c.isInitialized());
|
||||
|
@ -176,19 +183,20 @@ public class TerminalConnectorFactoryTest extends TestCase {
|
|||
assertFalse(c.isInitialized());
|
||||
c.getSettingsSummary();
|
||||
assertFalse(c.isInitialized());
|
||||
c.setTerminalSize(10,10);
|
||||
c.setTerminalSize(10, 10);
|
||||
assertFalse(c.isInitialized());
|
||||
c.load(null);
|
||||
assertFalse(c.isInitialized());
|
||||
c.save(null);
|
||||
assertFalse(c.isInitialized());
|
||||
if (!Platform.isRunning()) return;
|
||||
if (!Platform.isRunning())
|
||||
return;
|
||||
c.getAdapter(ConnectorMock.class);
|
||||
assertFalse(c.isInitialized());
|
||||
}
|
||||
|
||||
public void testConnect() {
|
||||
TerminalConnector c=makeTerminalConnector();
|
||||
TerminalConnector c = makeTerminalConnector();
|
||||
assertFalse(c.isInitialized());
|
||||
c.connect(new TerminalControlMock());
|
||||
assertTrue(c.isInitialized());
|
||||
|
@ -196,74 +204,76 @@ public class TerminalConnectorFactoryTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testDisconnect() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = makeTerminalConnector(mock);
|
||||
TerminalControlMock control=new TerminalControlMock();
|
||||
TerminalControlMock control = new TerminalControlMock();
|
||||
c.connect(control);
|
||||
c.disconnect();
|
||||
assertTrue(mock.fDisconnect);
|
||||
}
|
||||
|
||||
public void testGetTerminalToRemoteStream() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = makeTerminalConnector(mock);
|
||||
TerminalControlMock control=new TerminalControlMock();
|
||||
TerminalControlMock control = new TerminalControlMock();
|
||||
c.connect(control);
|
||||
assertSame(mock.fTerminalControl,control);
|
||||
assertSame(mock.fTerminalControl, control);
|
||||
}
|
||||
|
||||
public void testGetSettingsSummary() {
|
||||
TerminalConnector c=makeTerminalConnector();
|
||||
TerminalConnector c = makeTerminalConnector();
|
||||
assertEquals("Not Initialized", c.getSettingsSummary());
|
||||
c.connect(new TerminalControlMock());
|
||||
assertEquals("Summary", c.getSettingsSummary());
|
||||
}
|
||||
|
||||
public void testIsLocalEcho() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = makeTerminalConnector(mock);
|
||||
assertFalse(c.isLocalEcho());
|
||||
mock.fEcho=true;
|
||||
mock.fEcho = true;
|
||||
assertTrue(c.isLocalEcho());
|
||||
}
|
||||
|
||||
public void testLoad() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = makeTerminalConnector(mock);
|
||||
ISettingsStore s=new SettingsMock();
|
||||
ISettingsStore s = new SettingsMock();
|
||||
c.load(s);
|
||||
// the load is called after the connect...
|
||||
assertNull(mock.fLoadStore);
|
||||
c.connect(new TerminalControlMock());
|
||||
assertSame(s,mock.fLoadStore);
|
||||
assertSame(s, mock.fLoadStore);
|
||||
}
|
||||
|
||||
public void testSave() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = makeTerminalConnector(mock);
|
||||
ISettingsStore s=new SettingsMock();
|
||||
ISettingsStore s = new SettingsMock();
|
||||
c.save(s);
|
||||
assertNull(mock.fSaveStore);
|
||||
c.connect(new TerminalControlMock());
|
||||
c.save(s);
|
||||
assertSame(s,mock.fSaveStore);
|
||||
assertSame(s, mock.fSaveStore);
|
||||
}
|
||||
|
||||
public void testSetDefaultSettings() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = makeTerminalConnector(mock);
|
||||
c.setDefaultSettings();
|
||||
}
|
||||
|
||||
public void testSetTerminalSize() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = makeTerminalConnector(mock);
|
||||
c.setTerminalSize(100, 200);
|
||||
|
||||
}
|
||||
|
||||
public void testGetAdapter() {
|
||||
if (!Platform.isRunning()) return;
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
if (!Platform.isRunning())
|
||||
return;
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = makeTerminalConnector(mock);
|
||||
assertNull(c.getAdapter(ConnectorMock.class));
|
||||
// the load is called after the connect...
|
||||
|
|
|
@ -43,6 +43,7 @@ public class TerminalConnectorTest extends TestCase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public static class TerminalControlMock implements ITerminalControl {
|
||||
|
||||
public void setEncoding(String encoding) {
|
||||
|
@ -93,6 +94,7 @@ public class TerminalConnectorTest extends TestCase {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static class ConnectorMock extends TerminalConnectorImpl {
|
||||
|
||||
public boolean fEcho;
|
||||
|
@ -106,16 +108,19 @@ public class TerminalConnectorTest extends TestCase {
|
|||
public boolean isLocalEcho() {
|
||||
return fEcho;
|
||||
}
|
||||
|
||||
public void setTerminalSize(int newWidth, int newHeight) {
|
||||
fWidth=newWidth;
|
||||
fHeight=newHeight;
|
||||
fWidth = newWidth;
|
||||
fHeight = newHeight;
|
||||
}
|
||||
|
||||
public void connect(ITerminalControl control) {
|
||||
super.connect(control);
|
||||
fTerminalControl = control;
|
||||
}
|
||||
|
||||
public void doDisconnect() {
|
||||
fDisconnect=true;
|
||||
fDisconnect = true;
|
||||
}
|
||||
|
||||
public OutputStream getTerminalToRemoteStream() {
|
||||
|
@ -127,45 +132,50 @@ public class TerminalConnectorTest extends TestCase {
|
|||
}
|
||||
|
||||
public void load(ISettingsStore store) {
|
||||
fLoadStore=store;
|
||||
fLoadStore = store;
|
||||
}
|
||||
|
||||
public void save(ISettingsStore store) {
|
||||
fSaveStore=store;
|
||||
fSaveStore = store;
|
||||
}
|
||||
}
|
||||
|
||||
static class SimpleFactory implements Factory {
|
||||
final TerminalConnectorImpl fConnector;
|
||||
|
||||
public SimpleFactory(TerminalConnectorImpl connector) {
|
||||
fConnector = connector;
|
||||
}
|
||||
|
||||
public TerminalConnectorImpl makeConnector() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
return fConnector;
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetInitializationErrorMessage() {
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName", false);
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(new ConnectorMock()), "xID", "xName", false);
|
||||
c.connect(new TerminalControlMock());
|
||||
assertNull(c.getInitializationErrorMessage());
|
||||
|
||||
c=new TerminalConnector(new SimpleFactory(new ConnectorMock(){
|
||||
c = new TerminalConnector(new SimpleFactory(new ConnectorMock() {
|
||||
public void initialize() throws Exception {
|
||||
throw new Exception("FAILED");
|
||||
}}),"xID","xName", false);
|
||||
}
|
||||
}), "xID", "xName", false);
|
||||
c.connect(new TerminalControlMock());
|
||||
assertEquals("FAILED",c.getInitializationErrorMessage());
|
||||
assertEquals("FAILED", c.getInitializationErrorMessage());
|
||||
|
||||
}
|
||||
|
||||
public void testGetIdAndName() {
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName", false);
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(new ConnectorMock()), "xID", "xName", false);
|
||||
assertEquals("xID", c.getId());
|
||||
assertEquals("xName", c.getName());
|
||||
}
|
||||
|
||||
public void testConnect() {
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName", false);
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(new ConnectorMock()), "xID", "xName", false);
|
||||
assertFalse(c.isInitialized());
|
||||
c.connect(new TerminalControlMock());
|
||||
assertTrue(c.isInitialized());
|
||||
|
@ -173,68 +183,68 @@ public class TerminalConnectorTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testDisconnect() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false);
|
||||
TerminalControlMock control=new TerminalControlMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false);
|
||||
TerminalControlMock control = new TerminalControlMock();
|
||||
c.connect(control);
|
||||
c.disconnect();
|
||||
assertTrue(mock.fDisconnect);
|
||||
}
|
||||
|
||||
public void testGetTerminalToRemoteStream() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false);
|
||||
TerminalControlMock control=new TerminalControlMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false);
|
||||
TerminalControlMock control = new TerminalControlMock();
|
||||
c.connect(control);
|
||||
assertSame(mock.fTerminalControl,control);
|
||||
assertSame(mock.fTerminalControl, control);
|
||||
}
|
||||
|
||||
public void testGetSettingsSummary() {
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName", false);
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(new ConnectorMock()), "xID", "xName", false);
|
||||
assertEquals("Not Initialized", c.getSettingsSummary());
|
||||
c.connect(new TerminalControlMock());
|
||||
assertEquals("Summary", c.getSettingsSummary());
|
||||
}
|
||||
|
||||
public void testIsLocalEcho() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false);
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false);
|
||||
assertFalse(c.isLocalEcho());
|
||||
mock.fEcho=true;
|
||||
mock.fEcho = true;
|
||||
assertTrue(c.isLocalEcho());
|
||||
}
|
||||
|
||||
public void testLoad() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false);
|
||||
ISettingsStore s=new SettingsMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false);
|
||||
ISettingsStore s = new SettingsMock();
|
||||
c.load(s);
|
||||
// the load is called after the connect...
|
||||
assertNull(mock.fLoadStore);
|
||||
c.connect(new TerminalControlMock());
|
||||
assertSame(s,mock.fLoadStore);
|
||||
assertSame(s, mock.fLoadStore);
|
||||
}
|
||||
|
||||
public void testSave() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false);
|
||||
ISettingsStore s=new SettingsMock();
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false);
|
||||
ISettingsStore s = new SettingsMock();
|
||||
c.save(s);
|
||||
assertNull(mock.fSaveStore);
|
||||
c.connect(new TerminalControlMock());
|
||||
c.save(s);
|
||||
assertSame(s,mock.fSaveStore);
|
||||
assertSame(s, mock.fSaveStore);
|
||||
}
|
||||
|
||||
public void testSetDefaultSettings() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false);
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false);
|
||||
c.setDefaultSettings();
|
||||
}
|
||||
|
||||
public void testSetTerminalSize() {
|
||||
ConnectorMock mock=new ConnectorMock();
|
||||
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName", false);
|
||||
ConnectorMock mock = new ConnectorMock();
|
||||
TerminalConnector c = new TerminalConnector(new SimpleFactory(mock), "xID", "xName", false);
|
||||
c.setTerminalSize(100, 200);
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@ import java.io.UnsupportedEncodingException;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
public class TerminalToRemoteInjectionOutputStreamTest extends TestCase {
|
||||
final static String ENCODING="UTF-8";
|
||||
final static String ENCODING = "UTF-8";
|
||||
|
||||
/**
|
||||
* This class escapes strings coming on the original
|
||||
* terminal..
|
||||
|
@ -30,26 +31,30 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase {
|
|||
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
fOriginal.write('[');
|
||||
fOriginal.write(b);
|
||||
fOriginal.write(']');
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
fOriginal.write('[');
|
||||
fOriginal.write(b,off,len);
|
||||
fOriginal.write(b, off, len);
|
||||
fOriginal.write(']');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class NullInterceptor extends TerminalToRemoteInjectionOutputStream.Interceptor {
|
||||
}
|
||||
|
||||
public void testClose() throws UnsupportedEncodingException, IOException {
|
||||
ByteArrayOutputStream bs=new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s= new TerminalToRemoteInjectionOutputStream(bs);
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs);
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(),ENCODING));
|
||||
OutputStream os1=s.grabOutput();
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
OutputStream os1 = s.grabOutput();
|
||||
os1.write('x');
|
||||
s.write('A');
|
||||
os1.write('y');
|
||||
|
@ -57,7 +62,7 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase {
|
|||
os1.close();
|
||||
|
||||
s.write('-');
|
||||
OutputStream os=s.grabOutput();
|
||||
OutputStream os = s.grabOutput();
|
||||
// make sure the closed output does not inject anything
|
||||
try {
|
||||
os1.write('k');
|
||||
|
@ -75,24 +80,24 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase {
|
|||
}
|
||||
s.write('b');
|
||||
os.close();
|
||||
assertEquals("begin:xyAB-XYab", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:xyAB-XYab", new String(bs.toByteArray(), ENCODING));
|
||||
}
|
||||
|
||||
public void testFlush() {
|
||||
}
|
||||
|
||||
public void testWriteInt() throws UnsupportedEncodingException, IOException {
|
||||
ByteArrayOutputStream bs=new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s= new TerminalToRemoteInjectionOutputStream(bs);
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs);
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(),ENCODING));
|
||||
OutputStream os=s.grabOutput();
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
OutputStream os = s.grabOutput();
|
||||
os.write('x');
|
||||
s.write('A');
|
||||
os.write('y');
|
||||
s.write('B');
|
||||
s.close();
|
||||
assertEquals("begin:xyAB", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:xyAB", new String(bs.toByteArray(), ENCODING));
|
||||
|
||||
}
|
||||
|
||||
|
@ -101,76 +106,79 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase {
|
|||
|
||||
public void testWriteByteArrayIntInt() {
|
||||
}
|
||||
|
||||
public void testGrabOutput() throws UnsupportedEncodingException, IOException {
|
||||
ByteArrayOutputStream bs=new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s= new TerminalToRemoteInjectionOutputStream(bs);
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs);
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(),ENCODING));
|
||||
OutputStream os1=s.grabOutput();
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
OutputStream os1 = s.grabOutput();
|
||||
OutputStream os2;
|
||||
try {
|
||||
os2=s.grabOutput();
|
||||
os2 = s.grabOutput();
|
||||
fail("should fail until the foirst output is closed");
|
||||
} catch (IOException e) {
|
||||
}
|
||||
os1.close();
|
||||
os2=s.grabOutput();
|
||||
assertEquals("begin:", new String(bs.toByteArray(),ENCODING));
|
||||
os2 = s.grabOutput();
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
os2.write("Test".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
s.write(" west".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
os2.write(" the".getBytes(ENCODING));
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
os2.close();
|
||||
assertEquals("begin:Test the west", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test the west", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('!');
|
||||
assertEquals("begin:Test the west!", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test the west!", new String(bs.toByteArray(), ENCODING));
|
||||
|
||||
}
|
||||
|
||||
public void testGrabOutputWithCleverInterceptor() throws UnsupportedEncodingException, IOException {
|
||||
ByteArrayOutputStream bs=new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s= new TerminalToRemoteInjectionOutputStream(bs);
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs);
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
// the injector escapes the output coming from the main stream
|
||||
OutputStream os=s.grabOutput(new CleverInterceptor());
|
||||
assertEquals("begin:", new String(bs.toByteArray(),ENCODING));
|
||||
OutputStream os = s.grabOutput(new CleverInterceptor());
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
os.write("Test".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
s.write(" west".getBytes(ENCODING));
|
||||
assertEquals("begin:Test[ west]", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test[ west]", new String(bs.toByteArray(), ENCODING));
|
||||
os.write(" the".getBytes(ENCODING));
|
||||
assertEquals("begin:Test[ west] the", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test[ west] the", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('x');
|
||||
assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(), ENCODING));
|
||||
os.close();
|
||||
assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('!');
|
||||
assertEquals("begin:Test[ west] the[x]!", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test[ west] the[x]!", new String(bs.toByteArray(), ENCODING));
|
||||
|
||||
}
|
||||
|
||||
public void testGrabOutputWithNullInterceptor() throws UnsupportedEncodingException, IOException {
|
||||
ByteArrayOutputStream bs=new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s= new TerminalToRemoteInjectionOutputStream(bs);
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs);
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
// bytes written to the main stream are ignored while the injector
|
||||
// is active
|
||||
OutputStream os=s.grabOutput(new NullInterceptor());
|
||||
assertEquals("begin:", new String(bs.toByteArray(),ENCODING));
|
||||
OutputStream os = s.grabOutput(new NullInterceptor());
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
os.write("Test".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
s.write(" west".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
os.write(" the".getBytes(ENCODING));
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('x');
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
os.close();
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('!');
|
||||
assertEquals("begin:Test the!", new String(bs.toByteArray(),ENCODING));
|
||||
assertEquals("begin:Test the!", new String(bs.toByteArray(), ENCODING));
|
||||
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -22,9 +22,9 @@ public class SnapshotChangesTest extends TestCase {
|
|||
* @param expected a string of 0 and 1 (1 means changed)
|
||||
*/
|
||||
void assertChangedLines(ISnapshotChanges change, String expected) {
|
||||
StringBuffer buffer=new StringBuffer();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (int line = 0; line < expected.length(); line++) {
|
||||
if(change.hasLineChanged(line))
|
||||
if (change.hasLineChanged(line))
|
||||
buffer.append('1');
|
||||
else
|
||||
buffer.append('0');
|
||||
|
@ -33,18 +33,19 @@ public class SnapshotChangesTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testSnapshotChanges() {
|
||||
SnapshotChanges changes=new SnapshotChanges(1);
|
||||
SnapshotChanges changes = new SnapshotChanges(1);
|
||||
assertEquals(0, changes.getInterestWindowStartLine());
|
||||
assertEquals(0, changes.getInterestWindowSize());
|
||||
}
|
||||
|
||||
public void testSnapshotChangesWithWindow() {
|
||||
SnapshotChanges changes=new SnapshotChanges(2,5);
|
||||
SnapshotChanges changes = new SnapshotChanges(2, 5);
|
||||
assertEquals(2, changes.getInterestWindowStartLine());
|
||||
assertEquals(5, changes.getInterestWindowSize());
|
||||
}
|
||||
|
||||
public void testIsInInterestWindowIntInt() {
|
||||
SnapshotChanges changes=new SnapshotChanges(2,5);
|
||||
SnapshotChanges changes = new SnapshotChanges(2, 5);
|
||||
assertFalse(changes.isInInterestWindow(0, 1));
|
||||
assertFalse(changes.isInInterestWindow(0, 2));
|
||||
assertTrue(changes.isInInterestWindow(0, 3));
|
||||
|
@ -60,17 +61,18 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertFalse(changes.isInInterestWindow(7, 1));
|
||||
assertFalse(changes.isInInterestWindow(8, 10));
|
||||
}
|
||||
|
||||
public void testIsInInterestWindowIntIntNoWindow() {
|
||||
SnapshotChanges changes=new SnapshotChanges(3);
|
||||
SnapshotChanges changes = new SnapshotChanges(3);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
assertTrue(changes.isInInterestWindow(i,j));
|
||||
assertTrue(changes.isInInterestWindow(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsInInterestWindowInt() {
|
||||
SnapshotChanges changes=new SnapshotChanges(3,1);
|
||||
SnapshotChanges changes = new SnapshotChanges(3, 1);
|
||||
assertFalse(changes.isInInterestWindow(0));
|
||||
assertFalse(changes.isInInterestWindow(1));
|
||||
assertFalse(changes.isInInterestWindow(2));
|
||||
|
@ -80,14 +82,14 @@ public class SnapshotChangesTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testIsInInterestWindowIntNoWindow() {
|
||||
SnapshotChanges changes=new SnapshotChanges(3);
|
||||
SnapshotChanges changes = new SnapshotChanges(3);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertTrue(changes.isInInterestWindow(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void testFitLineToWindow() {
|
||||
SnapshotChanges changes=new SnapshotChanges(2,5);
|
||||
SnapshotChanges changes = new SnapshotChanges(2, 5);
|
||||
assertEquals(2, changes.fitLineToWindow(0));
|
||||
assertEquals(2, changes.fitLineToWindow(1));
|
||||
assertEquals(2, changes.fitLineToWindow(2));
|
||||
|
@ -112,7 +114,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testFitLineToWindowNoWindow() {
|
||||
SnapshotChanges changes=new SnapshotChanges(5);
|
||||
SnapshotChanges changes = new SnapshotChanges(5);
|
||||
assertEquals(0, changes.fitLineToWindow(0));
|
||||
assertEquals(1, changes.fitLineToWindow(1));
|
||||
assertEquals(2, changes.fitLineToWindow(2));
|
||||
|
@ -122,49 +124,51 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertEquals(6, changes.fitLineToWindow(6));
|
||||
assertEquals(7, changes.fitLineToWindow(7));
|
||||
}
|
||||
|
||||
public void testFitSizeToWindow() {
|
||||
SnapshotChanges changes=new SnapshotChanges(2,3);
|
||||
SnapshotChanges changes = new SnapshotChanges(2, 3);
|
||||
assertFalse(changes.isInInterestWindow(0, 1));
|
||||
assertFalse(changes.isInInterestWindow(0, 2));
|
||||
assertTrue(changes.isInInterestWindow(0, 3));
|
||||
assertEquals(1, changes.fitSizeToWindow(0,3));
|
||||
assertEquals(2, changes.fitSizeToWindow(0,4));
|
||||
assertEquals(3, changes.fitSizeToWindow(0,5));
|
||||
assertEquals(3, changes.fitSizeToWindow(0,6));
|
||||
assertEquals(3, changes.fitSizeToWindow(0,7));
|
||||
assertEquals(3, changes.fitSizeToWindow(0,8));
|
||||
assertEquals(3, changes.fitSizeToWindow(0,9));
|
||||
assertEquals(3, changes.fitSizeToWindow(1,9));
|
||||
assertEquals(3, changes.fitSizeToWindow(2,9));
|
||||
assertEquals(3, changes.fitSizeToWindow(2,3));
|
||||
assertEquals(2, changes.fitSizeToWindow(2,2));
|
||||
assertEquals(1, changes.fitSizeToWindow(2,1));
|
||||
assertEquals(2, changes.fitSizeToWindow(3,9));
|
||||
assertEquals(2, changes.fitSizeToWindow(3,2));
|
||||
assertEquals(1, changes.fitSizeToWindow(3,1));
|
||||
assertEquals(2, changes.fitSizeToWindow(3,2));
|
||||
assertEquals(2, changes.fitSizeToWindow(3,3));
|
||||
assertEquals(1, changes.fitSizeToWindow(4,1));
|
||||
assertEquals(1, changes.fitSizeToWindow(4,2));
|
||||
assertEquals(1, changes.fitSizeToWindow(0, 3));
|
||||
assertEquals(2, changes.fitSizeToWindow(0, 4));
|
||||
assertEquals(3, changes.fitSizeToWindow(0, 5));
|
||||
assertEquals(3, changes.fitSizeToWindow(0, 6));
|
||||
assertEquals(3, changes.fitSizeToWindow(0, 7));
|
||||
assertEquals(3, changes.fitSizeToWindow(0, 8));
|
||||
assertEquals(3, changes.fitSizeToWindow(0, 9));
|
||||
assertEquals(3, changes.fitSizeToWindow(1, 9));
|
||||
assertEquals(3, changes.fitSizeToWindow(2, 9));
|
||||
assertEquals(3, changes.fitSizeToWindow(2, 3));
|
||||
assertEquals(2, changes.fitSizeToWindow(2, 2));
|
||||
assertEquals(1, changes.fitSizeToWindow(2, 1));
|
||||
assertEquals(2, changes.fitSizeToWindow(3, 9));
|
||||
assertEquals(2, changes.fitSizeToWindow(3, 2));
|
||||
assertEquals(1, changes.fitSizeToWindow(3, 1));
|
||||
assertEquals(2, changes.fitSizeToWindow(3, 2));
|
||||
assertEquals(2, changes.fitSizeToWindow(3, 3));
|
||||
assertEquals(1, changes.fitSizeToWindow(4, 1));
|
||||
assertEquals(1, changes.fitSizeToWindow(4, 2));
|
||||
assertFalse(changes.isInInterestWindow(5, 1));
|
||||
|
||||
}
|
||||
public void testFitSizeToWindowNoWindow() {
|
||||
SnapshotChanges changes=new SnapshotChanges(3);
|
||||
assertEquals(1, changes.fitSizeToWindow(0,1));
|
||||
assertEquals(2, changes.fitSizeToWindow(0,2));
|
||||
assertEquals(3, changes.fitSizeToWindow(0,3));
|
||||
assertEquals(4, changes.fitSizeToWindow(0,4));
|
||||
assertEquals(5, changes.fitSizeToWindow(0,5));
|
||||
|
||||
assertEquals(5, changes.fitSizeToWindow(1,5));
|
||||
assertEquals(3, changes.fitSizeToWindow(2,3));
|
||||
assertEquals(2, changes.fitSizeToWindow(1,2));
|
||||
assertEquals(10, changes.fitSizeToWindow(5,10));
|
||||
public void testFitSizeToWindowNoWindow() {
|
||||
SnapshotChanges changes = new SnapshotChanges(3);
|
||||
assertEquals(1, changes.fitSizeToWindow(0, 1));
|
||||
assertEquals(2, changes.fitSizeToWindow(0, 2));
|
||||
assertEquals(3, changes.fitSizeToWindow(0, 3));
|
||||
assertEquals(4, changes.fitSizeToWindow(0, 4));
|
||||
assertEquals(5, changes.fitSizeToWindow(0, 5));
|
||||
|
||||
assertEquals(5, changes.fitSizeToWindow(1, 5));
|
||||
assertEquals(3, changes.fitSizeToWindow(2, 3));
|
||||
assertEquals(2, changes.fitSizeToWindow(1, 2));
|
||||
assertEquals(10, changes.fitSizeToWindow(5, 10));
|
||||
}
|
||||
|
||||
public void testMarkLineChanged() {
|
||||
SnapshotChanges changes=new SnapshotChanges(2,3);
|
||||
SnapshotChanges changes = new SnapshotChanges(2, 3);
|
||||
assertFalse(changes.hasChanged());
|
||||
changes.markLineChanged(0);
|
||||
assertFalse(changes.hasChanged());
|
||||
|
@ -173,26 +177,27 @@ public class SnapshotChangesTest extends TestCase {
|
|||
changes.markLineChanged(2);
|
||||
assertTrue(changes.hasChanged());
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
assertFalse(changes.hasChanged());
|
||||
changes.markLineChanged(3);
|
||||
assertTrue(changes.hasChanged());
|
||||
|
||||
assertLineChange(false,2,3,0);
|
||||
assertLineChange(false,2,3,1);
|
||||
assertLineChange(true,2,3,2);
|
||||
assertLineChange(true,2,3,3);
|
||||
assertLineChange(true,2,3,4);
|
||||
assertLineChange(false,2,3,5);
|
||||
assertLineChange(false,2,3,6);
|
||||
assertLineChange(false, 2, 3, 0);
|
||||
assertLineChange(false, 2, 3, 1);
|
||||
assertLineChange(true, 2, 3, 2);
|
||||
assertLineChange(true, 2, 3, 3);
|
||||
assertLineChange(true, 2, 3, 4);
|
||||
assertLineChange(false, 2, 3, 5);
|
||||
assertLineChange(false, 2, 3, 6);
|
||||
|
||||
assertLineChange(true,2,4,5);
|
||||
assertLineChange(true, 2, 4, 5);
|
||||
}
|
||||
|
||||
void assertLineChange(boolean expected, int windowStart, int windowSize, int changedLine) {
|
||||
SnapshotChanges changes=new SnapshotChanges(windowStart,windowSize);
|
||||
SnapshotChanges changes = new SnapshotChanges(windowStart, windowSize);
|
||||
assertFalse(changes.hasChanged());
|
||||
changes.markLineChanged(changedLine);
|
||||
if(expected) {
|
||||
if (expected) {
|
||||
assertEquals(changedLine, changes.getFirstChangedLine());
|
||||
assertEquals(changedLine, changes.getLastChangedLine());
|
||||
} else {
|
||||
|
@ -200,15 +205,16 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertEquals(-1, changes.getLastChangedLine());
|
||||
|
||||
}
|
||||
assertEquals(expected,changes.hasChanged());
|
||||
for (int i = 0; i < windowStart+windowSize+5; i++) {
|
||||
boolean e= i==changedLine && i>=windowStart && i<windowStart+windowSize;
|
||||
assertEquals(expected, changes.hasChanged());
|
||||
for (int i = 0; i < windowStart + windowSize + 5; i++) {
|
||||
boolean e = i == changedLine && i >= windowStart && i < windowStart + windowSize;
|
||||
assertEquals(e, changes.hasLineChanged(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testMarkLinesChanged() {
|
||||
SnapshotChanges changes=new SnapshotChanges(2,3);
|
||||
SnapshotChanges changes = new SnapshotChanges(2, 3);
|
||||
assertFalse(changes.hasChanged());
|
||||
assertEquals(Integer.MAX_VALUE, changes.getFirstChangedLine());
|
||||
assertEquals(-1, changes.getLastChangedLine());
|
||||
|
@ -228,65 +234,65 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00100000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLinesChanged(1, 3);
|
||||
assertTrue(changes.hasChanged());
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
assertEquals(3, changes.getLastChangedLine());
|
||||
assertChangedLines(changes, "00110000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLinesChanged(1, 4);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00111000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLinesChanged(1, 4);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00111000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLinesChanged(2, 4);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00111000000");
|
||||
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLinesChanged(3, 4);
|
||||
assertEquals(3, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00011000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLinesChanged(3, 1);
|
||||
assertEquals(3, changes.getFirstChangedLine());
|
||||
assertEquals(3, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00010000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLinesChanged(4, 1);
|
||||
assertEquals(4, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00001000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLinesChanged(5, 1);
|
||||
assertEquals(Integer.MAX_VALUE, changes.getFirstChangedLine());
|
||||
assertEquals(-1, changes.getLastChangedLine());
|
||||
assertFalse(changes.hasChanged());
|
||||
assertChangedLines(changes, "00000000000");
|
||||
}
|
||||
|
||||
public void testMarkLinesChangedNoWindow() {
|
||||
SnapshotChanges changes=new SnapshotChanges(10);
|
||||
SnapshotChanges changes = new SnapshotChanges(10);
|
||||
assertFalse(changes.hasChanged());
|
||||
assertEquals(Integer.MAX_VALUE, changes.getFirstChangedLine());
|
||||
assertEquals(-1, changes.getLastChangedLine());
|
||||
|
@ -297,22 +303,21 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertEquals(0, changes.getLastChangedLine());
|
||||
assertChangedLines(changes, "1000000000");
|
||||
|
||||
changes=new SnapshotChanges(10);
|
||||
changes = new SnapshotChanges(10);
|
||||
changes.markLinesChanged(0, 5);
|
||||
assertTrue(changes.hasChanged());
|
||||
assertEquals(0, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
assertChangedLines(changes, "1111100000");
|
||||
|
||||
changes=new SnapshotChanges(3);
|
||||
changes = new SnapshotChanges(3);
|
||||
changes.markLinesChanged(1, 6);
|
||||
assertTrue(changes.hasChanged());
|
||||
assertEquals(1, changes.getFirstChangedLine());
|
||||
assertEquals(6, changes.getLastChangedLine());
|
||||
assertChangedLines(changes, "011");
|
||||
|
||||
|
||||
changes=new SnapshotChanges(10);
|
||||
changes = new SnapshotChanges(10);
|
||||
changes.markLinesChanged(5, 6);
|
||||
assertTrue(changes.hasChanged());
|
||||
assertEquals(5, changes.getFirstChangedLine());
|
||||
|
@ -322,61 +327,62 @@ public class SnapshotChangesTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testHasChanged() {
|
||||
SnapshotChanges changes=new SnapshotChanges(0);
|
||||
SnapshotChanges changes = new SnapshotChanges(0);
|
||||
assertFalse(changes.hasChanged());
|
||||
changes=new SnapshotChanges(1);
|
||||
changes = new SnapshotChanges(1);
|
||||
assertFalse(changes.hasChanged());
|
||||
changes=new SnapshotChanges(1,9);
|
||||
changes = new SnapshotChanges(1, 9);
|
||||
assertFalse(changes.hasChanged());
|
||||
}
|
||||
|
||||
public void testSetAllChanged() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.setAllChanged(10);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00111000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.setAllChanged(3);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
assertEquals(2, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00111000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.setAllChanged(4);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
assertEquals(3, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00111000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.setAllChanged(5);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00111000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.setAllChanged(6);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "00111000000");
|
||||
}
|
||||
|
||||
public void testSetAllChangedNoWindow() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(5);
|
||||
changes = new SnapshotChanges(5);
|
||||
changes.setAllChanged(10);
|
||||
assertEquals(0, changes.getFirstChangedLine());
|
||||
assertEquals(9, changes.getLastChangedLine());
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "1111111111");
|
||||
|
||||
changes=new SnapshotChanges(5);
|
||||
changes = new SnapshotChanges(5);
|
||||
changes.setAllChanged(3);
|
||||
assertEquals(0, changes.getFirstChangedLine());
|
||||
assertEquals(2, changes.getLastChangedLine());
|
||||
|
@ -387,7 +393,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
|
||||
public void testConvertScrollingIntoChanges() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.scroll(0, 4, -1);
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "000100");
|
||||
|
@ -402,7 +408,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
|
||||
public void testConvertScrollingIntoChangesNoWindow() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(7);
|
||||
changes = new SnapshotChanges(7);
|
||||
changes.scroll(0, 4, -1);
|
||||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "000100");
|
||||
|
@ -414,9 +420,10 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertEquals(0, changes.getScrollWindowShift());
|
||||
assertChangedLines(changes, "111100");
|
||||
}
|
||||
|
||||
public void testScrollNoWindow() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(7);
|
||||
changes = new SnapshotChanges(7);
|
||||
changes.scroll(0, 3, -2);
|
||||
assertEquals(1, changes.getFirstChangedLine());
|
||||
assertEquals(2, changes.getLastChangedLine());
|
||||
|
@ -426,7 +433,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "0110000");
|
||||
|
||||
changes=new SnapshotChanges(7);
|
||||
changes = new SnapshotChanges(7);
|
||||
changes.scroll(0, 3, -1);
|
||||
changes.scroll(0, 3, -1);
|
||||
assertEquals(1, changes.getFirstChangedLine());
|
||||
|
@ -437,7 +444,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "0110000");
|
||||
|
||||
changes=new SnapshotChanges(7);
|
||||
changes = new SnapshotChanges(7);
|
||||
changes.scroll(0, 7, -1);
|
||||
changes.scroll(0, 7, -1);
|
||||
assertEquals(5, changes.getFirstChangedLine());
|
||||
|
@ -449,7 +456,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertChangedLines(changes, "0000011");
|
||||
|
||||
// positive scrolls cannot be optimized at the moment
|
||||
changes=new SnapshotChanges(7);
|
||||
changes = new SnapshotChanges(7);
|
||||
changes.scroll(0, 7, 1);
|
||||
changes.scroll(0, 7, 1);
|
||||
assertEquals(0, changes.getFirstChangedLine());
|
||||
|
@ -461,9 +468,10 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertChangedLines(changes, "1111111");
|
||||
|
||||
}
|
||||
|
||||
public void testScroll() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.scroll(0, 7, -1);
|
||||
assertEquals(4, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
|
@ -473,7 +481,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "0000100000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.scroll(0, 7, -2);
|
||||
assertEquals(3, changes.getFirstChangedLine());
|
||||
assertEquals(4, changes.getLastChangedLine());
|
||||
|
@ -483,9 +491,10 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "0001100000");
|
||||
}
|
||||
|
||||
public void testScrollNergative() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.scroll(0, 7, -1);
|
||||
changes.scroll(0, 7, -1);
|
||||
assertEquals(3, changes.getFirstChangedLine());
|
||||
|
@ -497,9 +506,10 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertChangedLines(changes, "0001100000");
|
||||
|
||||
}
|
||||
|
||||
public void testScrollPositive() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.scroll(0, 7, 1);
|
||||
changes.scroll(0, 7, 1);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
|
@ -510,7 +520,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "0011100000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.scroll(0, 3, 1);
|
||||
changes.scroll(0, 3, 1);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
|
@ -521,7 +531,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "0010000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.scroll(0, 4, 1);
|
||||
changes.scroll(0, 4, 1);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
|
@ -532,7 +542,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "0011000000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.scroll(0, 5, 1);
|
||||
changes.scroll(0, 5, 1);
|
||||
assertEquals(2, changes.getFirstChangedLine());
|
||||
|
@ -543,7 +553,7 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertTrue(changes.hasChanged());
|
||||
assertChangedLines(changes, "0011100000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.scroll(3, 5, 1);
|
||||
changes.scroll(3, 5, 1);
|
||||
assertEquals(3, changes.getFirstChangedLine());
|
||||
|
@ -557,60 +567,62 @@ public class SnapshotChangesTest extends TestCase {
|
|||
|
||||
public void testCopyChangedLines() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLineChanged(3);
|
||||
ITerminalTextData source=new TerminalTextDataStore();
|
||||
ITerminalTextData source = new TerminalTextDataStore();
|
||||
TerminalTextTestHelper.fillSimple(source, "01234567890");
|
||||
ITerminalTextData dest=new TerminalTextDataStore();
|
||||
ITerminalTextData dest = new TerminalTextDataStore();
|
||||
TerminalTextTestHelper.fillSimple(dest, "abcdefghijk");
|
||||
|
||||
changes.copyChangedLines(dest, source);
|
||||
assertEquals("abc3efghijk",TerminalTextTestHelper.toSimple(dest));
|
||||
assertEquals("abc3efghijk", TerminalTextTestHelper.toSimple(dest));
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.setAllChanged(7);
|
||||
source=new TerminalTextDataStore();
|
||||
source = new TerminalTextDataStore();
|
||||
TerminalTextTestHelper.fillSimple(source, "01234567890");
|
||||
dest=new TerminalTextDataStore();
|
||||
dest = new TerminalTextDataStore();
|
||||
TerminalTextTestHelper.fillSimple(dest, "abcdefghijk");
|
||||
|
||||
changes.copyChangedLines(dest, source);
|
||||
assertEquals("ab234fghijk",TerminalTextTestHelper.toSimple(dest));
|
||||
assertEquals("ab234fghijk", TerminalTextTestHelper.toSimple(dest));
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes.scroll(0,7,-1);
|
||||
source=new TerminalTextDataStore();
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.scroll(0, 7, -1);
|
||||
source = new TerminalTextDataStore();
|
||||
TerminalTextTestHelper.fillSimple(source, "01234567890");
|
||||
dest=new TerminalTextDataStore();
|
||||
dest = new TerminalTextDataStore();
|
||||
TerminalTextTestHelper.fillSimple(dest, "abcdefghijk");
|
||||
// only one line has changed! The other lines are scrolled!
|
||||
assertChangedLines(changes,"00001000");
|
||||
assertChangedLines(changes, "00001000");
|
||||
changes.copyChangedLines(dest, source);
|
||||
assertEquals("abcd4fghijk",TerminalTextTestHelper.toSimple(dest));
|
||||
assertEquals("abcd4fghijk", TerminalTextTestHelper.toSimple(dest));
|
||||
}
|
||||
|
||||
public void testCopyChangedLinesWithSmallSource() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLineChanged(3);
|
||||
ITerminalTextData source=new TerminalTextDataStore();
|
||||
ITerminalTextData source = new TerminalTextDataStore();
|
||||
source.setDimensions(2, 2);
|
||||
TerminalTextDataWindow dest=new TerminalTextDataWindow();
|
||||
TerminalTextDataWindow dest = new TerminalTextDataWindow();
|
||||
dest.setWindow(2, 2);
|
||||
changes.copyChangedLines(dest, source);
|
||||
}
|
||||
|
||||
public void testCopyChangedLinesWithSmallSource1() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
changes.markLineChanged(3);
|
||||
ITerminalTextData source=new TerminalTextDataStore();
|
||||
ITerminalTextData source = new TerminalTextDataStore();
|
||||
TerminalTextTestHelper.fillSimple(source, "01");
|
||||
ITerminalTextData dest=new TerminalTextDataStore();
|
||||
ITerminalTextData dest = new TerminalTextDataStore();
|
||||
changes.copyChangedLines(dest, source);
|
||||
}
|
||||
|
||||
public void testSetInterestWindowSize() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
// move the window
|
||||
changes.setInterestWindow(3, 3);
|
||||
// only one line has changed! The other lines are scrolled!
|
||||
|
@ -618,11 +630,11 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertEquals(3, changes.getScrollWindowSize());
|
||||
assertEquals(-1, changes.getScrollWindowShift());
|
||||
|
||||
assertChangedLines(changes,"0000010");
|
||||
assertChangedLines(changes, "0000010");
|
||||
changes.convertScrollingIntoChanges();
|
||||
assertChangedLines(changes,"0001110");
|
||||
assertChangedLines(changes, "0001110");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
// move the window
|
||||
changes.setInterestWindow(3, 4);
|
||||
// only one line has changed! The other lines are scrolled!
|
||||
|
@ -630,21 +642,20 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertEquals(3, changes.getScrollWindowSize());
|
||||
assertEquals(-1, changes.getScrollWindowShift());
|
||||
|
||||
assertChangedLines(changes,"0000011");
|
||||
assertChangedLines(changes, "0000011");
|
||||
changes.convertScrollingIntoChanges();
|
||||
assertChangedLines(changes,"0001111");
|
||||
assertChangedLines(changes, "0001111");
|
||||
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
// move the window
|
||||
changes.setInterestWindow(6, 3);
|
||||
// cannot scroll
|
||||
assertEquals(0, changes.getScrollWindowStartLine());
|
||||
assertEquals(0, changes.getScrollWindowSize());
|
||||
assertEquals(0, changes.getScrollWindowShift());
|
||||
assertChangedLines(changes,"000000111000");
|
||||
assertChangedLines(changes, "000000111000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
// expand the window
|
||||
changes.setInterestWindow(2, 5);
|
||||
// cannot scroll
|
||||
|
@ -652,30 +663,30 @@ public class SnapshotChangesTest extends TestCase {
|
|||
assertEquals(0, changes.getScrollWindowSize());
|
||||
assertEquals(0, changes.getScrollWindowShift());
|
||||
|
||||
assertChangedLines(changes,"0000011000");
|
||||
assertChangedLines(changes, "0000011000");
|
||||
}
|
||||
|
||||
public void testSetInterestWindowSize2() {
|
||||
SnapshotChanges changes;
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
// move the window
|
||||
changes.setInterestWindow(1, 3);
|
||||
assertChangedLines(changes,"0111000");
|
||||
assertChangedLines(changes, "0111000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
// move the window
|
||||
changes.setInterestWindow(1, 4);
|
||||
assertChangedLines(changes,"01111000");
|
||||
assertChangedLines(changes, "01111000");
|
||||
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
// expand the window
|
||||
changes.setInterestWindow(6, 3);
|
||||
assertChangedLines(changes,"000000111000");
|
||||
assertChangedLines(changes, "000000111000");
|
||||
|
||||
changes=new SnapshotChanges(2,3);
|
||||
changes = new SnapshotChanges(2, 3);
|
||||
// expand the window
|
||||
changes.setInterestWindow(1, 2);
|
||||
assertChangedLines(changes,"0110000");
|
||||
assertChangedLines(changes, "0110000");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue