List of usage examples for java.awt Image getScaledInstance
public Image getScaledInstance(int width, int height, int hints)
From source file:org.datacleaner.windows.AnalysisJobBuilderWindowImpl.java
private JToggleButton createMoreMenuButton() { final JMenuItem optionsMenuItem = WidgetFactory.createMenuItem("Options", IconUtils.MENU_OPTIONS); optionsMenuItem.addActionListener(new ActionListener() { @Override/* w w w . j a va 2s. c o m*/ public void actionPerformed(ActionEvent e) { OptionsDialog optionsDialog = _optionsDialogProvider.get(); optionsDialog.open(); } }); final JMenuItem monitorMenuItem = WidgetFactory.createMenuItem("DataCleaner monitor", IconUtils.MENU_DQ_MONITOR); monitorMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MonitorConnectionDialog dialog = _monitorConnectionDialogProvider.get(); dialog.open(); } }); final JMenuItem dictionariesMenuItem = WidgetFactory.createMenuItem("Dictionaries", IconUtils.DICTIONARY_IMAGEPATH); dictionariesMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReferenceDataDialog referenceDataDialog = _referenceDataDialogProvider.get(); referenceDataDialog.selectDictionariesTab(); referenceDataDialog.open(); } }); final JMenuItem synonymCatalogsMenuItem = WidgetFactory.createMenuItem("Synonyms", IconUtils.SYNONYM_CATALOG_IMAGEPATH); synonymCatalogsMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReferenceDataDialog referenceDataDialog = _referenceDataDialogProvider.get(); referenceDataDialog.selectSynonymsTab(); referenceDataDialog.open(); } }); final JMenuItem stringPatternsMenuItem = WidgetFactory.createMenuItem("String patterns", IconUtils.STRING_PATTERN_IMAGEPATH); stringPatternsMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReferenceDataDialog referenceDataDialog = _referenceDataDialogProvider.get(); referenceDataDialog.selectStringPatternsTab(); referenceDataDialog.open(); } }); final PopupButton popupButton = new PopupButton("More", imageManager.getImageIcon(IconUtils.ACTION_SCROLLDOWN_BRIGHT)); applyMenuPopupButttonStyling(popupButton); final JMenu windowsMenuItem = WidgetFactory.createMenu("Windows", 'w'); windowsMenuItem.setIcon(imageManager.getImageIcon("images/menu/windows.png", IconUtils.ICON_SIZE_SMALL)); final List<DCWindow> windows = getWindowContext().getWindows(); getWindowContext().addWindowListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { windowsMenuItem.removeAll(); for (final DCWindow window : windows) { final Image windowIcon = window.getWindowIcon(); final String title = window.getWindowTitle(); final ImageIcon icon = new ImageIcon(windowIcon.getScaledInstance(IconUtils.ICON_SIZE_SMALL, IconUtils.ICON_SIZE_SMALL, Image.SCALE_DEFAULT)); final JMenuItem switchToWindowItem = WidgetFactory.createMenuItem(title, icon); switchToWindowItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { window.toFront(); } }); windowsMenuItem.add(switchToWindowItem); } windowsMenuItem.add(new JSeparator()); JMenuItem closeAllWindowsItem = WidgetFactory.createMenuItem("Close all dialogs", (ImageIcon) null); closeAllWindowsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<DCWindow> windows = new ArrayList<>(getWindowContext().getWindows()); for (DCWindow window : windows) { if (window instanceof AbstractDialog) { window.close(); } } } }); windowsMenuItem.add(closeAllWindowsItem); } }); popupButton.getMenu().removeAll(); popupButton.getMenu().add(dictionariesMenuItem); popupButton.getMenu().add(synonymCatalogsMenuItem); popupButton.getMenu().add(stringPatternsMenuItem); popupButton.getMenu().add(new JSeparator()); popupButton.getMenu().add(windowsMenuItem); popupButton.getMenu().add(new JSeparator()); popupButton.getMenu().add(monitorMenuItem); popupButton.getMenu().add(optionsMenuItem); return popupButton; }
From source file:View.FormPengaturan.java
private void button_uploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_uploadActionPerformed JFileChooser jfc = new JFileChooser(); if (jfc.showOpenDialog(label_gambar) == JFileChooser.APPROVE_OPTION) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage(jfc.getSelectedFile().getAbsolutePath()); Image imagedResized = image.getScaledInstance(200, 250, Image.SCALE_DEFAULT); ImageIcon imageIcon = new ImageIcon(imagedResized); label_gambar.setIcon(imageIcon); label_namaFile.setText(jfc.getSelectedFile().getName());//nama file nya // System.out.println("jLabelnamaFile : " + label_namaFile.getText()); file = new File(jfc.getSelectedFile().getPath()); // file untuk dikopi // System.out.println("file : " + file.getPath()); }/*from w ww.ja v a2 s . co m*/ }
From source file:View.FormPengaturan.java
public void isiProfil() { try {/* w w w. ja v a 2 s . c om*/ Profil prof = PengaturanKontrol.getKoneksi().tampilProfil(); label_namaDesa.setText("BADAN USAHA MILIK DESA " + prof.getNamadesa()); label_alamatNotelp.setText(prof.getAlamatdesa() + " " + prof.getDesa() + " " + prof.getKecamatan() + " " + prof.getKabupaten() + " " + prof.getProvinsi() + " - " + prof.getNotelp()); text_namadesa.setText(prof.getNamadesa()); text_alamatdesa.setText(prof.getAlamatdesa()); text_noTelp.setText(prof.getNotelp()); text_desa.setText(prof.getDesa()); text_kecamatan.setText(prof.getKecamatan()); text_kabupaten.setText(prof.getKabupaten()); text_provinsi.setText(prof.getProvinsi()); text_email.setText(prof.getEmail()); String path = new File(".").getCanonicalPath(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage(path + "/Gambar/" + prof.getLogo()); // Image imagedResized = image.getScaledInstance(200, 250, Image.SCALE_DEFAULT); Image imagedResized = image.getScaledInstance(175, 145, Image.SCALE_DEFAULT); ImageIcon imageIcon = new ImageIcon(imagedResized); label_gambar.setIcon(imageIcon); label_namaFile.setText(prof.getLogo()); label_namaFile.setVisible(false); } catch (IOException ex) { Logger.getLogger(FormPengaturan.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(FormPengaturan.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.clipsmonitor.gui.MapGeneratorTopComponent.java
protected void updateLabel(String name) { try {/*from w w w . j av a2 s . co m*/ ImageIcon icon = new ImageIcon(img.getImage(name)); Image image = icon.getImage(); // transform it Image newimg = image.getScaledInstance(90, 90, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way icon = new ImageIcon(newimg); // transform it back Icons.setIcon(icon); Icons.setToolTipText("A drawing of a " + name.toLowerCase()); Icons.setText(null); } catch (NullPointerException e) { if (!img.getMapImg().isEmpty()) { Icons.setText("Image not found"); model.error(e.getLocalizedMessage()); } } updateLogArea(); }
From source file:ucar.unidata.idv.control.chart.ChartManager.java
/** * actually update the thumbnail image/* w w w .j a va 2s . com*/ */ public void updateThumbInner() { try { if (!showThumb) { return; } // if (settingData) return; if ((getContents().getWidth() == 0) || (getContents().getHeight() == 0)) { // Misc.runInABit(1000, this, "updateThumb",null); return; } List images = new ArrayList(); Image thumb = ImageUtils.getImage(getContents()); if (thumb == null) { return; } if ((thumb.getWidth(null) <= 0) || (thumb.getHeight(null) <= 0)) { return; } double ratio = thumb.getWidth(null) / (double) thumb.getHeight(null); // int width = Math.max(label.getWidth(),200); int width = 200; int height = (int) (width / ratio); thumb = ImageUtils.toBufferedImage(thumb.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING), BufferedImage.TYPE_INT_RGB); boolean chartsShowingSomething = false; for (ChartHolder chartHolder : chartHolders) { if (chartHolder.getBeingShown() && chartHolder.hasParameters()) { chartsShowingSomething = true; break; } } if (chartsShowingSomething) { getThumb().setIcon(new ImageIcon(thumb)); } else { getThumb().setIcon(GuiUtils.getImageIcon("/auxdata/ui/icons/OnePixel.gif")); } } catch (Exception exc) { // LogUtil.logException("Showing thumbnail", exc); } thumbUpdatePending = false; }
From source file:com.shending.support.CompressPic.java
public String compressPic() { try {//from w w w . j av a 2 s . co m // ? file = new File(inputDir); //System.out.println(inputDir + inputFileName); if (!file.exists()) { //throw new Exception("?"); } Image img = ImageIO.read(file); // ?? if (img.getWidth(null) == -1) { System.out.println(" can't read,retry!" + "<BR>"); return "no"; } else { int newWidth; int newHeight; // ? if (this.proportion == true) { // ? double rate1 = ((double) img.getWidth(null)) / (double) outputWidth + 0.1; double rate2 = ((double) img.getHeight(null)) / (double) outputHeight + 0.1; // ? double rate = rate1 > rate2 ? rate1 : rate2; newWidth = (int) (((double) img.getWidth(null)) / rate); newHeight = (int) (((double) img.getHeight(null)) / rate); } else { newWidth = outputWidth; // newHeight = outputHeight; // } BufferedImage tag = new BufferedImage((int) newWidth, (int) newHeight, BufferedImage.TYPE_INT_RGB); /* * Image.SCALE_SMOOTH ? ?? */ tag.getGraphics().drawImage(img.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null); File f = new File(outputDir); if (!f.exists()) { f.mkdirs(); } FileOutputStream out = new FileOutputStream(outputDir + outputFileName); // JPEGImageEncoder?? JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } } catch (IOException ex) { ex.printStackTrace(); } return "ok"; }
From source file:View.FormAnggota.java
public void sinkronGambar() { try {/*from w w w . j a v a 2s.c o m*/ Profil prof = PengaturanKontrol.getKoneksi().tampilProfil(); label_namaDesa.setText("BADAN USAHA MILIK DESA " + prof.getNamadesa()); label_alamatNotelp.setText(prof.getAlamatdesa() + " " + prof.getDesa() + " " + prof.getKecamatan() + " " + prof.getKabupaten() + " " + prof.getProvinsi() + " - " + prof.getNotelp()); String path = new File(".").getCanonicalPath() + "/Gambar/" + prof.getLogo(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage(path); Image imagedResized = image.getScaledInstance(110, 100, Image.SCALE_DEFAULT); ImageIcon imageIcon = new ImageIcon(imagedResized); label_kop.setIcon(imageIcon); } catch (IOException ex) { Logger.getLogger(FormPengaturan.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(FormPengaturan.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
/** * Scales image according to output DPI. If 96, do not need to scale * // w ww. j a v a 2s.c o m * @param img * @return */ private java.awt.Image scaleImage(java.awt.Image img) { if (this._ids.getDpiResolution() == 96) { // Do not scale in normal dpi return img; } double scale = this._ids.getDpiResolution() / 96d; int newWidth = (int) (img.getWidth((ImageObserver) getDisplayServer().getObserver()) * scale); int newHeight = (int) (img.getHeight((ImageObserver) getDisplayServer().getObserver()) * scale); return img.getScaledInstance(newWidth, newHeight, Image.SCALE_DEFAULT); }
From source file:View.FormAnggota.java
private void button_uploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_uploadActionPerformed JFileChooser jfc = new JFileChooser(); if (jfc.showOpenDialog(label_Gambar) == JFileChooser.APPROVE_OPTION) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage(jfc.getSelectedFile().getAbsolutePath()); Image imagedResized = image.getScaledInstance(175, 250, Image.SCALE_DEFAULT); ImageIcon imageIcon = new ImageIcon(imagedResized); label_Gambar.setIcon(imageIcon); label_namaFile.setText(jfc.getSelectedFile().getName());//nama file nya // System.out.println("jLabelnamaFile : " + label_namaFile.getText()); file = new File(jfc.getSelectedFile().getPath()); // file untuk dikopi // System.out.println("file : " + file.getPath()); }/*w ww . ja v a 2 s . co m*/ }
From source file:View.FormAnggota.java
private void tabel_anggotaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabel_anggotaMouseClicked try {/*w ww . j a va2s .c o m*/ custom(); int row1 = tabel_anggota.getSelectedRow(); text_idAnggota.setText(tabel_anggota.getValueAt(row1, 0).toString()); Anggota agt = AnggotaKontrol.getKoneksi().cariIdAnggota(tabel_anggota.getValueAt(row1, 1).toString()); text_nama.setText(agt.getNamaAnggota()); text_pekerjaan.setText(agt.getPekerjaan()); text_alamat.setText(agt.getAlamat()); text_rt.setText(Integer.toString(agt.getRt())); text_rw.setText(Integer.toString(agt.getRw())); combo_dusun.setSelectedItem(agt.getDusun()); text_desa.setText(agt.getDesa()); text_kota.setText(agt.getKota()); text_provinsi.setText(agt.getProvinsi()); text_telp.setText(agt.getNoTelp()); text_ktp.setText(agt.getNoKTP()); text_kecamatan.setText(agt.getKecamatan()); Anggota foto = AnggotaKontrol.getKoneksi().selectAnggota(agt.getIdAnggota()); String path = new File(".").getCanonicalPath(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage(path + "/Gambar/" + foto.getLogo()); // Image imagedResized = image.getScaledInstance(200, 250, Image.SCALE_DEFAULT); Image imagedResized = image.getScaledInstance(175, 250, Image.SCALE_DEFAULT); ImageIcon imageIcon = new ImageIcon(imagedResized); label_Gambar.setIcon(imageIcon); label_namaFile.setText(foto.getLogo()); dialog_anggota.setVisible(false); text_biaya.setEditable(false); } catch (SQLException ex) { Logger.getLogger(FormAnggota.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FormAnggota.class.getName()).log(Level.SEVERE, null, ex); } }