use of javax.swing.text.Style in project binnavi by google.
the class BaseTypeTableCellRenderer method renderStruct.
private static void renderStruct(final TypeInstance instance, final StyledDocument document, final boolean renderData) {
final Style structNameStyle = createDeclarationStyle(document);
final Style structMemberStyle = document.addStyle("STRUCTMEMBERSTYLE", structNameStyle);
StyleConstants.setForeground(structMemberStyle, Color.GRAY);
final Style structContentStyle = document.addStyle("STRUCTCONTENTSTYLE", structNameStyle);
StyleConstants.setForeground(structContentStyle, Color.BLUE);
StyleConstants.setAlignment(structNameStyle, StyleConstants.ALIGN_RIGHT);
final BaseType baseType = instance.getBaseType();
int maxMemberLength = 0;
for (final TypeMember member : baseType) {
if (member.getBaseType().getName().length() > maxMemberLength) {
maxMemberLength = member.getBaseType().getName().length();
}
}
int maxNameLength = 0;
for (final TypeMember member : baseType) {
if (member.getName().length() > maxNameLength) {
maxNameLength = member.getName().length();
}
}
/* Renders type information for structures - construct a string such as:
*
* struct STRUCT_NAME { BASE_TYPE_NAME
*/
try {
document.remove(0, document.getLength());
appendString(document, "struct " + baseType.getName() + " {\n", structNameStyle);
long memberOffset = 0;
for (final TypeMember member : baseType) {
appendString(document, " " + member.getBaseType().getName(), structNameStyle);
final String separator = Strings.repeat(" ", maxMemberLength - member.getBaseType().getName().length() + 1);
appendString(document, separator + member.getName(), structMemberStyle);
appendString(document, ";", structMemberStyle);
if (renderData) {
final String dataSeperator = Strings.repeat(".", maxNameLength - member.getName().length() + 1);
appendString(document, dataSeperator, structNameStyle);
appendString(document, renderInstanceData(member.getBaseType(), instance.getAddress().getOffset() + memberOffset, instance.getSection()), createDataStyle(document));
memberOffset += member.getBaseType().getByteSize();
}
appendString(document, "\n", structMemberStyle);
}
appendString(document, "};", structNameStyle);
} catch (final BadLocationException exception) {
CUtilityFunctions.logException(exception);
}
}
use of javax.swing.text.Style in project binnavi by google.
the class BaseTypeTableCellRenderer method createDataStyle.
private static Style createDataStyle(final StyledDocument document) {
final Style declStyle = document.addStyle("DATA_STYLE", null);
StyleConstants.setBackground(declStyle, Color.WHITE);
StyleConstants.setForeground(declStyle, Color.BLUE);
StyleConstants.setFontFamily(declStyle, GuiHelper.getMonospaceFont());
StyleConstants.setFontSize(declStyle, 11);
return declStyle;
}
use of javax.swing.text.Style in project jmeter by apache.
the class SamplerResultTab method createResponseMetadataPanel.
private Component createResponseMetadataPanel() {
stats = new JTextPane();
stats.setEditable(false);
stats.setBackground(backGround);
// Add styles to use for different types of status messages
StyledDocument doc = (StyledDocument) stats.getDocument();
Style style = doc.addStyle(STYLE_REDIRECT, null);
StyleConstants.setForeground(style, REDIRECT_COLOR);
style = doc.addStyle(STYLE_CLIENT_ERROR, null);
StyleConstants.setForeground(style, CLIENT_ERROR_COLOR);
style = doc.addStyle(STYLE_SERVER_ERROR, null);
StyleConstants.setForeground(style, SERVER_ERROR_COLOR);
paneRaw = GuiUtils.makeScrollPane(stats);
paneRaw.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
// Set up the 1st table Result with empty headers
tableResult = new JTable(resultModel);
JMeterUtils.applyHiDPI(tableResult);
// $NON-NLS-1$
tableResult.setToolTipText(JMeterUtils.getResString("textbox_tooltip_cell"));
tableResult.addMouseListener(new TextBoxDoubleClick(tableResult));
setFirstColumnPreferredSize(tableResult);
RendererUtils.applyRenderers(tableResult, RENDERERS_RESULT);
// Set up the 2nd table
tableResHeaders = new JTable(resHeadersModel);
JMeterUtils.applyHiDPI(tableResHeaders);
// $NON-NLS-1$
tableResHeaders.setToolTipText(JMeterUtils.getResString("textbox_tooltip_cell"));
tableResHeaders.addMouseListener(new TextBoxDoubleClick(tableResHeaders));
setFirstColumnPreferredSize(tableResHeaders);
tableResHeaders.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer());
RendererUtils.applyRenderers(tableResHeaders, RENDERERS_HEADERS);
// Set up the 3rd table
tableResFields = new JTable(resFieldsModel);
JMeterUtils.applyHiDPI(tableResFields);
// $NON-NLS-1$
tableResFields.setToolTipText(JMeterUtils.getResString("textbox_tooltip_cell"));
tableResFields.addMouseListener(new TextBoxDoubleClick(tableResFields));
setFirstColumnPreferredSize(tableResFields);
tableResFields.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer());
RendererUtils.applyRenderers(tableResFields, RENDERERS_FIELDS);
// Prepare the Results tabbed pane
tabbedResult = new JTabbedPane(SwingConstants.BOTTOM);
// Create the split pane
JSplitPane topSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, GuiUtils.makeScrollPane(tableResHeaders), GuiUtils.makeScrollPane(tableResFields));
topSplit.setOneTouchExpandable(true);
// set split ratio
topSplit.setResizeWeight(0.80);
// see bug jdk 4131528
topSplit.setBorder(null);
paneParsed = new JSplitPane(JSplitPane.VERTICAL_SPLIT, GuiUtils.makeScrollPane(tableResult), topSplit);
paneParsed.setOneTouchExpandable(true);
// set split ratio
paneParsed.setResizeWeight(0.40);
// see bug jdk 4131528
paneParsed.setBorder(null);
// setup bottom tabs, first Raw, second Parsed
//$NON-NLS-1$
tabbedResult.addTab(JMeterUtils.getResString("view_results_table_result_tab_raw"), paneRaw);
//$NON-NLS-1$
tabbedResult.addTab(JMeterUtils.getResString("view_results_table_result_tab_parsed"), paneParsed);
// Hint to background color on bottom tabs (grey, not blue)
JPanel panel = new JPanel(new BorderLayout());
panel.add(tabbedResult);
return panel;
}
use of javax.swing.text.Style in project intellij-community by JetBrains.
the class NotificationMessageElement method updateStyle.
protected void updateStyle(@NotNull JEditorPane editorPane, @Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
final HTMLDocument htmlDocument = (HTMLDocument) editorPane.getDocument();
final Style style = htmlDocument.getStyleSheet().getStyle(MSG_STYLE);
if (value instanceof LoadingNode) {
StyleConstants.setForeground(style, JBColor.GRAY);
} else {
if (selected) {
StyleConstants.setForeground(style, hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground());
} else {
StyleConstants.setForeground(style, UIUtil.getTreeTextForeground());
}
}
if (UIUtil.isUnderGTKLookAndFeel() || UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus || tree != null && WideSelectionTreeUI.isWideSelection(tree)) {
editorPane.setOpaque(false);
} else {
editorPane.setOpaque(selected && hasFocus);
}
htmlDocument.setCharacterAttributes(0, htmlDocument.getLength(), style, false);
}
use of javax.swing.text.Style in project intellij-community by JetBrains.
the class NotificationMessageElement method installJep.
protected JEditorPane installJep(@NotNull JEditorPane myEditorPane) {
String message = StringUtil.join(this.getText(), "<br>");
myEditorPane.setEditable(false);
myEditorPane.setOpaque(false);
myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit());
myEditorPane.setHighlighter(null);
final StyleSheet styleSheet = ((HTMLDocument) myEditorPane.getDocument()).getStyleSheet();
final Style style = styleSheet.addStyle(MSG_STYLE, null);
styleSheet.addStyle(LINK_STYLE, style);
myEditorPane.setText(message);
return myEditorPane;
}
Aggregations