List of usage examples for javax.swing ImageIcon getImage
@Transient
public Image getImage()
Image
. From source file:Main.java
/** * Resizes the icons of all the abstract buttons which are contained in * a container./*from www.j av a2 s . c o m*/ * * @param container a container containing abstract buttons * @param size the size which should be used for the icons */ public static void scaleAllAbstractButtonIconsOf(Container container, int size) { for (final Component c : container.getComponents()) { if (c instanceof AbstractButton) { final ImageIcon i = (ImageIcon) ((AbstractButton) c).getIcon(); if (i != null) { i.setImage(i.getImage().getScaledInstance(size, size, Image.SCALE_SMOOTH)); } } } }
From source file:sas.BarChart.java
public static JFreeChart createChart(CategoryDataset categorydataset, String name, String type, String t) { JFreeChart jfreechart = ChartFactory.createLineChart(name, null, type, categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.addSubtitle(new TextTitle(t)); TextTitle texttitle = new TextTitle(""); texttitle.setFont(new Font("SansSerif", 0, 10)); texttitle.setPosition(RectangleEdge.BOTTOM); texttitle.setHorizontalAlignment(HorizontalAlignment.CENTER); jfreechart.addSubtitle(texttitle);/*from ww w . j av a2s . c o m*/ CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setRangePannable(true); categoryplot.setRangeGridlinesVisible(false); java.net.URL url = (BarChart.class).getClassLoader().getResource("line_Chart_example.png"); if (url != null) { ImageIcon imageicon = new ImageIcon(url); jfreechart.setBackgroundImage(imageicon.getImage()); categoryplot.setBackgroundPaint(null); } NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartUtilities.applyCurrentTheme(jfreechart); LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); lineandshaperenderer.setDrawOutlines(true); lineandshaperenderer.setUseFillPaint(true); lineandshaperenderer.setBaseFillPaint(Color.white); lineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F)); lineandshaperenderer.setSeriesOutlineStroke(0, new BasicStroke(2.0F)); lineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D)); return jfreechart; }
From source file:net.chris54721.infinitycubed.utils.Utils.java
public static Image getImageResource(String imageName) { ImageIcon image = new ImageIcon(Toolkit.getDefaultToolkit().getImage(getResource(imageName, "png"))); if (image.getImageLoadStatus() == MediaTracker.COMPLETE) return image.getImage(); else {// www.ja v a 2 s .co m LogHelper.error("Failed loading image resource " + imageName); return null; } }
From source file:net.sf.webphotos.tools.Thumbnail.java
/** * Cria thumbs para as imagens. Testa se j existem valores setados para o * thumb, se no existir chama o mtodo/* ww w . j a v a2 s. c om*/ * {@link net.sf.webphotos.Thumbnail#inicializar() inicializar} para setar * seus valores. Abre o arquivo de imagem passado como parmetro e checa se * uma foto vlida. Obtm o tamanho original da imagem, checa se est no * formato paisagem ou retrato e utiliza o mtodo * {@link java.awt.Image#getScaledInstance(int,int,int) getScaledInstance} * para calcular os thumbs. Ao final, salva as imagens. * * @param caminhoCompletoImagem Caminho da imagem. */ public static void makeThumbs(String caminhoCompletoImagem) { String diretorio, arquivo; if (t1 == 0) { inicializar(); } try { File f = new File(caminhoCompletoImagem); if (!f.isFile() || !f.canRead()) { Util.err.println("[Thumbnail.makeThumbs]/ERRO: Erro no caminho do arquivo " + caminhoCompletoImagem + " incorreto"); return; } // Foto em alta corrompida if (getFormatName(f) == null) { Util.err.println("[Thumbnail.makeThumbs]/ERRO: Foto Corrompida"); return; } else { Util.out.println("[Thumbnail.makeThumbs]/INFO: Foto Ok!"); } diretorio = f.getParent(); arquivo = f.getName(); ImageIcon ii = new ImageIcon(f.getCanonicalPath()); Image i = ii.getImage(); Image tumb1, tumb2, tumb3, tumb4; // obtm o tamanho da imagem original int iWidth = i.getWidth(null); int iHeight = i.getHeight(null); //int w, h; if (iWidth > iHeight) { tumb1 = i.getScaledInstance(t1, (t1 * iHeight) / iWidth, Image.SCALE_SMOOTH); tumb2 = i.getScaledInstance(t2, (t2 * iHeight) / iWidth, Image.SCALE_SMOOTH); tumb3 = i.getScaledInstance(t3, (t3 * iHeight) / iWidth, Image.SCALE_SMOOTH); tumb4 = i.getScaledInstance(t4, (t4 * iHeight) / iWidth, Image.SCALE_SMOOTH); //w = t4; //h = (t4 * iHeight) / iWidth; } else { tumb1 = i.getScaledInstance((t1 * iWidth) / iHeight, t1, Image.SCALE_SMOOTH); tumb2 = i.getScaledInstance((t2 * iWidth) / iHeight, t2, Image.SCALE_SMOOTH); tumb3 = i.getScaledInstance((t3 * iWidth) / iHeight, t3, Image.SCALE_SMOOTH); tumb4 = i.getScaledInstance((t4 * iWidth) / iHeight, t4, Image.SCALE_SMOOTH); //w = (t4 * iWidth) / iHeight; //h = t4; } tumb4 = estampar(tumb4); Util.log("Salvando Imagens"); save(tumb1, diretorio + File.separator + "_a" + arquivo); save(tumb2, diretorio + File.separator + "_b" + arquivo); save(tumb3, diretorio + File.separator + "_c" + arquivo); save(tumb4, diretorio + File.separator + "_d" + arquivo); } catch (Exception e) { Util.err.println("[Thumbnail.makeThumbs]/ERRO: Inesperado - " + e.getMessage()); e.printStackTrace(Util.err); } }
From source file:net.rptools.lib.image.ImageUtil.java
public static ImageIcon resizeImage(ImageIcon imageIcon, int w, int h) { return new ImageIcon(imageIcon.getImage().getScaledInstance(w, h, Image.SCALE_SMOOTH)); }
From source file:com.invbf.sistemagestionmercadeo.reportes.ReportCreator.java
public static void generadorSolicitudBono(Solicitudentrega elemento) { ServletOutputStream servletOutputStream = null; try {/* w w w . j a v a2s.c o m*/ SolicitudBonoJuego elementoReporte = new SolicitudBonoJuego(); if (elemento.getSolicitante().getUsuariodetalle().getIdcargo() != null) { elementoReporte.setCargo(elemento.getSolicitante().getUsuariodetalle().getIdcargo().getNombre()); } else { elementoReporte.setCargo(""); } elementoReporte.setCasino(elemento.getIdCasino().getNombre()); SimpleDateFormat formateador = new SimpleDateFormat("dd-MMMM-yy", new Locale("es_ES")); elementoReporte.setFecha(formateador.format(elemento.getFecha())); elementoReporte.setJustificacion(elemento.getJustificacion()); elementoReporte.setNombre(elemento.getSolicitante().getNombreUsuario()); elementoReporte.setProposito(elemento.getPropositoEntrega().getNombre()); elementoReporte.setTipobono(elemento.getTipoBono().getNombre()); List<SolicitudBonoJuegoCliente> clientes = new ArrayList<SolicitudBonoJuegoCliente>(); int item = 1; Float total = 0f; for (Solicitudentregacliente sec : elemento.getSolicitudentregaclienteList()) { clientes.add(new SolicitudBonoJuegoCliente((item) + "", sec.getCliente().getNombres() + " " + sec.getCliente().getApellidos(), sec.getValorTotal().toString(), sec.getAreaid().getNombre())); total += sec.getValorTotal(); item++; } elementoReporte.setClientes(clientes); elementoReporte.setTotal(total.toString()); ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); InputStream input = externalContext .getResourceAsStream("/resources/reportes/solicitudbonosjuego.jasper"); InputStream subreport = externalContext .getResourceAsStream("/resources/reportes/solicitudbonosjuego_cliente.jasper"); InputStream logo = externalContext.getResourceAsStream("/resources/reportes/LogoMRCNegro.jpeg"); InputStream logoibf = externalContext.getResourceAsStream("/resources/reportes/IBFLogo01jpeg.jpeg"); ImageIcon tlc = new ImageIcon(IOUtils.toByteArray(logo)); ImageIcon ibf = new ImageIcon(IOUtils.toByteArray(logoibf)); elementoReporte.setIbf(ibf.getImage()); elementoReporte.setLogo(tlc.getImage()); List<SolicitudBonoJuego> lista = new ArrayList<SolicitudBonoJuego>(); lista.add(elementoReporte); JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(lista); JasperReport jasperMasterReport = (JasperReport) JRLoader.loadObject(input); JasperReport jasperSubReport = (JasperReport) JRLoader.loadObject(subreport); elementoReporte.setSubreportclientes(jasperSubReport); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("logo", lista.get(0).getLogo()); parameters.put("ibf", lista.get(0).getIbf()); parameters.put("clientes", lista.get(0).getClientes()); parameters.put("subreportclientes", jasperSubReport); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperMasterReport, parameters, beanColDataSource); HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); httpServletResponse.addHeader("Content-disposition", "attachment; filename=ActaSolicitudBonosJuego" + elemento.getId() + ".pdf"); servletOutputStream = httpServletResponse.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream); } catch (IOException ex) { Logger.getLogger(ReportCreator.class.getName()).log(Level.SEVERE, null, ex); } catch (JRException ex) { Logger.getLogger(ReportCreator.class.getName()).log(Level.SEVERE, null, ex); } finally { try { servletOutputStream.close(); } catch (IOException ex) { Logger.getLogger(ReportCreator.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.invbf.sistemagestionmercadeo.reportes.ReportCreator.java
public static void generadorPreorden(Solicitudentregalotesmaestro elemento) { try {//www . ja v a 2s . co m ActaREciboCustodiaBonosCajaBean elementoReporte = new ActaREciboCustodiaBonosCajaBean(); elementoReporte.setActnumber(elemento.getId().toString()); elementoReporte.setBonosPorDenominacionEntregars(new ArrayList<ListaBonosPorDenominacionEntregar>()); List<bonosnoincluidos> bonosnoincluidos = new ArrayList<bonosnoincluidos>(); for (Solicitudentregalote sel : elemento.getSolicitudentregaloteList()) { ListaBonosPorDenominacionEntregar lbde = new ListaBonosPorDenominacionEntregar(); lbde.setCantidad(sel.getCantidad().toString()); lbde.setDenominacion(getAsString(sel.getLotesBonosid().getDenominacion().getValor() + " ")); if (sel.getLotesBonosid().getTipoBono().getNombre().equals("PROMOCIONAL")) { lbde.setSaladejuego(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + " " + sel.getLotesBonosid().getTipoBono().getNombre()); lbde.setDel(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + "-" + sel.getDesde()); lbde.setAl(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + "-" + sel.getHasta()); } else { lbde.setSaladejuego(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + " " + sel.getLotesBonosid().getTipoBono().getNombre()); lbde.setDel(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + "-" + sel.getDesde()); lbde.setAl(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + "-" + sel.getHasta()); } elementoReporte.getBonosPorDenominacionEntregars().add(lbde); String bonosnoincluidosString = "Bono " + sel.getLotesBonosid().getTipoBono().getNombre() + " " + " / " + sel.getLotesBonosid().getDenominacion().getValor() + " / Faltantes: "; if (sel.getBononoincluidoList().isEmpty()) { for (Bononoincluido bonosnoincluido : sel.getBononoincluidoList()) { bonosnoincluidosString += " " + bonosnoincluido.getConsecutivo(); } bonosnoincluidos.add(new bonosnoincluidos(bonosnoincluidosString)); } } ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); InputStream input = externalContext .getResourceAsStream("/resources/reportes/OrdenProduccionLoteBono.jasper"); InputStream subreport = externalContext .getResourceAsStream("/resources/reportes/ReciboCustodiaBonosCaja_detalle.jasper"); InputStream logotexas = externalContext.getResourceAsStream("/resources/reportes/LogoTLCNegro-01.jpeg"); InputStream logomasters = externalContext.getResourceAsStream("/resources/reportes/IBFLogo01jpeg.jpeg"); InputStream logoibf = externalContext.getResourceAsStream("/resources/reportes/LogoMRCNegro.jpeg"); ImageIcon tlc = new ImageIcon(IOUtils.toByteArray(logotexas)); ImageIcon mrc = new ImageIcon(IOUtils.toByteArray(logomasters)); ImageIcon ibf = new ImageIcon(IOUtils.toByteArray(logoibf)); elementoReporte.setIbf(ibf.getImage()); elementoReporte.setMrc(mrc.getImage()); elementoReporte.setTlc(tlc.getImage()); elementoReporte.setBonosnoincluidos(bonosnoincluidos); List<ActaREciboCustodiaBonosCajaBean> lista = new ArrayList<ActaREciboCustodiaBonosCajaBean>(); lista.add(elementoReporte); JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(lista); JasperReport jasperMasterReport = (JasperReport) JRLoader.loadObject(input); JasperReport jasperSubReport = (JasperReport) JRLoader.loadObject(subreport); elementoReporte.setSubreportParameter(jasperSubReport); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("actnumber", lista.get(0).getActnumber()); parameters.put("tlc", lista.get(0).getTlc()); parameters.put("ibf", lista.get(0).getIbf()); parameters.put("mrc", lista.get(0).getMrc()); parameters.put("subreportParameter", jasperSubReport); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperMasterReport, parameters, beanColDataSource); HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); httpServletResponse.addHeader("Content-disposition", "attachment; filename=OrdenProduccionLotesBonos" + elemento.getId() + ".pdf"); ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream); } catch (JRException ex) { Logger.getLogger(GeneradorSolicitudLotesBonos.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GeneradorSolicitudLotesBonos.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:de.fhg.igd.swingrcp.SwingRCPUtilities.java
/** * Create a SWT Image from an {@link ImageIcon} * /*from w w w . j a v a 2s . co m*/ * {@link "http://www.eclipseproject.de/modules.php?name=Forums&file=viewtopic&t=5489"} * {@link "http://www.9php.com/FAQ/cxsjl/java/2007/11/5033330101296.html"} * * @param icon the {@link ImageIcon} * @return the SWT {@link ImageData} */ public static ImageData convertToSWT(ImageIcon icon) { BufferedImage img = GraphicsUtilities.createCompatibleTranslucentImage(icon.getIconWidth(), icon.getIconHeight()); img.getGraphics().drawImage(icon.getImage(), 0, 0, null); return convertToSWT(img); }
From source file:com.invbf.sistemagestionmercadeo.reportes.ReportCreator.java
public static void generadorEntregaBonosCaja(Solicitudentregalotesmaestro elemento) { try {/*ww w . ja v a2s . c om*/ ActaREciboCustodiaBonosCajaBean elementoReporte = new ActaREciboCustodiaBonosCajaBean(); elementoReporte.setActnumber(elemento.getId().toString()); elementoReporte.setBonosPorDenominacionEntregars(new ArrayList<ListaBonosPorDenominacionEntregar>()); List<bonosnoincluidos> bonosnoincluidos = new ArrayList<bonosnoincluidos>(); for (Solicitudentregalote sel : elemento.getSolicitudentregaloteList()) { ListaBonosPorDenominacionEntregar lbde = new ListaBonosPorDenominacionEntregar(); lbde.setCantidad(sel.getCantidad().toString()); lbde.setDenominacion(getAsString(sel.getLotesBonosid().getDenominacion().getValor() + " ")); if (sel.getLotesBonosid().getTipoBono().getNombre().equals("PROMOCIONAL")) { lbde.setSaladejuego(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + " " + sel.getLotesBonosid().getTipoBono().getNombre()); lbde.setDel(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + "-" + sel.getDesde()); lbde.setAl(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbreCiudad() + "-" + sel.getHasta()); } else { lbde.setSaladejuego(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + " " + sel.getLotesBonosid().getTipoBono().getNombre()); lbde.setDel(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + "-" + sel.getDesde()); lbde.setAl(sel.getLotesBonosid().getIdCasino().getCasinodetalle().getAbrenopromo() + "-" + sel.getHasta()); } elementoReporte.getBonosPorDenominacionEntregars().add(lbde); String bonosnoincluidosString = "Bono " + sel.getLotesBonosid().getTipoBono().getNombre() + " " + " / " + sel.getLotesBonosid().getDenominacion().getValor() + " / Faltantes: "; if (sel.getBononoincluidoList().isEmpty()) { for (Bononoincluido bonosnoincluido : sel.getBononoincluidoList()) { bonosnoincluidosString += " " + bonosnoincluido.getConsecutivo(); } bonosnoincluidos.add(new bonosnoincluidos(bonosnoincluidosString)); } } ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); InputStream input = externalContext .getResourceAsStream("/resources/reportes/ReciboCustodiaBonosCaja.jasper"); InputStream subreport = externalContext .getResourceAsStream("/resources/reportes/ReciboCustodiaBonosCaja_detalle.jasper"); InputStream bonosno = externalContext .getResourceAsStream("/resources/reportes/ReciboCustodiaBonosCaja_bonosnoincluidos.jasper"); InputStream logotexas = externalContext.getResourceAsStream("/resources/reportes/LogoTLCNegro-01.jpeg"); InputStream logomasters = externalContext.getResourceAsStream("/resources/reportes/IBFLogo01jpeg.jpeg"); InputStream logoibf = externalContext.getResourceAsStream("/resources/reportes/LogoMRCNegro.jpeg"); ImageIcon tlc = new ImageIcon(IOUtils.toByteArray(logotexas)); ImageIcon mrc = new ImageIcon(IOUtils.toByteArray(logomasters)); ImageIcon ibf = new ImageIcon(IOUtils.toByteArray(logoibf)); elementoReporte.setIbf(ibf.getImage()); elementoReporte.setMrc(mrc.getImage()); elementoReporte.setTlc(tlc.getImage()); elementoReporte.setBonosnoincluidos(bonosnoincluidos); List<ActaREciboCustodiaBonosCajaBean> lista = new ArrayList<ActaREciboCustodiaBonosCajaBean>(); lista.add(elementoReporte); JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(lista); JasperReport jasperMasterReport = (JasperReport) JRLoader.loadObject(input); JasperReport jasperSubReport = (JasperReport) JRLoader.loadObject(subreport); JasperReport bonosnoReport = (JasperReport) JRLoader.loadObject(bonosno); elementoReporte.setSubreportParameter(jasperSubReport); elementoReporte.setBonosno(bonosnoReport); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("actnumber", lista.get(0).getActnumber()); parameters.put("tlc", lista.get(0).getTlc()); parameters.put("ibf", lista.get(0).getIbf()); parameters.put("mrc", lista.get(0).getMrc()); parameters.put("subreportParameter", jasperSubReport); parameters.put("bonosno", bonosnoReport); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperMasterReport, parameters, beanColDataSource); HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); httpServletResponse.addHeader("Content-disposition", "attachment; filename=ActaReciboCustodiaBonosCaja" + elemento.getId() + ".pdf"); ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream); } catch (JRException ex) { Logger.getLogger(GeneradorSolicitudLotesBonos.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GeneradorSolicitudLotesBonos.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:jshm.gui.GuiUtil.java
/** * Resize an ImageIcon to the specified size. * @param icon The ImageIcon to resize/*from w w w . ja v a2s . c o m*/ * @param width The new width * @param height The new height */ public final static javax.swing.ImageIcon resizeIcon(ImageIcon icon, int width, int height) { LOG.info("Resizing to " + width + "x" + height); Image img = icon.getImage(); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics g = bi.createGraphics(); g.drawImage(img, 0, 0, width, height, null); g.dispose(); return new javax.swing.ImageIcon(bi); }