Example usage for java.awt Frame add

List of usage examples for java.awt Frame add

Introduction

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

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:org.eclipse.swt.snippets.Snippet319.java

public void go() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 319");
    shell.setBounds(10, 10, 600, 200);//from  w  w w . j ava  2s  .  c om

    /* Create SWT controls and add drag source */
    final Label swtLabel = new Label(shell, SWT.BORDER);
    swtLabel.setBounds(10, 10, 580, 50);
    swtLabel.setText("SWT drag source");
    DragSource dragSource = new DragSource(swtLabel, DND.DROP_COPY);
    dragSource.setTransfer(new MyTypeTransfer());
    dragSource.addDragListener(new DragSourceAdapter() {
        @Override
        public void dragSetData(DragSourceEvent event) {
            MyType object = new MyType();
            object.name = "content dragged from SWT";
            object.time = System.currentTimeMillis();
            event.data = object;
        }
    });

    /* Create AWT/Swing controls */
    Composite embeddedComposite = new Composite(shell, SWT.EMBEDDED);
    embeddedComposite.setBounds(10, 100, 580, 50);
    embeddedComposite.setLayout(new FillLayout());
    Frame frame = SWT_AWT.new_Frame(embeddedComposite);
    final JLabel jLabel = new JLabel("AWT/Swing drop target");
    frame.add(jLabel);

    /* Register the custom data flavour */
    final DataFlavor flavor = new DataFlavor(MIME_TYPE, "MyType custom flavor");
    /*
     * Note that according to jre/lib/flavormap.properties, the preferred way to
     * augment the default system flavor map is to specify the AWT.DnD.flavorMapFileURL
     * property in an awt.properties file.
     *
     * This snippet uses the alternate approach below in order to provide a simple
     * stand-alone snippet that demonstrates the functionality.  This implementation
     * works well, but if the instanceof check below fails for some reason when used
     * in a different context then the drop will not be accepted.
     */
    FlavorMap map = SystemFlavorMap.getDefaultFlavorMap();
    if (map instanceof SystemFlavorMap) {
        SystemFlavorMap systemMap = (SystemFlavorMap) map;
        systemMap.addFlavorForUnencodedNative(MIME_TYPE, flavor);
    }

    /* add drop target */
    DropTargetListener dropTargetListener = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dropTargetDropEvent) {
            try {
                dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY);
                ByteArrayInputStream inStream = (ByteArrayInputStream) dropTargetDropEvent.getTransferable()
                        .getTransferData(flavor);
                int available = inStream.available();
                byte[] bytes = new byte[available];
                inStream.read(bytes);
                MyType object = restoreFromByteArray(bytes);
                String string = object.name + ": " + new Date(object.time).toString();
                jLabel.setText(string);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    new DropTarget(jLabel, dropTargetListener);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:joachimeichborn.geotag.ui.parts.PicturesView.java

private void initializeDetailsSection(final Composite aParent) {
    final Composite details = new Composite(aParent, SWT.BORDER);
    details.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    details.setLayout(new GridLayout(3, false));

    preview = new ImageIcon();
    previewLabel = new JLabel(preview);
    previewContainer = new Composite(details, SWT.EMBEDDED);
    final GridData thumbnailGridData = new GridData();
    thumbnailGridData.verticalSpan = 7;/*  w w  w. j  av a 2 s . c o m*/
    thumbnailGridData.heightHint = 160;
    thumbnailGridData.widthHint = 160;
    previewContainer.setLayoutData(thumbnailGridData);
    final Frame frame = SWT_AWT.new_Frame(previewContainer);
    frame.add(previewLabel);
    final Color color = details.getBackground();
    frame.setBackground(new java.awt.Color(color.getGreen(), color.getGreen(), color.getBlue()));
    color.dispose();

    new Label(details, SWT.NONE).setText("Name: ");
    nameLabel = new Label(details, SWT.NONE);
    nameLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    new Label(details, SWT.NONE).setText("Path: ");
    pathLabel = new Label(details, SWT.NONE);
    pathLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    new Label(details, SWT.NONE).setText("Location name: ");
    locationNameLabel = new Label(details, SWT.NONE);
    locationNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    new Label(details, SWT.NONE).setText("City: ");
    cityLabel = new Label(details, SWT.NONE);
    cityLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    new Label(details, SWT.NONE).setText("Sublocation: ");
    sublocationLabel = new Label(details, SWT.NONE);
    sublocationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    new Label(details, SWT.NONE).setText("Provice: ");
    provinceLabel = new Label(details, SWT.NONE);
    provinceLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    new Label(details, SWT.NONE).setText("Country: ");
    countryLabel = new Label(details, SWT.NONE);
    countryLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
}

From source file:SWT2D.java

private void run() {
    // Create top level shell
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Java 2D Example");
    // GridLayout for canvas and button
    shell.setLayout(new GridLayout());
    // Create container for AWT canvas
    final Composite canvasComp = new Composite(shell, SWT.EMBEDDED);
    // Set preferred size
    GridData data = new GridData();
    data.widthHint = 600;//  ww  w . ja  v  a  2  s  . c om
    data.heightHint = 500;
    canvasComp.setLayoutData(data);
    // Create AWT Frame for Canvas
    java.awt.Frame canvasFrame = SWT_AWT.new_Frame(canvasComp);
    // Create Canvas and add it to the Frame
    final java.awt.Canvas canvas = new java.awt.Canvas();
    canvasFrame.add(canvas);
    // Get graphical context and cast to Java2D
    final java.awt.Graphics2D g2d = (java.awt.Graphics2D) canvas.getGraphics();
    // Enable antialiasing
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Remember initial transform
    final java.awt.geom.AffineTransform origTransform = g2d.getTransform();
    // Create Clear button and position it
    Button clearButton = new Button(shell, SWT.PUSH);
    clearButton.setText("Clear");
    data = new GridData();
    data.horizontalAlignment = GridData.CENTER;
    clearButton.setLayoutData(data);
    // Event processing for Clear button
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            // Delete word list and redraw canvas
            wordList.clear();
            canvasComp.redraw();
        }
    });
    // Process canvas mouse clicks
    canvas.addMouseListener(new java.awt.event.MouseListener() {
        public void mouseClicked(java.awt.event.MouseEvent e) {
        }

        public void mouseEntered(java.awt.event.MouseEvent e) {
        }

        public void mouseExited(java.awt.event.MouseEvent e) {
        }

        public void mousePressed(java.awt.event.MouseEvent e) {
            // Manage pop-up editor
            display.syncExec(new Runnable() {
                public void run() {
                    if (eShell == null) {
                        // Create new Shell: non-modal!
                        eShell = new Shell(shell, SWT.NO_TRIM | SWT.MODELESS);
                        eShell.setLayout(new FillLayout());
                        // Text input field
                        eText = new Text(eShell, SWT.BORDER);
                        eText.setText("Text rotation in the SWT?");
                        eShell.pack();
                        // Set position (Display coordinates)
                        java.awt.Rectangle bounds = canvas.getBounds();
                        org.eclipse.swt.graphics.Point pos = canvasComp.toDisplay(bounds.width / 2,
                                bounds.height / 2);
                        Point size = eShell.getSize();
                        eShell.setBounds(pos.x, pos.y, size.x, size.y);
                        // Open Shell
                        eShell.open();
                    } else if (!eShell.isVisible()) {
                        // Editor versteckt, sichtbar machen
                        eShell.setVisible(true);
                    } else {
                        // Editor is visible - get text
                        String t = eText.getText();
                        // set editor invisible
                        eShell.setVisible(false);
                        // Add text to list and redraw canvas
                        wordList.add(t);
                        canvasComp.redraw();
                    }
                }
            });
        }

        public void mouseReleased(java.awt.event.MouseEvent e) {
        }
    });
    // Redraw the canvas
    canvasComp.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            // Pass the redraw task to AWT event queue
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    // Compute canvas center
                    java.awt.Rectangle bounds = canvas.getBounds();
                    int originX = bounds.width / 2;
                    int originY = bounds.height / 2;
                    // Reset canvas
                    g2d.setTransform(origTransform);
                    g2d.setColor(java.awt.Color.WHITE);
                    g2d.fillRect(0, 0, bounds.width, bounds.height);
                    // Set font
                    g2d.setFont(new java.awt.Font("Myriad", java.awt.Font.PLAIN, 32));
                    double angle = 0d;
                    // Prepare star shape
                    double increment = Math.toRadians(30);
                    Iterator iter = wordList.iterator();
                    while (iter.hasNext()) {
                        // Determine text colors in RGB color cycle
                        float red = (float) (0.5 + 0.5 * Math.sin(angle));
                        float green = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(120)));
                        float blue = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(240)));
                        g2d.setColor(new java.awt.Color(red, green, blue));
                        // Redraw text
                        String text = (String) iter.next();
                        g2d.drawString(text, originX + 50, originY);
                        // Rotate for next text output
                        g2d.rotate(increment, originX, originY);
                        angle += increment;
                    }
                }
            });
        }
    });
    // Finish shell and open it
    shell.pack();
    shell.open();
    // SWT event processing
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:peakml.util.swt.widget.TimePlot.java

