-
Notifications
You must be signed in to change notification settings - Fork 334
Show cost with 2 decimals #1677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
8daa6fa
e2041bf
dcd2247
b3f0503
0de2d4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ of the License, or (at your option) any later version. | |
| import javax.swing.event.TableColumnModelListener; | ||
| import javax.swing.event.TreeExpansionEvent; | ||
| import javax.swing.event.TreeExpansionListener; | ||
| import javax.swing.table.DefaultTableCellRenderer; | ||
| import javax.swing.table.JTableHeader; | ||
| import javax.swing.table.TableCellEditor; | ||
| import javax.swing.table.TableCellRenderer; | ||
|
|
@@ -70,6 +71,7 @@ of the License, or (at your option) any later version. | |
| import java.awt.event.KeyEvent; | ||
| import java.awt.event.MouseAdapter; | ||
| import java.awt.event.MouseEvent; | ||
| import java.text.DecimalFormat; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
@@ -96,6 +98,15 @@ public void applyComponentOrientation(ComponentOrientation o) { | |
| } | ||
| }; | ||
|
|
||
| class DecimalRenderer extends DefaultTableCellRenderer { | ||
| private final DecimalFormat myFormatter = new DecimalFormat("#0.00"); | ||
|
|
||
| public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { | ||
| value = myFormatter.format((Number)value); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cast is not necessary. |
||
| return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); | ||
| } | ||
| } | ||
|
|
||
| private GPAction myEditCellAction = new GPAction("tree.edit") { | ||
| @Override | ||
| public void actionPerformed(ActionEvent e) { | ||
|
|
@@ -926,7 +937,11 @@ private TableCellRenderer createCellRenderer(Class<?> columnClass) { | |
| // renderer = TableCellRenderers.getNewDefaultRenderer(columnClass); | ||
| // | ||
| // } | ||
| return getTreeTable().getDefaultRenderer(columnClass); | ||
| if (Double.class.equals(columnClass)){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This way all columns with Double type will be formatted with two decimal digits. It is okay for cost (which is essentially money) but it may not be okay for other columns, including user-defined (imagine e.g. weight measured in tons). I think that the best way to achieve the goal is to override method Also, the same should be done with the editor, no? Otherwise the user will see values with 2 decimal digits, but once he starts editing, he will see something different. |
||
| return new DecimalRenderer(); | ||
| } else { | ||
| return getTreeTable().getDefaultRenderer(columnClass); | ||
| } | ||
| } | ||
|
|
||
| private TableCellEditor createCellEditor(Class<?> columnClass) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format of representing currency values is locale-specific. You want to use NumberFormat::getCurrencyInstance and pass the currently selected locale.
GanttLanguageis responsible for such things (and it stores the current locale)