DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Reversing an Array: An Exploration of Array Manipulation
  • Red-Black Trees in C#: A Guide to Efficient Self-Balancing Binary Search Trees
  • Required Capabilities in Self-Navigating Vehicle-Processing Architectures
  • Dataweave Exercise: Filter Like Functions in Arrays Module - Part 1

Trending

  • Testing SingleStore's MCP Server
  • What Is Plagiarism? How to Avoid It and Cite Sources
  • Debugging With Confidence in the Age of Observability-First Systems
  • How to Format Articles for DZone
  1. DZone
  2. Coding
  3. Frameworks
  4. Adding Color and Font preferences

Adding Color and Font preferences

By 
Prakash  user avatar
Prakash
·
Oct. 15, 08 · Interview
Likes (0)
Comment
Save
Tweet
Share
13.6K Views

Join the DZone community and get the full member experience.

Join For Free

You had that nice looking editors and views. You loved the button color and the geeky font. But your boss didn't. Solution? Put a preference so that the user can choose which ever he likes ;-)

Ok. That may not be the real rationale, but for a valid reason, you wanted to have Color and Font preferences in the PreferencePage. The obvious answer for us (the plugin develoepers) would be to add ColorFieldEditor & FontFieldEditor in our existing PreferencePage. But its not obvious for the user to look into your plugins Preference Page for changing them. Eclipse already provides a PreferencePage for these customizations: Colors and Fonts page ( General->Appearance->Colors and Fonts ) Users might be looking into this place to change the colors & fonts.


As you can see in the above image it categorizes the available preferences; gives a filter to search; provides space for description and preview; and a tool tip for the current value of the preference. This is much more than the *FieldEditor right? In this tip let us see how to add our preferences into that and access them.

You need to extend the org.eclipse.ui.themes extension point for adding your content into this page. I would like to provide one category with one color preference and one font preference. The extension is:

<extension point="org.eclipse.ui.themes">
<themeElementCategory id="com.eclipse-tips.blog.preferences.themeElementCategory" label="Eclipse Tips">
<description>
An example theme category
</description>
</themeElementCategory>
<colorDefinition categoryId="com.eclipse-tips.blog.preferences.themeElementCategory" id="com.eclipse-tips.blog.preferences.colorDefinition" label="Some Color" value="COLOR_DARK_BLUE">
<description>
Your description goes here
</description>
</colorDefinition>
<fontDefinition categoryId="com.eclipse-tips.blog.preferences.themeElementCategory" id="com.eclipse-tips.blog.preferences.fontDefinition" label="Some Font" value="Lucida Sans-italic-18">
<description>
Description for this font
</description>
</fontDefinition>
</extension>

Guess all the elements are self explanatory - except for the value element. For colorDefinition the value element will be the COLOR_* constants defined in the SWT class. You can specify your custom colors thru comma separated RGB values like 125,245,96. For fontDefinition it would be fontname-style-height. Now our UI will look like:



To get the values stored in the preferences, you need to use the IThemeManager:

IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
ITheme currentTheme = themeManager.getCurrentTheme();
ColorRegistry colorRegistry = currentTheme.getColorRegistry();
Color color = colorRegistry.get("com.eclipse-tips.blog.preferences.colorDefinition");

FontRegistry fontRegistry = currentTheme.getFontRegistry();
Font font = fontRegistry.get("com.eclipse-tips.blog.preferences.fontDefinition");
Once you get the current theme, you can get the preferences stored by giving the appropriate ids defined in the plugin.xml

What you have seen is just the tip of the iceberg. The themes extension point has much more functionalities (The Preview is one such example). I'll explain them later, but you can see the Extension Point description here.

This is an extract from http://blog.eclipse-tips.com/2008/08/adding-color-and-font-preferences.html

Element Filter (software) Eclipse Self (programming language) Extract Standard Widget Toolkit Space (architecture)

Opinions expressed by DZone contributors are their own.

Related

  • Reversing an Array: An Exploration of Array Manipulation
  • Red-Black Trees in C#: A Guide to Efficient Self-Balancing Binary Search Trees
  • Required Capabilities in Self-Navigating Vehicle-Processing Architectures
  • Dataweave Exercise: Filter Like Functions in Arrays Module - Part 1

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: