-
Notifications
You must be signed in to change notification settings - Fork 333
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 4 commits
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,15 +71,10 @@ 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.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.EventObject; | ||
| import java.util.GregorianCalendar; | ||
| import java.util.LinkedList; | ||
| import java.text.DecimalFormat; | ||
| import java.text.NumberFormat; | ||
| import java.util.*; | ||
| import java.util.List; | ||
| import java.util.ListIterator; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
@@ -96,6 +92,16 @@ public void applyComponentOrientation(ComponentOrientation o) { | |
| } | ||
| }; | ||
|
|
||
| class DecimalRenderer extends DefaultTableCellRenderer { | ||
| // private final DecimalFormat myFormatter = new DecimalFormat("#0.00"); | ||
| private final DecimalFormat myFormatter = new DecimalFormat(NumberFormat.getNumberInstance(GanttLanguage.getInstance().getLocale()).toString()); | ||
|
|
||
| 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) { | ||
|
|
@@ -905,12 +911,20 @@ protected List<ColumnList.Column> getDefaultColumns() { | |
| protected TableColumnExt newTableColumnExt(int modelIndex) { | ||
| TableColumnExt result = new TableColumnExt(modelIndex); | ||
| Class<?> columnClass = getTreeTableModel().getColumnClass(modelIndex); | ||
| TableCellRenderer renderer = createCellRenderer(columnClass); | ||
| String columnName = getTreeTableModel().getColumnName(modelIndex).toLowerCase(); | ||
|
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 class is abstract and is shared between Gantt chart and Resource chart. Please move all checks which are related to tasks into GanttTreeTable |
||
| TableCellRenderer renderer; | ||
| Boolean costColumn = false; | ||
|
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. you don't need to use |
||
| if (Double.class.equals(columnClass) && columnName.equals("cost")) { | ||
|
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 will work only if your system locale is English. Should it be some other locale, column name will not be "cost". You can find TaskDefaultColumn instance by model index: |
||
| renderer = new DecimalRenderer(); | ||
| costColumn = true; | ||
| } else { | ||
| renderer = createCellRenderer(columnClass); | ||
| } | ||
| if (renderer != null) { | ||
| result.setCellRenderer(renderer); | ||
| } | ||
| TableCellEditor editor = createCellEditor(columnClass); | ||
| if (editor != null) { | ||
| if (editor != null && !costColumn) { | ||
| result.setCellEditor(editor); | ||
| } else { | ||
| System.err.println("no editor for column=" + modelIndex + " class=" + columnClass); | ||
|
|
@@ -925,7 +939,7 @@ private TableCellRenderer createCellRenderer(Class<?> columnClass) { | |
| // { | ||
| // renderer = TableCellRenderers.getNewDefaultRenderer(columnClass); | ||
| // | ||
| // } | ||
| //} | ||
| return getTreeTable().getDefaultRenderer(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.
Pardon?
This fails because toString in format instances is not overridden and it is just a class name and memory address:
Besides, you can just use NumberFormat directly without converting to Decimalformat.
This format instance will not update when user changes interface language in GanttProject settings. You need to listen to language change events