Example usage for java.awt Toolkit getImage

List of usage examples for java.awt Toolkit getImage

Introduction

In this page you can find the example usage for java.awt Toolkit getImage.

Prototype

public abstract Image getImage(URL url);

Source Link

Document

Returns an image which gets pixel data from the specified URL.

Usage

From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.About.java

@SuppressWarnings("unchecked")
private void startup() {
    try {/*  w  w w . j a v a 2s.  com*/
        try {
            theFormControl = new FormControl(this, theSettingsPath);
        } catch (Exception ex) {
            LOG.error("Error loading form parameters", ex);
        }
        ClassLoader cLoader = Thread.currentThread().getContextClassLoader();
        Toolkit kit = Toolkit.getDefaultToolkit();
        Package p = this.getClass().getPackage();
        lblVersion.setText(p.getImplementationVersion());
        if (new File(theLogoFileName).exists()) {
            theLogo = kit.getImage(theLogoFileName);
        } else {
            java.net.URL imageURL = cLoader.getResource(theLogoFileName);
            if (imageURL != null) {
                theLogo = kit.getImage(imageURL);
            }
        }
        if (theLogo != null) {
            lblBuildNo.setForeground(Color.white);
            lblBuildNoLabel.setForeground(Color.white);
            //lblHeader.setForeground(Color.white);
            lblVersion.setForeground(Color.white);
            lblVersionLabel.setForeground(Color.white);
            paintImage();
        }
        //String manifestFileName = "/META-INF/MANIFEST.MF";
        Class cls = this.getClass();

        String className = cls.getSimpleName();
        String classFileName = className + ".class";
        String pathToThisClass = cls.getResource(classFileName).toString();
        int mark = pathToThisClass.indexOf("!");
        String pathToManifest = pathToThisClass.substring(0, mark + 1);
        if (!pathToManifest.equals("")) {
            pathToManifest += "/META-INF/MANIFEST.MF";
            LOG.debug("Path to manifest: " + pathToManifest);
            Manifest mf = new Manifest(new URL(pathToManifest).openStream());
            if (mf != null) {
                Attributes attr = mf.getMainAttributes();
                String attrVersion = "Implementation-Version";
                String attrBuild = "Implementation-Build";
                String version = attr.getValue(attrVersion);
                String build = attr.getValue(attrBuild);
                this.lblVersion.setText(version);
                this.lblBuildNo.setText(build);
            }
        }
        Runtime runtime = Runtime.getRuntime();
        long maxMemory = runtime.maxMemory();
        long allocatedMemory = runtime.totalMemory();
        long freeMemory = runtime.freeMemory();
        LOG.debug("free memory: " + freeMemory / 1024);
        LOG.debug("allocated memory: " + allocatedMemory / 1024);
        LOG.debug("max memory: " + maxMemory / 1024);
        LOG.debug("total free memory: " + (freeMemory + (maxMemory - allocatedMemory)) / 1024);
    } catch (IOException ex) {
        ex.printStackTrace();
        LOG.error(ex.getMessage(), ex);
    }
}

From source file:org.kepler.gui.KeplerXMLIcon.java

/**
 * Create a new Swing icon to use as a thumbnail in the Actor Library.
 * //from www.j  av  a  2  s  . c om
 * Looks for attributes in the following order, stopping if a match is
 * found:
 * 
 * 1) if SVG_BATIK_RENDERING enabled - looks for "_thumbnailRasterIcon",
 * which contains a pointer (typically a classpath-relative file path). If
 * it exists, uses it to create the thumbnail icon. If (a) it doesn't exist,
 * or (b) if rendering method is SVG_DIVA_RENDERING, proceed to next step,
 * since (a) we're dealing with an annotation or shape actor etc, or (b) we
 * don't want to render the new-style thumbnail and the old-style actor
 * icons.
 * 
 * 2) "_smallIconDescription", which contains an xml simple-svg description.
 * If it exists, uses it to create the icon, using the simple Diva rendering
 * system
 * 
 * If no match is found, a default image is used, as follows:
 * 
 * 3) looks for a cached actor icon (_bgFigure).
 * 
 * 4) If no cached one is available, it creates a scaled version of the
 * background figure by calling _divaCreateBackgroundFigure(), using the
 * old-style Diva svg rendering to render the xml simple-svg description in
 * the "_iconDescription" attribute, if it exists. Uses old diva rendering
 * because batik is very memory intensive, and is not required for this
 * task.
 * 
 * 5) If all else fails, it simply defers to the base class.
 * 
 * @return A Swing Icon.
 */
@Override
public Icon createIcon() {

    // In this class, we cache the rendered icon, since creating icons from
    // figures is expensive.
    if (_iconCache != null) {
        return _iconCache;
    }

    // We know that at this point,
    // _iconCache == null

    NamedObj container = (NamedObj) getContainerOrContainerToBe();

    // do not use batik to render the icons for non-director attributes.
    // see http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5266
    if (container instanceof Attribute && !(container instanceof Director)) {
        isBatikRendering = false;
    }

    Figure thumbFig = null;

    // 1) if SVG_BATIK_RENDERING enabled...
    if (isBatikRendering) {

        // ...looks for "_thumbnailRasterIcon", which contains a pointer
        // (typically a classpath-relative file path).
        ConfigurableAttribute rasterThumbAtt = null;
        try {
            rasterThumbAtt = (ConfigurableAttribute) container
                    .getAttribute(ComponentEntityConfig.RASTER_THUMB_ATTRIB_NAME);
        } catch (Exception ex2) {
            if (isDebugging) {
                log.warn(container.getName() + ": exception getting rasterThumbAtt attribute: "
                        + ex2.getMessage());
            }
            rasterThumbAtt = null;
        }
        if (isDebugging) {
            log.debug("createIcon(): " + container.getClass().getName() + " - just got rasterThumbAtt="
                    + rasterThumbAtt);
        }
        // If it exists, uses it to create the thumbnail icon.
        if (rasterThumbAtt != null) {

            // If the description has changed, update _divaThumbAttrib
            // and listeners
            if (_rasterThumbAttrib != rasterThumbAtt) {
                if (_rasterThumbAttrib != null) {
                    // Remove this as a listener if there
                    // was a previous description.
                    _rasterThumbAttrib.removeValueListener(this);
                }

                _rasterThumbAttrib = rasterThumbAtt;

                // Listen for changes in value to the icon description.
                _rasterThumbAttrib.addValueListener(this);
            }

            String thumbPath = rasterThumbAtt.getExpression();
            if (thumbPath == null || thumbPath.trim().length() < 1) {
                thumbFig = null;
            } else {
                if (isDebugging) {
                    log.debug("createIcon(): SVG_BATIK_RENDERING and rasterThumbAtt=" + thumbPath.trim());
                }
                try {
                    URL url = getClass().getResource(thumbPath.trim());
                    if (url == null) {
                        if (isDebugging) {
                            log.warn("\n ERROR - createIcon(): " + container.getClass().getName()
                                    + " : url==null for thumb path:\n" + thumbPath.trim());
                        }
                        thumbFig = null;
                    } else {
                        if (isDebugging) {
                            log.debug(":::: " + container.getClass().getName() + " - got thumbPath.trim() = "
                                    + thumbPath.trim());
                        }
                        Toolkit tk = Toolkit.getDefaultToolkit();
                        Image thumbImg = tk.getImage(url);
                        thumbFig = new ImageFigure(thumbImg);
                    }
                } catch (Exception ex) {
                    if (isDebugging) {
                        log.warn("createIcon(): " + container.getClass().getName()
                                + "\n exception getting thumbnail icon. Path = " + thumbPath.trim()
                                + "\n exception = " + ex);
                    }
                    thumbFig = null;
                }
            }
        }
    }
    // If(a)it doesn't
    // exist, or (b) if rendering method is SVG_DIVA_RENDERING, proceed to
    // next step, since (a) we're dealing with an annotation or shape actor
    // etc, or (b) we don't want to render the new-style thumbnail and the
    // old-style actor icons....

    if (thumbFig == null) {
        // 2) "_smallIconDescription", which contains an xml simple-svg
        // description. If it exists, uses it to create the icon, using the
        // simple Diva rendering system
        ConfigurableAttribute divaThumbAtt = null;
        try {
            divaThumbAtt = (ConfigurableAttribute) container.getAttribute(OLD_SVG_THUMB_ATTNAME);
        } catch (Exception ex1) {
            divaThumbAtt = null;
        }

        if (divaThumbAtt != null) {

            // If the description has changed, update _divaThumbAttrib
            // and listeners
            if (_divaThumbAttrib != divaThumbAtt) {
                if (_divaThumbAttrib != null) {
                    // Remove this as a listener if there
                    // was a previous description.
                    _divaThumbAttrib.removeValueListener(this);
                }

                _divaThumbAttrib = divaThumbAtt;

                // Listen for changes in value to the icon description.
                _divaThumbAttrib.addValueListener(this);
            }

            String divaThumbPath = null;
            try {
                divaThumbPath = divaThumbAtt.value();
            } catch (IOException ex3) {
                divaThumbPath = null;
            }
            if (divaThumbPath == null || divaThumbPath.trim().length() < 1) {
                thumbFig = null;
            } else {
                // clear the caches
                _recreateFigure();

                PaintedList paintedList = null;
                try {
                    paintedList = _divaCreatePaintedList(divaThumbPath.trim());
                    thumbFig = new PaintedFigure(paintedList);
                } catch (Exception ex4) {
                    thumbFig = null;
                }
            }
        }
    }

    // 3) looks for a cached actor icon (_bgFigure).
    if (thumbFig == null && _bgFigure != null) {
        thumbFig = _bgFigure;
    }

    // 4) If no cached one is available, it creates a scaled version of the
    // background figure by calling _divaCreateBackgroundFigure(), using
    // old-style Diva svg rendering to render the simple-svg description
    // in the (*large*) "_iconDescription" attribute, if it exists. Uses
    // diva because batik is very memory intensive, and is not needed
    // for this simple svg.
    if (thumbFig == null) {
        if (isDebugging) {
            log.debug("getIcon() : " + container.getClass().getName()
                    + " - doing thumbFig = createBackgroundFigure()");
        }
        thumbFig = createBackgroundFigure();
    }

    // 5) If all else fails, it simply defers to the base class.
    if (thumbFig == null) {
        return super.createIcon();
    }

    // The last argument says to turn anti-aliasing on.
    if (isBatikRendering) {
        _iconCache = new FigureIcon(thumbFig, 16, 16, 0, true);
    } else {
        // NOTE: The size is hardwired here. Should it be?
        // The second to last argument specifies the border.
        _iconCache = new FigureIcon(thumbFig, 20, 15, 0, true);
    }
    return _iconCache;
}

