private TLabel getStatusLabel() { getStatus(); if ((_statusIcon == null) || (_statusIcon.getIconWidth() > 0) && (_statusIcon.getIconHeight() > 0)) { _status.setIcon(_statusIcon); _status.setToolTipText(_statusText); } return _status; }
/** * Returns an ImageIcon for the given file, resized according to the given dimensions. If the * original file contains a pictures smaller than these width and height, the picture is returned * as is (nor resized). * * @param pictureFile The file, containing a picture, from which the user wants to extract a * static picture. * @param maxWidth The maximum allowed width for the static picture to generate. * @param maxHeight The maximum allowed height for the static picture to generate. * @return The created static picture, or null if the file is null. */ public static ImageIcon getImageIcon(File pictureFile, int maxWidth, int maxHeight) { ImageIcon thumbnail = null; if (pictureFile != null) { ImageIcon tmpIcon = new ImageIcon(pictureFile.getPath()); if (tmpIcon != null) { double scaleWidth = ((double) maxWidth) / tmpIcon.getIconWidth(); double scaleHeight = ((double) maxHeight) / tmpIcon.getIconHeight(); double scale = Math.min(scaleWidth, scaleHeight); if (scale < 1) { thumbnail = new ImageIcon( tmpIcon .getImage() .getScaledInstance( (int) (scale * tmpIcon.getIconWidth()), (int) (scale * tmpIcon.getIconHeight()), Image.SCALE_FAST)); } else { // no need to miniaturize thumbnail = tmpIcon; } } } return thumbnail; }
/** Load the thumb and arrow images. */ private void loadThumbArrowImage() { IconManager icons = IconManager.getInstance(); ImageIcon img = icons.getImageIcon(IconManager.THUMB); thumbWidth = img.getIconWidth(); thumbHeight = img.getIconHeight(); thumbImage = img.getImage(); img = icons.getImageIcon(IconManager.THUMB_DISABLED); disabledThumbImage = img.getImage(); img = icons.getImageIcon(IconManager.UP_ARROW_DISABLED_10); arrowWidth = img.getIconWidth(); arrowHeight = img.getIconHeight(); minArrowHeight = arrowHeight; minArrowWidth = arrowWidth; upArrowDisabledImage = img.getImage(); img = icons.getImageIcon(IconManager.DOWN_ARROW_DISABLED_10); downArrowDisabledImage = img.getImage(); img = icons.getImageIcon(IconManager.LEFT_ARROW_DISABLED_10); leftArrowDisabledImage = img.getImage(); img = icons.getImageIcon(IconManager.RIGHT_ARROW_DISABLED_10); rightArrowDisabledImage = img.getImage(); img = icons.getImageIcon(IconManager.UP_ARROW_10); upArrowImage = img.getImage(); img = icons.getImageIcon(IconManager.DOWN_ARROW_10); downArrowImage = img.getImage(); img = icons.getImageIcon(IconManager.LEFT_ARROW_10); leftArrowImage = img.getImage(); img = icons.getImageIcon(IconManager.RIGHT_ARROW_10); rightArrowImage = img.getImage(); }
public ImageIcon getImageIcon() { if (mImageIcon == null) { mImageIcon = new ImageIcon(mPath); /** If the image is too big, scale it down to max pixel size squared */ if (mImageIcon.getIconWidth() > sMAX_IMAGE_DIMENSION || mImageIcon.getIconHeight() > sMAX_IMAGE_DIMENSION) { /** * getScaled instance will correct any negative value to the correct value, maintaining * original aspect ratio. So, we only scale the larger value, and allow the image class to * determine the correct value for the other measurement */ int height = -1; int width = -1; /** Use the larger width or height value to determine the scaling factor */ if (mImageIcon.getIconHeight() > mImageIcon.getIconWidth()) { height = sMAX_IMAGE_DIMENSION; } else { width = sMAX_IMAGE_DIMENSION; } mImageIcon = new ImageIcon( mImageIcon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH)); } } return mImageIcon; }
public void fillWordList() { sf = new ScrollField(new Dimension(250, 300)); sf.setBounds(20, 250, 250, 300); ResultSet result = DatabaseController.getInstance() .runQuery("SELECT woord FROM woordenboek where status='Pending'"); try { // Onderstaande if(); word al in logics afgehandeld // if(result.next()==false) // { // this.getGui().showMessage("No words in pending list"); // } result.beforeFirst(); while (result.next()) { // System.out.println(result.next()); // create word panel ColoredRectangle wordPanel = new ColoredRectangle(new Rectangle(sf.getWidth(), 50), Color.gray); // create word label JLabel wordLabel = new JLabel(result.getString("woord")); wordLabel.setForeground(Color.white); wordLabel.setBounds(0, 0, 550, 50); wordLabel.setFont(FontController.getInstance().getFont("segoeuil")); wordLabel.setFont(new Font(wordLabel.getFont().getName(), Font.BOLD, 20)); // add label to panel wordPanel.add(wordLabel); // create edit buttonimage ImageIcon editLogo = new ImageIcon(getClass().getResource("/Assets/Images/edit.png")); JButton editButton = new JButton(editLogo); editButton.setBackground(Color.gray); editButton.setBounds( wordPanel.getWidth() - (editLogo.getIconWidth() + 10), wordPanel.getHeight() - 15 - editLogo.getIconHeight(), editLogo.getIconWidth() + 3, editLogo.getIconHeight() + 3); editButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); editButton.setName("btnWordOutList#" + result.getString("woord")); // addclickevent editButton.addActionListener(logics); // add editlabel to wordpanel wordPanel.add(editButton); wordPanel.setLayout(null); // add wordpanel to scollfield sf.addElement(wordPanel); } } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } this.add(sf); }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (list instanceof CheckList) { // calculate the max width of the logo int maxWidth = 0; for (int i = 0; i < list.getModel().getSize(); i++) { Object obj = list.getModel().getElementAt(i); if (obj instanceof MediaScraper) { MediaScraper ms = (MediaScraper) obj; ImageIcon logo = getIcon(ms.getLogoURL()); maxWidth = Math.max(maxWidth, logo.getIconWidth()); } } CheckList cbl = (CheckList) list; ListCheckModel model = cbl.getModel(); boolean checked = model.isChecked(value); boolean locked = model.isLocked(value); setSelected(checked); if (locked || cbl.isEnabled() == false) { setEnabled(false); } else { setEnabled(true); } if (getHighlight().equals(Highlight.MOUSE_OVER_AND_CHECKED_ITEMS) && (checked || isSelected)) { panel.setBackground(selectionBackground); panel.setForeground(selectionForeground); } else if (getHighlight().equals(Highlight.MOUSE_OVER) && isSelected) { panel.setBackground(selectionBackground); panel.setForeground(selectionForeground); } else if (getHighlight().equals(Highlight.CHECKED_ITEMS) && checked) { panel.setBackground(selectionBackground); panel.setForeground(selectionForeground); } else { panel.setBackground(background); panel.setForeground(foreground); } if (value instanceof MediaScraper) { MediaScraper scraper = (MediaScraper) value; int currentWidth = 0; ImageIcon logo = getIcon(scraper.getLogoURL()); if (logo != null) { currentWidth = logo.getIconWidth(); } label.setIcon(logo); label.setIconTextGap(maxWidth + 4 - currentWidth); // 4 = default iconTextGap } else { label.setIcon(null); label.setIconTextGap(4); // 4 = default iconTextGap } } label.setText(getText(value)); return panel; }
public ScrollingLinesPanel(ImageIcon background, List<String> lines) { super(); this.background = background; this.lines = lines; yPos = background.getIconHeight(); xPos = (int) ((float) background.getIconWidth() / 2.0f); setOpaque(false); setPreferredSize(new Dimension(background.getIconWidth(), background.getIconHeight())); }
public void setBackground(ImageIcon icon) { JLabel background = new JLabel(icon); background.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight()); JPanel imagePanel = (JPanel) this.getContentPane(); imagePanel.setOpaque(false); this.getLayeredPane().setLayout(null); this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(icon.getIconWidth(), icon.getIconHeight()); }
public ImageIcon scaleImage(ImageIcon icon) { if ((icon.getIconWidth() > 195 && icon.getIconHeight() > 190)) { ImageIcon imageScale = new ImageIcon( icon.getImage() .getScaledInstance( icon.getIconWidth() / 2, icon.getIconHeight() / 2, Image.SCALE_DEFAULT)); return this.scaleImage(imageScale); } else { return icon; } }
private void paintSprites(List<Sprite> sprites) { if (sprites != null) { for (int i = 0; i < sprites.size(); i++) { // get all sprites with getresource URL imagePath = this.getClass().getResource(sprites.get(i).getImageName().toString()); ImageIcon icon = new ImageIcon(imagePath); JLabel picLabel = new JLabel(icon); picLabel.setBounds( sprites.get(i).getX(), sprites.get(i).getY(), icon.getIconWidth(), icon.getIconHeight()); this.add(picLabel); } ImageIcon bgImageIcon = new ImageIcon(this.getClass().getResource(controller.getGameModel().getBkgURL())); Image reImage = bgImageIcon.getImage(); reImage = reImage.getScaledInstance( Dimensions.GAME_MAKER_RIGHT_PANEL_WIDTH, Dimensions.GAME_MAKER_RIGHT_PANEL_HEIGHT, Image.SCALE_SMOOTH); bgImageIcon = new ImageIcon(reImage); JLabel bkgImageLabel = new JLabel(bgImageIcon); bkgImageLabel.setBounds( 0, Dimensions.GAME_MAKER_RIGHT_PANEL_Y, Dimensions.GAME_MAKER_RIGHT_PANEL_WIDTH, Dimensions.GAME_MAKER_RIGHT_PANEL_HEIGHT); this.add(bkgImageLabel); } }
protected final void doActionPerformed(ActionEvent evt) { try { ApplicationDiagram diag = (ApplicationDiagram) (ApplicationContext.getFocusManager().getFocusObject()); Point clickPosition = getDiagramLocation(evt); if (clickPosition == null) clickPosition = GraphicUtil.rectangleGetCenter(diag.getMainView().getViewRect()); java.awt.Image image = SRSystemClipboard.getClipboardImage(); if (image == null) return; DbObject diagGo = diag.getDiagramGO(); Db db = diagGo.getDb(); ImageIcon icon = new ImageIcon(image); int imageHeigth = icon.getIconHeight(); int imageWidth = icon.getIconWidth(); db.beginTrans(Db.WRITE_TRANS, LocaleMgr.action.getString("pasteDiagramImage")); DbObject imageGo = diagGo.createComponent(DbGraphic.fImageGoDiagramImage.getMetaClass()); imageGo.set(DbGraphic.fImageGoDiagramImage, image); imageGo.set( DbGraphic.fGraphicalObjectRectangle, new Rectangle( clickPosition.x - (imageWidth / 2), clickPosition.y - (imageHeigth / 2), imageWidth, imageHeigth)); db.commitTrans(); } catch (Exception e) { org.modelsphere.jack.util.ExceptionHandler.processUncatchedException( ApplicationContext.getDefaultMainFrame(), e); } }
public Player(Point2D p) { super(p); direction = new Vector2D(0, -1); rotation = Rotation.NONE; double rotationSpeed = 0.17; sin = Math.sin(rotationSpeed); cos = Math.cos(rotationSpeed); boostingImage = ImageManager.getImage("boosting.png").getImage(); ImageIcon icon = ImageManager.getImage("player.png"); rectangle = new Rectangle(icon.getIconWidth(), icon.getIconHeight()); rectangle.setLocation(p.getPoint()); image = icon.getImage(); shields = 255; weaponIndex = 0; weapons = new ArrayList<Weapon>(); weapons.add(new SMP9(this)); weapons.add(new X2Vulcan(this)); weapons.add(new EM12Carbine(this)); weapons.add(new Stinger2(this)); weapons.add(new ALS22(this)); weapons.add(new Solaris(this)); weapon = weapons.get(weaponIndex); autoPilot = new AutoPilot(this); }
protected void doOutputImage(ImageField image) { if (image == null || image.getImageURL() == null) return; outputCellStart(image); ImageIcon icon = image.getImageIcon(); // For width and height String url = image.getImageURL().toString(); if (url.startsWith("file:")) url = url.substring(5); // Make an alt attribute from the URL String alt = url; int pos = alt.lastIndexOf("/"); if (pos != -1) alt = alt.substring(pos + 1); out.print( "<img src=\"" + StringUtils.escapeHTML(url) + "\" alt=\"" + StringUtils.escapeHTML(alt) + "\" width=\"" + icon.getIconWidth() + "\" height=\"" + icon.getIconHeight() + "\">"); outputCellEnd(); }
/** * Construct a new splash * * @param parent parent frame * @param img image to use for splash * @param timeout time to wait for splash to disapper * @param accesoryComponent accesory component */ public SplashWindow(JFrame parent, Image img, int timeout, JComponent accessoryComponent) { super(parent); // ImageIcon image = new ImageIcon(img); int w = image.getIconWidth() + 5; int h = image.getIconHeight() + 5; // Main panel mainPanel = new JPanel(new BorderLayout()); mainPanel.setOpaque(false); // Accesory component (if specified) if (accessoryComponent != null) { mainPanel.add(accessoryComponent, BorderLayout.SOUTH); // Image part } JLabel p = new JLabel(image); p.setBorder(null); p.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { hide(); } }); mainPanel.add(p, BorderLayout.CENTER); // This panel getContentPane().setLayout(new BorderLayout()); getContentPane().add(mainPanel); // Timeout after specified time timer = new Timer(0, null); timer.setRepeats(false); timer.setInitialDelay(timeout); // Centre the splash pack(); positionComponent(SwingConstants.CENTER, this); }
/** * Scale image to the given percentage. Caller chooses whether enclosing window is to grow with * the resize, or not. * * @param targetPercentage Desired final percentage of image's original size. * @param expandWindow If true then the surrounding window grows/shrinks with the * enlargement/reduction */ public void percentScaleImage(int targetPercentage, boolean expandWindow) { Image img = _fullSizeImgIcon.getImage(); ImageIcon imgIcon = new ImageIcon(img); int width = imgIcon.getIconWidth(); int newWidth = new Double(width * targetPercentage / 100f).intValue(); imgIcon.setImage(getScaledImage(imgIcon, newWidth)); _panel.remove(_label); _label = new JLabel(imgIcon); _panel.add(_label); if (expandWindow) pack(); else validate(); setTitle( _titleBarStartTxt + ": " + targetPercentage + "% of " + _fullSizeImgIcon.getImage().getWidth(null) + "x" + _fullSizeImgIcon.getImage().getHeight(null) + " (" + imgIcon.getImage().getWidth(null) + "x" + imgIcon.getImage().getHeight(null) + ")."); }
private JLabel getBackGround() { final ImageIcon boardImage = ImageUtils.createImageIcon("/com/bogdan/ui/resources/board.png"); JLabel backGroundLabel = new JLabel(boardImage); backGroundLabel.setOpaque(true); backGroundLabel.setBounds(0, 0, boardImage.getIconWidth(), boardImage.getIconHeight()); return backGroundLabel; }
@Override public int getIconWidth() { if (imageIcon != null) { return imageIcon.getIconWidth(); } else { return 0; } }
public boolean hit(Point point) { if (x < point.x && point.x < x + enlargeImage.getIconWidth()) { if (y < point.y && point.y < y + enlargeImage.getIconHeight()) { return true; } } return false; }
public static ImageIcon getHalfSizedIcon(String key) { ImageIcon icon = getIcon(key); Image image = icon.getImage(); Image half = image.getScaledInstance( icon.getIconWidth() / 2, icon.getIconHeight() / 2, Image.SCALE_DEFAULT); return new ImageIcon(half); }
public Player(double x) { hp = 100; pX = x; playerTex = new ImageIcon("TEXTURE/stickman.png"); pY = Constants.GROUND - playerTex.getIconHeight(); pRect = new Rectangle2D.Double(x + playerTex.getIconWidth() / 2, pY, 1, playerTex.getIconHeight()); }
public void setImage(String fileName) { this.fileName = fileName; image = Toolkit.getDefaultToolkit().createImage("img\\" + fileName); imageIcon = new ImageIcon(image); imageIcon.setImageObserver(imgLabel); imgLabel.setIcon(imageIcon); imgLabel.setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight()); }
/** * Adds a new label placed in the Arraylist misses and shows it. * * @param x = coordinates * @param y = coordinates */ private void showMiss(int x, int y) { ImageIcon image = new ImageIcon("img/miss.png"); misses.add(new JLabel(image)); misses.get(misses.size() - 1).setBounds(x, y, image.getIconWidth(), image.getIconHeight()); misses.get(misses.size() - 1).setVisible(true); layeredPane.add(misses.get(misses.size() - 1), new Integer(4)); if (dBg) System.out.println("Miss indicator shown at x: " + x + " y: " + y); }
public SizeButton(SlippyMapBBoxChooser slippyMapBBoxChooser) { this.slippyMapBBoxChooser = slippyMapBBoxChooser; enlargeImage = ImageProvider.get("view-fullscreen"); shrinkImage = ImageProvider.get("view-fullscreen-revert"); setPreferredSize(new Dimension(enlargeImage.getIconWidth(), enlargeImage.getIconHeight())); addMouseListener(mouseListener); setToolTipText(tr("Enlarge")); }
private void updateImages() { mainIcon.setIcon(model.getCharacterToken().getIcon()); if (model.getCharacter().getGameObject().hasThisAttribute(CharacterInfoCard.NO_INVERT_ICON)) { ImageIcon icon = model.getCharacter().getFullSizedIcon(); BufferedImage bi = new BufferedImage( icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics big = bi.getGraphics(); big.setColor(Color.black); big.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight()); big.drawImage(icon.getImage(), 0, 0, null); invertedIcon.setIcon(new ImageIcon(bi)); } else { invertedIcon.setIcon(getInvertedIcon()); } repaint(); }
public boolean setMapBackground(String image) { if (image == null) { mapImage = null; mapName = null; return true; } ImageIcon ii = new ImageIcon(image); if (ii.getIconWidth() <= 0 || ii.getIconHeight() <= 0) { log.warning("could not find image '" + image + '\''); return false; } mapImage = ii; mapName = image; setPreferredSize(new Dimension(ii.getIconWidth(), ii.getIconHeight())); repaint(); return true; }
@Override public void paintComponent(final Graphics g) { super.paintComponent(g); // draw entire component white g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); // yellow circle g.setColor(Color.yellow); g.fillOval(0, 0, 240, 240); // magenta circle g.setColor(Color.magenta); g.fillOval(160, 160, 240, 240); // paint the icon below blue sqaure int w = java2sLogo.getIconWidth(); int h = java2sLogo.getIconHeight(); java2sLogo.paintIcon(this, g, 280 - (w / 2), 120 - (h / 2)); // paint the icon below red sqaure java2sLogo.paintIcon(this, g, 120 - (w / 2), 280 - (h / 2)); // transparent red square g.setColor(m_tRed); g.fillRect(60, 220, 120, 120); // transparent green circle g.setColor(m_tGreen); g.fillOval(140, 140, 120, 120); // transparent blue square g.setColor(m_tBlue); g.fillRect(220, 60, 120, 120); g.setColor(Color.black); g.setFont(monoFont); FontMetrics fm = g.getFontMetrics(); w = fm.stringWidth("Java Source"); h = fm.getAscent(); g.drawString("Java Source", 120 - (w / 2), 120 + (h / 4)); g.setFont(sanSerifFont); fm = g.getFontMetrics(); w = fm.stringWidth("and"); h = fm.getAscent(); g.drawString("and", 200 - (w / 2), 200 + (h / 4)); g.setFont(serifFont); fm = g.getFontMetrics(); w = fm.stringWidth("Support."); h = fm.getAscent(); g.drawString("Support.", 280 - (w / 2), 280 + (h / 4)); }
private static java.awt.image.BufferedImage convertToBufferedImage(ImageIcon icon) { java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage( icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); // paint the Icon to the BufferedImage. icon.paintIcon(null, g, 0, 0); g.dispose(); return bi; }
public static ImageIcon resizePic(String iconLoc, int width, int height) { ImageIcon resizedImage = new ImageIcon(iconLoc); if (resizedImage.getIconHeight() > height) resizedImage = new ImageIcon(resizedImage.getImage().getScaledInstance(-1, height, Image.SCALE_SMOOTH)); if (resizedImage.getIconWidth() > width) resizedImage = new ImageIcon(resizedImage.getImage().getScaledInstance(width, -1, Image.SCALE_SMOOTH)); return resizedImage; }
/** * Gets an ImageIcon. * * @return the icon */ public ImageIcon getIcon() { if (icon == null && isAnImage) { icon = new ImageIcon(getURL()); if (icon.getIconWidth() < 1) { icon = null; isAnImage = false; } } return icon; }
@Test public void testRedimensionnerImage() { ImageIcon imageBar = new ImageIcon("ChatDesk/src/ca/qc/bdeb/gr1_420_P56_BB/Images/bar.png"); int tailleY = 20; int tailleX = 20; ImageIcon imageBarModifiee = Formatage.redimensionnerImage(imageBar, tailleX, tailleY); assertEquals(imageBarModifiee.getIconWidth(), tailleX); assertEquals(imageBarModifiee.getIconHeight(), tailleY); }