Adding swt and socket frontends
This commit is contained in:
4
gclc-swt/.gitignore
vendored
Normal file
4
gclc-swt/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/target/
|
||||
/.settings/
|
||||
/.classpath
|
||||
/.project
|
||||
70
gclc-swt/pom.xml
Normal file
70
gclc-swt/pom.xml
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
<!-- Copyright E. Bigeon (2015) -->
|
||||
<!-- -->
|
||||
<!-- emmanuel@bigeon.fr -->
|
||||
<!-- -->
|
||||
<!-- This software is a computer program whose purpose is to -->
|
||||
<!-- provide a swt window for console applications. -->
|
||||
<!-- -->
|
||||
<!-- This software is governed by the CeCILL license under French law and -->
|
||||
<!-- abiding by the rules of distribution of free software. You can use, -->
|
||||
<!-- modify and/or redistribute the software under the terms of the CeCILL -->
|
||||
<!-- license as circulated by CEA, CNRS and INRIA at the following URL -->
|
||||
<!-- "http://www.cecill.info". -->
|
||||
<!-- -->
|
||||
<!-- As a counterpart to the access to the source code and rights to copy, -->
|
||||
<!-- modify and redistribute granted by the license, users are provided only -->
|
||||
<!-- with a limited warranty and the software's author, the holder of the -->
|
||||
<!-- economic rights, and the successive licensors have only limited -->
|
||||
<!-- liability. -->
|
||||
<!-- -->
|
||||
<!-- In this respect, the user's attention is drawn to the risks associated -->
|
||||
<!-- with loading, using, modifying and/or developing or reproducing the -->
|
||||
<!-- software by the user in light of its specific status of free software, -->
|
||||
<!-- that may mean that it is complicated to manipulate, and that also -->
|
||||
<!-- therefore means that it is reserved for developers and experienced -->
|
||||
<!-- professionals having in-depth computer knowledge. Users are therefore -->
|
||||
<!-- encouraged to load and test the software's suitability as regards their -->
|
||||
<!-- requirements in conditions enabling the security of their systems and/or -->
|
||||
<!-- data to be ensured and, more generally, to use and operate it in the -->
|
||||
<!-- same conditions as regards security. -->
|
||||
<!-- -->
|
||||
<!-- The fact that you are presently reading this means that you have had -->
|
||||
<!-- knowledge of the CeCILL license and that you accept its terms. -->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>gclc-swt</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://www.bigeon.fr/emmanuel</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<parent>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
<artifactId>ebigeon-config</artifactId>
|
||||
<version>1.6.0</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
<artifactId>gclc</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.swt.gtk.linux</groupId>
|
||||
<artifactId>x86_64</artifactId>
|
||||
<version>3.3.0-v3346</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
<artifactId>collections</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<inceptionYear>2015</inceptionYear>
|
||||
<name>GCLC swt</name>
|
||||
<description>provide a swt window for console applications</description>
|
||||
</project>
|
||||
292
gclc-swt/src/main/java/fr/bigeon/gclc/swt/SWTConsole.java
Normal file
292
gclc-swt/src/main/java/fr/bigeon/gclc/swt/SWTConsole.java
Normal file
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
* Copyright E. Bigeon (2015)
|
||||
*
|
||||
* emmanuel@bigeon.fr
|
||||
*
|
||||
* This software is a computer program whose purpose is to
|
||||
* provide a swt window for console applications.
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*/
|
||||
/**
|
||||
* gclc-swt:fr.bigeon.gclc.swt.SWTConsole.java
|
||||
* Created on: Apr 18, 2015
|
||||
*/
|
||||
package fr.bigeon.gclc.swt;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.FocusAdapter;
|
||||
import org.eclipse.swt.events.FocusEvent;
|
||||
import org.eclipse.swt.events.KeyAdapter;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import fr.bigeon.collections.ArrayRibbon;
|
||||
import fr.bigeon.collections.Ribbon;
|
||||
import fr.bigeon.gclc.CommandRequestListener;
|
||||
import fr.bigeon.gclc.ConsoleApplication;
|
||||
import fr.bigeon.gclc.ConsoleManager;
|
||||
|
||||
/** A SWT component to connect to gclc {@link ConsoleApplication}
|
||||
* <p>
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public class SWTConsole extends Composite implements ConsoleManager, CommandRequestListener {
|
||||
/** The cmd prefix in the output console */
|
||||
private static final String CMD_PREFIX = "[CMD] "; //$NON-NLS-1$
|
||||
/** The console output text field */
|
||||
private final Text consoleOutput;
|
||||
/** The console input text field */
|
||||
private final Text consoleInput;
|
||||
/** The prompt label */
|
||||
private final Label lblPromptlabel;
|
||||
/** The prompt text */
|
||||
private String prompt = ">"; //$NON-NLS-1$
|
||||
/** The command entered by the user */
|
||||
private String command = null;
|
||||
/** If the prompt should be active */
|
||||
private boolean prompting = false;
|
||||
/** The object for thread synchronization with the prompt */
|
||||
private final Object promptLock = new Object();
|
||||
|
||||
/** The ribbon of commands */
|
||||
private final Ribbon<String> commands;
|
||||
/** The current index in the ribbon */
|
||||
private int currentIndex = 0;
|
||||
|
||||
/** Create the composite.
|
||||
*
|
||||
* @param parent the prent composite
|
||||
* @param style the composite style */
|
||||
public SWTConsole(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
|
||||
// inner elements
|
||||
commands = new ArrayRibbon<>(10);
|
||||
|
||||
setLayout(new GridLayout(2, false));
|
||||
|
||||
consoleOutput = new Text(this, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
|
||||
consoleOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
|
||||
consoleOutput.setRedraw(true);
|
||||
consoleOutput.addFocusListener(new FocusAdapter() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
consoleInput.setFocus();
|
||||
}
|
||||
});
|
||||
|
||||
lblPromptlabel = new Label(this, SWT.NONE);
|
||||
lblPromptlabel.setText(prompt);
|
||||
|
||||
consoleInput = new Text(this, SWT.BORDER);
|
||||
consoleInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
||||
consoleInput.addKeyListener(new KeyAdapter() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
// Enter validates the command if prompting
|
||||
if (e.keyCode == '\r' && prompting) {
|
||||
synchronized (promptLock) {
|
||||
command = consoleInput.getText();
|
||||
prompting = false;
|
||||
consoleInput.setText(new String());
|
||||
consoleOutput.append(CMD_PREFIX + command + System.lineSeparator());
|
||||
currentIndex = -1;
|
||||
promptLock.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
// Upper arrow retrieves previous commands
|
||||
if (e.keyCode == SWT.ARROW_UP) {
|
||||
if (currentIndex < commands.size() - 1) {
|
||||
currentIndex++;
|
||||
consoleInput.setText(commands.get(commands.size() - currentIndex - 1));
|
||||
consoleInput.setSelection(consoleInput.getText().length());
|
||||
}
|
||||
}
|
||||
|
||||
// Lower arrow retrieves next commands
|
||||
if (e.keyCode == SWT.ARROW_DOWN) {
|
||||
if (currentIndex == 0) {
|
||||
currentIndex--;
|
||||
consoleInput.setText(new String());
|
||||
} else if (currentIndex > 0) {
|
||||
consoleInput.setText(commands.get(commands.size() - (--currentIndex) - 1));
|
||||
consoleInput.setSelection(consoleInput.getText().length());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkSubclass() {
|
||||
// Disable the check that prevents subclassing of SWT components
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.ConsoleManager#setPrompt(java.lang.String) */
|
||||
@Override
|
||||
public void setPrompt(final String prompt) {
|
||||
this.prompt = prompt;
|
||||
Display.getDefault().syncExec(new Runnable() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
lblPromptlabel.setText(prompt);
|
||||
lblPromptlabel.pack();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.ConsoleManager#getPrompt() */
|
||||
@Override
|
||||
public String getPrompt() {
|
||||
return prompt;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.ConsoleManager#prompt() */
|
||||
@Override
|
||||
public String prompt() {
|
||||
synchronized (promptLock) {
|
||||
try {
|
||||
Display.getDefault().syncExec(new Runnable() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
consoleInput.setFocus();
|
||||
}
|
||||
});
|
||||
prompting = true;
|
||||
promptLock.wait();
|
||||
} catch (InterruptedException e) {
|
||||
command = null;
|
||||
}
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.ConsoleManager#prompt(java.lang.String) */
|
||||
@Override
|
||||
public String prompt(final String message) {
|
||||
synchronized (promptLock) {
|
||||
try {
|
||||
Display.getDefault().syncExec(new Runnable() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
lblPromptlabel.setText(message);
|
||||
// relayout
|
||||
SWTConsole.this.layout();
|
||||
consoleInput.setFocus();
|
||||
}
|
||||
});
|
||||
prompting = true;
|
||||
promptLock.wait();
|
||||
} catch (InterruptedException e) {
|
||||
command = null;
|
||||
} finally {
|
||||
Display.getDefault().syncExec(new Runnable() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
lblPromptlabel.setText(prompt);
|
||||
lblPromptlabel.pack();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.ConsoleManager#println(java.lang.String) */
|
||||
@Override
|
||||
public void println(final String message) {
|
||||
Display.getDefault().syncExec(new Runnable() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
consoleOutput.append(message + System.lineSeparator());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.ConsoleManager#print(java.lang.String) */
|
||||
@Override
|
||||
public void print(final String text) {
|
||||
Display.getDefault().syncExec(new Runnable() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
consoleOutput.append(text);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.ConsoleManager#println() */
|
||||
@Override
|
||||
public void println() {
|
||||
Display.getDefault().syncExec(new Runnable() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
consoleOutput.append(System.lineSeparator());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.swt.widgets.Composite#setFocus() */
|
||||
@Override
|
||||
public boolean setFocus() {
|
||||
return consoleInput.setFocus();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see
|
||||
* fr.bigeon.gclc.CommandRequestListener#commandRequest(java.lang.String) */
|
||||
@Override
|
||||
public void commandRequest(String request) {
|
||||
commands.add(request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright E. Bigeon (2015)
|
||||
*
|
||||
* emmanuel@bigeon.fr
|
||||
*
|
||||
* This software is a computer program whose purpose is to
|
||||
* provide a swt window for console applications.
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*/
|
||||
/**
|
||||
* gclc-swt:fr.bigeon.gclc.swt.SWTConsoleShell.java
|
||||
* Created on: Apr 18, 2015
|
||||
*/
|
||||
package fr.bigeon.gclc.swt;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import fr.bigeon.gclc.CommandRequestListener;
|
||||
import fr.bigeon.gclc.ConsoleManager;
|
||||
|
||||
/** A shell containing a {@link SWTConsole}
|
||||
* <p>
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public class SWTConsoleShell extends Shell {
|
||||
|
||||
/** The console component */
|
||||
private final SWTConsole console;
|
||||
|
||||
/** Create the shell.
|
||||
*
|
||||
* @param display the display */
|
||||
public SWTConsoleShell(Display display) {
|
||||
super(display, SWT.SHELL_TRIM);
|
||||
setLayout(new FillLayout(SWT.HORIZONTAL));
|
||||
|
||||
console = new SWTConsole(this, SWT.NONE);
|
||||
createContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create contents of the shell.
|
||||
*/
|
||||
protected void createContents() {
|
||||
setText("Console Application"); //$NON-NLS-1$
|
||||
setSize(450, 300);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkSubclass() {
|
||||
// Disable the check that prevents subclassing of SWT components
|
||||
}
|
||||
|
||||
/** @return the console manager */
|
||||
public ConsoleManager getManager() {
|
||||
return console;
|
||||
}
|
||||
|
||||
/** @return the element awaiting commands */
|
||||
public CommandRequestListener getCommandListener() {
|
||||
return console;
|
||||
}
|
||||
}
|
||||
102
gclc-swt/src/test/java/fr/bigeon/gclc/swt/AppTest.java
Normal file
102
gclc-swt/src/test/java/fr/bigeon/gclc/swt/AppTest.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright E. Bigeon (2015)
|
||||
*
|
||||
* emmanuel@bigeon.fr
|
||||
*
|
||||
* This software is a computer program whose purpose is to
|
||||
* provide a swt window for console applications.
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*/
|
||||
package fr.bigeon.gclc.swt;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public void testApp()
|
||||
{
|
||||
// Display display = new Display();
|
||||
// final Shell shell = new Shell(display);
|
||||
// shell.setLayout(new GridLayout(1, false));
|
||||
// SWTConsole swtConsole = new SWTConsole(shell, SWT.NONE);
|
||||
// swtConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
|
||||
// 1, 1));
|
||||
// final ConsoleApplication appl = new ConsoleApplication(swtConsole,
|
||||
// "exit",
|
||||
// "Hello", "See you");
|
||||
// shell.pack();
|
||||
// shell.open();
|
||||
// Thread applThread = new Thread(new Runnable() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// appl.start();
|
||||
// Display.getDefault().syncExec(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// shell.dispose();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// applThread.start();
|
||||
// while (!shell.isDisposed()) {
|
||||
// if (!display.readAndDispatch()) display.sleep();
|
||||
// }
|
||||
// display.dispose();
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user