List of usage examples for java.awt Color getBlue
public int getBlue()
From source file:edu.ku.brc.af.ui.forms.ViewFactory.java
/** * @param props// ww w . j a v a 2 s . com * @param bgColor * @return */ protected Color getBackgroundColor(final Properties props, final Color bgColor) { if (props != null) { String colorStr = props.getProperty("bgcolor"); if (StringUtils.isNotEmpty(colorStr)) { if (colorStr.endsWith("%")) { try { int percent = Integer.parseInt(colorStr.substring(0, colorStr.length() - 1)); double per = (percent / 100.0); int r = Math.min((int) (bgColor.getRed() * per), 255); int g = Math.min((int) (bgColor.getGreen() * per), 255); int b = Math.min((int) (bgColor.getBlue() * per), 255); return new Color(r, g, b); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ViewFactory.class, ex); log.error(ex); } } else { try { return UIHelper.parseRGB(colorStr); } catch (ConfigurationException ex) { log.error(ex); } } } } return bgColor; }
From source file:forge.toolbox.FSkin.java
/** Returns RGB components of a color, with a new * value for alpha. 0 = transparent, 255 = opaque. * * @param clr0 {@link java.awt.Color}/*from www . j ava2 s . c o m*/ * @param alpha int * @return {@link java.awt.Color} */ public static Color alphaColor(final Color clr0, final int alpha) { return new Color(clr0.getRed(), clr0.getGreen(), clr0.getBlue(), alpha); }
From source file:forge.toolbox.FSkin.java
/** Steps RGB components of a color up or down. * Returns opaque (non-alpha) stepped color. * Plus for lighter, minus for darker./*from w ww . ja v a 2s .c o m*/ * * @param clr0 {@link java.awt.Color} * @param step int * @return {@link java.awt.Color} */ public static Color stepColor(final Color clr0, final int step) { int r = clr0.getRed(); int g = clr0.getGreen(); int b = clr0.getBlue(); // Darker if (step < 0) { r = ((r + step > 0) ? r + step : 0); g = ((g + step > 0) ? g + step : 0); b = ((b + step > 0) ? b + step : 0); } else { r = ((r + step < 255) ? r + step : 255); g = ((g + step < 255) ? g + step : 255); b = ((b + step < 255) ? b + step : 255); } return new Color(r, g, b); }
From source file:forge.toolbox.FSkin.java
/** * @see <a href="http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx"> * http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx</a> *//*from w ww . j av a 2 s. c o m*/ public static boolean isColorBright(final Color c) { final int v = (int) Math.sqrt(c.getRed() * c.getRed() * 0.241 + c.getGreen() * c.getGreen() * 0.691 + c.getBlue() * c.getBlue() * 0.068); return v >= 130; }
From source file:plugins.tprovoost.Microscopy.MicroManagerForIcy.MMMainFrame.java
/** * Singleton pattern : private constructor Use instead. *//*from w ww .ja v a 2 s . c om*/ private MMMainFrame() { super(NODE_NAME, false, true, false, true); instancing = true; // -------------- // INITIALIZATION // -------------- _sysConfigFile = ""; _isConfigLoaded = false; _root = PluginPreferences.getPreferences().node(NODE_NAME); final MainFrame mainFrame = Icy.getMainInterface().getMainFrame(); // -------------- // PROGRESS FRAME // -------------- ThreadUtil.invokeLater(new Runnable() { @Override public void run() { _progressFrame = new IcyFrame("", false, false, false, false); _progressBar = new JProgressBar(); _progressBar.setString("Please wait while loading..."); _progressBar.setStringPainted(true); _progressBar.setIndeterminate(true); _progressBar.setMinimum(0); _progressBar.setMaximum(1000); _progressBar.setBounds(50, 50, 100, 30); _progressFrame.setSize(300, 100); _progressFrame.setResizable(false); _progressFrame.add(_progressBar); _progressFrame.addToMainDesktopPane(); loadConfig(true); if (_sysConfigFile == "") { instancing = false; return; } ThreadUtil.bgRun(new Runnable() { @Override public void run() { while (!_isConfigLoaded) { if (!instancing) return; try { Thread.sleep(10); } catch (InterruptedException e) { } } ThreadUtil.invokeLater(new Runnable() { @Override public void run() { // -------------------- // START INITIALIZATION // -------------------- if (_progressBar != null) getContentPane().remove(_progressBar); if (mCore == null) { close(); return; } // ReportingUtils.setCore(mCore); _afMgr = new AutofocusManager(MMMainFrame.this); acqMgr = new AcquisitionManager(); PositionList posList = new PositionList(); _camera_label = MMCoreJ.getG_Keyword_CameraName(); if (_camera_label == null) _camera_label = ""; try { setPositionList(posList); } catch (MMScriptException e1) { e1.printStackTrace(); } posListDlg_ = new PositionListDlg(mCore, MMMainFrame.this, _posList, null, dlg); posListDlg_.setModalityType(ModalityType.APPLICATION_MODAL); callback = new EventCallBackManager(); mCore.registerCallback(callback); engine_ = new AcquisitionWrapperEngineIcy(); engine_.setParentGUI(MMMainFrame.this); engine_.setCore(mCore, getAutofocusManager()); engine_.setPositionList(getPositionList()); setSystemMenuCallback(new MenuCallback() { @Override public JMenu getMenu() { JMenu toReturn = MMMainFrame.this.getDefaultSystemMenu(); JMenuItem hconfig = new JMenuItem("Configuration Wizard"); hconfig.setIcon(new IcyIcon("cog", MENU_ICON_SIZE)); hconfig.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!_pluginListEmpty && !ConfirmDialog.confirm("Are you sure ?", "<html>Loading the Configuration Wizard will unload all the devices and pause all running acquisitions.</br> Are you sure you want to continue ?</html>")) return; notifyConfigAboutToChange(null); try { mCore.unloadAllDevices(); } catch (Exception e1) { e1.printStackTrace(); } String previous_config = _sysConfigFile; ConfiguratorDlg2 configurator = new ConfiguratorDlg2(mCore, _sysConfigFile); configurator.setVisible(true); String res = configurator.getFileName(); if (_sysConfigFile == "" || _sysConfigFile == res || res == "") { _sysConfigFile = previous_config; loadConfig(); } refreshGUI(); notifyConfigChanged(null); } }); JMenuItem menuPxSizeConfigItem = new JMenuItem("Pixel Size Config"); menuPxSizeConfigItem.setIcon(new IcyIcon("link", MENU_ICON_SIZE)); menuPxSizeConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); menuPxSizeConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CalibrationListDlg dlg = new CalibrationListDlg(mCore); dlg.setDefaultCloseOperation(2); dlg.setParentGUI(MMMainFrame.this); dlg.setVisible(true); dlg.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { super.windowClosed(e); notifyConfigChanged(null); } }); notifyConfigAboutToChange(null); } }); JMenuItem loadConfigItem = new JMenuItem("Load Configuration"); loadConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); loadConfigItem.setIcon(new IcyIcon("folder_open", MENU_ICON_SIZE)); loadConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { loadConfig(); initializeGUI(); refreshGUI(); } }); JMenuItem saveConfigItem = new JMenuItem("Save Configuration"); saveConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); saveConfigItem.setIcon(new IcyIcon("save", MENU_ICON_SIZE)); saveConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveConfig(); } }); JMenuItem advancedConfigItem = new JMenuItem("Advanced Configuration"); advancedConfigItem.setIcon(new IcyIcon("wrench_plus", MENU_ICON_SIZE)); advancedConfigItem.addActionListener(new ActionListener() { /** */ @Override public void actionPerformed(ActionEvent e) { new ToolTipFrame( "<html><h3>About Advanced Config</h3><p>Advanced Configuration is a tool " + "in which you fill some data <br/>about your configuration that some " + "plugins may need to access to.<br/> Exemple: the real values of the magnification" + "of your objectives.</p></html>", "MM4IcyAdvancedConfig"); if (advancedDlg == null) advancedDlg = new AdvancedConfigurationDialog(); advancedDlg.setVisible(!advancedDlg.isVisible()); advancedDlg.setLocationRelativeTo(mainFrame); } }); JMenuItem loadPresetConfigItem = new JMenuItem( "Load Configuration Presets"); loadPresetConfigItem.setIcon(new IcyIcon("doc_import", MENU_ICON_SIZE)); loadPresetConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { notifyConfigAboutToChange(null); loadPresets(); notifyConfigChanged(null); } }); JMenuItem savePresetConfigItem = new JMenuItem( "Save Configuration Presets"); savePresetConfigItem.setIcon(new IcyIcon("doc_export", MENU_ICON_SIZE)); savePresetConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { savePresets(); } }); JMenuItem aboutItem = new JMenuItem("About"); aboutItem.setIcon(new IcyIcon("info", MENU_ICON_SIZE)); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JDialog dialog = new JDialog(mainFrame, "About"); JPanel panel_container = new JPanel(); panel_container .setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); JPanel center = new JPanel(new BorderLayout()); final JLabel value = new JLabel("<html><body>" + "<h2>About</h2><p>Micro-Manager for Icy is being developed by Thomas Provoost." + "<br/>Copyright 2011, Institut Pasteur</p><br/>" + "<p>This plugin is based on Micro-Manager v1.4.6. which is developed under the following license:<br/>" + "<i>This software is distributed free of charge in the hope that it will be<br/>" + "useful, but WITHOUT ANY WARRANTY; without even the implied<br/>" + "warranty of merchantability or fitness for a particular purpose. In no<br/>" + "event shall the copyright owner or contributors be liable for any direct,<br/>" + "indirect, incidental spacial, examplary, or consequential damages.<br/>" + "Copyright University of California San Francisco, 2007, 2008, 2009,<br/>" + "2010. All rights reserved.</i>" + "</p>" + "</body></html>"); JLabel link = new JLabel( "<html><a href=\"\">For more information, please follow this link.</a></html>"); link.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent mouseevent) { NetworkUtil.openBrowser( "http://valelab.ucsf.edu/~MM/MMwiki/index.php/Micro-Manager"); } }); value.setSize(new Dimension(50, 18)); value.setAlignmentX(SwingConstants.HORIZONTAL); value.setBorder(BorderFactory.createEmptyBorder(0, 0, 20, 0)); center.add(value, BorderLayout.CENTER); center.add(link, BorderLayout.SOUTH); JPanel panel_south = new JPanel(); panel_south.setLayout(new BoxLayout(panel_south, BoxLayout.X_AXIS)); JButton btn = new JButton("OK"); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionevent) { dialog.dispose(); } }); panel_south.add(Box.createHorizontalGlue()); panel_south.add(btn); panel_south.add(Box.createHorizontalGlue()); dialog.setLayout(new BorderLayout()); panel_container.setLayout(new BorderLayout()); panel_container.add(center, BorderLayout.CENTER); panel_container.add(panel_south, BorderLayout.SOUTH); dialog.add(panel_container, BorderLayout.CENTER); dialog.setResizable(false); dialog.setVisible(true); dialog.pack(); dialog.setLocation( (int) mainFrame.getSize().getWidth() / 2 - dialog.getWidth() / 2, (int) mainFrame.getSize().getHeight() / 2 - dialog.getHeight() / 2); dialog.setLocationRelativeTo(mainFrame); } }); JMenuItem propertyBrowserItem = new JMenuItem("Property Browser"); propertyBrowserItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, SHORTCUTKEY_MASK)); propertyBrowserItem.setIcon(new IcyIcon("db", MENU_ICON_SIZE)); propertyBrowserItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editor.setVisible(!editor.isVisible()); } }); int idx = 0; toReturn.insert(hconfig, idx++); toReturn.insert(loadConfigItem, idx++); toReturn.insert(saveConfigItem, idx++); toReturn.insert(advancedConfigItem, idx++); toReturn.insertSeparator(idx++); toReturn.insert(loadPresetConfigItem, idx++); toReturn.insert(savePresetConfigItem, idx++); toReturn.insertSeparator(idx++); toReturn.insert(propertyBrowserItem, idx++); toReturn.insert(menuPxSizeConfigItem, idx++); toReturn.insertSeparator(idx++); toReturn.insert(aboutItem, idx++); return toReturn; } }); saveConfigButton_ = new JButton("Save Button"); // SETUP _groupPad = new ConfigGroupPad(); _groupPad.setParentGUI(MMMainFrame.this); _groupPad.setFont(new Font("", 0, 10)); _groupPad.setCore(mCore); _groupPad.setParentGUI(MMMainFrame.this); _groupButtonsPanel = new ConfigButtonsPanel(); _groupButtonsPanel.setCore(mCore); _groupButtonsPanel.setGUI(MMMainFrame.this); _groupButtonsPanel.setConfigPad(_groupPad); // LEFT PART OF INTERFACE _panelConfig = new JPanel(); _panelConfig.setLayout(new BoxLayout(_panelConfig, BoxLayout.Y_AXIS)); _panelConfig.add(_groupPad, BorderLayout.CENTER); _panelConfig.add(_groupButtonsPanel, BorderLayout.SOUTH); _panelConfig.setPreferredSize(new Dimension(300, 300)); // MIDDLE PART OF INTERFACE _panel_cameraSettings = new JPanel(); _panel_cameraSettings.setLayout(new GridLayout(5, 2)); _panel_cameraSettings.setMinimumSize(new Dimension(100, 200)); _txtExposure = new JTextField(); try { mCore.setExposure(90.0D); _txtExposure.setText(String.valueOf(mCore.getExposure())); } catch (Exception e2) { _txtExposure.setText("90"); } _txtExposure.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20)); _txtExposure.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent keyevent) { if (keyevent.getKeyCode() == KeyEvent.VK_ENTER) setExposure(); } }); _panel_cameraSettings.add(new JLabel("Exposure [ms]: ")); _panel_cameraSettings.add(_txtExposure); _combo_binning = new JComboBox(); _combo_binning.setMaximumRowCount(4); _combo_binning.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25)); _combo_binning.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { changeBinning(); } }); _panel_cameraSettings.add(new JLabel("Binning: ")); _panel_cameraSettings.add(_combo_binning); _combo_shutters = new JComboBox(); _combo_shutters.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { if (_combo_shutters.getSelectedItem() != null) { mCore.setShutterDevice((String) _combo_shutters.getSelectedItem()); _prefs.put(PREF_SHUTTER, (String) _combo_shutters .getItemAt(_combo_shutters.getSelectedIndex())); } } catch (Exception e) { e.printStackTrace(); } } }); _combo_shutters.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25)); _panel_cameraSettings.add(new JLabel("Shutter : ")); _panel_cameraSettings.add(_combo_shutters); ActionListener action_listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateHistogram(); } }; _cbAbsoluteHisto = new JCheckBox(); _cbAbsoluteHisto.addActionListener(action_listener); _cbAbsoluteHisto.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionevent) { _comboBitDepth.setEnabled(_cbAbsoluteHisto.isSelected()); _prefs.putBoolean(PREF_ABS_HIST, _cbAbsoluteHisto.isSelected()); } }); _panel_cameraSettings.add(new JLabel("Display absolute histogram ?")); _panel_cameraSettings.add(_cbAbsoluteHisto); _comboBitDepth = new JComboBox(new String[] { "8-bit", "9-bit", "10-bit", "11-bit", "12-bit", "13-bit", "14-bit", "15-bit", "16-bit" }); _comboBitDepth.addActionListener(action_listener); _comboBitDepth.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionevent) { _prefs.putInt(PREF_BITDEPTH, _comboBitDepth.getSelectedIndex()); } }); _comboBitDepth.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20)); _comboBitDepth.setEnabled(false); _panel_cameraSettings.add(new JLabel("Select your bit depth for abs. hitogram: ")); _panel_cameraSettings.add(_comboBitDepth); // Acquisition _panelAcquisitions = new JPanel(); _panelAcquisitions.setLayout(new BoxLayout(_panelAcquisitions, BoxLayout.Y_AXIS)); // Color settings _panelColorChooser = new JPanel(); _panelColorChooser.setLayout(new BoxLayout(_panelColorChooser, BoxLayout.Y_AXIS)); painterPreferences = MicroscopePainterPreferences.getInstance(); painterPreferences.setPreferences(_prefs.node("paintersPreferences")); painterPreferences.loadColors(); HashMap<String, Color> allColors = painterPreferences.getColors(); String[] allKeys = (String[]) allColors.keySet().toArray(new String[0]); String[] columnNames = { "Painter", "Color", "Transparency" }; Object[][] data = new Object[allKeys.length][3]; for (int i = 0; i < allKeys.length; ++i) { final int actualRow = i; String actualKey = allKeys[i].toString(); data[i][0] = actualKey; data[i][1] = allColors.get(actualKey); final JSlider slider = new JSlider(0, 255, allColors.get(actualKey).getAlpha()); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent changeevent) { painterTable.setValueAt(slider, actualRow, 2); } }); data[i][2] = slider; } final AbstractTableModel tableModel = new JTableEvolvedModel(columnNames, data); painterTable = new JTable(tableModel); painterTable.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent tablemodelevent) { if (tablemodelevent.getType() == TableModelEvent.UPDATE) { int row = tablemodelevent.getFirstRow(); int col = tablemodelevent.getColumn(); String columnName = tableModel.getColumnName(col); String painterName = (String) tableModel.getValueAt(row, 0); if (columnName.contains("Color")) { // New color value int alpha = painterPreferences.getColor(painterName).getAlpha(); Color coloNew = (Color) tableModel.getValueAt(row, 1); painterPreferences.setColor(painterName, new Color(coloNew.getRed(), coloNew.getGreen(), coloNew.getBlue(), alpha)); } else if (columnName.contains("Transparency")) { // New alpha value Color c = painterPreferences.getColor(painterName); int alphaValue = ((JSlider) tableModel.getValueAt(row, 2)) .getValue(); painterPreferences.setColor(painterName, new Color(c.getRed(), c.getGreen(), c.getBlue(), alphaValue)); } /* * for (int i = 0; i < * tableModel.getRowCount(); ++i) { try { * String painterName = (String) * tableModel.getValueAt(i, 0); Color c = * (Color) tableModel.getValueAt(i, 1); int * alphaValue; if (ASpinnerChanged && * tablemodelevent.getFirstRow() == i) { * alphaValue = ((JSlider) * tableModel.getValueAt(i, 2)).getValue(); * } else { alphaValue = * painterPreferences.getColor * (painterPreferences * .getPainterName(i)).getAlpha(); } * painterPreferences.setColor(painterName, * new Color(c.getRed(), c.getGreen(), * c.getBlue(), alphaValue)); } catch * (Exception e) { System.out.println( * "error with painter table update"); } } */ } } }); painterTable.setPreferredScrollableViewportSize(new Dimension(500, 70)); painterTable.setFillsViewportHeight(true); // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(painterTable); // Set up renderer and editor for the Favorite Color // column. painterTable.setDefaultRenderer(Color.class, new ColorRenderer(true)); painterTable.setDefaultEditor(Color.class, new ColorEditor()); painterTable.setDefaultRenderer(JSlider.class, new SliderRenderer(0, 255)); painterTable.setDefaultEditor(JSlider.class, new SliderEditor()); _panelColorChooser.add(scrollPane); _panelColorChooser.add(Box.createVerticalGlue()); _mainPanel = new JPanel(); _mainPanel.setLayout(new BorderLayout()); // EDITOR // will refresh the data and verify if any change // occurs. // editor = new PropertyEditor(MMMainFrame.this); // editor.setCore(mCore); // editor.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); // editor.addToMainDesktopPane(); // editor.refresh(); // editor.start(); editor = new PropertyEditor(); editor.setGui(MMMainFrame.this); editor.setCore(mCore); editor.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); // editor.addToMainDesktopPane(); // editor.refresh(); // editor.start(); add(_mainPanel); initializeGUI(); loadPreferences(); refreshGUI(); setResizable(true); addToMainDesktopPane(); instanced = true; instancing = false; _singleton = MMMainFrame.this; setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addFrameListener(new IcyFrameAdapter() { @Override public void icyFrameClosing(IcyFrameEvent e) { customClose(); } }); acceptListener = new AcceptListener() { @Override public boolean accept(Object source) { close(); return _pluginListEmpty; } }; adapter = new MainAdapter() { @Override public void sequenceOpened(MainEvent event) { updateHistogram(); } }; Icy.getMainInterface().addCanExitListener(acceptListener); Icy.getMainInterface().addListener(adapter); } }); } }); } }); }
From source file:SplineInterpolatorTest.java
protected boolean isLocationWater(BufferedImage image, float posX, float posZ) { Color color = null; float imageWidth = image.getWidth(); float imageHeight = image.getHeight(); // range from 0 to 1 float nPixelX = (posX + LAND_WIDTH) / (2 * LAND_WIDTH); float nPixelY = (posZ + LAND_LENGTH) / (2 * LAND_LENGTH); // rescale//from w ww .j av a2 s . c o m nPixelX *= imageWidth; nPixelY *= imageHeight; if (nPixelX >= 0 && nPixelX < imageWidth && nPixelY >= 0 && nPixelY < imageHeight) { color = new Color(image.getRGB((int) nPixelX, (int) nPixelY)); return (color.getBlue() >= WATER_COLOR_BLUE && color.getGreen() <= WATER_COLOR_GREEN && color.getRed() <= WATER_COLOR_RED); } return false; }
From source file:net.sf.jasperreports.engine.util.JRApiWriter.java
/** * */// www.ja v a2 s . co m protected void write(String pattern, Color value, Color defaultValue) { if (value != null && value != defaultValue) { String strColor = MessageFormat.format("new Color({0}, {1}, {2})", new Object[] { value.getRed(), value.getGreen(), value.getBlue() }); write(MessageFormat.format(pattern, new Object[] { strColor })); } }
From source file:base.BasePlayer.BedCanvas.java
@Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_PLUS || keyCode == 107) { heightchanged = true;//ww w . j a va 2 s . c om for (int i = 0; i < bedTrack.size(); i++) { if (bedTrack.get(i).nodeHeight < 20) { bedTrack.get(i).nodeHeight++; } } repaint(); } if (keyCode == KeyEvent.VK_MINUS || keyCode == 109) { heightchanged = true; for (int i = 0; i < bedTrack.size(); i++) { if (bedTrack.get(i).nodeHeight > 1) { bedTrack.get(i).nodeHeight--; } } repaint(); } if (keyCode == KeyEvent.VK_PAGE_UP) { if (this.forwardColor.getAlpha() < 255) { this.forwardColor = new Color(this.forwardColor.getRed(), this.forwardColor.getGreen(), this.forwardColor.getBlue(), this.forwardColor.getAlpha() + 15); this.reverseColor = new Color(this.reverseColor.getRed(), this.reverseColor.getGreen(), this.reverseColor.getBlue(), this.reverseColor.getAlpha() + 15); for (int i = 0; i < bedTrack.size(); i++) { if (bedTrack.get(i).getColors().size() > 0) { Iterator<Map.Entry<Integer, Color>> it; Map.Entry<Integer, Color> pair; Color color; it = bedTrack.get(i).getColors().entrySet().iterator(); while (it.hasNext()) { pair = (Map.Entry<Integer, Color>) it.next(); color = pair.getValue(); color = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() + 15); bedTrack.get(i).getColors().put(pair.getKey(), color); } } } } repaint(); } if (keyCode == KeyEvent.VK_PAGE_DOWN) { if (this.forwardColor.getAlpha() > 0) { this.forwardColor = new Color(this.forwardColor.getRed(), this.forwardColor.getGreen(), this.forwardColor.getBlue(), this.forwardColor.getAlpha() - 15); this.reverseColor = new Color(this.reverseColor.getRed(), this.reverseColor.getGreen(), this.reverseColor.getBlue(), this.reverseColor.getAlpha() - 15); for (int i = 0; i < bedTrack.size(); i++) { if (bedTrack.get(i).getColors().size() > 0) { Iterator<Map.Entry<Integer, Color>> it; Map.Entry<Integer, Color> pair; Color color; it = bedTrack.get(i).getColors().entrySet().iterator(); while (it.hasNext()) { pair = (Map.Entry<Integer, Color>) it.next(); color = pair.getValue(); color = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() - 15); bedTrack.get(i).getColors().put(pair.getKey(), color); } } } } repaint(); } }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
/** * Create detail frames shown after calculation *//*from w ww . ja v a2 s.c o m*/ private void buildDetailedStatistics(HashMap<Village, String> attackMappings, List<Village> pNotAssignedVillages) { // <editor-fold defaultstate="collapsed" desc="Build not assigned source table"> Collections.sort(pNotAssignedVillages); DefaultTableModel sourcesModel = new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "Spieler", "Dorf" }) { private Class[] cTypes = new Class[] { Tribe.class, Village.class }; @Override public Class getColumnClass(int columnIndex) { return cTypes[columnIndex]; } }; for (Village notAssigned : pNotAssignedVillages) { Tribe t = notAssigned.getTribe(); if (t == null) { sourcesModel.addRow(new Object[] { Barbarians.getSingleton(), notAssigned }); } else { sourcesModel.addRow(new Object[] { t, notAssigned }); } } jNotAssignedSourcesTable.setModel(sourcesModel); TableRowSorter<TableModel> sourcesSorter = new TableRowSorter<TableModel>(sourcesModel); jNotAssignedSourcesTable.setRowSorter(sourcesSorter); DefaultTableCellRenderer headerRenderer = new SortableTableHeaderRenderer(); for (int i = 0; i < jNotAssignedSourcesTable.getColumnCount(); i++) { jNotAssignedSourcesTable.getColumn(jNotAssignedSourcesTable.getColumnName(i)) .setHeaderRenderer(headerRenderer); } jNotAssignedSourcesTable.revalidate(); //</editor-fold> // <editor-fold defaultstate="collapsed" desc="Build attacks per target table"> DefaultTableModel tableModel = new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "Spieler", "Dorf", "Angriffe" }) { Class[] types = new Class[] { Tribe.class, Village.class, String.class }; @Override public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }; List<Village> notFullTargets = new LinkedList<Village>(); Iterator<Village> keys = attackMappings.keySet().iterator(); while (keys.hasNext()) { Village key = keys.next(); Tribe t = key.getTribe(); //int notAssignedAmount = attackMappings.get(key); String attackCount = attackMappings.get(key); String[] split = attackCount.split("/"); int notAssignedAmount = Integer.parseInt(split[1]) - Integer.parseInt(split[0]); if (t != Barbarians.getSingleton()) { tableModel.addRow(new Object[] { t, key, attackCount }); } else { tableModel.addRow(new Object[] { "Barbaren", key, attackCount }); } if (notAssignedAmount > 0) { notFullTargets.add(key); } } jTargetDetailsTable.setModel(tableModel); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel); jTargetDetailsTable.setRowSorter(sorter); DefaultTableCellRenderer coloredRenderer = new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = new DefaultTableCellRenderer().getTableCellRendererComponent(table, value, isSelected, hasFocus, row, row); String t = ((DefaultTableCellRenderer) c).getText(); ((DefaultTableCellRenderer) c).setText(t); DefaultTableModel model = (DefaultTableModel) table.getModel(); int r = table.convertRowIndexToModel(row); String sVal = (String) model.getValueAt(r, 2); String[] split = sVal.split("/"); long max = Long.parseLong(split[1]); long v = Long.parseLong(split[0]); long diff = max - v; Color back = Color.RED; if (v == 0) { //color stays red } else if (v == max) { back = Color.GREEN; } else { float posv = 100.0f * (float) diff / (float) max; posv = ((int) posv / 10) * 10; posv /= 100; Color LAST_SEGMENT = new Color(255, 100, 0); int red = (int) Math.rint( (float) LAST_SEGMENT.getRed() * (1.0f - posv) + (float) Color.YELLOW.getRed() * posv); int green = (int) Math.rint((float) LAST_SEGMENT.getGreen() * (1.0f - posv) + (float) Color.YELLOW.getGreen() * posv); int blue = (int) Math.rint( (float) LAST_SEGMENT.getBlue() * (1.0f - posv) + (float) Color.YELLOW.getBlue() * posv); if (red < 0) { red = 0; } if (green < 0) { green = 0; } if (blue < 0) { blue = 0; } if (red > 254) { red = 254; } if (green > 254) { green = 254; } if (blue > 254) { blue = 254; } back = new Color(red, green, blue); } DefaultTableCellRenderer renderer = ((DefaultTableCellRenderer) c); if (!isSelected) { renderer.setBackground(back); } return c; } }; jTargetDetailsTable.setDefaultRenderer(Village.class, coloredRenderer); jTargetDetailsTable.setDefaultRenderer(Integer.class, coloredRenderer); jTargetDetailsTable.setDefaultRenderer(String.class, coloredRenderer); jTargetDetailsTable.setDefaultRenderer(Tribe.class, coloredRenderer); for (int i = 0; i < jTargetDetailsTable.getColumnCount(); i++) { jTargetDetailsTable.getColumn(jTargetDetailsTable.getColumnName(i)).setHeaderRenderer(headerRenderer); } jTargetDetailsTable.revalidate(); //</editor-fold> }
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
/** * Internal implementation to add an image (a world map, though other image data is also fine) to a slide. * Preserves the original image's aspect ratio, leaving blank space below and to the sides of the image. * @param slide the slide to add to.// w w w .j av a2s . com * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates. * @param picture the picture data. * @param markers an array of markers to draw over the map. * @param polygons * @return the picture shape object added to the slide. */ private static XSLFPictureShape addMap(final XSLFSlide slide, final Rectangle2D.Double anchor, final XSLFPictureData picture, final Marker[] markers, final MapData.Polygon[] polygons) { double tgtW = anchor.getWidth(), tgtH = anchor.getHeight(); final Dimension size = picture.getImageDimension(); final double ratio = size.getWidth() / size.getHeight(); if (ratio > tgtW / tgtH) { // source image is wider than target, clip fixed width variable height tgtH = tgtW / ratio; } else { tgtW = tgtH * ratio; } final XSLFPictureShape canvas = slide.createPicture(picture); // Vertically align top, horizontally-align center final double offsetX = anchor.getMinX() + 0.5 * (anchor.getWidth() - tgtW), offsetY = anchor.getMinY(); canvas.setAnchor(new Rectangle2D.Double(offsetX, offsetY, tgtW, tgtH)); if (polygons != null) { for (MapData.Polygon polygon : polygons) { final Color color = Color.decode(polygon.getColor()); final double[][] shapes = polygon.getPoints(); // The ESRI spec version 1.2.1 from http://www.opengeospatial.org/standards/sfa has section 6.1.11.1, // which defines polygons as follows: /// A Polygon is a planar Surface defined by 1 exterior boundary and 0 or more interior boundaries. // Each interior boundary defines a hole in the Polygon. A Triangle is a polygon with 3 distinct, // non-collinear vertices and no interior boundary. /// The exterior boundary LinearRing defines the top? of the surface which is the side of the surface // from which the exterior boundary appears to traverse the boundary in a counter clockwise direction. // The interior LinearRings will have the opposite orientation, and appear as clockwise // when viewed from the top? // so it's even-odd winding (whereas the Path2D default is non-zero-winding). final Path2D.Double path = new Path2D.Double(Path2D.WIND_EVEN_ODD); for (final double[] points : shapes) { for (int ii = 0; ii < points.length; ii += 2) { final double x1 = offsetX + points[ii] * tgtW; final double y1 = offsetY + points[ii + 1] * tgtH; if (ii == 0) { path.moveTo(x1, y1); } else { path.lineTo(x1, y1); } } path.closePath(); } final XSLFFreeformShape freeform = slide.createFreeform(); freeform.setPath(path); freeform.setStrokeStyle(0.5); // There's a 0.5 alpha transparency on the stroke, and a 0.2 alpha transparency on the polygon fill. freeform.setLineColor(transparentColor(color, 128)); freeform.setFillColor(transparentColor(color, 51)); if (StringUtils.isNotEmpty(polygon.getText())) { final PackageRelationship rel = freeform.getSheet().getPackagePart().addRelationship( slide.getPackagePart().getPartName(), TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation()); // We create a hyperlink which links back to this slide; so we get hover-over-detail-text on the polygon final CTHyperlink link = ((CTShape) freeform.getXmlObject()).getNvSpPr().getCNvPr() .addNewHlinkClick(); link.setTooltip(polygon.getText()); link.setId(rel.getId()); link.setAction("ppaction://hlinksldjump"); } } } for (Marker marker : markers) { final Color color = Color.decode(marker.getColor()); final double centerX = offsetX + marker.getX() * tgtW; final double centerY = offsetY + marker.getY() * tgtH; if (marker.isCluster()) { final XSLFGroupShape group = slide.createGroup(); double halfMark = 10; double mark = halfMark * 2; double innerHalfMark = 7; double innerMark = innerHalfMark * 2; // align these so the middle is the latlng position final Rectangle2D.Double groupAnchor = new Rectangle2D.Double(centerX - halfMark, centerY - halfMark, mark, mark); group.setAnchor(groupAnchor); group.setInteriorAnchor(groupAnchor); final XSLFAutoShape shape = group.createAutoShape(); shape.setShapeType(ShapeType.ELLIPSE); final boolean fade = marker.isFade(); // There's a 0.3 alpha transparency (255 * 0.3 is 76) when a marker is faded out final int FADE_ALPHA = 76; shape.setFillColor(transparentColor(color, fade ? 47 : 154)); shape.setAnchor(groupAnchor); final XSLFAutoShape inner = group.createAutoShape(); inner.setFillColor(fade ? transparentColor(color, FADE_ALPHA) : color); inner.setLineWidth(0.1); inner.setLineColor(new Color((int) (color.getRed() * 0.9), (int) (color.getGreen() * 0.9), (int) (color.getBlue() * 0.9), fade ? FADE_ALPHA : 255)); inner.setShapeType(ShapeType.ELLIPSE); inner.setHorizontalCentered(true); inner.setWordWrap(false); inner.setVerticalAlignment(VerticalAlignment.MIDDLE); inner.clearText(); final XSLFTextParagraph para = inner.addNewTextParagraph(); para.setTextAlign(TextParagraph.TextAlign.CENTER); final XSLFTextRun text = para.addNewTextRun(); text.setFontSize(6.0); final Color fontColor = Color.decode(StringUtils.defaultString(marker.getFontColor(), "#000000")); text.setFontColor(fade ? transparentColor(fontColor, FADE_ALPHA) : fontColor); text.setText(marker.getText()); inner.setAnchor(new Rectangle2D.Double(centerX - innerHalfMark, centerY - innerHalfMark, innerMark, innerMark)); } else { final XSLFGroupShape group = slide.createGroup(); final XSLFFreeformShape shape = group.createFreeform(); shape.setHorizontalCentered(true); shape.setWordWrap(false); shape.setVerticalAlignment(VerticalAlignment.BOTTOM); shape.setLineWidth(0.5); shape.setLineColor(color.darker()); shape.setFillColor(transparentColor(color, 210)); final double halfMark = 8, mark = halfMark * 2, extension = 0.85, markerHeight = (0.5 + extension) * mark, angle = Math.asin(0.5 / extension) * 180 / Math.PI; // Set group position group.setAnchor( new Rectangle2D.Double(centerX - halfMark, centerY - markerHeight, mark, markerHeight)); group.setInteriorAnchor(new Rectangle2D.Double(0, 0, mark, markerHeight)); // Draw a semicircle and a triangle to represent the marker, pointing at the precise x,y location final Path2D.Double path = new Path2D.Double(); path.moveTo(halfMark, markerHeight); path.append(new Arc2D.Double(0, 0, mark, mark, -angle, 180 + angle + angle, Arc2D.OPEN), true); path.lineTo(halfMark, markerHeight); shape.setPath(path); shape.setAnchor(new Rectangle2D.Double(0, 0, mark, markerHeight)); final XSLFAutoShape disc = group.createAutoShape(); disc.setShapeType(ShapeType.DONUT); final double discRadius = 0.25 * mark; final double discDiameter = 2 * discRadius; disc.setAnchor(new Rectangle2D.Double(halfMark - discRadius, halfMark - discRadius, discDiameter, discDiameter)); disc.setFillColor(Color.WHITE); disc.setLineColor(Color.WHITE); if (StringUtils.isNotEmpty(marker.getText())) { final PackageRelationship rel = shape.getSheet().getPackagePart().addRelationship( slide.getPackagePart().getPartName(), TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation()); // We create a hyperlink which links back to this slide; so we get hover-over-detail-text on the marker // Annoyingly, you can't put a link on the group, just on the individual shapes. for (XSLFShape clickable : group.getShapes()) { final CTHyperlink link = ((CTShape) clickable.getXmlObject()).getNvSpPr().getCNvPr() .addNewHlinkClick(); link.setTooltip(marker.getText()); link.setId(rel.getId()); link.setAction("ppaction://hlinksldjump"); } } } } return canvas; }