private Dimension calcTypeListPreferredSize(final List<ModuleBuilder> allModuleTypes) { int width = 0; int height = 0; final FontMetrics fontMetrics = myTypesList.getFontMetrics(myTypesList.getFont()); final int fontHeight = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent(); for (final ModuleBuilder type : allModuleTypes) { final Icon icon = type.getBigIcon(); final int iconHeight = icon != null ? icon.getIconHeight() : 0; final int iconWidth = icon != null ? icon.getIconWidth() : 0; height += Math.max(iconHeight, fontHeight) + 6; width = Math.max(width, iconWidth + fontMetrics.stringWidth(type.getPresentableName()) + 10); } return new Dimension(width, height); }
/** * Paints the image. * * @param g the rendering surface to use * @param a the allocated region to render into * @see View#paint */ public void paint(Graphics g, Shape a) { Color oldColor = g.getColor(); fBounds = a.getBounds(); int border = getBorder(); int x = fBounds.x + border + getSpace(X_AXIS); int y = fBounds.y + border + getSpace(Y_AXIS); int width = fWidth; int height = fHeight; int sel = getSelectionState(); // Make sure my Component is in the right place: /* if( fComponent == null ) { fComponent = new Component() { }; fComponent.addMouseListener(this); fComponent.addMouseMotionListener(this); fComponent.setCursor(Cursor.getDefaultCursor()); // use arrow cursor fContainer.add(fComponent); } fComponent.setBounds(x,y,width,height); */ // If no pixels yet, draw gray outline and icon: if (!hasPixels(this)) { g.setColor(Color.lightGray); g.drawRect(x, y, width - 1, height - 1); g.setColor(oldColor); loadIcons(); Icon icon = fImage == null ? sMissingImageIcon : sPendingImageIcon; if (icon != null) icon.paintIcon(getContainer(), g, x, y); } // Draw image: if (fImage != null) { g.drawImage(fImage, x, y, width, height, this); // Use the following instead of g.drawImage when // BufferedImageGraphics2D.setXORMode is fixed (4158822). // Use Xor mode when selected/highlighted. // ! Could darken image instead, but it would be more expensive. /* if( sel > 0 ) g.setXORMode(Color.white); g.drawImage(fImage,x, y, width,height,this); if( sel > 0 ) g.setPaintMode(); */ } // If selected exactly, we need a black border & grow-box: Color bc = getBorderColor(); if (sel == 2) { // Make sure there's room for a border: int delta = 2 - border; if (delta > 0) { x += delta; y += delta; width -= delta << 1; height -= delta << 1; border = 2; } bc = null; g.setColor(Color.black); // Draw grow box: g.fillRect(x + width - 5, y + height - 5, 5, 5); } // Draw border: if (border > 0) { if (bc != null) g.setColor(bc); // Draw a thick rectangle: for (int i = 1; i <= border; i++) g.drawRect(x - i, y - i, width - 1 + i + i, height - 1 + i + i); g.setColor(oldColor); } }