Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hideImageNodesMatching(htmlEditor, Pattern.compile(".*(Cut|Copy|Paste).*"), 0);
- Node seperator = htmlEditor.lookup(".separator");
- seperator.setVisible(false); seperator.setManaged(false);
- // modify font selections.
- int i = 0;
- for (Node candidate: (htmlEditor.lookupAll("MenuButton"))) {
- // fonts are selected by the second menu in the htmlEditor.
- if (candidate instanceof MenuButton && i == 1) {
- // limit the font selections to our predefined list.
- MenuButton menuButton = (MenuButton) candidate;
- List<MenuItem> removalList = FXCollections.observableArrayList();
- final List<MenuItem> fontSelections = menuButton.getItems();
- for (MenuItem item: fontSelections) {
- if (!limitedFonts.contains(item.getText())) {
- removalList.add(item);
- }
- }
- fontSelections.removeAll(removalList);
- // Select a font from out limited font selection.
- // Selection done in Platform.runLater because if you try to do
- // the selection immediately, it won't take place.
- Platform.runLater(new Runnable() {
- @Override public void run() {
- boolean fontSelected = false;
- for (final MenuItem item: fontSelections) {
- if ("Comic Sans MS".equals(item.getText())) {
- if (item instanceof RadioMenuItem) {
- ((RadioMenuItem) item).setSelected(true);
- fontSelected = true;
- }
- }
- }
- if (!fontSelected && fontSelections.size() > 0 && fontSelections.get(0) instanceof RadioMenuItem) {
- ((RadioMenuItem) fontSelections.get(0)).setSelected(true);
- }
- }
- });
- }
- i++;
- }
- // add a custom button to the top toolbar.
- Node node = htmlEditor.lookup(".top-toolbar");
- if (node instanceof ToolBar) {
- ToolBar bar = (ToolBar) node;
- ImageView graphic = new ImageView(new Image("http://bluebuddies.com/gallery/title/jpg/Smurf_Fun_100x100.jpg", 32, 32, true, true));
- graphic.setEffect(new DropShadow());
- Button smurfButton = new Button("", graphic);
- bar.getItems().add(smurfButton);
- smurfButton.setOnAction(new EventHandler<ActionEvent>() {
- @Override public void handle(ActionEvent arg0) {
- htmlEditor.setHtmlText("<font face='Comic Sans MS' color='blue'>Smurfs are having fun :-)</font>");
- }
- });
- }
- }
- // hide buttons containing nodes whose image url matches a given name pattern.
- public void hideImageNodesMatching(Node node, Pattern imageNamePattern, int depth) {
- if (node instanceof ImageView) {
- ImageView imageView = (ImageView) node;
- String url = imageView.getImage().impl_getUrl();
- if (url != null && imageNamePattern.matcher(url).matches()) {
- Node button = imageView.getParent().getParent();
- button.setVisible(false); button.setManaged(false);
- }
- }
- if (node instanceof Parent)
- for (Node child : ((Parent) node).getChildrenUnmodifiable())
- hideImageNodesMatching(child, imageNamePattern, depth + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement