List of usage examples for javax.swing ImageIcon getIconHeight
public int getIconHeight()
From source file:edu.ku.brc.ui.ImageDisplay.java
/** * Constructor with ImageIcon./*from w w w . j a v a2 s . co m*/ * @param imgIcon the icon to be displayed * @param isEditMode whether it is in browse mode or edit mode * @param hasBorder whether it has a border */ public ImageDisplay(final ImageIcon imgIcon, boolean isEditMode, boolean hasBorder) { this(imgIcon.getIconWidth(), imgIcon.getIconHeight(), isEditMode, hasBorder); setImage(imgIcon.getImage()); }
From source file:edu.ku.brc.specify.rstools.GoogleEarthExporter.java
/** * Takes an ImageIcon (in memory) and writes it out to a file. * @param icon the image icon/*from w w w .ja v a 2 s. co m*/ * @param output the destination file * @return true on success * @throws IOException */ protected boolean writeImageIconToFile(final ImageIcon icon, final File output) throws IOException { if (icon != null && icon.getIconWidth() > 0 && icon.getIconHeight() > 0 && output != null) { try { BufferedImage bimage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); if (bimage != null) { Graphics g = bimage.createGraphics(); if (g != null) { g.drawImage(icon.getImage(), 0, 0, null); g.dispose(); ImageIO.write(bimage, "PNG", output); return true; } } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(GoogleEarthExporter.class, ex); // no need to throw an exception or display it } } return false; }
From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java
/** * Method for enabling a user to choose a toolbar icon. * @param appLabel the label used to display the icon. * @param clearIconBtn the button used to clear the icon *///from w w w . j a va 2 s . c o m protected void chooseToolbarIcon(final JLabel appLabel, final JButton clearIconBtn) { FileDialog fileDialog = new FileDialog((Frame) UIRegistry.get(UIRegistry.FRAME), getResourceString("PREF_CHOOSE_APPICON_TITLE"), FileDialog.LOAD); //$NON-NLS-1$ fileDialog.setFilenameFilter(new ImageFilter()); UIHelper.centerAndShow(fileDialog); fileDialog.dispose(); String path = fileDialog.getDirectory(); if (StringUtils.isNotEmpty(path)) { String fullPath = path + File.separator + fileDialog.getFile(); File imageFile = new File(fullPath); if (imageFile.exists()) { ImageIcon newIcon = null; ImageIcon icon = new ImageIcon(fullPath); if (icon.getIconWidth() != -1 && icon.getIconHeight() != -1) { if (icon.getIconWidth() > 32 || icon.getIconHeight() > 32) { Image img = GraphicsUtils.getScaledImage(icon, 32, 32, false); if (img != null) { newIcon = new ImageIcon(img); } } else { newIcon = icon; } } ImageIcon appIcon; if (newIcon != null) { appLabel.setIcon(newIcon); clearIconBtn.setEnabled(true); String imgBufStr = GraphicsUtils.uuencodeImage(newAppIconName, newIcon); AppPreferences.getRemote().put(iconImagePrefName, imgBufStr); appIcon = newIcon; } else { appIcon = IconManager.getIcon("AppIcon"); appLabel.setIcon(appIcon); //$NON-NLS-1$ clearIconBtn.setEnabled(false); AppPreferences.getRemote().remove(iconImagePrefName); } IconEntry entry = IconManager.getIconEntryByName(INNER_APPICON_NAME); entry.setIcon(appIcon); if (entry.getIcons().get(IconManager.IconSize.Std32) != null) { entry.getIcons().get(IconManager.IconSize.Std32).setImageIcon(appIcon); } //((FormViewObj)form).getMVParent().set form.getValidator().dataChanged(null, null, null); } } }
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 ww w . j a v a2 s.c o 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 ww w .ja v a 2 s . com*/ * @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:misc.AccessibleScrollDemo.java
public AccessibleScrollDemo() { // Get the image to use. ImageIcon bee = createImageIcon("images/flyingBee.jpg", "Photograph of a flying bee."); // Create the row and column headers. columnView = new Rule(Rule.HORIZONTAL, true); if (bee != null) { columnView.setPreferredWidth(bee.getIconWidth()); } else {/*ww w .j ava2 s. c o m*/ columnView.setPreferredWidth(320); } columnView.getAccessibleContext().setAccessibleName("Column Header"); columnView.getAccessibleContext() .setAccessibleDescription("Displays horizontal ruler for " + "measuring scroll pane client."); rowView = new Rule(Rule.VERTICAL, true); if (bee != null) { rowView.setPreferredHeight(bee.getIconHeight()); } else { rowView.setPreferredHeight(480); } rowView.getAccessibleContext().setAccessibleName("Row Header"); rowView.getAccessibleContext() .setAccessibleDescription("Displays vertical ruler for " + "measuring scroll pane client."); // Create the corners. JPanel buttonCorner = new JPanel(); isMetric = new JToggleButton("cm", true); isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11)); isMetric.setMargin(new Insets(2, 2, 2, 2)); isMetric.addItemListener(this); isMetric.setToolTipText("Toggles rulers' unit of measure " + "between inches and centimeters."); buttonCorner.add(isMetric); //Use the default FlowLayout buttonCorner.getAccessibleContext().setAccessibleName("Upper Left Corner"); String desc = "Fills the corner of a scroll pane " + "with color for aesthetic reasons."; Corner lowerLeft = new Corner(); lowerLeft.getAccessibleContext().setAccessibleName("Lower Left Corner"); lowerLeft.getAccessibleContext().setAccessibleDescription(desc); Corner upperRight = new Corner(); upperRight.getAccessibleContext().setAccessibleName("Upper Right Corner"); upperRight.getAccessibleContext().setAccessibleDescription(desc); // Set up the scroll pane. picture = new ScrollablePicture(bee, columnView.getIncrement()); picture.setToolTipText(bee.getDescription()); picture.getAccessibleContext().setAccessibleName("Scroll pane client"); JScrollPane pictureScrollPane = new JScrollPane(picture); pictureScrollPane.setPreferredSize(new Dimension(300, 250)); pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black)); pictureScrollPane.setColumnHeaderView(columnView); pictureScrollPane.setRowHeaderView(rowView); // In theory, to support internationalization you would change // UPPER_LEFT_CORNER to UPPER_LEADING_CORNER, // LOWER_LEFT_CORNER to LOWER_LEADING_CORNER, and // UPPER_RIGHT_CORNER to UPPER_TRAILING_CORNER. In practice, // bug #4467063 makes that impossible (at least in 1.4.0). pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner); pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, lowerLeft); pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, upperRight); // Put it in this panel. setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); add(pictureScrollPane); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
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 www.j a va 2 s. 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 ww .ja v a2s . com*/ 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 {/*from w w w . j av a 2s. co 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:AccessibleScrollDemo.java
public AccessibleScrollDemo() { //Load the photograph into an image icon. ImageIcon david = new ImageIcon("images/youngdad.jpeg"); david.setDescription("Photograph of David McNabb in his youth."); //Create the row and column headers columnView = new Rule(Rule.HORIZONTAL, true); columnView.setPreferredWidth(david.getIconWidth()); columnView.getAccessibleContext().setAccessibleName("Column Header"); columnView.getAccessibleContext()//w w w . ja v a 2s . c o m .setAccessibleDescription("Displays horizontal ruler for " + "measuring scroll pane client."); rowView = new Rule(Rule.VERTICAL, true); rowView.setPreferredHeight(david.getIconHeight()); rowView.getAccessibleContext().setAccessibleName("Row Header"); rowView.getAccessibleContext() .setAccessibleDescription("Displays vertical ruler for " + "measuring scroll pane client."); //Create the corners JPanel buttonCorner = new JPanel(); isMetric = new JToggleButton("cm", true); isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11)); isMetric.setMargin(new Insets(2, 2, 2, 2)); isMetric.addItemListener(new UnitsListener()); isMetric.setToolTipText("Toggles rulers' unit of measure " + "between inches and centimeters."); buttonCorner.add(isMetric); //Use the default FlowLayout buttonCorner.getAccessibleContext().setAccessibleName("Upper Left Corner"); String desc = "Fills the corner of a scroll pane " + "with color for aesthetic reasons."; Corner lowerLeft = new Corner(); lowerLeft.getAccessibleContext().setAccessibleName("Lower Left Corner"); lowerLeft.getAccessibleContext().setAccessibleDescription(desc); Corner upperRight = new Corner(); upperRight.getAccessibleContext().setAccessibleName("Upper Right Corner"); upperRight.getAccessibleContext().setAccessibleDescription(desc); //Set up the scroll pane picture = new ScrollablePicture(david, columnView.getIncrement()); picture.setToolTipText(david.getDescription()); picture.getAccessibleContext().setAccessibleName("Scroll pane client"); JScrollPane pictureScrollPane = new JScrollPane(picture); pictureScrollPane.setPreferredSize(new Dimension(300, 250)); pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black)); pictureScrollPane.setColumnHeaderView(columnView); pictureScrollPane.setRowHeaderView(rowView); pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner); pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, lowerLeft); pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, upperRight); //Put it in this panel setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); add(pictureScrollPane); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }