Advertisement
Guest User

Untitled

a guest
Nov 20th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. hideImageNodesMatching(htmlEditor, Pattern.compile(".*(Cut|Copy|Paste).*"), 0);
  2. Node seperator = htmlEditor.lookup(".separator");
  3. seperator.setVisible(false); seperator.setManaged(false);
  4.  
  5. // modify font selections.
  6. int i = 0;
  7. for (Node candidate: (htmlEditor.lookupAll("MenuButton"))) {
  8. // fonts are selected by the second menu in the htmlEditor.
  9. if (candidate instanceof MenuButton && i == 1) {
  10. // limit the font selections to our predefined list.
  11. MenuButton menuButton = (MenuButton) candidate;
  12. List<MenuItem> removalList = FXCollections.observableArrayList();
  13. final List<MenuItem> fontSelections = menuButton.getItems();
  14. for (MenuItem item: fontSelections) {
  15. if (!limitedFonts.contains(item.getText())) {
  16. removalList.add(item);
  17. }
  18. }
  19. fontSelections.removeAll(removalList);
  20. // Select a font from out limited font selection.
  21. // Selection done in Platform.runLater because if you try to do
  22. // the selection immediately, it won't take place.
  23. Platform.runLater(new Runnable() {
  24. @Override public void run() {
  25. boolean fontSelected = false;
  26. for (final MenuItem item: fontSelections) {
  27. if ("Comic Sans MS".equals(item.getText())) {
  28. if (item instanceof RadioMenuItem) {
  29. ((RadioMenuItem) item).setSelected(true);
  30. fontSelected = true;
  31. }
  32. }
  33. }
  34. if (!fontSelected && fontSelections.size() > 0 && fontSelections.get(0) instanceof RadioMenuItem) {
  35. ((RadioMenuItem) fontSelections.get(0)).setSelected(true);
  36. }
  37. }
  38. });
  39. }
  40. i++;
  41. }
  42. // add a custom button to the top toolbar.
  43. Node node = htmlEditor.lookup(".top-toolbar");
  44. if (node instanceof ToolBar) {
  45. ToolBar bar = (ToolBar) node;
  46. ImageView graphic = new ImageView(new Image("http://bluebuddies.com/gallery/title/jpg/Smurf_Fun_100x100.jpg", 32, 32, true, true));
  47. graphic.setEffect(new DropShadow());
  48. Button smurfButton = new Button("", graphic);
  49. bar.getItems().add(smurfButton);
  50. smurfButton.setOnAction(new EventHandler<ActionEvent>() {
  51. @Override public void handle(ActionEvent arg0) {
  52. htmlEditor.setHtmlText("<font face='Comic Sans MS' color='blue'>Smurfs are having fun :-)</font>");
  53. }
  54. });
  55. }
  56. }
  57.  
  58. // hide buttons containing nodes whose image url matches a given name pattern.
  59. public void hideImageNodesMatching(Node node, Pattern imageNamePattern, int depth) {
  60. if (node instanceof ImageView) {
  61. ImageView imageView = (ImageView) node;
  62. String url = imageView.getImage().impl_getUrl();
  63. if (url != null && imageNamePattern.matcher(url).matches()) {
  64. Node button = imageView.getParent().getParent();
  65. button.setVisible(false); button.setManaged(false);
  66. }
  67. }
  68. if (node instanceof Parent)
  69. for (Node child : ((Parent) node).getChildrenUnmodifiable())
  70. hideImageNodesMatching(child, imageNamePattern, depth + 1);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement