Example usage for java.awt Color gray

List of usage examples for java.awt Color gray

Introduction

In this page you can find the example usage for java.awt Color gray.

Prototype

Color gray

To view the source code for java.awt Color gray.

Click Source Link

Document

The color gray.

Usage

From source file:ComplexCellRenderer.java

public static void main(String args[]) {
    Object elements[][] = { { new Font("Helvetica", Font.PLAIN, 20), Color.RED, new MyIcon(), "A" },
            { new Font("TimesRoman", Font.BOLD, 14), Color.BLUE, new MyIcon(), "A" },
            { new Font("Courier", Font.ITALIC, 18), Color.GREEN, new MyIcon(), "A" },
            { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.GRAY, new MyIcon(), "A" },
            { new Font("TimesRoman", Font.PLAIN, 32), Color.PINK, new MyIcon(), "A" },
            { new Font("Courier", Font.BOLD, 16), Color.YELLOW, new MyIcon(), "A" },
            { new Font("Helvetica", Font.ITALIC, 8), Color.DARK_GRAY, new MyIcon(), "A" } };

    JFrame frame = new JFrame("Complex Renderer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ListCellRenderer renderer = new ComplexCellRenderer();
    JComboBox comboBox = new JComboBox(elements);
    comboBox.setRenderer(renderer);/*from  w  w w  . ja  v  a2  s  . c o  m*/
    frame.add(comboBox, BorderLayout.NORTH);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ComplexCellRenderer.java

public static void main(String args[]) {
    Object elements[][] = { { new Font("Helvetica", Font.PLAIN, 20), Color.RED, new MyIcon(), "A" },
            { new Font("TimesRoman", Font.BOLD, 14), Color.BLUE, new MyIcon(), "A" },
            { new Font("Courier", Font.ITALIC, 18), Color.GREEN, new MyIcon(), "A" },
            { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.GRAY, new MyIcon(), "A" },
            { new Font("TimesRoman", Font.PLAIN, 32), Color.PINK, new MyIcon(), "A" },
            { new Font("Courier", Font.BOLD, 16), Color.YELLOW, new MyIcon(), "A" },
            { new Font("Helvetica", Font.ITALIC, 8), Color.DARK_GRAY, new MyIcon(), "A" } };

    JFrame frame = new JFrame("Complex Renderer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JList jlist = new JList(elements);
    ListCellRenderer renderer = new ComplexCellRenderer();
    jlist.setCellRenderer(renderer);/*from w ww.  j a v a  2s  .  co  m*/
    JScrollPane scrollPane = new JScrollPane(jlist);
    frame.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:OverlaySample.java

public static void main(String args[]) {

    ActionListener generalActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JComponent comp = (JComponent) actionEvent.getSource();
            System.out.println(actionEvent.getActionCommand() + ": " + comp.getBounds());
        }/*from w  w w  . ja  va  2 s .  c o m*/
    };

    ActionListener sizingActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            setupButtons(actionEvent.getActionCommand());
        }
    };

    JFrame frame = new JFrame("Overlay Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel();
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

    Object settings[][] = { { "Small", new Dimension(25, 25), Color.white },
            { "Medium", new Dimension(50, 50), Color.gray },
            { "Large", new Dimension(100, 100), Color.black } };
    JButton buttons[] = { smallButton, mediumButton, largeButton };

    for (int i = 0, n = settings.length; i < n; i++) {
        JButton button = buttons[i];
        button.addActionListener(generalActionListener);
        button.setActionCommand((String) settings[i][0]);
        button.setMaximumSize((Dimension) settings[i][1]);
        button.setBackground((Color) settings[i][2]);
        panel.add(button);
    }

    setupButtons(SET_CENTRAL);

    JPanel actionPanel = new JPanel();
    actionPanel.setBorder(BorderFactory.createTitledBorder("Change Alignment"));
    String actionSettings[] = { SET_MINIMUM, SET_MAXIMUM, SET_CENTRAL, SET_MIXED };
    for (int i = 0, n = actionSettings.length; i < n; i++) {
        JButton button = new JButton(actionSettings[i]);
        button.addActionListener(sizingActionListener);
        actionPanel.add(button);
    }

    Container contentPane = frame.getContentPane();
    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.add(actionPanel, BorderLayout.SOUTH);

    frame.setSize(400, 300);
    frame.setVisible(true);
}

From source file:PowerMethod.power_method.java

public static void main(String[] args) {
    //////////////////////////////////////////////////////
    // Edit vals to contain values for matrix A         //
    // Edit vals2 to contain values for initial vector  //
    //////////////////////////////////////////////////////
    double[][] vals = { { 3, 4 }, { 3, 1 } };
    RealMatrix A = new Array2DRowRealMatrix(vals);
    double[][] vals2 = { { 1 }, { 1 } };
    RealMatrix u = new Array2DRowRealMatrix(vals2);
    power_object a = power_method(A, u, .1, 7);

    List<RealMatrix> matrices = genMatrices();
    List<trace_det> trace_dets = new ArrayList<>();
    double trace;
    double det;//from w  w  w.j a  va  2  s. c  o m
    int iterA;
    int iterInverseA;
    for (RealMatrix r : matrices) {
        MatrixMethods m = new MatrixMethods(r);
        RealMatrix inverseR = m.inverseMatrix();
        power_object largestVal = power_method(r, u, .00005, 100);
        power_object smallestVal = power_method(inverseR, u, .00005, 100);
        if (largestVal == null || smallestVal == null) {
            continue;
        }
        trace = m.trace();
        det = m.determinant();
        iterA = largestVal.getNumN();
        iterInverseA = smallestVal.getNumN();
        trace_det td = new trace_det(trace, det, iterA, iterInverseA);
        trace_dets.add(td);
    }
    JFreeChart chart = ChartFactory.createXYLineChart("Trace vs. Determinant for Power Method", "Determinant",
            "Trace", createDataSetA(trace_dets), PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesPaint(2, Color.GREEN);
    renderer.setSeriesPaint(3, Color.BLACK);
    renderer.setSeriesPaint(4, Color.YELLOW);
    renderer.setSeriesPaint(5, Color.PINK);
    renderer.setSeriesPaint(6, Color.ORANGE);
    renderer.setSeriesPaint(7, Color.GRAY);
    renderer.setSeriesPaint(8, Color.MAGENTA);
    renderer.setSeriesPaint(9, Color.LIGHT_GRAY);
    renderer.setSeriesPaint(10, Color.DARK_GRAY);
    //renderer.setSeriesStroke( 0 , new BasicStroke( 3.0f ) );
    //renderer.setSeriesStroke( 1 , new BasicStroke( 2.0f ) );
    plot.setRenderer(renderer);
    ChartFrame frame = new ChartFrame("Power Method", chart);
    frame.pack();
    frame.setVisible(true);

    JFreeChart inverseChart = ChartFactory.createXYLineChart("Trace vs. Determinant for Inverse Power Method",
            "Determinant", "Trace", createDataSetAInverse(trace_dets), PlotOrientation.VERTICAL, true, true,
            false);
    ChartPanel inverseChartPanel = new ChartPanel(inverseChart);
    inverseChartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot inversePlot = inverseChart.getXYPlot();
    XYLineAndShapeRenderer inverseRenderer = new XYLineAndShapeRenderer();
    inverseRenderer.setSeriesPaint(0, Color.RED);
    inverseRenderer.setSeriesPaint(1, Color.BLUE);
    inverseRenderer.setSeriesPaint(2, Color.GREEN);
    inverseRenderer.setSeriesPaint(3, Color.BLACK);
    inverseRenderer.setSeriesPaint(4, Color.YELLOW);
    inverseRenderer.setSeriesPaint(5, Color.PINK);
    inverseRenderer.setSeriesPaint(6, Color.ORANGE);
    inverseRenderer.setSeriesPaint(7, Color.GRAY);
    inverseRenderer.setSeriesPaint(8, Color.MAGENTA);
    inverseRenderer.setSeriesPaint(9, Color.LIGHT_GRAY);
    inverseRenderer.setSeriesPaint(10, Color.DARK_GRAY);
    inversePlot.setRenderer(renderer);
    ChartFrame inverseFrame = new ChartFrame("Power Method", inverseChart);
    inverseFrame.pack();
    inverseFrame.setVisible(true);
}

From source file:it.iit.genomics.cru.igb.bundles.mi.view.TestJung.java

public static void main(String[] args) {

    Graph<MoleculeEntry, EdgeInteraction> graph = new SparseMultigraph<>();

    MoleculeEntry v1 = new MoleculeEntry("A");
    v1.addGeneName("A");
    v1.setTaxid("9606");

    MoleculeEntry v2 = new MoleculeEntry("B");
    v2.addGeneName("b");
    v2.setTaxid("9606");

    MoleculeEntry v3 = new MoleculeEntry("DNA");
    v3.addGeneName("DNA");
    v3.setTaxid(MoleculeEntry.TAXID_DNA);

    EdgeInteraction edge = new EdgeInteraction(true, true, true, "e1");
    graph.addEdge(edge, v1, v2, EdgeType.UNDIRECTED);

    EdgeInteraction edge2 = new EdgeInteraction(false, false, true, "e2");
    graph.addEdge(edge2, v1, v3, EdgeType.UNDIRECTED);

    EdgeInteraction edge3 = new EdgeInteraction(false, false, false, "e3");
    graph.addEdge(edge3, v2, v3, EdgeType.UNDIRECTED);

    // The Layout<V, E> is parameterized by the vertex and edge types
    Layout<MoleculeEntry, EdgeInteraction> layout = new ISOMLayout(graph);

    layout.setSize(new Dimension(500, 600)); // sets the initial size of the space
    // The BasicVisualizationServer<V,E> is parameterized by the edge types
    VisualizationViewer<MoleculeEntry, EdgeInteraction> vv = new VisualizationViewer<>(layout);

    vv.setPreferredSize(new Dimension(550, 650)); //Sets the viewing area size
    vv.setBackground(Color.WHITE);
    Transformer<MoleculeEntry, Paint> vertexPaint = new Transformer<MoleculeEntry, Paint>() {
        @Override/*ww w .  ja va  2s. co m*/
        public Paint transform(MoleculeEntry molecule) {
            switch (molecule.getTaxid()) {
            case MoleculeEntry.TAXID_DNA:
                ;
            case MoleculeEntry.TAXID_RNA:
                return Color.GREEN;
            case MoleculeEntry.TAXID_LIGAND:
                return Color.MAGENTA;
            default:
                return Color.GREEN;
            }
        }
    };

    Transformer<EdgeInteraction, Paint> edgePaint = new Transformer<EdgeInteraction, Paint>() {
        @Override
        public Paint transform(EdgeInteraction interaction) {
            return interaction.hasStructure ? Color.BLACK : Color.GRAY;
        }
    };

    final Stroke edgeStroke01 = new BasicStroke();

    final float nodeSize = 20;

    final Stroke edgeStrokeBothContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) },
            nodeSize, true, true);

    final Stroke edgeStrokeStartContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) },
            nodeSize, true, false);

    final Stroke edgeStrokeEndContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) },
            nodeSize, false, true);

    final Stroke edgeStrokeBothContact = new CompoundStroke(edgeStroke01, edgeStrokeBothContacts,
            CompoundStroke.ADD);

    final Stroke edgeStrokeStartContact = new CompoundStroke(edgeStroke01, edgeStrokeStartContacts,
            CompoundStroke.ADD);

    final Stroke edgeStrokeEndContact = new CompoundStroke(edgeStroke01, edgeStrokeEndContacts,
            CompoundStroke.ADD);

    Transformer<EdgeInteraction, Stroke> edgeStrokeTransformer = new Transformer<EdgeInteraction, Stroke>() {
        @Override
        public Stroke transform(EdgeInteraction s) {
            if (s.hasContactsA && s.hasContactsB) {
                return edgeStrokeBothContact;
            }

            if (s.hasContactsA) {
                return edgeStrokeStartContact;
            }

            if (s.hasContactsB) {
                return edgeStrokeEndContact;
            }

            return edgeStroke01;
        }
    };

    Transformer<MoleculeEntry, String> moleculeLabeller = new Transformer<MoleculeEntry, String>() {
        @Override
        public String transform(MoleculeEntry s) {
            return s.getGeneName();
        }
    };

    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeDrawPaintTransformer(edgePaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);

    vv.getRenderContext().setVertexLabelTransformer(moleculeLabeller);

    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    vv.setGraphMouse(graphMouse);

    JFrame frame = new JFrame("Network " + "A");

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.getContentPane().add(vv);
    frame.pack();

    frame.setVisible(true);
}

From source file:ColorSink.java

/** This is a simple test program for ColorSource and ColorSink */
public static void main(String[] args) {
    // Create a window
    JFrame f = new JFrame("ColorSourceTest");
    f.getContentPane().setLayout(new BorderLayout());

    // Add some ColorSources
    JPanel panel = new JPanel();
    f.getContentPane().add(panel, BorderLayout.NORTH);
    panel.add(new ColorSource(Color.yellow));
    panel.add(new ColorSource(Color.pink));
    panel.add(new ColorSource(Color.white));
    panel.add(new ColorSource(Color.gray));

    // Add a ColorSink
    ColorSink sink = new ColorSink();
    f.getContentPane().add(sink, BorderLayout.CENTER);

    // Pop it all up
    f.setSize(400, 300);//from   ww w . j a  va  2  s. com
    f.show();
}

From source file:MultiColumnIrregular.java

/**
 * An example using MultiColumnText with irregular columns.
 * @param args no arguments needed/*from   w  ww  .  j  av  a  2  s.c o  m*/
 */
public static void main(String[] args) {
    try {
        // step 1
        Document document = new Document();
        OutputStream out = new FileOutputStream("MultiColumnIrregular.pdf");
        PdfWriter writer = PdfWriter.getInstance(document, out);
        document.open();

        // calculate diamond shaped hole
        float diamondHeight = 400;
        float diamondWidth = 400;
        float gutter = 10;
        float bodyHeight = document.top() - document.bottom();
        float colMaxWidth = (document.right() - document.left() - (gutter * 2)) / 2f;
        float diamondTop = document.top() - ((bodyHeight - diamondHeight) / 2f);
        float diamondInset = colMaxWidth - (diamondWidth / 2f);
        float centerX = (document.right() - document.left()) / 2 + document.left();
        // draw stuff
        PdfContentByte cb = writer.getDirectContentUnder();

        MultiColumnText mct = new MultiColumnText(document.top() - document.bottom());

        // setup column 1
        float[] left = { document.left(), document.top(), document.left(), document.bottom() };
        float[] right = { document.left() + colMaxWidth, document.top(), document.left() + colMaxWidth,
                diamondTop, document.left() + diamondInset, diamondTop - diamondHeight / 2,
                document.left() + colMaxWidth, diamondTop - diamondHeight, document.left() + colMaxWidth,
                document.bottom() };
        mct.addColumn(left, right);

        // setup column 2
        left = new float[] { document.right() - colMaxWidth, document.top(), document.right() - colMaxWidth,
                diamondTop, document.right() - diamondInset, diamondTop - diamondHeight / 2,
                document.right() - colMaxWidth, diamondTop - diamondHeight, document.right() - colMaxWidth,
                document.bottom() };
        right = new float[] { document.right(), document.top(), document.right(), document.bottom() };
        mct.addColumn(left, right);

        // add text
        for (int i = 0; i < 8; i++) {
            mct.addElement(new Paragraph(
                    "GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur.  Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt.  Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.\n",
                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
            mct.addElement(new Paragraph(
                    "[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]\n",
                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
            mct.addElement(new Paragraph(
                    "Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix.  Is M. Messala, [et P.] M.  Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent:  perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri.  Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur:  una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit.  His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur.  Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.\n",
                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
            mct.addElement(new Paragraph(
                    "His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare.  Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant.  Ad eas res conficiendas Orgetorix deligitur.  Is sibi legationem ad civitates suscipit.  In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat.  Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset:  non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat.  Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.\n",
                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
            mct.addElement(new Paragraph(
                    "Ea res est Helvetiis per indicium enuntiata.  Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur.  Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit.  Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.",
                    FontFactory.getFont(FontFactory.HELVETICA, 12)));
        }
        do {
            cb.setLineWidth(5);
            cb.setColorStroke(Color.GRAY);
            cb.moveTo(centerX, document.top());
            cb.lineTo(centerX, document.bottom());
            cb.stroke();
            cb.moveTo(centerX, diamondTop);
            cb.lineTo(centerX - (diamondWidth / 2), diamondTop - (diamondHeight / 2));
            cb.lineTo(centerX, diamondTop - diamondHeight);
            cb.lineTo(centerX + (diamondWidth / 2), diamondTop - (diamondHeight / 2));
            cb.lineTo(centerX, diamondTop);
            cb.setColorFill(Color.GRAY);
            cb.fill();
            document.add(mct);
            mct.nextColumn();
        } while (mct.isOverflow());
        document.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static Border getBorderGray() {
    return BorderFactory.createLineBorder(Color.gray);
}

From source file:Main.java

/**
 * @return Default colored line border
 */
public static Border defaultLineBorder() {
    return BorderFactory.createLineBorder(Color.GRAY);
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.setColor(Color.gray);
    g.draw3DRect(25, 10, 50, 75, true);//from  w w  w.  j  a v  a 2s.  com
    g.draw3DRect(25, 110, 50, 75, false);
    g.fill3DRect(100, 10, 50, 75, true);
    g.fill3DRect(100, 110, 50, 75, false);
}