1. TextArea Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | import javafx.scene.Node; import javafx.scene.control.TextArea; import javafx.scene.input.Clipboard; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; public class FxTextArea implements FxNode { FxVBox vbox; FxToolBar hbox; TextArea text; int textSize = 11; public FxTextArea() { text = new TextArea(); } public FxTextArea(boolean toolbar) { this(); if( toolbar ) { hbox = new FxToolBar(); hbox.addToolBar(); hbox.add(new FxButton("Clear", () -> clear() )); hbox.add(new FxButton("Copy", () -> copyAllText() )); hbox.add(new FxButton("Paste", () -> pasteAllText() )); hbox.add(new FxButton("Paste Html", () -> pasteAllHtml() )); hbox.addSeparator(); hbox.add(new FxButton("Wrap", () -> wrapToggle() )); hbox.add(new FxButton("Font(-)", () -> decreaseTextSize() )); hbox.add(new FxButton("Font(+)", () -> increaseTextSize() )); VBox.setVgrow(hbox.get(), Priority.NEVER); VBox.setVgrow(text, Priority.ALWAYS); vbox = new FxVBox(); vbox.add(hbox.get()); vbox.add(text); } } @Override public Node get() { if( vbox != null ) { return vbox.get(); } else { return text; } } public void setFontSize(int size) { if( size > 0 ) { textSize = size; text.setStyle("-fx-font-size: " + size + ";"); //1em = 50px } } public void increaseTextSize() { textSize++; setFontSize(textSize); } public void decreaseTextSize() { if( textSize > 1 ) { textSize--; setFontSize(textSize); } } public String getText() { return text.getText(); } public void setText(String s) { text.setText(s); } public void appendText(String s) { text.appendText(s); } public void clear() { text.clear(); } public void copy() { text.copy(); } public void paste() { text.paste(); } public void clearAllText() { text.clear(); } public void copyAllText() { text.selectAll(); text.copy(); text.deselect(); } public void pasteAllText() { text.clear(); text.paste(); } public void pasteAllHtml() { final Clipboard clipboard = Clipboard.getSystemClipboard(); String data; if( clipboard.hasHtml() ) { data = clipboard.getHtml(); } else { data = clipboard.getString(); } text.setText(data); } public void insert(int index, String data) { text.insertText(index, data); } public void append(String data) { text.appendText(data); } public void wrapToggle() { text.setWrapText( ! text.isWrapText() ); } } |
댓글 없음:
댓글 쓰기