List of usage examples for java.awt Color getGreen
public int getGreen()
From source file:com.jcraft.weirdx.XColormap.java
static void reqAllocNamedColor(Client c) throws IOException { int foo;/*from w ww .j a v a2 s .c o m*/ int n; int len; InputOutput io = c.client; n = c.length; foo = io.readInt(); XColormap cmap = (XColormap) XResource.lookupIDByType(foo, XResource.RT_COLORMAP); c.length -= 2; if (cmap == null) { c.errorValue = foo; c.errorReason = 12; // Colormap return; } len = io.readShort(); io.readPad(2); n = n - 3; n *= 4; n -= len; io.readByte(c.bbuffer, 0, len); io.readPad(n); c.length = 0; len = chopspace(c.bbuffer, len); if (len == 0) { c.errorReason = 2; // BadValue return; } String s = new String(c.bbuffer, 0, len); Color color = (Color) rgbTable.get(s); if (color != null) { int red = color.getRed(); int green = color.getGreen(); int blue = color.getBlue(); int i = cmap.allocColor(c, color.getRed(), color.getGreen(), color.getBlue()); if (c.errorReason != 0) { return; } if (cmap.visual.depth.depth != 16) { LocalEntry ent = (LocalEntry) cmap.entries[i]; red = ent.r; green = ent.g; blue = ent.b; if (ent.refcnt == 1) { cmap.mkIcm(); } } synchronized (io) { io.writeByte(1); io.writePad(1); io.writeShort(c.seq); io.writeInt(0); io.writeInt(i); io.writeShort(red | (red << 8)); io.writeShort(green | (green << 8)); io.writeShort(blue | (blue << 8)); io.writeShort(red | (red << 8)); io.writeShort(green | (green << 8)); io.writeShort(blue | (blue << 8)); io.writePad(8); io.flush(); return; } } synchronized (io) { io.writeByte((byte) 0); io.writeByte((byte) 15); io.writeShort(c.seq); io.writePad(4); io.writeShort(0); io.writeByte((byte) 85); io.writePad(21); io.flush(); } }
From source file:edu.ku.brc.specify.plugins.latlon.LatLonUI.java
/** * Creates the UI./*from ww w .j av a 2s. c om*/ * @param localityCEP the locality object (can be null) */ protected void createEditUI() { loadAndPushResourceBundle("specify_plugins"); PanelBuilder builder = new PanelBuilder(new FormLayout("p", "p, 2px, p"), this); Color bgColor = getBackground(); bgColor = new Color(Math.min(bgColor.getRed() + 20, 255), Math.min(bgColor.getGreen() + 20, 255), Math.min(bgColor.getBlue() + 20, 255)); //System.out.println(bgColor); setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(bgColor), BorderFactory.createEmptyBorder(4, 4, 4, 4))); for (int i = 0; i < types.length; i++) { typeMapper.put(types[i], typeStrs[i]); } currentType = LatLonUIIFace.LatLonType.LLPoint; pointImages = new ImageIcon[pointNames.length]; for (int i = 0; i < pointNames.length; i++) { pointImages[i] = IconManager.getIcon(pointNames[i], IconManager.IconSize.Std16); } String[] formatLabels = new String[formats.length]; for (int i = 0; i < formats.length; i++) { formatLabels[i] = getResourceString(formats[i]); } cardPanel = new JPanel(cardLayout); formatSelector = createComboBox(formatLabels); latLonPanes = new JComponent[formatLabels.length]; formatSelector.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { swapForm(formatSelector.getSelectedIndex(), currentType); cardLayout.show(cardPanel, ((JComboBox) ae.getSource()).getSelectedItem().toString()); //stateChanged(null); } }); Dimension preferredSize = new Dimension(0, 0); cardSubPanes = new JPanel[formats.length * 2]; panels = new DDDDPanel[formats.length * 2]; int paneInx = 0; for (int i = 0; i < formats.length; i++) { cardSubPanes[i] = new JPanel(new BorderLayout()); try { String packageName = "edu.ku.brc.specify.plugins.latlon."; DDDDPanel latLon1 = Class.forName(packageName + formatClass[i]).asSubclass(DDDDPanel.class) .newInstance(); latLon1.setIsRequired(isRequired); latLon1.setViewMode(isViewMode); latLon1.init(); latLon1.setChangeListener(this); JPanel panel1 = latLon1; panel1.setBorder(panelBorder); panels[paneInx++] = latLon1; latLonPanes[i] = panel1; DDDDPanel latlon2 = Class.forName(packageName + formatClass[i]).asSubclass(DDDDPanel.class) .newInstance(); latlon2.setIsRequired(isRequired); latlon2.setViewMode(isViewMode); latlon2.init(); latlon2.setChangeListener(this); panels[paneInx++] = latlon2; JTabbedPane tabbedPane = new JTabbedPane( UIHelper.getOSType() == UIHelper.OSTYPE.MacOSX ? SwingConstants.BOTTOM : SwingConstants.RIGHT); tabbedPane.addTab(null, pointImages[0], panels[paneInx - 2]); tabbedPane.addTab(null, pointImages[0], panels[paneInx - 1]); latLonPanes[i] = tabbedPane; Dimension size = tabbedPane.getPreferredSize(); preferredSize.width = Math.max(preferredSize.width, size.width); preferredSize.height = Math.max(preferredSize.height, size.height); tabbedPane.removeAll(); cardSubPanes[i].add(panel1, BorderLayout.CENTER); cardPanel.add(formatLabels[i], cardSubPanes[i]); /*if (locality != null) { latLon1.set(locality.getLatitude1(), locality.getLongitude1(), locality.getLat1text(), locality.getLong1text()); latlon2.set(locality.getLatitude2(), locality.getLongitude2(), locality.getLat2text(), locality.getLong2text()); }*/ } catch (Exception e) { e.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(LatLonUI.class, e); } } // Makes they are all the same size for (int i = 0; i < formats.length; i++) { cardSubPanes[i].setPreferredSize(preferredSize); } //final LatLonPanel thisPanel = this; PanelBuilder botBtnBar = new PanelBuilder(new FormLayout("p:g,p,10px,p,10px,p,p:g", "p")); ButtonGroup btnGroup = new ButtonGroup(); botBtns = new JToggleButton[typeNames.length]; if (UIHelper.isMacOS()) { /*for (int i=0;i<botBtns.length;i++) { ImageIcon selIcon = IconManager.getIcon(typeNames[i]+"Sel", IconManager.IconSize.Std16); ImageIcon unselIcon = IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16); MacIconRadioButton rb = new MacIconRadioButton(selIcon, unselIcon); botBtns[i] = rb; rb.setBorder(new MacBtnBorder()); Dimension size = rb.getPreferredSize(); int max = Math.max(size.width, size.height); size.setSize(max, max); rb.setPreferredSize(size); }*/ BorderedRadioButton.setSelectedBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); BorderedRadioButton.setUnselectedBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); for (int i = 0; i < botBtns.length; i++) { BorderedRadioButton rb = new BorderedRadioButton( IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16)); botBtns[i] = rb; rb.makeSquare(); rb.setBorder(new MacBtnBorder()); } } else { BorderedRadioButton.setSelectedBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); BorderedRadioButton.setUnselectedBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); for (int i = 0; i < botBtns.length; i++) { BorderedRadioButton rb = new BorderedRadioButton( IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16)); botBtns[i] = rb; rb.makeSquare(); } } for (int i = 0; i < botBtns.length; i++) { botBtns[i].setToolTipText(typeToolTips[i]); botBtnBar.add(botBtns[i], cc.xy((i * 2) + 2, 1)); btnGroup.add(botBtns[i]); selectedTypeHash.put(botBtns[i], types[i]); botBtns[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { stateChanged(null); currentType = selectedTypeHash.get(ce.getSource()); swapForm(formatSelector.getSelectedIndex(), currentType); } }); } botBtns[0].setSelected(true); if (isViewMode) { typeLabel = createLabel(" "); } ActionListener infoAL = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doPrefs(); } }; JButton infoBtn = UIHelper.createIconBtn("Preferences", IconManager.IconSize.Std16, getResourceString("PREFERENCES"), true, infoAL); infoBtn.setEnabled(true); PanelBuilder topPane = new PanelBuilder( new FormLayout("l:p, c:p:g" + (isViewMode ? "" : ",4px,p,8px"), "p")); topPane.add(formatSelector, cc.xy(1, 1)); topPane.add(isViewMode ? typeLabel : botBtnBar.getPanel(), cc.xy(2, 1)); if (!isViewMode) topPane.add(infoBtn, cc.xy(4, 1)); builder.add(topPane.getPanel(), cc.xy(1, 1)); builder.add(cardPanel, cc.xy(1, 3)); prefsPanel = new PrefsPanel(false); prefsPanel.add(getResourceString("LatLonUI.LL_SEP")); prefsPanel.add(CompType.eCheckbox, getResourceString("LatLonUI.LATDEF_DIR"), LAT_PREF, Boolean.class, true); prefsPanel.add(CompType.eCheckbox, getResourceString("LatLonUI.LONDEF_DIR"), LON_PREF, Boolean.class, true); prefsPanel.add(CompType.eComboBox, getResourceString("LatLonUI.DEF_TYP"), TYP_PREF, Integer.class, typeNamesLabels, 0); prefsPanel.add(CompType.eComboBox, getResourceString("LatLonUI.DEF_FMT"), FMT_PREF, Integer.class, formatLabels, 0); prefsPanel.createForm(null, null); popResourceBundle(); }
From source file:com.hygenics.imaging.ImageCleanup.java
/** * Private method that performs the sharpen */// www . j av a2 s. c o m public byte[] sharpen(byte[] ibytes, int weight, String format) { /* * Kernel is |-1|-1|-1| |-1|weight|-1||-1|-1|-1| */ try { InputStream is = new ByteArrayInputStream(ibytes); BufferedImage proxyimage = ImageIO.read(is); // a secondary image for storing new outcomes BufferedImage image2 = new BufferedImage(proxyimage.getWidth(), proxyimage.getHeight(), BufferedImage.TYPE_BYTE_GRAY); // image width and height int width = proxyimage.getWidth(); int height = proxyimage.getHeight(); int r = 0; int g = 0; int b = 0; Color c = null; for (int x = 1; x < width - 1; x++) { for (int y = 1; y < height - 1; y++) { // sharpen the image using the kernel (center is c5) Color c00 = new Color(proxyimage.getRGB(x - 1, y - 1)); Color c01 = new Color(proxyimage.getRGB(x - 1, y)); Color c02 = new Color(proxyimage.getRGB(x - 1, y + 1)); Color c10 = new Color(proxyimage.getRGB(x, y - 1)); Color c11 = new Color(proxyimage.getRGB(x, y)); Color c12 = new Color(proxyimage.getRGB(x, y + 1)); Color c20 = new Color(proxyimage.getRGB(x + 1, y - 1)); Color c21 = new Color(proxyimage.getRGB(x + 1, y)); Color c22 = new Color(proxyimage.getRGB(x + 1, y + 1)); // apply the kernel for r r = -c00.getRed() - c01.getRed() - c02.getRed() - c10.getRed() + (weight * c11.getRed()) - c12.getRed() - c20.getRed() - c21.getRed() - c22.getRed(); // apply the kernel for g g = c00.getGreen() - c01.getGreen() - c02.getGreen() - c10.getGreen() + (weight * c11.getGreen()) - c12.getGreen() - c20.getGreen() - c21.getGreen() - c22.getGreen(); // apply the transformation for b b = c00.getBlue() - c01.getBlue() - c02.getBlue() - c10.getBlue() + (weight * c11.getBlue()) - c12.getBlue() - c20.getBlue() - c21.getBlue() - c22.getBlue(); // set the new rgb values r = Math.min(255, Math.max(0, r)); g = Math.min(255, Math.max(0, g)); b = Math.min(255, Math.max(0, b)); c = new Color(r, g, b); // set the new mask colors in the new image image2.setRGB(x, y, c.getRGB()); } } // add the new values back to the original image Color cmask = null; Color corig = null; for (int x = 1; x < width - 1; x++) { for (int y = 1; y < height - 1; y++) { // get the 2 colors cmask = new Color(image2.getRGB(x, y)); corig = new Color(proxyimage.getRGB(x, y)); // add the new values r = cmask.getRed() + corig.getRed(); g = cmask.getGreen() + corig.getGreen(); b = cmask.getBlue() + corig.getBlue(); // set the new rgb values r = Math.min(255, Math.max(0, r)); g = Math.min(255, Math.max(0, g)); b = Math.min(255, Math.max(0, b)); proxyimage.setRGB(x, y, new Color(r, g, b).getRGB()); } } try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { ImageIO.write(proxyimage, format, baos); ibytes = baos.toByteArray(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ibytes; }
From source file:com.jcraft.weirdx.XColormap.java
static void reqStoreNamedColor(Client c) throws IOException { int foo, n, len, doc, pixel; InputOutput io = c.client;/* w ww .j a v a 2 s.com*/ doc = c.data; n = c.length; foo = io.readInt(); XColormap cmap = (XColormap) XResource.lookupIDByType(foo, XResource.RT_COLORMAP); c.length -= 2; if (cmap == null) { c.errorValue = foo; c.errorReason = 12; // Colormap return; } pixel = io.readInt(); len = io.readShort(); io.readPad(2); n = n - 4; n *= 4; n -= len; io.readByte(c.bbuffer, 0, len); io.readPad(n); c.length = 0; len = chopspace(c.bbuffer, len); if (len == 0) { c.errorReason = 2; // BadValue return; } String s = new String(c.bbuffer, 0, len); Color color = (Color) rgbTable.get(s); if (pixel == -1) { LOG.warn("?? pixel=" + pixel); pixel = 25; } int red = color.getRed(), green = color.getGreen(), blue = color.getBlue(); Color cp = cmap.colors[pixel]; if (cp != null) { if (doc != 0) { if ((doc & 1) == 0) red = cp.getRed(); if ((doc & 2) == 0) green = cp.getGreen(); if ((doc & 4) == 0) blue = cp.getBlue(); } } c.errorReason = cmap.storeColor(c, pixel, red, green, blue, doc); if (c.errorReason == 0) { cmap.mkIcm(); } }
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java
@Override public void setPaintScale(PaintScale ps) { Logger.getLogger(getClass().getName()).info("Set paint scale called on HeatmapPanel"); // if (ps != null && ps instanceof GradientPaintScale) { Logger.getLogger(getClass().getName()).info("Paint scale using!"); GradientPaintScale sps = (GradientPaintScale) ps; if (this.ps != null) { double lb = this.ps.getLowerBound(); double ub = this.ps.getUpperBound(); sps.setLowerBound(lb);/*from w w w . j a va2 s . com*/ sps.setUpperBound(ub); //this.jSlider1.setValue(0); } this.alpha = (int) sps.getAlpha(); this.beta = (int) sps.getBeta(); this.ps = sps; Color c = (Color) sps.getPaint(this.ps.getUpperBound()); if (chartPanel != null) { JFreeChart jfc = chartPanel.getChart(); if (jfc != null) { XYPlot plot = jfc.getXYPlot(); if (!jCheckBox2.isSelected()) { Color bg = (Color) this.ps.getPaint(this.ps.getLowerBound()); Logger.getLogger(getClass().getName()).log(Level.INFO, "Background color: {0}", bg); setBackgroundColor(bg); } } } selectionFill = new Color(c.getRed(), c.getBlue(), c.getGreen(), 192); selectionOutline = new Color(c.getRed(), c.getBlue(), c.getGreen()).darker(); this.jSlider1.setMaximum(100); this.jSlider1.setMinimum(0); handleSliderChange(); // } }
From source file:util.program.ProgramTextCreator.java
/** * * @param prog// w ww .ja va 2 s. c om * 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:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
public static void setBackgroundColor(Component cellRendererComponent, JTable tbl, Object oValue, boolean bSelected, boolean bHasFocus, int iRow, int iColumn) { cellRendererComponent.setBackground(bSelected ? tbl.getSelectionBackground() : iRow % 2 == 0 ? tbl.getBackground() : NuclosThemeSettings.BACKGROUND_PANEL); cellRendererComponent.setForeground(bSelected ? tbl.getSelectionForeground() : tbl.getForeground()); final TableModel tm; final int adjustColIndex; if (tbl instanceof FixedColumnRowHeader.HeaderTable && ((FixedColumnRowHeader.HeaderTable) tbl).getExternalTable() != null) { tm = ((FixedColumnRowHeader.HeaderTable) tbl).getExternalTable().getModel(); adjustColIndex = FixedRowIndicatorTableModel.ROWMARKERCOLUMN_COUNT; } else {//from w ww . j a v a2 s . c o m tm = tbl.getModel(); adjustColIndex = 0; } // check whether the data of the component is readable for current user, by asking the security agent of the actual field if (tm instanceof SortableCollectableTableModel<?>) { final SortableCollectableTableModel<Collectable> tblModel = (SortableCollectableTableModel<Collectable>) tm; if (tblModel.getRowCount() > iRow) { final Collectable clct = tblModel.getCollectable(iRow); final Integer iTColumn = tbl.getColumnModel().getColumn(iColumn).getModelIndex() - adjustColIndex; final CollectableEntityField clctef = tblModel.getCollectableEntityField(iTColumn); if (clctef == null) { throw new NullPointerException("getTableCellRendererComponent failed to find field: " + clct + " tm index " + iTColumn); } boolean isEnabled = true; if (!clctef.isNullable() && isNull(oValue)) { cellRendererComponent.setBackground(getMandatoryColor()); cellRendererComponent.setForeground(tbl.getForeground()); } else { // if (clct.getId() == null) { // cellRendererComponent.setBackground(tbl.getBackground()); // cellRendererComponent.setForeground(tbl.getForeground()); // } else { if (tbl instanceof SubForm.SubFormTable) { SubFormTable subformtable = (SubForm.SubFormTable) tbl; Column subformcolumn = subformtable.getSubForm().getColumn(clctef.getName()); if (subformcolumn != null && !subformcolumn.isEnabled()) { isEnabled = false; if (bSelected) { cellRendererComponent .setBackground(NuclosThemeSettings.BACKGROUND_INACTIVESELECTEDCOLUMN); } else { cellRendererComponent.setBackground(NuclosThemeSettings.BACKGROUND_INACTIVECOLUMN); } } } // } try { EntityMetaDataVO meta = MetaDataClientProvider.getInstance() .getEntity(clctef.getEntityName()); if (meta.getRowColorScript() != null && !bSelected) { AbstractCollectableComponent.setBackground(cellRendererComponent, meta.getRowColorScript(), clct, meta, isEnabled); } } catch (CommonFatalException ex) { LOG.warn(ex); } } } } if (tbl instanceof TableRowMouseOverSupport) { TableRowMouseOverSupport trmos = (TableRowMouseOverSupport) tbl; if (trmos.isMouseOverRow(iRow)) { final Color bgColor = LangUtils.defaultIfNull(cellRendererComponent.getBackground(), Color.WHITE); cellRendererComponent .setBackground(new Color(Math.max(0, bgColor.getRed() - (bgColor.getRed() * 8 / 100)), Math.max(0, bgColor.getGreen() - (bgColor.getGreen() * 8 / 100)), Math.max(0, bgColor.getBlue() - (bgColor.getBlue() * 8 / 100)))); // cellRendererComponent.setBackground(UIManager.getColor("Table.selectionBackground")); } } }
From source file:AnimatedGifEncoder.java
/** * Returns index of palette color closest to c * // ww w .ja v a2 s . co m */ protected int findClosest(Color c) { if (colorTab == null) return -1; int r = c.getRed(); int g = c.getGreen(); int b = c.getBlue(); int minpos = 0; int dmin = 256 * 256 * 256; int len = colorTab.length; for (int i = 0; i < len;) { int dr = r - (colorTab[i++] & 0xff); int dg = g - (colorTab[i++] & 0xff); int db = b - (colorTab[i] & 0xff); int d = dr * dr + dg * dg + db * db; int index = i / 3; if (usedEntry[index] && (d < dmin)) { dmin = d; minpos = index; } i++; } return minpos; }
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
/** * Internal implementation to add a topic map to a slide. * @param slide the slide to add to.// ww w . j a v a 2 s . co m * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates. * @param data the topic map data. */ private static void addTopicMap(final XSLFSlide slide, final Rectangle2D.Double anchor, final TopicMapData data) { for (final TopicMapData.Path reqPath : data.getPaths()) { final XSLFFreeformShape shape = slide.createFreeform(); final Path2D.Double path = new Path2D.Double(); boolean first = true; for (double[] point : reqPath.getPoints()) { final double x = point[0] * anchor.getWidth() + anchor.getMinX(); final double y = point[1] * anchor.getHeight() + anchor.getMinY(); if (first) { path.moveTo(x, y); first = false; } else { path.lineTo(x, y); } } path.closePath(); shape.setPath(path); shape.setStrokeStyle(2); shape.setLineColor(Color.GRAY); shape.setHorizontalCentered(true); shape.setVerticalAlignment(VerticalAlignment.MIDDLE); shape.setTextAutofit(TextShape.TextAutofit.NORMAL); final XSLFTextParagraph text = shape.addNewTextParagraph(); final XSLFTextRun textRun = text.addNewTextRun(); textRun.setText(reqPath.name); textRun.setFontColor(Color.WHITE); textRun.setBold(true); final CTShape cs = (CTShape) shape.getXmlObject(); double max = 100, min = 1, scale = 100; final CTTextNormalAutofit autoFit = cs.getTxBody().getBodyPr().getNormAutofit(); final double availHeight = path.getBounds2D().getHeight(); final int RESIZE_ATTEMPTS = 7; for (int attempts = 0; attempts < RESIZE_ATTEMPTS; ++attempts) { // PowerPoint doesn't resize the text till you edit it once, which means the text initially looks too // large when you first view the slide; so we binary-chop to get a sensible initial approximation. // OpenOffice does the text resize on load so it doesn't have this problem. autoFit.setFontScale(Math.max(1, (int) (scale * 1000))); final double textHeight = shape.getTextHeight(); if (textHeight < availHeight) { min = scale; scale = 0.5 * (min + max); } else if (textHeight > availHeight) { max = scale; scale = 0.5 * (min + max); } else { break; } } final int opacity = (int) (100000 * reqPath.getOpacity()); final Color c1 = Color.decode(reqPath.getColor()); final Color c2 = Color.decode(reqPath.getColor2()); final CTGradientFillProperties gFill = cs.getSpPr().addNewGradFill(); gFill.addNewLin().setAng(3300000); final CTGradientStopList list = gFill.addNewGsLst(); final CTGradientStop stop1 = list.addNewGs(); stop1.setPos(0); final CTSRgbColor color1 = stop1.addNewSrgbClr(); color1.setVal(new byte[] { (byte) c1.getRed(), (byte) c1.getGreen(), (byte) c1.getBlue() }); color1.addNewAlpha().setVal(opacity); final CTGradientStop stop2 = list.addNewGs(); stop2.setPos(100000); final CTSRgbColor color2 = stop2.addNewSrgbClr(); color2.setVal(new byte[] { (byte) c2.getRed(), (byte) c2.getGreen(), (byte) c2.getBlue() }); color2.addNewAlpha().setVal(opacity); if (reqPath.level > 0) { // The nodes which aren't leaf nodes can be clicked on to hide them so you can see the nodes underneath. // This only works in PowerPoint; OpenOffice doesn't seem to support it. OpenOffice has its own syntax // to do something similar, but we don't use it since PowerPoint treats it as corrupt. final String shapeId = Integer.toString(shape.getShapeId()); final CTSlide slXML = slide.getXmlObject(); final CTTimeNodeList childTnLst; final CTBuildList bldLst; if (!slXML.isSetTiming()) { final CTSlideTiming timing = slXML.addNewTiming(); final CTTLCommonTimeNodeData ctn = timing.addNewTnLst().addNewPar().addNewCTn(); ctn.setDur("indefinite"); ctn.setRestart(STTLTimeNodeRestartTypeImpl.NEVER); ctn.setNodeType(STTLTimeNodeType.TM_ROOT); childTnLst = ctn.addNewChildTnLst(); bldLst = timing.addNewBldLst(); } else { final CTSlideTiming timing = slXML.getTiming(); childTnLst = timing.getTnLst().getParArray(0).getCTn().getChildTnLst(); bldLst = timing.getBldLst(); } final CTTLTimeNodeSequence seq = childTnLst.addNewSeq(); seq.setConcurrent(true); seq.setNextAc(STTLNextActionType.SEEK); final CTTLCommonTimeNodeData common = seq.addNewCTn(); common.setRestart(STTLTimeNodeRestartType.WHEN_NOT_ACTIVE); common.setFill(STTLTimeNodeFillType.HOLD); common.setEvtFilter("cancelBubble"); common.setNodeType(STTLTimeNodeType.INTERACTIVE_SEQ); final CTTLTimeConditionList condList = common.addNewStCondLst(); final CTTLTimeCondition cond = condList.addNewCond(); cond.setEvt(STTLTriggerEvent.ON_CLICK); cond.setDelay(0); cond.addNewTgtEl().addNewSpTgt().setSpid(shapeId); final CTTLTimeCondition endSync = common.addNewEndSync(); endSync.setEvt(STTLTriggerEvent.END); endSync.setDelay(0); endSync.addNewRtn().setVal(STTLTriggerRuntimeNode.ALL); // These holdCtn* 'hold' transitions with zero delay might seem redundant; but they're exported in the // PowerPoint XML, and the online PowerPoint Office365 viewer won't support the click animations // unless they're present (e.g. from the 'Start Slide Show' button in the browser). final CTTLCommonTimeNodeData holdCtn1 = common.addNewChildTnLst().addNewPar().addNewCTn(); holdCtn1.setFill(STTLTimeNodeFillType.HOLD); holdCtn1.addNewStCondLst().addNewCond().setDelay(0); final CTTLCommonTimeNodeData holdCtn2 = holdCtn1.addNewChildTnLst().addNewPar().addNewCTn(); holdCtn2.setFill(STTLTimeNodeFillType.HOLD); holdCtn2.addNewStCondLst().addNewCond().setDelay(0); final CTTLCommonTimeNodeData clickCtn = holdCtn2.addNewChildTnLst().addNewPar().addNewCTn(); clickCtn.setPresetID(10); clickCtn.setPresetClass(STTLTimeNodePresetClassType.EXIT); clickCtn.setPresetSubtype(0); clickCtn.setFill(STTLTimeNodeFillType.HOLD); clickCtn.setGrpId(0); clickCtn.setNodeType(STTLTimeNodeType.CLICK_EFFECT); clickCtn.addNewStCondLst().addNewCond().setDelay(0); final CTTimeNodeList clickChildTnList = clickCtn.addNewChildTnLst(); final CTTLAnimateEffectBehavior animEffect = clickChildTnList.addNewAnimEffect(); animEffect.setTransition(STTLAnimateEffectTransition.OUT); animEffect.setFilter("fade"); final CTTLCommonBehaviorData cBhvr = animEffect.addNewCBhvr(); final CTTLCommonTimeNodeData bhvrCtn = cBhvr.addNewCTn(); bhvrCtn.setDur(500); cBhvr.addNewTgtEl().addNewSpTgt().setSpid(shapeId); final CTTLSetBehavior clickSet = clickChildTnList.addNewSet(); final CTTLCommonBehaviorData clickSetBhvr = clickSet.addNewCBhvr(); final CTTLCommonTimeNodeData hideCtn = clickSetBhvr.addNewCTn(); hideCtn.setDur(1); hideCtn.setFill(STTLTimeNodeFillType.HOLD); hideCtn.addNewStCondLst().addNewCond().setDelay(499); clickSetBhvr.addNewTgtEl().addNewSpTgt().setSpid(shapeId); clickSetBhvr.addNewAttrNameLst().addAttrName("style.visibility"); clickSet.addNewTo().addNewStrVal().setVal("hidden"); final CTTLBuildParagraph bldP = bldLst.addNewBldP(); bldP.setSpid(shapeId); bldP.setGrpId(0); bldP.setAnimBg(true); } } }
From source file:org.apache.pdfbox.pdmodel.edit.PDPageContentStream.java
/** * Set the stroking color, specified as RGB. * * @param color The color to set./*from ww w. j a v a2 s . co m*/ * @throws IOException If an IO error occurs while writing to the stream. */ public void setStrokingColor(Color color) throws IOException { ColorSpace colorSpace = color.getColorSpace(); if (colorSpace.getType() == ColorSpace.TYPE_RGB) { setStrokingColor(color.getRed(), color.getGreen(), color.getBlue()); } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) { color.getColorComponents(colorComponents); setStrokingColor(colorComponents[0]); } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) { color.getColorComponents(colorComponents); setStrokingColor(colorComponents[0], colorComponents[2], colorComponents[2], colorComponents[3]); } else { throw new IOException("Error: unknown colorspace:" + colorSpace); } }