/** * This file is protected by Copyright. * Please refer to the COPYRIGHT file distributed with this source distribution. * * This file is part of REDHAWK IDE. * * 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. * */ package gov.redhawk.sca.sad.diagram.palette; import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.MarginBorder; import org.eclipse.draw2d.RectangleFigure; import org.eclipse.draw2d.StackLayout; import org.eclipse.draw2d.text.FlowPage; import org.eclipse.draw2d.text.ParagraphTextLayout; import org.eclipse.draw2d.text.TextFlow; /** * @since 3.2 */ public class LabelFigure extends RectangleFigure { /** The inner TextFlow **/ private TextFlow textFlow; private boolean empty; /** * Creates a new LabelFigure with a MarginBorder that is the given size and * a FlowPage containing a TextFlow with the style WORD_WRAP_SOFT. * * @param borderSize * the size of the MarginBorder */ public LabelFigure() { setBorder(new MarginBorder(5, 5, 5, 5)); FlowPage flowPage = new FlowPage(); textFlow = new TextFlow(); textFlow.setLayoutManager(new ParagraphTextLayout(textFlow, ParagraphTextLayout.WORD_WRAP_SOFT)); flowPage.add(textFlow); setLayoutManager(new StackLayout()); add(flowPage); setBackgroundColor(ColorConstants.white); setForegroundColor(ColorConstants.lightGray); } /** * Returns the text inside the TextFlow. * * @return the text flow inside the text. */ public String getText() { if (empty) { return ""; } else { return textFlow.getText(); } } /** * Sets the text of the TextFlow to the given value. * * @param newText * the new text value. */ public void setText(String newText) { if (newText == null || newText.isEmpty()) { this.empty = true; newText = "type filter text"; textFlow.setForegroundColor(ColorConstants.lightGray); } else { this.empty = false; textFlow.setForegroundColor(ColorConstants.black); } textFlow.setText(newText); } }