Example usage for java.text DecimalFormat setMaximumFractionDigits

List of usage examples for java.text DecimalFormat setMaximumFractionDigits

Introduction

In this page you can find the example usage for java.text DecimalFormat setMaximumFractionDigits.

Prototype

@Override
public void setMaximumFractionDigits(int newValue) 

Source Link

Document

Sets the maximum number of digits allowed in the fraction portion of a number.

Usage

From source file:org.yccheok.jstock.gui.NewSellTransactionJDialog.java

private void initComponentsWithoutBrokerageFirm() {
    jPanel2 = new javax.swing.JPanel();
    jTextField1 = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    jSpinner1 = new javax.swing.JSpinner();
    jPanel3 = CalendarFactory.createDateField();
    jLabel4 = new javax.swing.JLabel();
    jFormattedTextField1 = getCurrencyJFormattedTextField(false);
    jFormattedTextField2 = getCurrencyJFormattedTextField(false);
    jFormattedTextField3 = getCurrencyJFormattedTextField(false);
    jFormattedTextField4 = getCurrencyJFormattedTextField(false);
    jFormattedTextField5 = getCurrencyJFormattedTextField(false);
    jLabel10 = new javax.swing.JLabel();
    jFormattedTextField6 = getPercentageJFormattedTextField();
    jLabel1 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    jFormattedTextField7 = getCurrencyJFormattedTextField(false);
    jLabel11 = new javax.swing.JLabel();
    jFormattedTextField8 = getCurrencyJFormattedTextField(true);
    jLabel12 = new javax.swing.JLabel();
    jPanel4 = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jPanel1 = new javax.swing.JPanel();
    jLabel6 = new javax.swing.JLabel();
    jButton3 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui"); // NOI18N
    setTitle(bundle.getString("NewSellTransactionJDialog_Sell")); // NOI18N
    setResizable(false);/*from w  w  w.  j a  v  a 2s  . c  o m*/

    jPanel2.setBorder(javax.swing.BorderFactory
            .createTitledBorder(bundle.getString("NewSellTransactionJDialog_Transaction"))); // NOI18N

    jTextField1.setEditable(false);

    jLabel2.setText(bundle.getString("NewBuyTransactionJDialog_Symbol")); // NOI18N

    jSpinner1.setModel(new javax.swing.SpinnerNumberModel(100.0d, 0.001d, null, 100.0d));
    JSpinner.NumberEditor numberEditor = (JSpinner.NumberEditor) jSpinner1.getEditor();
    final DecimalFormat decimalFormat = numberEditor.getFormat();
    decimalFormat.setMaximumFractionDigits(4);
    numberEditor.getTextField().addMouseListener(getJFormattedTextFieldMouseListener());
    jSpinner1.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            jSpinner1StateChanged(evt);
        }
    });

    jPanel3.setBackground(new java.awt.Color(204, 255, 255));
    jPanel3.setMaximumSize(new java.awt.Dimension(32767, 20));
    jPanel3.setPreferredSize(new java.awt.Dimension(100, 20));

    jLabel4.setText(bundle.getString("NewBuyTransactionJDialog_Date")); // NOI18N

    jFormattedTextField1.setValue(new Double(0.0));
    jFormattedTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jFormattedTextField1KeyTyped(evt);
        }
    });

    jFormattedTextField2.setEditable(false);
    jFormattedTextField2.setValue(new Double(0.0));

    jFormattedTextField3.setEditable(false);
    jFormattedTextField3.setValue(new Double(0.0));

    jFormattedTextField4.setValue(new Double(0.0));
    jFormattedTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jFormattedTextField4KeyTyped(evt);
        }
    });

    jFormattedTextField5.setValue(new Double(0.0));
    jFormattedTextField5.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jFormattedTextField5KeyTyped(evt);
        }
    });

    jLabel10.setFont(jLabel10.getFont().deriveFont(jLabel10.getFont().getStyle() | java.awt.Font.BOLD));
    jLabel10.setText(bundle.getString("NewSellTransactionJDialog_Profit%")); // NOI18N

    jFormattedTextField6.setEditable(false);
    jFormattedTextField6.setFont(jFormattedTextField6.getFont()
            .deriveFont(jFormattedTextField6.getFont().getStyle() | java.awt.Font.BOLD));
    jFormattedTextField6.setValue(new Double(0.0));

    jLabel1.setText(bundle.getString("NewSellTransactionJDialog_Unit")); // NOI18N

    jLabel3.setText(bundle.getString("NewSellTransactionJDialog_Price")); // NOI18N

    jLabel5.setText(bundle.getString("NewSellTransactionJDialog_Value")); // NOI18N

    jLabel7.setText(bundle.getString("NewSellTransactionJDialog_BuyCost")); // NOI18N

    jLabel8.setText(bundle.getString("NewSellTransactionJDialog_Broker")); // NOI18N

    jLabel9.setText(bundle.getString("NewSellTransactionJDialog_Clearing")); // NOI18N

    jFormattedTextField7.setValue(new Double(0.0));
    jFormattedTextField7.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jFormattedTextField7KeyTyped(evt);
        }
    });

    jLabel11.setText(bundle.getString("NewSellTransactionJDialog_StampDuty")); // NOI18N

    jFormattedTextField8.setEditable(false);
    jFormattedTextField8.setFont(jFormattedTextField8.getFont()
            .deriveFont(jFormattedTextField8.getFont().getStyle() | java.awt.Font.BOLD));
    jFormattedTextField8.setValue(new Double(0.0));

    jLabel12.setFont(jLabel12.getFont().deriveFont(jLabel12.getFont().getStyle() | java.awt.Font.BOLD));
    jLabel12.setText(bundle.getString("NewSellTransactionJDialog_Profit$")); // NOI18N

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(jPanel2Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel9)
                    .addComponent(jLabel2).addComponent(jLabel3).addComponent(jLabel5).addComponent(jLabel7)
                    .addComponent(jLabel8).addComponent(jLabel1).addComponent(jLabel4).addComponent(jLabel11)
                    .addComponent(jLabel12).addComponent(jLabel10))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jFormattedTextField6, javax.swing.GroupLayout.DEFAULT_SIZE, 109,
                                    Short.MAX_VALUE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 109,
                                    Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                            .addComponent(jSpinner1, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                            .addComponent(jFormattedTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 109,
                                    Short.MAX_VALUE)
                            .addComponent(jFormattedTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 109,
                                    Short.MAX_VALUE)
                            .addComponent(jFormattedTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 109,
                                    Short.MAX_VALUE)
                            .addComponent(jFormattedTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 109,
                                    Short.MAX_VALUE)
                            .addComponent(jFormattedTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 109,
                                    Short.MAX_VALUE)
                            .addComponent(jFormattedTextField7, javax.swing.GroupLayout.DEFAULT_SIZE, 101,
                                    Short.MAX_VALUE)
                            .addComponent(jFormattedTextField8, javax.swing.GroupLayout.DEFAULT_SIZE, 79,
                                    Short.MAX_VALUE))
                    .addContainerGap()));

    jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
            new java.awt.Component[] { jFormattedTextField1, jFormattedTextField2, jFormattedTextField3,
                    jFormattedTextField4, jFormattedTextField5, jFormattedTextField6, jFormattedTextField7,
                    jFormattedTextField8, jPanel3, jSpinner1, jTextField1 });

    jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { jLabel1, jLabel10,
            jLabel11, jLabel12, jLabel2, jLabel3, jLabel4, jLabel5, jLabel7, jLabel8, jLabel9 });

    jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup().addGap(14, 14, 14)
                                    .addComponent(jLabel9))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jFormattedTextField5, javax.swing.GroupLayout.PREFERRED_SIZE,
                                            javax.swing.GroupLayout.DEFAULT_SIZE,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(jPanel2Layout
                                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel11).addComponent(jFormattedTextField7,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField6, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12).addComponent(jFormattedTextField8,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap()));

    jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL,
            new java.awt.Component[] { jFormattedTextField1, jFormattedTextField2, jFormattedTextField3,
                    jFormattedTextField4, jFormattedTextField5, jFormattedTextField6, jPanel3, jSpinner1,
                    jTextField1 });

    getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

    jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/apply.png"))); // NOI18N
    jButton1.setText(bundle.getString("NewSellTransactionJDialog_OK")); // NOI18N
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });
    jPanel4.add(jButton1);

    jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/button_cancel.png"))); // NOI18N
    jButton2.setText(bundle.getString("NewSellTransactionJDialog_Cancel")); // NOI18N
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });
    jPanel4.add(jButton2);

    getContentPane().add(jPanel4, java.awt.BorderLayout.SOUTH);

    jPanel1.setBorder(
            javax.swing.BorderFactory.createTitledBorder(bundle.getString("NewSellTransactionJDialog_Stock"))); // NOI18N
    jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 15, 5));

    jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/outbox.png"))); // NOI18N
    jPanel1.add(jLabel6);

    jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/idea.png"))); // NOI18N
    jButton3.setText(bundle.getString("NewSellTransactionJDialog_BestPrice")); // NOI18N
    jButton3.setToolTipText("Suggest the best selling price to break even.");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton3ActionPerformed(evt);
        }
    });
    jPanel1.add(jButton3);

    getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

    pack();
}

From source file:org.yccheok.jstock.gui.NewSellTransactionJDialog.java

/** This method is called from within the constructor to
 * initialize the form./*  w  w  w  .  j  a v  a  2  s.c  om*/
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    jPanel2 = new javax.swing.JPanel();
    jTextField1 = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    jSpinner1 = new javax.swing.JSpinner();
    jPanel3 = CalendarFactory.createDateField();
    jLabel4 = new javax.swing.JLabel();
    jFormattedTextField1 = getCurrencyJFormattedTextField(false);
    jFormattedTextField2 = getCurrencyJFormattedTextField(false);
    jFormattedTextField3 = getCurrencyJFormattedTextField(false);
    jFormattedTextField4 = getCurrencyJFormattedTextField(false);
    jFormattedTextField5 = getCurrencyJFormattedTextField(false);
    jLabel10 = new javax.swing.JLabel();
    jFormattedTextField6 = getPercentageJFormattedTextField();
    jLabel1 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    jFormattedTextField7 = getCurrencyJFormattedTextField(false);
    jLabel11 = new javax.swing.JLabel();
    jFormattedTextField8 = getCurrencyJFormattedTextField(true);
    jLabel12 = new javax.swing.JLabel();
    jComboBox1 = new javax.swing.JComboBox<>();
    jPanel4 = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jPanel1 = new javax.swing.JPanel();
    jLabel6 = new javax.swing.JLabel();
    jButton3 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui"); // NOI18N
    setTitle(bundle.getString("NewSellTransactionJDialog_Sell")); // NOI18N
    setResizable(false);

    jPanel2.setBorder(javax.swing.BorderFactory
            .createTitledBorder(bundle.getString("NewSellTransactionJDialog_Transaction"))); // NOI18N

    jTextField1.setEditable(false);

    jLabel2.setText(bundle.getString("NewBuyTransactionJDialog_Symbol")); // NOI18N

    jSpinner1.setModel(new javax.swing.SpinnerNumberModel(100.0d, 0.001d, null, 100.0d));
    JSpinner.NumberEditor numberEditor = (JSpinner.NumberEditor) jSpinner1.getEditor();
    final DecimalFormat decimalFormat = numberEditor.getFormat();
    decimalFormat.setMaximumFractionDigits(4);
    numberEditor.getTextField().addMouseListener(getJFormattedTextFieldMouseListener());
    jSpinner1.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            jSpinner1StateChanged(evt);
        }
    });

    jPanel3.setBackground(new java.awt.Color(204, 255, 255));
    jPanel3.setMaximumSize(new java.awt.Dimension(32767, 20));
    jPanel3.setPreferredSize(new java.awt.Dimension(100, 20));

    jLabel4.setText(bundle.getString("NewBuyTransactionJDialog_Date")); // NOI18N

    jFormattedTextField1.setValue(new Double(0.0));
    jFormattedTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jFormattedTextField1KeyTyped(evt);
        }
    });

    jFormattedTextField2.setEditable(false);
    jFormattedTextField2.setValue(new Double(0.0));

    jFormattedTextField3.setEditable(false);
    jFormattedTextField3.setValue(new Double(0.0));

    jFormattedTextField4.setValue(new Double(0.0));
    jFormattedTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jFormattedTextField4KeyTyped(evt);
        }
    });

    jFormattedTextField5.setValue(new Double(0.0));
    jFormattedTextField5.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jFormattedTextField5KeyTyped(evt);
        }
    });

    jLabel10.setFont(jLabel10.getFont().deriveFont(jLabel10.getFont().getStyle() | java.awt.Font.BOLD));
    jLabel10.setText(bundle.getString("NewSellTransactionJDialog_Profit%")); // NOI18N

    jFormattedTextField6.setEditable(false);
    jFormattedTextField6.setFont(jFormattedTextField6.getFont()
            .deriveFont(jFormattedTextField6.getFont().getStyle() | java.awt.Font.BOLD));
    jFormattedTextField6.setValue(new Double(0.0));

    jLabel1.setText(bundle.getString("NewSellTransactionJDialog_Unit")); // NOI18N

    jLabel3.setText(bundle.getString("NewSellTransactionJDialog_Price")); // NOI18N

    jLabel5.setText(bundle.getString("NewSellTransactionJDialog_Value")); // NOI18N

    jLabel7.setText(bundle.getString("NewSellTransactionJDialog_BuyCost")); // NOI18N

    jLabel8.setText(bundle.getString("NewSellTransactionJDialog_Broker")); // NOI18N

    jLabel9.setText(bundle.getString("NewSellTransactionJDialog_Clearing")); // NOI18N

    jFormattedTextField7.setValue(new Double(0.0));
    jFormattedTextField7.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jFormattedTextField7KeyTyped(evt);
        }
    });

    jLabel11.setText(bundle.getString("NewSellTransactionJDialog_StampDuty")); // NOI18N

    jFormattedTextField8.setEditable(false);
    jFormattedTextField8.setFont(jFormattedTextField8.getFont()
            .deriveFont(jFormattedTextField8.getFont().getStyle() | java.awt.Font.BOLD));
    jFormattedTextField8.setValue(new Double(0.0));

    jLabel12.setFont(jLabel12.getFont().deriveFont(jLabel12.getFont().getStyle() | java.awt.Font.BOLD));
    jLabel12.setText(bundle.getString("NewSellTransactionJDialog_Profit$")); // NOI18N

    jComboBox1.setModel(
            new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout
            .setHorizontalGroup(jPanel2Layout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel2Layout
                            .createSequentialGroup().addContainerGap().addGroup(
                                    jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel9).addComponent(jLabel2).addComponent(jLabel3)
                                            .addComponent(jLabel5).addComponent(
                                                    jLabel7)
                                            .addComponent(jLabel8).addComponent(jLabel1).addComponent(jLabel4)
                                            .addComponent(jLabel11).addComponent(jLabel12)
                                            .addComponent(jLabel10))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanel2Layout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jFormattedTextField6, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            109, Short.MAX_VALUE)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 109,
                                            Short.MAX_VALUE)
                                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 109,
                                            Short.MAX_VALUE)
                                    .addComponent(jSpinner1, javax.swing.GroupLayout.DEFAULT_SIZE, 109,
                                            Short.MAX_VALUE)
                                    .addComponent(jFormattedTextField1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            109, Short.MAX_VALUE)
                                    .addComponent(jFormattedTextField2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            109, Short.MAX_VALUE)
                                    .addComponent(jFormattedTextField3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            109, Short.MAX_VALUE)
                                    .addComponent(jFormattedTextField4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            109, Short.MAX_VALUE)
                                    .addComponent(jFormattedTextField5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            109, Short.MAX_VALUE)
                                    .addComponent(jFormattedTextField7, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            101, Short.MAX_VALUE)
                                    .addComponent(jFormattedTextField8, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            79, Short.MAX_VALUE)
                                    .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            Short.MAX_VALUE))
                            .addContainerGap()));

    jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
            new java.awt.Component[] { jFormattedTextField1, jFormattedTextField2, jFormattedTextField3,
                    jFormattedTextField4, jFormattedTextField5, jFormattedTextField6, jFormattedTextField7,
                    jFormattedTextField8, jPanel3, jSpinner1, jTextField1 });

    jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { jLabel1, jLabel10,
            jLabel11, jLabel12, jLabel2, jLabel3, jLabel4, jLabel5, jLabel7, jLabel8, jLabel9 });

    jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2).addComponent(jTextField1,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup().addGap(14, 14, 14)
                                    .addComponent(jLabel9))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jFormattedTextField5, javax.swing.GroupLayout.PREFERRED_SIZE,
                                            javax.swing.GroupLayout.DEFAULT_SIZE,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(jPanel2Layout
                                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel11).addComponent(jFormattedTextField7,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField6, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12).addComponent(jFormattedTextField8,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap()));

    jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL,
            new java.awt.Component[] { jFormattedTextField1, jFormattedTextField2, jFormattedTextField3,
                    jFormattedTextField4, jFormattedTextField5, jFormattedTextField6, jPanel3, jSpinner1,
                    jTextField1 });

    getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

    jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/apply.png"))); // NOI18N
    jButton1.setText(bundle.getString("NewSellTransactionJDialog_OK")); // NOI18N
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });
    jPanel4.add(jButton1);

    jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/button_cancel.png"))); // NOI18N
    jButton2.setText(bundle.getString("NewSellTransactionJDialog_Cancel")); // NOI18N
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });
    jPanel4.add(jButton2);

    getContentPane().add(jPanel4, java.awt.BorderLayout.SOUTH);

    jPanel1.setBorder(
            javax.swing.BorderFactory.createTitledBorder(bundle.getString("NewSellTransactionJDialog_Stock"))); // NOI18N
    jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 15, 5));

    jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/outbox.png"))); // NOI18N
    jPanel1.add(jLabel6);

    jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/idea.png"))); // NOI18N
    jButton3.setText(bundle.getString("NewSellTransactionJDialog_BestPrice")); // NOI18N
    jButton3.setToolTipText("Suggest the best selling price to break even.");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton3ActionPerformed(evt);
        }
    });
    jPanel1.add(jButton3);

    getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

    pack();
}

