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:JuliaSet2.java

public void print() {
    // Create some attributes objects. This is Java 1.3 stuff.
    // In Java 1.1, we'd use a java.util.Preferences object instead.
    JobAttributes jattrs = new JobAttributes();
    PageAttributes pattrs = new PageAttributes();

    // Set some example attributes: monochrome, landscape mode
    pattrs.setColor(PageAttributes.ColorType.MONOCHROME);
    pattrs.setOrientationRequested(PageAttributes.OrientationRequestedType.LANDSCAPE);
    // Print to file by default
    jattrs.setDestination(JobAttributes.DestinationType.FILE);
    jattrs.setFileName("juliaset.ps");

    // Look up the Frame that holds this component
    Component frame = this;
    while (!(frame instanceof Frame))
        frame = frame.getParent();

    // Get a PrintJob object to print the Julia set with.
    // The getPrintJob() method displays a print dialog and allows the user
    // to override and modify the default JobAttributes and PageAttributes
    Toolkit toolkit = this.getToolkit();
    PrintJob job = toolkit.getPrintJob((Frame) frame, "JuliaSet1", jattrs, pattrs);

    // We get a null PrintJob if the user clicked cancel
    if (job == null)
        return;//from ww w.  ja  v a2s.co m

    // Get a Graphics object from the PrintJob.
    // We print simply by drawing to this Graphics object.
    Graphics g = job.getGraphics();

    // Center the image on the page
    Dimension pagesize = job.getPageDimension(); // how big is page?
    Dimension panesize = this.getSize(); // how big is image?
    g.translate((pagesize.width - panesize.width) / 2, // center it
            (pagesize.height - panesize.height) / 2);

    // Draw a box around the Julia Set and label it
    g.drawRect(-1, -1, panesize.width + 2, panesize.height + 2);
    g.drawString("Julia Set for c={" + cx + "," + cy + "}", 0, -15);

    // Set a clipping region
    g.setClip(0, 0, panesize.width, panesize.height);

    // Now print the component by calling its paint method
    this.paint(g);

    // Finally tell the printer we're done with the page.
    // No output will be generated if we don't call dispose() here.
    g.dispose();
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static void centerComponent(Component component) {
    component.setLocation((component.getParent().getWidth() - component.getWidth()) / 2,
            (component.getParent().getHeight() - component.getHeight()) / 2);
}

From source file:org.apache.cayenne.modeler.util.CayenneController.java

/**
 * Finds a Window in the view hierarchy.
 *///from  w w  w .  jav  a  2s. c  om
public Window getWindow() {
    Component view = getView();
    while (view != null) {
        if (view instanceof Window) {
            return (Window) view;
        }

        view = view.getParent();
    }

    return null;
}

From source file:org.apache.cayenne.modeler.util.CayenneController.java

/**
 * Finds a JFrame in the view hierarchy.
 *//*  w w  w .j a  va2  s  .  c o m*/
public JFrame getFrame() {
    Component view = getView();
    while (view != null) {
        if (view instanceof JFrame) {
            return (JFrame) view;
        }

        view = view.getParent();
    }

    return null;
}

From source file:org.nuclos.client.ui.CenteringPanel.java

/**
 * creates a new CenteringPanel around the given component.
 * @param compChild//from w ww.j a v a  2 s  . c om
 * @param bFilled If true, the size of the child is adjusted to <code>this</code>.
 * If <code>false</code>, the size of the child is not adjusted, but its location is adjusted
 * so it is always centered in <code>this</code>.
 * @precondition compChild != null
 * @postcondition this.getComponentCount() == 1
 * @postcondition compChild.getParent() == this
 * @postcondition this.isFilled() == bFilled
 */
public CenteringPanel(Component compChild, boolean bFilled) {
    this(bFilled);

    if (compChild == null) {
        throw new NullArgumentException("compChild");
    }
    this.add(compChild);

    assert this.getComponentCount() == 1;
    assert compChild.getParent() == this;
    assert this.isFilled() == bFilled;
}

From source file:org.zaproxy.zap.extension.scripts.SyntaxHighlightTextArea.java

public void saveConfiguration(String key, FileConfiguration fileConfiguration) {
    fileConfiguration.setProperty(key + ANTI_ALIASING, Boolean.valueOf(this.getAntiAliasingEnabled()));

    Component c = getParent();
    if (c instanceof JViewport) {
        c = c.getParent();
        if (c instanceof RTextScrollPane) {
            final RTextScrollPane scrollPane = (RTextScrollPane) c;
            fileConfiguration.setProperty(key + SHOW_LINE_NUMBERS,
                    Boolean.valueOf(scrollPane.getLineNumbersEnabled()));
            fileConfiguration.setProperty(key + CODE_FOLDING, Boolean.valueOf(this.isCodeFoldingEnabled()));
        }/*from   www  .  ja  v a 2s. c o m*/
    }

    fileConfiguration.setProperty(key + WORD_WRAP, Boolean.valueOf(this.getLineWrap()));

    fileConfiguration.setProperty(key + HIGHLIGHT_CURRENT_LINE,
            Boolean.valueOf(this.getHighlightCurrentLine()));
    fileConfiguration.setProperty(key + FADE_CURRENT_HIGHLIGHT_LINE,
            Boolean.valueOf(this.getFadeCurrentLineHighlight()));

    fileConfiguration.setProperty(key + SHOW_WHITESPACE_CHARACTERS,
            Boolean.valueOf(this.isWhitespaceVisible()));
    fileConfiguration.setProperty(key + SHOW_NEWLINE_CHARACTERS, Boolean.valueOf(this.getEOLMarkersVisible()));

    fileConfiguration.setProperty(key + MARK_OCCURRENCES, Boolean.valueOf(this.getMarkOccurrences()));

    fileConfiguration.setProperty(key + ROUNDED_SELECTION_EDGES,
            Boolean.valueOf(this.getRoundedSelectionEdges()));

    fileConfiguration.setProperty(key + BRACKET_MATCHING, Boolean.valueOf(this.isBracketMatchingEnabled()));
    fileConfiguration.setProperty(key + ANIMATED_BRACKET_MATCHING,
            Boolean.valueOf(this.getAnimateBracketMatching()));
}

From source file:org.zaproxy.zap.extension.scripts.SyntaxHighlightTextArea.java

public void loadConfiguration(String key, FileConfiguration fileConfiguration) {
    setAntiAliasingEnabled(fileConfiguration.getBoolean(key + ANTI_ALIASING, this.getAntiAliasingEnabled()));

    Component c = getParent();
    if (c instanceof JViewport) {
        c = c.getParent();
        if (c instanceof RTextScrollPane) {
            final RTextScrollPane scrollPane = (RTextScrollPane) c;
            scrollPane.setLineNumbersEnabled(
                    fileConfiguration.getBoolean(key + SHOW_LINE_NUMBERS, scrollPane.getLineNumbersEnabled()));

            setCodeFoldingEnabled(/*ww  w  . j  av a  2  s. c o m*/
                    fileConfiguration.getBoolean(key + CODE_FOLDING, this.isCodeFoldingEnabled()));
            scrollPane.setFoldIndicatorEnabled(this.isCodeFoldingEnabled());
        }
    }

    setLineWrap(fileConfiguration.getBoolean(key + WORD_WRAP, this.getLineWrap()));

    setHighlightCurrentLine(
            fileConfiguration.getBoolean(key + HIGHLIGHT_CURRENT_LINE, this.getHighlightCurrentLine()));
    setFadeCurrentLineHighlight(fileConfiguration.getBoolean(key + FADE_CURRENT_HIGHLIGHT_LINE,
            this.getFadeCurrentLineHighlight()));

    setWhitespaceVisible(
            fileConfiguration.getBoolean(key + SHOW_WHITESPACE_CHARACTERS, this.isWhitespaceVisible()));
    setEOLMarkersVisible(
            fileConfiguration.getBoolean(key + SHOW_NEWLINE_CHARACTERS, this.getEOLMarkersVisible()));

    setMarkOccurrences(fileConfiguration.getBoolean(key + MARK_OCCURRENCES, this.getMarkOccurrences()));

    setRoundedSelectionEdges(
            fileConfiguration.getBoolean(key + ROUNDED_SELECTION_EDGES, this.getRoundedSelectionEdges()));

    setBracketMatchingEnabled(
            fileConfiguration.getBoolean(key + BRACKET_MATCHING, this.isBracketMatchingEnabled()));
    setAnimateBracketMatching(
            fileConfiguration.getBoolean(key + ANIMATED_BRACKET_MATCHING, this.getAnimateBracketMatching()));
}

From source file:org.nuclos.client.ui.CenteringPanel.java

/**
 * sets compChild as the centered component. Does nothing, if <code>compChild</code> is already the centered component.
 * @param compChild//from ww  w . jav  a 2  s .  co m
 * @postcondition compChild != null --> compChild.getParent() == this
 */
public void setCenteredComponent(Component compChild) {
    if (this.getCenteredComponent() != compChild) {
        this.removeAll();
        if (compChild != null) {
            super.add(compChild, bFilled ? BorderLayout.CENTER : null);
        }
        this.validate();
    }
    assert compChild == null || compChild.getParent() == this;
}

From source file:op.tools.SYSTools.java

public static void centerOnParent(Component comp) {
    centerOnParent(comp.getParent(), comp);
}

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

private TableauFrame getTableauFrame(Figure figure) {

    Component parent = getParent(figure);

    if (parent != null) {
        while (parent.getParent() != null) {
            parent = parent.getParent();
        }//w w w.  ja  v a2  s .c o  m
        if (parent instanceof TableauFrame) {
            log.debug("TABLEAUFRAME FOUND");
            return (TableauFrame) parent;
        }
    }
    log.warn("getTableauFrame() returning NULL!!");
    return null;
}