List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:org.kalypso.chart.ext.test.layer.TortenLayer.java
/** * @see org.kalypso.chart.framework.model.layer.IChartLayer#paint(org.eclipse.swt.graphics.GC) *//*from ww w. ja va 2 s. c o m*/ @Override public void paint(final GC gc) { final IAxis da = getDomainAxis(); final IAxis ta = getTargetAxis(); final int startX = da.numericToScreen(-100); final int startY = ta.numericToScreen(-100); final int endX = da.numericToScreen(100); final int endY = ta.numericToScreen(100); final int centerX = da.numericToScreen(0); final int centerY = ta.numericToScreen(0); final int width = Math.abs(endX - startX); final int height = Math.abs(endY - startY); final Device dev = gc.getDevice(); gc.setForeground(dev.getSystemColor(SWT.COLOR_BLACK)); gc.setBackground(dev.getSystemColor(SWT.COLOR_BLACK)); gc.fillOval(startX, startY, width, height); gc.drawLine(centerX, startY, centerX, endY); gc.drawLine(startX, centerY, endX, centerY); for (int i = 0; i < m_pieces; i++) { final int angleStart = i * (int) (360.0f / m_pieces); final int angle = (int) (360.0f / m_pieces); final java.awt.Color color = new java.awt.Color( java.awt.Color.HSBtoRGB(1.0f / m_pieces * i, 1.0f, 1.0f)); final RGB fillRGB = new RGB(color.getRed(), color.getGreen(), color.getBlue()); final Color fillColor = OdysseusChartFramework.getDefault().getColorRegistry().getResource(dev, fillRGB); gc.setBackground(fillColor); gc.setForeground(dev.getSystemColor(SWT.COLOR_BLACK)); gc.setLineWidth(5); gc.fillArc(startX, startY, width, height, angleStart, angle); gc.drawArc(startX, startY, width, height, angleStart, angle); } gc.setForeground(dev.getSystemColor(SWT.COLOR_BLACK)); gc.setLineWidth(5); for (int i = 0; i < m_pieces; i++) { final int angleStart = (int) (i * (360.0f / m_pieces)); final double angleRad = Math.toRadians(angleStart); final double h = 100.0f; final double g = Math.sin(angleRad) * h; final double a = Math.cos(angleRad) * h; final double gStrich = ta.numericToScreen(g) - centerY; final double aStrich = da.numericToScreen(a) - centerX; gc.drawLine(centerX, centerY, (int) (centerX + aStrich), (int) (centerY + gStrich)); } gc.setLineWidth(10); gc.setLineDash(new int[] { 10, 10 }); gc.setForeground(dev.getSystemColor(SWT.COLOR_WHITE)); for (int i = 0; i < m_pieces; i++) { final int angleStart = (int) (i * (360.0f / m_pieces)); final double angleRad = Math.toRadians(angleStart); final double h = 100.0f; final double g = (int) (Math.sin(angleRad) * h); final double a = (int) (Math.cos(angleRad) * h); final double gStrich = ta.numericToScreen(g) - centerY; final double aStrich = da.numericToScreen(a) - centerX; final double hStrich = Math.sqrt(Math.pow(aStrich, 2) + Math.pow(gStrich, 2)); final Transform t = new Transform(dev); t.translate(centerX, centerY); t.rotate(angleStart); gc.setTransform(t); gc.drawLine(20, 0, (int) hStrich, 0); t.dispose(); } gc.setTransform(null); }
From source file:com.alvermont.terraj.planet.project.PetersProjection.java
/** * Carry out the projection// w w w . jav a 2 s . c om */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; depth = (3 * ((int) (log2(scale * height)))) + 6; double y; double cos2; double theta1; double scale1; int k; int i; int j; int water; int land; y = 2.0 * Math.sin(lat); k = (int) ((0.5 * y * width * scale) / Math.PI); water = 0; land = 0; progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { progress.progressStep(j); y = (0.5 * Math.PI * ((2.0 * (j - k)) - height)) / width / scale; if (Math.abs(y) > 1.0) { for (i = 0; i < width; ++i) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } } else { cos2 = Math.sqrt(1.0 - (y * y)); if (cos2 > 0.0) { scale1 = (scale * width) / height / cos2 / Math.PI; depth = (3 * ((int) (log2(scale1 * height)))) + 3; for (i = 0; i < width; ++i) { theta1 = lon - (0.5 * Math.PI) + ((Math.PI * ((2.0 * i) - width)) / width / scale); colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2); if (doShade) { shades[i][j] = shade; } if (colours[i][j] < colourLand0) { ++water; } else { ++land; } } } } } progress.progressComplete("Terrain Generated"); log.debug("Water percentage: " + ((100 * water) / (water + land))); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = 2.0 * Math.sin(Math.toRadians(theta1)); j = (height / 2) + (int) ((0.5 * y * width * scale) / Math.PI) + k; if ((j >= 0) && (j < height)) { for (i = 0; i < width; ++i) colours[i][j] = BLACK; } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta1 = 0.0; theta1 > -360.0; theta1 -= vgrid) ; for (theta1 = theta1; theta1 < 360.0; theta1 += vgrid) { i = (int) (0.5 * width * (1.0 + ((scale * (Math.toRadians(theta1) - lon)) / Math.PI))); if ((i >= 0) && (i < width)) { for (j = Math.max(0, (height / 2) - (int) ((width * scale) / Math.PI) + k); j < Math.min(height, (height / 2) + (int) ((width * scale) / Math.PI) + k); ++j) colours[i][j] = BLACK; } } } if (doShade) { smoothshades(); } doOutlining(); }
From source file:com.alvermont.terraj.planet.project.OrthographicProjection.java
/** * Carry out the projection//from ww w . j a v a 2s . com */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); colours = new short[width][height]; shades = new short[width][height]; double x; double y; double z; double x1; double y1; double z1; double ymin; double ymax; double theta1; double theta2; double zz; int i; int j; depth = (3 * ((int) (log2(scale * height)))) + 6; final double sla = Math.sin(lat); final double cla = Math.cos(lat); final double slo = Math.sin(lon); final double clo = Math.cos(lon); cacheParameters(); ymin = 2.0; ymax = -2.0; progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { progress.progressStep(j); for (i = 0; i < width; ++i) { x = ((2.0 * i) - width) / height / scale; y = ((2.0 * j) - height) / height / scale; if (((x * x) + (y * y)) > 1.0) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } else { z = Math.sqrt(1.0 - (x * x) - (y * y)); x1 = (clo * x) + (slo * sla * y) + (slo * cla * z); y1 = (cla * y) - (sla * z); z1 = (-slo * x) + (clo * sla * y) + (clo * cla * z); if (y1 < ymin) { ymin = y1; } if (y1 > ymax) { ymax = y1; } colours[i][j] = (short) planet0(x1, y1, z1); if (doShade) { shades[i][j] = shade; } } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.sin(Math.toRadians(theta1)); if ((ymin <= y) && (y <= ymax)) { zz = Math.sqrt(1 - (y * y)); for (theta2 = -Math.PI; theta2 < Math.PI; theta2 += (0.5 / width / scale)) { x = Math.sin(theta2) * zz; z = Math.cos(theta2) * zz; x1 = (clo * x) + (slo * z); y1 = ((slo * sla * x) + (cla * y)) - (clo * sla * z); z1 = (-slo * cla * x) + (sla * y) + (clo * cla * z); if (0.0 >= z1) { i = (int) (0.5 * ((height * scale * x1) + width)); j = (int) (0.5 * ((height * scale * y1) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta2 = -Math.PI; theta2 < Math.PI; theta2 += (0.5 / width / scale)) { y = Math.sin(theta2); if ((ymin <= y) && (y <= ymax)) { for (theta1 = 0.0; theta1 < 360.0; theta1 += vgrid) { x = Math.sin(Math.toRadians(theta1)) * Math.cos(theta2); z = Math.cos(Math.toRadians(theta1)) * Math.cos(theta2); x1 = (clo * x) + (slo * z); y1 = ((slo * sla * x) + (cla * y)) - (clo * sla * z); z1 = (-slo * cla * x) + (sla * y) + (clo * cla * z); if (0.0 >= z1) { i = (int) (0.5 * ((height * scale * x1) + width)); j = (int) (0.5 * ((height * scale * y1) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } } if (doShade) { smoothshades(); } doOutlining(); }
From source file:org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.java
/** * This is the public method for setting the appearance stream. * * @param apValue the String value which the appearance should represent * @throws IOException If there is an error creating the stream. *//*w w w . j ava2s .c o m*/ public void setAppearanceValue(String apValue) throws IOException { value = apValue; for (PDAnnotationWidget widget : field.getWidgets()) { PDRectangle rect = widget.getRectangle(); if (rect == null) { widget.getCOSObject().removeItem(COSName.AP); LOG.warn("widget of field " + field.getFullyQualifiedName() + " has no rectangle, no appearance stream created"); continue; } PDFormFieldAdditionalActions actions = field.getActions(); // in case all tests fail the field will be formatted by acrobat // when it is opened. See FreedomExpressions.pdf for an example of this. if (actions == null || actions.getF() == null || widget.getCOSObject().getDictionaryObject(COSName.AP) != null) { PDAppearanceDictionary appearanceDict = widget.getAppearance(); if (appearanceDict == null) { appearanceDict = new PDAppearanceDictionary(); widget.setAppearance(appearanceDict); } PDAppearanceEntry appearance = appearanceDict.getNormalAppearance(); // TODO support appearances other than "normal" PDAppearanceStream appearanceStream; if (appearance.isStream()) { appearanceStream = appearance.getAppearanceStream(); } else { appearanceStream = new PDAppearanceStream(field.getAcroForm().getDocument()); // Calculate the entries for the bounding box and the transformation matrix // settings for the appearance stream int rotation = resolveRotation(widget); Matrix matrix = Matrix.getRotateInstance(Math.toRadians(rotation), 0, 0); Point2D.Float point2D = matrix.transformPoint(rect.getWidth(), rect.getHeight()); PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), Math.abs((float) point2D.getY())); appearanceStream.setBBox(bbox); appearanceStream.setMatrix(calculateMatrix(bbox, rotation)); appearanceStream.setFormType(1); appearanceStream.setResources(new PDResources()); appearanceDict.setNormalAppearance(appearanceStream); // TODO support appearances other than "normal" } /* * Adobe Acrobat always recreates the complete appearance stream if there is an appearance characteristics * entry (the widget dictionaries MK entry). In addition if there is no content yet also create the appearance * stream from the entries. * */ if (widget.getAppearanceCharacteristics() != null || appearanceStream.getContentStream().getLength() == 0) { initializeAppearanceContent(widget, appearanceStream); } setAppearanceContent(widget, appearanceStream); } } }
From source file:fr.amap.lidar.amapvox.commons.GTheta.java
/** * <p>Get the transmittance from the specified angle (radians or degrees) and the specified Leaf Angle Distribution.</p> * 0 is vertical, 90 is horizontal (zenithal angle, measured from vertical). * @param theta Angle//from www . ja va 2 s . c o m * @param degrees true if the given angle is in degrees, false otherwise * @return directional transmittance (GTheta) */ public double getGThetaFromAngle(double theta, boolean degrees) { if (degrees) { if (theta > 90) { //get an angle between 0 and 90 theta = 180 - theta; } } else { if (theta > (Math.PI / 2.0)) { //get an angle between 0 and pi/2 theta = Math.PI - theta; } } if (transmittanceFunctions != null && !isBuildingTable) { //a table was built int indice = 0; if (degrees) { indice = (int) (theta / res); } else { indice = (int) (Math.toDegrees(theta) / res); } if (indice >= transmittanceFunctions.length) { indice = transmittanceFunctions.length - 1; } else if (indice < 0) { indice = 0; } return transmittanceFunctions[indice]; } else { //no table was built, get transmittance on the fly if (pdfArray == null) { setupDensityProbabilityArray(DEFAULT_STEP_NUMBER); } if (distribution.getType() == SPHERIC) { return 0.5; //the result for spherical distribution is always 0.5, saving processing time } else { if (degrees) { theta = Math.toRadians(theta); } if (theta == 0) { theta = Double.MIN_VALUE; } if (theta >= Math.PI / 2.0) { theta = (Math.PI / 2.0) - 0.00001; } UnivariateFunction function1 = new CustomFunction1(theta); UnivariateFunction function2 = new CustomFunction2(theta); TrapezoidIntegrator integrator = new TrapezoidIntegrator(); double sum = 0; for (int j = 0; j < nbIntervals; j++) { double thetaL = (serie_angulaire[j] + serie_angulaire[j + 1]) / 2.0d; double Fi = (pdfArray[j]) / SOM; double cotcot = Math.abs(1 / (Math.tan(theta) * Math.tan(thetaL))); double Hi; if (cotcot > 1 || Double.isInfinite(cotcot)) { Hi = integrator.integrate(10000, function1, serie_angulaire[j], serie_angulaire[j + 1]); } else { Hi = integrator.integrate(10000, function2, serie_angulaire[j], serie_angulaire[j + 1]); //System.out.println("nb evaluations: " + integrator.getEvaluations()); } double Gi = Fi * Hi / ((Math.PI / 2) / (double) serie_angulaire.length); //because we need the average value not the actual integral value!!!! sum += Gi; } return sum; } } }
From source file:org.springframework.cloud.stream.app.pose.estimation.processor.PoseEstimateOutputMessageBuilder.java
private void drawPartOval(Part part, int radius, Graphics2D g) { int partX = part.getNormalizedX(); int partY = part.getNormalizedY(); g.setColor(GraphicsUtils.LIMBS_COLORS[part.getPartType().getId()]); g.fillOval(partX - radius, partY - radius, 2 * radius, 2 * radius); if (this.poseProperties.isDrawPartLabels()) { String label = part.getPartType().getId() + ":" + part.getPartType().name(); FontMetrics fm = g.getFontMetrics(); int labelX = partX + 5; int labelY = partY - 5; AffineTransform t = g.getTransform(); g.setTransform(AffineTransform.getRotateInstance(Math.toRadians(-35), labelX, labelY)); g.drawString(label, labelX, labelY); g.setTransform(t);/*from w w w . j av a2s.c o m*/ } }
From source file:com.liusoft.dlog4j.action.PhotoAction.java
/** * //from w w w. jav a 2s . c o m * @param ctx * @param imgURL * @param orient * @return * @throws IOException */ protected boolean rotate(HttpContext ctx, String imgURL, int orient) throws IOException { PhotoSaver saver = this.getPhotoSaver(); InputStream inImg = saver.read(ctx, imgURL); BufferedImage old_img = (BufferedImage) ImageIO.read(inImg); int width = old_img.getWidth(); int height = old_img.getHeight(); BufferedImage new_img = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = new_img.createGraphics(); AffineTransform origXform = g2d.getTransform(); AffineTransform newXform = (AffineTransform) (origXform.clone()); // center of rotation is center of the panel double radian = 0; double xRot = 0; double yRot = 0; switch (orient) { case 3: radian = 180.0; xRot = width / 2.0; yRot = height / 2.0; case 6: radian = 90.0; xRot = height / 2.0; yRot = xRot; break; case 8: radian = 270.0; xRot = width / 2.0; yRot = xRot; break; default: return false; } newXform.rotate(Math.toRadians(radian), xRot, yRot); g2d.setTransform(newXform); // draw image centered in panel g2d.drawImage(old_img, 0, 0, null); // Reset to Original g2d.setTransform(origXform); OutputStream out = saver.write(ctx, imgURL); try { ImageIO.write(new_img, "JPG", out); } finally { out.close(); } return true; }
From source file:com.alvermont.terraj.planet.project.SinusoidProjection.java
/** * Carry out the projection/*from w w w. j a v a 2 s .c o m*/ */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; double y; double theta1; double theta2; double cos2; double l1; double i1; double scale1; int k; int i; int j; int l; int c; k = (int) ((lat * width * scale) / Math.PI); progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { progress.progressStep(j); y = ((2.0 * (j - k)) - height) / width / scale * Math.PI; if (Math.abs(y) >= (0.5 * Math.PI)) { for (i = 0; i < width; ++i) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } } else { cos2 = Math.cos(y); if (cos2 > 0.0) { scale1 = (scale * width) / height / cos2 / Math.PI; depth = (3 * ((int) (log2(scale1 * height)))) + 3; for (i = 0; i < width; ++i) { l = (i * 12) / width; l1 = (l * width) / 12.0; i1 = i - l1; theta2 = lon - (0.5 * Math.PI) + ((Math.PI * ((2.0 * l1) - width)) / width / scale); theta1 = ((Math.PI * ((2.0 * i1) - (width / 12))) / width / scale) / cos2; if (Math.abs(theta1) > (Math.PI / 12.0)) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } else { colours[i][j] = (short) planet0(Math.cos(theta1 + theta2) * cos2, Math.sin(y), -Math.sin(theta1 + theta2) * cos2); if (doShade) { shades[i][j] = shade; } } } } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.toRadians(theta1); cos2 = Math.cos(y); j = (height / 2) + (int) ((0.5 * y * width * scale) / Math.PI) + k; if ((j >= 0) && (j < height)) { for (i = 0; i < width; ++i) { l = (i * 12) / width; l1 = (l * width) / 12.0; i1 = i - l1; theta2 = ((Math.PI * ((2.0 * i1) - (width / 12))) / width / scale) / cos2; if (Math.abs(theta2) <= (Math.PI / 12.0)) { colours[i][j] = BLACK; } } } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta1 = 0.0; theta1 > -360.0; theta1 -= vgrid) ; for (theta1 = theta1; theta1 < 360.0; theta1 += vgrid) { i = (int) (0.5 * width * (1.0 + ((scale * (Math.toRadians(theta1) - lon)) / Math.PI))); if ((i >= 0) && (i < width)) { for (j = Math.max(0, (height / 2) - (int) ((0.25 * Math.PI * width * scale) / Math.PI) + k); j < Math.min( height, (height / 2) + (int) ((0.25 * Math.PI * width * scale) / Math.PI) + k); ++j) { y = ((2.0 * (j - k)) - height) / width / scale * Math.PI; cos2 = Math.cos(y); l = (i * 12) / width; l1 = ((l * width) / 12.0) + (width / 24.0); i1 = i - l1; c = (int) (l1 + (i1 * cos2)); if ((c >= 0) && (c < width)) { colours[c][j] = BLACK; } } } } } if (doShade) { smoothshades(); } doOutlining(); }
From source file:com.dat255.ht13.grupp23.activites.MapController.java
public double calculateDistance(Point anotherPosition, Point currentPosition) { LatLng latlng1 = new LatLng(anotherPosition.getX(), anotherPosition.getX()); double lat1 = latlng1.latitude; double lng1 = latlng1.longitude; LatLng latlng2 = new LatLng(currentPosition.getX(), currentPosition.getX()); double lat2 = latlng2.latitude; double lng2 = latlng2.longitude; double earthRadius = 3958.75; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c; double meterConversion = 1609; return (dist * meterConversion); }
From source file:SWT2D.java
private void run() { // Create top level shell final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Java 2D Example"); // GridLayout for canvas and button shell.setLayout(new GridLayout()); // Create container for AWT canvas final Composite canvasComp = new Composite(shell, SWT.EMBEDDED); // Set preferred size GridData data = new GridData(); data.widthHint = 600;/* w ww . ja v a 2 s.c om*/ data.heightHint = 500; canvasComp.setLayoutData(data); // Create AWT Frame for Canvas java.awt.Frame canvasFrame = SWT_AWT.new_Frame(canvasComp); // Create Canvas and add it to the Frame final java.awt.Canvas canvas = new java.awt.Canvas(); canvasFrame.add(canvas); // Get graphical context and cast to Java2D final java.awt.Graphics2D g2d = (java.awt.Graphics2D) canvas.getGraphics(); // Enable antialiasing g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Remember initial transform final java.awt.geom.AffineTransform origTransform = g2d.getTransform(); // Create Clear button and position it Button clearButton = new Button(shell, SWT.PUSH); clearButton.setText("Clear"); data = new GridData(); data.horizontalAlignment = GridData.CENTER; clearButton.setLayoutData(data); // Event processing for Clear button clearButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // Delete word list and redraw canvas wordList.clear(); canvasComp.redraw(); } }); // Process canvas mouse clicks canvas.addMouseListener(new java.awt.event.MouseListener() { public void mouseClicked(java.awt.event.MouseEvent e) { } public void mouseEntered(java.awt.event.MouseEvent e) { } public void mouseExited(java.awt.event.MouseEvent e) { } public void mousePressed(java.awt.event.MouseEvent e) { // Manage pop-up editor display.syncExec(new Runnable() { public void run() { if (eShell == null) { // Create new Shell: non-modal! eShell = new Shell(shell, SWT.NO_TRIM | SWT.MODELESS); eShell.setLayout(new FillLayout()); // Text input field eText = new Text(eShell, SWT.BORDER); eText.setText("Text rotation in the SWT?"); eShell.pack(); // Set position (Display coordinates) java.awt.Rectangle bounds = canvas.getBounds(); org.eclipse.swt.graphics.Point pos = canvasComp.toDisplay(bounds.width / 2, bounds.height / 2); Point size = eShell.getSize(); eShell.setBounds(pos.x, pos.y, size.x, size.y); // Open Shell eShell.open(); } else if (!eShell.isVisible()) { // Editor versteckt, sichtbar machen eShell.setVisible(true); } else { // Editor is visible - get text String t = eText.getText(); // set editor invisible eShell.setVisible(false); // Add text to list and redraw canvas wordList.add(t); canvasComp.redraw(); } } }); } public void mouseReleased(java.awt.event.MouseEvent e) { } }); // Redraw the canvas canvasComp.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { // Pass the redraw task to AWT event queue java.awt.EventQueue.invokeLater(new Runnable() { public void run() { // Compute canvas center java.awt.Rectangle bounds = canvas.getBounds(); int originX = bounds.width / 2; int originY = bounds.height / 2; // Reset canvas g2d.setTransform(origTransform); g2d.setColor(java.awt.Color.WHITE); g2d.fillRect(0, 0, bounds.width, bounds.height); // Set font g2d.setFont(new java.awt.Font("Myriad", java.awt.Font.PLAIN, 32)); double angle = 0d; // Prepare star shape double increment = Math.toRadians(30); Iterator iter = wordList.iterator(); while (iter.hasNext()) { // Determine text colors in RGB color cycle float red = (float) (0.5 + 0.5 * Math.sin(angle)); float green = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(120))); float blue = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(240))); g2d.setColor(new java.awt.Color(red, green, blue)); // Redraw text String text = (String) iter.next(); g2d.drawString(text, originX + 50, originY); // Rotate for next text output g2d.rotate(increment, originX, originY); angle += increment; } } }); } }); // Finish shell and open it shell.pack(); shell.open(); // SWT event processing while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }