1012 ** let's just use the default.... 1013 */ 1014 if ((fontSizeComboBox.getValue() == null) || !fontSizeComboBox.getValue().equals(sizeFontMap.get(SIZE_SMALL))) { 1015 fontSizeComboBox.setValue(sizeFontMap.get(SIZE_SMALL)); 1016 } 1017 } 1018 } 1019 1020 boldButton.setDisable(!isCommandEnabled(BOLD.getCommand())); 1021 boldButton.setSelected(getCommandState(BOLD.getCommand())); 1022 italicButton.setDisable(!isCommandEnabled(ITALIC.getCommand())); 1023 italicButton.setSelected(getCommandState(ITALIC.getCommand())); 1024 underlineButton.setDisable(!isCommandEnabled(UNDERLINE.getCommand())); 1025 underlineButton.setSelected(getCommandState(UNDERLINE.getCommand())); 1026 strikethroughButton.setDisable(!isCommandEnabled(STRIKETHROUGH.getCommand())); 1027 strikethroughButton.setSelected(getCommandState(STRIKETHROUGH.getCommand())); 1028 1029 fgColorButton.setDisable(!isCommandEnabled(FOREGROUND_COLOR.getCommand())); 1030 String foregroundColorValue = getCommandValue(FOREGROUND_COLOR.getCommand()); 1031 if (foregroundColorValue != null) { 1032 Color c = Color.web(rgbToHex((String)foregroundColorValue)); 1033 fgColorButton.setValue(c); 1034 } 1035 1036 bgColorButton.setDisable(!isCommandEnabled(BACKGROUND_COLOR.getCommand())); 1037 String backgroundColorValue = getCommandValue(BACKGROUND_COLOR.getCommand()); 1038 if (backgroundColorValue != null) { 1039 Color c = Color.web(rgbToHex((String)backgroundColorValue)); 1040 bgColorButton.setValue(c); 1041 } 1042 1043 atomicityCount = atomicityCount == 0 ? 0 : --atomicityCount; 1044 } 1045 1046 private void enableToolbar(final boolean enable) { 1047 Platform.runLater(() -> { 1048 1049 // Make sure buttons have been created to avoid NPE 1050 if (copyButton == null) return; 1051 1052 /* 1053 ** if we're to enable, we still only enable 1054 ** the cut/copy/paste buttons that make sense 1055 */ 1056 if (enable) { 1057 copyButton.setDisable(!isCommandEnabled(COPY.getCommand())); 1058 cutButton.setDisable(!isCommandEnabled(CUT.getCommand())); 1059 pasteButton.setDisable(!isCommandEnabled(PASTE.getCommand())); 1102 private void setContentEditable(boolean b) { 1103 HTMLDocument htmlDocument = (HTMLDocument)webPage.getDocument(webPage.getMainFrame()); 1104 HTMLElement htmlDocumentElement = (HTMLElement)htmlDocument.getDocumentElement(); 1105 HTMLElement htmlBodyElement = (HTMLElement)htmlDocumentElement.getElementsByTagName("body").item(0); 1106 htmlBodyElement.setAttribute("contenteditable", Boolean.toString(b)); 1107 } 1108 1109 private void setDesignMode(String mode) { 1110 HTMLDocumentImpl htmlDocumentImpl = (HTMLDocumentImpl)webPage.getDocument(webPage.getMainFrame()); 1111 htmlDocumentImpl.setDesignMode(mode); 1112 } 1113 1114 private boolean getCommandState(String command) { 1115 return webPage.queryCommandState(command); 1116 } 1117 1118 private String getCommandValue(String command) { 1119 return webPage.queryCommandValue(command); 1120 } 1121 1122 private static String rgbToHex(String value) { 1123 if (value.startsWith("rgba")) { 1124 String[] components = value.substring(value.indexOf('(') + 1, value.lastIndexOf(')')).split(","); 1125 value = String.format("#%02X%02X%02X%02X", 1126 Integer.parseInt(components[0].trim()), 1127 Integer.parseInt(components[1].trim()), 1128 Integer.parseInt(components[2].trim()), 1129 Integer.parseInt(components[3].trim())); 1130 // The default background color for WebView, according to the HTML 1131 // standard is rgba=#00000000 (black). The canvas background is expected 1132 // to be white. 1133 if ("#00000000".equals(value)) { 1134 return "#FFFFFFFF"; 1135 } 1136 } else if (value.startsWith("rgb")) { 1137 String[] components = value.substring(value.indexOf('(') + 1, value.lastIndexOf(')')).split(","); 1138 value = String.format("#%02X%02X%02X", 1139 Integer.parseInt(components[0].trim()), 1140 Integer.parseInt(components[1].trim()), 1141 Integer.parseInt(components[2].trim())); 1142 } 1143 1144 return value; 1145 } 1146 1147 private void applyTextFormatting() { 1148 if (getCommandState(BULLETS.getCommand()) || getCommandState(NUMBERS.getCommand())) { 1149 return; 1150 } 1151 1152 if (webPage.getClientCommittedTextLength() == 0) { 1153 String format = formatStyleMap.get(formatComboBox.getValue()); 1154 String font = fontFamilyComboBox.getValue().toString(); 1155 1156 executeCommand(FORMAT.getCommand(), format); 1157 executeCommand(FONT_FAMILY.getCommand(), font); 1158 } 1159 } 1160 1161 void print(PrinterJob job) { 1162 webView.getEngine().print(job); 1163 } 1164 | 1012 ** let's just use the default.... 1013 */ 1014 if ((fontSizeComboBox.getValue() == null) || !fontSizeComboBox.getValue().equals(sizeFontMap.get(SIZE_SMALL))) { 1015 fontSizeComboBox.setValue(sizeFontMap.get(SIZE_SMALL)); 1016 } 1017 } 1018 } 1019 1020 boldButton.setDisable(!isCommandEnabled(BOLD.getCommand())); 1021 boldButton.setSelected(getCommandState(BOLD.getCommand())); 1022 italicButton.setDisable(!isCommandEnabled(ITALIC.getCommand())); 1023 italicButton.setSelected(getCommandState(ITALIC.getCommand())); 1024 underlineButton.setDisable(!isCommandEnabled(UNDERLINE.getCommand())); 1025 underlineButton.setSelected(getCommandState(UNDERLINE.getCommand())); 1026 strikethroughButton.setDisable(!isCommandEnabled(STRIKETHROUGH.getCommand())); 1027 strikethroughButton.setSelected(getCommandState(STRIKETHROUGH.getCommand())); 1028 1029 fgColorButton.setDisable(!isCommandEnabled(FOREGROUND_COLOR.getCommand())); 1030 String foregroundColorValue = getCommandValue(FOREGROUND_COLOR.getCommand()); 1031 if (foregroundColorValue != null) { 1032 Color c = getColor(foregroundColorValue); 1033 fgColorButton.setValue(c); 1034 } 1035 1036 bgColorButton.setDisable(!isCommandEnabled(BACKGROUND_COLOR.getCommand())); 1037 String backgroundColorValue = getCommandValue(BACKGROUND_COLOR.getCommand()); 1038 if (backgroundColorValue != null) { 1039 Color c = getColor(backgroundColorValue); 1040 bgColorButton.setValue(c); 1041 } 1042 1043 atomicityCount = atomicityCount == 0 ? 0 : --atomicityCount; 1044 } 1045 1046 private void enableToolbar(final boolean enable) { 1047 Platform.runLater(() -> { 1048 1049 // Make sure buttons have been created to avoid NPE 1050 if (copyButton == null) return; 1051 1052 /* 1053 ** if we're to enable, we still only enable 1054 ** the cut/copy/paste buttons that make sense 1055 */ 1056 if (enable) { 1057 copyButton.setDisable(!isCommandEnabled(COPY.getCommand())); 1058 cutButton.setDisable(!isCommandEnabled(CUT.getCommand())); 1059 pasteButton.setDisable(!isCommandEnabled(PASTE.getCommand())); 1102 private void setContentEditable(boolean b) { 1103 HTMLDocument htmlDocument = (HTMLDocument)webPage.getDocument(webPage.getMainFrame()); 1104 HTMLElement htmlDocumentElement = (HTMLElement)htmlDocument.getDocumentElement(); 1105 HTMLElement htmlBodyElement = (HTMLElement)htmlDocumentElement.getElementsByTagName("body").item(0); 1106 htmlBodyElement.setAttribute("contenteditable", Boolean.toString(b)); 1107 } 1108 1109 private void setDesignMode(String mode) { 1110 HTMLDocumentImpl htmlDocumentImpl = (HTMLDocumentImpl)webPage.getDocument(webPage.getMainFrame()); 1111 htmlDocumentImpl.setDesignMode(mode); 1112 } 1113 1114 private boolean getCommandState(String command) { 1115 return webPage.queryCommandState(command); 1116 } 1117 1118 private String getCommandValue(String command) { 1119 return webPage.queryCommandValue(command); 1120 } 1121 1122 private Color getColor(String value) { 1123 Color color = Color.web(value); 1124 /* The default background color for WebView, according to the HTML 1125 * standard is rgba=#00000000 (black). The canvas background is expected 1126 * to be white. 1127 */ 1128 if (color.toString().equals("0x00000000")) { 1129 color = Color.web("#FFFFFFFF"); 1130 } 1131 return color; 1132 } 1133 1134 private void applyTextFormatting() { 1135 if (getCommandState(BULLETS.getCommand()) || getCommandState(NUMBERS.getCommand())) { 1136 return; 1137 } 1138 1139 if (webPage.getClientCommittedTextLength() == 0) { 1140 String format = formatStyleMap.get(formatComboBox.getValue()); 1141 String font = fontFamilyComboBox.getValue().toString(); 1142 1143 executeCommand(FORMAT.getCommand(), format); 1144 executeCommand(FONT_FAMILY.getCommand(), font); 1145 } 1146 } 1147 1148 void print(PrinterJob job) { 1149 webView.getEngine().print(job); 1150 } 1151 |