@Override public void scrollRectToVisible(Rectangle contentRect) { Container parent; int dx = getX(), dy = getY(); for (parent = getParent(); !(parent == null) && !(parent instanceof JComponent) && !(parent instanceof CellRendererPane); parent = parent.getParent()) { Rectangle bounds = parent.getBounds(); dx += bounds.x; dy += bounds.y; } if (!(parent == null) && !(parent instanceof CellRendererPane)) { contentRect.x += dx; contentRect.y += dy; ((JComponent) parent).scrollRectToVisible(contentRect); contentRect.x -= dx; contentRect.y -= dy; } }
/** * Constructs a new graphics export canvas. */ public mxGraphicsCanvas2D(Graphics2D g) { setGraphics(g); state.g = g; // Initializes the cell renderer pane for drawing HTML markup try { rendererPane = new CellRendererPane(); } catch (Exception e) { // ignore } }
/** * Creates a new button. * * @param cb the combo that the button is used for (<code>null</code> not * permitted). * @param i the icon displayed on the button. * @param onlyIcon a flag that specifies whether the button displays only an * icon, or text as well. * @param pane the rendering pane. * @param list the list. */ public MetalComboBoxButton(JComboBox cb, Icon i, boolean onlyIcon, CellRendererPane pane, JList list) { super(); if (cb == null) throw new NullPointerException("Null 'cb' argument"); comboBox = cb; comboIcon = i; iconOnly = onlyIcon; listBox = list; rendererPane = pane; setRolloverEnabled(false); setEnabled(comboBox.isEnabled()); setFocusable(comboBox.isEnabled()); }
private BufferedImage getScreenshot(Container panel) { Dimension size = new Dimension((int) panel.getPreferredSize().getWidth()+50, (int) panel.getPreferredSize().getHeight()+10); panel.setSize(size); this.layoutComponent(panel); BufferedImage img = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_RGB); //Remove buttons panel panel.getComponent(2).setVisible(false); CellRendererPane crp = new CellRendererPane(); crp.add(panel); crp.paintComponent(img.createGraphics(), panel, crp, panel.getBounds()); //Re-add buttons panel panel.getComponent(2).setVisible(true); return img; }
PlasticComboBoxButton(JComboBox comboBox, Icon comboIcon, boolean iconOnly, CellRendererPane rendererPane, JList listBox) /* 36: */ { /* 37: 80 */ super(""); /* 38: 81 */ setModel(new DefaultButtonModel() /* 39: */ { /* 40: */ public void setArmed(boolean armed) /* 41: */ { /* 42: 83 */ super.setArmed((isPressed()) || (armed)); /* 43: */ } /* 44: 85 */ }); /* 45: 86 */ this.comboBox = comboBox; /* 46: 87 */ this.comboIcon = comboIcon; /* 47: 88 */ this.iconOnly = iconOnly; /* 48: 89 */ this.rendererPane = rendererPane; /* 49: 90 */ this.listBox = listBox; /* 50: 91 */ setEnabled(comboBox.isEnabled()); /* 51: 92 */ setFocusable(false); /* 52: 93 */ setRequestFocusEnabled(comboBox.isEnabled()); /* 53: 94 */ setBorder(UIManager.getBorder("ComboBox.arrowButtonBorder")); /* 54: 95 */ setMargin(new Insets(0, 2, 0, 2)); /* 55: 96 */ this.borderPaintsFocus = UIManager.getBoolean("ComboBox.borderPaintsFocus"); /* 56: */ }
protected CellRendererPane createCellRendererPane() { return new CellRendererPane() { public void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h, boolean shouldValidate) { w = p.getWidth() - x; Insets m = p.getInsets(); if(m != null) { w -= m.right; } super.paintComponent(g, c, p, x, y, w, h, shouldValidate); } }; }
/** * Initializes <code>this.list</code> by calling <code>installDefaults()</code>, * <code>installListeners()</code>, and <code>installKeyboardActions()</code> * in order. * * @see #installDefaults * @see #installListeners * @see #installKeyboardActions */ public void installUI(JComponent c) { list = (JXList)c; layoutOrientation = list.getLayoutOrientation(); rendererPane = new CellRendererPane(); list.add(rendererPane); columnCount = 1; updateLayoutStateNeeded = modelChanged; isLeftToRight = list.getComponentOrientation().isLeftToRight(); installDefaults(); installListeners(); installKeyboardActions(); installSortUI(); }
/** * Issue #77-swingx: support year-wise navigation. * Alleviate the problem by allowing custom calendar headers. * * Here: test that the monthViewUI uses the custom header if available. */ @Test public void testZoomableCustomHeader() { UIManager.put(CalendarHeaderHandler.uiControllerID, "org.jdesktop.swingx.plaf.basic.SpinningCalendarHeaderHandler"); JXMonthView monthView = new JXMonthView(); monthView.setZoomable(true); // digging into internals Container header = (Container) monthView.getComponent(0); if (header instanceof CellRendererPane) { header = (Container) monthView.getComponent(1); } try { assertTrue("expected SpinningCalendarHeader but was " + header.getClass(), header instanceof SpinningCalendarHeaderHandler.SpinningCalendarHeader); } finally { UIManager.put(CalendarHeaderHandler.uiControllerID, null); } }
@Override public void installUI( JComponent c ) { if ( !( c instanceof JBroTableHeader ) ) throw new IllegalArgumentException( "Not a groupable header: " + c ); JBroTableHeader header = ( JBroTableHeader )c; this.header = header; int levelsCnt = table.getData() == null ? 0 : table.getData().getFieldGroups().size(); delegates = new ArrayList< ComponentUI >( levelsCnt ); headers = new ArrayList< JTableHeader >( levelsCnt ); rendererPanes = new ArrayList< CellRendererPane >( levelsCnt ); if ( heightsCache == null || heightsCache.length < levelsCnt ) heightsCache = new int[ levelsCnt ]; updateModel(); super.installUI( c ); SwingUtilities.updateComponentTreeUI( header ); for ( JTableHeader delegateHeader : headers ) SwingUtilities.updateComponentTreeUI( delegateHeader ); }
/** * Creates a custom {@link CellRendererPane} that sets the renderer * component to be non-opqaque if the associated row isn't selected. This * custom {@code CellRendererPane} is needed because a table UI delegate has * no prepare renderer like {@link JTable} has. */ protected CellRendererPane createCustomCellRendererPane() { return new CellRendererPane() { @Override public void paintComponent(Graphics graphics, Component component, Container container, int x, int y, int w, int h, boolean shouldValidate) { int rowAtPoint = table.rowAtPoint(new Point(x, y)); boolean isSelected = table.isRowSelected(rowAtPoint); if (component instanceof JComponent) { JComponent jComponent = (JComponent) component; jComponent.setOpaque(isSelected); jComponent.setBorder(isSelected ? getSelectedRowBorder() : getRowBorder()); jComponent.setBackground(isSelected ? table .getSelectionBackground() : TRANSPARENT_COLOR); } super.paintComponent(graphics, component, container, x, y, w, h, shouldValidate); } }; }
public AccessibleText getAccessibleText() { if (pane == null) { //Cheat just a bit here - will do for now - the text is //there, more or less where it should be, and a screen //reader should be able to find it; exact bounds don't //make much difference pane = new JEditorPane(); pane.setBounds (panel.getBounds()); pane.getAccessibleContext().getAccessibleText(); pane.setFont (panel.getFont()); CellRendererPane cell = new CellRendererPane(); cell.add (pane); } pane.setText(getText()); pane.selectAll(); pane.validate(); return pane.getAccessibleContext().getAccessibleText(); }
public void testInstallUninstallComponents() throws Exception { ui.comboBox = comboBox; ui.popup = new BasicComboPopup(comboBox); ui.uninstallComponents(); assertEquals(0, ui.comboBox.getComponentCount()); assertNull(ui.arrowButton); assertNull(ui.editor); ui.installComponents(); assertEquals(2, ui.comboBox.getComponentCount()); assertTrue(ui.comboBox.getComponent(0) instanceof BasicArrowButton); assertTrue(ui.comboBox.getComponent(1) instanceof CellRendererPane); assertNotNull(ui.arrowButton); assertNull(ui.editor); ui.comboBox.add(new JLabel()); ui.uninstallComponents(); assertEquals(0, ui.comboBox.getComponentCount()); assertNull(ui.arrowButton); assertNull(ui.editor); comboBox.setEditable(true); ui.installComponents(); assertNotNull(ui.arrowButton); assertNotNull(ui.editor); }
protected void paintTable(Graphics g) { treeTableCellRenderer.prepareForTable(g); Graphics cg = g.create(0, 0, treeTable.getWidth(), treeTable.getHeight()); try { table.paint(cg); } finally { cg.dispose(); } // JTable doesn't paint anything for the editing cell, // so painting the background color is placed here if (table.isEditing()) { int col = table.getEditingColumn(); int row = table.getEditingRow(); boolean sel = treeTableCellRenderer.isSelected( tree.isRowSelected(row) && table.isColumnSelected(col)); TreeTableCellRenderer r = treeTable.getCellRenderer(row, col); Component c = r.getTreeTableCellRendererComponent( treeTable, null, sel, false, row, col); // TODO, create CellRendererPane for TreeTable, for use by the focus renderer too. CellRendererPane rp = (CellRendererPane)table.getComponent(0); Rectangle cell = table.getCellRect(row, col, true); rp.paintComponent(g, c, table, cell.x, cell.y, cell.width, cell.height, true); rp.removeAll(); } }
@Override public void installUI(JComponent component) { grid = (JGrid) component; rendererPane = new CellRendererPane(); grid.add(rendererPane); // gridHeader = (JGrid) component; component.setOpaque(false); LookAndFeel.installColorsAndFont( component, "TableHeader.background", "TableHeader.foreground", "TableHeader.font"); installDefaults(); installListeners(); installKeyboardActions(); }
/** Creates a new instance of DefaultOutlineTreeCellRenderer */ public DefaultOutlineCellRenderer() { theCheckBox = createCheckBox(); // In order to paint the check-box correctly, following condition must be true: // SwingUtilities.getAncestorOfClass(CellRendererPane.class, theCheckBox) != null // (See e.g.: paintSkin() method in com/sun/java/swing/plaf/windows/XPStyle.java) fakeCellRendererPane = new CellRendererPane(); fakeCellRendererPane.add(theCheckBox); }
/** * Constructs a new graphics canvas for the given graphics object. */ public mxGraphics2DCanvas(Graphics2D g) { this.g = g; // Initializes the cell renderer pane for drawing HTML markup try { rendererPane = new CellRendererPane(); } catch (Exception e) { // ignore } }
@Override public void run() { Dimension size = new Dimension(575, 275); for (String lookAndFeelClassName : LOOK_AND_FEELS) { ExampleRunner.useLookAndFeel(lookAndFeelClassName); FontChooser fontChooser = new FontChooser(new Font("Helvetica", Font.PLAIN, 24)); fontChooser.setBorder(new EmptyBorder(10, 10, 10, 10)); fontChooser.setSize(size); layoutComponent(fontChooser); CellRendererPane rendererPane = new CellRendererPane(); rendererPane.add(fontChooser); BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = image.createGraphics(); rendererPane.paintComponent(graphics, fontChooser, rendererPane, fontChooser.getBounds()); String pathname = createFileName(lookAndFeelClassName); try { ImageIO.write(image, "png", new File(pathname)); } catch (IOException e) { throw new RuntimeException(e); } } }
public void installUI(JComponent comp) { table = (JTable) comp; rendererPane = new CellRendererPane(); table.add(rendererPane); installDefaults(); installKeyboardActions(); installListeners(); }
public void installUI(JComponent c) { header = (JTableHeader) c; rendererPane = new CellRendererPane(); installDefaults(); installKeyboardActions(); installListeners(); }
void addTo(Component component) { if (component == null || component instanceof CellRendererPane) { return; } if (component instanceof Container) { addTo((Container)component); } MnemonicWrapper.getWrapper(component); }
private Component findActualComponent(Component c) { Component actual = SwingUtilities.getAncestorOfClass(CellRendererPane.class, c); if((actual != null) && (actual.getParent() != null)) { c = findActualComponent(actual.getParent()); } return c; }
/** * {@inheritDoc} */ @Override public Dimension getPreferredSize() { if (getComponentCount() == 1 && getComponent(0) instanceof CellRendererPane) { return BasicGraphicsUtils.getPreferredButtonSize(fgStamp, getIconTextGap()); } return super.getPreferredSize(); }
/** * Creates and installs the renderingHandler and infrastructure to use it. */ protected void installRenderingHandler() { setRenderingHandler(createRenderingHandler()); if (getRenderingHandler() != null) { rendererPane = new CellRendererPane(); monthView.add(rendererPane); } }
/** * Issue #1046-swingx: month title not updated when traversing months * (programatically or by navigating in monthView) */ @Test public void testZoomableAddsCalendarHeader() { JXMonthView monthView = new JXMonthView(); monthView.setZoomable(true); // digging into internals Container header = (Container) monthView.getComponent(0); if (header instanceof CellRendererPane) { header = (Container) monthView.getComponent(1); } assertTrue("expected BasicCalendarHeader but was " + header.getClass(), header instanceof BasicCalendarHeaderHandler.BasicCalendarHeader); }
/** * Issue #1046-swingx: month title not updated when traversing months * (programatically or by navigating in monthView) */ @Test public void testZoomableUpdateUIKeepsCalendarHeader() { JXMonthView monthView = new JXMonthView(); monthView.setZoomable(true); monthView.updateUI(); // digging into internals Component header = monthView.getComponent(0); if (header instanceof CellRendererPane) { header = (Container) monthView.getComponent(1); } assertTrue("expected BasicCalendarHeader but was " + header.getClass(), header instanceof BasicCalendarHeaderHandler.BasicCalendarHeader); }