Java Doc for StyledLabelBuilder.java in  » Swing-Library » jide-common » com » jidesoft » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jide common » com.jidesoft.swing 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.jidesoft.swing.StyledLabelBuilder

StyledLabelBuilder
public class StyledLabelBuilder (Code)
StyledLabelBuilder is a quick way to define StyledLabel. It provides two ways to handle the creation and modification of StyleLabels.

The first is to use it as a builder (thus the name). This way is preferred if you want to create a StyledLabel with a specific format and partially generic content. Example:

StyledLabel label = new StyledLabelBuilder()
 .add(file.getName())
 .add(" (", Font.BOLD)
 .add(file.getPath(), "italic") // using annotation style - see section two for information about annotations
 .add(")", Font.BOLD)
 .createLabel();
This code would be used to create a label like "something.txt (/temp/something.txt)" with some styling (the braces would be bold, the path would be italic). In case you find yourself reusing a specific style quite often in such a label you might consider to create a style for it. This can be done with the help of the StyledLabelBuilder.register -methods. As an example, the code above could be rewritten like this (though it only pays off when used for creation of longer styles):
StyledLabelBuilder builder = new StyledLabelBuilder()
 .register("OPERATOR", Font.BOLD, new Color(0x000052)) // use parameters
 .register("PATH", "italic, f:#0000CD"); // or style annotations
 StyledLabel label = builder
 .add(file.getName())
 .add(" (", "OPERATOR")
 .add(file.getPath(), "PATH,underlined") // use a style + style annotation
 .add(")", "OPERATOR")
 .createLabel();
Note that we're using different font colors this time. It pays off as soon as you want to modify a specific group of text parts or as your styles start to get more complicated. The StyledLabelBuilder.clear() -method is very useful if you want to use these styles. Instead of re-creating a new builder each time, you can use the clear-method to clear the internal buffer of text without removing the previously defined styles.

Let's have an example (we're going to reuse the code from above!):

builder.clear();
 builder
 .add(file.getName())
 .add(" (", "OPERATOR")
 .add(file.getPath(), "PATH")
 .add(")", "OPERATOR")
 .configure(label);

If we were using Java 5, we could also do this:

// no need to call 
StyledLabelBuilder.clear()  this time
 builder.configure(label, String.format("%s ({%s:PATH})", file.getName(), file.getPath()));

Each of the StyledLabelBuilder.add and StyledLabelBuilder.register methods is the same as using the corresponding StyleRange-constructor directly (except that you don't have to care about its start and length).

The second, even more advanced, way to use this class is in combination with an annotated string. Using the static StyledLabelBuilder.setStyledText or StyledLabelBuilder.createStyledLabel methods you can create a fully styled label from just on string. This is ideal if you need the string to be configurable or locale-specific. The usage is even more easy than the builder-approach: StyledLabel label = StyledLabelBuilder.createStyledLabel("I'm your {first:bold} styled {label:italic}!"); In the above example, the resulting label would have a a bold "first" and an italic "label". Each annotation is started by a "{" and ended by a "}". The text you want to be styled accordingly is seperated from its annotations by a ":". If your text needs to contain a ":" itself, you need to escape it using the "\" character. The same goes for "{" that are not supposed to start an annotation. You don't need to escape the "}" at all. If it is used within the annotated string it'll be ignored. It only counts after the annotation seperator (":"). There are multiply annotations available. Each annotation offers a shortcut made up from one or two of their characters. For example: We used "bold" and "italic" in the example above, but we could've used "b" and "i" instead. It is also possible to combine multiple styles by seperating them with a ",". As an example: {This text is bold, italic and blue:b,i,f:blue} Instead of writing "b,i" you can also write "bi" or "bolditalic". This example brings us to colors. They've to be started with "f" or "font" for the font-color or "l" or "line" for the line-color or "b" or "background" for the background color. There are a lot of ways to specify a color. You may use its HTML name (as I did in the above example) or any of these: f:(0,0,255) f:#00F l:#0000FF l:0x0000FF The "#00F" notation is just like it is in CSS. It is the same as if you had written "#0000FF". You can get and modify the map of color-names the parser is using with the static StyledLabelBuilder.getColorNamesMap() -method.

You saw some styles above. Here is a complete list of styles and its shortcut.

Font styles

  • plain or p
  • bold or b
  • italic or i
  • bolditalic or bi
Additional styles
  • strike or s
  • doublestrike or ds
  • waved or w
  • underlined or u
  • dotted or d
  • superscript or sp
  • subscript or sb


author:
   Patrick Gotthardt




Constructor Summary
public  StyledLabelBuilder()
    

Method Summary
public  StyledLabelBuilderadd(String text)
    
public  StyledLabelBuilderadd(String text, Color fontColor)
    
public  StyledLabelBuilderadd(String text, int fontStyle)
    
public  StyledLabelBuilderadd(String text, int fontStyle, Color fontColor)
    
public  StyledLabelBuilderadd(String text, int fontStyle, Color fontColor, int additionalStyle)
    
public  StyledLabelBuilderadd(String text, int fontStyle, Color fontColor, int additionalStyle, Color lineColor)
    
public  StyledLabelBuilderadd(String text, int fontStyle, Color fontColor, Color backgroundColor, int additionalStyle, Color lineColor)
    
public  StyledLabelBuilderadd(String text, int fontStyle, Color fontColor, Color backgroundColor, int additionalStyle, Color lineColor, Stroke lineStroke)
    
public  StyledLabelBuilderadd(String text, int fontStyle, Color fontColor, int additionalStyle, Color lineColor, Stroke lineStroke, float fontShrinkRatio)
    
public  StyledLabelBuilderadd(String text, String style)
    
public  StyledLabelBuilderadd(String text, int fontStyle, int additionalStyle)
    
public  StyledLabelBuilderadd(String text, int fontStyle, int additionalStyle, float fontShrinkRatio)
    
public  voidclear()
    
public  StyledLabelconfigure(StyledLabel label, String style)
    
public  StyledLabelconfigure(StyledLabel label)
    
public  StyledLabelcreateLabel()
    
public static  StyledLabelcreateStyledLabel(String text)
    
public static  MapgetColorNamesMap()
    
public  StyledLabelBuilderregister(String text, Color fontColor)
    
public  StyledLabelBuilderregister(String text, int fontStyle)
    
public  StyledLabelBuilderregister(String text, int fontStyle, Color fontColor)
    
public  StyledLabelBuilderregister(String text, int fontStyle, Color fontColor, int additionalStyle)
    
public  StyledLabelBuilderregister(String text, int fontStyle, Color fontColor, int additionalStyle, Color lineColor)
    
public  StyledLabelBuilderregister(String text, int fontStyle, Color fontColor, int additionalStyle, Color lineColor, Stroke lineStroke)
    
public  StyledLabelBuilderregister(String text, int fontStyle, Color fontColor, int additionalStyle, Color lineColor, Stroke lineStroke, float fontShrinkRatio)
    
public  StyledLabelBuilderregister(String text, int fontStyle, int additionalStyle)
    
public  StyledLabelBuilderregister(String text, int fontStyle, int additionalStyle, float fontShrinkRatio)
    
public  StyledLabelBuilderregister(String text, String format)
    
public static  voidsetStyledText(StyledLabel label, String text)
    
public static  voidsetStyledText(StyledLabel label, char[] text)
    


Constructor Detail
StyledLabelBuilder
public StyledLabelBuilder()(Code)




Method Detail
add
public StyledLabelBuilder add(String text)(Code)



add
public StyledLabelBuilder add(String text, Color fontColor)(Code)



add
public StyledLabelBuilder add(String text, int fontStyle)(Code)



add
public StyledLabelBuilder add(String text, int fontStyle, Color fontColor)(Code)



add
public StyledLabelBuilder add(String text, int fontStyle, Color fontColor, int additionalStyle)(Code)



add
public StyledLabelBuilder add(String text, int fontStyle, Color fontColor, int additionalStyle, Color lineColor)(Code)



add
public StyledLabelBuilder add(String text, int fontStyle, Color fontColor, Color backgroundColor, int additionalStyle, Color lineColor)(Code)



add
public StyledLabelBuilder add(String text, int fontStyle, Color fontColor, Color backgroundColor, int additionalStyle, Color lineColor, Stroke lineStroke)(Code)



add
public StyledLabelBuilder add(String text, int fontStyle, Color fontColor, int additionalStyle, Color lineColor, Stroke lineStroke, float fontShrinkRatio)(Code)



add
public StyledLabelBuilder add(String text, String style)(Code)



add
public StyledLabelBuilder add(String text, int fontStyle, int additionalStyle)(Code)



add
public StyledLabelBuilder add(String text, int fontStyle, int additionalStyle, float fontShrinkRatio)(Code)



clear
public void clear()(Code)



configure
public StyledLabel configure(StyledLabel label, String style)(Code)



configure
public StyledLabel configure(StyledLabel label)(Code)



createLabel
public StyledLabel createLabel()(Code)



createStyledLabel
public static StyledLabel createStyledLabel(String text)(Code)



getColorNamesMap
public static Map getColorNamesMap()(Code)



register
public StyledLabelBuilder register(String text, Color fontColor)(Code)



register
public StyledLabelBuilder register(String text, int fontStyle)(Code)



register
public StyledLabelBuilder register(String text, int fontStyle, Color fontColor)(Code)



register
public StyledLabelBuilder register(String text, int fontStyle, Color fontColor, int additionalStyle)(Code)



register
public StyledLabelBuilder register(String text, int fontStyle, Color fontColor, int additionalStyle, Color lineColor)(Code)



register
public StyledLabelBuilder register(String text, int fontStyle, Color fontColor, int additionalStyle, Color lineColor, Stroke lineStroke)(Code)



register
public StyledLabelBuilder register(String text, int fontStyle, Color fontColor, int additionalStyle, Color lineColor, Stroke lineStroke, float fontShrinkRatio)(Code)



register
public StyledLabelBuilder register(String text, int fontStyle, int additionalStyle)(Code)



register
public StyledLabelBuilder register(String text, int fontStyle, int additionalStyle, float fontShrinkRatio)(Code)



register
public StyledLabelBuilder register(String text, String format)(Code)



setStyledText
public static void setStyledText(StyledLabel label, String text)(Code)



setStyledText
public static void setStyledText(StyledLabel label, char[] text)(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.