List of usage examples for java.awt Color orange
Color orange
To view the source code for java.awt Color orange.
Click Source Link
From source file:com.viettel.util.excel.DynamicExport.java
public void setCellFormat(int r1, int c1, int r2, int c2, int formatType) throws CellException { CellFormat format = view.getCellFormat(r1, c1, r2, c2); if (formatType == HEADER_FORMAT) { // <editor-fold defaultstate="collapsed" desc="Header cua bang"> short border = CellFormat.BorderThin; format.setLeftBorder(border);//from ww w . j av a2 s . c om format.setRightBorder(border); format.setTopBorder(border); format.setBottomBorder(border); format.setHorizontalInsideBorder(border); format.setVerticalInsideBorder(border); Color borderColor = Color.GREEN.darker(); format.setLeftBorderColor(borderColor); format.setRightBorderColor(borderColor); format.setTopBorderColor(borderColor); format.setBottomBorderColor(borderColor); format.setFontBold(true); format.setPattern((short) 1); format.setPatternFG(new Color(254, 252, 172)); format.setWordWrap(true); format.setVerticalAlignment(CellFormat.VerticalAlignmentCenter); format.setHorizontalAlignment(CellFormat.HorizontalAlignmentCenter); // </editor-fold> } else if (formatType == BORDER_FORMAT) { // <editor-fold defaultstate="collapsed" // desc="Border cho du lieu binh thuong"> short border = CellFormat.BorderThin; format.setLeftBorder(border); format.setRightBorder(border); format.setTopBorder(border); format.setBottomBorder(border); format.setHorizontalInsideBorder(border); format.setVerticalInsideBorder(border); Color borderColor = Color.GREEN.darker(); format.setLeftBorderColor(borderColor); format.setRightBorderColor(borderColor); format.setTopBorderColor(borderColor); format.setBottomBorderColor(borderColor); // format.setFontBold(false); view.setRowHeightAuto(r1, c1, r2, c2, true); // view.setRowHeight(r1, r2, 200, true, true); format.setWordWrap(true); // </editor-fold> } else if (formatType == BORDER_FORMAT_NON_WRAP) { // <editor-fold defaultstate="collapsed" // desc="Border cho du lieu binh thuong"> short border = CellFormat.BorderThin; format.setLeftBorder(border); format.setRightBorder(border); format.setTopBorder(border); format.setBottomBorder(border); format.setHorizontalInsideBorder(border); format.setVerticalInsideBorder(border); Color borderColor = Color.GREEN.darker(); format.setLeftBorderColor(borderColor); format.setRightBorderColor(borderColor); format.setTopBorderColor(borderColor); format.setBottomBorderColor(borderColor); // format.setFontBold(false); format.setPattern((short) 1); // view.setRowHeightAuto(r1, c1, r2, c2, true); view.setRowHeight(r1, r2, 200, true, true); format.setWordWrap(false); // </editor-fold> } else if (formatType == BLACK_BORDER_FORMAT) { // <editor-fold defaultstate="collapsed" // desc="Border cho du lieu binh thuong"> short border = CellFormat.BorderThin; format.setLeftBorder(border); format.setRightBorder(border); format.setTopBorder(border); format.setBottomBorder(border); format.setHorizontalInsideBorder(border); format.setVerticalInsideBorder(border); Color borderColor = Color.BLACK.darker(); format.setLeftBorderColor(borderColor); format.setRightBorderColor(borderColor); format.setTopBorderColor(borderColor); format.setBottomBorderColor(borderColor); // format.setFontBold(false); format.setWordWrap(true); // </editor-fold> } else if (formatType == TITLE) { format.setFontBold(true); format.setPattern((short) 1); format.setPatternFG(Color.GREEN); format.setHorizontalAlignment(CellFormat.HorizontalAlignmentCenter); } else if (formatType == GROUP_LEVEL1_FORMAT) { format.setFontBold(true); format.setPattern((short) 1); format.setPatternFG(Color.ORANGE); } else if (formatType == GROUP_LEVEL2_FORMAT) { format.setFontBold(true); format.setFontItalic(true); format.setPattern((short) 1); format.setPatternFG(new Color(135, 206, 250)); } else if (formatType == GROUP_LEVEL3_FORMAT) { format.setFontBold(true); format.setFontItalic(true); format.setPattern((short) 1); format.setPatternFG(new Color(10, 175, 255)); } else if (formatType == GROUP_LEVEL4_FORMAT) { format.setFontBold(true); format.setFontItalic(true); format.setPattern((short) 1); format.setPatternFG(new Color(209, 232, 170)); } else if (formatType == GROUP_LEVEL5_FORMAT) { format.setFontBold(true); format.setFontItalic(true); format.setPattern((short) 1); format.setPatternFG(new Color(250, 250, 210)); } else if (formatType == GROUP_LEVEL6_FORMAT) { format.setFontBold(true); format.setFontItalic(true); format.setPattern((short) 1); format.setPatternFG(new Color(209, 238, 238)); } else if (formatType == ACCOUNTING_FORMAT) { String numberFormat = "_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)"; format.setCustomFormat(numberFormat); } else if (formatType == NUMBER_FORMAT) { String numberFormat = "#,##0"; format.setCustomFormat(numberFormat); } else if (formatType == NUMBER_FORMAT_D) { String numberFormat = "#,##0.00"; format.setCustomFormat(numberFormat); } else if (formatType == BOLD_WHITE) { // SonPN format.setFontBold(true); format.setPattern((short) 1); format.setPatternFG(Color.WHITE); // format.setHorizontalAlignment(CellFormat.HorizontalAlignmentLeft); } else if (formatType == CENTER_FORMAT) { format.setHorizontalAlignment(CellFormat.HorizontalAlignmentCenter); } else if (formatType == BOLD_CENTER_FORMAT) { format.setFontBold(true); format.setWordWrap(true); format.setVerticalAlignment((short) 1); format.setHorizontalAlignment(CellFormat.HorizontalAlignmentCenter); } else if (formatType == BOLD_FORMAT) { format.setFontBold(true); } else if (formatType == BOLD_WHITE_CENTER) { // SonPN format.setFontBold(true); format.setPattern((short) 1); // format.setPatternFG(Color.WHITE); format.setHorizontalAlignment(CellFormat.HorizontalAlignmentCenter); } else if (formatType == NOMARL_WHITE_CENTER) { // SonPN format.setFontBold(false); format.setPattern((short) 1); format.setPatternFG(Color.WHITE); format.setHorizontalAlignment(CellFormat.HorizontalAlignmentCenter); } else if (formatType == NORMAL_ITALIC) { format.setFontItalic(true); } else if (formatType == GROUP_DATA_FORMAT) { format.setPattern((short) 1); format.setPatternFG(Color.YELLOW); } else if (formatType == PERCENT_FORMAT) { format.setFontBold(true); // format.setFontItalic(true); format.setPattern((short) 1); // format.setPatternFG(new Color(209, 232, 170)); String percentFormat = "#,##" + "%"; format.setCustomFormat(percentFormat); } else if (formatType == CENTER_VERTICAL_FORMAT) { format.setVerticalAlignment(CellFormat.VerticalAlignmentCenter); } else if (formatType == TOP_VERTICAL_FORMAT) { format.setVerticalAlignment(CellFormat.VerticalAlignmentTop); } else if (formatType == SHRINK_TO_FIT) { format.setShrinkToFit(true); } else if (formatType == HEADER_ORANGE) { format.setFontBold(true); format.setVerticalAlignment(CellFormat.VerticalAlignmentCenter); format.setHorizontalAlignment(CellFormat.HorizontalAlignmentCenter); format.setPattern((short) 1); format.setPatternFG(Color.ORANGE); } else if (formatType == HEADER_YELLOW) { format.setFontBold(true); format.setVerticalAlignment(CellFormat.VerticalAlignmentCenter); format.setHorizontalAlignment(CellFormat.HorizontalAlignmentCenter); format.setPattern((short) 1); format.setPatternFG(Color.YELLOW); } else if (formatType == ALIGN_LEFT) { format.setHorizontalAlignment(CellFormat.HorizontalAlignmentLeft); } else if (formatType == ALIGN_RIGHT) { format.setHorizontalAlignment(CellFormat.HorizontalAlignmentRight); } else if (formatType == CELL_COLOR_YELLOW) { format.setPattern((short) 1); format.setPatternFG(Color.YELLOW); } else if (formatType == NO_WRAP_TEXT) { format.setWordWrap(false); } else if (formatType == BLACK_BORDER_NO_HORIZONTAL_NONE_WRAP) { short border = CellFormat.BorderThin; format.setLeftBorder(border); format.setRightBorder(border); format.setTopBorder(border); format.setBottomBorder(border); format.setVerticalInsideBorder(border); Color borderColor = Color.BLACK.darker(); format.setLeftBorderColor(borderColor); format.setRightBorderColor(borderColor); format.setTopBorderColor(borderColor); format.setBottomBorderColor(borderColor); format.setWordWrap(false); } else if (formatType == BLACK_BORDER_NO_HORIZONTAL) { short border = CellFormat.BorderThin; format.setLeftBorder(border); format.setRightBorder(border); format.setTopBorder(border); format.setBottomBorder(border); format.setVerticalInsideBorder(border); Color borderColor = Color.BLACK.darker(); format.setLeftBorderColor(borderColor); format.setRightBorderColor(borderColor); format.setTopBorderColor(borderColor); format.setBottomBorderColor(borderColor); format.setWordWrap(true); } else if (formatType == BORDER_FORMAT_NO_ROW_HEIGHT) { short border = CellFormat.BorderThin; format.setLeftBorder(border); format.setRightBorder(border); format.setTopBorder(border); format.setBottomBorder(border); format.setHorizontalInsideBorder(border); format.setVerticalInsideBorder(border); Color borderColor = Color.GREEN.darker(); format.setLeftBorderColor(borderColor); format.setRightBorderColor(borderColor); format.setTopBorderColor(borderColor); format.setBottomBorderColor(borderColor); format.setWordWrap(true); // view.setRowHeightAuto(r1, c1, r2, c2, true); } else if (formatType == MERGE_CELL) { format.setMergeCells(true); } view.setCellFormat(format, r1, c1, r2, c2); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample pie chart. * * @return a sample pie chart./*from ww w. j a v a2 s .co m*/ */ public JFreeChart createPieChartOne() { // create a default chart based on some sample data... final String title = this.resources.getString("pie.pie1.title"); final CategoryDataset data = DemoDatasetFactory.createCategoryDataset(); final PieDataset extracted = DatasetUtilities.createPieDatasetForRow(data, 0); final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false); // then customise it a little... chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.orange)); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setCircular(false); // make section 1 explode by 100%... plot.setExplodePercent(1, 1.00); return chart; }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java
private void setupTreeGUI() { //create a graph Graph<String, String> ig = Graphs .<String, String>synchronizedDirectedGraph(new DirectedSparseMultigraph<String, String>()); ObservableGraph<String, String> og = new ObservableGraph<String, String>(ig); og.addGraphEventListener(new GraphEventListener<String, String>() { public void handleGraphEvent(GraphEvent<String, String> evt) { System.err.println("got " + evt); }/*from ww w. ja va 2 s . c o m*/ }); this.g = og; //create a graphdraw layout = new FRLayout<String, String>(g); //layout = new ISOMLayout<String, String>(g); //layout = new KKLayout<String, String>(g); //layout = new CircleLayout<String, String>(g); vv = new VisualizationViewer<String, String>(layout, null); //tree2Panel.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); tree2Panel.setLayout(new BorderLayout()); tree2Panel.setBackground(java.awt.Color.lightGray); tree2Panel.setFont(new Font("Serif", Font.PLAIN, 12)); vv.getModel().getRelaxer().setSleepTime(500); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse<Number, Number>(); vv.setGraphMouse(graphMouse); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller()); Transformer<String, Paint> vertexColor = new Transformer<String, Paint>() { public Paint transform(String i) { if (i.equals(ComponentTreeCellRenderer.getFullTitle(sample, false))) { return Color.ORANGE; } else { return Color.PINK; } } }; Transformer<String, Paint> edgeColor = new Transformer<String, Paint>() { public Paint transform(String i) { return Color.WHITE; } }; Transformer<String, Shape> vertexShape = new Transformer<String, Shape>() { public Shape transform(String i) { if (i.equals(ComponentTreeCellRenderer.getFullTitle(sample, false))) { return new Rectangle(-150, -20, 300, 40); } else { return new Rectangle(-150, -10, 300, 20); } } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexColor); vv.getRenderContext().setEdgeDrawPaintTransformer(edgeColor); vv.getRenderContext().setVertexShapeTransformer(vertexShape); ; vv.setForeground(Color.BLACK); tree2Panel.add(vv, BorderLayout.CENTER); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.setRenderer(new JUNGModeRenderer()); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(scaleGrid); controls.add(modeBox); tree2Panel.add(controls, BorderLayout.NORTH); }
From source file:edu.unibonn.kmeans.mapreduce.plotting.TimeSeriesPlotter_KMeans.java
private Paint getColor(int color_number) { Color curr_color = null;// w ww . j av a2 s .co m switch (color_number) { case 0: curr_color = Color.BLUE; break; case 1: curr_color = Color.GREEN; break; case 2: curr_color = Color.RED; break; case 3: curr_color = Color.PINK; break; case 4: curr_color = Color.MAGENTA; break; case 5: curr_color = Color.CYAN; break; case 6: curr_color = Color.DARK_GRAY; break; case 7: curr_color = Color.LIGHT_GRAY; break; case 8: curr_color = Color.YELLOW; break; case 9: curr_color = Color.ORANGE; break; case 10: curr_color = Color.BLACK; break; // case 11: curr_color = Color.YELLOW; // break; // case 12: curr_color = Color.BLACK; // break; // case 13: curr_color = Color.BLACK; // break; // case 14: curr_color = Color.BLACK; // break; // case 15: curr_color = Color.BLACK; // break; // case 16: curr_color = Color.BLACK; // break; // case 17: curr_color = Color.BLACK; // break; // case 18: curr_color = Color.BLACK; // break; // case 20: curr_color = Color.BLACK; // break; // case 21: curr_color = Color.BLACK; // break; // case 22: curr_color = Color.BLACK; // break; // case 23: curr_color = Color.BLACK; // break; default: curr_color = Color.WHITE; break; } return curr_color; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java
private static JFreeChart createWaterfallChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createWaterfallChart("Waterfall Chart Demo 1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );/*from w w w . j a va 2 s .co m*/ chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); WaterfallBarRenderer renderer = (WaterfallBarRenderer) plot.getRenderer(); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); // GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); // renderer.setSeriesPaint(0, gp0); // renderer.setSeriesPaint(1, gp1); // renderer.setSeriesPaint(2, gp2); //?? renderer.setFirstBarPaint(gp0); renderer.setLastBarPaint(gp2); renderer.setPositiveBarPaint(Color.orange); renderer.setNegativeBarPaint(Color.cyan); return chart; }
From source file:org.ofbiz.common.CommonEvents.java
public static String getCaptcha(HttpServletRequest request, HttpServletResponse response) { try {/*from w w w . java 2s.c o m*/ Delegator delegator = (Delegator) request.getAttribute("delegator"); final String captchaSizeConfigName = StringUtils.defaultIfEmpty(request.getParameter("captchaSize"), "default"); final String captchaSizeConfig = EntityUtilProperties.getPropertyValue("captcha.properties", "captcha." + captchaSizeConfigName, delegator); final String[] captchaSizeConfigs = captchaSizeConfig.split("\\|"); final String captchaCodeId = StringUtils.defaultIfEmpty(request.getParameter("captchaCodeId"), ""); // this is used to uniquely identify in the user session the attribute where the captcha code for the last captcha for the form is stored final int fontSize = Integer.parseInt(captchaSizeConfigs[0]); final int height = Integer.parseInt(captchaSizeConfigs[1]); final int width = Integer.parseInt(captchaSizeConfigs[2]); final int charsToPrint = UtilProperties.getPropertyAsInteger("captcha.properties", "captcha.code_length", 6); final char[] availableChars = EntityUtilProperties .getPropertyValue("captcha.properties", "captcha.characters", delegator).toCharArray(); //It is possible to pass the font size, image width and height with the request as well Color backgroundColor = Color.gray; Color borderColor = Color.DARK_GRAY; Color textColor = Color.ORANGE; Color circleColor = new Color(160, 160, 160); Font textFont = new Font("Arial", Font.PLAIN, fontSize); int circlesToDraw = 6; float horizMargin = 20.0f; double rotationRange = 0.7; // in radians BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) bufferedImage.getGraphics(); g.setColor(backgroundColor); g.fillRect(0, 0, width, height); //Generating some circles for background noise g.setColor(circleColor); for (int i = 0; i < circlesToDraw; i++) { int circleRadius = (int) (Math.random() * height / 2.0); int circleX = (int) (Math.random() * width - circleRadius); int circleY = (int) (Math.random() * height - circleRadius); g.drawOval(circleX, circleY, circleRadius * 2, circleRadius * 2); } g.setColor(textColor); g.setFont(textFont); FontMetrics fontMetrics = g.getFontMetrics(); int maxAdvance = fontMetrics.getMaxAdvance(); int fontHeight = fontMetrics.getHeight(); String captchaCode = RandomStringUtils.random(6, availableChars); float spaceForLetters = -horizMargin * 2 + width; float spacePerChar = spaceForLetters / (charsToPrint - 1.0f); for (int i = 0; i < captchaCode.length(); i++) { // this is a separate canvas used for the character so that // we can rotate it independently int charWidth = fontMetrics.charWidth(captchaCode.charAt(i)); int charDim = Math.max(maxAdvance, fontHeight); int halfCharDim = (charDim / 2); BufferedImage charImage = new BufferedImage(charDim, charDim, BufferedImage.TYPE_INT_ARGB); Graphics2D charGraphics = charImage.createGraphics(); charGraphics.translate(halfCharDim, halfCharDim); double angle = (Math.random() - 0.5) * rotationRange; charGraphics.transform(AffineTransform.getRotateInstance(angle)); charGraphics.translate(-halfCharDim, -halfCharDim); charGraphics.setColor(textColor); charGraphics.setFont(textFont); int charX = (int) (0.5 * charDim - 0.5 * charWidth); charGraphics.drawString("" + captchaCode.charAt(i), charX, ((charDim - fontMetrics.getAscent()) / 2 + fontMetrics.getAscent())); float x = horizMargin + spacePerChar * (i) - charDim / 2.0f; int y = ((height - charDim) / 2); g.drawImage(charImage, (int) x, y, charDim, charDim, null, null); charGraphics.dispose(); } // Drawing the image border g.setColor(borderColor); g.drawRect(0, 0, width - 1, height - 1); g.dispose(); response.setContentType("image/jpeg"); ImageIO.write(bufferedImage, "jpg", response.getOutputStream()); HttpSession session = request.getSession(); Map<String, String> captchaCodeMap = UtilGenerics.checkMap(session.getAttribute("_CAPTCHA_CODE_")); if (captchaCodeMap == null) { captchaCodeMap = new HashMap<String, String>(); session.setAttribute("_CAPTCHA_CODE_", captchaCodeMap); } captchaCodeMap.put(captchaCodeId, captchaCode); } catch (Exception ioe) { Debug.logError(ioe.getMessage(), module); } return "success"; }
From source file:com.bdb.weather.display.freeplot.HistoricalFreePlot.java
/** * Create the series for pressure values. * //from w w w .j a v a 2s . co m * @param stroke The stroke that is used to draw the series * @param timeMethod The method that is used to "get" the date from the record */ private List<FreePlotSeries<HistoricalRecord>> createSolarRadiationSeries(Stroke stroke, Function<HistoricalRecord, TemporalAccessor> timeMethod) { List<FreePlotSeries<HistoricalRecord>> list = new ArrayList<>(); int n = 0; list.add(new FreePlotSeries<>(SOLAR_RADIATION_SERIES_NAME, n++, Color.ORANGE, stroke, HistoricalRecord::getAvgSolarRadiation, timeMethod, INTERVAL_CLASS)); return list; }
From source file:org.apache.ofbiz.common.CommonEvents.java
public static String getCaptcha(HttpServletRequest request, HttpServletResponse response) { try {//from w ww .j a v a 2s .c om Delegator delegator = (Delegator) request.getAttribute("delegator"); final String captchaSizeConfigName = StringUtils.defaultIfEmpty(request.getParameter("captchaSize"), "default"); final String captchaSizeConfig = EntityUtilProperties.getPropertyValue("captcha", "captcha." + captchaSizeConfigName, delegator); final String[] captchaSizeConfigs = captchaSizeConfig.split("\\|"); final String captchaCodeId = StringUtils.defaultIfEmpty(request.getParameter("captchaCodeId"), ""); // this is used to uniquely identify in the user session the attribute where the captcha code for the last captcha for the form is stored final int fontSize = Integer.parseInt(captchaSizeConfigs[0]); final int height = Integer.parseInt(captchaSizeConfigs[1]); final int width = Integer.parseInt(captchaSizeConfigs[2]); final int charsToPrint = UtilProperties.getPropertyAsInteger("captcha", "captcha.code_length", 6); final char[] availableChars = EntityUtilProperties .getPropertyValue("captcha", "captcha.characters", delegator).toCharArray(); //It is possible to pass the font size, image width and height with the request as well Color backgroundColor = Color.gray; Color borderColor = Color.DARK_GRAY; Color textColor = Color.ORANGE; Color circleColor = new Color(160, 160, 160); Font textFont = new Font("Arial", Font.PLAIN, fontSize); int circlesToDraw = 6; float horizMargin = 20.0f; double rotationRange = 0.7; // in radians BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) bufferedImage.getGraphics(); g.setColor(backgroundColor); g.fillRect(0, 0, width, height); //Generating some circles for background noise g.setColor(circleColor); for (int i = 0; i < circlesToDraw; i++) { int circleRadius = (int) (Math.random() * height / 2.0); int circleX = (int) (Math.random() * width - circleRadius); int circleY = (int) (Math.random() * height - circleRadius); g.drawOval(circleX, circleY, circleRadius * 2, circleRadius * 2); } g.setColor(textColor); g.setFont(textFont); FontMetrics fontMetrics = g.getFontMetrics(); int maxAdvance = fontMetrics.getMaxAdvance(); int fontHeight = fontMetrics.getHeight(); String captchaCode = RandomStringUtils.random(6, availableChars); float spaceForLetters = -horizMargin * 2 + width; float spacePerChar = spaceForLetters / (charsToPrint - 1.0f); for (int i = 0; i < captchaCode.length(); i++) { // this is a separate canvas used for the character so that // we can rotate it independently int charWidth = fontMetrics.charWidth(captchaCode.charAt(i)); int charDim = Math.max(maxAdvance, fontHeight); int halfCharDim = (charDim / 2); BufferedImage charImage = new BufferedImage(charDim, charDim, BufferedImage.TYPE_INT_ARGB); Graphics2D charGraphics = charImage.createGraphics(); charGraphics.translate(halfCharDim, halfCharDim); double angle = (Math.random() - 0.5) * rotationRange; charGraphics.transform(AffineTransform.getRotateInstance(angle)); charGraphics.translate(-halfCharDim, -halfCharDim); charGraphics.setColor(textColor); charGraphics.setFont(textFont); int charX = (int) (0.5 * charDim - 0.5 * charWidth); charGraphics.drawString("" + captchaCode.charAt(i), charX, ((charDim - fontMetrics.getAscent()) / 2 + fontMetrics.getAscent())); float x = horizMargin + spacePerChar * (i) - charDim / 2.0f; int y = ((height - charDim) / 2); g.drawImage(charImage, (int) x, y, charDim, charDim, null, null); charGraphics.dispose(); } // Drawing the image border g.setColor(borderColor); g.drawRect(0, 0, width - 1, height - 1); g.dispose(); response.setContentType("image/jpeg"); ImageIO.write(bufferedImage, "jpg", response.getOutputStream()); HttpSession session = request.getSession(); Map<String, String> captchaCodeMap = UtilGenerics.checkMap(session.getAttribute("_CAPTCHA_CODE_")); if (captchaCodeMap == null) { captchaCodeMap = new HashMap<String, String>(); session.setAttribute("_CAPTCHA_CODE_", captchaCodeMap); } captchaCodeMap.put(captchaCodeId, captchaCode); } catch (Exception ioe) { Debug.logError(ioe.getMessage(), module); } return "success"; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java
private static JFreeChart createLineChart3D(CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); LineRenderer3D renderer = new LineRenderer3D(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); }//from w w w . j a v a 2s. c o m if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("Line Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.orange, 0.0f, 0.0f, new Color(0, 64, 64)); renderer.setWallPaint(gp); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:umontreal.iro.lecuyer.charts.XYLineChart.java
/** * Displays bar chart on the screen using Swing. * This method creates an application containing a bar chart panel displaying * the chart. The created frame is positioned on-screen, and displayed before * it is returned. The <TT>width</TT> and the <TT>height</TT> * of the chart are measured in pixels. * /*from ww w. j a v a 2s . c o m*/ * @param width frame width in pixels. * * @param height frame height in pixels. * * @return frame containing the bar chart.; * */ public JFrame viewBar(int width, int height) { JFrame myFrame; if (chart.getTitle() != null) myFrame = new JFrame("XYLineChart from SSJ: " + chart.getTitle().getText()); else myFrame = new JFrame("XYLineChart from SSJ"); XYPlot plot = (XYPlot) chart.getPlot(); //Create the bar plot.setDataset(0, dataset.getSeriesCollection()); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setSeriesPaint(0, Color.ORANGE); renderer.setSeriesShape(0, new Line2D.Double(0, 0, 0, 1000)); plot.setRenderer(0, renderer); //Create the points plot.setDataset(1, dataset.getSeriesCollection()); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true); renderer2.setSeriesPaint(0, Color.ORANGE); renderer2.setSeriesShape(0, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0)); plot.setRenderer(1, renderer2); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(width, height)); myFrame.setContentPane(chartPanel); myFrame.pack(); myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); myFrame.setLocationRelativeTo(null); myFrame.setVisible(true); return myFrame; }