Example usage for java.awt Graphics fillRect

List of usage examples for java.awt Graphics fillRect

Introduction

In this page you can find the example usage for java.awt Graphics fillRect.

Prototype

public abstract void fillRect(int x, int y, int width, int height);

Source Link

Document

Fills the specified rectangle.

Usage

From source file:ubic.basecode.graphics.MatrixDisplay.java

/**
 * Draws column names vertically (turned 90 degrees counter-clockwise)
 * /*from   w ww.j  a  v  a  2  s  .co  m*/
 * @param g Graphics
 */
protected void drawColumnNames(Graphics g, boolean leaveRoomForScalebar) {

    if (colorMatrix == null)
        return;
    Color oldColor = g.getColor();

    int y = m_columnLabelHeight;
    if (leaveRoomForScalebar) {
        y += SCALE_BAR_ROOM;
    }

    g.setColor(Color.white);
    g.fillRect(0, 0, this.getWidth(), y);

    g.setColor(Color.black);
    g.setFont(m_labelFont);

    int columnCount = colorMatrix.getColumnCount();
    for (int j = 0; j < columnCount; j++) {
        // compute the coordinates
        int x = m_cellSize.width + j * m_cellSize.width - m_fontGutter;

        Object columnName = colorMatrix.getColumnName(j);
        if (null == columnName) {
            columnName = "Undefined";
        }

        // fix the name length as 20 characters
        // add ellipses (...) if > 20
        // spacepad to 20 if < 20
        String columnNameString = columnName.toString();
        if (m_maxColumnLength > 0) {
            columnNameString = padColumnString(columnNameString);
        }

        // print the text vertically
        Util.drawVerticalString(g, columnNameString, m_labelFont, x, y);

    }
    g.setColor(oldColor);
}

From source file:CustomAlphaTest.java

protected void drawGraph() {
    if (m_Alpha != null) {
        Graphics g = m_Image.getGraphics();

        g.setColor(Color.white);//from  w  ww  .  ja v a2s.co m
        g.fillRect(0, 0, m_kWidth, m_kHeight);
        g.setColor(Color.black);

        m_Alpha.setStartTime(0);
        long lMaxTime = getMaxTime();

        computeDrawScale(lMaxTime);

        drawAxes(g, lMaxTime);
        drawPhases(g, lMaxTime);
        drawAlpha(g, lMaxTime);
    }
}

From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java

protected void drawPageError(Graphics grx) {
    grx.setColor(Color.white);//from  w w  w. jav a 2  s  . co  m
    grx.fillRect(0, 0, viewerContext.getJasperPrint().getPageWidth() + 1,
            viewerContext.getJasperPrint().getPageHeight() + 1);
}

From source file:thesaurusEditor.gui.graph.MainGraph.java

/**
 * create an instance of a simple graph with basic controls
 *///from www .  j  a va2s .  c om
public MainGraph(List<Konzept> konzepte, Main main) {

    // create a simple graph for the demo
    this.konzepte = konzepte;
    this.main = main;

    main.getController().getThesaurus().addObserver(this);

    graph = new DirectedSparseGraph<Konzept, EdgeClass>();

    for (Konzept k : konzepte) {
        graph.addVertex(k);
    }
    createEdges(konzepte);

    layout = new PersistentLayoutImpl<Konzept, EdgeClass>(new FRLayout<Konzept, EdgeClass>(graph));
    //layout = new FRLayout<Konzept,EdgeClass>(graph);
    Dimension preferredSize = new Dimension(1300, 900);
    final VisualizationModel<Konzept, EdgeClass> visualizationModel = new DefaultVisualizationModel<Konzept, EdgeClass>(
            layout, preferredSize);
    vv = new VisualizationViewer<Konzept, EdgeClass>(visualizationModel, preferredSize);

    // this class will provide both label drawing and vertex shapes
    VertexLabelAsShapeRenderer<Konzept, EdgeClass> vlasr = new VertexLabelAsShapeRenderer<Konzept, EdgeClass>(
            vv.getRenderContext());

    // customize the render context
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<Konzept, String>() {
        public String transform(Konzept k) {
            return "";
        }
    });
    // this chains together Transformers so that the html tags
    // are prepended to the toString method output
    /*new ChainedTransformer<Konzept,String>(new Transformer[]{
    new ToStringLabeller<Konzept>(),
    new Transformer<Konzept,String>() {
     public String transform(Konzept input) {
        return input.toString();
     }}}));*/
    vv.getRenderContext().setVertexShapeTransformer(new Transformer<Konzept, Shape>() {
        public Shape transform(Konzept k) {
            return new Rectangle(-((k.toString().length() * 8 + 10) / 2), -(10), k.toString().length() * 7 + 18,
                    21);
        }
    });
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red));
    vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.black));
    vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f)));

    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<Konzept>(vv.getPickedVertexState(), Color.white, Color.yellow));
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<EdgeClass>(vv.getPickedEdgeState(), Color.black, Color.red));

    vv.getRenderContext().setVertexIconTransformer(new Transformer<Konzept, Icon>() {

        /*
         * Implements the Icon interface to draw an Icon with background color and
         * a text label
         */
        public Icon transform(final Konzept v) {
            return new Icon() {
                private Konzept k;

                public int getIconHeight() {
                    return 20;
                }

                public int getIconWidth() {
                    if (k != null) {
                        return k.toString().length() * 7 + 10;
                    }
                    return v.toString().length() * 7 + 10;
                }

                public void paintIcon(Component c, Graphics g, int x, int y) {
                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.yellow);
                    } else {
                        g.setColor(Color.lightGray);
                    }
                    g.fillRect(x, y, v.toString().length() * 8 + 10, 20);

                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.black);
                    } else {
                        g.setColor(Color.black);
                    }
                    g.drawRect(x, y, v.toString().length() * 8 + 10, 20);
                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.black);
                    } else {
                        g.setColor(Color.black);
                    }
                    this.k = v;

                    if (vv.getPickedVertexState().isPicked(v)) {
                        Font font = new Font("DejaVu Sans Mono", Font.BOLD, 14);
                        g.setFont(font);
                        g.drawString("" + v, x + 6, y + 15);
                    } else {
                        Font font = new Font("DejaVu Sans Mono", Font.PLAIN, 14);
                        g.setFont(font);
                        g.drawString("" + v, x + 6, y + 15);
                    }
                    this.k = v;

                }
            };
        }
    });

    // customize the renderer
    /*GradientVertexRenderer<Konzept,EdgeClass> vertex = new GradientVertexRenderer<Konzept,EdgeClass>(Color.white, Color.white, true);
    vv.getRenderer().setVertexRenderer(vertex);
    vv.getRenderer().setVertexLabelRenderer(vlasr); */

    vv.setBackground(Color.white);

    // add a listener for ToolTips
    KonzeptParser<Konzept> parser = new KonzeptParser<Konzept>();
    vv.setVertexToolTipTransformer(parser);

    /*final DefaultModalGraphMouse<Konzept,Edge> graphMouse = 
    new DefaultModalGraphMouse<Konzept,Edge>();
    */

    Factory<Konzept> vertexFactory = new VertexFactory();
    Factory<EdgeClass> edgeFactory = new EdgeFactory();

    graphMouse = new MyModalGraphMouse<Konzept, EdgeClass>(vv.getRenderContext(), vertexFactory, edgeFactory,
            main, vv);

    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());
    // the EditingGraphMouse will pass mouse event coordinates to the
    // vertexLocations function to set the locations of the vertices as
    // they are created
    //        graphMouse.setVertexLocations(vertexLocations);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    graphMouse.setMode(ModalGraphMouse.Mode.EDITING);

    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(graphMouse.getModeListener());
    //graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton();
    plus.setIcon(new ImageIcon(getClass().getResource("/thesaurusEditor/img/zoom_in.png")));
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton();
    minus.setIcon(new ImageIcon(getClass().getResource("/thesaurusEditor/img/zoom_out.png")));
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JPanel controls = new JPanel();
    JPanel zoomControls = new JPanel(new GridLayout(1, 2));
    //zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom"));
    zoomControls.add(plus);
    zoomControls.add(minus);
    controls.add(zoomControls);
    //controls.add(modeBox);
    /*
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(gzsp);
    gzsp.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 374, Short.MAX_VALUE)
    );
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 106, Short.MAX_VALUE)
    );
            
            
    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(controls);
    controls.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
    jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 374, Short.MAX_VALUE)
    );
    jPanel2Layout.setVerticalGroup(
    jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 164, Short.MAX_VALUE)
    );*/

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(gzsp, javax.swing.GroupLayout.Alignment.TRAILING,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(controls, javax.swing.GroupLayout.Alignment.TRAILING,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
            javax.swing.GroupLayout.Alignment.TRAILING,
            layout.createSequentialGroup().addContainerGap()
                    .addComponent(gzsp, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(controls, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap()));

}

From source file:uk.co.modularaudio.util.audio.gui.patternsequencer.PatternSequenceAmpGrid.java

private void paintCells(final Graphics g, final int startCol, final int endCol) {
    g.setColor(blockColour);/*from  ww  w .  j  av a  2  s . c  om*/
    for (int i = startCol; i <= endCol; i++) {
        if (i < 0 || i > numCols - 1) {
            continue;
        }
        final PatternSequenceStep psn = dataModel.getNoteAtStep(i);
        final MidiNote mn = psn.note;
        if (mn != null) {
            final float amp = psn.amp;
            final boolean isContinuation = psn.isContinuation;
            final int scaledAmp = (int) (amp * AMP_BOX_HEIGHT) - 6;
            final int startX = (i * cellDimensions.width) + 2;
            final int endX = (isContinuation ? startX + cellDimensions.width - 4
                    : startX + (cellDimensions.width / 2));
            final int endY = size.height - 3;
            final int startY = endY - scaledAmp;

            g.fillRect(startX, startY, endX - startX, endY - startY);
        }
    }

}

From source file:org.jtrfp.trcl.core.ResourceManager.java

/**
 * Returns RAW image as an R8-G8-B8 buffer with a side-width which is the square root of the total number of pixels
 * @param name/* w ww.  ja v  a  2 s. c o m*/
 * @param palette
 * @param proc
 * @return
 * @throws IOException
 * @throws FileLoadException
 * @throws IllegalAccessException
 * @throws NotSquareException 
 * @since Oct 26, 2012
 */
public BufferedImage getRAWImage(String name, Color[] palette) throws IOException, FileLoadException,
        IllegalAccessException, NotSquareException, NonPowerOfTwoException {
    final RAWFile dat = getRAW(name);
    final byte[] raw = dat.getRawBytes();
    if (raw.length != dat.getSideLength() * dat.getSideLength())
        throw new NotSquareException(name);
    if ((dat.getSideLength() & (dat.getSideLength() - 1)) != 0)
        throw new NonPowerOfTwoException(name);
    final BufferedImage stamper = new BufferedImage(dat.getSideLength(), dat.getSideLength(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics stG = stamper.getGraphics();
    for (int i = 0; i < raw.length; i++) {
        Color c = palette[(int) raw[i] & 0xFF];
        stG.setColor(c);
        stG.fillRect(i % dat.getSideLength(), i / dat.getSideLength(), 1, 1);
    }
    stG.dispose();
    Graphics g = stamper.getGraphics();
    //The following code stamps the filename into the texture for debugging purposes
    if (tr.isStampingTextures()) {
        g.setFont(new Font(g.getFont().getName(), g.getFont().getStyle(), 9));
        g.drawString(name, 1, 16);
    }

    g.dispose();
    return stamper;
}

From source file:ro.nextreports.designer.querybuilder.SQLViewPanel.java

private void initUI() {
    sqlEditor = new Editor() {
        public void afterCaretMove() {
            removeHighlightErrorLine();/*from  w w w. j  a v  a 2 s . co m*/
        }
    };
    this.queryArea = sqlEditor.getEditorPanel().getEditorPane();
    queryArea.setText(DEFAULT_QUERY);

    errorPainter = new javax.swing.text.Highlighter.HighlightPainter() {
        @Override
        public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) {
            try {
                Rectangle r = c.modelToView(c.getCaretPosition());
                g.setColor(Color.RED.brighter().brighter());
                g.fillRect(0, r.y, c.getWidth(), r.height);
            } catch (BadLocationException e) {
                // ignore
            }
        }
    };

    ActionMap actionMap = sqlEditor.getEditorPanel().getEditorPane().getActionMap();

    // create the toolbar
    JToolBar toolBar = new JToolBar();
    toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders
    toolBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
    toolBar.setBorderPainted(false);

    // add cut action
    Action cutAction = actionMap.get(BaseEditorKit.cutAction);
    cutAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("cut"));
    cutAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.cut"));
    toolBar.add(cutAction);

    // add copy action
    Action copyAction = actionMap.get(BaseEditorKit.copyAction);
    copyAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("copy"));
    copyAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.copy"));
    toolBar.add(copyAction);

    // add paste action
    Action pasteAction = actionMap.get(BaseEditorKit.pasteAction);
    pasteAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("paste"));
    pasteAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.paste"));
    toolBar.add(pasteAction);

    // add separator
    SwingUtil.addCustomSeparator(toolBar);

    // add undo action
    Action undoAction = actionMap.get(BaseEditorKit.undoAction);
    undoAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("undo"));
    undoAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("undo"));
    toolBar.add(undoAction);

    // add redo action
    Action redoAction = actionMap.get(BaseEditorKit.redoAction);
    redoAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("redo"));
    redoAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("redo"));
    toolBar.add(redoAction);

    // add separator
    SwingUtil.addCustomSeparator(toolBar);

    // add find action
    Action findReplaceAction = actionMap.get(BaseEditorKit.findReplaceAction);
    findReplaceAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("find"));
    findReplaceAction.putValue(Action.SHORT_DESCRIPTION,
            I18NSupport.getString("sqleditor.findReplaceActionName"));
    toolBar.add(findReplaceAction);

    // add separator
    SwingUtil.addCustomSeparator(toolBar);

    // add run action
    runAction = new SQLRunAction();
    runAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("run"));
    runAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(ShortcutsUtil.getShortcut("query.run.accelerator", "control 4")));
    runAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("run.query") + " ("
            + ShortcutsUtil.getShortcut("query.run.accelerator.display", "Ctrl 4") + ")");
    // runAction is globally registered in QueryBuilderPanel !
    toolBar.add(runAction);

    //        ro.nextreports.designer.util.SwingUtil.registerButtonsForFocus(buttonsPanel);

    // create the table
    resultTable = new JXTable();
    resultTable.setDefaultRenderer(Integer.class, new ToStringRenderer()); // to remove thousand separators
    resultTable.setDefaultRenderer(Long.class, new ToStringRenderer());
    resultTable.setDefaultRenderer(Date.class, new DateRenderer());
    resultTable.setDefaultRenderer(Double.class, new DoubleRenderer());
    resultTable.addMouseListener(new CopyTableMouseAdapter(resultTable));
    TableUtil.setRowHeader(resultTable);
    resultTable.setColumnControlVisible(true);
    //        resultTable.getTableHeader().setReorderingAllowed(false);
    resultTable.setHorizontalScrollEnabled(true);

    // highlight table
    Highlighter alternateHighlighter = HighlighterFactory.createAlternateStriping(Color.WHITE,
            ColorUtil.PANEL_BACKROUND_COLOR);
    Highlighter nullHighlighter = new TextHighlighter(ResultSetTableModel.NULL_VALUE, Color.YELLOW.brighter());
    Highlighter blobHighlighter = new TextHighlighter(ResultSetTableModel.BLOB_VALUE, Color.GRAY.brighter());
    Highlighter clobHighlighter = new TextHighlighter(ResultSetTableModel.CLOB_VALUE, Color.GRAY.brighter());
    resultTable.setHighlighters(alternateHighlighter, nullHighlighter, blobHighlighter, clobHighlighter);
    resultTable.setBackground(ColorUtil.PANEL_BACKROUND_COLOR);
    resultTable.setGridColor(Color.LIGHT_GRAY);

    resultTable.setRolloverEnabled(true);
    resultTable.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.RED));

    JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    split.setResizeWeight(0.66);
    split.setOneTouchExpandable(true);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new GridBagLayout());
    topPanel.add(toolBar, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    topPanel.add(sqlEditor, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

    JPanel bottomPanel = new JPanel();
    bottomPanel.setLayout(new GridBagLayout());
    JScrollPane scrPanel = new JScrollPane(resultTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    statusPanel = new SQLStatusPanel();
    bottomPanel.add(scrPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    bottomPanel.add(statusPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

    split.setTopComponent(topPanel);
    split.setBottomComponent(bottomPanel);
    split.setDividerLocation(400);

    setLayout(new BorderLayout());
    this.add(split, BorderLayout.CENTER);
}

From source file:fr.avianey.androidsvgdrawable.SvgDrawablePlugin.java

/**
 * Draw the stretch and content area defined by the {@link NinePatch} around the given image
 * @param is/*w  ww  .j  a v  a  2s.c  o  m*/
 * @param finalName
 * @param ninePatch
 * @param ratio
 * @throws IOException
 */
private void toNinePatch(final InputStream is, final String finalName, final NinePatch ninePatch,
        final double ratio) throws IOException {
    BufferedImage image = ImageIO.read(is);
    final int w = image.getWidth();
    final int h = image.getHeight();
    BufferedImage ninePatchImage = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB);
    Graphics g = ninePatchImage.getGraphics();
    g.drawImage(image, 1, 1, null);

    // draw patch
    g.setColor(Color.BLACK);

    Zone stretch = ninePatch.getStretch();
    Zone content = ninePatch.getContent();

    if (stretch.getX() == null) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("+ ninepatch stretch(x) [start=0 - size=" + w + "]");
        }
        g.fillRect(1, 0, w, 1);
    } else {
        for (int[] seg : stretch.getX()) {
            final int start = NinePatch.start(seg[0], seg[1], w, ratio);
            final int size = NinePatch.size(seg[0], seg[1], w, ratio);
            if (getLog().isDebugEnabled()) {
                getLog().debug("+ ninepatch stretch(x) [start=" + start + " - size=" + size + "]");
            }
            g.fillRect(start + 1, 0, size, 1);
        }
    }

    if (stretch.getY() == null) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("+ ninepatch stretch(y) [start=0 - size=" + h + "]");
        }
        g.fillRect(0, 1, 1, h);
    } else {
        for (int[] seg : stretch.getY()) {
            final int start = NinePatch.start(seg[0], seg[1], h, ratio);
            final int size = NinePatch.size(seg[0], seg[1], h, ratio);
            if (getLog().isDebugEnabled()) {
                getLog().debug("+ ninepatch stretch(y) [start=" + start + " - size=" + size + "]");
            }
            g.fillRect(0, start + 1, 1, size);
        }
    }

    if (content.getX() == null) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("+ ninepatch content(x) [start=0 - size=" + w + "]");
        }
        g.fillRect(1, h + 1, w, 1);
    } else {
        for (int[] seg : content.getX()) {
            final int start = NinePatch.start(seg[0], seg[1], w, ratio);
            final int size = NinePatch.size(seg[0], seg[1], w, ratio);
            if (getLog().isDebugEnabled()) {
                getLog().debug("+ ninepatch content(x) [start=" + start + " - size=" + size + "]");
            }
            g.fillRect(start + 1, h + 1, size, 1);
        }
    }

    if (content.getY() == null) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("+ ninepatch content(y) [start=0 - size=" + h + "]");
        }
        g.fillRect(w + 1, 1, 1, h);
    } else {
        for (int[] seg : content.getY()) {
            final int start = NinePatch.start(seg[0], seg[1], h, ratio);
            final int size = NinePatch.size(seg[0], seg[1], h, ratio);
            if (getLog().isDebugEnabled()) {
                getLog().debug("+ ninepatch content(y) [start=" + start + " - size=" + size + "]");
            }
            g.fillRect(w + 1, start + 1, 1, size);
        }
    }

    ImageIO.write(ninePatchImage, "png", new File(finalName));
}

From source file:uk.co.modularaudio.mads.base.oscilloscope.ui.OscilloscopeDisplayUiJComponent.java

private void paintIntoImage(final Graphics g, final OscilloscopeWriteableScopeData scopeData) {
    //      Graphics2D g2d = (Graphics2D)g;
    //      Rectangle clipBounds = g.getClipBounds();
    final Font f = g.getFont();
    final Font newFont = f.deriveFont(12);
    g.setFont(newFont);//from w w  w.j ava2s.  com
    final int x = 0;
    final int y = 0;

    newMaxMag0 = 0.5f;
    newMaxMag1 = 0.5f;

    final int width = getWidth();
    final int height = getHeight();

    final int plotWidth = width - (SCALE_WIDTH * 2);
    final int plotStart = SCALE_WIDTH;
    final int plotHeight = getHeight();

    //      g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
    g.setColor(Color.BLACK);
    g.fillRect(x, y, width, height);

    if (scopeData != null) {

        final int numSamplesInBuffer = scopeData.desiredDataLength;

        final float[] float0Data = scopeData.floatBuffer0;
        final FloatType float0Type = scopeData.floatBuffer0Type;
        switch (float0Type) {
        case AUDIO:
            maxMag0 = 1.0f;
            break;
        case CV:
            break;
        }
        final boolean displayFloat0 = scopeData.float0Written;

        final float[] float1Data = scopeData.floatBuffer1;
        final FloatType float1Type = scopeData.floatBuffer1Type;
        switch (float1Type) {
        case AUDIO:
            maxMag1 = 1.0f;
            break;
        case CV:
            break;
        }
        final boolean displayFloat1 = scopeData.float1Written;

        if (displayFloat0) {
            // Float data draw
            g.setColor(Color.RED);
            drawScale(g, height, maxMag0, 0);
            plotAllDataValues(g, plotWidth, plotStart, plotHeight, numSamplesInBuffer, float0Data, true);
        }

        if (displayFloat1) {
            // CV data draw
            g.setColor(Color.YELLOW);
            drawScale(g, height, maxMag1, plotStart + plotWidth);
            plotAllDataValues(g, plotWidth, plotStart, plotHeight, numSamplesInBuffer, float1Data, false);
        }
        maxMag0 = newMaxMag0;
        maxMag1 = newMaxMag1;
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchAttackFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    AttackTableTab activeTab = getActiveTab();
    int idx = jAttackTabPane.getSelectedIndex();
    if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("TimeChange")) {
            activeTab.fireChangeTimeEvent();
        } else if (e.getActionCommand().equals("UnitChange")) {
            activeTab.fireChangeUnitEvent();
        } else if (e.getActionCommand().equals("Recolor")) {
            activeTab.updateSortHighlighter();
        } else if (e.getActionCommand().equals("ExportScript")) {
            activeTab.fireExportScriptEvent();
        } else if (e.getActionCommand().equals("Copy")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("BBCopy")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.CLIPBOARD_BB);
        } else if (e.getActionCommand().equals("Cut")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD);
            jAttackTabPane.setSelectedIndex(idx);
        } else if (e.getActionCommand().equals("Paste")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD);
            jAttackTabPane.setSelectedIndex(idx);
        } else if (e.getActionCommand().equals("Delete")) {
            activeTab.deleteSelection(true);
        } else if (e.getActionCommand().equals("Find")) {
            BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT);
            Graphics g = back.getGraphics();
            g.setColor(new Color(120, 120, 120, 120));
            g.fillRect(0, 0, back.getWidth(), back.getHeight());
            g.setColor(new Color(120, 120, 120));
            g.drawLine(0, 0, 3, 3);//from  w  w  w  .  jav  a2 s. c o  m
            g.dispose();
            TexturePaint paint = new TexturePaint(back,
                    new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));

            jxSearchPane.setBackgroundPainter(new MattePainter(paint));
            DefaultListModel model = new DefaultListModel();

            for (int i = 0; i < activeTab.getAttackTable().getColumnCount(); i++) {
                TableColumnExt col = activeTab.getAttackTable().getColumnExt(i);
                if (col.isVisible()) {
                    if (!col.getTitle().equals("Einheit") && !col.getTitle().equals("Typ")
                            && !col.getTitle().equals("Sonstiges") && !col.getTitle().equals("Abschickzeit")
                            && !col.getTitle().equals("Ankunftzeit") && !col.getTitle().equals("Verbleibend")) {
                        model.addElement(col.getTitle());
                    }
                }
            }
            jXColumnList.setModel(model);
            jXColumnList.setSelectedIndex(0);
            jxSearchPane.setVisible(true);
        }
    }
}