Changed behavior of the delete key

Added click selection support for Textfields
This commit is contained in:
Viproz 2018-11-07 16:16:37 +01:00
parent 1f7cb64986
commit 2e47b179cf
2 changed files with 33 additions and 7 deletions

View File

@ -843,7 +843,7 @@ public final class ControlWindow {
_myApplet.frame.removeNotify( );
_myApplet.frame.setUndecorated( isUndecorated );
_myApplet.setSize( _myApplet.width , _myApplet.height );
_myApplet.setBounds( 0 , 0 , _myApplet.width , _myApplet.height );
//_myApplet.setBounds( 0 , 0 , _myApplet.width , _myApplet.height );
_myApplet.frame.setSize( _myApplet.width , _myApplet.height );
_myApplet.frame.addNotify( );
}

View File

@ -134,8 +134,8 @@ public class Textfield extends Controller< Textfield > {
keyMapping = new HashMap< Integer , TextfieldCommand >( );
keyMapping.put( ENTER , new Enter( ) );
keyMapping.put( DEFAULT , new InsertCharacter( ) );
keyMapping.put( DELETE , new DeleteCharacter( ) );
keyMapping.put( BACKSPACE , new DeleteCharacter( ) );
keyMapping.put( DELETE , new DeleteCharacterRight( ) );
keyMapping.put( BACKSPACE , new DeleteCharacterLeft( ) );
keyMapping.put( LEFT , new MoveLeft( ) );
keyMapping.put( RIGHT , new MoveRight( ) );
keyMapping.put( UP , new MoveUp( ) );
@ -261,11 +261,27 @@ public class Textfield extends Controller< Textfield > {
@Override protected void mousePressed( ) {
if ( isActive ) {
// TODO System.out.println("adjust cursor");
// Multiline not supported
}
int x = ( int ) ( getControlWindow( ).mouseX - x( getAbsolutePosition( ) ) );
int y = ( int ) ( getControlWindow( ).mouseY - y( getAbsolutePosition( ) ) );
int x = ( int ) ( getControlWindow( ).mouseX - x( getPosition( ) ) );
int y = ( int ) ( getControlWindow( ).mouseY - y( getPosition( ) ) );
int i = 0;
int textWidth;
for(i = 0 ; i <= _myTextBuffer.length() ; i++) {
textWidth = ControlFont.getWidthFor( _myTextBuffer.substring( 0 , i ) , _myValueLabel , buffer );
if(textWidth > x) {
if(i != 0 && textWidth-x > ControlFont.getWidthFor( _myTextBuffer.substring( i-1 , i ) , _myValueLabel , buffer )/2) {
i--;
}
break;
}
}
if(i > _myTextBuffer.length())
i = _myTextBuffer.length();
setIndex(i);
// TODO System.out.println(x + ":" + y);
setFocus( true );
}
@ -424,7 +440,7 @@ public class Textfield extends Controller< Textfield > {
}
}
class DeleteCharacter implements TextfieldCommand {
class DeleteCharacterLeft implements TextfieldCommand {
public void execute( ) {
if ( _myTextBuffer.length( ) > 0 && _myTextBufferIndex > 0 ) {
@ -434,6 +450,16 @@ public class Textfield extends Controller< Textfield > {
}
}
class DeleteCharacterRight implements TextfieldCommand {
public void execute( ) {
if ( _myTextBuffer.length( ) > 0 && _myTextBufferIndex < _myTextBuffer.length( ) ) {
_myTextBuffer.deleteCharAt( _myTextBufferIndex );
setIndex( _myTextBufferIndex );
}
}
}
class MoveLeft implements TextfieldCommand {
public void execute( ) {