use of g4p_controls.StyledString.TextLayoutHitInfo in project hid-serial by rayshobby.
the class GTextField method mouseEvent.
public void mouseEvent(MouseEvent event) {
if (!visible || !enabled || !available)
return;
calcTransformedOrigin(winApp.mouseX, winApp.mouseY);
// Remove translation
ox -= tx;
// Remove translation
oy -= ty;
currSpot = whichHotSpot(ox, oy);
if (currSpot == 1 || focusIsWith == this)
cursorIsOver = this;
else if (cursorIsOver == this)
cursorIsOver = null;
switch(event.getAction()) {
case MouseEvent.PRESS:
if (currSpot == 1) {
if (focusIsWith != this && z >= focusObjectZ()) {
keepCursorInView = true;
takeFocus();
}
dragging = false;
if (stext == null || stext.length() == 0) {
stext = new StyledString(" ", wrapWidth);
stext.getLines(buffer.g2);
}
endTLHI = stext.calculateFromXY(buffer.g2, ox + ptx, oy + pty);
startTLHI = new TextLayoutHitInfo(endTLHI);
calculateCaretPos(endTLHI);
bufferInvalid = true;
} else {
// Not over this control so if we have focus loose it
if (focusIsWith == this)
loseFocus(null);
}
break;
case MouseEvent.RELEASE:
dragging = false;
bufferInvalid = true;
break;
case MouseEvent.DRAG:
if (focusIsWith == this) {
keepCursorInView = true;
dragging = true;
endTLHI = stext.calculateFromXY(buffer.g2, ox + ptx, oy + pty);
calculateCaretPos(endTLHI);
fireEvent(this, GEvent.SELECTION_CHANGED);
bufferInvalid = true;
}
break;
}
}
use of g4p_controls.StyledString.TextLayoutHitInfo in project hid-serial by rayshobby.
the class GEditableTextControl method getSelectedText.
/**
* Get the text that has been selected (highlighted) by the user. <br>
* @return the selected text without styling
*/
public String getSelectedText() {
if (!hasSelection())
return "";
TextLayoutHitInfo startSelTLHI;
TextLayoutHitInfo endSelTLHI;
if (endTLHI.compareTo(startTLHI) == -1) {
startSelTLHI = endTLHI;
endSelTLHI = startTLHI;
} else {
startSelTLHI = startTLHI;
endSelTLHI = endTLHI;
}
int ss = startSelTLHI.tli.startCharIndex + startSelTLHI.thi.getInsertionIndex();
int ee = endSelTLHI.tli.startCharIndex + endSelTLHI.thi.getInsertionIndex();
String s = stext.getPlainText().substring(ss, ee);
return s;
}
use of g4p_controls.StyledString.TextLayoutHitInfo in project hid-serial by rayshobby.
the class GEditableTextControl method setSelectedTextStyle.
/**
* If some text has been selected then set the style. If there is no selection then
* the text is unchanged.
*
*
* @param style
*/
public void setSelectedTextStyle(TextAttribute style, Object value) {
if (!hasSelection())
return;
TextLayoutHitInfo startSelTLHI;
TextLayoutHitInfo endSelTLHI;
if (endTLHI.compareTo(startTLHI) == -1) {
startSelTLHI = endTLHI;
endSelTLHI = startTLHI;
} else {
startSelTLHI = startTLHI;
endSelTLHI = endTLHI;
}
int ss = startSelTLHI.tli.startCharIndex + startSelTLHI.thi.getInsertionIndex();
int ee = endSelTLHI.tli.startCharIndex + endSelTLHI.thi.getInsertionIndex();
stext.addAttribute(style, value, ss, ee);
// We have modified the text style so the end of the selection may have
// moved, so it needs to be recalculated. The start will be unaffected.
stext.getLines(buffer.g2);
endSelTLHI.tli = stext.getTLIforCharNo(ee);
int cn = ee - endSelTLHI.tli.startCharIndex;
if (// start of line
cn == 0)
endSelTLHI.thi = endSelTLHI.tli.layout.getNextLeftHit(1);
else
endSelTLHI.thi = endSelTLHI.tli.layout.getNextRightHit(cn - 1);
bufferInvalid = true;
}
use of g4p_controls.StyledString.TextLayoutHitInfo in project hid-serial by rayshobby.
the class GEditableTextControl method loadText.
/**
* Load the styled string to be used by this control. <br>
* It will also restore any text selection saved with the text.
*
* @param fname the name of the file to use
* @return true if loaded successfully else false
*/
public boolean loadText(String fname) {
StyledString ss = StyledString.load(winApp, fname);
if (ss == null)
return false;
setStyledText(ss);
// Now restore any text selection
if (stext.startIdx >= 0) {
// we have a selection
// Selection starts at ...
startTLHI = new TextLayoutHitInfo();
startTLHI.tli = stext.getTLIforCharNo(stext.startIdx);
int pInLayout = stext.startIdx - startTLHI.tli.startCharIndex;
if (pInLayout == 0)
startTLHI.thi = startTLHI.tli.layout.getNextLeftHit(1);
else
startTLHI.thi = startTLHI.tli.layout.getNextRightHit(pInLayout - 1);
// Selection ends at ...
endTLHI = new TextLayoutHitInfo();
endTLHI.tli = stext.getTLIforCharNo(stext.endIdx);
pInLayout = stext.endIdx - endTLHI.tli.startCharIndex;
if (pInLayout == 0)
endTLHI.thi = endTLHI.tli.layout.getNextLeftHit(1);
else
endTLHI.thi = endTLHI.tli.layout.getNextRightHit(pInLayout - 1);
calculateCaretPos(endTLHI);
}
bufferInvalid = true;
return true;
}
Aggregations