Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.mihalis.opal/src/main/java/org/mihalis/opal/preferenceWindow/widgets/PWLabel.java')
-rw-r--r--org.mihalis.opal/src/main/java/org/mihalis/opal/preferenceWindow/widgets/PWLabel.java92
1 files changed, 92 insertions, 0 deletions
diff --git a/org.mihalis.opal/src/main/java/org/mihalis/opal/preferenceWindow/widgets/PWLabel.java b/org.mihalis.opal/src/main/java/org/mihalis/opal/preferenceWindow/widgets/PWLabel.java
new file mode 100644
index 0000000..353ba75
--- /dev/null
+++ b/org.mihalis.opal/src/main/java/org/mihalis/opal/preferenceWindow/widgets/PWLabel.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.mihalis.opal.utils.SWTGraphicUtil;
+
+/**
+ * Instances of this class are labels, that could contain some HTML tags
+ * (B,I,U).
+ */
+public class PWLabel extends PWWidget {
+
+ /** The label widget. */
+ private StyledText labelWidget;
+
+ /**
+ * Constructor.
+ *
+ * @param label associated label
+ */
+ public PWLabel(final String label) {
+ super(label, null, 1, true);
+ setAlignment(GridData.FILL);
+ setGrabExcessSpace(true);
+ }
+
+ /**
+ * Builds the.
+ *
+ * @param parent the parent
+ * @return the control
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ if (getLabel() == null) {
+ throw new UnsupportedOperationException("You need to set a description for a PWLabel object");
+ }
+ this.labelWidget = new StyledText(parent, SWT.WRAP | SWT.READ_ONLY);
+ this.labelWidget.setEnabled(false);
+ this.labelWidget.setBackground(parent.getBackground());
+ this.labelWidget.setText(getLabel());
+ SWTGraphicUtil.applyHTMLFormating(this.labelWidget);
+ return this.labelWidget;
+ }
+
+ /**
+ * Check.
+ *
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ }
+
+ /**
+ * Enable or disable.
+ *
+ * @return true, if successful
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#enableOrDisable()
+ */
+ @Override
+ public boolean enableOrDisable() {
+ if (this.enabler == null) {
+ return true;
+ }
+
+ final boolean enabled = this.enabler.isEnabled();
+ if (!this.labelWidget.isDisposed()) {
+ if (enabled) {
+ this.labelWidget.setForeground(this.labelWidget.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+ } else {
+ this.labelWidget.setForeground(this.labelWidget.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
+ }
+ }
+ return enabled;
+ }
+
+}

Back to the top