public TimePlot(Composite parent, int style) {
    super(parent, SWT.EMBEDDED | style);

    // layout/*from  w  ww  .ja  v a2  s  .  c o  m*/
    setLayout(new FillLayout());

    // create the components
    timeplot = new peakml.util.jfreechart.FastTimePlot("", "");
    timeplot.setBackgroundPaint(Color.WHITE);
    linechart = new JFreeChart("", timeplot);
    linechart.setBackgroundPaint(Color.WHITE);

    // add the components
    // --------------------------------------------------------------------------------
    // This uses the SWT-trick for embedding AWT-controls in an SWT-Composite.
    // 2009-10-17: Tested the SWT setup in jfreechart.experimental - this is still better.
    try {
        System.setProperty("sun.awt.noerasebackground", "true");
    } catch (NoSuchMethodError error) {
        ;
    }

    java.awt.Frame frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(this);
    ChartPanel panel = new ChartPanel(linechart, false, false, false, false, false);

    panel.setFillZoomRectangle(true);
    panel.setMouseZoomable(true, true);

    // create a new ChartPanel, without the popup-menu (5x false)
    frame.add(panel);
    // --------------------------------------------------------------------------------
}

From source file:org.vast.stt.renderer.JFreeChart.JFreeChartRenderer.java

@Override
public void init() {
    swt_awt = new Composite(composite, SWT.EMBEDDED | SWT.DOUBLE_BUFFERED);
    Frame rootFrame = SWT_AWT.new_Frame(swt_awt);
    swt_awt.setBounds(0, 0, composite.getClientArea().width, composite.getClientArea().height);
    chartPanel = new ChartPanel(null);
    chartPanel.setDoubleBuffered(true);/*from   w  w w  . j ava  2s .com*/
    //chartPanel.setPopupMenu(null);
    rootFrame.add(chartPanel);
    //composite.addPaintListener(this);
}

From source file:peakml.util.swt.widget.DerivativeGraph.java

public DerivativeGraph(Composite parent, int style) {
    super(parent, SWT.EMBEDDED | style);

    // layout//from w  ww . java 2  s  .  com
    setLayout(new FillLayout());

    // create the components
    spectrumplot = new FastSpectrumPlot("mass", "intensity");
    spectrumplot.setBackgroundPaint(Color.WHITE);
    linechart = new JFreeChart("", spectrumplot);
    linechart.setBackgroundPaint(Color.WHITE);

    //      org.jfree.experimental.chart.swt.ChartComposite c =
    //         new org.jfree.experimental.chart.swt.ChartComposite(this, SWT.NONE, linechart);
    //      
    //      c.setRangeZoomable(true);
    //      c.setDomainZoomable(true);

    // add the components
    // --------------------------------------------------------------------------------
    // This uses the SWT-trick for embedding AWT-controls in an SWT-Composite.
    // 2009-10-17: Tested the SWT setup in jfreechart.experimental - this is still better.
    try {
        System.setProperty("sun.awt.noerasebackground", "true");
    } catch (NoSuchMethodError error) {
        ;
    }

    java.awt.Frame frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(this);
    ChartPanel panel = new ChartPanel(linechart, false, false, false, false, false);

    panel.setFillZoomRectangle(true);
    panel.setMouseZoomable(true, true);

    // create a new ChartPanel, without the popup-menu (5x false)
    frame.add(panel);
    // --------------------------------------------------------------------------------
}

From source file:peakml.util.swt.widget.IPeakGraph.java

public IPeakGraph(Composite parent, int style) {
    super(parent, SWT.EMBEDDED | style);

    // layout/* ww w  . j  a va 2s .  c om*/
    setLayout(new FillLayout());

    // create the components
    timeplot = new FastTimePlot("retention time", "intensity");
    timeplot.setBackgroundPaint(Color.WHITE);
    linechart = new JFreeChart("", timeplot);
    linechart.setBackgroundPaint(Color.WHITE);

    //      org.jfree.experimental.chart.swt.ChartComposite c =
    //         new org.jfree.experimental.chart.swt.ChartComposite(this, SWT.NONE, linechart);
    //      
    //      c.setRangeZoomable(true);
    //      c.setDomainZoomable(true);

    // add the components
    // --------------------------------------------------------------------------------
    // This uses the SWT-trick for embedding AWT-controls in an SWT-Composite.
    // 2009-10-17: Tested the SWT setup in jfreechart.experimental - this is still better.
    try {
        System.setProperty("sun.awt.noerasebackground", "true");
    } catch (NoSuchMethodError error) {
        ;
    }

    java.awt.Frame frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(this);
    ChartPanel panel = new ChartPanel(linechart, false, false, false, false, false);

    panel.setFillZoomRectangle(true);
    panel.setMouseZoomable(true, true);

    // create a new ChartPanel, without the popup-menu (5x false)
    frame.add(panel);
    // --------------------------------------------------------------------------------
}

From source file:edu.harvard.i2b2.eclipse.plugins.patientMapping.views.PatientMappingView.java

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it./*from w  ww  .j ava2 s  .  c om*/
 */
@Override
public void createPartControl(Composite parent) {
    log.info("Patient Mapping plugin version 1.7.0");
    timelineComposite = parent;

    if (!(UserInfoBean.getInstance().isRoleInProject("DATA_LDS"))) {
        new NoAccessComposite(parent, SWT.NONE);
        return;
    }

    //explorer = new MainComposite(parent, false);*/

    Composite composite = new Composite(parent, SWT.EMBEDDED);

    /* Create and setting up frame */
    ////for mac fix
    //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
    //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
    Frame runFrame = SWT_AWT.new_Frame(composite);
    Panel runPanel = new Panel(new BorderLayout());
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.out.println("Error setting native LAF: " + e);
    }

    runFrame.add(runPanel);
    JRootPane runRoot = new JRootPane();
    runPanel.add(runRoot);
    oAwtContainer = runRoot.getContentPane();

    runTreePanel = new PatientMappingJPanel(oAwtContainer);//PreviousQueryPanel(this);
    //runTreePanel.setBackground(Color.BLUE);

    oAwtContainer.add(runTreePanel);

    // Setup help context
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, PATIENTMAPPING_VIEW_CONTEXT_ID);
    addHelpButtonToToolBar();
}

From source file:edu.harvard.i2b2.eclipse.plugins.query.views.QueryView.java

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it.//  ww w  .ja  v a 2  s .co m
 */
@Override
public void createPartControl(Composite parent) {

    // setup context help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, QUERY_VIEW_CONTEXT_ID);
    addHelpButtonToToolBar();

    log.info("Query Tool plugin version 1.7.0");
    GridLayout topGridLayout = new GridLayout(1, false);
    topGridLayout.numColumns = 1;
    topGridLayout.marginWidth = 2;
    topGridLayout.marginHeight = 2;
    parent.setLayout(topGridLayout);

    queryComposite = new Composite(parent, SWT.NONE);
    queryComposite.setLayout(new FillLayout(SWT.VERTICAL));
    GridData gridData2 = new GridData();
    gridData2.horizontalAlignment = GridData.FILL;
    gridData2.verticalAlignment = GridData.FILL;
    gridData2.grabExcessHorizontalSpace = true;
    gridData2.grabExcessVerticalSpace = true;
    queryComposite.setLayoutData(gridData2);

    Composite rightComp = new Composite(queryComposite, SWT.BORDER | SWT.EMBEDDED | SWT.DragDetect);
    /* Create and setting up frame */
    ////for mac fix
    //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
    //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
    Frame frame = SWT_AWT.new_Frame(rightComp);
    Panel panel = new Panel(new BorderLayout());
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.out.println("Error setting native LAF: " + e);
    }

    frame.add(panel);
    JRootPane root = new JRootPane();
    panel.add(root);
    oAwtContainer = root.getContentPane();

    if (mode_ == 0) {
        queryToolPanel = new QueryToolInvestigatorPanel(this);
    } else {
        queryToolPanel = new QueryToolPanel();
    }

    oAwtContainer.add(queryToolPanel);

}

From source file:edu.harvard.i2b2.eclipse.plugins.adminTool.views.AdminToolView.java

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it.// w ww . jav a2  s.  c  o m
 */
@Override
public void createPartControl(Composite parent) {
    log.info("Patient Mapping plugin version 1.7.0");
    timelineComposite = parent;

    boolean isManager = false;
    ArrayList<String> roles = (ArrayList<String>) UserInfoBean.getInstance().getProjectRoles();
    for (String param : roles) {
        if (param.equalsIgnoreCase("manager")) {
            isManager = true;
            break;
        }
    }

    if (!(UserInfoBean.getInstance().isRoleInProject("DATA_PROT")) || !isManager) {
        new NoAccessComposite(parent, SWT.NONE);
        return;
    }

    //explorer = new MainComposite(parent, false);*/

    Composite composite = new Composite(parent, SWT.EMBEDDED);

    /* Create and setting up frame */
    ////for mac fix
    //if ( System.getProperty("os.name").toLowerCase().startsWith("mac"))
    //SWT_AWT.embeddedFrameClass = "sun.lwawt.macosx.CViewEmbeddedFrame";
    Frame runFrame = SWT_AWT.new_Frame(composite);
    Panel runPanel = new Panel(new BorderLayout());
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.out.println("Error setting native LAF: " + e);
    }

    runFrame.add(runPanel);
    JRootPane runRoot = new JRootPane();
    runPanel.add(runRoot);
    oAwtContainer = runRoot.getContentPane();

    runTreePanel = new AdminToolJPanel();//PatientMappingJPanel();//PreviousQueryPanel(this);
    //runTreePanel.setBackground(Color.BLUE);

    oAwtContainer.add(runTreePanel);

    // Setup help context
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ADMINTOOL_VIEW_CONTEXT_ID);
    addHelpButtonToToolBar();
}