📄 jmedesktop.java
字号:
synchronized ( parent.getTreeLock() ) {
if ( parent instanceof Container ) {
Container container = (Container) parent;
int ncomponents = container.getComponentCount();
for ( int i = 0; i < ncomponents; i++ ) {
Component comp = container.getComponent( i );
if ( comp != null
&& comp.isVisible()
&& ( dragAndDropSupport == null || !dragAndDropSupport.isDragPanel(comp) )
&& comp.contains( x - comp.getX(), y - comp.getY() ) ) {
child = comp;
break;
}
}
}
}
}
if ( child != null ) {
if ( parent instanceof JTabbedPane && child != parent ) {
child = ( (JTabbedPane) parent ).getSelectedComponent();
}
x -= child.getX();
y -= child.getY();
}
return child != parent && child != null ? componentAt( x, y, child, scanRootPanes ) : child;
}
private void sendEnteredEvent( Component comp, Component lastComponent, int buttonMask, Point pos ) {
if ( comp != null && comp != lastComponent ) {
sendEnteredEvent( comp.getParent(), lastComponent, buttonMask, pos );
pos = convertPoint( lastComponent, pos.x, pos.y, comp );
final MouseEvent event = new MouseEvent( comp,
MouseEvent.MOUSE_ENTERED,
System.currentTimeMillis(), buttonMask, pos.x, pos.y, 0, false, 0 );
dispatchEvent( comp, event );
}
}
private void sendExitedEvent( Component lastComponent, int buttonMask, Point pos ) {
final MouseEvent event = new MouseEvent( lastComponent,
MouseEvent.MOUSE_EXITED,
System.currentTimeMillis(), buttonMask, pos.x, pos.y, 1, false, 0 );
dispatchEvent( lastComponent, event );
}
private final LockRunnable paintLockRunnable = new LockRunnable();
public void draw( Renderer r ) {
if ( graphics.isDirty() ) {
final boolean synchronizingThreadsOnUpdate = this.synchronizingThreadsOnUpdate;
if ( synchronizingThreadsOnUpdate ) {
synchronized ( paintLockRunnable ) {
try {
paintLockRunnable.wait = true;
SwingUtilities.invokeLater( paintLockRunnable );
paintLockRunnable.wait( 100 );
} catch ( InterruptedException e ) {
logger.logp(Level.SEVERE, this.getClass().toString(), "draw(Renderer r)", "Exception", e);
}
}
}
try {
if ( graphics != null && texture.getTextureId() > 0) {
graphics.update( texture );
}
} finally {
if ( synchronizingThreadsOnUpdate ) {
synchronized ( paintLockRunnable ) {
paintLockRunnable.notifyAll();
}
}
}
}
super.draw( r );
}
public JDesktopPane getJDesktop() {
return desktop;
}
public Component getFocusOwner() {
if ( !focusCleared ) {
return this.awtWindow.getFocusOwner();
}
return null;
}
private class LockRunnable implements Runnable {
private boolean wait = false;
public void run() {
synchronized ( paintLockRunnable ) {
notifyAll();
if ( wait ) {
try {
//wait for repaint to finish
wait = false;
paintLockRunnable.wait( 200 );
} catch ( InterruptedException e ) {
logger.logp(Level.SEVERE, this.getClass().toString(),
"run()", "Exception", e);
}
}
}
}
}
private static class MyPopupFactory extends PopupFactory {
private final PopupFactory defaultPopupFactory = new PopupFactory();
public Popup getPopup( Component owner, Component contents, int x, int y ) throws IllegalArgumentException {
while ( !( owner instanceof JDesktopPane ) ) {
owner = owner.getParent();
if ( owner == null ) {
logger.warning("jME Popup creation failed, default popup created - desktop not found in component hierarchy of "
+ owner);
return defaultPopupFactory.getPopup( owner, contents, x, y );
}
}
JMEDesktop.LightWeightPopup popup = new JMEDesktop.LightWeightPopup( (JComponent) owner );
popup.adjust( owner, contents, x, y );
return popup;
}
}
private class ButtonAction extends InputAction {
private final int swingButtonIndex;
/**
* @param swingButtonIndex button index sent in generated swing event,
* InputHandler.BUTTON_ALL for mapping 0: MouseEvent.BUTTON1, 1: MouseEvent.BUTTON2, 2: MouseEvent.BUTTON3
*/
public ButtonAction( int swingButtonIndex ) {
this.swingButtonIndex = swingButtonIndex;
}
public void performAction( InputActionEvent evt ) {
onButton( swingButtonIndex != InputHandler.BUTTON_ALL ?
swingButtonIndex : getSwingButtonIndex( evt.getTriggerIndex() ),
evt.getTriggerPressed(), lastXin, lastYin );
}
}
private int getSwingButtonIndex( int jmeButtonIndex ) {
switch ( jmeButtonIndex ) {
case 0: return MouseEvent.BUTTON1;
case 1: return MouseEvent.BUTTON2;
case 2: return MouseEvent.BUTTON3;
default: return MouseEvent.NOBUTTON; //todo: warn here?
}
}
private class XUpdateAction extends InputAction {
public XUpdateAction() {
setSpeed( 1 );
}
public void performAction( InputActionEvent evt ) {
int screenWidth = DisplaySystem.getDisplaySystem().getWidth();
onMove( (int) ( screenWidth * evt.getTriggerDelta() * getSpeed() ), 0,
(int) ( screenWidth * evt.getTriggerPosition() * getSpeed() ), lastYin );
}
}
private class YUpdateAction extends InputAction {
public YUpdateAction() {
setSpeed( 1 );
}
public void performAction( InputActionEvent evt ) {
int screenHeight = DisplaySystem.getDisplaySystem().getHeight();
onMove( 0, (int) ( screenHeight * evt.getTriggerDelta() * getSpeed() ), lastXin,
(int) ( screenHeight * evt.getTriggerPosition() * getSpeed() ) );
}
}
private class WheelUpdateAction extends InputAction {
public WheelUpdateAction() {
setSpeed( 1 );
}
public void performAction( InputActionEvent evt ) {
onWheel( (int) ( evt.getTriggerDelta() * getSpeed() ), lastXin, lastYin );
}
}
private class KeyUpdateAction extends InputAction {
public void performAction( InputActionEvent evt ) {
onKey( evt.getTriggerCharacter(), evt.getTriggerIndex(), evt.getTriggerPressed() );
}
}
/**
* @return current modal component
* @see #setModalComponent(java.awt.Component)
*/
public Component getModalComponent() {
return this.modalComponent;
}
/**
* @see #setModalComponent(java.awt.Component)
*/
private Component modalComponent;
/**
* Filter the swing event to allow events to the specified component and its children only.
* Note: this does not prevent shortcuts and mnemonics to work for the other components!
*
* @param value component that can be exclusively accessed (including children)
*/
public void setModalComponent( final Component value ) {
this.modalComponent = value;
}
protected void setParent( Node parent ) {
if ( desktop != null ) {
super.setParent( parent );
}
else {
throw new IllegalStateException( "already disposed" );
}
}
/**
* Call this method of the desktop is no longer needed. Removes this from the scenegraph, later use is not
* possible any more.
*/
public void dispose() {
if ( desktop != null ) {
if ( getParent() != null ) {
getParent().detachChild( this );
}
inputHandler.removeAllActions();
if ( inputHandler.getParent() != null ) {
inputHandler.getParent().removeFromAttachedHandlers( inputHandler );
}
try {
SwingUtilities.invokeAndWait( new Runnable() {
public void run() {
desktop.removeAll();
awtWindow.dispose();
}
} );
} catch ( InterruptedException e ) {
logger.logp(Level.SEVERE, this.getClass().toString(), "dispose()", "Exception", e);
} catch ( InvocationTargetException e ) {
logger.logp(Level.SEVERE, this.getClass().toString(), "dispose()", "Exception", e);
}
desktop = null;
desktopsUsed--;
if ( desktopsUsed == 0 ) {
PopupFactory.setSharedInstance( new PopupFactory() );
}
}
}
private static class ScrollPaneRepaintFixListener implements ContainerListener {
public void componentAdded( ContainerEvent e ) {
Component child = e.getChild();
componentAdded( child );
}
private void componentAdded( Component child ) {
if ( child instanceof Container ) {
Container container = (Container) child;
addTo( container );
container.addContainerListener( this );
}
if ( child instanceof JScrollPane ) {
final JScrollPane scrollPane = (JScrollPane) child;
// note: the listener added here is only a fix for repaint problems with scrolling
subscribeRepaintListener( scrollPane.getViewport() );
}
}
private void addTo( Container container ) {
container.addContainerListener( this );
for ( int i = 0; i < container.getComponentCount(); i++ ) {
componentAdded( container.getComponent( i ) );
}
}
private void removeFrom( Container container ) {
container.removeContainerListener( this );
for ( int i = 0; i < container.getComponentCount(); i++ ) {
componentRemoved( container.getComponent( i ) );
}
}
private void subscribeRepaintListener( JViewport viewport ) {
for ( int i = 0; i < viewport.getChangeListeners().length; i++ ) {
ChangeListener listener = viewport.getChangeListeners()[i];
if ( listener instanceof ScrollPaneRepaintChangeListener ) {
// listener already subscribed
return;
}
}
viewport.addChangeListener( new ScrollPaneRepaintChangeListener( viewport ) );
}
public void componentRemoved( ContainerEvent e ) {
Component child = e.getChild();
componentRemoved( child );
}
private void componentRemoved( Component child ) {
if ( child instanceof Container ) {
Container container = (Container) child;
removeFrom( container );
}
}
private static class ScrollPaneRepaintChangeListener implements ChangeListener {
private final Component component;
public ScrollPaneRepaintChangeListener( Component component ) {
this.component = component;
}
public void stateChanged( ChangeEvent e ) {
component.repaint();
}
}
}
/**
* Resizing jMEDesktop is not supported.
* @param width -
* @param height -
*/
@Deprecated
public void resize( float width, float height ) {
super.resize(width, height);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -