Example usage for java.awt Window add

List of usage examples for java.awt Window add

Introduction

In this page you can find the example usage for java.awt Window add.

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:corelyzer.ui.CorelyzerApp.java

/**
 * Called by the DisplayConfiguration dialog class to begin the creation of
 * the OpenGL windows given previously set parameters of rows and columns of
 * monitors, and the properties of each monitor
 *//*from www  . j a v  a  2 s  .  c om*/
public void createGLWindows() {
    int nrows = preferences.numberOfRows;
    int ncols = preferences.numberOfColumns;
    int tileWidth = preferences.screenWidth;
    int tileHeight = preferences.screenHeight;

    float borderLeft = preferences.borderLeft;
    float borderRight = preferences.borderRight;
    float borderDown = preferences.borderDown;
    float borderUp = preferences.borderUp;

    float screenDpiX = preferences.dpix;
    float screenDpiY = preferences.dpiy;

    int row_offset, column_offset;

    try {
        row_offset = Integer.parseInt(preferences.getProperty("display.row_offset"));
        column_offset = Integer.parseInt(preferences.getProperty("display.column_offset"));
    } catch (NumberFormatException e) {
        row_offset = 0;
        column_offset = 0;
    }

    // brg 1/17/2012: In Windows Vista and 7, Z-order issues with tool windows and the main canvas
    // are abundant and beyond my abilities to fix. We discovered a workaround - reduce the
    // canvas size by a single row/column of pixels, and everything will work properly. Enforce
    // this programatically until we find a fix.
    final String osName = System.getProperty("os.name").toLowerCase();
    final boolean isWindowsCompositingOS = (osName.equals("windows 7") || osName.equals("windows vista"));
    if (isWindowsCompositingOS)
        tileHeight--; // remove one row

    SceneGraph.setCanvasRowcAndColumn(nrows, ncols);

    sharedContext = null;
    int r, c, canvasNum = 0;
    for (r = 0; r < nrows; r++) {
        for (c = 0; c < ncols; c++) {
            // Allow alpha GL context
            GLProfile profile = GLProfile.getDefault();
            GLCapabilities cap = new GLCapabilities(profile);//GLProfile.getDefault() );
            cap.setAlphaBits(8);
            // System.out.println("---> GL " + cap.toString());

            /*
             * if(MAC_OS_X) { win = new JFrame(); ((JFrame)
             * win).setUndecorated(true); } else { win = new JWindow(); }
             */

            Window win = new JFrame();
            ((JFrame) win).setUndecorated(true);

            win.setLocation(c * tileWidth + column_offset, r * tileHeight + row_offset);

            // brg 3/16/2012: Once we have a shared context, it must be passed in the constructor.
            // The setContext() method doesn't work. (JOGL bug?)
            GLCanvas cvs = null;
            if (sharedContext != null)
                cvs = new GLCanvas(cap, null, sharedContext, null);
            else
                cvs = new GLCanvas(cap);

            win.add(cvs);
            win.addWindowFocusListener(new WindowFocusListener() {
                public void windowGainedFocus(final WindowEvent event) {
                    // do nothing
                }

                public void windowLostFocus(final WindowEvent event) {
                    String isCanvasAlwaysBelow = preferences.getProperty("ui.canvas.alwaysBelow");

                    boolean b;
                    try {
                        b = Boolean.parseBoolean(isCanvasAlwaysBelow);
                    } catch (Exception e) {
                        b = true;
                    }

                    if (b) {
                        GLWindowsToBack();
                    }
                }
            });

            canvasNum++;

            windowVec.add(win);

            final float px = tileWidth * c + (borderLeft + borderRight) * screenDpiX * c;
            final float py = tileHeight * r + (borderUp + borderDown) * screenDpiY * r;
            final int id = SceneGraph.genCanvas(px, py, tileWidth, tileHeight, screenDpiX, screenDpiY);

            CorelyzerGLCanvas cglc = new CorelyzerGLCanvas(cvs, tileWidth, tileHeight, px, py, id);
            canvasVec.add(cglc);

            // if it's the bottom most screen or the first column,
            // then mark to draw depth scale
            if (c == 0) {
                SceneGraph.setCanvasFirstColumn(cglc.getCanvasID(), true);
            }

            if (r == nrows - 1) {
                SceneGraph.setCanvasBottomRow(cglc.getCanvasID(), true);
            }

            win.pack();
            win.setVisible(true);

            // brg 3/16/2012: In JOGL2, a GLCanvas's context is only usable after the
            // canvas has been made visible. Grab the context from the first canvas
            // and share with subsequent canvases at construction-time.
            if (sharedContext == null)
                sharedContext = cvs.getContext();

            win.toBack();
        }
    }

    createTrackMenuItem.setEnabled(true);
    loadDataMenuItem.setEnabled(true);
    loadStateFileMenuItem.setEnabled(true);

    isGLInited = true;
}

From source file:com.jcraft.weirdx.XWindow.java

void reparent(XWindow newparent, int xx, int yy, Client c) throws IOException {
    boolean wasMapped;

    synchronized (LOCK) {
        if (parent == null)
            return;

        int bw = borderWidth;
        wasMapped = ((attr & mapped) != 0);
        XWindow prev;// www.j  a va  2s .c o m

        makeOptional();

        if (wasMapped) {
            unmapWindow(false);
        }

        c.cevent.mkReparentNotify(id, id, newparent.id, xx, yy, ((attr & overrideRedirect) != 0 ? 1 : 0));

        sendEvent(c.cevent, 1, newparent);

        prev = parent;
        if (prev.firstChild == this)
            prev.firstChild = nextSib;
        if (prev.lastChild == this)
            prev.lastChild = prevSib;

        if (nextSib != null)
            nextSib.prevSib = prevSib;
        if (prevSib != null)
            prevSib.nextSib = nextSib;

        parent = newparent;

        nextSib = newparent.firstChild;
        prevSib = null;
        if (newparent.firstChild != null)
            newparent.firstChild.prevSib = this;
        else
            newparent.lastChild = this;
        newparent.firstChild = this;

        origin.x = (short) (xx);
        origin.y = (short) (yy);
        x = (short) (xx + newparent.x);
        y = (short) (yy + newparent.y);

        if (screen.windowmode != WeirdX.InBrowser && hasFrame()) {
            java.awt.Window frame = getFrame();
            frame.remove((java.awt.Component) ddxwindow);
            //   frame.dispose();                                        
            delFrame();
        }
        if (screen.windowmode != WeirdX.InBrowser && newparent == screen.root) {
            java.awt.Window frame = getFrame();
            /*if(frame instanceof JFrame){                               
              ((JFrame)frame).setJMenuBar(null);                       
              ((JFrame)frame).getContentPane().setLayout(null);        
                ((JFrame)frame).setResizable(false);                                 
            }                                                          
            else*/ if (frame instanceof Frame) {
                ((Frame) frame).setMenuBar(null);
                ((Frame) frame).setResizable(true);
            }

            ddxwindow.setLocation(0, 0);

            frame.add((java.awt.Component) ddxwindow);

            frame.validate();
            Insets insets = frame.getInsets();
            frame.setSize(this.width + this.borderWidth * 2 + insets.left + insets.right,
                    this.height + this.borderWidth * 2 + insets.bottom + insets.top);
            frame.validate();

            if (frame instanceof Frame) {
                addWindowListener((java.awt.Frame) frame);
                addComponentListener((java.awt.Frame) frame);
            }
        } else {
            newparent.ddxwindow.add((java.awt.Component) ddxwindow, 0); // ???
            ddxwindow.setLocation(origin.x - borderWidth + parent.borderWidth,
                    origin.y - borderWidth + parent.borderWidth);
        }

        resizeChildrenWinSize(0, 0, 0, 0);

        if (wasMapped) {
            mapWindow(c);
        }

        recalculateDeliverableEvents();
    }
}

From source file:com.jcraft.weirdx.XWindow.java

XWindow(int wid, XWindow prnt, int x, int y, int width, int height, int bwidth, int clss, byte depth,
        Client client, int visual, int msk) throws IOException {
    this(wid);//from   w  ww .  j av  a  2s  .co m
    WindowOpt opt;
    this.client = client;
    this.parent = prnt;
    screen = prnt.screen;

    if (clss == CopyFromParent)
        clss = prnt.clss;
    this.clss = clss;

    if ((clss != InputOutput) && (clss != InputOnly)) {
        client.errorValue = clss;
        client.errorReason = 2; // BadValue;
        return;
    }

    if ((clss != InputOnly) && (prnt.clss == InputOnly)) {
        client.errorValue = clss;
        client.errorReason = 8; // BadMatch;
        return;
    }
    if ((clss == InputOnly) && ((bwidth != 0) || (depth != 0))) {
        client.errorValue = 0;
        client.errorReason = 8; // BadMatch;
        return;
    }

    if ((clss == InputOutput) && (depth == 0)) {
        depth = prnt.depth;
    }

    opt = prnt.optional;
    if (opt == null) {
        opt = prnt.findOptional().optional;
    }
    if (visual == CopyFromParent) {
        visual = opt.visual;
    }
    if ((visual != opt.visual) || (depth != prnt.depth)) {
        boolean foo = false;
        Depth pdepth;
        for (int i = 0; i < screen.depth.length; i++) {
            pdepth = screen.depth[i];
            if (depth == pdepth.depth || depth == 0) {
                if (pdepth.visual != null) {
                    for (int j = 0; j < pdepth.visual.length; j++) {
                        if (visual == pdepth.visual[j].id) {
                            foo = true;
                            break;
                        }
                    }
                }
            }
        }
        if (!foo) {
            client.errorValue = 0;
            client.errorReason = 8; // BadMatch;
            return;
        }
    }
    if (((msk & (CWBorderPixmap | CWBorderPixel)) == 0) && (clss != InputOnly) && (depth != prnt.depth)) {
        client.errorValue = 0;
        client.errorReason = 8; // BadMatch;
        return;
    }

    this.depth = depth;
    if (depth == prnt.depth) {
        this.bitsPerPixel = prnt.bitsPerPixel;
    } else {
        int ii = 0;
        while (ii < Format.format.length) {
            if (Format.format[ii].depth == screen.rootDepth)
                break;
            ii++;
        }
        if (ii == Format.format.length) {
            // ???
            ii = 0;
        }
        this.bitsPerPixel = Format.format[ii].bpp;
    }

    this.type = prnt.type;
    if (clss == InputOnly)
        this.type = UNDRAWABLE_WINDOW;

    setDefault();

    if (visual != opt.visual) {
        makeOptional();
        this.optional.visual = visual;
        this.optional.colormap = screen.defaultColormap;
    }
    this.borderWidth = bwidth;
    attr &= ~backgroundState;
    attr &= ~borderIsPixel;
    attr |= (prnt.attr & borderIsPixel);

    this.border = prnt.border.dup();

    if ((attr & borderIsPixel) == 0) {
        this.border.pixmap.ref();
    }
    this.origin.x = (short) (x + bwidth);
    this.origin.y = (short) (y + bwidth);
    this.width = width;
    this.height = height;
    this.x = (short) (prnt.x + x + bwidth);
    this.y = (short) (prnt.y + y + bwidth);

    synchronized (LOCK) {
        this.nextSib = prnt.firstChild;
        if (prnt.firstChild != null)
            prnt.firstChild.prevSib = this;
        else
            prnt.lastChild = this;
        prnt.firstChild = this;
    }

    if ((msk & CWEventMask) == 0) {
        recalculateDeliverableEvents();
    }

    msk &= 0x7fff;
    if (msk != 0) {
        changeAttr(client, msk);
    }

    if (client.errorReason != 0) {
        this.delete();
        return;
    }

    if ((msk & CWBackingStore) != 0 && (defaultBackingStore != 0)) {
        attr &= ~backingStore;
        attr |= (defaultBackingStore << backingStoreOffset);
        attr |= forcedBS;
    }

    //  ddxwindow=new DDXWindow();
    try {
        ddxwindow = (DDXWindow) dDXWindow.newInstance();
    } catch (Exception e) {
        LOG.error(e);
        /*ddxwindow=new DDXWindow();*/ }
    ddxwindow.init(this);

    try {
        if (screen.windowmode != WeirdX.InBrowser && prnt == screen.root) {
            final java.awt.Window frame = getFrame();
            /*
            if(frame instanceof JFrame){                               
              ((JFrame)frame).setJMenuBar(null);                       
              ((JFrame)frame).getContentPane().setLayout(null);        
                ((JFrame)frame).setResizable(false);                                 
            }                                                          
            else*/ if (frame instanceof Frame) {
                ((Frame) frame).setMenuBar(null);
                ((Frame) frame).setResizable(true);
            }

            ddxwindow.setLocation(0, 0);

            //   if(frame instanceof JFrame){                               
            //     ((JFrame)frame).getContentPane().add((java.awt.Component)ddxwindow);
            //   }                                                          
            //   else{                                                      
            frame.add((java.awt.Component) ddxwindow);
            //   }                                                          

            frame.pack();
            Insets insets = frame.getInsets();
            /*
            frame.setSize(this.width+this.borderWidth*2+             
                     insets.left+insets.right,                  
                     this.height+this.borderWidth*2+            
                     insets.bottom+insets.top);                 
            */
            frame.setLocation(this.origin.x - this.borderWidth + parent.borderWidth,
                    this.origin.y - this.borderWidth + parent.borderWidth);

            if (frame instanceof Frame) {
                addWindowListener((java.awt.Frame) frame);
                addComponentListener((java.awt.Frame) frame);
            }
        } else {
            ddxwindow.setLocation(origin.x - borderWidth + parent.borderWidth,
                    origin.y - borderWidth + parent.borderWidth);
            prnt.ddxwindow.add((java.awt.Component) ddxwindow, 0);
        }
        if ((attr & cursorIsNone) == 0) {
            XCursor cur = getCursor();
            if (cur != null) {
                ddxwindow.setCursor(cur.cursor);
            }
        }
        if (bwidth > 0) {
            ddxwindow.setBorderPixmap(border.pixmap);
        }
    } catch (Exception ee) {
        //System.out.println("error: Window?? "+ee);
    }

    if (prnt.subSend()) {
        client.cevent.mkCreateNotify(prnt.id, id, x, y, width, height, borderWidth,
                (attr & overrideRedirect) != 0 ? 0 : 1);
        prnt.sendEvent(client.cevent, 1, null);
    }
}

From source file:com.xilinx.ultrascale.gui.MainScreen_video.java

private EmbeddedMediaPlayerComponent create(final Window frame, final int i) {

    final EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent() {
        protected String[] onGetMediaPlayerFactoryArgs() {
            if (i == 1) {
                return VLC_ARGS;
            } else {
                return null;
            }/* w  ww . java  2s  .co m*/
        }

    };

    // You *must* do this...
    mediaPlayerComponent.getMediaPlayer().setEnableKeyInputHandling(false);
    mediaPlayerComponent.getMediaPlayer().setEnableMouseInputHandling(false);

    /*mediaPlayerComponent.getVideoSurface().addMouseListener(new MouseAdapter() {
     @Override
     public void mouseClicked(MouseEvent event) {
     if (event.getClickCount() == 2) {
     if (screen.getFullScreenWindow() == null) {
     screen.setFullScreenWindow(frame);
     mediaPlayerComponent.getMediaPlayer().setAspectRatio("16:10");
                        
     } else {
     screen.setFullScreenWindow(null);
     mediaPlayerComponent.getMediaPlayer().setAspectRatio(aspectRatio);
     }
     }
     }
     });*/
    frame.add(mediaPlayerComponent);

    frame.setVisible(false);
    mediaPlayerComponent.getMediaPlayer().setAspectRatio(aspectRatio);
    return mediaPlayerComponent;
}