/** * This function re-computes the total number of hours for the selected period. It is ran every * time the user edits a text field specifying the number of hours for a particular top-level * project. Percentage labels are also updated. */ private void recomputeTotal() { double total = 0; for (Row row : rows.values()) { try { row.hours = Double.parseDouble(row.hoursTF.getText()); total += row.hours; row.hoursTF.setForeground(normalColour); } catch (NumberFormatException e) { row.hoursTF.setForeground(errorColour); totalLabel.setText("ERROR"); totalLabel.setForeground(errorColour); return; } } totalLabel.setText(decimalFormat.format(total)); totalLabel.setForeground(normalColour); for (Row row : rows.values()) { String percentS = decimalFormat.format(total == 0 ? 0 : 100 * row.hours / total); row.percentL.setText("(" + percentS + "%)"); } pack(); }
public void OpenFileToolbar() { JFileChooser fileChooser = new JFileChooser(); int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { opentFile(file.getPath()); Workspaces workspaces = Application.getInstance().getWorkspaces(); Map<String, Workspaces.ViewFrame> frames = workspaces.getOpenFrames(); Object[] objFrames = frames.values().toArray(); ViewFrame[] viewFrames = new ViewFrame[objFrames.length]; for (int i = 0; i < objFrames.length; i++) { viewFrames[i] = (ViewFrame) objFrames[i]; if (viewFrames[i].isSelected()) viewFrames[i].setTitle(file.getPath()); } } catch (Exception ex) { ex.printStackTrace(); } } }