List of usage examples for javax.swing ImageIcon getIconWidth
public int getIconWidth()
From source file:nl.phanos.liteliveresultsclient.gui.ResultsWindows.java
private void showPhoto() { int pheight = jScrollPane1.getPreferredSize().height; if (jCheckBoxMenuItem2.getState() == true && this.resultFile != null && this.resultFile.Photo != null) { ImageIcon myPicture = new ImageIcon(this.resultFile.Photo); Dimension dim = getScaledDimension(myPicture.getIconWidth(), myPicture.getIconHeight(), LayerdPane.getWidth() / 2, pheight); Image image = myPicture.getImage(); // transform it Image newimg = image.getScaledInstance(dim.width, dim.height, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way myPicture = new ImageIcon(newimg); // transform it back photolabel.setIcon(myPicture);//from w w w . j av a 2 s . co m photopanel.setPreferredSize(new Dimension(LayerdPane.getWidth() / 2, pheight)); System.out.println(myPicture.getIconWidth()); } else { photopanel.setPreferredSize(new Dimension(0, pheight)); } repaint(); }
From source file:edu.ku.brc.specify.rstools.GoogleEarthExporter.java
/** * @param outputFile/*from w w w . jav a 2 s .c o m*/ * @param defaultIconFile */ protected void createKMZ(final File outputFile, final File defaultIconFile) throws IOException { // now we have the KML in outputFile // we need to create a KMZ (zip file containing doc.kml and other files) // create a buffer for reading the files byte[] buf = new byte[1024]; int len; // create the KMZ file File outputKMZ = File.createTempFile("sp6-export-", ".kmz"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputKMZ)); // add the doc.kml file to the ZIP FileInputStream in = new FileInputStream(outputFile); // add ZIP entry to output stream out.putNextEntry(new ZipEntry("doc.kml")); // copy the bytes while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } // complete the entry out.closeEntry(); in.close(); // add a "files" directory to the KMZ file ZipEntry filesDir = new ZipEntry("files/"); out.putNextEntry(filesDir); out.closeEntry(); if (defaultIconFile != null) { File iconTmpFile = defaultIconFile; if (false) { // Shrink File ImageIcon icon = new ImageIcon(defaultIconFile.getAbsolutePath()); BufferedImage bimage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics g = bimage.createGraphics(); g.drawImage(icon.getImage(), 0, 0, null); g.dispose(); BufferedImage scaledBI = GraphicsUtils.getScaledInstance(bimage, 16, 16, true); iconTmpFile = File.createTempFile("sp6-export-icon-scaled", ".png"); ImageIO.write(scaledBI, "PNG", iconTmpFile); } // add the specify32.png file (default icon file) to the ZIP (in the "files" directory) in = new FileInputStream(iconTmpFile); // add ZIP entry to output stream out.putNextEntry(new ZipEntry("files/specify32.png")); // copy the bytes while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } // complete the entry out.closeEntry(); in.close(); } // complete the ZIP file out.close(); // now put the KMZ file where the KML output was FileUtils.copyFile(outputKMZ, outputFile); outputKMZ.delete(); }
From source file:edu.ku.brc.af.prefs.PrefsToolbar.java
/** * Loads a Section or grouping of Prefs. * @param sectionElement the section elemnent * @param altName the localized title//from w ww. j a va2s . c o m */ protected void loadSectionPrefs(final Element sectionElement, final ResourceBundle resBundle) { RolloverCommand.setVertGap(2); //List<NavBoxButton> btns = new Vector<NavBoxButton>(); //int totalWidth = 0; try { List<?> prefs = sectionElement.selectNodes("pref"); //$NON-NLS-1$ //numPrefs = prefs.size(); for (Iterator<?> iterPrefs = prefs.iterator(); iterPrefs.hasNext();) { org.dom4j.Element pref = (org.dom4j.Element) iterPrefs.next(); String prefName = pref.attributeValue("name"); //$NON-NLS-1$ String prefTitle = pref.attributeValue("title"); //$NON-NLS-1$ String iconPath = pref.attributeValue("icon"); //$NON-NLS-1$ String panelClass = pref.attributeValue("panelClass"); //$NON-NLS-1$ String viewSetName = pref.attributeValue("viewsetname"); //$NON-NLS-1$ String viewName = pref.attributeValue("viewname"); //$NON-NLS-1$ String hContext = pref.attributeValue("help"); //$NON-NLS-1$ if (AppContextMgr.isSecurityOn()) { PermissionSettings perm = SecurityMgr.getInstance().getPermission("Prefs." + prefName); //PermissionSettings.dumpPermissions("Prefs: "+prefName, perm.getOptions()); if (!perm.canView()) // this means Enabled { continue; } } if (StringUtils.isNotEmpty(prefTitle) && StringUtils.isNotEmpty(iconPath) && StringUtils.isNotEmpty(panelClass)) { if (resBundle != null) { try { prefTitle = resBundle.getString(prefTitle); } catch (MissingResourceException ex) { log.error("Couldn't find key[" + prefTitle + "]"); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PrefsToolbar.class, ex); } } ImageIcon icon; if (iconPath.startsWith("http") || iconPath.startsWith("file")) //$NON-NLS-1$ //$NON-NLS-2$ { icon = new ImageIcon(new URL(iconPath)); } else { icon = IconManager.getImage(iconPath); } if (icon != null) { if (icon.getIconWidth() > iconSize || icon.getIconHeight() > iconSize) { icon = new ImageIcon( icon.getImage().getScaledInstance(iconSize, iconSize, Image.SCALE_SMOOTH)); } } if (icon == null) { log.error("Icon was created - path[" + iconPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } NavBoxButton btn = new NavBoxButton(getResourceString(prefTitle), icon); btn.setOpaque(false); btn.setVerticalLayout(true); btn.setBorder(BorderFactory.createEmptyBorder(4, 4, 2, 4)); try { Class<?> panelClassObj = Class.forName(panelClass); Component comp = (Component) panelClassObj.newInstance(); if (comp instanceof PrefsPanelIFace) { PrefsPanelIFace prefPanel = (PrefsPanelIFace) comp; prefPanel.setName(prefName); prefPanel.setTitle(prefTitle); prefPanel.setHelpContext(hContext); if (!prefPanel.isOKToLoad() || (AppContextMgr.isSecurityOn() && !prefPanel.getPermissions().canView())) { continue; } prefPanel.setPrefsPanelMgr(prefsPanelMgr); } if (panelClassObj == GenericPrefsPanel.class) { if (StringUtils.isNotEmpty(viewSetName) && StringUtils.isNotEmpty(viewName)) { GenericPrefsPanel genericPrefsPanel = (GenericPrefsPanel) comp; genericPrefsPanel.createForm(viewSetName, viewName); } else { log.error( "ViewSetName[" + viewSetName + "] or ViewName[" + viewName + "] is empty!"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } prefsPanelMgr.addPanel(prefTitle, comp); add(btn.getUIComponent()); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PrefsToolbar.class, ex); log.error(ex); // XXX FIXME ex.printStackTrace(); } btn.addActionListener(new ShowAction(prefTitle, btn)); } } if (getComponentCount() > 0) { prevBtn = (RolloverCommand) getComponent(0); prevBtn.setActive(true); } /*int aveWidth = totalWidth / btns.size(); for (NavBoxButton nbb : btns) { Dimension size = nbb.getPreferredSize(); if (size.width < aveWidth) { size.width = aveWidth; } nbb.setPreferredSize(size); nbb.setSize(size); } */ } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PrefsToolbar.class, ex); throw new RuntimeException(ex); } finally { RolloverCommand.setVertGap(0); } }
From source file:edu.ku.brc.specify.plugins.ipadexporter.InstitutionConfigDlg.java
private String copyInstImage() { // These are form the iPad app final int kWidth = 770; final int kHeight = 435; String filePath = (String) imageView.getValue(); if (StringUtils.isNotEmpty(filePath)) { try {//from w w w . ja v a2 s . c o m File srcFile; if (filePath.startsWith("file:")) { URL url = new URL(filePath); srcFile = new File(url.toURI()); } else { srcFile = new File(filePath); } String baseName = FilenameUtils.getBaseName(filePath); String fileName = baseName + ".png"; File destFile = new File(UIRegistry.getAppDataDir() + File.separator + fileName); if (!srcFile.getAbsolutePath().equals(destFile.getAbsolutePath())) { ImageIcon img = new ImageIcon(srcFile.getAbsolutePath()); if (img.getIconWidth() > kWidth || img.getIconHeight() > kHeight) { Image image = GraphicsUtils.getScaledImage(img, kWidth, kHeight, true); try { ImageIO.write(toBufferedImage(image), "PNG", destFile); //$NON-NLS-1$ } catch (Exception ex) { } } else { FileUtils.copyFile(srcFile, destFile); } } return fileName; } catch (Exception ex) { ex.printStackTrace(); } } return null; }
From source file:App.java
protected ImageIcon scaleBufferedImageWithoutLabel(BufferedImage img) { ImageIcon icon = null; try {/*w w w . j a va2s .c o m*/ icon = new ImageIcon(img); double width = icon.getIconWidth(); double height = icon.getIconHeight(); double labelWidth = 150; double labelHight = 150; double scaleWidth = width / labelWidth; double scaleHeight = height / labelHight; if (width >= height) { // horizontal image double newWidth = width / scaleWidth; icon = new ImageIcon(icon.getImage().getScaledInstance((int) newWidth, -1, Image.SCALE_SMOOTH)); } else { // vertical image double newHeight = height / scaleHeight; icon = new ImageIcon(icon.getImage().getScaledInstance(-1, (int) newHeight, Image.SCALE_SMOOTH)); } } catch (NullPointerException e) { try { originalImage = (BufferedImage) ImageIO.read(new File("img/error.png")); } catch (IOException e2) { e2.printStackTrace(); } e.printStackTrace(); } return icon; }
From source file:edu.ku.brc.ui.IconManager.java
/** * Gets a scaled icon and if it doesn't exist it creates one and scales it * @param icon image to be scaled/* w w w. j a va 2 s.c om*/ * @param iconSize the icon size (Std) * @param scaledIconSize the new scaled size in pixels * @return the scaled icon */ public Image getFastScale(final ImageIcon icon, final IconSize iconSize, final IconSize scaledIconSize) { if (icon != null) { int width = scaledIconSize.size(); int height = scaledIconSize.size(); if ((width < 0) || (height < 0)) { //image is nonstd, revert to original size width = icon.getIconWidth(); height = icon.getIconHeight(); } Image imgMemory = createImage(icon.getImage().getSource()); //make sure all pixels in the image were loaded imgMemory = new ImageIcon(imgMemory).getImage(); BufferedImage thumbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = thumbImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(imgMemory, 0, 0, width, height, null); graphics2D.dispose(); imgMemory = thumbImage; return imgMemory; } //else log.error("Couldn't find icon [" + iconSize + "] to scale to [" + scaledIconSize + "]"); return null; }
From source file:AppSpringLayout.java
protected ImageIcon scaleBufferedImageWithoutLabel(BufferedImage img) { ImageIcon icon = null; try {// w w w .ja v a 2s . co m icon = new ImageIcon(img); double width = icon.getIconWidth(); double height = icon.getIconHeight(); double labelWidth = 300; double labelHight = 300; double scaleWidth = width / labelWidth; double scaleHeight = height / labelHight; if (width >= height) { // horizontal image double newWidth = width / scaleWidth; icon = new ImageIcon(icon.getImage().getScaledInstance((int) newWidth, -1, Image.SCALE_SMOOTH)); } else { // vertical image double newHeight = height / scaleHeight; icon = new ImageIcon(icon.getImage().getScaledInstance(-1, (int) newHeight, Image.SCALE_SMOOTH)); } } catch (NullPointerException e) { try { originalImage = (BufferedImage) ImageIO.read(new File("img/error.png")); } catch (IOException e2) { e2.printStackTrace(); } e.printStackTrace(); } return icon; }
From source file:AppSpringLayout.java
protected ImageIcon scaleBufferedImage(BufferedImage img, JLabel label) { ImageIcon icon = null; try {/* w w w . j a v a 2 s .c o m*/ icon = new ImageIcon(img); double width = icon.getIconWidth(); double height = icon.getIconHeight(); double labelWidth = label.getWidth(); double labelHight = label.getHeight(); double scaleWidth = width / labelWidth; double scaleHeight = height / labelHight; if (width >= height) { // horizontal image double newWidth = width / scaleWidth; icon = new ImageIcon(icon.getImage().getScaledInstance((int) newWidth, -1, Image.SCALE_SMOOTH)); } else { // vertical image double newHeight = height / scaleHeight; icon = new ImageIcon(icon.getImage().getScaledInstance(-1, (int) newHeight, Image.SCALE_SMOOTH)); } } catch (NullPointerException e) { try { originalImage = (BufferedImage) ImageIO.read(new File("img/error.png")); } catch (IOException e2) { e2.printStackTrace(); } e.printStackTrace(); } return icon; }
From source file:edu.ku.brc.specify.BackupAndRestoreApp.java
/** * @param imgEncoded uuencoded image string *///from ww w .j a va 2 s . c o m protected void setAppIcon(final String imgEncoded) { ImageIcon appImgIcon = null; if (StringUtils.isNotEmpty(imgEncoded)) { appImgIcon = GraphicsUtils.uudecodeImage("", imgEncoded); //$NON-NLS-1$ if (appImgIcon != null && appImgIcon.getIconWidth() == 32 && appImgIcon.getIconHeight() == 32) { appIcon.setIcon(appImgIcon); return; } } appImgIcon = IconManager.getImage(getIconName(), IconManager.IconSize.Std32); //$NON-NLS-1$ appIcon.setIcon(appImgIcon); }
From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java
private JPanel getOverlayPanel() { final JPanel overlayPanel = new JPanel(); overlayPanel.setOpaque(false);// ww w . jav a 2 s .co m overlayPanel.setLayout(new GridBagLayout()); filterTextField.addKeyListener(new KeyListener() { @Override public void keyTyped(final KeyEvent e) { } @Override public void keyReleased(final KeyEvent e) { } @Override public void keyPressed(final KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { hideFilter(); } } }); filterTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(final DocumentEvent e) { textChanged(); } @Override public void insertUpdate(final DocumentEvent e) { textChanged(); } @Override public void changedUpdate(final DocumentEvent e) { } private void textChanged() { serverListModel.filter(filterTextField.getText()); } }); final SearchField searchField = new SearchField(filterTextField); final ImageIcon closeIcon = Utils.icon("cross16.png"); final JButton closeButton = new JButton(closeIcon); closeButton.setBounds(10, 10, closeIcon.getIconWidth(), closeIcon.getIconHeight()); closeButton.setMargin(new Insets(0, 0, 0, 0)); closeButton.setOpaque(false); closeButton.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { hideFilter(); } }); searchPanel.add(searchField); searchPanel.add(closeButton); // searchPanel.setBorder(BorderFactory // .createBevelBorder(BevelBorder.RAISED)); searchPanel.setBorder(BorderFactory.createEtchedBorder()); searchPanel.setVisible(false); searchPanel.setAlignmentX(RIGHT_ALIGNMENT); final GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.LAST_LINE_END; c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 0; c.weightx = 1.0; c.weighty = 1.0; c.insets = new Insets(3, 3, 3, 3); overlayPanel.add(searchPanel, c); return overlayPanel; }