📄 gtkcomponentpeer.java
字号:
new Rectangle(x, y, width, height))); else RepaintTimerTask.schedule(tm, x, y, width, height, awtComponent); } /** * Used for scheduling delayed paint updates on the event queue. */ private static class RepaintTimerTask extends TimerTask { private static final Timer repaintTimer = new Timer(true); private int x, y, width, height; private Component awtComponent; RepaintTimerTask(Component c, int x, int y, int width, int height) { this.x = x; this.y = y; this.width = width; this.height = height; this.awtComponent = c; } public void run() { q().postEvent (new PaintEvent (awtComponent, PaintEvent.UPDATE, new Rectangle (x, y, width, height))); } static void schedule(long tm, int x, int y, int width, int height, Component c) { repaintTimer.schedule(new RepaintTimerTask(c, x, y, width, height), tm); } } public void requestFocus () { gtkWidgetRequestFocus(); postFocusEvent(FocusEvent.FOCUS_GAINED, false); } public void reshape (int x, int y, int width, int height) { setBounds (x, y, width, height); } public void setBackground (Color c) { gtkWidgetSetBackground (c.getRed(), c.getGreen(), c.getBlue()); } native void setNativeBounds (int x, int y, int width, int height); public void setBounds (int x, int y, int width, int height) { int new_x = x; int new_y = y; Component parent = awtComponent.getParent (); // Heavyweight components that are children of one or more // lightweight containers have to be handled specially. Because // calls to GLightweightPeer.setBounds do nothing, GTK has no // knowledge of the lightweight containers' positions. So we have // to add the offsets manually when placing a heavyweight // component within a lightweight container. The lightweight // container may itself be in a lightweight container and so on, // so we need to continue adding offsets until we reach a // container whose position GTK knows -- that is, the first // non-lightweight. Insets i; while (parent.isLightweight()) { i = ((Container) parent).getInsets(); new_x += parent.getX() + i.left; new_y += parent.getY() + i.top; parent = parent.getParent(); } // We only need to convert from Java to GTK coordinates if we're // placing a heavyweight component in a Window. if (parent instanceof Window) { GtkWindowPeer peer = (GtkWindowPeer) parent.getPeer (); // important: we want the window peer's insets here, not the // window's, since user sub-classes of Window can override // getInset and we only want to correct for the frame borders, // not for any user-defined inset values Insets insets = peer.getInsets (); int menuBarHeight = 0; if (peer instanceof GtkFramePeer) menuBarHeight = ((GtkFramePeer) peer).getMenuBarHeight (); new_x -= insets.left; new_y -= insets.top; new_y += menuBarHeight; } setNativeBounds (new_x, new_y, width, height); // If the height or width were (or are now) smaller than zero // then we want to adjust the visibility. setVisible(awtComponent.isVisible()); } void setCursor () { setCursor (awtComponent.getCursor ()); } public void setCursor (Cursor cursor) { if (Thread.currentThread() == GtkToolkit.mainThread) gtkWidgetSetCursorUnlocked (cursor.getType ()); else gtkWidgetSetCursor (cursor.getType ()); } public void setEnabled (boolean b) { gtkWidgetSetSensitive (b); } public void setFont (Font f) { // FIXME: This should really affect the widget tree below me. // Currently this is only handled if the call is made directly on // a text widget, which implements setFont() itself. gtkWidgetModifyFont(f.getName(), f.getStyle(), f.getSize()); } public void setForeground (Color c) { gtkWidgetSetForeground (c.getRed(), c.getGreen(), c.getBlue()); } public Color getForeground () { int rgb[] = gtkWidgetGetForeground (); return new Color (rgb[0], rgb[1], rgb[2]); } public Color getBackground () { int rgb[] = gtkWidgetGetBackground (); return new Color (rgb[0], rgb[1], rgb[2]); } public native void setVisibleNative (boolean b); public native void setVisibleNativeUnlocked (boolean b); public void setVisible (boolean b) { // Only really set visible when component is bigger than zero pixels. if (b) { Rectangle bounds = awtComponent.getBounds(); b = (bounds.width > 0) && (bounds.height > 0); } if (Thread.currentThread() == GtkToolkit.mainThread) setVisibleNativeUnlocked (b); else setVisibleNative (b); } public void hide () { setVisible (false); } public void show () { setVisible (true); } protected void postMouseEvent(int id, long when, int mods, int x, int y, int clickCount, boolean popupTrigger) { q().postEvent(new MouseEvent(awtComponent, id, when, mods, x, y, clickCount, popupTrigger)); } /** * Callback for component_scroll_cb. */ protected void postMouseWheelEvent(int id, long when, int mods, int x, int y, int clickCount, boolean popupTrigger, int type, int amount, int rotation) { q().postEvent(new MouseWheelEvent(awtComponent, id, when, mods, x, y, clickCount, popupTrigger, type, amount, rotation)); } protected void postExposeEvent (int x, int y, int width, int height) { q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT, new Rectangle (x, y, width, height))); } protected void postKeyEvent (int id, long when, int mods, int keyCode, char keyChar, int keyLocation) { KeyEvent keyEvent = new KeyEvent (awtComponent, id, when, mods, keyCode, keyChar, keyLocation); EventQueue q = q(); // Also post a KEY_TYPED event if keyEvent is a key press that // doesn't represent an action or modifier key. if (keyEvent.getID () == KeyEvent.KEY_PRESSED && (!keyEvent.isActionKey () && keyCode != KeyEvent.VK_SHIFT && keyCode != KeyEvent.VK_CONTROL && keyCode != KeyEvent.VK_ALT)) { synchronized(q) { q.postEvent(keyEvent); keyEvent = new KeyEvent(awtComponent, KeyEvent.KEY_TYPED, when, mods, KeyEvent.VK_UNDEFINED, keyChar, keyLocation); q.postEvent(keyEvent); } } else q.postEvent(keyEvent); } protected void postFocusEvent (int id, boolean temporary) { q().postEvent (new FocusEvent (awtComponent, id, temporary)); } protected void postItemEvent (Object item, int stateChange) { q().postEvent (new ItemEvent ((ItemSelectable)awtComponent, ItemEvent.ITEM_STATE_CHANGED, item, stateChange)); } protected void postTextEvent () { q().postEvent (new TextEvent (awtComponent, TextEvent.TEXT_VALUE_CHANGED)); } public GraphicsConfiguration getGraphicsConfiguration () { // FIXME: just a stub for now. return null; } public void setEventMask (long mask) { // FIXME: just a stub for now. } public boolean isFocusable () { return false; } public boolean requestFocus (Component source, boolean b1, boolean b2, long x) { return false; } public boolean isObscured () { return false; } public boolean canDetermineObscurity () { return false; } public void coalescePaintEvent (PaintEvent e) { } public void updateCursorImmediately () { if (awtComponent.getCursor() != null) setCursor(awtComponent.getCursor()); } public boolean handlesWheelScrolling () { return false; } // Convenience method to create a new volatile image on the screen // on which this component is displayed. public VolatileImage createVolatileImage (int width, int height) { return new GtkVolatileImage (width, height); } // Creates buffers used in a buffering strategy. public void createBuffers (int numBuffers, BufferCapabilities caps) throws AWTException { // numBuffers == 2 implies double-buffering, meaning one back // buffer and one front buffer. if (numBuffers == 2) backBuffer = new GtkVolatileImage(awtComponent.getWidth(), awtComponent.getHeight(), caps.getBackBufferCapabilities()); else throw new AWTException("GtkComponentPeer.createBuffers:" + " multi-buffering not supported"); this.caps = caps; } // Return the back buffer. public Image getBackBuffer () { return backBuffer; } // FIXME: flip should be implemented as a fast native operation public void flip (BufferCapabilities.FlipContents contents) { getGraphics().drawImage(backBuffer, awtComponent.getWidth(), awtComponent.getHeight(), null); // create new back buffer and clear it to the background color. if (contents == BufferCapabilities.FlipContents.BACKGROUND) { backBuffer = createVolatileImage(awtComponent.getWidth(), awtComponent.getHeight()); backBuffer.getGraphics().clearRect(0, 0, awtComponent.getWidth(), awtComponent.getHeight()); } // FIXME: support BufferCapabilities.FlipContents.PRIOR } // Release the resources allocated to back buffers. public void destroyBuffers () { backBuffer.flush(); } public String toString () { return "peer of " + awtComponent.toString(); } public Rectangle getBounds() { // FIXME: implement return null; } public void reparent(ContainerPeer parent) { // FIXME: implement } public void setBounds(int x, int y, int width, int height, int z) { // FIXME: implement setBounds (x, y, width, height); } public boolean isReparentSupported() { // FIXME: implement return false; } public void layout() { // FIXME: implement }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -