Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2023 Google, Inc.
* Copyright (c) 2011, 2025 Google, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -13,17 +13,12 @@
package org.eclipse.wb.internal.draw2d;

import org.eclipse.wb.draw2d.FigureUtils;
import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.draw2d.geometry.Rectangle;

/**
* A Label which draws its text vertically.
Expand All @@ -34,8 +29,13 @@ public final class VerticalLabel extends Label {
private Dimension m_preferredSize;

@Override
protected void paintClientArea(Graphics graphics) {
drawVerticalText(getText(), 0, 0, graphics, false);
protected void paintFigure(Graphics graphics) {
graphics.fillRectangle(getBounds());
Rectangle r = getClientArea();
graphics.translate(r.getLocation());
graphics.translate(r.width, 0);
graphics.rotate(90);
graphics.drawText(getText(), 0, 0);
}

/**
Expand All @@ -57,73 +57,4 @@ public void invalidate() {
m_preferredSize = null;
super.invalidate();
}

/**
* Draws text vertically (rotates plus or minus 90 degrees). Uses the current font, color, and
* background.
*
* @param string
* the text to draw
* @param x
* the x coordinate of the top left corner of the drawing rectangle
* @param y
* the y coordinate of the top left corner of the drawing rectangle
* @param graphics
* the GC on which to draw the text
*/
private static void drawVerticalText(String string, int x, int y, Graphics graphics, boolean isUp) {
// Get the current display
Display display = Display.getCurrent();
if (display == null) {
SWT.error(SWT.ERROR_THREAD_INVALID_ACCESS);
}
// Determine string's dimensions
Point pt = ((GC) ReflectionUtils.getFieldObject(graphics, "gc")).textExtent(string);
// Create an image the same size as the string
Image stringImage = new Image(display, pt.x, pt.y);
// Create a GC so we can draw the image
GC stringGc = new GC(stringImage);
// Set attributes from the original GC to the new GC
stringGc.setForeground(graphics.getForegroundColor());
stringGc.setBackground(graphics.getBackgroundColor());
stringGc.setFont(graphics.getFont());
// Draw the text onto the image
stringGc.drawText(string, 0, 0);
// Draw the image vertically onto the original GC
Image rotatedImage = rotateImage(stringImage, isUp);
// Draw the vertical image onto the original GC
graphics.drawImage(rotatedImage, x, y);
// Dispose
rotatedImage.dispose();
stringGc.dispose();
stringImage.dispose();
}

/**
* Rotates an image vertically (rotates plus or minus 90 degrees)
*/
private static Image rotateImage(Image image, boolean up) {
// Get the current display
Display display = Display.getCurrent();
if (display == null) {
SWT.error(SWT.ERROR_THREAD_INVALID_ACCESS);
}
// Use the image's data to create a rotated image's data
ImageData sd = image.getImageData();
ImageData dd = new ImageData(sd.height, sd.width, sd.depth, sd.palette);
// Determine which way to rotate, depending on up or down
// Run through the horizontal pixels
for (int sx = 0; sx < sd.width; sx++) {
// Run through the vertical pixels
for (int sy = 0; sy < sd.height; sy++) {
// Determine where to move pixel to in destination image data
int dx = up ? sy : sd.height - sy - 1;
int dy = up ? sd.width - sx - 1 : sx;
// Swap the x, y source data to y, x in the destination
dd.setPixel(dx, dy, sd.getPixel(sx, sy));
}
}
// Create the vertical image
return new Image(display, dd);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2024 Google, Inc.
* Copyright (c) 2011, 2025 Google, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -13,14 +13,14 @@
package org.eclipse.wb.core.gef.figure;

import org.eclipse.wb.draw2d.Layer;
import org.eclipse.wb.draw2d.border.Border;
import org.eclipse.wb.draw2d.border.CompoundBorder;
import org.eclipse.wb.draw2d.border.LineBorder;
import org.eclipse.wb.draw2d.border.MarginBorder;
import org.eclipse.wb.internal.draw2d.Label;
import org.eclipse.wb.internal.draw2d.VerticalLabel;

import org.eclipse.draw2d.Border;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.CompoundBorder;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
Expand Down
Loading