package gnu.awt.xlib;
import java.awt.*;
import java.awt.dnd.*;
import java.awt.dnd.peer.*;
import java.awt.font.*;
import java.awt.im.*;
import java.awt.peer.*;
import java.awt.image.ImageProducer;
import java.awt.image.ImageObserver;
import java.net.*;
import java.awt.datatransfer.Clipboard;
import java.io.InputStream;
import java.text.AttributedString;
import java.util.Map;
import java.util.Properties;
import gnu.gcj.xlib.Display;
import gnu.gcj.xlib.Screen;
import gnu.gcj.xlib.Visual;
import gnu.java.awt.ClasspathToolkit;
import gnu.java.awt.peer.ClasspathFontPeer;
import gnu.java.awt.peer.ClasspathTextLayoutPeer;
public class XToolkit extends ClasspathToolkit
{
static XToolkit INSTANCE;
Display display;
EventQueue queue;
XEventLoop eventLoop;
XGraphicsConfiguration defaultConfig;
public XToolkit()
{
INSTANCE = this;
display = new Display();
synchronized (display)
{
queue = new XEventQueue(display);
eventLoop = new XEventLoop(display, queue);
}
}
public void flushIfIdle()
{
eventLoop.flushIfIdle();
}
protected ButtonPeer createButton(Button frontend)
{
return null;
}
protected TextFieldPeer createTextField(TextField frontend)
{
return null; }
protected LabelPeer createLabel(Label frontend)
{
return null; }
protected ListPeer createList(List frontend)
{
return null; }
protected CheckboxPeer createCheckbox(Checkbox frontend)
{
return null; }
protected ScrollbarPeer createScrollbar(Scrollbar frontend)
{
return null; }
protected ScrollPanePeer createScrollPane(ScrollPane frontend)
{
return null; }
protected TextAreaPeer createTextArea(TextArea frontend)
{
return null; }
protected ChoicePeer createChoice(Choice frontend)
{
return null; }
protected FramePeer createFrame(Frame frontend) {
return new XFramePeer(frontend);
}
protected CanvasPeer createCanvas(Canvas frontend) {
XCanvasPeer peer = new XCanvasPeer(frontend);
return peer;
}
protected PanelPeer createPanel(Panel frontend) {
return new XPanelPeer(frontend);
}
protected WindowPeer createWindow(Window frontend)
{
return null; }
protected DialogPeer createDialog(Dialog frontend)
{
return null; }
protected MenuBarPeer createMenuBar(MenuBar frontend)
{
return null; }
protected MenuPeer createMenu(Menu frontend)
{
return null; }
protected PopupMenuPeer createPopupMenu(PopupMenu frontend)
{
return null; }
protected MenuItemPeer createMenuItem(MenuItem frontend)
{
return null; }
protected FileDialogPeer createFileDialog(FileDialog frontend)
{
return null; }
protected CheckboxMenuItemPeer
createCheckboxMenuItem(CheckboxMenuItem frontend)
{
return null; }
protected java.awt.peer.FontPeer getFontPeer(String name, int style)
{
return new XFontPeer (name,style);
}
public Dimension getScreenSize()
{
throw new UnsupportedOperationException("not implemented yet");
}
public int getScreenResolution()
{
throw new UnsupportedOperationException("not implemented yet");
}
public java.awt.image.ColorModel getColorModel()
{
return getDefaultXGraphicsConfiguration().getColorModel();
}
public String[] getFontList()
{
throw new UnsupportedOperationException("not implemented yet");
}
public FontMetrics getFontMetrics(Font font)
{
return getDefaultXGraphicsConfiguration().getXFontMetrics(font);
}
public void sync()
{
flushIfIdle ();
}
public Image getImage(String filename)
{
return createImage(filename);
}
public Image getImage(URL url)
{
throw new UnsupportedOperationException("not implemented yet");
}
public Image createImage(String filename)
{
return null;
}
public Image createImage(URL url)
{
throw new UnsupportedOperationException("not implemented yet");
}
public boolean prepareImage(Image image,
int width,
int height,
ImageObserver observer)
{
throw new UnsupportedOperationException("not implemented yet");
}
public int checkImage(Image image,
int width,
int height,
ImageObserver observer)
{
throw new UnsupportedOperationException("not implemented yet");
}
public Image createImage(ImageProducer producer)
{
throw new UnsupportedOperationException("not implemented yet");
}
public Image createImage(byte[] imagedata,
int imageoffset,
int imagelength)
{
throw new UnsupportedOperationException("not implemented yet");
}
public void beep()
{
throw new UnsupportedOperationException("not implemented yet");
}
public Clipboard getSystemClipboard()
{
return null; }
protected EventQueue getSystemEventQueueImpl()
{
return queue;
}
public PrintJob getPrintJob (Frame frame, String title, Properties props)
{
return null; }
XGraphicsConfiguration getDefaultXGraphicsConfiguration()
{
if (defaultConfig == null)
{
Screen screen = display.getDefaultScreen();
Visual visual = screen.getRootVisual();
defaultConfig = new XGraphicsConfiguration(visual);
if (!defaultConfig.getVisual().getScreen().equals(screen))
{
String msg = "screen of graphics configuration is not " +
"default screen";
throw new Error(msg);
}
}
return defaultConfig;
}
public DragSourceContextPeer
createDragSourceContextPeer(DragGestureEvent dge)
throws InvalidDnDOperationException
{
throw new UnsupportedOperationException("not implemented");
}
public DragGestureRecognizer
createDragGestureRecognizer(Class abstractRecognizerClass,
DragSource ds, Component c,
int srcActions, DragGestureListener dgl)
{
throw new UnsupportedOperationException("not implemented");
}
public Map mapInputMethodHighlight(InputMethodHighlight highlight)
{
throw new UnsupportedOperationException("not implemented");
}
public GraphicsEnvironment getLocalGraphicsEnvironment ()
{
throw new java.lang.UnsupportedOperationException ();
}
public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs)
{
int style = Font.PLAIN;
float size = 12;
if (attrs.containsKey (TextAttribute.WEIGHT))
{
Float weight = (Float) attrs.get (TextAttribute.WEIGHT);
if (weight.floatValue () >= TextAttribute.WEIGHT_BOLD.floatValue ())
style += Font.BOLD;
}
if (attrs.containsKey (TextAttribute.POSTURE))
{
Float posture = (Float) attrs.get (TextAttribute.POSTURE);
if (posture.floatValue () >= TextAttribute.POSTURE_OBLIQUE.floatValue ())
style += Font.ITALIC;
}
if (attrs.containsKey (TextAttribute.SIZE))
{
Float fsize = (Float) attrs.get (TextAttribute.SIZE);
size = fsize.floatValue ();
}
return new XFontPeer (name,style,size);
}
public ClasspathTextLayoutPeer
getClasspathTextLayoutPeer (AttributedString str, FontRenderContext frc)
{
throw new Error("not implemented");
}
public Font createFont (int format, InputStream stream)
{
throw new java.lang.UnsupportedOperationException ();
}
public RobotPeer createRobot (GraphicsDevice screen) throws AWTException
{
throw new java.lang.UnsupportedOperationException ();
}
boolean interrupted;
public boolean nativeQueueEmpty()
{
return eventLoop.isIdle();
}
public void wakeNativeQueue()
{
interrupted = true;
eventLoop.interrupt();
}
public void iterateNativeQueue(java.awt.EventQueue locked, boolean block)
{
interrupted = false;
while (!interrupted)
eventLoop.postNextEvent(block);
};
}