List of usage examples for javax.swing ImageIcon getIconHeight
public int getIconHeight()
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//from w w w.j ava 2 s. c o m * @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:edu.ku.brc.specify.BackupAndRestoreApp.java
/** * @param imgEncoded uuencoded image string *//*w ww . ja v a2 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:AppSpringLayout.java
protected ImageIcon scaleBufferedImageWithoutLabel(BufferedImage img) { ImageIcon icon = null; try {/*from www . j a va 2 s. com*/ 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 av a 2 s. c om 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:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java
private JPanel getOverlayPanel() { final JPanel overlayPanel = new JPanel(); overlayPanel.setOpaque(false);/*from w w w . jav a 2 s .com*/ 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; }
From source file:components.RootLayeredPaneDemo.java
public RootLayeredPaneDemo(JLayeredPane layeredPane) { super(new GridLayout(1, 1)); //Create and load the duke icon. final ImageIcon icon = createImageIcon("images/dukeWaveRed.gif"); //Create and set up the layered pane. this.layeredPane = layeredPane; layeredPane.addMouseMotionListener(this); //This is the origin of the first label added. Point origin = new Point(10, 100); //This is the offset for computing the origin for the next label. int offset = 35; //Add several overlapping, colored labels to the layered pane //using absolute positioning/sizing. for (int i = 0; i < layerStrings.length; i++) { JLabel label = createColoredLabel(layerStrings[i], layerColors[i], origin); layeredPane.add(label, new Integer(layers[i])); origin.x += offset;/* ww w. ja v a 2s.c o m*/ origin.y += offset; } //Create and add the Duke label to the layered pane. dukeLabel = new JLabel(icon); if (icon != null) { dukeLabel.setBounds(15, 225, icon.getIconWidth(), icon.getIconHeight()); } else { System.err.println("Duke icon not found; using black square instead."); dukeLabel.setBounds(15, 225, 30, 30); dukeLabel.setOpaque(true); dukeLabel.setBackground(Color.BLACK); } layeredPane.add(dukeLabel, new Integer(layers[INITIAL_DUKE_LAYER_INDEX]), 0); //Add control pane to this JPanel. add(createControlPanel()); }
From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java
/** * Create the UI for the panel//from w w w. j a v a 2 s . c om */ protected void createUI() { createForm("Preferences", "Formatting"); //$NON-NLS-1$ //$NON-NLS-2$ UIValidator.setIgnoreAllValidation(this, true); JLabel fontNamesLabel = form.getLabelFor("fontNames"); //$NON-NLS-1$ ValComboBox fontNamesVCB = form.getCompById("fontNames"); //$NON-NLS-1$ JLabel fontSizesLabel = form.getLabelFor("fontSizes"); //$NON-NLS-1$ ValComboBox fontSizesVCB = form.getCompById("fontSizes"); //$NON-NLS-1$ JLabel controlSizesLabel = form.getLabelFor("controlSizes"); //$NON-NLS-1$ ValComboBox controlSizesVCB = form.getCompById("controlSizes"); //$NON-NLS-1$ formTypesCBX = form.getCompById("formtype"); //$NON-NLS-1$ fontNames = fontNamesVCB.getComboBox(); fontSizes = fontSizesVCB.getComboBox(); controlSizes = controlSizesVCB.getComboBox(); testField = form.getCompById("fontTest"); //$NON-NLS-1$ if (testField != null) { testField.setText(UIRegistry.getResourceString("FormattingPrefsPanel.THIS_TEST")); //$NON-NLS-1$ } if (UIHelper.isMacOS_10_5_X()) { fontNamesLabel.setVisible(false); fontNamesVCB.setVisible(false); fontSizesLabel.setVisible(false); fontSizesVCB.setVisible(false); testField.setVisible(false); int inx = -1; int i = 0; Vector<String> controlSizeTitles = new Vector<String>(); for (UIHelper.CONTROLSIZE cs : UIHelper.CONTROLSIZE.values()) { String titleStr = getResourceString(cs.toString()); controlSizeTitles.add(titleStr); controlSizesHash.put(titleStr, cs); controlSizes.addItem(titleStr); if (cs == UIHelper.getControlSize()) { inx = i; } i++; } controlSizes.setSelectedIndex(inx); Font baseFont = UIRegistry.getBaseFont(); if (baseFont != null) { fontNames.addItem(baseFont.getFamily()); fontSizes.addItem(Integer.toString(baseFont.getSize())); fontNames.setSelectedIndex(0); fontSizes.setSelectedIndex(0); } } else { controlSizesLabel.setVisible(false); controlSizesVCB.setVisible(false); Hashtable<String, Boolean> namesUsed = new Hashtable<String, Boolean>(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (Font font : ge.getAllFonts()) { if (namesUsed.get(font.getFamily()) == null) { fontNames.addItem(font.getFamily()); namesUsed.put(font.getFamily(), true); //$NON-NLS-1$ } } for (int i = BASE_FONT_SIZE; i < 22; i++) { fontSizes.addItem(Integer.toString(i)); } Font baseFont = UIRegistry.getBaseFont(); if (baseFont != null) { fontNames.setSelectedItem(baseFont.getFamily()); fontSizes.setSelectedItem(Integer.toString(baseFont.getSize())); if (testField != null) { ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { testField.setFont(new Font((String) fontNames.getSelectedItem(), Font.PLAIN, fontSizes.getSelectedIndex() + BASE_FONT_SIZE)); form.getUIComponent().validate(); clearFontSettings = false; } }; fontNames.addActionListener(al); fontSizes.addActionListener(al); } } } //----------------------------------- // Do DisciplineType Icons //----------------------------------- String iconName = AppPreferences.getRemote().get(getDisciplineImageName(), "CollectionObject"); //$NON-NLS-1$ //$NON-NLS-2$ List<Pair<String, ImageIcon>> list = IconManager.getListByType("disciplines", IconManager.IconSize.Std16); //$NON-NLS-1$ Collections.sort(list, new Comparator<Pair<String, ImageIcon>>() { public int compare(Pair<String, ImageIcon> o1, Pair<String, ImageIcon> o2) { String s1 = UIRegistry.getResourceString(o1.first); String s2 = UIRegistry.getResourceString(o2.first); return s1.compareTo(s2); } }); disciplineCBX = (ValComboBox) form.getCompById("disciplineIconCBX"); //$NON-NLS-1$ final JLabel dispLabel = form.getCompById("disciplineIcon"); //$NON-NLS-1$ JComboBox comboBox = disciplineCBX.getComboBox(); comboBox.setRenderer(new DefaultListCellRenderer() { @SuppressWarnings("unchecked") //$NON-NLS-1$ public Component getListCellRendererComponent(JList listArg, Object value, int index, boolean isSelected, boolean cellHasFocus) { Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) value; JLabel label = (JLabel) super.getListCellRendererComponent(listArg, value, index, isSelected, cellHasFocus); if (item != null) { label.setIcon(item.second); label.setText(UIRegistry.getResourceString(item.first)); } return label; } }); int inx = 0; Pair<String, ImageIcon> colObj = new Pair<String, ImageIcon>("colobj_backstop", //$NON-NLS-1$ IconManager.getIcon("colobj_backstop", IconManager.IconSize.Std16)); //$NON-NLS-1$ comboBox.addItem(colObj); int cnt = 1; for (Pair<String, ImageIcon> item : list) { if (item.first.equals(iconName)) { inx = cnt; } comboBox.addItem(item); cnt++; } comboBox.addActionListener(new ActionListener() { @SuppressWarnings("unchecked") //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { JComboBox cbx = (JComboBox) e.getSource(); Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) cbx.getSelectedItem(); if (item != null) { dispLabel.setIcon(IconManager.getIcon(item.first)); form.getUIComponent().validate(); } } }); comboBox.setSelectedIndex(inx); //----------------------------------- // Date Field //----------------------------------- dateFieldCBX = form.getCompById("scrdateformat"); //$NON-NLS-1$ fillDateFormat(); //----------------------------------- // FormType //----------------------------------- fillFormTypes(); //----------------------------------- // Do App Icon //----------------------------------- final JButton getIconBtn = form.getCompById("GetIconImage"); //$NON-NLS-1$ final JButton clearIconBtn = form.getCompById("ClearIconImage"); //$NON-NLS-1$ final JLabel appLabel = form.getCompById("appIcon"); //$NON-NLS-1$ final JButton resetDefFontBtn = form.getCompById("ResetDefFontBtn"); //$NON-NLS-1$ String imgEncoded = AppPreferences.getRemote().get(iconImagePrefName, ""); //$NON-NLS-1$ ImageIcon innerAppImgIcon = null; if (StringUtils.isNotEmpty(imgEncoded)) { innerAppImgIcon = GraphicsUtils.uudecodeImage("", imgEncoded); //$NON-NLS-1$ if (innerAppImgIcon != null && innerAppImgIcon.getIconWidth() != 32 || innerAppImgIcon.getIconHeight() != 32) { innerAppImgIcon = null; clearIconBtn.setEnabled(false); } else { clearIconBtn.setEnabled(true); } } if (innerAppImgIcon == null) { innerAppImgIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$ clearIconBtn.setEnabled(false); } else { clearIconBtn.setEnabled(true); } appLabel.setIcon(innerAppImgIcon); getIconBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { chooseToolbarIcon(appLabel, clearIconBtn); } }); clearIconBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ImageIcon appIcon = IconManager.getIcon("AppIcon"); 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); } appLabel.setIcon(IconManager.getIcon("AppIcon")); //$NON-NLS-1$ clearIconBtn.setEnabled(false); AppPreferences.getRemote().remove(iconImagePrefName); form.getValidator().dataChanged(null, null, null); } }); resetDefFontBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Font sysDefFont = UIRegistry.getDefaultFont(); ComboBoxModel model = fontNames.getModel(); for (int i = 0; i < model.getSize(); i++) { //System.out.println("["+model.getElementAt(i).toString()+"]["+sysDefFont.getFamily()+"]"); if (model.getElementAt(i).toString().equals(sysDefFont.getFamily())) { fontNames.setSelectedIndex(i); clearFontSettings = true; break; } } if (clearFontSettings) { fontSizes.setSelectedIndex(sysDefFont.getSize() - BASE_FONT_SIZE); clearFontSettings = true; // needs to be redone } form.getValidator().dataChanged(null, null, null); } }); //----------------------------------- // Do Banner Icon Size //----------------------------------- String fmtStr = "%d x %d pixels";//getResourceString("BNR_ICON_SIZE"); bnrIconSizeCBX = form.getCompById("bnrIconSizeCBX"); //$NON-NLS-1$ int size = AppPreferences.getLocalPrefs().getInt(BNR_ICON_SIZE, 20); inx = 0; cnt = 0; for (int pixelSize : pixelSizes) { ((DefaultComboBoxModel) bnrIconSizeCBX.getModel()) .addElement(String.format(fmtStr, pixelSize, pixelSize)); if (pixelSize == size) { inx = cnt; } cnt++; } bnrIconSizeCBX.getComboBox().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { form.getUIComponent().validate(); } }); bnrIconSizeCBX.getComboBox().setSelectedIndex(inx); UIValidator.setIgnoreAllValidation(this, false); fontNamesVCB.setChanged(false); fontSizesVCB.setChanged(false); form.getValidator().validateForm(); }
From source file:edu.ku.brc.specify.ui.AppBase.java
/** * @param imgEncoded uuencoded image string *///from w w w . j ava2s.c o m protected void setAppIcon(final String imgEncoded) { String appIconName = "AppIcon"; String innerAppIconName = "InnerAppIcon"; 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); CustomDialog.setAppIcon(appImgIcon); CustomFrame.setAppIcon(appImgIcon); IconManager.register(innerAppIconName, appImgIcon, null, IconManager.IconSize.Std32); return; } } appImgIcon = IconManager.getImage(appIconName, IconManager.IconSize.Std32); //$NON-NLS-1$ appIcon.setIcon(appImgIcon); if (!UIHelper.isMacOS()) { appImgIcon = IconManager.getImage("SpecifyWhite32", IconManager.IconSize.Std32); //$NON-NLS-1$ } CustomDialog.setAppIcon(appImgIcon); CustomFrame.setAppIcon(appImgIcon); IconManager.register(innerAppIconName, appImgIcon, null, IconManager.IconSize.Std32); if (this.topFrame != null) { this.topFrame.setIconImage(appImgIcon.getImage()); } }
From source file:LayeredPaneDemo.java
public LayeredPaneDemo() { setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); // Create and load the duke icon. final ImageIcon icon = new ImageIcon("yourFile.gif"); // Create and set up the layered pane. layeredPane = new JLayeredPane(); layeredPane.setPreferredSize(new Dimension(300, 310)); layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke")); layeredPane.addMouseMotionListener(this); // This is the origin of the first label added. Point origin = new Point(10, 20); // This is the offset for computing the origin for the next label. int offset = 35; // Add several overlapping, colored labels to the layered pane // using absolute positioning/sizing. for (int i = 0; i < layerStrings.length; i++) { JLabel label = createColoredLabel(layerStrings[i], layerColors[i], origin); layeredPane.add(label, new Integer(i)); origin.x += offset;//from w w w . jav a 2 s . c o m origin.y += offset; } // Create and add the Duke label to the layered pane. dukeLabel = new JLabel(icon); if (icon != null) { dukeLabel.setBounds(15, 225, icon.getIconWidth(), icon.getIconHeight()); } else { System.err.println("Duke icon not found; using black square instead."); dukeLabel.setBounds(15, 225, 30, 30); dukeLabel.setOpaque(true); dukeLabel.setBackground(Color.BLACK); } layeredPane.add(dukeLabel, new Integer(2), 0); // Add control pane and layered pane to this JPanel. add(Box.createRigidArea(new Dimension(0, 10))); add(createControlPanel()); add(Box.createRigidArea(new Dimension(0, 10))); add(layeredPane); }
From source file:components.LayeredPaneDemo.java
public LayeredPaneDemo() { setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); //Create and load the duke icon. final ImageIcon icon = createImageIcon("images/dukeWaveRed.gif"); //Create and set up the layered pane. layeredPane = new JLayeredPane(); layeredPane.setPreferredSize(new Dimension(300, 310)); layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke")); layeredPane.addMouseMotionListener(this); //This is the origin of the first label added. Point origin = new Point(10, 20); //This is the offset for computing the origin for the next label. int offset = 35; //Add several overlapping, colored labels to the layered pane //using absolute positioning/sizing. for (int i = 0; i < layerStrings.length; i++) { JLabel label = createColoredLabel(layerStrings[i], layerColors[i], origin); layeredPane.add(label, new Integer(i)); origin.x += offset;/*from w w w. j ava 2s. co m*/ origin.y += offset; } //Create and add the Duke label to the layered pane. dukeLabel = new JLabel(icon); if (icon != null) { dukeLabel.setBounds(15, 225, icon.getIconWidth(), icon.getIconHeight()); } else { System.err.println("Duke icon not found; using black square instead."); dukeLabel.setBounds(15, 225, 30, 30); dukeLabel.setOpaque(true); dukeLabel.setBackground(Color.BLACK); } layeredPane.add(dukeLabel, new Integer(2), 0); //Add control pane and layered pane to this JPanel. add(Box.createRigidArea(new Dimension(0, 10))); add(createControlPanel()); add(Box.createRigidArea(new Dimension(0, 10))); add(layeredPane); }