package de.fulda.mmprog.audio.gui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
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.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import de.fulda.mmprog.audio.controller.Controller;
public class AlternativeGUI {
private Controller myctrl;
private Table table;
private String filen;
static int[] circle(int r, int offsetX, int offsetY)
{
int[] polygon = new int[8 * r + 4];
//x^2 + y^2 = r^2
for (int i = 0; i < 2 * r + 1; i++) {
int x = i - r;
int y = (int)Math.sqrt(r*r - x*x);
polygon[2*i] = offsetX + x;
polygon[2*i+1] = offsetY + y;
polygon[8*r - 2*i - 2] = offsetX + x;
polygon[8*r - 2*i - 1] = offsetY - y;
}
return polygon;
}
public void open() {
final Display display = new Display();
//Shell must be created with style SWT.NO_TRIM
final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP );
shell.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
//define a region
Region region = new Region();
//Anfang ist oben links die Ecke
region.add(new int[]{238, 0, 785, 0, 800, 15, 800, 455, 785 ,470
, 785, 526, 765, 545, 290, 545, 270, 525
, 270, 510, 185, 495, 146, 513, 90, 416
, 118, 389, 241, 6});
region.add(circle(222, 233, 225));
region.add(circle(75, 77, 485));
region.add(circle(75, 236, 460));
region.add(circle(15, 785, 15));//rechts Oben, runde Ecke
region.add(circle(15, 785, 455));
region.add(circle(15, 770, 530));
/* So kann man noch Flächen rausschneiden
region.subtract(new int[]{80, 50, 55, 105, 79, 105});
region.subtract(circle(60, 100, 150));
*/
//define the shape of the shell using setRegion
shell.setRegion(region);
Rectangle size = region.getBounds();
shell.setSize(size.width, size.height);
//shell.setSize(800,600);
ImageData data = new ImageData("Skin2.jpg");
final Image i = new Image(display, data);
shell.addPaintListener(new PaintListener()
{
public void paintControl(PaintEvent e)
{
e.gc.drawImage(i, 0, 0);
}
});
//add ability to move shell around
Listener l = new Listener()
{
Point origin;
public void handleEvent(Event e)
{
switch (e.type)
{
case SWT.MouseDown:
origin = new Point(e.x, e.y);
break;
case SWT.MouseUp:
origin = null;
break;
case SWT.MouseMove:
if (origin != null)
{
Point p = display.map(shell, null, e.x, e.y);
shell.setLocation(p.x - origin.x, p.y - origin.y);
}
break;
}
}
};
shell.addListener(SWT.MouseDown, l);
shell.addListener(SWT.MouseUp, l);
shell.addListener(SWT.MouseMove, l);
Button exit = new Button(shell, SWT.FLAT | SWT.PUSH);
exit.setBackground(shell.getBackground());
exit.setText("X");
exit.pack();
exit.setLocation(769, 9);
exit.addListener(SWT.Selection, new Listener()
{
public void handleEvent(Event e)
{
shell.close();
}
}
);
/*
Button play = new Button(shell, SWT.PUSH | SWT.FLAT | SWT.NO_BACKGROUND);
Image playImage = new Image(shell.getDisplay(),"PlayButton2.gif");
play.setImage(playImage);
play.pack();
play.setLocation(220, 454);
play.addListener(SWT.Selection, new Listener()
{
public void handleEvent(Event e)
{
shell.close();
}
}
);
*/
// ButtonGIF wird an die Stelle gezeichnet, hat mir aber auch nicht
/* weiter geholfen
ImageData playData = new ImageData("PlayButton2.gif");
final Image playImage = new Image(display, playData);
shell.addPaintListener(new PaintListener(){
public void paintControl(PaintEvent e) {
e.gc.drawImage(playImage, 220, 454);
}
}); */
Group group1 = new Group(shell,SWT.NO_TRIM );
group1.setBounds(30,440,90,90);
group1.setText("Volume");
//HintergrundLabel für den Controller
ImageData controlData = new ImageData("Controller.gif");
final Image controllerImage = new Image(display, controlData);
Label controlLabel = new Label(shell,SWT.FLAT);
//controlLabel.setBounds(300,420,94,94);
controlLabel.setBounds(188,424,92,92);
controlLabel.setImage(controllerImage);
/*
controlLabel.addMouseListener(MouseListener l)
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
region.dispose();
display.dispose();
}
}