List of usage examples for javax.swing ImageIcon getIconWidth
public int getIconWidth()
From source file:edu.ku.brc.specify.ui.containers.ContainerTreeRenderer.java
/** * @param g2d//from w w w .j a v a2s . co m * @param xc * @param yc * @param imgIcon * @param hitsInx * @return */ private int drawIcon(final Graphics2D g2d, final int xc, final int yc, final ImageIcon imgIcon, final int hitsInx) { g2d.drawImage(imgIcon.getImage(), xc, yc, null); hitRects[hitsInx].setBounds(xc, yc, imgIcon.getIconWidth(), imgIcon.getIconHeight()); Point p = hitRects[hitsInx].getLocation(); SwingUtilities.convertPointToScreen(p, this); hitRects[hitsInx].setLocation(p); return imgIcon.getIconWidth() + iconSep; }
From source file:IconDemoApplet.java
private void updatePhotograph(int index, Photo pic) { ImageIcon icon = pic.getIcon(); photographLabel.setToolTipText(pic.filename + ": " + icon.getIconWidth() + " X " + icon.getIconHeight()); photographLabel.setIcon(icon);// w w w.jav a2s . co m photographLabel.setText(""); }
From source file:net.sourceforge.atunes.kernel.modules.tags.PropertiesFileTagAdapter.java
@Override public ImageIcon getImage(final ILocalAudioObject audioObject, final int width, final int height) { String coverFileName = getFileNameForCover(audioObject); ImageIcon image = null; if (coverFileName != null && new File(coverFileName).exists()) { image = new ImageIcon(coverFileName); }/*from w w w . j av a2 s . com*/ if (image != null) { if (width == -1 || height == -1) { return image; } int maxSize = (image.getIconWidth() > image.getIconHeight()) ? image.getIconWidth() : image.getIconHeight(); int newWidth = (int) ((float) image.getIconWidth() / (float) maxSize * width); int newHeight = (int) ((float) image.getIconHeight() / (float) maxSize * height); return ImageUtils.scaleImageBicubic(image.getImage(), newWidth, newHeight); } return image; }
From source file:cool.pandora.modeller.ui.jpanel.base.BagInfoForm.java
private void createFormFieldsFromMap(final BagTableFormBuilder formBuilder) { int rowCount = 0; final int index = 2; final Set<String> keys = fieldMap.keySet(); for (final BagInfoField field : fieldMap.values()) { formBuilder.row();/*from w w w . j a v a2s.co m*/ rowCount++; final ImageIcon imageIcon = bagView.getPropertyImage("bag.delete.image"); JButton removeButton = new JButton(imageIcon); final Dimension dimension = removeButton.getPreferredSize(); dimension.width = imageIcon.getIconWidth(); removeButton.setMaximumSize(dimension); removeButton.setOpaque(false); removeButton.setBorderPainted(false); removeButton.setContentAreaFilled(false); removeButton.addActionListener(new RemoveFieldHandler()); logger.debug("OrganizationInfoForm add: " + field); if (field.getValue() != null && field.getValue().length() > 60) { field.setComponentType(BagInfoField.TEXTAREA_COMPONENT); } if (field.isRequired()) { removeButton = new JButton(); removeButton.setOpaque(false); removeButton.setBorderPainted(false); removeButton.setContentAreaFilled(false); } switch (field.getComponentType()) { case BagInfoField.TEXTAREA_COMPONENT: final JComponent[] tlist = formBuilder.addTextArea(field.isRequired(), field.getLabel(), removeButton); final JComponent textarea = tlist[index]; textarea.setEnabled(field.isEnabled()); textarea.addFocusListener(this); ((NoTabTextArea) textarea).setText(field.getValue()); textarea.setBorder(new EmptyBorder(1, 1, 1, 1)); ((NoTabTextArea) textarea).setLineWrap(true); if (rowCount == 1) { focusField = textarea; } break; case BagInfoField.TEXTFIELD_COMPONENT: final JComponent[] flist = formBuilder.add(field.isRequired(), field.getLabel(), removeButton); final JComponent comp = flist[index]; comp.setEnabled(field.isEnabled()); comp.addFocusListener(this); ((JTextField) comp).setText(field.getValue()); if (rowCount == 1) { focusField = comp; } break; case BagInfoField.LIST_COMPONENT: final List<String> elements = field.getElements(); final JComponent[] llist = formBuilder.addList(field.isRequired(), field.getLabel(), elements, field.getValue(), removeButton); final JComponent lcomp = llist[index]; lcomp.setEnabled(field.isEnabled()); lcomp.addFocusListener(this); if (field.getValue() != null) { ((JComboBox<?>) lcomp).setSelectedItem(field.getValue().trim()); } if (rowCount == 1) { focusField = lcomp; } break; default: } } if (focusField != null) { focusField.requestFocus(); } }
From source file:GrafosTroleBus.java
public GrafosTroleBus() { setLayout(new BorderLayout()); //definir puntos de trolebus (latitude y longitude) @autor sa map.put("RECREO", new String[] { "-0.2516682", "-78.521524" }); //Recreo map.put("P14", new String[] { "-0.2445098", "-78.51902" }); //Villaflora map.put("P15", new String[] { "-0.2396436", "-78.51698" }); //Chimbacalle N-S map.put("P16", new String[] { "-0.2378458", "-78.515976" }); //Chimbacalle S-N map.put("P17", new String[] { "-0.2356805", "-78.514816" }); //Colina map.put("P18", new String[] { "-0.234052", "-78.514237" }); //Jefferson Perez map.put("P19", new String[] { "-0.2312856", "-78.513627" }); //Recoleta N-S map.put("P20", new String[] { "-0.2307005", "-78.513051" }); //Recoleta S-N map.put("P21", new String[] { "-0.2263919", "-78.513011" }); //P21 Cumanda N-S map.put("P22", new String[] { "-0.226424", "-78.512803" }); //P22 Cumanda S-N map.put("P23", new String[] { "-0.2234658", "-78.512542" }); //P23 Santo Domingo map.put("P24", new String[] { "-0.2185857", "-78.508601" }); //P24 Plaza del Teatro N-S map.put("P25", new String[] { "-0.219605", "-78.50813" }); //P25 Plaza del Teatro S-N map.put("P26", new String[] { "-0.2177808", "-78.505977" }); //P26 Hermano Miguel map.put("P27", new String[] { "-0.2169088", "-78.50521" }); //P27 Banco Central map.put("P28", new String[] { "-0.214267", "-78.502999" }); //P28 La Alameda S-N map.put("P29", new String[] { "-0.2137705", "-78.50293" }); //P29 La Alameda N-S map.put("P30", new String[] { "-0.2084939", "-78.500255" }); //P30 Ejido N-S map.put("P31", new String[] { "-0.2088076", "-78.500032" }); //P31 Ejido S-N map.put("P32", new String[] { "-0.2047989", "-78.4988" }); //P32 La Mariscal N-S map.put("P33", new String[] { "-0.2041972", "-78.498491" }); //P33 La Mariscal S-N map.put("P34", new String[] { "-0.2009718", "-78.49715" }); //P34 Santa Clara S-N map.put("P35", new String[] { "-0.201056", "-78.496979" }); //P35 Santa Clara N-S map.put("P36", new String[] { "-0.1986325", "-78.496141" }); //P36 La Colon S-N map.put("P37", new String[] { "-0.1978432", "-78.495563" }); //P37 La Colon N-S map.put("P38", new String[] { "-0.1921587", "-78.493445" }); //P38 Cuero y Caicedo S-N map.put("P39", new String[] { "-0.1915098", "-78.493001" }); //P39 Cuero y Caicedo N-S map.put("P40", new String[] { "-0.1889467", "-78.492149" }); //P40 Mariana de Jess S-N map.put("P41", new String[] { "-0.1875567", "-78.491303" }); //P41 Mariana de Jesus N-S map.put("P42", new String[] { "-0.1853693", "-78.490878" }); //P42 El Floron S-N map.put("P43", new String[] { "-0.1846687", "-78.490403" }); //P43 El Floron N-S map.put("P44", new String[] { "-0.1817679", "-78.489808" }); //P44 Carolina S-N map.put("P45", new String[] { "-0.1810849", "-78.489336" }); //P45 Carolina N-S map.put("P46", new String[] { "-0.1787274", "-78.488954" }); //P46 Estadio S-N map.put("P47", new String[] { "-0.1780172", "-78.488621" }); //P47 Estadio N-S map.put("P48", new String[] { "-0.172087", "-78.487589" }); //P48 La Y S-N map.put("P49", new String[] { "-0.1713146", "-78.487277" }); //P49 La Y N-S map.put("LA Y", new String[] { "-0.1635504", "-78.485374" }); //Estacin La Y nodoList = new ArrayList<String>(map.keySet()); // create a simple graph for the demo graph = new DirectedSparseMultigraph<String, Number>(); createVertices();/*from w ww .ja va 2 s. c o m*/ createEdges(); ImageIcon mapIcon = null; String imageLocation = "/mapa_quito.png"; try { mapIcon = new ImageIcon(getClass().getResource(imageLocation)); ImageWidth = mapIcon.getIconWidth(); ImageHeight = mapIcon.getIconHeight(); } catch (Exception ex) { System.err.println("Can't load \"" + imageLocation + "\""); } final ImageIcon icon = mapIcon; Dimension layoutSize = new Dimension(ImageWidth, ImageHeight); Layout<String, Number> layout = new StaticLayout<String, Number>(graph, new ChainedTransformer<String, Point2D>(new Transformer[] { new CityTransformer(map), new LatLonPixelTransformer(new Dimension(ImageWidth, ImageHeight)) })); layout.setSize(layoutSize); vv = new VisualizationViewer<String, Number>(layout, new Dimension(MonitorWidth, MonitorHeight)); if (icon != null) { vv.addPreRenderPaintable(new VisualizationViewer.Paintable() { public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform oldXform = g2d.getTransform(); AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.LAYOUT).getTransform(); AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.VIEW).getTransform(); AffineTransform at = new AffineTransform(); at.concatenate(g2d.getTransform()); at.concatenate(vat); at.concatenate(lat); g2d.setTransform(at); g.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), vv); g2d.setTransform(oldXform); } public boolean useTransform() { return false; } }); } vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red, Color.white, Color.blue, vv.getPickedVertexState(), false)); // add my listeners for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); vv.setEdgeToolTipTransformer(new Transformer<Number, String>() { public String transform(Number edge) { return "E" + graph.getEndpoints(edge).toString(); } }); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); add(panel); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<Object, Object>(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode"); final ScalingControl scaler = new CrossoverScalingControl(); vv.scaleToLayout(scaler); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity(); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(reset); add(controls, BorderLayout.SOUTH); }
From source file:edu.ku.brc.ui.ImageDisplay.java
/** * Constructor with ImageIcon.//w w w .j a v a 2 s. c o 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: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()/*from w w w. j a 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)); }
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 .jav a 2s. com*/ * @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:business.ImageManager.java
public void doLoadPortraits() { // boolean showPortrait = SettingsManager.getInstance().isConfig("ShowCharacterPortraits", "1", "0"); ///*from w w w.j a v a2s.c o m*/ // if (!showPortrait ) { // return; // } if (!portraitMap.isEmpty()) { return; } String portraitsPath = SettingsManager.getInstance().getConfig("PortraitsFolder", ""); File portraitsFolder = new File(portraitsPath); if (!portraitsFolder.exists() || portraitsFolder.list().length <= 0) { log.debug("Folder '" + portraitsPath + "' not found."); return; } log.debug("Folder '" + portraitsPath + "' found."); File[] portraitsFile = portraitsFolder.listFiles(); for (File portraitFile : portraitsFile) { portraitFile.toURI(); ImageIcon portraitIcon = new ImageIcon(portraitFile.getAbsolutePath()); portraitIcon.getIconWidth(); portraitMap.put(portraitFile.getName(), portraitIcon); } }
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 *//* w w w.j av a 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); } } }