From 4228069c493c06734c2aec3d18ee7fec16d0316f Mon Sep 17 00:00:00 2001 From: Kornelius Rohmeyer Date: Fri, 1 Oct 2010 08:25:57 +0000 Subject: [PATCH] Better layout and number rounding for PView. --- .../java-src/org/mutoss/gui/graph/PPanel.java | 15 +++++++++------ .../inst/java-src/org/mutoss/gui/graph/PView.java | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/gMCP/inst/java-src/org/mutoss/gui/graph/PPanel.java b/pkg/gMCP/inst/java-src/org/mutoss/gui/graph/PPanel.java index b0fe1b95..75597bc8 100644 --- a/pkg/gMCP/inst/java-src/org/mutoss/gui/graph/PPanel.java +++ b/pkg/gMCP/inst/java-src/org/mutoss/gui/graph/PPanel.java @@ -6,6 +6,7 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import java.text.DecimalFormat; import java.util.Vector; import javax.swing.JButton; @@ -32,6 +33,8 @@ public class PPanel implements ActionListener, KeyListener, NodeListener { PView pview; Boolean rejected = false; + DecimalFormat format = new DecimalFormat("#.#####"); + public Vector getComponent() { Vector v = new Vector(); v.add(label); @@ -50,11 +53,11 @@ public PPanel(Node node, PView pview) { label = new JLabel(name); - wTF = new JTextField(""+w); + wTF = new JTextField(format.format(w), 7); wTF.addActionListener(this); wTF.addKeyListener(this); - pTF = new JTextField(""+p); + pTF = new JTextField(format.format(p), 7); pTF.addActionListener(this); pTF.addKeyListener(this); @@ -139,8 +142,8 @@ public void keyTyped(KeyEvent e) { public void update() { this.name = node.name; this.w = node.getAlpha(); - wTF.setText(""+w); - pTF.setText(""+p); + wTF.setText(format.format(w)); + pTF.setText(format.format(p)); if (!rejected) { keyTyped(null); } @@ -149,8 +152,8 @@ public void update() { public void updated(Node node) { this.name = node.name; this.w = node.getAlpha(); - wTF.setText(""+w); - pTF.setText(""+p); + wTF.setText(format.format(w)); + pTF.setText(format.format(p)); pview.updateLabels(); } diff --git a/pkg/gMCP/inst/java-src/org/mutoss/gui/graph/PView.java b/pkg/gMCP/inst/java-src/org/mutoss/gui/graph/PView.java index 12cd1d06..3c7939bf 100644 --- a/pkg/gMCP/inst/java-src/org/mutoss/gui/graph/PView.java +++ b/pkg/gMCP/inst/java-src/org/mutoss/gui/graph/PView.java @@ -6,6 +6,7 @@ import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.text.DecimalFormat; import java.util.List; import java.util.Vector; @@ -97,6 +98,8 @@ public void actionPerformed(ActionEvent e) { } + DecimalFormat format = new DecimalFormat("#.####"); + public void updateLabels() { double alpha = 0; for (PPanel p : panels) { @@ -104,7 +107,7 @@ public void updateLabels() { alpha += p.w; } } - String text = "Total α: "+(""+alpha).substring(0, Math.min(7,(""+alpha).length())); + String text = "Total α: "+format.format(alpha); if (alpha>=1) { label.setForeground(Color.RED); text += "; The total α is greater or equal 1!";