Skip to content

Commit

Permalink
Better layout and number rounding for PView.
Browse files Browse the repository at this point in the history
  • Loading branch information
kornl committed Oct 1, 2010
1 parent f4834d4 commit 4228069
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 9 additions & 6 deletions pkg/gMCP/inst/java-src/org/mutoss/gui/graph/PPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +33,8 @@ public class PPanel implements ActionListener, KeyListener, NodeListener {
PView pview;
Boolean rejected = false;

DecimalFormat format = new DecimalFormat("#.#####");

public Vector<Component> getComponent() {
Vector<Component> v = new Vector<Component>();
v.add(label);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/gMCP/inst/java-src/org/mutoss/gui/graph/PView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -97,14 +98,16 @@ public void actionPerformed(ActionEvent e) {

}

DecimalFormat format = new DecimalFormat("#.####");

public void updateLabels() {
double alpha = 0;
for (PPanel p : panels) {
if (!p.rejected) {
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!";
Expand Down

0 comments on commit 4228069

Please sign in to comment.