From source file:paquete.Ventana.java

private void muestraRecorridoMapa() {
    //Cambia los siguientes valores por las direciones de origen y destino deseadas
    String origen = jTextLatitud.getText() + "," + jTextLongitud.getText();
    String destino = jTextDestino.getText();

    //Hay que sustituir los espacios por el carcter %20 para que se
    //  interprete bien la URL que se generar
    destino = destino.replaceAll(" ", "%20");

    //Cambia el nombre [etiqueta] por el nombre de un objeto JLabel (etiqueta) que
    //  has debido colocar antes en el formulario y que ser donde se muestre el mapa.
    //  Deja la etiqueta del formulario sin ningn texto en el diseo.
    javax.swing.JLabel jLabelMapa = jLabelMapaRuta;

    //Indica aqu el tamao que desees para el mapa
    int tamHorizontal = 200;
    int tamVertical = 200;
    //Puedes encontrar ms informacin sobre el uso de mapas estticos de Google Maps aqu:
    //  http://code.google.com/intl/es-ES/apis/maps/documentation/staticmaps/

    //A partir de aqu no hace falta cambiar nada
    try {//from w w  w  .  j a v  a2 s.  c  o  m
        String txtDireccionImagenMapa = "http://maps.google.com/maps/api/staticmap?path=" + origen + "|"
                + destino + "&size=" + tamHorizontal + "x" + tamVertical + "&language=ES&sensor=false";
        System.out.println(txtDireccionImagenMapa);
        java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
        java.awt.Image imagenMapa = toolkit.getImage(new java.net.URL(txtDireccionImagenMapa));
        jLabelMapa.setIcon(new javax.swing.ImageIcon(imagenMapa));
    } catch (java.net.MalformedURLException e) {
        javax.swing.JOptionPane.showMessageDialog(this, "La direccin de imagen indicada no es correcta");
    }
}

From source file:processing.app.Theme.java

/**
 * Return an Image object from inside the Processing lib folder.
 *//*from   w  w w.j  a va2  s  .  c  o  m*/
static public Image getLibImage(String filename, Component who, int width, int height) {
    Image image = null;

    // Use vector image when available
    Resource vectorFile = getThemeResource(filename + ".svg");
    if (vectorFile.exists()) {
        try {
            image = imageFromSVG(vectorFile.getUrl(), width, height);
        } catch (Exception e) {
            System.err.println("Failed to load " + vectorFile + ": " + e.getMessage());
        }
    }

    Resource bitmapFile = getThemeResource(filename + ".png");

    // Otherwise fall-back to PNG bitmaps, allowing user-defined bitmaps to
    // override built-in svgs
    if (image == null || bitmapFile.getPriority() > vectorFile.getPriority()) {
        Resource bitmap2xFile = getThemeResource(filename + "@2x.png");

        Resource imageFile;
        if (((getScale() > 125 && bitmap2xFile.exists()) || !bitmapFile.exists())
                && (bitmapFile.isUserDefined() && bitmap2xFile.isUserDefined())) {
            imageFile = bitmap2xFile;
        } else {
            imageFile = bitmapFile;
        }
        Toolkit tk = Toolkit.getDefaultToolkit();
        image = tk.getImage(imageFile.getUrl());
    }

    MediaTracker tracker = new MediaTracker(who);
    try {
        tracker.addImage(image, 0);
        tracker.waitForAll();
    } catch (InterruptedException e) {
    }

    if (image.getWidth(null) != width || image.getHeight(null) != height) {
        image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
        try {
            tracker.addImage(image, 1);
            tracker.waitForAll();
        } catch (InterruptedException e) {
        }
    }

    return image;
}

From source file:rems.Program.java

