Example usage for java.util Formatter format

List of usage examples for java.util Formatter format

Introduction

In this page you can find the example usage for java.util Formatter format.

Prototype

public Formatter format(String format, Object... args) 

Source Link

Document

Writes a formatted string to this object's destination using the specified format string and arguments.

Usage

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql.CFAccPgSqlSchema.java

public static String getQuotedTimestampString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/*from w w  w.  j  a  v a 2s .  c  om*/
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", val.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", val.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH));
        buff.append(" ");
        fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY));
        buff.append(":");
        fmt.format("%1$02d", val.get(Calendar.MINUTE));
        buff.append(":");
        fmt.format("%1$02d", val.get(Calendar.SECOND));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getTZDateString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {// w ww.  j a  v  a  2s.  co m
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer();
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getTZTimeString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/*w  w  w.  j  av  a  2  s.  c o m*/
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer();
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getTZTimestampString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/*from   w  w w .j  a  v a  2 s . c o  m*/
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer();
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getQuotedTZDateString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/*w  w  w . j a v a2  s .c om*/
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getQuotedTZTimeString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//w w w .  j  a  v  a2 s .  co  m
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getQuotedTZTimestampString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//w  ww  .  j  ava2 s .  c  o  m
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:edu.ku.brc.af.auth.UserAndMasterPasswordMgr.java

/**
 * Super simple encryption of just converting string to HEX.
 * @param str the string to be encrypted
 * @return hex-ified string// w w w  .ja  va 2s.  c o  m
 */
private String encrypt(final String str) {
    Formatter formatter = new Formatter();
    for (byte b : str.getBytes()) {
        formatter.format("%02x", b);
    }
    String s = formatter.toString();
    formatter.close();
    return s;
}

From source file:edu.ku.brc.specify.tasks.subpane.LocalityMapperSubPane.java

/**
 *
 *///from w w  w .  j a va  2s.c o m
protected void createUI() {
    kmlGen = new CollectingEventLocalityKMLGenerator();
    this.collectingEvents = new ArrayList<CollectingEvent>();

    CollectingEvent startCE = null;
    CollectingEvent endCE = null;

    Vector<Locality> localities = new Vector<Locality>();
    Vector<String> labels = new Vector<String>();
    for (Object obj : colEvents) {
        CollectingEvent collectingEvent = (CollectingEvent) obj;

        Locality locality = collectingEvent.getLocality();
        if (locality == null || locality.getLatitude1() == null || locality.getLongitude1() == null) {
            continue;
        }

        collectingEvents.add(collectingEvent);
        kmlGen.addDataObj(collectingEvent, "");

        if (collectingEvents.size() == 1) {
            startCE = collectingEvent;
            endCE = collectingEvent;
        }
        // XXX TODO FIX ME!
        if (startCE == null || endCE == null) {
            return;
        }
        // There may be an End Date that is further out than than the End Date of the last item
        // with the latest Start Date
        if (startCE.getStartDate().compareTo(collectingEvent.getStartDate()) > 1) {
            startCE = collectingEvent;
        }
        Calendar leftCal = endCE.getEndDate() != null ? endCE.getEndDate() : endCE.getStartDate();
        Calendar rightCal = collectingEvent.getEndDate() != null ? collectingEvent.getEndDate()
                : collectingEvent.getStartDate();
        if (leftCal.compareTo(rightCal) < 0) {
            endCE = collectingEvent;
        }

        Hashtable<String, Object> map = new Hashtable<String, Object>();

        Set<CollectionObject> colObjs = collectingEvent.getCollectionObjects();

        map.put("startDate", collectingEvent.getStartDate());
        map.put("endDate", collectingEvent.getEndDate());

        Set<Object> taxonNames = new HashSet<Object>();
        for (CollectionObject co : colObjs) {
            for (Determination d : co.getDeterminations()) {
                if (d.isCurrentDet()) {
                    //System.out.println(d.getTaxon().getName() + "("+co.getCountAmt()+")");
                    Taxon taxon = d.getPreferredTaxon();
                    if (taxon != null) {
                        taxonNames.add(taxon.getName()
                                + (co.getCountAmt() != null ? " (" + co.getCountAmt() + ")" : ""));
                        if (taxon.getRankId() == 220) {
                            Taxon genus = taxon.getParent();
                            if (genus.getRankId() == 180) {
                                ImageGetter imgGetter = new ImageGetter(imageGetterList, imageMap, imageURLs,
                                        genus.getName(), taxon.getName());
                                imageGetterList.add(imgGetter);
                            }
                        }
                    }
                    break;
                }
            }
        }
        map.put("taxonItems", taxonNames);

        map.put("latitude1", locality.getLatitude1());
        map.put("longitude1", locality.getLongitude1());

        /*
        Calendar cal = collectingEvent.getStartDate();
        if (cal != null)
        {
          labels.add(scrDateFormat.format(cal.getTime()));
                
        } else if (collectingEvent.getVerbatimDate() != null)
        {
          labels.add(collectingEvent.getVerbatimDate());
                
        } else
        {
          labels.add(Integer.toString(collectingEvent.getCollectingEventId()));
                
        }
        */
        labels.add(Integer.toString(collectingEvents.size()));
        localities.add(locality);
        valueList.add(map);

    }

    // XXX Fix me shouldn't be hard coded here to make it work
    localityMapper.setMaxMapWidth(515);
    localityMapper.setMaxMapHeight(375);

    Color arrow = new Color(220, 220, 220);
    localityMapper.setArrowColor(arrow);
    localityMapper.setDotColor(Color.WHITE);
    localityMapper.setDotSize(4);
    localityMapper.setLabelColor(Color.RED);

    int inx = 0;
    for (Locality locality : localities) {
        localityMapper.addLocationAndLabel(locality, labels != null ? labels.get(inx) : null);
        inx++;
    }
    localityMapper.setCurrentLoc(localities.get(0));
    localityMapper.setCurrentLocColor(Color.RED);

    // XXX DEMO  (Hard Coded 'null' means everyone would have one which may not be true)
    // "null" ViewSet name means it should use the default
    ViewIFace view = AppContextMgr.getInstance().getView("LocalityMapper");

    // TODO WHERE's the ERROR checking !
    multiView = new MultiView(null, null, view, AltViewIFace.CreationMode.VIEW, MultiView.NO_OPTIONS);
    multiView.setBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(new Color(138, 128, 128)),
                    BorderFactory.createEmptyBorder(4, 4, 4, 4)));

    formViewObj = multiView.getCurrentViewAsFormViewObj();
    formViewObj.getUIComponent().setBackground(Color.WHITE);

    imageJList = formViewObj.getCompById("taxonItems");
    imageJList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                String nameStr = (String) imageJList.getSelectedValue();
                if (nameStr != null) {
                    int index = nameStr.indexOf(" (");
                    if (index > -1) {
                        nameStr = nameStr.substring(0, index);
                    }
                }

                //System.out.println("Getting["+name+"]");
                Image img = null;
                if (StringUtils.isNotEmpty(nameStr)) {
                    img = imageMap.get(nameStr); // might return null
                    ImageDisplay imgDisplay = formViewObj.getCompById("image");
                    if (img != null) {
                        imgDisplay.setImage(new ImageIcon(img));
                    } else {
                        imgDisplay.setImage((Image) null);
                    }
                }

            }
        }
    });

    // XXX TODO FIX ME!
    if (startCE == null || endCE == null) {
        return;
    }
    String startDateStr = scrDateFormat.format(startCE.getStartDate().getTime());
    String endDateStr = scrDateFormat
            .format((endCE.getEndDate() != null ? endCE.getEndDate() : endCE.getStartDate()).getTime());

    Formatter formatter = new Formatter();
    titleLabel.setText(formatter
            .format(getResourceString("LocalityMapperTitle"), new Object[] { startDateStr, endDateStr })
            .toString());

    Font font = titleLabel.getFont();
    titleLabel.setFont(new Font(font.getFontName(), Font.BOLD, font.getSize() + 2));

    recordSetController = new ResultSetController(null, false, false, false, null, collectingEvents.size(),
            true);
    recordSetController.addListener(this);
    recordSetController.getPanel().setBackground(Color.WHITE);

    controlPanel = new ControlBarPanel(getBackground());
    controlPanel.add(recordSetController.getPanel());
    controlPanel.setRecordSetController(recordSetController);
    controlPanel.setBackground(Color.WHITE);

    googleBtn = new JButton(IconManager.getIcon("GoogleEarth", IconManager.STD_ICON_SIZE));
    googleBtn.setMargin(new Insets(1, 1, 1, 1));
    googleBtn.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    googleBtn.setSize(new Dimension(18, 18));
    googleBtn.setPreferredSize(new Dimension(18, 18));
    googleBtn.setMaximumSize(new Dimension(18, 18));
    googleBtn.setFocusable(false);
    googleBtn.setBackground(Color.WHITE);

    controlPanel.addButtons(new JButton[] { googleBtn }, false);

    googleBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                UIRegistry.displayStatusBarText("Exporting Collecting Events in KML."); // XXX I18N
                kmlGen.setSpeciesToImageMapper(imageURLs);
                kmlGen.outputToFile(System.getProperty("user.home") + File.separator + "specify.kml");

            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(LocalityMapperSubPane.class, ex);
                ex.printStackTrace();
            }
        }
    });

    addMouseMotionListener(new MouseMotionListener() {
        public void mouseDragged(MouseEvent e) {
            // nothing
        }

        public void mouseMoved(MouseEvent e) {
            checkMouseLocation(e.getPoint(), false);
        }
    });

    addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            checkMouseLocation(e.getPoint(), true);
        }

    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            getLocalityMap();
        }
    });

}

From source file:net.sourceforge.fenixedu.domain.candidacy.PersonalInformationBean.java

public String getFormattedValues() {
    Formatter result = new Formatter();

    final Student student = getStudent();
    result.format("Student Number: %d\n", student.getNumber());
    result.format("Name: %s\n", student.getPerson().getName());
    if (hasPhdIndividualProgramProcess()) {
        result.format("Degree: %s\n", getPhdIndividualProgramProcess().getDisplayName());
    } else {/*from   w  ww. j a v a  2s.co m*/
        result.format("Degree: %s\n", getRegistration().getDegree().getPresentationName());
    }

    return result.toString();
}