List of usage examples for javax.swing ImageIcon getIconWidth
public int getIconWidth()
From source file:util.io.IOUtilities.java
/** * Writes the given image icon to the given file in the given imageType. * * @param icon The icon to write./*from w ww. ja va 2 s . c o m*/ * @param imageType The image type. * @param targetFile The file to write the image to. * * @return <code>True</code> if the file could be written, <code>false</code> if something went wrong. * @since 2.6 */ public static boolean writeImageIconToFile(ImageIcon icon, String imageType, File targetFile) { try { BufferedImage iconimage = new BufferedImage(icon.getIconWidth(), icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = iconimage.createGraphics(); icon.paintIcon(null, g2, 0, 0); g2.dispose(); ImageIO.write(iconimage, imageType, targetFile); } catch (Exception e) { return false; } return true; }
From source file:util.program.ProgramTextCreator.java
/** * * @param prog/* w ww . java2s .co m*/ * The Program to show * @param doc * The HTMLDocument. * @param fieldArr * The object array with the field types. * @param tFont * The title Font. * @param bFont * The body Font. * @param settings * Settings of the ProgramPanel * @param showHelpLinks * Show the Help-Links (Quality of Data, ShowView) * @param zoom * The zoom value for the picture. * @param showPluginIcons * If the plugin icons should be shown. * @return The HTML String. * @since 3.0 */ public static String createInfoText(Program prog, ExtendedHTMLDocument doc, Object[] fieldArr, Font tFont, Font bFont, ProgramPanelSettings settings, boolean showHelpLinks, int zoom, boolean showPluginIcons, boolean showPersonLinks) { String debugTables = "0"; //set to "1" for debugging, to "0" for no debugging try { // NOTE: All field types are included until type 25 (REPETITION_ON_TYPE) StringBuilder buffer = new StringBuilder(1024); String titleFont, titleSize, bodyFont; int bodyStyle; int titleStyle; if (tFont == null && bFont != null) { titleFont = bodyFont = bFont.getFamily(); titleSize = mBodyFontSize = String.valueOf(bFont.getSize()); titleStyle = bodyStyle = bFont.getStyle(); } else if (tFont != null && bFont != null) { titleFont = tFont.getFamily(); bodyFont = bFont.getFamily(); titleSize = String.valueOf(tFont.getSize()); mBodyFontSize = String.valueOf(bFont.getSize()); titleStyle = tFont.getStyle(); bodyStyle = bFont.getStyle(); } else { return null; } if (fieldArr == null) { return null; } buffer.append("<html>"); buffer.append("<table width=\"100%\" border=\"" + debugTables + "\" style=\"font-family:"); buffer.append(bodyFont); buffer.append(";").append(getCssStyle(bodyStyle)).append("\"><tr>"); buffer.append("<td width=\"60\">"); buffer.append("<p \"align=center\">"); JLabel channelLogo = new JLabel(prog.getChannel().getIcon()); channelLogo.setToolTipText(prog.getChannel().getName()); buffer.append(doc.createCompTag(channelLogo)); buffer.append( "</p></td><td><table width=\"100%\" border=\"" + debugTables + "\" cellpadding=\"0\"><tr><td>"); buffer.append("<div style=\"color:#ff0000; font-size:"); buffer.append(mBodyFontSize); buffer.append(";\"><b>"); Date currentDate = Date.getCurrentDate(); Date programDate = prog.getDate(); if (programDate.equals(currentDate.addDays(-1))) { buffer.append(Localizer.getLocalization(Localizer.I18N_YESTERDAY)); buffer.append(" "); } else if (programDate.equals(currentDate)) { buffer.append(Localizer.getLocalization(Localizer.I18N_TODAY)); buffer.append(" "); } else if (programDate.equals(currentDate.addDays(1))) { buffer.append(Localizer.getLocalization(Localizer.I18N_TOMORROW)); buffer.append(" "); } buffer.append(prog.getDateString()); buffer.append(" "); buffer.append(prog.getTimeString()); if (prog.getLength() > 0) { buffer.append('-'); buffer.append(prog.getEndTimeString()); } buffer.append(" "); buffer.append(prog.getChannel()); buffer.append("</b></div><div style=\"color:#003366; font-size:"); buffer.append(titleSize); buffer.append("; line-height:2.5em; font-family:"); buffer.append(titleFont).append(";").append(getCssStyle(titleStyle)); buffer.append("\">"); buffer.append(prog.getTitle()); buffer.append("</div>"); String episode = CompoundedProgramFieldType.EPISODE_COMPOSITION.getFormattedValueForProgram(prog); if (episode != null && episode.trim().length() > 0) { buffer.append("<div style=\"color:#808080; font-size:"); buffer.append(mBodyFontSize); buffer.append("\">"); buffer.append(episode); buffer.append("</div>"); } buffer.append("</td><td align=\"right\" valign=\"top\"><table border=\"" + debugTables + "\"><tr><td>"); JButton btn = new JButton(TVBrowserIcons.left(TVBrowserIcons.SIZE_SMALL)); buffer.append(doc.createCompTag(btn)); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ProgramInfo.getInstance().historyBack(); } }); btn.setEnabled(ProgramInfo.getInstance().canNavigateBack()); btn.setToolTipText(ProgramInfo.getInstance().navigationBackwardText()); buffer.append("</td><td>"); btn = new JButton(TVBrowserIcons.right(TVBrowserIcons.SIZE_SMALL)); buffer.append(doc.createCompTag(btn)); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ProgramInfo.getInstance().historyForward(); } }); btn.setEnabled(ProgramInfo.getInstance().canNavigateForward()); btn.setToolTipText(ProgramInfo.getInstance().navigationForwardText()); buffer.append("</td></tr></table></td></tr></table></td></tr>"); boolean show = false; if (settings.isShowingPictureForPlugins()) { String[] pluginIds = settings.getPluginIds(); Marker[] markers = prog.getMarkerArr(); if (markers != null && pluginIds != null) { for (Marker marker : markers) { for (String pluginId : pluginIds) { if (marker.getId().compareTo(pluginId) == 0) { show = true; break; } } } } } Color foreground = Color.black;//Settings.propProgramPanelForegroundColor.getColor(); if (settings.isShowingPictureEver() || (settings.isShowingPictureInTimeRange() && !ProgramUtilities.isNotInTimeRange(settings.getPictureTimeRangeStart(), settings.getPictureTimeRangeEnd(), prog)) || show || (settings.isShowingPictureForDuration() && settings.getDuration() <= prog.getLength())) { byte[] image = prog.getBinaryField(ProgramFieldType.PICTURE_TYPE); if (image != null) { String line = "<tr><td></td><td valign=\"top\" style=\"color:rgb(" + foreground.getRed() + "," + foreground.getGreen() + "," + foreground.getBlue() + "); font-size:0\">"; buffer.append(line); try { ImageIcon imageIcon = new ImageIcon(image); if (zoom != 100) { imageIcon = (ImageIcon) UiUtilities.scaleIcon(imageIcon, imageIcon.getIconWidth() * zoom / 100); } StringBuilder value = new StringBuilder(); String textField = prog.getTextField(ProgramFieldType.PICTURE_COPYRIGHT_TYPE); if (textField != null) { value.append(textField); } if (settings.isShowingPictureDescription()) { textField = prog.getTextField(ProgramFieldType.PICTURE_DESCRIPTION_TYPE); if (textField != null) { value.append("<br>").append(textField); } } buffer.append(doc.createCompTag(new JLabel(imageIcon))); buffer.append("<div style=\"font-size:"); buffer.append(mBodyFontSize); buffer.append("\">"); buffer.append(value); buffer.append("</div>"); buffer.append("</td></tr>"); } catch (Exception e) { // Picture was wrong; buffer.delete(buffer.length() - line.length(), buffer.length()); } } } Marker[] pluginArr = prog.getMarkerArr(); if (showPluginIcons && (pluginArr != null) && (pluginArr.length != 0)) { addSeparator(doc, buffer); buffer.append("<tr><td valign=\"top\" style=\"color:#808080; font-size:"); buffer.append(mBodyFontSize); buffer.append("\"><b>"); buffer.append(mLocalizer.msg("markedBy", "Marked by")); buffer.append("</b></td><td valign=\"middle\" style=\"font-size:4\">"); openPara(buffer, "info"); // Workaround: Without the the component are not put in one line. buffer.append(" "); for (int markerCount = pluginArr.length - 1; markerCount >= 0; markerCount--) { Icon[] icons = pluginArr[markerCount].getMarkIcons(prog); if (icons != null) { for (int i = icons.length - 1; i >= 0; i--) { JLabel iconLabel = new JLabel(icons[i]); PluginAccess plugin = Plugin.getPluginManager() .getActivatedPluginForId(pluginArr[markerCount].getId()); if (plugin != null) { iconLabel.setToolTipText(plugin.getInfo().getName()); } else { InternalPluginProxyIf internalPlugin = InternalPluginProxyList.getInstance() .getProxyForId(pluginArr[markerCount].getId()); if (internalPlugin != null) { iconLabel.setToolTipText(internalPlugin.getName()); if (internalPlugin.equals(FavoritesPluginProxy.getInstance())) { // if this is a favorite, add the names of the favorite String favTitles = ""; for (Favorite favorite : FavoriteTreeModel.getInstance() .getFavoritesContainingProgram(prog)) { if (favTitles.length() > 0) { favTitles = favTitles + ", "; } favTitles = favTitles + favorite.getName(); } if (favTitles.length() > 0) { iconLabel.setToolTipText( iconLabel.getToolTipText() + " (" + favTitles + ")"); } } } else { iconLabel.setToolTipText(pluginArr[markerCount].toString()); } } buffer.append(doc.createCompTag(iconLabel)); buffer.append(" "); } } } closePara(buffer); buffer.append("</td></tr>"); } PluginAccess[] plugins = Plugin.getPluginManager().getActivatedPlugins(); ArrayList<JLabel> iconLabels = new ArrayList<JLabel>(); for (PluginAccess plugin : plugins) { Icon[] icons = plugin.getProgramTableIcons(prog); if (icons != null) { for (Icon icon : icons) { JLabel iconLabel = new JLabel(icon); iconLabel.setToolTipText(plugin.getInfo().getName()); iconLabels.add(iconLabel); } } } if (showPluginIcons && iconLabels.size() > 0) { addSeparator(doc, buffer); buffer.append("<tr><td valign=\"middle\" style=\"color:#808080; font-size:"); buffer.append(mBodyFontSize); buffer.append("\"><b>"); buffer.append("Plugin-Icons"); buffer.append("</b></td><td valign=\"top\" style=\"font-size:4\">"); openPara(buffer, "info"); // Workaround: Without the the component are not put in one line. buffer.append(" "); for (JLabel iconLabel : iconLabels) { buffer.append(doc.createCompTag(iconLabel)); buffer.append(" "); } closePara(buffer); buffer.append("</td></tr>"); } addSeparator(doc, buffer); for (Object id : fieldArr) { ProgramFieldType type = null; if (id instanceof String) { if (((String) id).matches("\\d+")) { try { type = ProgramFieldType.getTypeForId(Integer.parseInt((String) id, 10)); } catch (Exception e) { // Empty Catch } } if (type == null) { int length = prog.getLength(); if (length > 0 && ((String) id).trim().length() > 0) { buffer.append("<tr><td valign=\"top\" style=\"color:gray; font-size:"); buffer.append(mBodyFontSize); buffer.append("\"><b>"); buffer.append(mLocalizer.msg("duration", "Program duration/<br>-end")); buffer.append("</b></td><td style=\"color:rgb(" + foreground.getRed() + "," + foreground.getGreen() + "," + foreground.getBlue() + "); font-size:"); buffer.append(mBodyFontSize); buffer.append("\">"); openPara(buffer, "time"); String msg = mLocalizer.msg("minutes", "{0} min", length); buffer.append(msg).append(" ("); buffer.append(mLocalizer.msg("until", "until {0}", prog.getEndTimeString())); int netLength = prog.getIntField(ProgramFieldType.NET_PLAYING_TIME_TYPE); if (netLength != -1) { msg = mLocalizer.msg("netMinuted", "{0} min net", netLength); buffer.append(" - ").append(msg); } buffer.append(')'); closePara(buffer); buffer.append("</td></tr>"); addSeparator(doc, buffer); } } } else if (id instanceof CompoundedProgramFieldType) { CompoundedProgramFieldType value = (CompoundedProgramFieldType) id; String entry = value.getFormattedValueForProgram(prog); if (entry != null) { startInfoSection(buffer, value.getName()); buffer.append(HTMLTextHelper.convertTextToHtml(entry, false)); addSeparator(doc, buffer); } } else { type = (ProgramFieldType) id; if (type == ProgramFieldType.DESCRIPTION_TYPE) { String description = checkDescription(prog.getDescription()); if (description != null && description.length() > 0) { addEntry(doc, buffer, prog, ProgramFieldType.DESCRIPTION_TYPE, true, showHelpLinks, showPersonLinks); } else { addEntry(doc, buffer, prog, ProgramFieldType.SHORT_DESCRIPTION_TYPE, true, showHelpLinks, showPersonLinks); } } else if (type == ProgramFieldType.INFO_TYPE) { int info = prog.getInfo(); if ((info != -1) && (info != 0)) { buffer.append("<tr><td valign=\"top\" style=\"color:gray; font-size:"); buffer.append(mBodyFontSize); buffer.append("\"><b>"); buffer.append(type.getLocalizedName()); buffer.append("</b></td><td valign=\"middle\" style=\"font-size:5\">"); openPara(buffer, "info"); // Workaround: Without the the component are not put in one // line. buffer.append(" "); int[] infoBitArr = ProgramInfoHelper.getInfoBits(); Icon[] infoIconArr = ProgramInfoHelper.getInfoIcons(); String[] infoMsgArr = ProgramInfoHelper.getInfoIconMessages(); for (int i = 0; i < infoBitArr.length; i++) { if (ProgramInfoHelper.bitSet(info, infoBitArr[i])) { JLabel iconLabel; if (infoIconArr[i] != null) { iconLabel = new JLabel(infoIconArr[i]); } else { iconLabel = new JLabel(infoMsgArr[i]); } iconLabel.setToolTipText(infoMsgArr[i]); buffer.append(doc.createCompTag(iconLabel)); buffer.append(" "); } } closePara(buffer); buffer.append("</td></tr>"); addSeparator(doc, buffer); } } else if (type == ProgramFieldType.URL_TYPE) { addEntry(doc, buffer, prog, ProgramFieldType.URL_TYPE, true, showHelpLinks, showPersonLinks); } else if (type == ProgramFieldType.ACTOR_LIST_TYPE) { ArrayList<String> knownNames = new ArrayList<String>(); String[] recognizedActors = ProgramUtilities.getActorNames(prog); if (recognizedActors != null) { knownNames.addAll(Arrays.asList(recognizedActors)); } String actorField = prog.getTextField(type); if (actorField != null) { ArrayList<String>[] lists = ProgramUtilities.splitActors(prog); if (lists == null) { lists = splitActorsSimple(prog); } if (lists != null && lists[0].size() > 0) { startInfoSection(buffer, type.getLocalizedName()); buffer.append("<table border=\"0\" cellpadding=\"0\" style=\"font-family:"); buffer.append(bodyFont); buffer.append(";\">"); for (int i = 0; i < lists[0].size(); i++) { String[] parts = new String[2]; parts[0] = lists[0].get(i); parts[1] = ""; if (i < lists[1].size()) { parts[1] = lists[1].get(i); } int actorIndex = 0; if (showPersonLinks) { if (knownNames.contains(parts[0])) { parts[0] = addPersonLink(parts[0]); } else if (knownNames.contains(parts[1])) { parts[1] = addPersonLink(parts[1]); actorIndex = 1; } } buffer.append("<tr><td valign=\"top\">• </td><td valign=\"top\">"); buffer.append(parts[actorIndex]); buffer.append("</td><td width=\"10\"> </td>"); if (parts[1 - actorIndex].length() > 0) { buffer.append("<td valign=\"top\">"); buffer.append(parts[1 - actorIndex]); buffer.append("</td>"); } else { // if roles are missing add next actor in the same line if (i + 1 < lists[0].size() && lists[1].size() == 0) { i++; buffer.append( "<td valign=\"top\">• </td><td valign=\"top\">"); if (showPersonLinks) { buffer.append(addSearchLink(lists[0].get(i))); } else { buffer.append(lists[0].get(i)); } buffer.append("</td>"); } } buffer.append("</td></tr>"); } buffer.append("</table>"); buffer.append("</td></tr>"); addSeparator(doc, buffer); } else { addEntry(doc, buffer, prog, type, showHelpLinks, showPersonLinks); } } } else { addEntry(doc, buffer, prog, type, showHelpLinks, showPersonLinks); } } } if (showHelpLinks) { buffer.append( "<tr><td colspan=\"2\" valign=\"top\" align=\"center\" style=\"color:#808080; font-size:"); buffer.append(mBodyFontSize).append("\">"); buffer.append("<a href=\""); buffer.append( mLocalizer.msg("dataInfo", "http://wiki.tvbrowser.org/index.php/Qualit%C3%A4t_der_Daten")) .append("\">"); buffer.append(mLocalizer.msg("dataQuality", "Details of the data quality")); buffer.append("</a>"); buffer.append("</td></tr>"); } buffer.append("</table></html>"); return buffer.toString(); } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:util.ui.PictureAreaIcon.java
/** * Constructor for programs with picture. * * @param p The program with the picture. * @param f The font for the description. * @param width The width of this area.//www . ja va 2 s . c o m * @param showDescription If description should be shown. * @param grayFilter If the image should be filtered to gray if the program is expired. * @param zoom If the picture should be zoomed to width. */ public PictureAreaIcon(Program p, Font f, int width, boolean showDescription, boolean grayFilter, boolean zoom) { mProgram = p; mIsExpired = false; mIsGrayFilter = grayFilter; if (showDescription) { mDescriptionLines = Settings.propPictureDescriptionLines.getInt(); } else { mDescriptionLines = 0; } byte[] picture = p.getBinaryField(ProgramFieldType.PICTURE_TYPE); if (picture != null) { ImageIcon imic = new ImageIcon(picture); if (width == -1) { width = imic.getIconWidth() + 6; } if (imic.getIconWidth() > width - 6 || (zoom && imic.getIconWidth() != width)) { mScaledIcon = (ImageIcon) UiUtilities.scaleIcon(imic, width - 6); } else { mScaledIcon = imic; } } mCopyrightText = new TextAreaIcon(p.getTextField(ProgramFieldType.PICTURE_COPYRIGHT_TYPE), f.deriveFont((float) (f.getSize() * 0.9)), width - 6); String pictureText = showDescription ? p.getTextField(ProgramFieldType.PICTURE_DESCRIPTION_TYPE) : ""; if (StringUtils.isNotEmpty(pictureText)) { mDescriptionText = new TextAreaIcon(pictureText, f, width - 6); mDescriptionText.setMaximumLineCount(mDescriptionLines); } else { // reset show description as the string is empty mDescriptionLines = 0; } }
From source file:view.BackgroundImageController.java
public void setGraphBackgroundImage(final VisualizationViewer vv, final ImageIcon background, final double xOffset, final double yOffset) { removeBackgroundImage(vv);/*from ww w .jav a 2s . c o m*/ preRender = 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(background.getImage(), (int) Math.round(-background.getIconWidth() / xOffset), (int) Math.round(-background.getIconHeight() / yOffset), background.getIconWidth(), background.getIconHeight(), vv); g2d.setTransform(oldXform); } public boolean useTransform() { return false; } }; vv.addPreRenderPaintable(preRender); background.getImage().flush(); Runtime.getRuntime().gc(); }