Java Examples for javax.swing.text.html.StyleSheet
The following java examples will help you to understand the usage of javax.swing.text.html.StyleSheet. These source code samples are taken from different open source projects.
Example 1
| Project: TimeFlow-master File: HtmlDisplay.java View source code |
public static JEditorPane create() {
JEditorPane p = new JEditorPane();
p.setEditable(false);
p.setContentType("text/html");
Font font = UIManager.getFont("Label.font");
String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }";
StyleSheet styles = ((HTMLDocument) p.getDocument()).getStyleSheet();
styles.addRule(bodyRule);
return p;
}Example 2
| Project: jsystem-master File: HTMLJavaDocView.java View source code |
protected EditorKit createDefaultEditorKit() {
if (htmlKit == null) {
htmlKit = new HTMLEditorKit();
setEditorKit(htmlKit);
if (htmlKit.getStyleSheet().getStyleSheets() != null)
return htmlKit;
javax.swing.text.html.StyleSheet css = new javax.swing.text.html.StyleSheet();
java.awt.Font f = /*new javax.swing.JTextArea().*/
getFont();
css.addRule(// NOI18N
new StringBuffer("body { font-size: ").append(f.getSize()).append("; font-family: ").append(f.getName()).append(// NOI18N
"; }").toString());
css.addStyleSheet(htmlKit.getStyleSheet());
htmlKit.setStyleSheet(css);
}
return htmlKit;
}Example 3
| Project: antlrworks2-master File: HTMLDocView.java View source code |
private void setBodyFontInCSS() {
javax.swing.text.html.StyleSheet css = new javax.swing.text.html.StyleSheet();
FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class);
Coloring c = Coloring.fromAttributeSet(fcs.getFontColors(FontColorNames.DEFAULT_COLORING));
java.awt.Font f = c.getFont();
css.addRule(// NOI18N
new StringBuilder("body { font-size: ").append(f.getSize()).append("; font-family: ").append(// NOI18N
getFont().getFamily()).append("; color: ").append(getForegroundColor()).append(// NOI18N
";}").toString());
// do not use monospaced font, just adjust fontsize
css.addStyleSheet(htmlKit.getStyleSheet());
htmlKit.setStyleSheet(css);
}Example 4
| Project: goworks-master File: HTMLDocView.java View source code |
private void setBodyFontInCSS() {
javax.swing.text.html.StyleSheet css = new javax.swing.text.html.StyleSheet();
FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class);
Coloring c = Coloring.fromAttributeSet(fcs.getFontColors(FontColorNames.DEFAULT_COLORING));
java.awt.Font f = c.getFont();
css.addRule(// NOI18N
new StringBuilder("body { font-size: ").append(f.getSize()).append("; font-family: ").append(// NOI18N
getFont().getFamily()).append("; color: ").append(getForegroundColor()).append(// NOI18N
";}").toString());
// do not use monospaced font, just adjust fontsize
css.addStyleSheet(htmlKit.getStyleSheet());
htmlKit.setStyleSheet(css);
}Example 5
| Project: openrocket-master File: SlideSetManager.java View source code |
/**
* Load all the tours.
*/
public void load() throws IOException {
slideSets.clear();
List<String> tours = loadTourList();
StyleSheet styleSheet = loadStyleSheet();
for (String fileAndDir : tours) {
String base;
String file;
String fullFileAndDir = baseDir + fileAndDir;
int index = fullFileAndDir.lastIndexOf('/');
if (index >= 0) {
base = fullFileAndDir.substring(0, index);
file = fullFileAndDir.substring(index + 1);
} else {
base = "";
file = "";
}
SlideSetLoader loader = new SlideSetLoader(base);
SlideSet set = loader.load(file);
set.setStyleSheet(styleSheet);
slideSets.put(fileAndDir, set);
}
}Example 6
| Project: josm-master File: HelpBrowser.java View source code |
/**
* Builds the style sheet used in the internal help browser
*
* @return the style sheet
*/
protected StyleSheet buildStyleSheet() {
StyleSheet ss = new StyleSheet();
final String css;
try (CachedFile cf = new CachedFile("resource://data/help-browser.css")) {
css = new String(cf.getByteContent(), StandardCharsets.ISO_8859_1);
} catch (IOException e) {
Main.error(tr("Failed to read CSS file ''help-browser.css''. Exception is: {0}", e.toString()));
Main.error(e);
return ss;
}
ss.addRule(css);
return ss;
}Example 7
| Project: josm-older-master File: HelpBrowser.java View source code |
/**
* Builds the style sheet used in the internal help browser
*
* @return the style sheet
*/
protected StyleSheet buildStyleSheet() {
StyleSheet ss = new StyleSheet();
BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/data/help-browser.css")));
StringBuffer css = new StringBuffer();
try {
String line = null;
while ((line = reader.readLine()) != null) {
css.append(line);
css.append("\n");
}
reader.close();
} catch (Exception e) {
System.err.println(tr("Failed to read CSS file ''help-browser.css''. Exception is: {0}", e.toString()));
e.printStackTrace();
return ss;
}
ss.addRule(css.toString());
return ss;
}Example 8
| Project: openjdk-master File: Test6817933.java View source code |
public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception exception) {
exception.printStackTrace();
return;
}
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
StyleSheet css = new StyleSheet();
css.addRule(STYLE);
HTMLEditorKit kit = new HTMLEditorKit();
kit.setStyleSheet(css);
JFrame frame = new JFrame(STYLE);
frame.add(chooser = new JFileChooser());
frame.setSize(640, 480);
frame.setVisible(true);
}
});
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
toolkit.realSync(500);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
JToggleButton button = get(JToggleButton.class, get(WindowsPlacesBar.class, chooser));
int width = button.getWidth();
int height = button.getHeight() / 3;
Point point = new Point(0, height * 2);
SwingUtilities.convertPointToScreen(point, button);
width += point.x;
height += point.y;
int count = 0;
Robot robot = new Robot();
for (int x = point.x; x < width; x++) {
for (int y = point.y; y < height; y++) {
count += COLOR.equals(robot.getPixelColor(x, y)) ? -2 : 1;
}
}
if (count < 0) {
throw new Exception("TEST ERROR: a lot of red pixels");
}
} catch (Exception exception) {
throw new Error(exception);
} finally {
SwingUtilities.getWindowAncestor(chooser).dispose();
}
}
});
}Example 9
| Project: Rel-master File: BrowserSwing.java View source code |
private void setEnhancedOutputStyle(JTextPane pane) {
pane.setContentType("text/html");
pane.setEditable(false);
HTMLEditorKit editorKit = new HTMLEditorKit();
HTMLDocument defaultDocument = (HTMLDocument) editorKit.createDefaultDocument();
pane.setEditorKit(editorKit);
pane.setDocument(defaultDocument);
StyleSheet css = editorKit.getStyleSheet();
for (String entry : style.getFormattedStyle()) css.addRule(entry);
}Example 10
| Project: ATLauncher-NextGen-master File: Resources.java View source code |
public static StyleSheet makeStyleSheet(String name) { try { if (resources.containsKey(name)) { Object obj = resources.get(name); if (!(obj instanceof StyleSheet)) { throw new RuntimeException("Reference for " + name + " ended up with a bad value, suggested=" + StyleSheet.class.getName() + "; got=" + obj.getClass().getName()); } else { return (StyleSheet) obj; } } else { StyleSheet sheet = new StyleSheet(); Reader reader = new InputStreamReader(System.class.getResourceAsStream("/assets/css/" + name + ".css")); sheet.loadRules(reader, null); reader.close(); resources.put(name, sheet); return sheet; } } catch (Exception ex) { throw new RuntimeException(ex); } }
Example 11
| Project: autopsy-master File: ExtractedContentPanel.java View source code |
private void customizeComponents() {
HTMLEditorKit editorKit = new HTMLEditorKit() {
@Override
public ViewFactory getViewFactory() {
return new HTMLFactory() {
@Override
public View create(Element e) {
View v = super.create(e);
if (v instanceof InlineView) {
return new InlineView(e) {
@Override
public int getBreakWeight(int axis, float pos, float len) {
return GoodBreakWeight;
}
@Override
public View breakView(int axis, int p0, float pos, float len) {
if (axis == View.X_AXIS) {
checkPainter();
int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
if (p0 == getStartOffset() && p1 == getEndOffset()) {
return this;
}
return createFragment(p0, p1);
}
return this;
}
};
} else if (v instanceof ParagraphView) {
return new ParagraphView(e) {
@Override
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
if (r == null) {
r = new SizeRequirements();
}
float pref = layoutPool.getPreferredSpan(axis);
float min = layoutPool.getMinimumSpan(axis);
// Don't include insets, Box.getXXXSpan will include them.
r.minimum = (int) min;
r.preferred = Math.max(r.minimum, (int) pref);
r.maximum = Integer.MAX_VALUE;
r.alignment = 0.5f;
return r;
}
};
}
return v;
}
};
}
};
// set font size manually in an effort to get fonts in this panel to look
// similar to what is in the 'String View' content viewer.
StyleSheet ss = editorKit.getStyleSheet();
//NON-NLS
ss.addRule("body {font-size: 8.5px;}");
extractedTextPane.setEditorKit(editorKit);
sourceComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
IndexedText source = (IndexedText) e.getItem();
setMarkup(source);
}
}
});
setSources(new ArrayList<IndexedText>());
extractedTextPane.setComponentPopupMenu(rightClickMenu);
ActionListener actList = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem jmi = (JMenuItem) e.getSource();
if (jmi.equals(copyMenuItem)) {
extractedTextPane.copy();
} else if (jmi.equals(selectAllMenuItem)) {
extractedTextPane.selectAll();
}
}
};
copyMenuItem.addActionListener(actList);
selectAllMenuItem.addActionListener(actList);
}Example 12
| Project: Desktop-master File: EditNodeTextField.java View source code |
/* (non-Javadoc)
* @see org.freeplane.view.swing.map.INodeTextField#show()
*/
@SuppressWarnings("serial")
@Override
public void show(final RootPaneContainer frame) {
final ModeController modeController = Controller.getCurrentModeController();
final IMapViewManager viewController = modeController.getController().getMapViewManager();
final MTextController textController = (MTextController) TextController.getController(modeController);
nodeView = (NodeView) SwingUtilities.getAncestorOfClass(NodeView.class, parent);
font = parent.getFont();
zoom = viewController.getZoom();
if (zoom != 1F) {
final float fontSize = (int) (Math.rint(font.getSize() * zoom));
font = font.deriveFont(fontSize);
}
final HTMLEditorKit kit = new ScaledEditorKit() {
@Override
public void write(Writer out, Document doc, int pos, int len) throws IOException, BadLocationException {
if (doc instanceof HTMLDocument) {
HTMLWriter w = new SHTMLWriter(out, (HTMLDocument) doc, pos, len);
w.write();
} else {
super.write(out, doc, pos, len);
}
}
};
textfield.setEditorKit(kit);
final InputMap inputMap = textfield.getInputMap();
final ActionMap actionMap = textfield.getActionMap();
actionMap.put(DefaultEditorKit.pasteAction, pasteAction);
inputMap.put((KeyStroke) boldAction.getValue(Action.ACCELERATOR_KEY), "boldAction");
actionMap.put("boldAction", boldAction);
inputMap.put((KeyStroke) italicAction.getValue(Action.ACCELERATOR_KEY), "italicAction");
actionMap.put("italicAction", italicAction);
inputMap.put((KeyStroke) underlineAction.getValue(Action.ACCELERATOR_KEY), "underlineAction");
actionMap.put("underlineAction", underlineAction);
inputMap.put((KeyStroke) redAction.getValue(Action.ACCELERATOR_KEY), "redAction");
actionMap.put("redAction", redAction);
inputMap.put((KeyStroke) greenAction.getValue(Action.ACCELERATOR_KEY), "greenAction");
actionMap.put("greenAction", greenAction);
inputMap.put((KeyStroke) blueAction.getValue(Action.ACCELERATOR_KEY), "blueAction");
actionMap.put("blueAction", blueAction);
inputMap.put((KeyStroke) blackAction.getValue(Action.ACCELERATOR_KEY), "blackAction");
actionMap.put("blackAction", blackAction);
inputMap.put((KeyStroke) defaultColorAction.getValue(Action.ACCELERATOR_KEY), "defaultColorAction");
actionMap.put("defaultColorAction", defaultColorAction);
inputMap.put((KeyStroke) removeFormattingAction.getValue(Action.ACCELERATOR_KEY), "removeFormattingAction");
actionMap.put("removeFormattingAction", removeFormattingAction);
final Color nodeTextColor = parent.getForeground();
textfield.setCaretColor(nodeTextColor);
final StringBuilder ruleBuilder = new StringBuilder(100);
ruleBuilder.append("body {");
ruleBuilder.append("font-family: ").append(font.getFamily()).append(";");
final int fontSize = Math.round(font.getSize() / UITools.FONT_SCALE_FACTOR);
ruleBuilder.append("font-size: ").append(fontSize).append("pt;");
if (font.isItalic()) {
ruleBuilder.append("font-style: italic; ");
}
if (font.isBold()) {
ruleBuilder.append("font-weight: bold; ");
}
ruleBuilder.append("color: ").append(ColorUtils.colorToString(nodeTextColor)).append(";");
final Color bgColor = getBackground();
ruleBuilder.append("background-color: ").append(ColorUtils.colorToString(bgColor)).append(";");
ruleBuilder.append("}\n");
final HTMLDocument document = (HTMLDocument) textfield.getDocument();
final StyleSheet styleSheet = document.getStyleSheet();
styleSheet.addRule(ruleBuilder.toString());
textfield.setText(text);
final MapView mapView = (MapView) viewController.getMapViewComponent();
if (!mapView.isValid())
mapView.validate();
final NodeStyleController nsc = NodeStyleController.getController(modeController);
maxWidth = nsc.getMaxWidth(node);
final Icon icon = parent.getIcon();
if (icon != null) {
maxWidth -= icon.getIconWidth();
maxWidth -= parent.getIconTextGap();
}
maxWidth = mapView.getZoomed(maxWidth);
extraWidth = ResourceController.getResourceController().getIntProperty("editor_extra_width", 80);
extraWidth = mapView.getZoomed(extraWidth);
final TextFieldListener textFieldListener = new TextFieldListener();
this.textFieldListener = textFieldListener;
textfield.addFocusListener(textFieldListener);
textfield.addKeyListener(textFieldListener);
textfield.addMouseListener(textFieldListener);
mapViewChangeListener = new MapViewChangeListener();
Controller.getCurrentController().getMapViewManager().addMapViewChangeListener(mapViewChangeListener);
SpellCheckerController.getController().enableAutoSpell(textfield, true);
mapView.scrollNodeToVisible(nodeView);
assert (parent.isValid());
final int nodeWidth = parent.getWidth();
final int nodeHeight = parent.getHeight();
final Dimension textFieldSize;
textfield.setBorder(new MatteBorder(2, 2, 2, 2, nodeView.getSelectedColor()));
textFieldSize = textfield.getPreferredSize();
textFieldSize.width += 1;
if (textFieldSize.width < extraWidth)
textFieldSize.width = extraWidth;
if (textFieldSize.width < 10)
textFieldSize.width = 10;
if (textFieldSize.width > maxWidth) {
textFieldSize.width = maxWidth;
setLineWrap();
textFieldSize.height = textfield.getPreferredSize().height;
}
final Rectangle textR = ((ZoomableLabelUI) parent.getUI()).getTextR(parent);
textFieldSize.width = Math.max(textFieldSize.width, textR.width);
textFieldSize.height = Math.max(textFieldSize.height, textR.height);
textfield.setSize(textFieldSize.width, textFieldSize.height);
horizontalSpace = Math.max(nodeWidth - textFieldSize.width, textR.x);
verticalSpace = Math.max(nodeHeight - textFieldSize.height, textR.y);
final Dimension newParentSize = new Dimension(horizontalSpace + textFieldSize.width, verticalSpace + textFieldSize.height);
parent.setPreferredSize(newParentSize);
final Point location = new Point(textR.x - 2, textR.y);
if (!layoutMapOnTextChange)
UITools.convertPointToAncestor(parent, location, mapView);
textfield.setBounds(location.x, location.y, textFieldSize.width, textFieldSize.height);
parent.setText("");
if (nodeView.isRoot() && parent instanceof MainView)
parent.setHorizontalAlignment(JLabel.LEFT);
if (layoutMapOnTextChange)
parent.add(textfield, 0);
else
mapView.add(textfield, 0);
final EventBuffer eventQueue = MTextController.getController().getEventQueue();
KeyEvent firstEvent = eventQueue.getFirstEvent();
redispatchKeyEvents(textfield, firstEvent);
if (firstEvent == null) {
MouseEvent currentEvent = eventQueue.getMouseEvent();
int pos = document.getLength();
if (currentEvent != null) {
MouseEvent mouseEvent = (MouseEvent) currentEvent;
if (mouseEvent.getComponent().equals(parent)) {
final Point point = mouseEvent.getPoint();
point.x -= textR.x;
point.y -= textR.y;
pos = textfield.viewToModel(point);
}
}
textfield.setCaretPosition(pos);
}
document.addDocumentListener(documentListener);
if (textController.isMinimized(node)) {
layout();
}
textfield.repaint();
textfield.requestFocusInWindow();
}Example 13
| Project: Docear-master File: EditNodeTextField.java View source code |
/* (non-Javadoc)
* @see org.freeplane.view.swing.map.INodeTextField#show()
*/
@SuppressWarnings("serial")
@Override
public void show(final RootPaneContainer frame) {
final ModeController modeController = Controller.getCurrentModeController();
final ViewController viewController = modeController.getController().getViewController();
final MTextController textController = (MTextController) TextController.getController(modeController);
nodeView = (NodeView) SwingUtilities.getAncestorOfClass(NodeView.class, parent);
font = parent.getFont();
zoom = viewController.getZoom();
if (zoom != 1F) {
final float fontSize = (int) (Math.rint(font.getSize() * zoom));
font = font.deriveFont(fontSize);
}
final HTMLEditorKit kit = new ScaledEditorKit() {
@Override
public void write(Writer out, Document doc, int pos, int len) throws IOException, BadLocationException {
if (doc instanceof HTMLDocument) {
HTMLWriter w = new SHTMLWriter(out, (HTMLDocument) doc, pos, len);
w.write();
} else {
super.write(out, doc, pos, len);
}
}
};
textfield.setEditorKit(kit);
final InputMap inputMap = textfield.getInputMap();
final ActionMap actionMap = textfield.getActionMap();
actionMap.put(DefaultEditorKit.pasteAction, pasteAction);
inputMap.put((KeyStroke) boldAction.getValue(Action.ACCELERATOR_KEY), "boldAction");
actionMap.put("boldAction", boldAction);
inputMap.put((KeyStroke) italicAction.getValue(Action.ACCELERATOR_KEY), "italicAction");
actionMap.put("italicAction", italicAction);
inputMap.put((KeyStroke) underlineAction.getValue(Action.ACCELERATOR_KEY), "underlineAction");
actionMap.put("underlineAction", underlineAction);
inputMap.put((KeyStroke) redAction.getValue(Action.ACCELERATOR_KEY), "redAction");
actionMap.put("redAction", redAction);
inputMap.put((KeyStroke) greenAction.getValue(Action.ACCELERATOR_KEY), "greenAction");
actionMap.put("greenAction", greenAction);
inputMap.put((KeyStroke) blueAction.getValue(Action.ACCELERATOR_KEY), "blueAction");
actionMap.put("blueAction", blueAction);
inputMap.put((KeyStroke) blackAction.getValue(Action.ACCELERATOR_KEY), "blackAction");
actionMap.put("blackAction", blackAction);
inputMap.put((KeyStroke) defaultColorAction.getValue(Action.ACCELERATOR_KEY), "defaultColorAction");
actionMap.put("defaultColorAction", defaultColorAction);
inputMap.put((KeyStroke) removeFormattingAction.getValue(Action.ACCELERATOR_KEY), "removeFormattingAction");
actionMap.put("removeFormattingAction", removeFormattingAction);
final Color nodeTextColor = parent.getForeground();
textfield.setCaretColor(nodeTextColor);
final StringBuilder ruleBuilder = new StringBuilder(100);
ruleBuilder.append("body {");
ruleBuilder.append("font-family: ").append(font.getFamily()).append(";");
final int fontSize = Math.round(font.getSize() / UITools.FONT_SCALE_FACTOR);
ruleBuilder.append("font-size: ").append(fontSize).append("pt;");
if (font.isItalic()) {
ruleBuilder.append("font-style: italic; ");
}
if (font.isBold()) {
ruleBuilder.append("font-weight: bold; ");
}
ruleBuilder.append("color: ").append(ColorUtils.colorToString(nodeTextColor)).append(";");
final Color bgColor = getBackground();
ruleBuilder.append("background-color: ").append(ColorUtils.colorToString(bgColor)).append(";");
ruleBuilder.append("}\n");
final HTMLDocument document = (HTMLDocument) textfield.getDocument();
final StyleSheet styleSheet = document.getStyleSheet();
styleSheet.addRule(ruleBuilder.toString());
textfield.setText(text);
final MapView mapView = (MapView) viewController.getMapView();
if (!mapView.isValid())
mapView.validate();
final NodeStyleController nsc = NodeStyleController.getController(modeController);
maxWidth = nsc.getMaxWidth(node);
final Icon icon = parent.getIcon();
if (icon != null) {
maxWidth -= icon.getIconWidth();
maxWidth -= parent.getIconTextGap();
}
maxWidth = mapView.getZoomed(maxWidth);
extraWidth = ResourceController.getResourceController().getIntProperty("editor_extra_width", 80);
extraWidth = mapView.getZoomed(extraWidth);
final TextFieldListener textFieldListener = new TextFieldListener();
this.textFieldListener = textFieldListener;
textfield.addFocusListener(textFieldListener);
textfield.addKeyListener(textFieldListener);
textfield.addMouseListener(textFieldListener);
mapViewChangeListener = new MapViewChangeListener();
Controller.getCurrentController().getMapViewManager().addMapViewChangeListener(mapViewChangeListener);
SpellCheckerController.getController().enableAutoSpell(textfield, true);
mapView.scrollNodeToVisible(nodeView);
assert (parent.isValid());
final int nodeWidth = parent.getWidth();
final int nodeHeight = parent.getHeight();
final Dimension textFieldSize;
textfield.setBorder(new MatteBorder(2, 2, 2, 2, nodeView.getSelectedColor()));
textFieldSize = textfield.getPreferredSize();
textFieldSize.width += 1;
if (textFieldSize.width < extraWidth)
textFieldSize.width = extraWidth;
if (textFieldSize.width < 10)
textFieldSize.width = 10;
if (textFieldSize.width > maxWidth) {
textFieldSize.width = maxWidth;
setLineWrap();
textFieldSize.height = textfield.getPreferredSize().height;
}
final Rectangle textR = ((ZoomableLabelUI) parent.getUI()).getTextR(parent);
textFieldSize.width = Math.max(textFieldSize.width, textR.width);
textFieldSize.height = Math.max(textFieldSize.height, textR.height);
textfield.setSize(textFieldSize.width, textFieldSize.height);
horizontalSpace = Math.max(nodeWidth - textFieldSize.width, textR.x);
verticalSpace = Math.max(nodeHeight - textFieldSize.height, textR.y);
final Dimension newParentSize = new Dimension(horizontalSpace + textFieldSize.width, verticalSpace + textFieldSize.height);
parent.setPreferredSize(newParentSize);
final Point location = new Point(textR.x - 2, textR.y);
if (!layoutMapOnTextChange)
UITools.convertPointToAncestor(parent, location, mapView);
textfield.setBounds(location.x, location.y, textFieldSize.width, textFieldSize.height);
parent.setText("");
if (nodeView.isRoot() && parent instanceof MainView)
parent.setHorizontalAlignment(JLabel.LEFT);
if (layoutMapOnTextChange)
parent.add(textfield, 0);
else
mapView.add(textfield, 0);
final EventBuffer eventQueue = MTextController.getController().getEventQueue();
KeyEvent firstEvent = eventQueue.getFirstEvent();
redispatchKeyEvents(textfield, firstEvent);
if (firstEvent == null) {
MouseEvent currentEvent = eventQueue.getMouseEvent();
int pos = document.getLength();
if (currentEvent != null) {
MouseEvent mouseEvent = (MouseEvent) currentEvent;
if (mouseEvent.getComponent().equals(parent)) {
final Point point = mouseEvent.getPoint();
point.x -= textR.x;
point.y -= textR.y;
pos = textfield.viewToModel(point);
}
}
textfield.setCaretPosition(pos);
}
document.addDocumentListener(documentListener);
if (textController.isMinimized(node)) {
layout();
}
textfield.repaint();
textfield.requestFocusInWindow();
}Example 14
| Project: EKit-for-SCIL-master File: ExtendedHTMLEditorKit.java View source code |
public Document createDefaultDocument() {
StyleSheet styles = getStyleSheet();
StyleSheet ss = new StyleSheet();
ss.addStyleSheet(styles);
ExtendedHTMLDocument doc = new ExtendedHTMLDocument(ss);
doc.setParser(getParser());
doc.setAsynchronousLoadPriority(4);
doc.setTokenThreshold(100);
return doc;
}Example 15
| Project: ekit-master File: EkitCore.java View source code |
protected void insertLocalImage(File whatImage) throws IOException, BadLocationException {
try {
if (whatImage == null) {
whatImage = getImageFromChooser(imageChooserStartDir, extsIMG, Translatrix.getTranslationString("FiletypeIMG"));
}
if (whatImage != null) {
BufferedImage resizeImageJpg = getNewImage(ImageIO.read(whatImage));
int randomNumber = random.nextInt();
File file = new File(FileUtilizator.RamadaSenderTemporaryFolder + randomNumber + "mkyong_jpg.jpg");
FileUtilizator.putFile(randomNumber + "mkyong_jpg.jpg");
ImageIO.write(resizeImageJpg, "jpg", file);
imageChooserStartDir = file.getParent();
int caretPos = jtpMain.getCaretPosition();
htmlKit.insertHTML(htmlDoc, caretPos, "<IMG STYLE=\"width: 600px;\" SRC=\"" + file + "\">", 0, 0, HTML.Tag.IMG);
StyleSheet styleSheet = htmlKit.getStyleSheet();
styleSheet.addRule(String.format("img {width: 400px; }"));
htmlKit.setStyleSheet(styleSheet);
jtpMain.setCaretPosition(caretPos + 1);
refreshOnUpdate();
// System.out.println(htmlKit.get);
}
System.out.println(jtpMain.getText());
} catch (Exception e) {
e.printStackTrace();
try {
final String filePath = whatImage.getAbsolutePath();
Thread t = new Thread(new Runnable() {
public void run() {
try {
System.out.println("start proccesing");
OnlineConvert oc = OnlineConvert.create("23e81a25be377d042f8a6d51afbcce44", false);
System.out.println(oc.convert("convert-to-png", OnlineConvert.SOURCE_TYPE_FILE_PATH, filePath, "1245.jpg", null, ""));
System.out.println(oc.getProgress());
String url = oc.getDownloadUrl();
int randomNumber = random.nextInt();
File newFile = new File(FileUtilizator.RamadaSenderTemporaryFolder + randomNumber + "tempffffffffa");
downloadFileFromURL(url, newFile);
FileUtilizator.putFile(randomNumber + "tempffffffffa");
String str = readStream(new FileInputStream(newFile));
int i = str.indexOf("id=\"dropbox_selector\"");
if (i != -1) {
try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
String fileUrl = str.substring(i + 28, i + 28 + str.substring(i + 28).indexOf("\""));
File currFile = new File(FileUtilizator.RamadaSenderTemporaryFolder + randomNumber + "imageekit");
FileUtilizator.putFile(randomNumber + "imageekit");
URL link = new URL(fileUrl);
InputStream in = new BufferedInputStream(link.openStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int n = 0;
while (-1 != (n = in.read(buf))) {
out.write(buf, 0, n);
}
out.close();
in.close();
byte[] response = out.toByteArray();
FileOutputStream fos = new FileOutputStream(currFile);
fos.write(response);
fos.close();
BufferedImage resizeImageJpg = getNewImage(ImageIO.read(currFile));
ImageIO.write(resizeImageJpg, "jpg", currFile);
imageChooserStartDir = currFile.toString();
int caretPos = jtpMain.getCaretPosition();
htmlKit.insertHTML(htmlDoc, caretPos, "<IMG SRC=\"" + currFile + "\">", 0, 0, HTML.Tag.IMG);
jtpMain.setCaretPosition(caretPos + 1);
refreshOnUpdate();
} else {
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(mainWindow, "Please, select the file in normal format", "Information", JOptionPane.INFORMATION_MESSAGE);
}
});
t2.setDaemon(true);
t2.start();
}
System.out.println("end");
} catch (Exception e1) {
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(mainWindow, "Ops, this file can not be load. Please use file in another format.", "Information", JOptionPane.INFORMATION_MESSAGE);
}
});
t2.setDaemon(true);
t2.start();
e1.printStackTrace();
}
}
});
t.start();
new Thread(new Runnable() {
@Override
public void run() {
dlg.setVisible(true);
}
}).start();
t.join();
new Thread(new Runnable() {
@Override
public void run() {
dlg.setVisible(false);
}
}).start();
} catch (Exception e1) {
JOptionPane.showMessageDialog(mainWindow, "Ops, this file can not be load. Please use file in another format.", "Information", JOptionPane.INFORMATION_MESSAGE);
e1.printStackTrace();
}
}
}Example 16
| Project: Girinoscope-master File: AboutDialog.java View source code |
private JEditorPane createEditorPane(String text) {
HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("body {bgcolor: white;}");
JEditorPane editorPane = new JEditorPane();
editorPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
editorPane.setOpaque(true);
editorPane.setEditorKit(kit);
editorPane.setContentType("text/html");
editorPane.setText(text);
editorPane.setEditable(false);
editorPane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(final HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
final String href = getHref(event);
try {
Desktop.getDesktop().browse(new URI(href));
} catch (IOException e) {
logger.log(Level.WARNING, "Can’t open link " + href, e);
} catch (URISyntaxException e) {
logger.log(Level.WARNING, "Can’t open link " + href, e);
}
}
}
});
return editorPane;
}Example 17
| Project: openjdk8-jdk-master File: Test6817933.java View source code |
public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception exception) {
exception.printStackTrace();
return;
}
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
StyleSheet css = new StyleSheet();
css.addRule(STYLE);
HTMLEditorKit kit = new HTMLEditorKit();
kit.setStyleSheet(css);
JFrame frame = new JFrame(STYLE);
frame.add(chooser = new JFileChooser());
frame.setSize(640, 480);
frame.setVisible(true);
}
});
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
toolkit.realSync(500);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
JToggleButton button = get(JToggleButton.class, get(WindowsPlacesBar.class, chooser));
int width = button.getWidth();
int height = button.getHeight() / 3;
Point point = new Point(0, height * 2);
SwingUtilities.convertPointToScreen(point, button);
width += point.x;
height += point.y;
int count = 0;
Robot robot = new Robot();
for (int x = point.x; x < width; x++) {
for (int y = point.y; y < height; y++) {
count += COLOR.equals(robot.getPixelColor(x, y)) ? -2 : 1;
}
}
if (count < 0) {
throw new Exception("TEST ERROR: a lot of red pixels");
}
} catch (Exception exception) {
throw new Error(exception);
} finally {
SwingUtilities.getWindowAncestor(chooser).dispose();
}
}
});
}Example 18
| Project: QuiltPlayer-master File: WikiView.java View source code |
/*
* (non-Javadoc)
*
* @see org.quiltplayer.view.components.View#getUI()
*/
@Override
public JComponent getUI() {
panel = new JPanel(new MigLayout("ins 1cm 3cm 0 3cm, center, w 80%!"));
panel.setOpaque(true);
JEditorPane htmlPane = null;
htmlPane = new JEditorPane("text/html", content) {
/*
* (non-Javadoc)
*
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
*/
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
super.paintComponent(g);
}
};
htmlPane.setOpaque(false);
htmlPane.setDragEnabled(false);
htmlPane.setEditable(true);
htmlPane.setFocusable(false);
htmlPane.setFont(FontFactory.getFont(13));
htmlPane.setForeground(Color.white);
htmlPane.setBounds(10, 10, panel.getWidth() - 150, panel.getHeight());
final Font font = FontFactory.getFont(13);
String pRule = "p { font-family: " + font.getName() + "; " + "font-size: " + font.getSize() + "pt; color: #EEEEEE; }";
String spanRule = "span { font-family: " + font.getName() + "; " + "font-size: " + font.getSize() + "pt; color: #FFFFFF; }";
String linkRule = "a { font-family: " + font.getName() + "; " + "font-size: " + font.getSize() + "pt;" + "color: #AAAAAA;}";
String linkRule2 = "a:hoover { text-decoration: none; font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt;" + "color: #FFFFFF;}";
((HTMLDocument) htmlPane.getDocument()).getStyleSheet().addRule(linkRule);
((HTMLDocument) htmlPane.getDocument()).getStyleSheet().addRule(pRule);
((HTMLDocument) htmlPane.getDocument()).getStyleSheet().addRule(spanRule);
((HTMLDocument) htmlPane.getDocument()).getStyleSheet().addRule(linkRule2);
StyleSheet styles = ((HTMLDocument) htmlPane.getDocument()).getStyleSheet();
Enumeration<?> rules = styles.getStyleNames();
while (rules.hasMoreElements()) {
String name = (String) rules.nextElement();
Style rule = styles.getStyle(name);
System.out.println(rule.toString());
}
htmlPane.setCaretPosition(0);
panel.add(htmlPane, "w 100%, h 100%");
final QScrollPane pane = new QScrollPane(panel, ScrollDirection.VERTICAL);
return new JXLayer<JScrollPane>(pane, new JScrollPaneLayerUI());
}Example 19
| Project: simjr-master File: CheatSheetHtmlPane.java View source code |
public void addStyleSheet(String file) {
final URL source = CheatSheetHtmlPane.class.getResource(STYLE_SHEET);
if (source == null) {
logger.warn("Could not locate cheatsheet stylesheet at '" + STYLE_SHEET + "'");
return;
}
final HTMLEditorKit editorKit = new HTMLEditorKit();
final StyleSheet styleSheet = new StyleSheet();
styleSheet.addStyleSheet(editorKit.getStyleSheet());
styleSheet.importStyleSheet(source);
editorKit.setStyleSheet(styleSheet);
setEditorKit(editorKit);
}Example 20
| Project: urduhtmlmaster-master File: ExtendedHTMLEditorKit.java View source code |
public Document createDefaultDocument() {
StyleSheet styles = getStyleSheet();
StyleSheet ss = new StyleSheet();
ss.addStyleSheet(styles);
ExtendedHTMLDocument doc = new ExtendedHTMLDocument(ss);
doc.setParser(getParser());
doc.setAsynchronousLoadPriority(4);
doc.setTokenThreshold(100);
return doc;
}Example 21
| Project: ATLauncher-master File: Resources.java View source code |
public static StyleSheet makeStyleSheet(String name) { try { if (resources.containsKey(name)) { Object obj = resources.get(name); if (!(obj instanceof StyleSheet)) { throw new ChunkyException("Reference for " + name + " ended up with a bad value, " + "suggested=" + StyleSheet.class.getName() + "; got=" + obj.getClass().getName()); } else { return (StyleSheet) obj; } } else { StyleSheet sheet = new StyleSheet(); File themeFile = App.settings.getThemeFile(); if (themeFile != null) { InputStream stream = null; ZipFile zipFile = new ZipFile(themeFile); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().equals("css/" + name + ".css")) { stream = zipFile.getInputStream(entry); break; } } if (stream != null) { Reader reader = new InputStreamReader(stream); sheet.loadRules(reader, null); reader.close(); stream.close(); zipFile.close(); resources.put(name, sheet); return sheet; } zipFile.close(); } Reader reader = new InputStreamReader(System.class.getResourceAsStream("/assets/css/" + name + ".css")); sheet.loadRules(reader, null); reader.close(); resources.put(name, sheet); return sheet; } } catch (Exception ex) { throw new ChunkyException(ex); } }
Example 22
| Project: blogbridge-master File: CustomImageView.java View source code |
/**
* Update any cached values that come from attributes.
*/
protected void setPropertiesFromAttributes() {
StyleSheet sheet = getStyleSheet();
this.attr = sheet.getViewAttributes(this);
// Gutters
borderSize = (short) getIntAttr(HTML.Attribute.BORDER, isLink() ? LINK_BORDER : 0);
if (borderSize == 0 && image == null)
borderSize = 1;
rightInset = (short) (getIntAttr(HTML.Attribute.HSPACE, 0) + borderSize);
leftInset = rightInset;
bottomInset = (short) (getIntAttr(HTML.Attribute.VSPACE, 0) + borderSize);
topInset = bottomInset;
borderColor = ((StyledDocument) getDocument()).getForeground(getAttributes());
AttributeSet attrs = getElement().getAttributes();
// Alignment.
// PENDING: This needs to be changed to support the CSS versions
// when conversion from ALIGN to VERTICAL_ALIGN is complete.
Object alignment = attrs.getAttribute(HTML.Attribute.ALIGN);
vAlign = 1.0f;
if (alignment != null) {
alignment = alignment.toString();
if ("top".equals(alignment)) {
vAlign = 0f;
} else if ("middle".equals(alignment)) {
vAlign = .5f;
}
}
AttributeSet anchorAttr = (AttributeSet) attrs.getAttribute(HTML.Tag.A);
if (anchorAttr != null && anchorAttr.isDefined(HTML.Attribute.HREF)) {
synchronized (this) {
state |= LINK_FLAG;
}
} else {
synchronized (this) {
state = (state | LINK_FLAG) ^ LINK_FLAG;
}
}
}Example 23
| Project: consulo-master File: UIUtil.java View source code |
@Nullable public static StyleSheet loadStyleSheet(@Nullable URL url) { if (url == null) return null; try { StyleSheet styleSheet = new StyleSheet(); styleSheet.loadRules(new InputStreamReader(url.openStream(), CharsetToolkit.UTF8), url); return styleSheet; } catch (IOException e) { LOG.warn(url + " loading failed", e); return null; } }
Example 24
| Project: HearthAttack-master File: JFileChooserBugFix.java View source code |
/** Restore the background.
* @param background The background to be restored.
* @see #saveBackground()
*/
public void restoreBackground(Color background) {
try {
if (background != null) {
// Restore the background color.
String rgb = Integer.toHexString(background.getRGB());
String rule = "body {background: #" + rgb.substring(2, rgb.length()) + ";}";
StyleSheet styleSheet = _HTMLEditorKit.getStyleSheet();
styleSheet.addRule(rule);
_HTMLEditorKit.setStyleSheet(styleSheet);
}
} catch (Exception ex) {
log.error("Problem restoring background color. {}", ex);
}
}Example 25
| Project: HearthSim-master File: JFileChooserBugFix.java View source code |
/** Restore the background.
* @param background The background to be restored.
* @see #saveBackground()
*/
public void restoreBackground(Color background) {
try {
if (background != null) {
// Restore the background color.
String rgb = Integer.toHexString(background.getRGB());
String rule = "body {background: #" + rgb.substring(2, rgb.length()) + ";}";
StyleSheet styleSheet = _HTMLEditorKit.getStyleSheet();
styleSheet.addRule(rule);
_HTMLEditorKit.setStyleSheet(styleSheet);
}
} catch (Exception ex) {
log.error("Problem restoring background color. {}", ex);
}
}Example 26
| Project: intellij-community-master File: UIUtil.java View source code |
@Nullable public static StyleSheet loadStyleSheet(@Nullable URL url) { if (url == null) return null; try { StyleSheet styleSheet = new StyleSheet(); styleSheet.loadRules(new InputStreamReader(url.openStream(), CharsetToolkit.UTF8), url); return styleSheet; } catch (IOException e) { LOG.warn(url + " loading failed", e); return null; } }
Example 27
| Project: ptii-master File: HTMLViewer.java View source code |
///////////////////////////////////////////////////////////////////
//// private methods ////
/** Initialize the HTMLViewer.
*/
private void _init() {
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
pane.setContentType("text/html");
pane.setEditable(false);
pane.addHyperlinkListener(this);
if (_styleSheetURL != null) {
// If _styleSheetURL is non-null, we set the style sheet
// once and only once. If try to do this in a static initializer,
// then the styles are wrong.
HTMLDocument doc = (HTMLDocument) pane.getDocument();
StyleSheet styleSheet = doc.getStyleSheet();
styleSheet.importStyleSheet(_styleSheetURL);
if (_HTMLEditorKit == null) {
_HTMLEditorKit = new HTMLEditorKit();
}
_HTMLEditorKit.setStyleSheet(styleSheet);
_styleSheetURL = null;
}
// java 1.5, this will turn on anti-aliased fonts
try {
// We use reflection so that this compiles everywhere.
Class swingUtilities = Class.forName("com.sun.java.swing.SwingUtilities2");
Field propertyField = swingUtilities.getDeclaredField("AA_TEXT_PROPERTY_KEY");
pane.putClientProperty(propertyField.get(null), Boolean.TRUE);
} catch (Throwable ex) {
}
_scroller = new JScrollPane(pane);
_addMainPane();
}Example 28
| Project: rapidminer-5-master File: UpdatePanelTab.java View source code |
private void updateDisplayPane() {
Object selectedValue = packageList.getSelectedValue();
PackageDescriptor desc = null;
if (selectedValue instanceof PackageDescriptor) {
desc = (PackageDescriptor) selectedValue;
lastSelected = desc;
} else {
packageList.clearSelection();
if (lastSelected != null) {
desc = lastSelected;
}
}
if (desc != null) {
for (Component component : extensionButtonPane.getComponents()) {
component.setVisible(true);
}
installButton.setVisible(false);
extensionButtonPane.setVisible(true);
//.makeDefaultStylesheet();
StyleSheet css = new StyleSheet();
css.addRule("a {text-decoration:underline; color:blue;}");
css.addRule("h1 {font-size: 14px;}");
css.addRule("h2 {font-size: 11px;font-weight:bold;}");
css.addRule("div, p, hr { margin-bottom:8px }");
css.addRule("div.changes-section{padding-left:10px;font-size:9px;color:#444444;}");
css.addRule(".changes-header-version {margin-top:10px;margin-bottom:5px;color:#111111;}");
css.addRule("ul {padding-left:10px;}");
css.addRule("ul li {margin-left:0px;padding-left:0px;}");
HTMLDocument doc = new HTMLDocument(css);
displayPane.setDocument(doc);
displayPane.setText(updateModel.toString(desc, listModel.getChanges(desc.getPackageId())));
displayPane.setCaretPosition(0);
installButton.setSelected(updateModel.isSelectedForInstallation(desc));
boolean isInstalled = false;
boolean isUpToDate = false;
boolean isRapidMiner = "STAND_ALONE".equals(desc.getPackageTypeName());
if (isRapidMiner) {
isUpToDate = RapidMiner.getVersion().isAtLeast(new VersionNumber(desc.getVersion()));
isInstalled = true;
} else {
//updatesExist = !RapidMiner.getVersion().isAtLeast(new VersionNumber(getService().getLatestVersion("rapidminer", TARGET_PLATFORM)));
ManagedExtension ext = ManagedExtension.get(desc.getPackageId());
if (ext != null) {
isInstalled = true;
String installed = ext.getLatestInstalledVersion();
if (installed != null) {
boolean upToDate = installed.compareTo(desc.getVersion()) >= 0;
if (upToDate) {
isUpToDate = true;
} else {
isUpToDate = false;
}
}
}
}
if (desc.isRestricted() && !isInstalled) {
if (!usAccount.isLoggedIn()) {
// restricted, uninstalled, not logged in
installButton.setVisible(false);
loginForInstallHint.setText(I18N.getMessage(I18N.getGUIBundle(), "gui.label.update.need_to_log_in.label"));
} else if (updateModel.isPurchased(desc)) {
// restricted, purchased but not installed yet
installButton.setText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.install.select.label"));
installButton.getAction().putValue(Action.MNEMONIC_KEY, (int) I18N.getMessage(I18N.getGUIBundle(), "gui.action.install.select.mne").toUpperCase().charAt(0));
extensionHomepageLink.setText(I18N.getMessage(I18N.getGUIBundle(), "gui.label.update.extension_homepage.label"));
installButton.setPurchaseFirst(false);
installButton.setVisible(true);
installButton.setEnabled(true);
loginForInstallHint.setText("");
if (updateModel.isSelectedForInstallation(desc)) {
installButton.setIcon(SwingTools.createIcon("16/checkbox.png"));
} else {
installButton.setIcon(SwingTools.createIcon("16/checkbox_unchecked.png"));
}
} else {
// restricted, not purchased
installButton.setText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.update.purchase.label"));
installButton.setIcon(SwingTools.createIcon("16/shopping_cart_empty.png"));
installButton.getAction().putValue(Action.MNEMONIC_KEY, (int) I18N.getMessage(I18N.getGUIBundle(), "gui.action.update.purchase.mne").toUpperCase().charAt(0));
extensionHomepageLink.setText(I18N.getMessage(I18N.getGUIBundle(), "gui.label.update.extension_homepage.label"));
installButton.setVisible(true);
loginForInstallHint.setText("");
installButton.setPurchaseFirst(true);
}
} else {
if (isInstalled) {
extensionHomepageLink.setText(I18N.getMessage(I18N.getGUIBundle(), "gui.label.update.extension_homepage.label"));
if (!isUpToDate) {
// not restricted / restricted and installed but not updated
installButton.setText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.update.select.label"));
installButton.getAction().putValue(Action.MNEMONIC_KEY, (int) I18N.getMessage(I18N.getGUIBundle(), "gui.action.update.select.mne").toUpperCase().charAt(0));
installButton.setPurchaseFirst(false);
installButton.setEnabled(true);
installButton.setVisible(true);
loginForInstallHint.setText("");
if (updateModel.isSelectedForInstallation(desc)) {
installButton.setIcon(SwingTools.createIcon("16/checkbox.png"));
} else {
installButton.setIcon(SwingTools.createIcon("16/checkbox_unchecked.png"));
}
} else {
// Installed and updated. So showing nothing.
installButton.setVisible(false);
loginForInstallHint.setText("");
}
} else {
// not restricted / restricted not installed
installButton.setText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.install.select.label"));
installButton.getAction().putValue(Action.MNEMONIC_KEY, (int) I18N.getMessage(I18N.getGUIBundle(), "gui.action.install.select.mne").toUpperCase().charAt(0));
extensionHomepageLink.setText(I18N.getMessage(I18N.getGUIBundle(), "gui.label.update.extension_homepage.label"));
installButton.setPurchaseFirst(false);
installButton.setVisible(true);
installButton.setEnabled(true);
loginForInstallHint.setText("");
if (updateModel.isSelectedForInstallation(desc)) {
installButton.setIcon(SwingTools.createIcon("16/checkbox.png"));
} else {
installButton.setIcon(SwingTools.createIcon("16/checkbox_unchecked.png"));
}
}
}
if (isRapidMiner) {
extensionHomepageLink.setText(I18N.getMessage(I18N.getGUIBundle(), "gui.label.update.product_homepage.label"));
}
}
}Example 29
| Project: rapidminer-studio-master File: SingleResultOverview.java View source code |
/**
* Creates the main text representation of this result.
*
* @param text
* @return
*/
private Component makeMainLabel(String text) {
JEditorPane label = new ExtendedHTMLJEditorPane("text/html", text);
StyleSheet css = ((HTMLEditorKit) label.getEditorKit()).getStyleSheet();
css.addRule("body {font-family:Sans;font-size:11pt}");
css.addRule("h3 {margin:0; padding:0}");
css.addRule("h4 {margin-bottom:0; margin-top:1ex; padding:0}");
css.addRule("p {margin-top:0; margin-bottom:1ex; padding:0}");
css.addRule("ul {margin-top:0; margin-bottom:1ex; list-style-image: url(" + getClass().getResource("/com/rapidminer/resources/icons/modern/help/circle.png") + ")}");
css.addRule("ul li {padding-bottom: 2px}");
css.addRule("li.outPorts {padding-bottom: 0px}");
css.addRule("ul li ul {margin-top:0; margin-bottom:1ex; list-style-image: url(" + getClass().getResource("/com/rapidminer/resources/icons/modern/help/line.png") + ")");
css.addRule("li ul li {padding-bottom:0}");
label.setEditable(false);
label.setBackground(Colors.WHITE);
JScrollPane pane = new JScrollPane(label);
pane.setBackground(Colors.WHITE);
pane.setBorder(null);
return pane;
}Example 30
| Project: rapidminer-vega-master File: OperatorDocViewer.java View source code |
@Override
public void installDefaultStylesheet() {
//StyleSheet css = new StyleSheet();
HTMLEditorKit hed = new HTMLEditorKit();
StyleSheet css = hed.getStyleSheet();
css.addRule("body {font-family:Sans;font-size:12pt}");
css.addRule("h4 {margin-bottom:2px; margin-top:2ex; padding-left:4px; padding:0; color:#446699; font-size:16pt}");
css.addRule("p {margin-top:0; margin-bottom:2ex; padding:0}");
css.addRule("dt {font-weight:bold;}");
css.addRule("ul.ports {margin-top:0; margin-bottom:1ex; list-style-image:url(" + Tools.getResource("icons/help/circle.png") + "); }");
css.addRule("ul li {padding-bottom:1ex}");
css.addRule("ul.param_dep {margin-top:0; margin-bottom:1ex; list-style-type:none; list-style-image:none; }");
css.addRule("li ul li {padding-bottom:0}");
css.addRule("hr {color:red; background-color:red}");
css.addRule("table {font-style:italic;}");
// css.addRule("div.thumb tright {align:right;}");
// css.addRule("div.thumb left {align:left;}");
//String hcolor = Integer.toHexString(SwingTools.DARKEST_BLUE.darker().darker().darker().getRGB());
//hcolor = hcolor.substring(2, 8);
//css.addRule("h2, h3, h4 { border-width:3px; border-style:solid; border-color:#"+Integer.toHexString(SwingTools.RAPID_I_ORANGE.getRGB())+"; }");
//css.addRule("a:hover {text-decoration:underline}");
//css.addRule("hr {color:red; background-color:red}");
//((HTMLEditorKit)getEditorKit()).setStyleSheet(css);
Document doc = hed.createDefaultDocument();
editor.setDocument(doc);
}Example 31
| Project: sulky-master File: SwingLogging.java View source code |
public static void logStyles(HTMLEditorKit htmlEditorKit) {
final Logger logger = LoggerFactory.getLogger(SwingLogging.class);
if (logger.isDebugEnabled()) {
StringBuilder msg = new StringBuilder();
msg.append("Primary:\n");
StyleSheet styleSheet = htmlEditorKit.getStyleSheet();
appendStyles(styleSheet, msg);
logger.debug(msg.toString());
}
}Example 32
| Project: maptool-master File: MessagePanelImageView.java View source code |
/**
* Update any cached values that come from attributes.
*/
protected void setPropertiesFromAttributes() {
StyleSheet sheet = getStyleSheet();
this.attr = sheet.getViewAttributes(this);
// Gutters
borderSize = (short) getIntAttr(HTML.Attribute.BORDER, isLink() ? DEFAULT_BORDER : 0);
leftInset = rightInset = (short) (getIntAttr(HTML.Attribute.HSPACE, 0) + borderSize);
topInset = bottomInset = (short) (getIntAttr(HTML.Attribute.VSPACE, 0) + borderSize);
borderColor = ((StyledDocument) getDocument()).getForeground(getAttributes());
AttributeSet attr = getElement().getAttributes();
// Alignment.
// PENDING: This needs to be changed to support the CSS versions
// when conversion from ALIGN to VERTICAL_ALIGN is complete.
Object alignment = attr.getAttribute(HTML.Attribute.ALIGN);
vAlign = 1.0f;
if (alignment != null) {
alignment = alignment.toString();
if ("top".equals(alignment)) {
vAlign = 0f;
} else if ("middle".equals(alignment)) {
vAlign = .5f;
}
}
AttributeSet anchorAttr = (AttributeSet) attr.getAttribute(HTML.Tag.A);
if (anchorAttr != null && anchorAttr.isDefined(HTML.Attribute.HREF)) {
synchronized (this) {
state |= LINK_FLAG;
}
} else {
synchronized (this) {
state = (state | LINK_FLAG) ^ LINK_FLAG;
}
}
}Example 33
| Project: nbscala-master File: BrokenPlatformCustomizer.java View source code |
//GEN-END:initComponents
private void postInitComponents() {
this.platformName.setText(platform.getDisplayName());
Collection installFolders = platform.getInstallFolderURLs();
if (installFolders.size() > 0) {
this.platformHome.setForeground(new Color(164, 0, 0));
this.platformHome.setText(new File(URI.create(((URL) installFolders.iterator().next()).toExternalForm())).getAbsolutePath());
}
HTMLEditorKit htmlkit = new HTMLEditorKit();
StyleSheet css = htmlkit.getStyleSheet();
if (css.getStyleSheets() == null) {
StyleSheet css2 = new StyleSheet();
Font f = jLabel1.getFont();
css2.addRule(// NOI18N
new StringBuffer("body { font-size: ").append(f.getSize()).append("; font-family: ").append(f.getName()).append(// NOI18N
"; }").toString());
css2.addStyleSheet(css);
htmlkit.setStyleSheet(css2);
}
jTextPane1.setEditorKit(htmlkit);
jTextPane1.setText(NbBundle.getMessage(BrokenPlatformCustomizer.class, "MSG_BrokenProject"));
}Example 34
| Project: nextreports-designer-master File: AboutAction.java View source code |
private JComponent createPanel() {
System.setProperty("awt.useSystemAAFontSettings", "on");
final JEditorPane editorPane = new JEditorPane();
HTMLEditorKit kit = new HTMLEditorKit();
editorPane.setEditorKit(kit);
editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
editorPane.setFont(new Font("Arial", Font.PLAIN, 12));
editorPane.setPreferredSize(new Dimension(350, 180));
editorPane.setEditable(false);
editorPane.setContentType("text/html");
editorPane.setBackground(new Color(234, 241, 248));
// add some styles to the html
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule(".firstCol {margin-left: 25px; }");
styleSheet.addRule(".secondCol {color: blue; }");
Document doc = kit.createDefaultDocument();
editorPane.setDocument(doc);
editorPane.setText("<html>" + "<body>" + "<table border='0px' BGCOLOR=\"#EAF1F8\">" + "<tr><td colspan=2>" + "<img src='" + ImageUtil.getImageURL("logo").toExternalForm() + "'>" + "</td></tr>" + "<tr><td class=\"firstCol\"><b>" + VERSION + "</b></td><td class=\"secondCol\">" + VERSION_NO + "</td></tr>" + "<tr><td class=\"firstCol\"><b>" + BUILD + "</b></td><td class=\"secondCol\">" + ReleaseInfo.getBuildNumber() + " (" + BUILD_DATE + ")" + "</td></tr>" + "<tr><td class=\"firstCol\"><b>" + SITE + "</b></td><td class=\"secondCol\">" + "<a href=\"" + SITE_VALUE + "\">" + SITE_SMALL_VALUE + "</a></td></tr>" + "<tr><td class=\"firstCol\"><b>" + COPYRIGHT + "</b></td><td class=\"secondCol\">" + DEVELOPER + "</td></tr>" + "</table>" + "</body>" + "</html>");
// Add Hyperlink listener to process hyperlinks
editorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(final HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
EventQueue.invokeLater(new Runnable() {
public void run() {
SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
editorPane.setToolTipText(e.getURL().toExternalForm());
}
});
} else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
EventQueue.invokeLater(new Runnable() {
public void run() {
SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getDefaultCursor());
editorPane.setToolTipText(null);
}
});
} else if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
FileUtil.openUrl(e.getURL().toString(), AboutAction.class);
}
}
});
editorPane.addMouseListener(mouseListener);
JScrollPane sp = new JScrollPane(editorPane);
return sp;
}Example 35
| Project: nmedit-master File: ModuleHelpPage.java View source code |
private void createComponents() {
setLayout(new BorderLayout());
textArea = new JEditorPane();
textArea.setEditable(false);
textArea.setContentType("text/html");
add(new JScrollPane(textArea), BorderLayout.CENTER);
StyleSheet ss = new StyleSheet();
ss.addRule("h1 { font-size:24pt; font-weight: bold; margin-top:6pt; margin-bottom:4pt; }" + "h2 { font-size:20pt; font-weight: bold; margin-top:6pt; margin-bottom:4pt; }" + "h3 { font-size:16pt; font-weight: bold; color:blue; }" + "strong {font-weight: bold; }" + ".indent { margin-left:12pt; }" + "ul {margin-left: 16pt; }" + ".module_image { margin-top:12pt;margin-bottom:12pt; }" + "body{padding:12pt;}");
doc = new HTMLDocument(ss);
ParserDelegator pd = new ParserDelegator();
doc.setParser(pd);
textArea.setDocument(doc);
}Example 36
| Project: tabletoptool-master File: MessagePanelImageView.java View source code |
/**
* Update any cached values that come from attributes.
*/
protected void setPropertiesFromAttributes() {
StyleSheet sheet = getStyleSheet();
this.attr = sheet.getViewAttributes(this);
// Gutters
borderSize = (short) getIntAttr(HTML.Attribute.BORDER, isLink() ? DEFAULT_BORDER : 0);
leftInset = rightInset = (short) (getIntAttr(HTML.Attribute.HSPACE, 0) + borderSize);
topInset = bottomInset = (short) (getIntAttr(HTML.Attribute.VSPACE, 0) + borderSize);
borderColor = ((StyledDocument) getDocument()).getForeground(getAttributes());
AttributeSet attr = getElement().getAttributes();
// Alignment.
// PENDING: This needs to be changed to support the CSS versions
// when conversion from ALIGN to VERTICAL_ALIGN is complete.
Object alignment = attr.getAttribute(HTML.Attribute.ALIGN);
vAlign = 1.0f;
if (alignment != null) {
alignment = alignment.toString();
if ("top".equals(alignment)) {
vAlign = 0f;
} else if ("middle".equals(alignment)) {
vAlign = .5f;
}
}
AttributeSet anchorAttr = (AttributeSet) attr.getAttribute(HTML.Tag.A);
if (anchorAttr != null && anchorAttr.isDefined(HTML.Attribute.HREF)) {
synchronized (this) {
state |= LINK_FLAG;
}
} else {
synchronized (this) {
state = (state | LINK_FLAG) ^ LINK_FLAG;
}
}
}Example 37
| Project: UniversalMediaServer-master File: LanguageSelection.java View source code |
private JComponent buildComponent() {
// UIManager manages to get the background color wrong for text
// components on OS X, so we apply the color manually
Color backgroundColor = UIManager.getColor("Panel.background");
rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.PAGE_AXIS));
// It needs to be something in the title text, or the size calculation for the border will be wrong.
selectionPanelBorder.setTitle(" ");
selectionPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(selectionPanelBorder, BorderFactory.createEmptyBorder(10, 5, 10, 5))));
selectionPanel.setLayout(new BoxLayout(selectionPanel, BoxLayout.PAGE_AXIS));
descriptionText.setEditable(false);
descriptionText.setBackground(backgroundColor);
descriptionText.setFocusable(false);
descriptionText.setLineWrap(true);
descriptionText.setWrapStyleWord(true);
descriptionText.setBorder(BorderFactory.createEmptyBorder(5, 15, 10, 15));
selectionPanel.add(descriptionText);
jLanguage = new JComboBox<>(keyedModel);
jLanguage.setEditable(false);
jLanguage.setPreferredSize(new Dimension(50, jLanguage.getPreferredSize().height));
jLanguage.addActionListener(new LanguageComboBoxActionListener());
languagePanel.setLayout(new BoxLayout(languagePanel, BoxLayout.PAGE_AXIS));
languagePanel.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
languagePanel.add(jLanguage);
selectionPanel.add(languagePanel);
warningText.setEditable(false);
warningText.setFocusable(false);
warningText.setBackground(backgroundColor);
warningText.setFont(warningText.getFont().deriveFont(Font.BOLD));
warningText.setLineWrap(true);
warningText.setWrapStyleWord(true);
warningText.setBorder(BorderFactory.createEmptyBorder(5, 15, 0, 15));
selectionPanel.add(warningText);
// It needs to be something in the title text, or the size calculation for the border will be wrong.
infoTextBorder.setTitle(" ");
infoText.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(infoTextBorder, BorderFactory.createEmptyBorder(15, 20, 20, 20))));
infoText.setEditable(false);
infoText.setFocusable(false);
infoText.setBackground(backgroundColor);
infoText.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
// This exercise is to avoid using the default shared StyleSheet with padding
CustomHTMLEditorKit editorKit = new CustomHTMLEditorKit();
StyleSheet styleSheet = new StyleSheet();
styleSheet.addRule("a { color: #0000EE; text-decoration:underline; }");
editorKit.setStyleSheet(styleSheet);
infoText.setEditorKit(editorKit);
infoText.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
boolean error = false;
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI(e.getDescription()));
} catch (IOExceptionURISyntaxException | ex) {
LOGGER.error("Language selection failed to open translation page hyperlink: ", ex.getMessage());
LOGGER.trace("", ex);
error = true;
}
} else {
LOGGER.warn("Desktop is not supported, the clicked translation page link can't be opened");
error = true;
}
if (error) {
JOptionPane.showOptionDialog(dialog, String.format(buildString("LanguageSelection.6", true), PMS.CROWDIN_LINK), buildString("Dialog.Error"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, null, null);
}
}
}
});
rootPanel.add(selectionPanel);
rootPanel.add(infoText);
applyButton.addActionListener(new ApplyButtonActionListener());
applyButton.setActionCommand("apply");
selectButton.addActionListener(new SelectButtonActionListener());
selectButton.setActionCommand("select");
return rootPanel;
}Example 38
| Project: cooper-master File: DesignPrinciplePanel.java View source code |
private JComponent createPackageDesignPrinciple(String path) {
JEditorPane text = new JEditorPane();
text.setContentType("text/html;charset=utf-8");
text.setEditable(false);
try {
StyleSheet ss = new StyleSheet();
StyleSheet s1 = new StyleSheet();
s1.importStyleSheet(new URL(null, "classpath:/culture/包的设计原则_files/style.css", new ClassPathURLStreamHandler()));
ss.addStyleSheet(s1);
HTMLEditorKit kit = new HTMLEditorKit();
ss.addStyleSheet(kit.getStyleSheet());
kit.setStyleSheet(ss);
text.setEditorKit(kit);
text.setPage(new URL(null, "classpath:/culture/" + path, new ClassPathURLStreamHandler()));
text.setCaretPosition(0);
} catch (Exception e) {
e.printStackTrace();
}
return new JScrollPane(text);
}Example 39
| Project: jplag-master File: InfoPanel.java View source code |
/**
* This method initializes jEditorPane
*
* @return javax.swing.JEditorPane
*/
private JEditorPane getJEditorPane() {
if (jEditorPane == null) {
jEditorPane = new JEditorPane();
jEditorPane.setPreferredSize(new java.awt.Dimension(290, 120));
jEditorPane.setEditable(false);
jEditorPane.setBackground(Color.WHITE);
StyleSheet styleSheet = new StyleSheet();
//$NON-NLS-1$
styleSheet.addRule("body { font-family: Dialog; font-size: 12; }");
styleSheet.addRule(//$NON-NLS-1$
"a { font-size: 12; font-weight: normal; " + //$NON-NLS-1$
"color: #0000ff; text-decoration: underline;}");
HTMLEditorKit htmlKit = (HTMLEditorKit) (jEditorPane.getEditorKitForContentType(//$NON-NLS-1$
"text/html"));
htmlKit.setStyleSheet(styleSheet);
//$NON-NLS-1$
jEditorPane.setContentType("text/html");
jEditorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent arg0) {
if (arg0.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
File f = new File(InfoPanel.this.activeClient.getEncodedIndex_html());
DesktopUtils.openWebpage(f.toURI());
}
}
});
}
return jEditorPane;
}Example 40
| Project: LimeWire-Pirate-Edition-master File: CustomHyperlinkUI.java View source code |
/**
* Overridden to return our own slimmed down style sheet.
*/
@Override
public StyleSheet getStyleSheet() {
if (defaultStyles == null) {
defaultStyles = new StyleSheet();
StringReader r = new StringReader(styleChanges);
try {
defaultStyles.loadRules(r, null);
} catch (Throwable e) {
}
r.close();
defaultStyles.addStyleSheet(super.getStyleSheet());
}
return defaultStyles;
}Example 41
| Project: limewire5-ruby-master File: CustomHyperlinkUI.java View source code |
/**
* Overridden to return our own slimmed down style sheet.
*/
@Override
public StyleSheet getStyleSheet() {
if (defaultStyles == null) {
defaultStyles = new StyleSheet();
StringReader r = new StringReader(styleChanges);
try {
defaultStyles.loadRules(r, null);
} catch (Throwable e) {
}
r.close();
defaultStyles.addStyleSheet(super.getStyleSheet());
}
return defaultStyles;
}Example 42
| Project: OmegaT-master File: DictionariesTextArea.java View source code |
@Override
public void setFont(Font font) {
super.setFont(font);
Document doc = getDocument();
if (!(doc instanceof HTMLDocument)) {
return;
}
StyleSheet styleSheet = ((HTMLDocument) doc).getStyleSheet();
styleSheet.addRule("body { font-family: " + font.getName() + "; " + " font-size: " + font.getSize() + "; " + " font-style: " + (font.getStyle() == Font.BOLD ? "bold" : font.getStyle() == Font.ITALIC ? "italic" : "normal") + "; " + " color: " + EditorColor.COLOR_FOREGROUND.toHex() + "; " + " background: " + EditorColor.COLOR_BACKGROUND.toHex() + "; " + " }");
}Example 43
| Project: RouteConverter-master File: BrowserDisplayer.java View source code |
public void setTextFontSize(String size) {
int newsize;
StyleSheet css = doc.getStyleSheet();
try {
if (size.equals("xx-small")) {
newsize = (int) css.getPointSize(0);
} else if (size.equals("x-small")) {
newsize = (int) css.getPointSize(1);
} else if (size.equals("small")) {
newsize = (int) css.getPointSize(2);
} else if (size.equals("medium")) {
newsize = (int) css.getPointSize(3);
} else if (size.equals("large")) {
newsize = (int) css.getPointSize(4);
} else if (size.equals("x-large")) {
newsize = (int) css.getPointSize(5);
} else if (size.equals("xx-large")) {
newsize = (int) css.getPointSize(6);
} else if (size.equals("bigger")) {
newsize = (int) css.getPointSize("+1");
} else if (size.equals("smaller")) {
newsize = (int) css.getPointSize("-1");
} else if (size.endsWith("pt")) {
String sz = size.substring(0, size.length() - 2);
newsize = Integer.parseInt(sz);
} else {
newsize = (int) css.getPointSize(size);
}
} catch (NumberFormatException nfe) {
return;
}
if (newsize == 0) {
return;
}
textAttribs.removeAttribute(FontSize);
textAttribs.addAttribute(FontSize, newsize);
setFont(getAttributeSetFont(textAttribs));
Font font = getFont();
}Example 44
| Project: bioknime-master File: JEmbossProcessorNodeDialog.java View source code |
/**
* Called from the tree selection listener, this method updates the HTML widget based on the
* user-chosen emboss program.
* @param html_fragment2
*/
public void update_html(String prog, String html_fragment) {
m_html_help.setContentType("text/html");
Font font = UIManager.getFont("Label.font");
String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: 9pt; }";
String trRule = "tr.even { background-color: #FFFFFF; } \n" + "tr.odd { background-color: #E0E0E0; }";
StyleSheet ss = ((HTMLDocument) m_html_help.getDocument()).getStyleSheet();
ss.addRule(bodyRule);
ss.addRule(trRule);
// remove ugly markup from ACDtable result
html_fragment = html_fragment.replaceFirst("<table[^>]+?>", "<table bgcolor=\"#C0C0C0\">");
Pattern p = Pattern.compile("<tr bgcolor=\"#[A-F0-9]+\">");
Matcher m = p.matcher(html_fragment);
StringBuffer html_sb = new StringBuffer(html_fragment.length());
int row_id = 1;
while (m.find()) {
if (row_id++ % 2 == 0) {
m.appendReplacement(html_sb, "<tr class=\"even\">");
} else {
m.appendReplacement(html_sb, "<tr class=\"odd\">");
}
}
m.appendTail(html_sb);
//Logger.getAnonymousLogger().info(html_sb.toString());
String descr = "";
TreePath tp = m_progs_tree.getSelectionPath();
if (tp != null) {
Object child = tp.getLastPathComponent();
if (child instanceof EmbossProgramDescription) {
descr = ((EmbossProgramDescription) child).getDescription();
}
}
m_html_help.setText("<html><body><b>" + prog + ": " + descr + "</b><p>" + html_sb + "</p></body></html>");
}Example 45
| Project: Darcula-master File: DarculaLaf.java View source code |
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
private static void patchStyledEditorKit() {
try {
StyleSheet defaultStyles = new StyleSheet();
InputStream is = DarculaLaf.class.getResourceAsStream("darcula.css");
Reader r = new BufferedReader(new InputStreamReader(is, "UTF-8"));
defaultStyles.loadRules(r, null);
r.close();
final Field keyField = HTMLEditorKit.class.getDeclaredField("DEFAULT_STYLES_KEY");
keyField.setAccessible(true);
final Object key = keyField.get(null);
AppContext.getAppContext().put(key, defaultStyles);
} catch (Throwable e) {
log(e);
}
}Example 46
| Project: geogebra-master File: StatisticsCalculatorD.java View source code |
private static void setStyleSheets(HTMLEditorKit kit) {
// add some styles to the html
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("body {color:#00008B; font : 9pt verdana; margin: 4px; }");
String padding = "padding-top:2px; padding-bottom:2px;padding-left:5px;padding-right:5px;";
styleSheet.addRule("td {text-align: center; border-top-width: 1px; border-bottom-width: 1px;border-left-width: 1px;border-right-width: 1px;border-style:solid; border-color:#00008B;" + padding + "}");
}Example 47
| Project: geotoolkit-master File: WMSPresenter.java View source code |
/**
* Render html in a JTextPane
* @param stream InputStream
* @throws IOException
*/
private static Component renderHTML(InputStream stream) throws IOException {
String html = getStringContent(stream);
String css = null;
final Pattern style = Pattern.compile("<style>([^><]+?)</style>", Pattern.MULTILINE);
final Matcher matcher = style.matcher(html);
if (matcher.find()) {
css = matcher.group(1);
html = html.substring(0, matcher.start(0)) + html.substring(matcher.end(0));
}
final StyleSheet styles = new StyleSheet();
if (css != null) {
styles.addRule(css);
}
final JTextPane textPane = new JTextPane();
textPane.setEditable(false);
textPane.setContentType("text/html");
textPane.setStyledDocument(new HTMLDocument(styles));
textPane.setText(html);
return textPane;
}Example 48
| Project: jbidwatcher-master File: OptionUI.java View source code |
/**
* @brief Show a large HTML-formatted text display, with buttons
* below, to select what to do.
*
* @param inSB - The data to show in the buffer.
* @param inSize - The size to show it at.
* @param frameName - The name of the frame to show.
* @param choices - The array of choices to show.
* @param borderTitle - The title to surround the panel with.
* @param al - Who to notify that a choice was made.
*
* @return - The JFrame of the display.
*/
public JFrame showChoiceTextDisplay(StringBuffer inSB, Dimension inSize, String frameName, List<String> choices, String borderTitle, ActionListener al) {
JEditorPane jep = new JEditorPane();
HTMLEditorKit hek = new HTMLEditorKit();
jep.setEditable(false);
jep.setEditorKit(hek);
jep.addHyperlinkListener(new Hyperactive(jep));
jep.setPreferredSize(inSize);
jep.setMaximumSize(inSize);
jep.setMinimumSize(inSize);
JFrame otherFrame = new JBidFrame(frameName);
JPanel insidePanel = new JPanel(new BorderLayout());
JScrollPane jsp = new JScrollPane(jep);
StyleSheet sheet = hek.getStyleSheet();
sheet.addRule(".smaller { font-size: 85%; }");
sheet.addRule(".banner { font-size: 110%; }");
sheet.addRule("body { font-family: Verdana, Geneva, Tahoma, sans-serif; }");
sheet.addRule("ul li { margin-bottom: 4px; }");
sheet.addRule(".changelog { color: #333333; margin-left: 20px; padding-left: 3px; background-color: #eeeeee; }");
sheet.addRule(".changelog h1 { font-size: 110%; }");
jep.setDocument(hek.createDefaultDocument());
jep.setText(inSB.toString());
jsp.getVerticalScrollBar().setValue(0);
otherFrame.setPreferredSize(inSize);
otherFrame.setMaximumSize(inSize);
otherFrame.setMinimumSize(inSize);
otherFrame.getContentPane().add(insidePanel);
insidePanel.add(jsp, BorderLayout.CENTER);
if (borderTitle != null) {
insidePanel.setBorder(BorderFactory.createTitledBorder(borderTitle));
} else {
insidePanel.setBorder(BorderFactory.createEmptyBorder());
}
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
boolean isFirst = true;
JButton firstButton = null;
for (String info : choices) {
if (info.startsWith("CHECK")) {
JCheckBox tmpCheck = new JCheckBox(info.substring(6));
tmpCheck.addActionListener(al);
bottomPanel.add(tmpCheck);
} else if (info.startsWith("TEXT")) {
JLabel tmpLabel = new JLabel(info.substring(5));
bottomPanel.add(tmpLabel);
} else {
JButton step_button = new JButton(info);
step_button.addActionListener(al);
bottomPanel.add(step_button);
if (isFirst) {
isFirst = false;
firstButton = step_button;
}
}
}
insidePanel.add(bottomPanel, BorderLayout.SOUTH);
jep.setCaretPosition(0);
otherFrame.setLocation(getCenter(inSize));
otherFrame.pack();
otherFrame.setVisible(true);
if (firstButton != null)
firstButton.requestFocusInWindow();
return otherFrame;
}Example 49
| Project: opgraph-master File: NodeLibraryViewer.java View source code |
private void initializeComponents(NodeLibrary library) {
setLayout(new BorderLayout());
this.renderer = new DefaultTreeCellRenderer();
this.renderer.setOpenIcon(null);
this.renderer.setLeafIcon(null);
this.renderer.setClosedIcon(null);
this.expandedCategories = new HashSet<String>();
this.libraryTree = new JTree();
this.infoPane = new JEditorPane();
this.filterField = new SearchField("Enter Filter Text");
libraryTree.setRootVisible(false);
libraryTree.setEditable(false);
libraryTree.setBackground(Color.WHITE);
libraryTree.setShowsRootHandles(true);
libraryTree.setRowHeight(-1);
libraryTree.setCellRenderer(renderer);
libraryTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
libraryTree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent e) {
if (e.getPath().getPathCount() >= 2) {
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getPathComponent(1);
if (node != null && (node.getUserObject() instanceof String))
expandedCategories.add((String) node.getUserObject());
}
}
@Override
public void treeCollapsed(TreeExpansionEvent e) {
if (e.getPath().getPathCount() >= 2) {
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getPathComponent(1);
if (node != null && (node.getUserObject() instanceof String))
expandedCategories.remove(node.getUserObject());
}
}
});
libraryTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
if (selectedNode != null) {
final Object selectedObject = selectedNode.getUserObject();
if (selectedObject != null && selectedObject instanceof NodeData) {
final NodeData info = (NodeData) selectedObject;
infoPane.setText(getHTMLForNodeInfo(info));
}
}
}
});
libraryTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && libraryTree.getSelectionPath() != null) {
final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) libraryTree.getSelectionPath().getLastPathComponent();
if (selectedNode != null) {
final Object selectedObject = selectedNode.getUserObject();
if (selectedObject != null && selectedObject instanceof NodeData) {
final NodeData info = (NodeData) selectedObject;
final GraphDocument document = GraphEditorModel.getActiveDocument();
if (document != null) {
try {
final OpGraph graph = document.getGraph();
document.getUndoSupport().postEdit(new AddNodeEdit(graph, info, -1, -1));
} catch (InstantiationException exc) {
final String message = "Unable to create '" + info.name + "'";
LOGGER.severe(message);
ErrorDialog.showError(exc, message);
}
}
}
}
}
}
});
setLibrary(library);
// Create the filter field context menu
final JRadioButtonMenuItem fullTextItem = new JRadioButtonMenuItem("Full Text");
final JRadioButtonMenuItem nameItem = new JRadioButtonMenuItem("Name");
final JRadioButtonMenuItem descriptionItem = new JRadioButtonMenuItem("Description");
final JRadioButtonMenuItem categoryItem = new JRadioButtonMenuItem("Category");
fullTextItem.setActionCommand("fulltext");
fullTextItem.addActionListener(updateFilterAction);
fullTextItem.setSelected(true);
nameItem.setActionCommand("name");
nameItem.addActionListener(updateFilterAction);
descriptionItem.setActionCommand("description");
descriptionItem.addActionListener(updateFilterAction);
categoryItem.setActionCommand("category");
categoryItem.addActionListener(updateFilterAction);
final ButtonGroup group = new ButtonGroup();
group.add(fullTextItem);
group.add(nameItem);
group.add(descriptionItem);
group.add(categoryItem);
final JPopupMenu filterPopup = new JPopupMenu();
filterPopup.add(fullTextItem);
filterPopup.addSeparator();
filterPopup.add(nameItem);
filterPopup.add(descriptionItem);
filterPopup.add(categoryItem);
filterField.setContextPopup(filterPopup);
// Filter field initialization
filterField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
final ActionEvent ae = new ActionEvent(filterField.getDocument(), 0, "filter");
updateFilterAction.actionPerformed(ae);
}
@Override
public void insertUpdate(DocumentEvent e) {
final ActionEvent ae = new ActionEvent(filterField.getDocument(), 0, "filter");
updateFilterAction.actionPerformed(ae);
}
@Override
public void changedUpdate(DocumentEvent e) {
}
});
// Node information pane
final StyleSheet style = new StyleSheet();
style.addRule("body { background: white; font: 12pt sans-serif; }");
style.addRule("h1 { font: bold 16pt; margin: 5px; }");
style.addRule("p { margin: 5px 10px; }");
final HTMLEditorKit htmlKit = new HTMLEditorKit();
htmlKit.setStyleSheet(style);
infoPane.setEditable(false);
infoPane.setEditorKit(htmlKit);
// Drag support for creation of nodes
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(libraryTree, DnDConstants.ACTION_COPY, gestureListener);
// Search field and library tree on the left
final JPanel searchFieldPanel = new JPanel(new BorderLayout());
searchFieldPanel.setOpaque(false);
searchFieldPanel.add(filterField);
searchFieldPanel.setBorder(new EmptyBorder(5, 2, 5, 2));
final JScrollPane libraryScrollPane = new JScrollPane(libraryTree);
libraryScrollPane.setBorder(null);
final JPanel libraryPanel = new JPanel(new BorderLayout());
libraryPanel.setBackground(Color.WHITE);
libraryPanel.add(searchFieldPanel, BorderLayout.NORTH);
libraryPanel.add(libraryScrollPane, BorderLayout.CENTER);
// Split pane between tree and description
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setBorder(null);
splitPane.setLeftComponent(libraryPanel);
splitPane.setRightComponent(infoPane);
splitPane.setDividerSize(3);
splitPane.setDividerLocation(libraryTree.getPreferredSize().width + 100);
add(splitPane, BorderLayout.CENTER);
}Example 50
| Project: TranslationPlugin-master File: TranslationBalloon.java View source code |
@NotNull
private static HTMLEditorKit getErrorHTMLKit() {
HTMLEditorKit kit = UIUtil.getHTMLEditorKit();
JBFont font = JBUI.Fonts.label(16);
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule(String.format("body {color:#FF3333; font-family: %s;font-size: %s; text-align: center;}", font.getFamily(), font.getSize()));
styleSheet.addRule("a {color:#FF0000;}");
return kit;
}Example 51
| Project: Weasis-master File: WeasisLauncher.java View source code |
private static void showMessage(final WeasisFrame mainFrame, Map<String, String> serverProp, final Properties l_prop) {
//$NON-NLS-1$
String versionOld = serverProp.get("prev." + P_WEASIS_VERSION);
String versionNew = serverProp.get(P_WEASIS_VERSION);
// First time launch
if (versionOld == null) {
//$NON-NLS-1$ //$NON-NLS-2$
String val = getGeneralProperty("weasis.show.disclaimer", "true", serverProp, l_prop, false, false);
if (Boolean.valueOf(val)) {
EventQueue.invokeLater(() -> {
Object[] options = //$NON-NLS-1$ //$NON-NLS-2$
{ Messages.getString("WeasisLauncher.ok"), Messages.getString("WeasisLauncher.no") };
String appName = System.getProperty(P_WEASIS_NAME);
int response = JOptionPane.showOptionDialog(mainFrame.getRootPaneContainer() == null ? null : mainFrame.getRootPaneContainer().getContentPane(), //$NON-NLS-1$
String.format(Messages.getString("WeasisLauncher.msg"), appName), //$NON-NLS-1$
String.format(Messages.getString("WeasisLauncher.first"), appName), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, null);
if (response == 0) {
// Write "false" in weasis.properties. It can be useful when preferences are store remotely.
// The user will accept the disclaimer only once.
//$NON-NLS-1$
l_prop.setProperty("weasis.show.disclaimer", Boolean.FALSE.toString());
if (prefDir != null) {
FileUtil.storeProperties(new File(prefDir, APP_PROPERTY_FILE), l_prop, null);
}
} else {
File sourceID_props = new //$NON-NLS-1$
File(//$NON-NLS-1$
System.getProperty(P_WEASIS_PATH, ""), //$NON-NLS-1$ //$NON-NLS-2$
System.getProperty("weasis.source.id") + ".properties");
// delete the properties file to ask again
sourceID_props.delete();
//$NON-NLS-1$
System.err.println("Refusing the disclaimer");
System.exit(-1);
}
});
}
} else if (versionNew != null && !versionNew.equals(versionOld)) {
//$NON-NLS-1$ //$NON-NLS-2$
String val = getGeneralProperty("weasis.show.release", "true", serverProp, l_prop, false, false);
if (Boolean.valueOf(val)) {
Version vOld = getVersion(versionOld);
Version vNew = getVersion(versionNew);
if (vNew.compareTo(vOld) > 0) {
//$NON-NLS-1$
String lastTag = l_prop.getProperty("weasis.version.release", null);
if (lastTag != null) {
vOld = getVersion(lastTag);
if (vNew.compareTo(vOld) <= 0) {
// Message has been already displayed once.
return;
}
}
// Can be useful when preferences are store remotely.
// The user will see the release message only once.
//$NON-NLS-1$
l_prop.setProperty("weasis.version.release", vNew.toString());
if (prefDir != null) {
FileUtil.storeProperties(new File(prefDir, APP_PROPERTY_FILE), l_prop, null);
}
}
//$NON-NLS-1$
final String releaseNotesUrl = serverProp.get("weasis.releasenotes");
//$NON-NLS-1$
final StringBuilder message = new StringBuilder("<P>");
message.append(//$NON-NLS-1$
String.format(//$NON-NLS-1$
Messages.getString("WeasisLauncher.change.version"), System.getProperty(P_WEASIS_NAME), versionOld, versionNew));
EventQueue.invokeLater(() -> {
JTextPane jTextPane1 = new JTextPane();
HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet ss = kit.getStyleSheet();
ss.addRule(//$NON-NLS-1$
"body {font-family:sans-serif;font-size:12pt;background-color:#" + Integer.toHexString((jTextPane1.getBackground().getRGB() & 0xffffff) | 0x1000000).substring(1) + //$NON-NLS-1$
";color:#" + Integer.toHexString((jTextPane1.getForeground().getRGB() & 0xffffff) | 0x1000000).substring(1) + //$NON-NLS-1$
";margin:3;font-weight:normal;}");
//$NON-NLS-1$
jTextPane1.setContentType("text/html");
jTextPane1.setEditable(false);
jTextPane1.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
JTextPane pane = (JTextPane) e.getSource();
if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
pane.setToolTipText(e.getDescription());
} else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
pane.setToolTipText(null);
} else if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (System.getProperty("os.name", "unknown").toLowerCase().startsWith("linux")) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
try {
//$NON-NLS-1$
String cmd = String.format("xdg-open %s", e.getURL());
Runtime.getRuntime().exec(cmd);
} catch (IOException e1) {
System.err.println("Unable to launch the WEB browser");
e1.printStackTrace();
}
} else if (Desktop.isDesktopSupported()) {
final Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(e.getURL().toURI());
} catch (Exception ex) {
System.err.println("Unable to launch the WEB browser");
}
}
}
}
}
});
//$NON-NLS-1$
message.append("<BR>");
//$NON-NLS-1$
String rn = Messages.getString("WeasisLauncher.release");
message.append(//$NON-NLS-1$
String.format(//$NON-NLS-1$
"<a href=\"%s", releaseNotesUrl));
//$NON-NLS-1$
message.append("\" style=\"color:#FF9900\">");
message.append(rn);
//$NON-NLS-1$
message.append("</a>");
//$NON-NLS-1$
message.append("</P>");
jTextPane1.setText(message.toString());
JOptionPane.showMessageDialog(mainFrame.getRootPaneContainer() == null ? null : mainFrame.getRootPaneContainer().getContentPane(), jTextPane1, Messages.getString("WeasisLauncher.News"), //$NON-NLS-1$
JOptionPane.PLAIN_MESSAGE);
});
}
}
}Example 52
| Project: FTBLaunch-master File: OSUtils.java View source code |
public static StyleSheet makeStyleSheet(String name) { try { StyleSheet sheet = new StyleSheet(); Reader reader = new InputStreamReader(System.class.getResourceAsStream("/css/" + name + ".css")); sheet.loadRules(reader, null); reader.close(); return sheet; } catch (Exception ex) { ex.printStackTrace(); return null; } }
Example 53
| Project: FTNTLaunch-master File: OSUtils.java View source code |
public static StyleSheet makeStyleSheet(String name) { try { StyleSheet sheet = new StyleSheet(); Reader reader = new InputStreamReader(System.class.getResourceAsStream("/css/" + name + ".css")); sheet.loadRules(reader, null); reader.close(); return sheet; } catch (Exception ex) { ex.printStackTrace(); return null; } }
Example 54
| Project: multibit-hd-master File: HelpScreenView.java View source code |
/**
* @return The HTML editor kit providing the CSS styles
*/
private HTMLEditorKit createEditorKit() {
// Create an HTML editor kit
HTMLEditorKit kit = new HTMLEditorKit() {
@Override
public Document createDefaultDocument() {
return super.createDefaultDocument();
}
};
// Set a basic style sheet
StyleSheet styleSheet = kit.getStyleSheet();
// Avoid setting the background here since it can bleed through the look and feel
styleSheet.addRule("body{font-family:\"Helvetica Neue\",\"Liberation Sans\",Arial,sans-serif;margin:0;padding:0;}");
styleSheet.addRule("h1,h2{font-family:\"Helvetica Neue\",\"Liberation Sans\",Arial,sans-serif;font-weight:normal;}");
Color headingHexColor = Themes.currentTheme.text();
String headingHexColorString = String.format("#%02x%02x%02x", headingHexColor.getRed(), headingHexColor.getGreen(), headingHexColor.getBlue());
styleSheet.addRule("h1{color:" + headingHexColorString + ";font-size:200%;}");
styleSheet.addRule("h2{color:" + headingHexColorString + ";font-size:180%;}");
styleSheet.addRule("h3{color:" + headingHexColorString + ";font-size:150%;}");
styleSheet.addRule("h4{color:" + headingHexColorString + ";font-size:120%;}");
styleSheet.addRule("h1 img,h2 img,h3 img{vertical-align:middle;margin-right:5px;}");
styleSheet.addRule("a { color: " + linkHexColor + "; font-weight:bold;}");
styleSheet.addRule("a img{border:0;}");
return kit;
}Example 55
| Project: pcgen-deprecated-master File: RelativeImageView.java View source code |
/**
* Update any cached values that come from attributes.
*/
protected void setPropertiesFromAttributes() {
StyleSheet sheet = getStyleSheet();
this.attr = sheet.getViewAttributes(this);
// Gutters
borderSize = (short) getIntAttr(HTML.Attribute.BORDER, isLink() ? DEFAULT_BORDER : 0);
if ((borderSize == 0) && (image == null)) {
borderSize = 1;
}
leftInset = rightInset = (short) (getIntAttr(HTML.Attribute.HSPACE, 0) + borderSize);
topInset = bottomInset = (short) (getIntAttr(HTML.Attribute.VSPACE, 0) + borderSize);
borderColor = ((StyledDocument) getDocument()).getForeground(getAttributes());
AttributeSet anAttr = getElement().getAttributes();
// Alignment.
// PENDING: This needs to be changed to support the CSS versions
// when conversion from ALIGN to VERTICAL_ALIGN is complete.
Object alignment = anAttr.getAttribute(HTML.Attribute.ALIGN);
vAlign = 1.0f;
if (alignment != null) {
alignment = alignment.toString();
if ("top".equals(alignment)) {
vAlign = 0f;
} else if ("middle".equals(alignment)) {
vAlign = .5f;
}
}
AttributeSet anchorAttr = (AttributeSet) anAttr.getAttribute(HTML.Tag.A);
if ((anchorAttr != null) && anchorAttr.isDefined(HTML.Attribute.HREF)) {
synchronized (this) {
state |= LINK_FLAG;
}
} else {
synchronized (this) {
state = (state | LINK_FLAG) ^ LINK_FLAG;
}
}
}Example 56
| Project: pcgen-master File: RelativeImageView.java View source code |
/**
* Update any cached values that come from attributes.
*/
protected void setPropertiesFromAttributes() {
StyleSheet sheet = getStyleSheet();
this.attr = sheet.getViewAttributes(this);
// Gutters
borderSize = (short) getIntAttr(HTML.Attribute.BORDER, isLink() ? DEFAULT_BORDER : 0);
if ((borderSize == 0) && (image == null)) {
borderSize = 1;
}
leftInset = rightInset = (short) (getIntAttr(HTML.Attribute.HSPACE, 0) + borderSize);
topInset = bottomInset = (short) (getIntAttr(HTML.Attribute.VSPACE, 0) + borderSize);
borderColor = ((StyledDocument) getDocument()).getForeground(getAttributes());
AttributeSet anAttr = getElement().getAttributes();
// Alignment.
// PENDING: This needs to be changed to support the CSS versions
// when conversion from ALIGN to VERTICAL_ALIGN is complete.
Object alignment = anAttr.getAttribute(HTML.Attribute.ALIGN);
vAlign = 1.0f;
if (alignment != null) {
alignment = alignment.toString();
if ("top".equals(alignment)) {
vAlign = 0.0f;
} else if ("middle".equals(alignment)) {
vAlign = 0.5f;
}
}
AttributeSet anchorAttr = (AttributeSet) anAttr.getAttribute(HTML.Tag.A);
if ((anchorAttr != null) && anchorAttr.isDefined(HTML.Attribute.HREF)) {
synchronized (this) {
state |= LINK_FLAG;
}
} else {
synchronized (this) {
state = (state | LINK_FLAG) ^ LINK_FLAG;
}
}
}Example 57
| Project: PokemonLabClient-master File: ServerConnect.java View source code |
private static void setHtmlMessage(JEditorPane pane, String message) {
HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet css = new StyleSheet();
css.addRule("a {color: blue; text-decoration: underline;}");
kit.setStyleSheet(css);
HyperlinkListener listener = new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
LobbyWindow.viewWebPage(e.getURL());
}
}
};
pane.setEditorKit(kit);
pane.addHyperlinkListener(listener);
message = "<p>" + message;
message = message.replaceAll("\n", "</p><p>");
message += "</p>";
HTMLDocument doc = (HTMLDocument) pane.getDocument();
try {
kit.insertHTML(doc, 0, message, 0, 0, null);
} catch (Exception e) {
}
pane.setCaretPosition(0);
}Example 58
| Project: praxis-live-master File: PraxisLiveLookAndFeel.java View source code |
@Override
public Object call() throws Exception {
//change the default link foreground color
HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet newStyleSheet = new StyleSheet();
Font f = new JLabel().getFont();
newStyleSheet.addRule(// NOI18N
new StringBuffer("body { font-size: ").append(f.getSize()).append("; font-family: ").append(f.getName()).append(// NOI18N
"; }").toString());
//NOI18N
newStyleSheet.addRule("a { color: #A4A4FF; text-decoration: underline}");
newStyleSheet.addStyleSheet(kit.getStyleSheet());
kit.setStyleSheet(newStyleSheet);
return null;
}Example 59
| Project: process-master File: DetailPanel.java View source code |
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Sets coloring based on whether installed or not;
* also makes ugly blue HTML links into the specified color (black).
*/
static void setForegroundStyle(JTextPane textPane, boolean installed, boolean selected) {
Document doc = textPane.getDocument();
if (doc instanceof HTMLDocument) {
HTMLDocument html = (HTMLDocument) doc;
StyleSheet stylesheet = html.getStyleSheet();
// slightly grayed when installed
String c = (installed && !selected) ? "#555555" : "#000000";
stylesheet.addRule("body { color:" + c + "; }");
stylesheet.addRule("a { color:" + c + "; }");
}
}Example 60
| Project: processing-master File: DetailPanel.java View source code |
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Sets coloring based on whether installed or not;
* also makes ugly blue HTML links into the specified color (black).
*/
static void setForegroundStyle(JTextPane textPane, boolean installed, boolean selected) {
Document doc = textPane.getDocument();
if (doc instanceof HTMLDocument) {
HTMLDocument html = (HTMLDocument) doc;
StyleSheet stylesheet = html.getStyleSheet();
// slightly grayed when installed
String c = (installed && !selected) ? "#555555" : "#000000";
stylesheet.addRule("body { color:" + c + "; }");
stylesheet.addRule("a { color:" + c + "; }");
}
}Example 61
| Project: Clotho-Core-master File: SeqCheckerTopComponent.java View source code |
protected void addHTMLPane() {
_htmlPane = new JEditorPane();
_htmlPane.setEditable(false);
_scrollPane4 = new JScrollPane(_htmlPane);
HTMLEditorKit kit = new HTMLEditorKit();
_htmlPane.setEditorKit(kit);
// StyleSheet styleSheet = kit.getStyleSheet();
// styleSheet.addRule("body {color:#000; font-family:times; margin: 4px; }");
// styleSheet.addRule("h1 {color: blue;}");
// styleSheet.addRule("h2 {color: #ff0000;}");
// styleSheet.addRule("pre {font : 10px monaco; color : black; background-color : #fafafa; }");
String htmlString = "<html>\n" + "<body>\n" + "<h2>Sequence Check Details</h2>\n" + "<p>The DNA sequence level details of a check are displayed in this space.</p>\n" + "</body>\n";
Document doc = kit.createDefaultDocument();
_htmlPane.setDocument(doc);
_htmlPane.setText(htmlString);
_mainSplitPane.setRightComponent(_scrollPane4);
_mainSplitPane.setDividerLocation(200);
}Example 62
| Project: ClothoBiofabEdition-master File: SeqCheckerTopComponent.java View source code |
protected void addHTMLPane() {
_htmlPane = new JEditorPane();
_htmlPane.setEditable(false);
_scrollPane4 = new JScrollPane(_htmlPane);
HTMLEditorKit kit = new HTMLEditorKit();
_htmlPane.setEditorKit(kit);
// StyleSheet styleSheet = kit.getStyleSheet();
// styleSheet.addRule("body {color:#000; font-family:times; margin: 4px; }");
// styleSheet.addRule("h1 {color: blue;}");
// styleSheet.addRule("h2 {color: #ff0000;}");
// styleSheet.addRule("pre {font : 10px monaco; color : black; background-color : #fafafa; }");
String htmlString = "<html>\n" + "<body>\n" + "<h2>Sequence Check Details</h2>\n" + "<p>The DNA sequence level details of a check are displayed in this space.</p>\n" + "</body>\n";
Document doc = kit.createDefaultDocument();
_htmlPane.setDocument(doc);
_htmlPane.setText(htmlString);
_mainSplitPane.setRightComponent(_scrollPane4);
_mainSplitPane.setDividerLocation(200);
}Example 63
| Project: idea-multimarkdown-master File: MultiMarkdownPreviewEditor.java View source code |
protected void setStyleSheet() {
if (isRawHtml)
return;
MultiMarkdownEditorKit htmlKit = new MultiMarkdownEditorKit();
final StyleSheet style = new MultiMarkdownStyleSheet();
if (!MultiMarkdownGlobalSettings.getInstance().useCustomCss(false)) {
style.importStyleSheet(MultiMarkdownGlobalSettings.getInstance().getCssFileURL(false));
} else {
try {
style.loadRules(new StringReader(MultiMarkdownGlobalSettings.getInstance().getCssText(false)), null);
} catch (IOException e) {
e.printStackTrace();
}
}
htmlKit.setStyleSheet(style);
jEditorPane.setEditorKit(htmlKit);
}Example 64
| Project: kolmafia-master File: BasicHyperlinkUI.java View source code |
/**
* Overriden to return our own slimmed down style sheet.
*/
@Override
public StyleSheet getStyleSheet() {
if (defaultStyles == null) {
defaultStyles = new StyleSheet();
StringReader r = new StringReader(styleChanges);
try {
defaultStyles.loadRules(r, null);
} catch (Throwable e) {
}
r.close();
defaultStyles.addStyleSheet(super.getStyleSheet());
}
return defaultStyles;
}Example 65
| Project: pentaho-reporting-master File: HtmlRichTextConverter.java View source code |
private static AttributeSet computeStyle(final javax.swing.text.Element elem, final StyleSheet styles) {
final AttributeSet a = elem.getAttributes();
final AttributeSet htmlAttr = styles.translateHTMLToCSS(a);
final ArrayList<AttributeSet> muxList = new ArrayList<AttributeSet>();
if (htmlAttr.getAttributeCount() != 0) {
muxList.add(htmlAttr);
}
if (elem.isLeaf()) {
// The swing-parser has a very weird way of storing attributes for the HTML elements. The
// tag-name is used as key for the attribute set, so you have to know the element type before
// you can do anything sensible with it. Or as we do here, you have to search for the HTML.Tag
// object. Arghh.
final Enumeration keys = a.getAttributeNames();
while (keys.hasMoreElements()) {
final Object key = keys.nextElement();
if (!(key instanceof HTML.Tag)) {
continue;
}
if (key == HTML.Tag.A) {
final Object o = a.getAttribute(key);
if (o instanceof AttributeSet) {
final AttributeSet attr = (AttributeSet) o;
if (attr.getAttribute(HTML.Attribute.HREF) == null) {
continue;
} else {
SimpleAttributeSet hrefAttributeSet = new SimpleAttributeSet();
hrefAttributeSet.addAttribute(HTML.Attribute.HREF, attr.getAttribute(HTML.Attribute.HREF));
muxList.add(hrefAttributeSet);
}
}
}
final AttributeSet cssRule = styles.getRule((HTML.Tag) key, elem);
if (cssRule != null) {
muxList.add(cssRule);
}
}
} else {
final HTML.Tag t = (HTML.Tag) a.getAttribute(StyleConstants.NameAttribute);
final AttributeSet cssRule = styles.getRule(t, elem);
if (cssRule != null) {
muxList.add(cssRule);
}
}
final MutableAttributeSet retval = new SimpleAttributeSet();
for (int i = muxList.size() - 1; i >= 0; i--) {
final AttributeSet o = muxList.get(i);
retval.addAttributes(o);
}
return retval;
}Example 66
| Project: Scute-master File: BasicHyperlinkUI.java View source code |
/**
* Overriden to return our own slimmed down style sheet.
*/
@Override
public StyleSheet getStyleSheet() {
if (defaultStyles == null) {
defaultStyles = new StyleSheet();
StringReader r = new StringReader(styleChanges);
try {
defaultStyles.loadRules(r, null);
} catch (Throwable e) {
}
r.close();
defaultStyles.addStyleSheet(super.getStyleSheet());
}
return defaultStyles;
}Example 67
| Project: SikuliX-2014-master File: BasicHyperlinkUI.java View source code |
/**
* Overriden to return our own slimmed down style sheet.
*/
@Override
public StyleSheet getStyleSheet() {
if (defaultStyles == null) {
defaultStyles = new StyleSheet();
StringReader r = new StringReader(styleChanges);
try {
defaultStyles.loadRules(r, null);
} catch (Throwable e) {
}
r.close();
defaultStyles.addStyleSheet(super.getStyleSheet());
}
return defaultStyles;
}Example 68
| Project: swingx-master File: BasicHyperlinkUI.java View source code |
/**
* Overriden to return our own slimmed down style sheet.
*/
@Override
public StyleSheet getStyleSheet() {
if (defaultStyles == null) {
defaultStyles = new StyleSheet();
StringReader r = new StringReader(styleChanges);
try {
defaultStyles.loadRules(r, null);
} catch (Throwable e) {
}
r.close();
defaultStyles.addStyleSheet(super.getStyleSheet());
}
return defaultStyles;
}Example 69
| Project: VUE-master File: FontEditorPanel.java View source code |
AttributeSet getMaxAttributes(RichTextBox editorPane, String elemName) {
SHTMLDocument doc = (SHTMLDocument) editorPane.getDocument();
Element e = doc.getCharacterElement(editorPane.getSelectionStart());
StyleSheet s = doc.getStyleSheet();
if (elemName != null && elemName.length() > 0) {
e = Util.findElementUp(elemName, e);
return SHTMLPanelImpl.getMaxAttributes(e, s);
}
final MutableAttributeSet maxAttributes = (MutableAttributeSet) SHTMLPanelImpl.getMaxAttributes(e, s);
final StyledEditorKit editorKit = (StyledEditorKit) editorPane.getEditorKit();
final MutableAttributeSet inputAttributes = editorKit.getInputAttributes();
maxAttributes.addAttributes(inputAttributes);
return maxAttributes;
}Example 70
| Project: org.revisionfilter-master File: MainFrame.java View source code |
private void setStyleSheets() {
StyleSheet styleSheet = new StyleSheet();
styleSheet.addRule("body {font-size: " + Driver.getFontSize() + "pt}");
styleSheet.addRule("H1 {color: red; font-size: 120%; font-weight: bold;}");
styleSheet.addRule("code {font-family: courier; font-size: " + Driver.getFontSize() + "pt}");
styleSheet.addRule(" a:link { color: #0000FF; } ");
styleSheet.addRule(" a:visited { color: #800080; } ");
styleSheet.addRule(" a:active { color: #FF0000; text-decoration: underline; } ");
htmlEditorKit.setStyleSheet(styleSheet);
summaryHtmlArea.setEditorKit(htmlEditorKit);
}Example 71
| Project: servoy-client-master File: FixedHTMLEditorKit.java View source code |
/**
* Create an uninitialized text storage model that is appropriate for this type of editor.
*
* @return the model
*/
@Override
public Document createDefaultDocument() {
StyleSheet styles = getStyleSheet();
StyleSheet ss = createStyleSheet();
ss.addStyleSheet(styles);
// make <BR> tags add "\n" into the document and do not add white space "\n" to the document
HTMLDocument doc = new HTMLDocument(ss) {
@Override
public ParserCallback getReader(int pos) {
Object desc = getProperty(Document.StreamDescriptionProperty);
if (desc instanceof URL) {
setBase((URL) desc);
}
HTMLReader reader = new HTMLReader(pos) {
private boolean insideHead = false;
@Override
protected void addSpecialElement(Tag t, MutableAttributeSet a) {
int l1 = parseBuffer.size();
super.addSpecialElement(t, a);
if (l1 < parseBuffer.size() && t == HTML.Tag.BR) {
char[] one = new char[1];
one[0] = '\n';
ElementSpec es = parseBuffer.lastElement();
ElementSpec newEs = new ElementSpec(es.getAttributes().copyAttributes(), ElementSpec.ContentType, one, 0, 1);
parseBuffer.setElementAt(newEs, parseBuffer.size() - 1);
}
}
@Override
protected void blockClose(Tag t) {
super.blockClose(t);
if (t == HTML.Tag.HEAD) {
insideHead = false;
}
}
@Override
protected void blockOpen(Tag t, MutableAttributeSet attr) {
super.blockOpen(t, attr);
if (t == HTML.Tag.HEAD) {
insideHead = true;
}
}
@Override
protected void addContent(char[] data, int offs, int length, boolean generateImpliedPIfNecessary) {
if (!insideHead) {
super.addContent(data, offs, length, generateImpliedPIfNecessary);
}
}
};
return reader;
}
};
doc.setParser(getParser());
doc.setAsynchronousLoadPriority(4);
doc.setTokenThreshold(50);
return doc;
}Example 72
| Project: asciidoctor-intellij-plugin-master File: UIUtil.java View source code |
@NotNull public static StyleSheet loadStyleSheet(@NotNull URL url) { try { StyleSheet styleSheet = new StyleSheet(); styleSheet.loadRules(new InputStreamReader(url.openStream(), CharsetToolkit.UTF8), url); return styleSheet; } catch (IOException e) { throw new RuntimeException(e); } }
Example 73
| Project: inquisition-master File: ExplanationPanelHTMLEditorKit.java View source code |
@Override
public Document createDefaultDocument() {
StyleSheet styles = getStyleSheet();
HTMLDocument doc = new HTMLDocument(styles);
return doc;
}Example 74
| Project: openflexo-master File: FlexoCSSResource.java View source code |
public StyleSheet getStyleSheet() throws MalformedURLException { if (styleSheet == null) { styleSheet = new StyleSheet(); styleSheet.importStyleSheet(getFile().toURI().toURL()); } return styleSheet; }
Example 75
| Project: carrie-in-java-master File: JPanelHTML.java View source code |
public StyleSheet getStyleSheetFromEditorPane() {
javax.swing.text.html.HTMLEditorKit kit = (HTMLEditorKit) content.getEditorKit();
return kit.getStyleSheet();
}Example 76
| Project: epublib-master File: MyHtmlEditorKit.java View source code |
public void setStyleSheet(StyleSheet s) {
htmlEditorKit.setStyleSheet(s);
}Example 77
| Project: jeboorker-master File: MyHtmlEditorKit.java View source code |
public void setStyleSheet(StyleSheet s) {
htmlEditorKit.setStyleSheet(s);
}Example 78
| Project: josm-plugins-master File: IssueView.java View source code |
/**
* Builds the style sheet used in the internal help browser
*
* @return the style sheet
*/
protected void initStyleSheet(HtmlPanel view) {
StyleSheet ss = ((HTMLEditorKit) view.getEditorPane().getEditorKit()).getStyleSheet();
ss.addRule("em {font-style: italic}");
ss.addRule("tt {font-family: Courier New}");
ss.addRule(".object-name {background-color:rgb(240, 240, 240); color: blue;}");
}Example 79
| Project: Thngm-master File: HTMLOptionsPane.java View source code |
public void setStyleSheet(StyleSheet ss) {
styleSheet = ss;
}Example 80
| Project: GameMaker-HTML5-Player-master File: AboutBox.java View source code |
protected static void addSSRules(StyleSheet s) {
s.addRule("body { font-size: 12pt; font-family: Dialog; }");
}Example 81
| Project: LateralGM-master File: AboutBox.java View source code |
protected static void addSSRules(StyleSheet s) {
s.addRule("body { font-size: 12pt; font-family: Dialog; }");
}Example 82
| Project: LibMaker-master File: AboutBox.java View source code |
protected static void addSSRules(StyleSheet s) {
s.addRule("body { font-size: 12pt; font-family: Dialog; }");
}Example 83
| Project: visualvm-master File: ThreadDumpView.java View source code |
@Override
public Document createDefaultDocument() {
StyleSheet styles = getStyleSheet();
StyleSheet ss = new StyleSheet();
ss.addStyleSheet(styles);
HTMLDocument doc = new CustomHTMLDocument(ss);
doc.setParser(getParser());
doc.setAsynchronousLoadPriority(4);
doc.setTokenThreshold(100);
return doc;
}Example 84
| Project: Open-Quark-master File: NavViewerPane.java View source code |
/**
* @see javax.swing.text.EditorKit#createDefaultDocument()
*/
@Override
public Document createDefaultDocument() {
StyleSheet styles = getStyleSheet();
NavHtmlDocument doc = new NavHtmlDocument(styles);
doc.setParser(getParser());
doc.setAsynchronousLoadPriority(4);
doc.setTokenThreshold(100);
return doc;
}Example 85
| Project: xowa-master File: GxwTextHtml_lang.java View source code |
public void Html_css_set(String s) {
StyleSheet styleSheet = htmlKit.getStyleSheet();
styleSheet.addRule(s);
}