@Override protected Transferable createTransferable(SComponent component, SMouseEvent event) { if(component instanceof STextComponent) { STextComponent textComponent = (STextComponent)component; String[] stringArray = event.getPoint().getCoordinates().split("-"); int startIndex = Integer.parseInt(stringArray[0]); int endIndex = Integer.parseInt(stringArray[1]); textComponent.setSelectionStart(startIndex); textComponent.setSelectionEnd(endIndex); } return super.createTransferable(component, event); }
@Override public void processLowLevelEvent(String name, String... values) { if(values == null || values.length != 1) return; String[] vals = values[0].split(":"); SComponent component = SessionManager.getSession().getComponentByName(vals[0]); this.focus = component; if(vals.length > 1 && component instanceof STextComponent) { STextComponent textComponent = (STextComponent)component; String[] selections = vals[1].split("-"); if(selections.length > 1) { textComponent.setSelectionStart(Integer.parseInt(selections[0])); textComponent.setSelectionEnd(Integer.parseInt(selections[1])); } else { int position = Integer.parseInt(selections[0]); textComponent.setCaretPosition(position); textComponent.setSelectionStart(position); textComponent.setSelectionEnd(position); } } }
@Override public boolean importData(TransferSupport support) { if(support.isDrop()) { int index = ((STextComponent.DropLocation)support.getDropLocation()).getIndex(); ((STextComponent)support.getComponent()).setCaretPosition(index); ((STextComponent)support.getComponent()).setSelectionStart(index); ((STextComponent)support.getComponent()).setSelectionEnd(index); } return super.importData(support); }