开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
Course2TextEditor
/
src
/
application
/
TextProController.java
Course2TextEditor
/
src
/
application
/
TextProController.java
TextProController.java 5.92 KB
一键复制 编辑 原始数据 按行查看 历史
Lu Ning 提交于 2016年04月17日 16:18 +08:00 . initial commit
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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
package application;
import java.util.function.Consumer;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TextProController {
private final static double DEFAULT_SPACING = 55;
private final static double CONTROL_HEIGHT = 132;
private final static double SPACE_DIV = 8.5;
private final static double BUTTON_WIDTH = 160.0;
private final static double RBOX_THRESHOLD = 520; // threshold to change spacing of right VBox
// used when showing new stage/scene
private MainApp mainApp;
// used for getting new objects
private LaunchClass launch;
// UI Controls
private AutoSpellingTextArea textBox;
@FXML
private VBox leftPane;
@FXML
private VBox rightBox;
@FXML
private HBox container;
@FXML
private Label fLabel;
@FXML
private Pane bufferPane;
@FXML
private TextField fleschField;
@FXML
private CheckBox autocompleteBox;
@FXML
private CheckBox spellingBox;
//private Node
/**
* Initializes the controller class. This method is automatically called
* after the fxml file has been loaded.
*
* Initialize and add text area to application
*/
@FXML
private void initialize() {
// make field displaying flesch score read-only
fleschField.setEditable(false);
launch = new LaunchClass();
// instantiate and add custom text area
spelling.Dictionary dic = launch.getDictionary();
textBox = new AutoSpellingTextArea(launch.getAutoComplete(), launch.getSpellingSuggest(dic), dic);
textBox.setPrefSize(570, 492);
textBox.setStyle("-fx-font-size: 14px");
textBox.setWrapText(true);
// add text area as first child of left VBox
ObservableList<Node> nodeList = leftPane.getChildren();
Node firstChild = nodeList.get(0);
nodeList.set(0, textBox);
nodeList.add(firstChild);
VBox.setVgrow(textBox, Priority.ALWAYS);
// ADD LISTENERS FOR ADJUSTING ON RESIZE
container.widthProperty().addListener(li -> {
if((container.getWidth() - leftPane.getPrefWidth()) < BUTTON_WIDTH) {
rightBox.setVisible(false);
}
else {
rightBox.setVisible(true);
}
});
// function for setting spacing of rightBox
Consumer<VBox> adjustSpacing = box -> {
if(container.getHeight() < RBOX_THRESHOLD) {
rightBox.setSpacing((container.getHeight() - CONTROL_HEIGHT)/SPACE_DIV);
}
else {
rightBox.setSpacing(DEFAULT_SPACING);
}
};
container.heightProperty().addListener(li -> {
adjustSpacing.accept(rightBox);
});
rightBox.visibleProperty().addListener( li -> {
if(rightBox.isVisible()) {
container.getChildren().add(rightBox);
adjustSpacing.accept(rightBox);
}
else {
container.getChildren().remove(rightBox);
}
});
}
/**
* Is called by the main application to give a reference back to itself.
* Also give reference to AutoSpellingTextArea
*
*
* @param mainApp
*/
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
}
@FXML
private void handleFleschIndex() {
String text = textBox.getText();
double fIndex = 0;
// check if text input
if(!text.equals("")) {
// create Document representation of current text
document.Document doc = launch.getDocument(text);
fIndex = doc.getFleschScore();
//get string with two decimal places for index to
String fString = String.format("%.2f", fIndex);
// display string in text field
fleschField.setText(fString);
}
else {
// reset text field
fleschField.setText("");
mainApp.showInputErrorDialog("No text entered.");
}
}
@FXML
private void handleLoadText() {
//return string??
mainApp.showLoadFileDialog(textBox);
//textBox.appendText(text);
}
@FXML
private void handleEditDistance() {
String selectedText = textBox.getSelectedText();
mainApp.showEditDistanceDialog(selectedText);
}
@FXML
private void handleMarkovText() {
// get MTG object
textgen.MarkovTextGenerator mtg = launch.getMTG();
Task<textgen.MarkovTextGenerator> task = new Task<textgen.MarkovTextGenerator>() {
@Override
public textgen.MarkovTextGenerator call() {
// process long-running computation, data retrieval, etc...
mtg.retrain(textBox.getText());
return mtg;
}
};
// stage for load dialog
final Stage loadStage = new Stage();
// consume close request until task is finished
loadStage.setOnCloseRequest( e -> {
if(!task.isDone()) {
e.consume();
}
});
// show loading dialog when task is running
task.setOnRunning( e -> {
mainApp.showLoadStage(loadStage, "Training MTG...");
});
// MTG trained, close loading dialog, show MTG dialog
task.setOnSucceeded(e -> {
loadStage.close();
textgen.MarkovTextGenerator result = task.getValue();
mainApp.showMarkovDialog(result);
});
Thread thread = new Thread(task);
thread.start();
}
@FXML
private void handleAutoComplete() {
if(autocompleteBox.isSelected()) {
textBox.setAutoComplete(true);
}
else {
textBox.setAutoComplete(false);
}
}
@FXML
private void handleSpelling() {
if(spellingBox.isSelected()) {
textBox.setSpelling(true);
}
else {
textBox.setSpelling(false);
}
}
@FXML
private void handleClear() {
textBox.clear();
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
暂无标签
BSD-2-Clause
使用 BSD-2-Clause 开源许可协议
, Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/luning/Course2TextEditor.git
git@gitee.com:luning/Course2TextEditor.git
luning
Course2TextEditor
Course2TextEditor
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /