Example usage for java.awt Component getParent

List of usage examples for java.awt Component getParent

Introduction

In this page you can find the example usage for java.awt Component getParent.

Prototype

public Container getParent() 

Source Link

Document

Gets the parent of this component.

Usage

From source file:self.philbrown.javaQuery.$.java

/** Sets the set of views to the parents of all currently-selected views */
public $ parent() {
    List<Component> _views = new ArrayList<Component>();
    for (Component view : this.views) {
        Component parent = view.getParent();
        if (parent != null && !_views.contains(parent)) {
            _views.add(parent);//  w w  w. j  av a2 s  .co m
        }
    }
    this.views.clear();
    this.views = _views;
    return this;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Animates the selected views out of its parent by sliding it right, past its edge
 * @param options use to modify the behavior of the animation
 *///from   www.  j a  va2s. co m
@SuppressWarnings("unchecked")
public void slideRight(final AnimationOptions options) {
    for (final Component view : this.views) {
        Component parent = view.getParent();
        float x = 0;
        if (parent != null) {
            x = parent.getWidth();
        } else {
            Rectangle display = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
            x = display.height;
        }
        $.with(view).animate(QuickMap.qm($.entry("x", x)), options);
    }
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Animates the selected views out of its parent by sliding it down, past its bottom
 * @param options use to modify the behavior of the animation
 *///from w  w w .  ja v  a 2 s  . c o  m
@SuppressWarnings("unchecked")
public void slideDown(final AnimationOptions options) {
    for (final Component view : this.views) {
        Component parent = view.getParent();
        float y = 0;
        if (parent != null) {
            y = parent.getHeight();
        } else {
            Rectangle display = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

            y = display.height;
        }
        $.with(view).animate(QuickMap.qm(QuickEntry.qe("y", y)), options);
    }

}

From source file:self.philbrown.javaQuery.$.java

/**
 * Selects all views within the given current selection that are the single 
 * children of their parent views//from  w w  w . j ava 2s  . co m
 * @param v the view whose hierarchy will be checked
 * @return a list of the found views.
 */
private List<Component> recursivelySelectOnlyChilds(Component v) {
    List<Component> list = new ArrayList<Component>();
    if (v instanceof Container) {
        for (int i = 0; i < ((Container) v).getComponentCount(); i++) {
            list.addAll(recursivelySelectOnlyChilds(((Container) v).getComponent(i)));
        }
    }
    if (v.getParent() instanceof Container && ((Container) v.getParent()).getComponentCount() == 1)
        list.add(v);
    return list;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Includes the given image inside of the selected views. If a view is an `ImageView`, its image
 * is set. Otherwise, the background image of the view is set.
 * @param image the drawable image to include
 * @return this/*  w  w  w .j  a  v  a 2 s.  c  o m*/
 */
public $ image(Image image) {
    for (Component v : views) {
        if (v instanceof JLabel) {
            ((JLabel) v).setIcon(new ImageIcon(image));
        } else if (v instanceof Window) {
            ((Window) v).setIconImage(image);
        } else {
            if (v instanceof Container) {
                JLabel l = new JLabel(new ImageIcon(image));
                l.setBounds(v.getBounds());
                ((Container) v).add(l);
            } else if (v.getParent() != null && v.getParent() instanceof Container) {
                JLabel l = new JLabel(new ImageIcon(image));
                l.setBounds(v.getBounds());
                ((Container) v.getParent()).add(l);
            }

        }
    }
    return this;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * For `ImageView`s, this will set the image to the given asset or url. Otherwise, it will set the
 * background image for the selected views.
 * @param source asset path, file path (starting with "file://") or URL to image
 * @param width specifies the output bitmap width
 * @param height specifies the output bitmap height
 * @param error if the given source is a file or asset, this receives a javaQuery wrapping the 
 * current context and the {@code Throwable} error. Otherwise, this will receive an
 * Ajax error.//from w  w  w.  java  2s . com
 * @return this
 * @see AjaxOptions#error(Function)
 */
public $ image(String source, int width, int height, Function error) {
    if (source.startsWith("file://")) {
        try {
            Image image = ImageIO.read(new File(source.substring(7)));

            for (Component v : views) {
                if (v instanceof JLabel) {
                    ((JLabel) v).setIcon(new ImageIcon(image));
                } else if (v instanceof Window) {
                    ((Window) v).setIconImage(image);
                } else {
                    if (v instanceof Container) {
                        JLabel l = new JLabel(new ImageIcon(image));
                        l.setBounds(v.getBounds());
                        ((Container) v).add(l);
                    } else if (v.getParent() != null && v.getParent() instanceof Container) {
                        JLabel l = new JLabel(new ImageIcon(image));
                        l.setBounds(v.getBounds());
                        ((Container) v.getParent()).add(l);
                    }

                }
            }
        } catch (Throwable t) {
            if (error != null) {
                error.invoke($.with(view(0)), t);
            }
        }
    } else {
        boolean fallthrough = false;
        try {
            new URL(source);
        } catch (Throwable t) {
            fallthrough = true;
        }
        if (fallthrough) {
            AjaxOptions options = new AjaxOptions().url(source).type("GET").dataType("image").context(view(0))
                    .global(false).success(new Function() {
                        @Override
                        public void invoke($ javaQuery, Object... params) {
                            Image image = (Image) params[0];
                            for (Component v : views) {
                                if (v instanceof JLabel) {
                                    ((JLabel) v).setIcon(new ImageIcon(image));
                                } else if (v instanceof Window) {
                                    ((Window) v).setIconImage(image);
                                } else {
                                    if (v instanceof Container) {
                                        JLabel l = new JLabel(new ImageIcon(image));
                                        l.setBounds(v.getBounds());
                                        ((Container) v).add(l);
                                    } else if (v.getParent() != null && v.getParent() instanceof Container) {
                                        JLabel l = new JLabel(new ImageIcon(image));
                                        l.setBounds(v.getBounds());
                                        ((Container) v.getParent()).add(l);
                                    }

                                }
                            }
                        }
                    });

            if (error != null) {
                options.error(error);
            }
            if (width >= 0) {
                options.imageWidth(width);
            }
            if (height >= 0) {
                options.imageHeight(height);
            }
            $.ajax(options);
        }
    }
    return this;
}

From source file:com.actelion.research.table.view.JVisualization.java

private float[] createSimilarityListSMP(String idcode, Object descriptor, int descriptorColumn) {
    float[] similarity = mTableModel.getSimilarityListFromCache(idcode, descriptorColumn);
    if (similarity != null)
        return similarity;

    Component c = this;
    while (!(c instanceof Frame))
        c = c.getParent();

    JProgressDialog progressDialog = new JProgressDialog((Frame) c) {
        private static final long serialVersionUID = 0x20110325;

        public void stopProgress() {
            super.stopProgress();
            close();/*  ww w  . j  av  a 2  s  .com*/
        }
    };

    mTableModel.createSimilarityListSMP(null, descriptor, idcode, descriptorColumn, progressDialog);

    progressDialog.setVisible(true);
    similarity = mTableModel.getSimilarityListSMP();

    return similarity;
}

From source file:org.kepler.gui.ViewManager.java

/**
*
*//*from  w  w  w .j  a  va 2  s.c  o m*/
public void addCanvasToLocation(Component canvas, TableauFrame parent) throws Exception {
    ConfigurationProperty commonProperty = ConfigurationManager.getInstance()
            .getProperty(ConfigurationManager.getModule("common"));
    // get //canvasViewPaneLocation/viewPane
    List<ConfigurationProperty> viewPaneList = commonProperty.getProperties("canvasViewPaneLocation.viewPane");
    // for each viewPane
    for (int i = 0; i < viewPaneList.size(); i++) {
        ConfigurationProperty viewPaneProp = (ConfigurationProperty) viewPaneList.get(i);
        // get viewPane.name
        String viewPaneName = viewPaneProp.getProperty("name").getValue();

        // ViewPane theViewPane = getViewPane(parent, viewPane.name);
        ViewPane theViewPane = getViewPane(parent, viewPaneName);
        // if theViewPane == null, throw exception
        if (theViewPane == null) {
            // Check for the case where the ViewPane *is* actually defined
            // in configuration.xml, but it was not parsed from that file
            // because it was specified along with a tableau filter, which
            // the current tableau does not pass.
            if (isInConfigurationFile(viewPaneName)) {
                continue;
            }
            throw new Exception(viewPaneName + " ViewPane specified in " + viewPaneProp.getModule()
                    + " configuration.xml" + " was not found in the ViewManager."
                    + " Make sure you have specified this in the configuration.xml file.");
        }
        List<ConfigurationProperty> viewPaneLocationList = viewPaneProp.getProperties("viewPaneLocation");
        // for each viewPane.viewPaneLocation
        for (int j = 0; j < viewPaneLocationList.size(); j++) {
            ConfigurationProperty viewPaneLocationProp = (ConfigurationProperty) viewPaneLocationList.get(j);
            // get viewPane.viewPaneLocation.name
            String viewPaneLocationName = viewPaneLocationProp.getProperty("name").getValue();
            // if !theViewPane.hasLocation(viewPane.viewPaneLocation.name)
            // throw exception
            if (!theViewPane.hasLocation(viewPaneLocationName)) {
                throw new Exception("The ViewPaneLocation, " + viewPaneLocationName
                        + ", is not an available location of ViewPane, " + viewPaneName);
            }
            // theViewPane.getLocationContainer(viewPane.viewPaneLocation.name).add("Workflow",
            // canvas);

            // see if the tab name for the canvas is specified
            String canvasTabPaneName = "Workflow";
            ConfigurationProperty tabPaneProp = viewPaneProp.getProperty("tabPanename");
            if (tabPaneProp != null) {
                canvasTabPaneName = tabPaneProp.getValue();
            }

            canvas.setName(canvasTabPaneName);

            // add the canvas as the first tab in the view.
            theViewPane.getLocationContainer(viewPaneLocationName).add(canvas, 0);

            // if the canvas is part of a tabbed pane, make sure it is
            // selected
            Component container = canvas.getParent();
            if (container instanceof JTabbedPane) {
                ((JTabbedPane) container).setSelectedIndex(0);
            }
        }
    }
}

From source file:com.actelion.research.table.view.JVisualization.java

/**
 * @param rowID if != -1 then update this row only
 *///from  w  w  w.  j a v  a2s  .  c  o m
private void updateSimilarityMarkerSizes(int rowID) {
    if (mActivePoint == null || !mTableModel.isDescriptorColumn(mMarkerSizeColumn)) {
        mSimilarityMarkerSize = null;
    } else if (rowID != -1) {
        for (int i = 0; i < mDataPoints; i++) {
            if (mPoint[i].record.getID() == rowID) {
                mSimilarityMarkerSize[rowID] = (float) mTableModel.getDescriptorSimilarity(mActivePoint.record,
                        mPoint[i].record, mMarkerSizeColumn);
                break;
            }
        }
    } else {
        if (DescriptorConstants.DESCRIPTOR_Flexophore.shortName
                .equals(mTableModel.getColumnSpecialType(mMarkerSizeColumn))) {
            // if we have the slow 3DPPMM2 then use a progress dialog and multi-threading
            mSimilarityMarkerSize = null;
            Object descriptor = mActivePoint.record.getData(mMarkerSizeColumn);
            if (descriptor != null) {
                Component c = this;
                while (!(c instanceof Frame))
                    c = c.getParent();

                String idcode = new String(
                        (byte[]) mActivePoint.record.getData(mTableModel.getParentColumn(mMarkerSizeColumn)));
                mSimilarityMarkerSize = createSimilarityListSMP(idcode, descriptor, mMarkerSizeColumn);
            }
        } else {
            mSimilarityMarkerSize = new float[mDataPoints];
            for (int i = 0; i < mDataPoints; i++)
                mSimilarityMarkerSize[mPoint[i].record.getID()] = (float) mTableModel
                        .getDescriptorSimilarity(mActivePoint.record, mPoint[i].record, mMarkerSizeColumn);
        }
    }
}

From source file:com.actelion.research.table.view.JVisualization.java

/**
 * @param axis/*from   w w  w .j  a v a 2 s .com*/
 * @param rowID if != -1 then update this row only
 */
private void setSimilarityValues(int axis, int rowID) {
    int column = mAxisIndex[axis];
    if (mActivePoint == null) {
        mAxisSimilarity[axis] = null;
    } else if (rowID != -1) {
        for (int i = 0; i < mDataPoints; i++) {
            if (mPoint[i].record.getID() == rowID) {
                mAxisSimilarity[axis][rowID] = (float) mTableModel.getDescriptorSimilarity(mActivePoint.record,
                        mPoint[i].record, column);
                break;
            }
        }
    } else {
        if (DescriptorConstants.DESCRIPTOR_Flexophore.shortName
                .equals(mTableModel.getColumnSpecialType(column))) {
            // if we have the slow 3DPPMM2 then use a progress dialog and multi-threading
            mAxisSimilarity[axis] = null;
            Object descriptor = mActivePoint.record.getData(column);
            if (descriptor != null) {
                Component c = this;
                while (!(c instanceof Frame))
                    c = c.getParent();

                String idcode = new String(
                        (byte[]) mActivePoint.record.getData(mTableModel.getParentColumn(column)));
                mAxisSimilarity[axis] = createSimilarityListSMP(idcode, descriptor, column);
            }
        } else {
            mAxisSimilarity[axis] = new float[mDataPoints];
            for (int i = 0; i < mDataPoints; i++)
                mAxisSimilarity[axis][mPoint[i].record.getID()] = (float) mTableModel
                        .getDescriptorSimilarity(mActivePoint.record, mPoint[i].record, column);
        }
    }
    invalidateOffImage(true);
}