Java Code Examples for javax.swing.JComponent.getParent()

The following are Jave code examples for showing how to use getParent() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: DropTargetLayer.java   View Source Code Vote up 6 votes
private void drawSelectedComponent(Graphics2D g2, JComponent selected, RADComponent rad) {
    if(selected == null) return;
    if(selected.getParent() == null || !selected.getParent().isVisible()) return;
    // draw normal border around toplevel menus
    if (selected instanceof JMenu && selected.getParent() instanceof JMenuBar) {
        JMenuItem menu = (JMenuItem) selected;
        Point location = SwingUtilities.convertPoint(menu, new Point(0, 0), this);
        g2.translate(location.x, location.y);
        // #114610: keep drop rectangle guidelines consistent when menu component is inserted from menu-bar into submenu
        g2.setStroke((currentTargetType == DropTargetType.INTO_SUBMENU) ? DROP_TARGET_LINE_STROKE : SELECTION_STROKE);
        g2.setColor(SELECTION_COLOR);
        g2.drawRect(0, 0, menu.getWidth() - 1, menu.getHeight() - 1);
        g2.translate(-location.x, -location.y);
    }
    
    // style only menuitems and menus that aren't also toplevel menus
    // don't do subrect drawing if doing a drag
    if (selected instanceof JMenuItem && !(selected.getParent() instanceof JMenuBar) && currentTargetComponent == null) {
        JMenuItem item = (JMenuItem) selected;
        drawSubselectedItem(g2, item);
    }

}
 
Example 2
Project: freecol   File: QuickActionMenu.java   View Source Code Vote up 6 votes
/**
 * Add specific menu items for a given component.
 *
 * @param comp The specific {@code JComponent}.
 * @return This {@code QuickActionMenu}.
 */
public QuickActionMenu addMenuItems(JComponent comp) {
    if (comp instanceof UnitLabel) {
        createUnitMenu((UnitLabel)comp);
    } else if (comp instanceof GoodsLabel) {
        createGoodsMenu((GoodsLabel)comp);
    } else if (comp instanceof MarketLabel) {
        createMarketMenu((MarketLabel)comp);
    } else if (comp instanceof ASingleTilePanel) {
        createTileMenu((ASingleTilePanel)comp);
    } else if (comp.getParent() instanceof ASingleTilePanel) {
        // Also check the parent to show the popup in the
        // center of the colony panel tile.
        createTileMenu((ASingleTilePanel)comp.getParent());
    }
    return this;
}
 
Example 3
Project: incubator-netbeans   File: SystemAction.java   View Source Code Vote up 6 votes
/** Create an icon.
* @param comp a component, which must be unattached to a container
*             and should not be used for other purposes
*/
public ComponentIcon(JComponent comp) {
    if (comp.getParent() != null) {
        throw new IllegalArgumentException();
    }

    this.comp = comp;

    Dimension size = comp.getPreferredSize();

    // Careful! If you have e.g. a JLabel with empty text, width = 0 => exceptions.
    // Must make sure it is at least a reasonable size.
    comp.setSize(Math.max(size.width, 16), Math.max(size.height, 16));
}
 
Example 4
Project: incubator-netbeans   File: DataView.java   View Source Code Vote up 6 votes
public void activateFilter() {
    JComponent panel = getBottomPanel();
    
    if (filterPanel == null) {
        filterPanel = FilterUtils.createFilterPanel(getResultsComponent(), getExcludesFilter(), getFilterOptions());
        panel.add(filterPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }
    
    panel.setVisible(true);
    
    filterPanel.setVisible(true);
    filterPanel.requestFocusInWindow();
}
 
Example 5
Project: incubator-netbeans   File: DataView.java   View Source Code Vote up 6 votes
public void activateSearch() {
    JComponent panel = getBottomPanel();
    
    if (searchPanel == null) {
        SearchUtils.TreeHelper searchHelper = getSearchHelper();
        if (searchHelper == null) searchPanel = SearchUtils.createSearchPanel(getResultsComponent(), getSearchOptions());
        else searchPanel = SearchUtils.createSearchPanel((ProfilerTreeTable)getResultsComponent(), searchHelper, getSearchOptions());
        panel.add(searchPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }
    
    panel.setVisible(true);
    
    searchPanel.setVisible(true);
    searchPanel.requestFocusInWindow();
}
 
Example 6
Project: FreeCol   File: QuickActionMenu.java   View Source Code Vote up 6 votes
/**
 * Add specific menu items for a given component.
 *
 * @param comp The specific {@code JComponent}.
 * @return This {@code QuickActionMenu}.
 */
public QuickActionMenu addMenuItems(JComponent comp) {
    if (comp instanceof UnitLabel) {
        createUnitMenu((UnitLabel)comp);
    } else if (comp instanceof GoodsLabel) {
        createGoodsMenu((GoodsLabel)comp);
    } else if (comp instanceof MarketLabel) {
        createMarketMenu((MarketLabel)comp);
    } else if (comp instanceof ASingleTilePanel) {
        createTileMenu((ASingleTilePanel)comp);
    } else if (comp.getParent() instanceof ASingleTilePanel) {
        // Also check the parent to show the popup in the
        // center of the colony panel tile.
        createTileMenu((ASingleTilePanel)comp.getParent());
    }
    return this;
}
 
Example 7
Project: VISNode   File: HierarchyMouseDispatcher.java   View Source Code Vote up 5 votes
/**
 * Test the hierarchy between the two components
 * 
 * @param source
 * @param listen
 * @return boolean
 */
private boolean testHierarchy(JComponent source, JComponent listen) {
    if (source == listen) {
        return true;
    }
    if (source.getParent() == null || !(source.getParent() instanceof JComponent)) {
        return false;
    }
    return testHierarchy((JComponent) source.getParent(), listen);
}
 
Example 8
Project: incubator-netbeans   File: PopupManager.java   View Source Code Vote up 5 votes
/** Variation of the method for computing the bounds
 * for the concrete view component. As the component can possibly
 * be placed in a scroll pane it's first necessary
 * to translate the cursor bounds and also translate
 * back the resulting popup bounds.
 * @param popup  popup panel to be displayed
 * @param view component over which the popup is displayed.
 * @param cursorBounds the bounds of the caret or mouse cursor
 *    relative to the upper-left corner of the visible view.
 * @param placement where to place the popup panel according to
 *    the cursor position.
 * @return bounds of popup panel relative to the upper-left corner
 *    of the underlying view component.
 *    <CODE>null</CODE> if there is no place to display popup.
 */
protected static Rectangle computeBounds(JComponent popup,
JComponent view, Rectangle cursorBounds, Placement placement, HorizontalBounds horizontalBounds) {
    
    if (horizontalBounds == null) horizontalBounds = ViewPortBounds;
    
    Rectangle ret;
    Component viewParent = view.getParent();
    
    if (viewParent instanceof JLayeredPane) {
        viewParent = viewParent.getParent();
    }
    
    if (viewParent instanceof JViewport) {
        Rectangle viewBounds = ((JViewport)viewParent).getViewRect();

        Rectangle translatedCursorBounds = (Rectangle)cursorBounds.clone();
        if (placement != FixedPoint) {
            translatedCursorBounds.translate(-viewBounds.x, -viewBounds.y);
        }

        ret = computeBounds(popup, viewBounds.width, viewBounds.height,
            translatedCursorBounds, placement, horizontalBounds);
        
        if (ret != null) { // valid bounds
            ret.translate(viewBounds.x, viewBounds.y);
        }
        
    } else { // not in scroll pane
        ret = computeBounds(popup, view.getWidth(), view.getHeight(),
            cursorBounds, placement);
    }
    
    return ret;
}
 
Example 9
Project: incubator-netbeans   File: CssStylesTC.java   View Source Code Vote up 5 votes
private void setContent(JComponent component) {
    if(component.getParent() == null) {
        //not shown
        removeAll();
        add(component, BorderLayout.CENTER);
        revalidate();
        repaint();
    }
}
 
Example 10
Project: FreeCol   File: TradeRouteInputPanel.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
protected void exportDone(JComponent source, Transferable data,
                          int action) {
    try {
        CargoLabel label = (CargoLabel)data.getTransferData(DefaultTransferHandler.flavor);
        if (source.getParent() instanceof CargoPanel) {
            TradeRouteInputPanel.this.cargoPanel.remove(label);
            int[] indices = TradeRouteInputPanel.this.stopList
                .getSelectedIndices();
            for (int stopIndex : indices) {
                TradeRouteStop stop = TradeRouteInputPanel.this
                    .stopListModel.get(stopIndex);
                List<GoodsType> cargo = new ArrayList<>(stop.getCargo());
                for (int index = 0; index < cargo.size(); index++) {
                    if (cargo.get(index) == label.getType()) {
                        cargo.remove(index);
                        break;
                    }
                }
                stop.setCargo(cargo);
            }
            TradeRouteInputPanel.this.stopList.revalidate();
            TradeRouteInputPanel.this.stopList.repaint();
            TradeRouteInputPanel.this.cargoPanel.revalidate();
            TradeRouteInputPanel.this.cargoPanel.repaint();
        }
    } catch (IOException|UnsupportedFlavorException ex) {
        logger.log(Level.WARNING, "CargoHandler export", ex);
    }
}
 
Example 11
Project: AgentWorkbench   File: TimeModelController.java   View Source Code Vote up 5 votes
/**
 * Returns the current index position of the project window tab.
 * @return the index position of project window tab
 */
private int getIndexPositionOfProjectWindowTab() {
	int indexPosFound = 0;
	if (this.pwt!=null) {
		JComponent component = this.pwt.getJComponentForVisualization();
		if (component.getParent()!=null) {
			JTabbedPane jTabbedPane = (JTabbedPane) component.getParent();	
			indexPosFound = jTabbedPane.indexOfComponent(this.pwt.getJComponentForVisualization());
		}
	}
	return indexPosFound;
}
 
Example 12
Project: JavaGraph   File: ResourceDisplay.java   View Source Code Vote up 5 votes
/** Adjust the info panel by retrieving upper and lower info subpanels from the selected tab. */
protected void buildInfoPanel() {
    JComponent upperInfoPanel = null;
    JComponent lowerInfoPanel = null;
    ResourceTab tab = getSelectedTab();
    if (tab != null) {
        upperInfoPanel = tab.getUpperInfoPanel();
        lowerInfoPanel = tab.getLowerInfoPanel();
    }
    JPanel infoPanel = (JPanel) getInfoPanel();
    String key;
    if (lowerInfoPanel == null || !lowerInfoPanel.isEnabled()) {
        // if we switch from split to single, freeze the divider location
        if (upperInfoPanel != null && upperInfoPanel.getParent() == getSplitInfoPanel()) {
            this.frozenDividerPos = getSplitInfoPanel().getDividerLocation();
        }
        getSingleInfoPanel().removeAll();
        if (upperInfoPanel != null) {
            getSingleInfoPanel().add(upperInfoPanel, BorderLayout.CENTER);
            getSingleInfoPanel().validate();
            getSingleInfoPanel().repaint();
        }
        key = this.SINGLE_INFO_KEY;
    } else {
        JSplitPane splitInfoPanel = getSplitInfoPanel();
        int dividerPos = this.frozenDividerPos;
        this.frozenDividerPos = 0;
        if (dividerPos == 0) {
            dividerPos = splitInfoPanel.getDividerLocation();
        }
        splitInfoPanel.setTopComponent(upperInfoPanel);
        splitInfoPanel.setBottomComponent(lowerInfoPanel);
        splitInfoPanel.setDividerLocation(dividerPos);
        key = this.SPLIT_INFO_KEY;
    }
    ((CardLayout) infoPanel.getLayout()).show(infoPanel, key);
}
 
Example 13
Project: rapidminer   File: ButtonUI.java   View Source Code Vote up 5 votes
@Override
public Dimension getPreferredSize(JComponent c) {
	if (c.getParent() instanceof JToolBar) {
		return new Dimension((int) super.getPreferredSize(c).getWidth() + 6,
				(int) super.getPreferredSize(c).getHeight() + 6);
	} else {
		return new Dimension((int) super.getPreferredSize(c).getWidth() + 10, (int) super.getPreferredSize(c)
				.getHeight() + 6);
	}
}
 
Example 14
Project: rapidminer   File: ToggleButtonUI.java   View Source Code Vote up 5 votes
@Override
public Dimension getPreferredSize(JComponent c) {
	if (c.getParent() instanceof JToolBar) {
		return new Dimension((int) super.getPreferredSize(c).getWidth() + 6,
				(int) super.getPreferredSize(c).getHeight() + 6);
	} else {
		return new Dimension((int) super.getPreferredSize(c).getWidth() + 10, (int) super.getPreferredSize(c)
				.getHeight() + 6);
	}
}
 
Example 15
Project: brModelo   File: Dialogos.java   View Source Code Vote up 5 votes
public static String ShowDlgTexto(JComponent form, String texto) {
    DlgExecutor dlg = new DlgExecutor((Frame) form.getParent(), true);
    dlg.Texto.setText(texto);
    //dlg.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    dlg.setLocationRelativeTo(form);
    dlg.setVisible(true);

    if (dlg.getResultado() == JOptionPane.OK_OPTION) {
        return dlg.Texto.getText();
    }
    return texto;
}
 
Example 16
Project: rapidminer   File: RadioButtonUI.java   View Source Code Vote up 5 votes
@Override
public synchronized void paint(Graphics g, JComponent c) {
	// without this, checkboxes and radio buttons have a fixed bg color instead of using the bg
	// color of the container they are in
	if (c.getParent() != null) {
		c.setBackground(c.getParent().getBackground());
	}
	super.paint(g, c);
}
 
Example 17
Project: AgentWorkbench   File: PlugIn.java   View Source Code Vote up 4 votes
/**
 * This method can be used to remove all custom components
 * for menus and for the toolbar.
 */
private void removeCustomElements() {
	
	// --- Remove custom toolbar/menu elements --------
	for (int i = 0; i < customJComponent.size(); i++) {
		JComponent component = customJComponent.get(i);
		Container container = component.getParent();
		if (container!=null) container.remove(component);
	}
	customJComponent = new Vector<JComponent>();
	
	// --- Remove custom tab elements -----------------
	for (int i = customProjectWindowTab.size()-1; i>-1; i--) {
		ProjectWindowTab pwt = customProjectWindowTab.get(i);
		pwt.remove();
	}
	customProjectWindowTab = new Vector<ProjectWindowTab>();
	
	// --- Remove custom environment types ------------
	for (int i = customEnvironmentTypes.size()-1; i>-1; i--) {
		EnvironmentType envType = customEnvironmentTypes.get(i);
		if (envType.equals(this.project.getEnvironmentModelType())) {
			this.project.setEnvironmentModelName("none");
		}
		project.getEnvironmentsComboBoxModel().removeElement(envType);
		Application.getGlobalInfo().removeEnvironmentType(envType);
	}
	customEnvironmentTypes = new Vector<EnvironmentType>();
	
	// --- Remove custom ontology visualizations ------
	for (int i = customOntologyClassVisualisation.size()-1; i>-1; i--) {
		OntologyClassVisualisation ontoClVis = customOntologyClassVisualisation.get(i);
		OntologyVisualisationConfiguration.unregisterOntologyClassVisualisation(ontoClVis);
	}
	customOntologyClassVisualisation = new Vector<OntologyClassVisualisation>();
	
	// --- Refresh the main window --------------------
	if (Application.getMainWindow()!=null) {
		Application.getMainWindow().validate();
		Application.getMainWindow().repaint();
	}
	
}
 
Example 18
Project: rapidminer   File: RapidLookTools.java   View Source Code Vote up 4 votes
public static boolean isVLToolbarButton(JComponent b) {
	return b.getParent() instanceof VLToolBar;
}
 
Example 19
Project: rapidminer   File: ProgressBarUI.java   View Source Code Vote up 4 votes
@Override
protected void paintDeterminate(Graphics g, JComponent c) {
	boolean compressed = Boolean.parseBoolean(String.valueOf(progressBar
			.getClientProperty(RapidLookTools.PROPERTY_PROGRESSBAR_COMPRESSED)));

	int y = 0;
	int x = 0;
	int w;
	int h;
	if (compressed) {
		x = (int) (c.getWidth() * 0.67);
		w = (int) (c.getWidth() * 0.33);
		y = 3;
		h = c.getHeight() - 6;
	} else {
		w = c.getWidth();
		h = c.getHeight() / 2;
	}

	int amountFull = getAmountFull(progressBar.getInsets(), w, h);

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (c.isOpaque()) {
		if (c.getParent() != null) {
			g2.setColor(c.getParent().getBackground());
		} else {
			g2.setColor(c.getBackground());
		}
		g2.fillRect(x, y, c.getWidth(), c.getHeight());
	}

	g2.setColor(Colors.PROGRESSBAR_BACKGROUND);
	g2.fillRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	g2.setColor(Colors.PROGRESSBAR_BORDER);
	g2.drawRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	Paint gp = new GradientPaint(x, y + 3, Colors.PROGRESSBAR_DETERMINATE_FOREGROUND_GRADIENT_START, x, h - 5,
			Colors.PROGRESSBAR_DETERMINATE_FOREGROUND_GRADIENT_END);
	g2.setPaint(gp);
	g2.fillRoundRect(x + 3, y + 3, amountFull - 5, h - 5, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);

	drawString(g2, w, h, compressed);
}
 
Example 20
Project: rapidminer   File: ProgressBarUI.java   View Source Code Vote up 4 votes
@Override
protected void paintIndeterminate(Graphics g, JComponent c) {
	boolean compressed = Boolean.parseBoolean(String.valueOf(progressBar
			.getClientProperty(RapidLookTools.PROPERTY_PROGRESSBAR_COMPRESSED)));

	int y = 0;
	int x = 0;
	int w;
	int h;
	if (compressed) {
		x = (int) (c.getWidth() * 0.67);
		w = (int) (c.getWidth() * 0.33);
		y = 3;
		h = c.getHeight() - 6;
	} else {
		w = c.getWidth();
		h = c.getHeight() / 2;
	}

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (c.isOpaque()) {
		if (c.getParent() != null) {
			g2.setColor(c.getParent().getBackground());
		} else {
			g2.setColor(c.getBackground());
		}
		g2.fillRect(x, y, c.getWidth(), c.getHeight());
	}

	g2.setColor(Colors.PROGRESSBAR_BACKGROUND);
	g2.fillRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	g2.setColor(Colors.PROGRESSBAR_BORDER);
	g2.drawRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	// make sure we don't draw over the boundaries
	RoundRectangle2D clipRect = new RoundRectangle2D.Double(x + 3, y + 3, w - 5, h - 5,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
	g2.setClip(clipRect);

	for (double xCoord = x + -4 * ANIMATION_BAR_LENGTH + System.currentTimeMillis() * ANIMATION_SPEED
			% (2 * ANIMATION_BAR_LENGTH); xCoord < x + w + 2 * ANIMATION_BAR_LENGTH;) {
		g2.setColor(Colors.PROGRESSBAR_INDETERMINATE_FOREGROUND_1);
		g2.fill(createIntermediateShape(xCoord, ANIMATION_BAR_LENGTH, h));
		xCoord += ANIMATION_BAR_LENGTH;
		g2.setColor(Colors.PROGRESSBAR_INDETERMINATE_FOREGROUND_2);
		g2.fill(createIntermediateShape(xCoord, ANIMATION_BAR_LENGTH, h));
		xCoord += ANIMATION_BAR_LENGTH;
	}
	g2.setClip(null);

	drawString(g2, w, h, compressed);
}