From source file:com.FluksoViz.FluksoVizActivity.java

private String setDecimalFormatProcent(double input_double) {
    // Try Localized numbers and avoid "re-creation" of object
    DecimalFormat df = new DecimalFormat();
    df.setMaximumIntegerDigits(5);/*from   w  ww . j  a v  a2  s. c  o  m*/
    df.setMaximumFractionDigits(0);

    if (input_double < 100)
        df.setMaximumIntegerDigits(2);

    if (input_double < 10) {
        df.setMaximumFractionDigits(2);
        df.setMaximumIntegerDigits(1);
    }

    return df.format(input_double);
}

From source file:com.FluksoViz.FluksoVizActivity.java

private String setDecimalFormat(double input_double) {
    // Try Localized numbers and avoid "re-creation" of object
    DecimalFormat df = new DecimalFormat(); // Localized decimal format
    df.setMaximumIntegerDigits(5);/*from  ww  w. j  a v  a2 s.  co m*/
    df.setMaximumFractionDigits(0);

    if (input_double < 1000)
        df.setMaximumIntegerDigits(4);

    if (input_double < 100) {
        df.setMaximumIntegerDigits(3);
        df.setMaximumFractionDigits(2);
    }

    /*
     * Fraction digits set above, if you change this logic remember to set
     * fraction digits here
     */
    if (input_double < 10)
        df.setMaximumIntegerDigits(2);

    return df.format(input_double);
}

From source file:semaforo.Semaforo.java

public static void editGrafico() {
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);
    double cfd = 0.0;
    double bull = 0.0;
    double bear = 0.0;
    if (countCfd != 0)
        cfd = (countCfd * 100) / (countBear + countBull + countCfd);
    if (countBull != 0)
        bull = ((countBull * 100) / (countBear + countBull + countCfd));
    if (countBear != 0)
        bear = ((countBear * 100) / (countBear + countBull + countCfd));
    Semaforo.l1.setText("CFD (" + String.format("%.2f", cfd) + "%)");
    Semaforo.l2.setText("BULL (" + String.format("%.2f", bull) + "%)");
    Semaforo.l3.setText("BEAR (" + String.format("%.2f", bear) + "%)");
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("CFD (" + cfd + "%)", new Integer((int) countCfd));
    pieDataset.setValue("BULL (" + bull + "%)", new Integer((int) countBull));
    pieDataset.setValue("BEAR (" + bear + "%)", new Integer((int) countBear));
    JFreeChart chart = null;/*w w  w  .  ja v  a 2 s .c  om*/
    chart = ChartFactory.createPieChart("", // chart title
            pieDataset, // data
            false, // no legend
            false, // tooltips
            false // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 0));
    PiePlot plot = null;
    plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.00);
    plot.setOutlineVisible(true);

    // use gradients and white borders for the section colours

    plot.setBaseSectionOutlinePaint(Color.BLACK);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 0));
    plot.setLabelLinkPaint(Color.BLACK);
    plot.setLabelLinkStroke(new BasicStroke(0.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.BLACK);
    plot.setLabelBackgroundPaint(null);
    plot.setLabelBackgroundPaint(Color.BLACK);
    plot.setLabelShadowPaint(Color.BLACK);

    // add a subtitle giving the data source       

    // Mostramos la grafica dentro del jPanel1
    Semaforo.panel.setChart(chart);
}

From source file:com.eveningoutpost.dexdrip.Home.java

private void displayCurrentInfo() {
    DecimalFormat df = new DecimalFormat("#");
    df.setMaximumFractionDigits(0);

    final boolean isDexbridge = CollectionServiceStarter.isDexBridgeOrWifiandDexBridge();
    final boolean hasBtWixel = DexCollectionType.hasBtWixel();
    final boolean isLimitter = CollectionServiceStarter.isLimitter();
    //boolean isWifiWixel = CollectionServiceStarter.isWifiandBTWixel(getApplicationContext()) | CollectionServiceStarter.isWifiWixel(getApplicationContext());
    //  if (isDexbridge||isLimitter||hasBtWixel||is_follower) {
    if (DexCollectionType.hasBattery()) {
        final int bridgeBattery = prefs.getInt("bridge_battery", 0);

        if (bridgeBattery < 1) {
            //dexbridgeBattery.setText(R.string.waiting_for_packet);
            dexbridgeBattery.setVisibility(View.INVISIBLE);
        } else {//from   w w w  .j av  a2 s . c  o m
            if (isDexbridge) {
                dexbridgeBattery.setText(getString(R.string.xbridge_battery) + ": " + bridgeBattery + "%");
            } else if (isLimitter) {
                dexbridgeBattery.setText(getString(R.string.limitter_battery) + ": " + bridgeBattery + "%");
            } else {
                dexbridgeBattery.setText(
                        "Bridge battery" + ": " + bridgeBattery + ((bridgeBattery < 200) ? "%" : "mV"));
            }
        }
        if (bridgeBattery < 50)
            dexbridgeBattery.setTextColor(Color.YELLOW);
        if (bridgeBattery < 25)
            dexbridgeBattery.setTextColor(Color.RED);
        else
            dexbridgeBattery.setTextColor(Color.GREEN);
        dexbridgeBattery.setVisibility(View.VISIBLE);

    } else {
        dexbridgeBattery.setVisibility(View.INVISIBLE);
    }
    if (DexCollectionType.hasWifi()) {
        final int bridgeBattery = prefs.getInt("parakeet_battery", 0);
        if (bridgeBattery > 0) {
            if (bridgeBattery < 50) {
                parakeetBattery.setText(getString(R.string.parakeet_battery) + ": " + bridgeBattery + "%");

                if (bridgeBattery < 40) {
                    parakeetBattery.setTextColor(Color.RED);
                } else {
                    parakeetBattery.setTextColor(Color.YELLOW);
                }
                parakeetBattery.setVisibility(View.VISIBLE);
            } else {
                parakeetBattery.setVisibility(View.INVISIBLE);
            }
        }
    } else {
        parakeetBattery.setVisibility(View.INVISIBLE);
    }
    if (!prefs.getBoolean("display_bridge_battery", true)) {
        dexbridgeBattery.setVisibility(View.INVISIBLE);
        parakeetBattery.setVisibility(View.INVISIBLE);
    }

    final int sensor_age = prefs.getInt("nfc_sensor_age", 0);
    if ((sensor_age > 0) && (DexCollectionType.hasLibre())) {
        sensorAge.setText("Age: " + JoH.qs(((double) sensor_age) / 1440, 1) + "d"
                + (Home.getPreferencesBooleanDefaultFalse("nfc_age_problem") ? " \u26A0\u26A0\u26A0" : ""));
        sensorAge.setVisibility(View.VISIBLE);
        if (sensor_age < 1440) {
            sensorAge.setTextColor(Color.YELLOW);
        } else if (sensor_age < (1440 * 12)) {
            sensorAge.setTextColor(Color.GREEN);
        } else {
            sensorAge.setTextColor(Color.RED);
        }
    } else {
        sensorAge.setVisibility(View.GONE);
    }
    if (blockTouches) {
        sensorAge.setText("SCANNING.. DISPLAY LOCKED!");
        sensorAge.setVisibility(View.VISIBLE);
        sensorAge.setTextColor(Color.GREEN);
    }

    if ((currentBgValueText.getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) > 0) {
        currentBgValueText.setPaintFlags(currentBgValueText.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
        dexbridgeBattery.setPaintFlags(dexbridgeBattery.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
        if (get_follower()) {
            GcmActivity.requestPing();
        }
    }
    BgReading lastBgReading = BgReading.lastNoSenssor();
    boolean predictive = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
            .getBoolean("predictive_bg", false);
    if (isBTShare) {
        predictive = false;
    }
    if (lastBgReading != null) {
        displayCurrentInfoFromReading(lastBgReading, predictive);
    } else {
        display_delta = "";
    }

    if (prefs.getBoolean("extra_status_line", false)) {
        extraStatusLineText.setText(extraStatusLine());
        extraStatusLineText.setVisibility(View.VISIBLE);
    } else {
        extraStatusLineText.setText("");
        extraStatusLineText.setVisibility(View.GONE);
    }
}

From source file:com.eveningoutpost.dexdrip.Home.java

private void handleWordPair() {
    boolean preserve = false;
    if ((thisnumber == -1) || (thisword == ""))
        return;/*w ww .java 2 s  .  c om*/

    Log.d(TAG, "GOT WORD PAIR: " + thisnumber + " = " + thisword);

    switch (thisword) {

    case "rapid":
        if ((insulinset == false) && (thisnumber > 0)) {
            thisinsulinnumber = thisnumber;
            textInsulinDose.setText(Double.toString(thisnumber) + " units");
            Log.d(TAG, "Rapid dose: " + Double.toString(thisnumber));
            insulinset = true;
            btnInsulinDose.setVisibility(View.VISIBLE);
            textInsulinDose.setVisibility(View.VISIBLE);
        } else {
            Log.d(TAG, "Rapid dose already set");
            preserve = true;
        }
        break;

    case "carbs":
        if ((carbsset == false) && (thisnumber > 0)) {
            thiscarbsnumber = thisnumber;
            textCarbohydrates.setText(Integer.toString((int) thisnumber) + " carbs");
            carbsset = true;
            Log.d(TAG, "Carbs eaten: " + Double.toString(thisnumber));
            btnCarbohydrates.setVisibility(View.VISIBLE);
            textCarbohydrates.setVisibility(View.VISIBLE);
        } else {
            Log.d(TAG, "Carbs already set");
            preserve = true;
        }
        break;

    case "blood":
        if ((glucoseset == false) && (thisnumber > 0)) {
            thisglucosenumber = thisnumber;
            if (prefs.getString("units", "mgdl").equals("mgdl")) {
                if (textBloodGlucose != null)
                    textBloodGlucose.setText(Double.toString(thisnumber) + " mg/dl");
            } else {
                if (textBloodGlucose != null)
                    textBloodGlucose.setText(Double.toString(thisnumber) + " mmol/l");
            }

            Log.d(TAG, "Blood test: " + Double.toString(thisnumber));
            glucoseset = true;
            if (textBloodGlucose != null) {
                btnBloodGlucose.setVisibility(View.VISIBLE);
                textBloodGlucose.setVisibility(View.VISIBLE);
            }

        } else {
            Log.d(TAG, "Blood glucose already set");
            preserve = true;
        }
        break;

    case "time":
        Log.d(TAG, "processing time keyword");
        if ((timeset == false) && (thisnumber >= 0)) {

            final NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
            final DecimalFormat df = (DecimalFormat) nf;
            //DecimalFormat df = new DecimalFormat("#");
            df.setMinimumIntegerDigits(2);
            df.setMinimumFractionDigits(2);
            df.setMaximumFractionDigits(2);
            df.setMaximumIntegerDigits(2);

            final Calendar c = Calendar.getInstance();

            final SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("dd/M/yyyy ", Locale.US);
            final SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("dd/M/yyyy HH.mm", Locale.US); // TODO double check 24 hour 12.00 etc
            final String datenew = simpleDateFormat1.format(c.getTime()) + df.format(thisnumber);

            Log.d(TAG, "Time Timing data datenew: " + datenew);

            final Date datethen;
            final Date datenow = new Date();

            try {
                datethen = simpleDateFormat2.parse(datenew);
                double difference = datenow.getTime() - datethen.getTime();
                // is it more than 1 hour in the future? If so it must be yesterday
                if (difference < -(1000 * 60 * 60)) {
                    difference = difference + (86400 * 1000);
                } else {
                    // - midnight feast pre-bolus nom nom
                    if (difference > (60 * 60 * 23 * 1000))
                        difference = difference - (86400 * 1000);
                }

                Log.d(TAG, "Time Timing data: " + df.format(thisnumber) + " = difference ms: "
                        + JoH.qs(difference));
                textTime.setText(df.format(thisnumber));
                timeset = true;
                thistimeoffset = difference;
                btnTime.setVisibility(View.VISIBLE);
                textTime.setVisibility(View.VISIBLE);
            } catch (ParseException e) {
                // toast to explain?
                Log.d(TAG, "Got exception parsing date time");
            }
        } else {
            Log.d(TAG, "Time data already set");
            preserve = true;
        }
        break;
    } // end switch

    if (preserve == false) {
        Log.d(TAG, "Clearing speech values");
        thisnumber = -1;
        thisword = "";
    } else {
        Log.d(TAG, "Preserving speech values");
    }

    // don't show approve/cancel if we only have time
    if (insulinset || glucoseset || carbsset) {
        btnApprove.setVisibility(View.VISIBLE);
        btnCancel.setVisibility(View.VISIBLE);

        if (small_screen) {
            final float button_scale_factor = 0.60f;
            ((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).leftMargin = 0;
            ((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).leftMargin = 0;
            ((ViewGroup.MarginLayoutParams) btnBloodGlucose.getLayoutParams()).setMarginStart(0);
            ((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).setMarginStart(0);
            ((ViewGroup.MarginLayoutParams) btnApprove.getLayoutParams()).rightMargin = 0;
            ((ViewGroup.MarginLayoutParams) btnCancel.getLayoutParams()).rightMargin = 0;
            btnApprove.setScaleX(button_scale_factor);
            btnApprove.setScaleY(button_scale_factor);
            btnCancel.setScaleX(button_scale_factor);
            btnCancel.setScaleY(button_scale_factor);
            btnInsulinDose.setScaleX(button_scale_factor);
            btnCarbohydrates.setScaleX(button_scale_factor);
            btnCarbohydrates.setScaleY(button_scale_factor);
            btnBloodGlucose.setScaleX(button_scale_factor);
            btnBloodGlucose.setScaleY(button_scale_factor);
            btnInsulinDose.setScaleY(button_scale_factor);
            btnTime.setScaleX(button_scale_factor);
            btnTime.setScaleY(button_scale_factor);

            final int small_text_size = 12;

            textCarbohydrates.setTextSize(small_text_size);
            textInsulinDose.setTextSize(small_text_size);
            textBloodGlucose.setTextSize(small_text_size);
            textTime.setTextSize(small_text_size);

        }

    }

    if (insulinset || glucoseset || carbsset || timeset) {
        if (chart != null) {
            chart.setAlpha((float) 0.10);
        }
        WatchUpdaterService.sendTreatment(thiscarbsnumber, thisinsulinnumber, thisglucosenumber, thistimeoffset,
                textTime.getText().toString());
    }

}

From source file:semaforo.Semaforo.java

public synchronized void updateTableWeek(JTable TableWeek, int index, int tamano) {

    Settings settings = Controller.getSettings();

    //  TableWeek.getColumnModel().getColumn(0).setPreferredWidth(120);
    //  TableWeek.getColumnModel().getColumn(9).setPreferredWidth(120);
    // CustomRenderer cr = new CustomRenderer(TableWeek.getDefaultRenderer(Object.class), Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY);
    //  TableWeek.setDefaultRenderer(Object.class, cr);
    DefaultTableModel model = (DefaultTableModel) TableWeek.getModel();

    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(3);

    int num = Math.min(settings.getTickers().size(), model.getRowCount());
    if (TableWeek.getModel().getRowCount() > 0) {
        num = Math.min(settings.getTickers().size(), TableWeek.getModel().getRowCount());
    }/* ww w.  j a v a  2 s.  c  om*/

    for (int i = 0; i < num; i++) {
        for (int m = 0; m < TableTicker.getModel().getRowCount(); m++) {
            if (TableTicker != null && TableTicker.getModel() != null) {
                if (TableTicker.getModel().getValueAt(m, 0) != null) {
                    if (TableTicker.getModel().getValueAt(m, 0)
                            .equals(settings.getTickers().get(i).getName())) {
                        model.setValueAt(String.format("%.2f", settings.getTickers().get(i).getMinValue(index)),
                                m, 0);
                        model.setValueAt(String.format("%.2f", settings.getTickers().get(i).getMaxValue(index)),
                                m, tamano); //TODO: Parametrizar
                        //                            JOptionPane.showMessageDialog(null,index+"", "", JOptionPane.ERROR_MESSAGE);
                        if (index == 13) {
                            DDBB.updateTicker(TableTicker.getModel().getValueAt(m, 0).toString(),
                                    String.format("%.2f", settings.getTickers().get(i).getMinValue(index)),
                                    String.format("%.2f", settings.getTickers().get(i).getMaxValue(index)));
                        }
                    }
                }
            }
        }
    }
}

From source file:semaforo.Semaforo.java

public synchronized void updateTableTickers() {
    Settings settings = Controller.getSettings();

    //  TableWeek.getColumnModel().getColumn(0).setPreferredWidth(120);
    //  TableWeek.getColumnModel().getColumn(9).setPreferredWidth(120);
    // CustomRenderer cr = new CustomRenderer(TableWeek.getDefaultRenderer(Object.class), Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY);
    //  TableWeek.setDefaultRenderer(Object.class, cr);
    DefaultTableModel model = (DefaultTableModel) TableTicker.getModel();

    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);

    int num = Math.min(settings.getTickers().size(), model.getRowCount());
    if (TableTicker.getModel().getRowCount() > 0) {
        num = Math.min(settings.getTickers().size(), TableTicker.getModel().getRowCount());
    }//from w ww .j  a  va  2  s .  c  o m

    isload = false;

    for (int i = 0; i < num; i++) {
        if (settings.getTickers().get(i).getCurrentPrice() <= 0) {
            isload = true;
        }
    }

    new Thread() {

        @Override
        public void run() {
            if (loadingDialog == null) {
                JFrame frame = new JFrame();
                loadingDialog = new LoadingDialog(null, "Please Wait", "Loading Data");
                loadingDialog.setEnabled(false);
                loadingDialog.setAlwaysOnTop(false);

            }

            if (loadingDialog.isShowing() && isload == false /*&& isloadHistory == false*/) {
                loadingDialog.setVisible(false);
            } else if (!loadingDialog.isShowing() && isload == true /*&& isloadHistory == true*/) {
                loadingDialog.setVisible(true);
            }

        }
    }.start();

}

From source file:com.zoffcc.applications.zanavi.Navit.java

public static String logHeap(Class clazz) {
    Double allocated = Double.valueOf(Debug.getNativeHeapAllocatedSize()) / Double.valueOf((1048576));
    Double sum_size = Double.valueOf(Debug.getNativeHeapSize() / Double.valueOf(1048576.0));
    Double free = Double.valueOf(Debug.getNativeHeapFreeSize() / Double.valueOf(1048576.0));
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);
    df.setMinimumFractionDigits(2);/*from   w  w w  .  j av  a2  s.c  om*/

    // Log.d("Navit", "MemMem:DEBUG: =================================");
    Log.d("Navit",
            "MemMem:DEBUG:heap native: allc " + df.format(allocated) + "MB sum=" + df.format(sum_size) + "MB ("
                    + df.format(free) + "MB free) in ["
                    + clazz.getName().replaceAll("com.zoffcc.applications.zanavi.", "") + "]");
    Log.d("Navit",
            "MemMem:DEBUG:java memory: allc: "
                    + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "MB sum="
                    + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "MB ("
                    + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + "MB free)");

    calcAvailableMemory();

    String mem_type = "NATIVE";
    try {
        if (android.os.Build.VERSION.SDK_INT >= 11) {
            mem_type = "JAVA";
        }
    } catch (Exception e) {
    }
    return ("" + df.format(allocated) + "/" + df.format(sum_size) + "(" + df.format(free) + ")" + ":"
            + df.format(Double.valueOf(Runtime.getRuntime().totalMemory() / 1048576)) + "/"
            + df.format(Double.valueOf(Runtime.getRuntime().maxMemory() / 1048576)) + "("
            + df.format(Double.valueOf(Runtime.getRuntime().freeMemory() / 1048576)) + ") " + mem_type);
}