public static String formatDtSt(ResultSet dtst, String rptTitle, String[] colsToGrp, String[] colsToCnt,
        String[] colsToSum, String[] colsToAvrg, String[] colsToFrmt) {
    try {// w ww  . ja v a2s. c  o m
        DecimalFormat myFormatter = new DecimalFormat("###,##0.00");
        DecimalFormat myFormatter2 = new DecimalFormat("###,##0");
        String finalStr = rptTitle.toUpperCase();
        finalStr += "\r\n\r\n";
        ResultSetMetaData dtstmd = dtst.getMetaData();
        dtst.last();
        int ttlRws = dtst.getRow();
        dtst.beforeFirst();
        int colCnt = dtstmd.getColumnCount();

        long[] colcntVals = new long[colCnt];
        double[] colsumVals = new double[colCnt];
        double[] colavrgVals = new double[colCnt];
        finalStr += "|";
        for (int f = 0; f < colCnt; f++) {
            int colLen = dtstmd.getColumnName(f + 1).length();
            if (colLen >= 3) {
                finalStr += StringUtils.rightPad("=", colLen, '=');
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        finalStr += "|";
        for (int e = 0; e < colCnt; e++) {
            int colLen = dtstmd.getColumnName(e + 1).length();
            if (colLen >= 3) {
                if (Program.mustColBeFrmtd(String.valueOf(e), colsToFrmt) == true) {
                    finalStr += StringUtils.leftPad(dtstmd.getColumnName(e + 1).substring(0, colLen - 2).trim(),
                            colLen, ' ');
                } else {
                    finalStr += StringUtils.leftPad(dtstmd.getColumnName(e + 1).substring(0, colLen - 2),
                            colLen, ' ');
                }
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        finalStr += "|";
        for (int f = 0; f < colCnt; f++) {
            int colLen = dtstmd.getColumnName(f + 1).length();
            if (colLen >= 3) {
                finalStr += StringUtils.rightPad("=", colLen, '=');
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        String[][] prevRowVal = new String[ttlRws][colCnt];
        for (int i = 0; i < ttlRws; i++) {
            String[][] lineFormat = new String[colCnt][];
            dtst.next();
            for (int a = 0; a < colCnt; a++) {
                double nwval = 0;
                prevRowVal[i][a] = dtst.getString(a + 1);

                boolean mstgrp = mustColBeGrpd(String.valueOf(a), colsToGrp);
                if (mustColBeCntd(String.valueOf(a), colsToCnt) == true) {
                    if ((i > 0) && (prevRowVal[i - 1][a].equals(dtst.getString(a + 1))) && (mstgrp == true)) {
                    } else {
                        colcntVals[a] += 1;
                    }
                } else if (mustColBeSumd(String.valueOf(a), colsToSum) == true) {
                    nwval = Double.parseDouble(dtst.getString(a + 1));
                    if ((i > 0) && (prevRowVal[i - 1][a].equals(dtst.getString(a + 1))) && (mstgrp == true)) {
                    } else {
                        colsumVals[a] += nwval;
                    }
                } else if (mustColBeAvrgd(String.valueOf(a), colsToAvrg) == true) {
                    nwval = Double.parseDouble(dtst.getString(a + 1));
                    if ((i > 0) && (prevRowVal[i - 1][a].equals(dtst.getString(a + 1))) && (mstgrp == true)) {
                    } else {
                        colcntVals[a] += 1;
                        colsumVals[a] += nwval;
                    }
                }

                int colLen = dtstmd.getColumnName(a + 1).length();
                String[] arry;
                BufferedImage bi;
                Graphics g; // stands for Buffered Image Graphics
                Toolkit toolkit;
                MediaTracker tracker;
                if (colLen >= 3) {
                    if ((i > 0) && (prevRowVal[i - 1][a].equals(dtst.getString(a + 1)))
                            && (mustColBeGrpd(String.valueOf(a), colsToGrp) == true)) {
                        toolkit = Toolkit.getDefaultToolkit();
                        Image img = toolkit.getImage(Global.appStatPath + "/staffs.png");
                        Font nwFont = new Font("Courier New", 11, Font.PLAIN);
                        bi = new BufferedImage(70, 70, BufferedImage.TYPE_INT_RGB);
                        g = bi.getGraphics();
                        float ght = (float) g.getFontMetrics(nwFont).stringWidth(
                                StringUtils.rightPad(dtstmd.getColumnName(a + 1).trim(), colLen, '='));
                        float ght1 = (float) g.getFontMetrics(nwFont).stringWidth("=");
                        arry = breakDownStr("    ", colLen, 25, g, ght - ght1);
                    } else {
                        toolkit = Toolkit.getDefaultToolkit();
                        Image img = toolkit.getImage(Global.appStatPath + "/staffs.png");
                        Font nwFont = new Font("Courier New", 11, Font.PLAIN);
                        bi = new BufferedImage(70, 70, BufferedImage.TYPE_INT_RGB);
                        g = bi.getGraphics();
                        float ght = (float) g.getFontMetrics(nwFont).stringWidth(
                                StringUtils.rightPad(dtstmd.getColumnName(a + 1).trim(), colLen, '='));
                        float ght1 = (float) g.getFontMetrics(nwFont).stringWidth("=");
                        arry = breakDownStr(dtst.getString(a + 1), colLen, 25, g, ght - ght1);
                    }
                    lineFormat[a] = arry;
                }
            }
            String frshLn = "";
            for (int c = 0; c < 25; c++) {
                String frsh = "|";
                for (int b = 0; b < colCnt; b++) {
                    int colLen = dtstmd.getColumnName(b + 1).length();
                    if (colLen >= 3) {
                        if (Program.mustColBeFrmtd(String.valueOf(b), colsToFrmt) == true) {
                            double num = Double.parseDouble(lineFormat[b][c].trim());
                            if (!lineFormat[b][c].trim().equals("")) {
                                frsh += StringUtils.leftPad(myFormatter.format(num), colLen, ' ').substring(0,
                                        colLen);//.trim().PadRight(60, ' ')
                            } else {
                                frsh += lineFormat[b][c].substring(0, colLen); //.trim().PadRight(60, ' ')
                            }
                        } else {
                            frsh += lineFormat[b][c].substring(0, colLen); //.trim().PadRight(60, ' ')
                        }
                        frsh += "|";
                    }
                }
                String nwtst = frsh;
                frsh += "\r\n";
                if (nwtst.replace("|", " ").trim().equals("")) {
                    c = 24;
                } else {
                    frshLn += frsh;
                }
            }
            finalStr += frshLn;
        }
        finalStr += "\r\n";
        finalStr += "|";
        for (int f = 0; f < colCnt; f++) {
            int colLen = dtstmd.getColumnName(f + 1).length();
            if (colLen >= 3) {
                finalStr += StringUtils.rightPad("=", colLen, '=');
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        finalStr += "|";
        //Populate Counts/Sums/Averages
        for (int f = 0; f < colCnt; f++) {
            int colLen = dtstmd.getColumnName(f + 1).length();
            if (colLen >= 3) {
                if (mustColBeCntd(String.valueOf(f), colsToCnt) == true) {
                    if (mustColBeFrmtd(String.valueOf(f), colsToFrmt) == true) {
                        finalStr += "Count = " + StringUtils
                                .leftPad(myFormatter2.format(colcntVals[f]), colLen, ' ').substring(0, colLen);
                    } else {
                        finalStr += "Count = " + StringUtils
                                .rightPad(String.valueOf(colcntVals[f]), colLen, ' ').substring(0, colLen);
                    }
                } else if (mustColBeSumd(String.valueOf(f), colsToSum) == true) {
                    if (mustColBeFrmtd(String.valueOf(f), colsToFrmt) == true) {
                        finalStr += "Sum = " + StringUtils
                                .leftPad(myFormatter.format(colsumVals[f]), colLen, ' ').substring(0, colLen);
                    } else {
                        finalStr += "Sum = " + StringUtils.rightPad(String.valueOf(colsumVals[f]), colLen, ' ')
                                .substring(0, colLen);
                    }
                } else if (mustColBeAvrgd(String.valueOf(f), colsToAvrg) == true) {
                    if (mustColBeFrmtd(String.valueOf(f), colsToFrmt) == true) {
                        finalStr += "Average = " + StringUtils
                                .leftPad((myFormatter.format(colsumVals[f] / colcntVals[f])), colLen, ' ')
                                .substring(0, colLen);
                    } else {
                        finalStr += "Average = " + StringUtils
                                .rightPad((String.valueOf(colsumVals[f] / colcntVals[f])), colLen, ' ')
                                .substring(0, colLen);
                    }
                } else {
                    finalStr += StringUtils.rightPad(" ", colLen, ' ').substring(0, colLen);
                }
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        finalStr += "|";
        for (int f = 0; f < colCnt; f++) {
            int colLen = dtstmd.getColumnName(f + 1).length();
            if (colLen >= 3) {
                finalStr += StringUtils.rightPad("-", colLen, '-').substring(0, colLen);
                finalStr += "|";
            }
        }
        finalStr += "\r\n";
        return finalStr;
    } catch (SQLException ex) {
        return "";
    } catch (NumberFormatException ex) {
        return "";
    }
}

From source file:taximetro.main.java

private void jTextFielddestinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFielddestinoActionPerformed
    //Generar el mapa a partir de la direccin en formato texto introducida.
    //al darle a Enter.
    String origen = jTextFieldlatitud.getText() + "," + jTextFieldlongitud.getText();
    String destino = jTextFielddestino.getText();
    //Hay que sustituir los espacios por el carcter %20 para que se
    //  interprete bien la URL que se generar
    destino = destino.replaceAll(" ", "%20");
    //Cambia el nombre [etiqueta] por el nombre de un objeto JLabel (etiqueta) que
    //  has debido colocar antes en el formulario y que ser donde se muestre el mapa.
    //  Deja la etiqueta del formulario sin ningn texto en el diseo.
    javax.swing.JLabel jLabelMapa = jLabelmapa;
    //Indica aqu el tamao que desees para el mapa
    int tamHorizontal = 200;
    int tamVertical = 200;
    //Puedes encontrar ms informacin sobre el uso de mapas estticos de Google Maps aqu:
    //  http://code.google.com/intl/es-ES/apis/maps/documentation/staticmaps/

    //A partir de aqu no hace falta cambiar nada
    try {//from  w w w  .  j  a va  2  s .  c om
        String txtDireccionImagenMapa = "http://maps.google.com/maps/api/staticmap?path=" + origen + "|"
                + destino + "&size=" + tamHorizontal + "x" + tamVertical + "&language=ES&sensor=false";
        System.out.println(txtDireccionImagenMapa);
        java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
        java.awt.Image imagenMapa = toolkit.getImage(new java.net.URL(txtDireccionImagenMapa));
        jLabelMapa.setIcon(new javax.swing.ImageIcon(imagenMapa));
    } catch (java.net.MalformedURLException e) {
        javax.swing.JOptionPane.showMessageDialog(this, "La direccin de imagen indicada no es correcta");
    }
}

From source file:taximetro.Taximetro.java

private void direccionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_direccionFocusLost
    //Cambia los siguientes valores por las direciones de origen y destino deseadas
    String origen = latitudFormato.getText() + "," + longitudFormato.getText();
    String destino = direccion.getText();
    //Hay que sustituir los espacios por el carcter %20 para que se
    //  interprete bien la URL que se generar
    destino = destino.replaceAll(" ", "%20");
    //Cambia el nombre [etiqueta] por el nombre de un objeto JLabel (etiqueta) que
    //  has debido colocar antes en el formulario y que ser donde se muestre el mapa.
    //  Deja la etiqueta del formulario sin ningn texto en el diseo.
    javax.swing.JLabel jLabelMapa = mapa;
    //Indica aqu el tamao que desees para el mapa
    int tamHorizontal = 256;
    int tamVertical = 256;
    //Puedes encontrar ms informacin sobre el uso de mapas estticos de Google Maps aqu:
    //  http://code.google.com/intl/es-ES/apis/maps/documentation/staticmaps/

    //A partir de aqu no hace falta cambiar nada
    try {/*from   w  w w . jav a 2s  .  c  o  m*/
        String txtDireccionImagenMapa = "http://maps.google.com/maps/api/staticmap?path=" + origen + "|"
                + destino + "&size=" + tamHorizontal + "x" + tamVertical + "&language=ES&sensor=false";
        System.out.println(txtDireccionImagenMapa);
        java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
        java.awt.Image imagenMapa = toolkit.getImage(new java.net.URL(txtDireccionImagenMapa));
        jLabelMapa.setIcon(new javax.swing.ImageIcon(imagenMapa));
    } catch (java.net.MalformedURLException e) {
        javax.swing.JOptionPane.showMessageDialog(this, "La direccin de imagen indicada no es correcta");
    }
}

From source file:taximetrotema2.Main.java

private void jToggleButtonBanderaVerdeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButtonBanderaVerdeActionPerformed
    jToggleButtonStop.setEnabled(true);//from   w w w.jav a 2  s . c  o  m

    fechaHoraSalida = Calendar.getInstance();
    formatoHora.format(fechaHoraSalida.getTime());

    double latitud = Double.valueOf(jTextFieldLatitud.getText());
    double longitud = Double.valueOf(jTextFieldLongitud.getText());

    CoordinatesConverter conversorCoordenadas = new CoordinatesConverter();
    jLabel4.setText(conversorCoordenadas.decimalToDMS(latitud));
    jLabel5.setText(conversorCoordenadas.decimalToDMS(longitud));

    //Cambia los siguientes valores por las direciones de origen y destino deseadas
    String origen = jTextFieldLatitud.getText() + "," + jTextFieldLongitud.getText();
    String destino = jTextFieldDestino.getText();
    //Hay que sustituir los espacios por el carcter %20 para que se
    //  interprete bien la URL que se generar
    destino = destino.replaceAll(" ", "%20");
    //Cambia el nombre [etiqueta] por el nombre de un objeto JLabel (etiqueta) que
    //  has debido colocar antes en el formulario y que ser donde se muestre el mapa.
    //  Deja la etiqueta del formulario sin ningn texto en el diseo.
    javax.swing.JLabel jLabelMapa = jLabelMapaRuta;
    //Indica aqu el tamao que desees para el mapa
    int tamHorizontal = 300;
    int tamVertical = 270;
    //Puedes encontrar ms informacin sobre el uso de mapas estticos de Google Maps aqu:
    //  http://code.google.com/intl/es-ES/apis/maps/documentation/staticmaps/

    //A partir de aqu no hace falta cambiar nada
    try {
        String txtDireccionImagenMapa = "http://maps.google.com/maps/api/staticmap?path=" + origen + "|"
                + destino + "&size=" + tamHorizontal + "x" + tamVertical + "&language=ES&sensor=false";
        System.out.println(txtDireccionImagenMapa);
        java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
        java.awt.Image imagenMapa = toolkit.getImage(new java.net.URL(txtDireccionImagenMapa));
        jLabelMapa.setIcon(new javax.swing.ImageIcon(imagenMapa));
    } catch (java.net.MalformedURLException e) {
        javax.swing.JOptionPane.showMessageDialog(this, "La direccin de imagen indicada no es correcta");
    }
    jToggleButtonBanderaVerde.setEnabled(false);
}

From source file:View.FormAnggota.java

private void tabel_anggotaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabel_anggotaMouseClicked
    try {/*ww w  . j a v  a  2s.  c om*/
        custom();
        int row1 = tabel_anggota.getSelectedRow();
        text_idAnggota.setText(tabel_anggota.getValueAt(row1, 0).toString());
        Anggota agt = AnggotaKontrol.getKoneksi().cariIdAnggota(tabel_anggota.getValueAt(row1, 1).toString());
        text_nama.setText(agt.getNamaAnggota());
        text_pekerjaan.setText(agt.getPekerjaan());
        text_alamat.setText(agt.getAlamat());
        text_rt.setText(Integer.toString(agt.getRt()));
        text_rw.setText(Integer.toString(agt.getRw()));
        combo_dusun.setSelectedItem(agt.getDusun());
        text_desa.setText(agt.getDesa());
        text_kota.setText(agt.getKota());
        text_provinsi.setText(agt.getProvinsi());
        text_telp.setText(agt.getNoTelp());
        text_ktp.setText(agt.getNoKTP());
        text_kecamatan.setText(agt.getKecamatan());

        Anggota foto = AnggotaKontrol.getKoneksi().selectAnggota(agt.getIdAnggota());
        String path = new File(".").getCanonicalPath();
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image image = toolkit.getImage(path + "/Gambar/" + foto.getLogo());
        //            Image imagedResized = image.getScaledInstance(200, 250, Image.SCALE_DEFAULT);
        Image imagedResized = image.getScaledInstance(175, 250, Image.SCALE_DEFAULT);
        ImageIcon imageIcon = new ImageIcon(imagedResized);

        label_Gambar.setIcon(imageIcon);
        label_namaFile.setText(foto.getLogo());

        dialog_anggota.setVisible(false);
        text_biaya.setEditable(false);
    } catch (SQLException ex) {
        Logger.getLogger(FormAnggota.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(FormAnggota.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:View.FormAnggota.java

private void button_uploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_uploadActionPerformed
    JFileChooser jfc = new JFileChooser();
    if (jfc.showOpenDialog(label_Gambar) == JFileChooser.APPROVE_OPTION) {

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image image = toolkit.getImage(jfc.getSelectedFile().getAbsolutePath());
        Image imagedResized = image.getScaledInstance(175, 250, Image.SCALE_DEFAULT);
        ImageIcon imageIcon = new ImageIcon(imagedResized);

        label_Gambar.setIcon(imageIcon);
        label_namaFile.setText(jfc.getSelectedFile().getName());//nama file nya
        //            System.out.println("jLabelnamaFile : " + label_namaFile.getText());

        file = new File(jfc.getSelectedFile().getPath()); // file untuk dikopi
        //            System.out.println("file : " + file.getPath());
    }/*from  w w w . jav  a 2s .  c o  m*/
}