jndesktop.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 592 行 · 第 1/2 页

JAVA
592
字号
                                && tempWindow.getLocation().y <= event.getY()
                                && (tempWindow.getLocation().x + tempWindow
                                        .getSize().width) >= event.getX()
                                && (tempWindow.getLocation().y + tempWindow
                                        .getSize().height) >= event.getY()) {
                            window = tempWindow;
                        }
                    }
                }

        if (window != null) {
            if (!window.isActive()) {
                activateWindow(window);
                // move active window at the end of the list
            }
            // kk
            event.translatePoint(window.getX(), window.getY());

            window.processMouseMotionEvent(event);
            event.consume();

            if (window.getCursor() != null) {
                lastCursor = cursor;
                cursor = window.getCursor();
            }
        } else {
            org.jnode.wt.components.JNSimpleContainer sc = ((org.jnode.wt.components.JNSimpleContainer) containers
                    .get(DESKTOP_LAYER));
            if (sc != null) sc.processMouseMotionEvent(event);
        }
    }

    /*
     * protected void processMouseMotionEvent(JNodeMouseEvent event) {
     * super.processMouseMotionEvent(event); // if (activeWindow != null &&
     * activeWindow.inRelocateMode) { // //System.out.println("mouseMotion in
     * relocate mode"); //// windowMoved(activeWindow); // //update(clipG); // }
     * //Repeat code should be trimmed, if 't works. JNWindow window = null; if
     * (window == null)
     * 
     * for (Iterator it = getLayers().iterator(); it.hasNext();) {
     * JNSimpleContainer c = (JNSimpleContainer) it.next(); for (Iterator iter =
     * c.getComponents().iterator(); iter.hasNext();) { final JNComponent
     * component = (JNComponent) iter.next(); if (component instanceof
     * JNWindow) { final JNWindow tempWindow = (JNWindow) component; final
     * Point wLoc = tempWindow.getLocation(); final Dimension wSize =
     * tempWindow.getSize(); if (wLoc.x <= event.getX() && wLoc.y <=
     * event.getY() && (wLoc.x + wSize.width) >= event.getX() && (wLoc.y +
     * wSize.height) >= event.getY()) {
     * 
     * window = tempWindow; } } } }
     * 
     * if (window != null) { if (!window.isActive()) { activateWindow(window); //
     * move active window at the end of the list }
     * window.processMouseMotionEvent(event); event.consume(); if
     * (window.getCursor() != null) { //lastCursor = cursor; cursor =
     * window.getCursor(); } } else {
     * getLayer(DESKTOP_LAYER).processMouseEvent(event); }
     * 
     * updateMousePointer(event.getX(), event.getY());
     *  
     */

    /*
     * processes the mouse events the are posted in the queue
     */
    protected void processMouseMotionEvent_old(JNodeMouseEvent e) {
        if (activeWindow != null && activeWindow.inRelocateMode) {
            //System.out.println("mouseMotion in relocate mode");
            int x = activeWindow.getLocation().x + (e.getX() - lastMouseX);
            int y = activeWindow.getLocation().y + (e.getY() - lastMouseY);

            // I need to set the cliping do that I don't paint all again
            Graphics g = getGraphics();
            g.clipRect(Math.min(activeWindow.getLocation().x, x) - 1, Math.min(
                    activeWindow.getLocation().y, y) - 1, activeWindow
                    .getSize().width
                    + Math.abs(x - activeWindow.getLocation().x) + 3,
                    activeWindow.getSize().height
                            + Math.abs(y - activeWindow.getLocation().y) + 3);

            activeWindow.setLocation(x, y);
            // paint imediatly
            validate();
            update(g);
            //		}
            // kk
            e.translatePoint(activeWindow.getX(), activeWindow.getY());
            activeWindow.processMouseEvent(e);
            e.consume();

        }
        updateMousePointer(e.getX(), e.getY());

    }

    public void processWindowEvent(JNWindowEvent event) {
        if (event.getID() == WindowEvent.WINDOW_CLOSED) {
            // remove window from desktop
            this.unregisterWindow((JNWindow) event.getSource());
        }
    }

    public void registerWindow(JNWindow window) {
        window.setParent(this);
        this.activateWindow(window);
    }

    public synchronized void removeDesktopListener(
            JNDesktopListener desktopListener) {
        desktopListeners.remove(desktopListener);
    }

    /**
     * @param cursor
     *            The cursor to set.
     */
    public void setCursor(JNCursor cursor) {
        this.cursor = cursor;
    }

    /**
     * @param size
     *            The size to set.
     */
    public void setSize(Dimension size) {
        //bg.setSize(size);
        super.setSize(size);
        invalidate();
    }

    private void startAppManager() {
        //this.add(bg, DESKTOP_BACKGROUND_LAYER);

        /*
         * final JNButton newWindowBtn = new JNButton("New"); //
         * newWindowBtn.setSize(new Dimension(40, 20)); //
         * newWindowBtn.setBackground(Color.red);
         * newWindowBtn.addMouseListener(new JNMouseAdapter() {
         * 
         * public void mouseClicked(JNodeMouseEvent event) {
         * createRandomWindow();
         *  } }); newWindowBtn.setLocation(10, 10); // this.add(newWindowBtn,
         * DESKTOP_LAYER);
         * 
         * final JNButton closebtn = new JNButton("Clear"); //
         * closebtn.setSize(new Dimension(40, 20)); //
         * closebtn.setBackground(Color.red); closebtn.addMouseListener(new
         * JNMouseAdapter() {
         * 
         * public void mouseClicked(JNodeMouseEvent event) { close(); } });
         * closebtn.setLocation(160, 10); this.add(closebtn, DESKTOP_LAYER);
         */
        /*
         * final JNButton tbtn = new JNButton("300,10"); tbtn.setLocation(300,
         * 10); this.add(tbtn, DESKTOP_LAYER);
         * 
         * final JNButton t2btn = new JNButton("400,0"); t2btn.setLocation(400,
         * 0);
         */

    }

    /*
     * private void startAppManager() { //this.add(bg,
     * DESKTOP_BACKGROUND_LAYER);
     * 
     * final JNButton newWindowBtn = new JNButton(""); newWindowBtn.setSize(new
     * Dimension(40, 20)); newWindowBtn.setBackground(Color.RED);
     * newWindowBtn.addMouseListener(new JNMouseAdapter() {
     * 
     * public void mouseClicked(JNodeMouseEvent event) { createRandomWindow();
     *  } }); newWindowBtn.setLocation(10, 10); this.add(newWindowBtn,
     * DESKTOP_LAYER);
     * 
     * final JNButton closebtn = new JNButton("Close"); closebtn.setSize(new
     * Dimension(40, 20)); closebtn.setBackground(Color.RED);
     * closebtn.addMouseListener(new JNMouseAdapter() {
     * 
     * public void mouseClicked(JNodeMouseEvent event) { close(); } });
     * closebtn.setLocation(60, 10); this.add(closebtn, DESKTOP_LAYER); }
     */

/*    private void startAppManager2() {
        //this.add(bg, DESKTOP_BACKGROUND_LAYER);

        final JNButton newWindowBtn = new JNButton("New");
        //		newWindowBtn.setSize(new Dimension(40, 20));
        //		newWindowBtn.setBackground(Color.red);
        newWindowBtn.addMouseListener(new JNMouseAdapter() {

            public void mouseClicked(JNodeMouseEvent event) {
                //	createRandomWindow();

            }
        });
        newWindowBtn.setLocation(150, 100);
        newWindowBtn.setName("New");
        this.add(newWindowBtn, MENU_COMBO_LAYER);

        JNButton menucombo = new JNButton("menucombo");
        menucombo.setLocation(100, 10);
        menucombo.setName("menucombo");
        this.add(menucombo,
                org.jnode.wt.components.JNLayeredContainer.MENU_COMBO_LAYER);

        JNButton second = new JNButton("kishore");
        second.setLocation(100, 200);
        second.setName("kishore");
        this.add(second, MENU_COMBO_LAYER);

        final JNButton closebtn = new JNButton("Clear");
        //		closebtn.setSize(new Dimension(40, 20));
        //		closebtn.setBackground(Color.red);
        closebtn.addMouseListener(new JNMouseAdapter() {

            public void mouseClicked(JNodeMouseEvent event) {
                //		close();
            }
        });
        closebtn.setLocation(160, 10);
        //this.add(closebtn, DESKTOP_LAYER);
        //		this.add(closebtn, new Integer(1007));

        
         * final JNButton tbtn = new JNButton("300,10"); tbtn.setLocation(300,
         * 10); this.add(tbtn, DESKTOP_LAYER);
         * 
         * final JNButton t2btn = new JNButton("400,0"); t2btn.setLocation(400,
         * 0);
         

    }
*/
    public void unregisterWindow(JNWindow window) {
        window.setParent(null);
        // remove this window
        remove(window, getLayer(window));
        this.activeWindow = null;
        if (((org.jnode.wt.components.JNSimpleContainer) containers
                .get(JNDesktop.ACTIVE_LAYER)).getComponentList().isEmpty()
                && this.getWindowsCount() > 0) {
            // bring a new one in active mode
            JNWindow newActiveWindow = (JNWindow) ((org.jnode.wt.components.JNSimpleContainer) containers
                    .get(org.jnode.wt.components.JNLayeredContainer.DEFAULT_LAYER))
                    .getComponentList()
                    .get(
                            ((org.jnode.wt.components.JNSimpleContainer) containers
                                    .get(org.jnode.wt.components.JNLayeredContainer.DEFAULT_LAYER))
                                    .getComponentList().size() - 1);
            activateWindow(newActiveWindow);
        }
        if (this.getWindowsCount() == 0 && inClose) {
            // close this desktop
            closed();
        } else
            this.repaint();

    }

    /**
     *  
     */
    private void updateMousePointer(int x, int y) {
        if (!getDesktopManager().isHardwareCursor()) {
            if (cursor == null) cursor = JNCursor.defaultCursor();
            if (lastCursor == null) lastCursor = JNCursor.defaultCursor();
            Graphics g = this.getGraphics().create();
            g.clipRect(lastMouseX - 1, lastMouseY - 30,
                    lastCursor.getSize().width + 20,
                    lastCursor.getSize().height + 30);
            update(g);
            g.translate(x, y);
            cursor.draw(g);
        }
        this.lastMouseX = x;
        this.lastMouseY = y;
    }

    public void windowMoved(JNWindow jnWindow, Rectangle oldBounds) {
        //        final Rectangle oldBounds = activeWindow.getBounds();
        //        final int x = activeWindow.getX() + (e.getX() - lastMouseX);
        //        final int y = activeWindow.getY() + (e.getY() - lastMouseY);

        //        activeWindow.setLocation(x, y);
        //final Rectangle newBounds = jnWindow.getBounds();

        //final Rectangle repaintBounds =
        // oldBounds.createUnion(newBounds).getBounds();

        // repaint the moved areas
        validate();
        //        repaint(repaintBounds);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?