public code v1
This commit is contained in:
@@ -0,0 +1,644 @@
|
||||
package flintstones.model.ui.service;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.StyledString;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.graphics.FontData;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Monitor;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.wb.swt.SWTResourceManager;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import flintstones.helper.debug.DH;
|
||||
import flintstones.model.ui.service.style.ForegroundStyler;
|
||||
|
||||
/**
|
||||
* The Interface UiService.
|
||||
*
|
||||
* @author UJA
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
public class UiService {
|
||||
|
||||
/** Label to request an "error" font. */
|
||||
public static String FONT_TEXT_ERROR = "font_error";
|
||||
|
||||
/** The font text success. */
|
||||
public static String FONT_TEXT_SUCCESS = "font_success";
|
||||
|
||||
/** Label to request an "section" font. */
|
||||
public static String FONT_SECTION_TITLE = "font_section";
|
||||
|
||||
public static String FONT_BIG_TITLE = "font_big";
|
||||
|
||||
/** Label to request an "text" font. */
|
||||
public static String FONT_TEXT_NORMAL = "font_text";
|
||||
|
||||
/** Label to request an "bold text" font. */
|
||||
public static String FONT_TEXT_BOLD = "font_text_bold";
|
||||
|
||||
/** Label to request an "bold text" font. */
|
||||
public static String FONT_CODE = "font_code";
|
||||
|
||||
/** Label to request an "warning" font. */
|
||||
public static String FONT_WARNING = "font_warning";
|
||||
|
||||
public static String FONT_BUTTON = "font_button";
|
||||
|
||||
/** The code background. */
|
||||
public static String CODE_BACKGROUND = "code_background";
|
||||
|
||||
/** The code foreground. */
|
||||
public static String CODE_FOREGROUND = "code_foreground";
|
||||
|
||||
/** The code value. */
|
||||
public static String CODE_VALUE = "code_variable";
|
||||
|
||||
/** The code operator. */
|
||||
public static String CODE_OPERATOR = "code_operator";
|
||||
|
||||
/** The code key. */
|
||||
public static String CODE_KEY = "code_object";
|
||||
|
||||
/** The code string. */
|
||||
public static String CODE_STRING = "code_string";
|
||||
|
||||
/** The code method. */
|
||||
public static String CODE_METHOD = "code_method";
|
||||
|
||||
/** The code condition. */
|
||||
public static String CODE_CONDITION = "code_condition";
|
||||
|
||||
/** The code comment. */
|
||||
public static String CODE_COMMENT = "code_comment";
|
||||
|
||||
/** The code wrong status. */
|
||||
public static String CODE_WRONG = "code_wrong";
|
||||
|
||||
/** The code right status. */
|
||||
public static String CODE_RIGHT = "code_right";
|
||||
|
||||
/** The background color for wrong input elements. */
|
||||
public static Color COLOR_BG_WRONG = new Color(Display.getDefault(), 255, 150, 150);
|
||||
|
||||
/** The color background success color. */
|
||||
public static Color COLOR_BG_SUCCESS = new Color(Display.getDefault(), 150, 255, 150);
|
||||
|
||||
/** The default background color for input elements. */
|
||||
public static Color COLOR_BG_NORMAL = new Color(Display.getDefault(), 255, 255, 255);
|
||||
|
||||
/** The background button normal color. */
|
||||
public static Color COLOR_BG_BUTTON_NORMAL = new Color(Display.getDefault(), 228, 228, 228);
|
||||
|
||||
/** The background button highlight. */
|
||||
public static Color COLOR_BG_BUTTON_HIGHLIGHT = new Color(Display.getDefault(), 225, 245, 243);
|
||||
|
||||
/** The background button highlight 2. */
|
||||
public static Color COLOR_BG_BUTTON_HIGHLIGHT2 = new Color(Display.getDefault(), 240, 230, 220);
|
||||
|
||||
/** The background color for disabled input elements. */
|
||||
public static Color COLOR_BG_DISABLED = new Color(Display.getDefault(), 215, 215, 215);
|
||||
|
||||
/** The color foreground normal color. */
|
||||
public static Color COLOR_FG_NORMAL = new Color(Display.getDefault(), 0, 0, 0);
|
||||
|
||||
/** The color foreground secondary color. */
|
||||
public static Color COLOR_FG_SECONDARY = new Color(Display.getDefault(), 149, 125, 71);
|
||||
|
||||
public static Color COLOR_FG_ERROR = new Color(Display.getDefault(), 150, 0, 0);
|
||||
|
||||
public static Color COLOR_FG_SUCCESS = new Color(Display.getDefault(), 0, 150, 0);
|
||||
|
||||
//public static Color COLOR_MAIN = new Color(Display.getDefault(), 0, 144, 255);
|
||||
public static Color COLOR_MAIN = new Color(Display.getDefault(), 61, 113, 178); // CONTROL -> button_background
|
||||
public static Color COLOR_MAIN_FG = new Color(Display.getDefault(), 255, 255, 255); // CONTROL -> button_foreground
|
||||
public static Color COLOR_BORDER_BG = new Color(Display.getDefault(), 173, 173, 173); // Composite
|
||||
public static Color COLOR_MAIN_HOVER = new Color(Display.getDefault(), 124, 182, 255); // HOVER
|
||||
|
||||
public static Color COLOR_SECONDARY = new Color(Display.getDefault(), 135, 113, 179); // CONTROL -> button_background
|
||||
public static Color COLOR_SECONDARY_FG = new Color(Display.getDefault(), 255, 255, 255); // CONTROL -> button_foreground
|
||||
public static Color COLOR_SECONDARY_HOVER = new Color(Display.getDefault(), 95, 53, 181);
|
||||
|
||||
public static Color COLOR_TERTIARY = new Color(Display.getDefault(), 181, 158, 53); // CONTROL -> button_background
|
||||
public static Color COLOR_TERTIARY_FG = new Color(Display.getDefault(), 255, 255, 255); // CONTROL -> button_foreground
|
||||
public static Color COLOR_TERTIARY_HOVER = new Color(Display.getDefault(), 181, 158, 77);
|
||||
|
||||
|
||||
|
||||
/** Add button. */
|
||||
public static String IMAGE_CONTROLS_ADD = "add.png";
|
||||
|
||||
/** Edit button. */
|
||||
public static String IMAGE_CONTROLS_EDIT = "quick_edit.gif";
|
||||
|
||||
/** Remove button. */
|
||||
public static String IMAGE_CONTROLS_REMOVE = "remove.gif";
|
||||
|
||||
/** Run button. */
|
||||
public static String IMAGE_CONTROLS_RUN = "execute.png";
|
||||
|
||||
/** Deselect button. */
|
||||
public static String IMAGE_CONTROLS_DESELECT = "deselect.png";
|
||||
|
||||
/**
|
||||
* Apply predefined styles to labels and other text elements based on the type
|
||||
* of the element. "section", "error".
|
||||
*
|
||||
* @param item A Label or text item
|
||||
* @param type The chosen style for the item.
|
||||
*/
|
||||
public static void setFont(Control item, String type) {
|
||||
if (type.equals(UiService.FONT_SECTION_TITLE))
|
||||
item.setFont(SWTResourceManager.getFont("Cantarell", 11, SWT.BOLD));
|
||||
else if (type.equals(UiService.FONT_TEXT_ERROR))
|
||||
item.setFont(SWTResourceManager.getFont("Helvetica", 8, SWT.ITALIC));
|
||||
else if (type.equals(UiService.FONT_TEXT_SUCCESS))
|
||||
item.setFont(SWTResourceManager.getFont("Helvetica", 8, SWT.ITALIC));
|
||||
else if (type.equals(UiService.FONT_TEXT_NORMAL))
|
||||
item.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.NORMAL));
|
||||
else if (type.equals(UiService.FONT_TEXT_BOLD))
|
||||
item.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.BOLD));
|
||||
else if (type.equals(UiService.FONT_CODE))
|
||||
item.setFont(SWTResourceManager.getFont("Consolas", 10, SWT.NORMAL));
|
||||
else if (type.equals(UiService.FONT_WARNING))
|
||||
item.setFont(SWTResourceManager.getFont("Occidental", 10, SWT.BOLD));
|
||||
else if (type.equals(UiService.FONT_BIG_TITLE))
|
||||
item.setFont(SWTResourceManager.getFont("Times New Roman", 17, SWT.BOLD));
|
||||
else if (type.equals(UiService.FONT_BUTTON))
|
||||
item.setFont(SWTResourceManager.getFont("Helvetica", 10, SWT.BOLD));
|
||||
else
|
||||
throw new Error("El estilo seleccionado no ex�ste. No se aplicar� estilo: " + type);
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/1449968/change-just-the-font-size-in-swt
|
||||
public static void setFontSize(Control item, int size) {
|
||||
FontData[] fD = item.getFont().getFontData();
|
||||
fD[0].setHeight(size);
|
||||
item.setFont(new Font(Display.getCurrent(), fD[0]));
|
||||
}
|
||||
|
||||
public static void setFontColor(Control item, Color c) {
|
||||
item.setForeground(c);
|
||||
}
|
||||
|
||||
public static void setFontFamily(Control item, String font) {
|
||||
|
||||
FontData[] fD = item.getFont().getFontData();
|
||||
fD[0].setName(font);
|
||||
item.setFont(new Font(Display.getCurrent(), fD[0]));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply GridData to an items. It work like a GridData wrapper that place an
|
||||
* element into a GridLayout using gravity-like params.
|
||||
*
|
||||
* @param item The item to position
|
||||
* @param horAlign Horizontal alignment. -1 LEFT. 0 CENTER. 1 RIGHT. 9 FILL.
|
||||
* @param verAlign Vertical alignment. -1 BOTTM. 0 CENTER. 1 UP. 9 FILL.
|
||||
* @param horGrab Grab extra horizontal spacing.
|
||||
* @param verGrab Grab extra vertical spacing.
|
||||
* @return The styled gridData.
|
||||
*/
|
||||
public static GridData setGridData(Control item, int horAlign, int verAlign, boolean horGrab, boolean verGrab) {
|
||||
|
||||
int horizontal = SWT.CENTER;
|
||||
if (horAlign == -1)
|
||||
horizontal = SWT.LEFT;
|
||||
if (horAlign == 1)
|
||||
horizontal = SWT.RIGHT;
|
||||
if (horAlign == 9)
|
||||
horizontal = SWT.FILL;
|
||||
|
||||
int vertical = SWT.CENTER;
|
||||
if (verAlign == -1)
|
||||
vertical = SWT.BOTTOM;
|
||||
if (verAlign == 1)
|
||||
vertical = SWT.TOP;
|
||||
if (verAlign == 9)
|
||||
vertical = SWT.FILL;
|
||||
|
||||
GridData data = new GridData(horizontal, vertical, horGrab, verGrab);
|
||||
|
||||
item.setLayoutData(data);
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new GridLayout with the given columns.
|
||||
*
|
||||
* @param base The base layout
|
||||
* @param colNumber Number of columns 1+.
|
||||
* @return The new layout
|
||||
*/
|
||||
public static GridLayout setGridLayout(Composite base, int colNumber) {
|
||||
return setGridLayout(base, colNumber, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new GridLayout with the given columns.
|
||||
*
|
||||
* @param base The base layout
|
||||
* @param colNumber Number of columns 1+.
|
||||
* @param sameWidth the same width
|
||||
* @return The new layout
|
||||
*/
|
||||
public static GridLayout setGridLayout(Composite base, int colNumber, boolean sameWidth) {
|
||||
GridLayout gridLayout = new GridLayout(colNumber, sameWidth);
|
||||
gridLayout.verticalSpacing = 0;
|
||||
base.setLayout(gridLayout);
|
||||
return gridLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the background color.
|
||||
*
|
||||
* @param c the c
|
||||
* @param r the red value
|
||||
* @param g the green value
|
||||
* @param b the blue value
|
||||
*/
|
||||
public static void setBackgroundColor(Control c, Color color) {
|
||||
c.setBackground(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the background color.
|
||||
*
|
||||
* @param c the composite
|
||||
* @param all every color value
|
||||
*/
|
||||
public static void setBackgroundColor(Control c, int all) {
|
||||
setBackgroundColor(c, getColor(all, all, all));
|
||||
}
|
||||
|
||||
public static void setBackgroundColor(Control c, int r, int g, int b) {
|
||||
setBackgroundColor(c, getColor(r, g, b));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color.
|
||||
*
|
||||
* @param all the all
|
||||
* @return the color
|
||||
*/
|
||||
public static Color getColor(int all) {
|
||||
return getColor(all, all, all);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the swt color object.
|
||||
*
|
||||
* @param r the red value
|
||||
* @param g the green value
|
||||
* @param b the blue value
|
||||
* @return the color
|
||||
*/
|
||||
public static Color getColor(int r, int g, int b) {
|
||||
return new Color(Display.getCurrent(), r, g, b);
|
||||
}
|
||||
|
||||
public static Color[] getColorScale(int cuts, boolean reverse) {
|
||||
|
||||
int max = 255;
|
||||
int desp = 255 / cuts;
|
||||
|
||||
Color[] colors = new Color[cuts];
|
||||
|
||||
for (int i = 0; i < cuts; i++) {
|
||||
int despI = desp * i;
|
||||
|
||||
if (reverse)
|
||||
colors[i] = getColor(despI, max - despI, 0);
|
||||
else
|
||||
colors[i] = getColor(max - despI, despI, 0);
|
||||
}
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
public static String toHEX(Color c) {
|
||||
RGB rgb = c.getRGB();
|
||||
return String.format("#%02x%02x%02x", rgb.red, rgb.green, rgb.blue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the swt code color for code/pseudocode.
|
||||
*
|
||||
* @param type the type
|
||||
* @param dark the dark
|
||||
* @return the code color
|
||||
*/
|
||||
public static Color getCodeForeground(String type, boolean dark) {
|
||||
|
||||
if (dark) {
|
||||
|
||||
if (type.equals(UiService.CODE_BACKGROUND))
|
||||
return getColor(28, 31, 34);
|
||||
if (type.equals(UiService.CODE_VALUE))
|
||||
return getColor(237, 127, 66);
|
||||
if (type.equals(UiService.CODE_KEY))
|
||||
return getColor(102, 225, 248);
|
||||
if (type.equals(UiService.CODE_STRING))
|
||||
return getColor(23, 173, 103);
|
||||
if (type.equals(UiService.CODE_METHOD))
|
||||
return getColor(125, 236, 33);
|
||||
if (type.equals(UiService.CODE_CONDITION))
|
||||
return getColor(204, 120, 50);
|
||||
if (type.equals(UiService.CODE_WRONG))
|
||||
return getColor(255, 0, 0);
|
||||
if (type.equals(UiService.CODE_RIGHT))
|
||||
return getColor(0, 255, 0);
|
||||
return getColor(255, 255, 255);
|
||||
|
||||
}
|
||||
|
||||
if (type.equals(UiService.CODE_BACKGROUND))
|
||||
return getColor(28, 31, 34);
|
||||
if (type.equals(UiService.CODE_VALUE))
|
||||
return getColor(237, 127, 66);
|
||||
if (type.equals(UiService.CODE_KEY))
|
||||
return getColor(102, 225, 248);
|
||||
if (type.equals(UiService.CODE_STRING))
|
||||
return getColor(23, 173, 103);
|
||||
if (type.equals(UiService.CODE_METHOD))
|
||||
return getColor(125, 236, 33);
|
||||
if (type.equals(UiService.CODE_CONDITION))
|
||||
return getColor(204, 120, 50);
|
||||
if (type.equals(UiService.CODE_WRONG))
|
||||
return getColor(255, 0, 0);
|
||||
if (type.equals(UiService.CODE_RIGHT))
|
||||
return getColor(0, 255, 0);
|
||||
return getColor(255, 255, 255);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the swt style for code/pseudocode.
|
||||
*
|
||||
* @param type the type
|
||||
* @param dark the dark theme is enabled?
|
||||
* @return the code style
|
||||
*/
|
||||
public static int getCodeStyle(String type, boolean dark) {
|
||||
if (type.equals(UiService.CODE_COMMENT))
|
||||
return SWT.BOLD;
|
||||
if (type.equals(UiService.CODE_WRONG))
|
||||
return SWT.BOLD;
|
||||
if (type.equals(UiService.CODE_RIGHT))
|
||||
return SWT.BOLD;
|
||||
return SWT.NONE;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the margin.
|
||||
*
|
||||
* @param base the base
|
||||
* @param all all the sides margin
|
||||
* @return the grid layout
|
||||
*/
|
||||
public static GridLayout setMargin(Composite base, int all) {
|
||||
return setMargin(base, all, all, all, all);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the margin.
|
||||
*
|
||||
* @param base the base
|
||||
* @param vertical up/down side margin
|
||||
* @param horizontal right/left side margin
|
||||
* @return the grid layout
|
||||
*/
|
||||
public static GridLayout setMargin(Composite base, int vertical, int horizontal) {
|
||||
return setMargin(base, vertical, horizontal, vertical, horizontal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the margin.
|
||||
*
|
||||
* @param base the base
|
||||
* @param up the up margin
|
||||
* @param right the right margin
|
||||
* @param down the down margin
|
||||
* @param left the left margin
|
||||
* @return the grid layout
|
||||
*/
|
||||
public static GridLayout setMargin(Composite base, int up, int right, int down, int left) {
|
||||
GridLayout current = (GridLayout) base.getLayout();
|
||||
current.marginTop = up;
|
||||
current.marginRight = right;
|
||||
current.marginLeft = left;
|
||||
current.marginBottom = down;
|
||||
current.verticalSpacing = (up + down)/2;
|
||||
base.setLayout(current);
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug UI with colors using grayscale backgrounds.
|
||||
*
|
||||
* @param args the args
|
||||
*/
|
||||
public static void debugWithColors(Control... args) {
|
||||
int total = args.length;
|
||||
int step = 256 / total;
|
||||
|
||||
for (int i = 0; i < total; i++) {
|
||||
Control c = args[i];
|
||||
setBackgroundColor(c, i * step);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re layout shell to adjust it to the content size.
|
||||
*
|
||||
* @param shell the shell
|
||||
*/
|
||||
public static void reLayoutShell(Shell shell) {
|
||||
shell.layout(true, true);
|
||||
final Point newSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
|
||||
shell.setSize(newSize);
|
||||
|
||||
centerShell(shell, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Center shell into the window/monitor.
|
||||
*
|
||||
* @param shell the shell
|
||||
* @param inMonitor the in monitor
|
||||
*/
|
||||
public static void centerShell(Shell shell, boolean inMonitor) {
|
||||
|
||||
int x;
|
||||
int y;
|
||||
if (inMonitor) {
|
||||
Monitor m = shell.getMonitor();
|
||||
Rectangle bounds = m.getBounds();
|
||||
Rectangle rect = shell.getBounds();
|
||||
|
||||
x = bounds.x + (bounds.width - rect.width) / 2;
|
||||
y = bounds.y + (bounds.height - rect.height) / 2;
|
||||
} else {
|
||||
Rectangle parentSize = shell.getParent().getBounds();
|
||||
Rectangle shellSize = shell.getBounds();
|
||||
x = (parentSize.width - shellSize.width) / 2 + parentSize.x;
|
||||
y = (parentSize.height - shellSize.height) / 2 + parentSize.y;
|
||||
}
|
||||
|
||||
shell.setLocation(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the background color.
|
||||
*
|
||||
* @param c the c
|
||||
* @param color the color
|
||||
*/
|
||||
private static ImageDescriptor getImageDescriptor(String folder, String fileName) {
|
||||
Bundle bundle = FrameworkUtil.getBundle(UiService.class);
|
||||
|
||||
URL url = FileLocator.find(bundle, new Path("icons/" + fileName), null);
|
||||
ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url);
|
||||
|
||||
return imageDescriptor;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the icon
|
||||
*/
|
||||
public static ImageDescriptor getIcon(String name, Composite parent) {
|
||||
return getImageDescriptor("icons", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the image
|
||||
*/
|
||||
public static ImageDescriptor getImage(String name, Composite parent) {
|
||||
return getImageDescriptor("images", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon and will dispose it when the parent composite is disposed.
|
||||
*
|
||||
* @param name the name
|
||||
* @param parent the parent
|
||||
* @return the icon
|
||||
*/
|
||||
public static ImageDescriptor getIcon(String name) {
|
||||
if (!name.contains("."))
|
||||
name += ".png";
|
||||
return getIcon(name, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image and will dispose it when the parent composite is disposed.
|
||||
*
|
||||
* @param name the name
|
||||
* @param parent the parent
|
||||
* @return the image
|
||||
*/
|
||||
public static ImageDescriptor getImage(String name) {
|
||||
return getImage(name, null);
|
||||
}
|
||||
|
||||
public static StyledString paintText(String primaryText, String secondaryText, Color secondaryColor) {
|
||||
return paintText(primaryText, secondaryText, UiService.COLOR_FG_NORMAL, secondaryColor);
|
||||
}
|
||||
|
||||
public static StyledString paintText(String primaryText, String secondaryText, Color primaryColor,
|
||||
Color secondaryColor) {
|
||||
|
||||
Color foregroundColorLeft = primaryColor;
|
||||
Color foregroundColorRight = secondaryColor;
|
||||
|
||||
StyledString leftT = new StyledString(primaryText, new ForegroundStyler(foregroundColorLeft));
|
||||
StyledString rightT = new StyledString(secondaryText, new ForegroundStyler(foregroundColorRight));
|
||||
|
||||
return leftT.append(" ").append(rightT);
|
||||
}
|
||||
|
||||
public static StyledString paintTextWithBrackets(String primaryText, String secondaryText) {
|
||||
return paintTextWithBrackets(primaryText, secondaryText, UiService.COLOR_FG_NORMAL, UiService.COLOR_FG_SECONDARY);
|
||||
}
|
||||
|
||||
public static StyledString paintTextWithBrackets(String primaryText, String secondaryText, Color secondaryColor) {
|
||||
return paintTextWithBrackets(primaryText, secondaryText, UiService.COLOR_FG_NORMAL, secondaryColor);
|
||||
}
|
||||
|
||||
public static StyledString paintTextWithBrackets(String primaryText, String secondaryText, Color primaryColor,
|
||||
Color secondaryColor) {
|
||||
|
||||
Color foregroundColorLeft = primaryColor;
|
||||
Color foregroundColorRight = secondaryColor;
|
||||
|
||||
StyledString leftT = new StyledString(primaryText, new ForegroundStyler(foregroundColorLeft));
|
||||
StyledString rightT = new StyledString("["+secondaryText+"]", new ForegroundStyler(foregroundColorRight));
|
||||
|
||||
return leftT.append(" ").append(rightT);
|
||||
}
|
||||
|
||||
public static GridData setGridDataAuto(Control control) {
|
||||
if (control instanceof Label)
|
||||
return setGridData(control, -1, 1, true, false);
|
||||
if (control instanceof Text)
|
||||
return setGridData(control, 9, 0, true, false);
|
||||
else if (control instanceof Composite)
|
||||
return setGridData(control, 9, 9, true, true);
|
||||
|
||||
throw new RuntimeException("Control no soportado " + control.getClass());
|
||||
|
||||
}
|
||||
|
||||
public static void DumpComposites(Composite base, int level) {
|
||||
|
||||
String t = "\t";
|
||||
String tabs = "";
|
||||
for (int i = 0; i < level; i++)
|
||||
tabs += t;
|
||||
|
||||
DH.out(tabs + base.getLayout() + " s " + base.getSize() );
|
||||
// DH.out(tabs + base.getLayoutData());
|
||||
if (base.getLayout() instanceof GridLayout) {
|
||||
// GridLayout l = (GridLayout) base.getLayout();
|
||||
GridData d = (GridData) base.getLayoutData();
|
||||
DH.out(tabs + d);
|
||||
|
||||
}
|
||||
|
||||
Control[] controls = base.getChildren();
|
||||
for (Control c : controls)
|
||||
if (c instanceof Composite)
|
||||
DumpComposites((Composite) c, level + 1);
|
||||
else
|
||||
DH.out(tabs + t + c.toString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package flintstones.model.ui.service.style;
|
||||
|
||||
import org.eclipse.jface.viewers.StyledString.Styler;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.TextStyle;
|
||||
|
||||
public class ForegroundStyler extends Styler {
|
||||
|
||||
Color chosenColor;
|
||||
|
||||
public ForegroundStyler(Color color) {
|
||||
chosenColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyStyles(TextStyle textStyle) {
|
||||
textStyle.foreground = chosenColor;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user