List of usage examples for javax.swing.table DefaultTableCellRenderer DefaultTableCellRenderer
public DefaultTableCellRenderer()
From source file:org.prom5.analysis.performance.PerformanceAnalysisGUI.java
/** * Calculates metrics related to activities, such as waiting time, execution * time and throughput time. and displays these on the metricsBottomPanel, * * @param activity ExtendedActivity: the activity involved *//*from w ww. j ava2 s . co m*/ private void displayActivityMetrics(ExtendedActivity activity) { tablePanel.removeAll(); try { //calculate time-metrics of the activity based on the selected instances activity.calculateMetrics(getSelectedInstanceIDs(), advancedSettings[3], failedInstances); activity.checkWhichMetricsToUse(); //initialize the activityTable ThreeMetricsRowExtraTableModel atm = new ThreeMetricsRowExtraTableModel(); atm.setHeadings("", "Waiting time (" + timeSort + ")", "Execution" + " time (" + timeSort + ")", "Sojourn time (" + timeSort + ")"); activityTable.setModel(atm); activityTable.setBorder(BorderFactory.createEtchedBorder()); activityTable.setPreferredSize(new Dimension(480, 128)); activityTable.setMinimumSize(new Dimension(480, 128)); activityTable.getColumnModel().getColumn(0).setPreferredWidth(60); activityTable.getColumnModel().getColumn(0).setMaxWidth(150); DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer(); dtcr.setBackground(new Color(235, 235, 235)); activityTable.getColumnModel().getColumn(0).setCellRenderer(dtcr); activityTable.setRowSelectionAllowed(false); activityTable.getTableHeader().setFont(new Font("SansSerif", Font.BOLD, 12)); /* Iterator entries = mapping.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entr = (Map.Entry) entries.next(); if (entr.getKey() instanceof ExtendedTransition) { ExtendedTransition transition = (ExtendedTransition) entr.getKey(); ExtendedActivity act = transition.getAssociatedActivity(); if (act != null) { act.calculateMetrics(getSelectedInstanceIDs(), advancedSettings[3], failedInstances); act.checkWhichMetricsToUse(); act.getArrivalRate(); } } }*/ //fill table with the calculated activity time-metrics TableCellRenderer renderer = new CustomTableCellRenderer(activity.getBoundWaitingUsed(), activity.getBoundExecutionUsed(), activity.getBoundSojournUsed()); activityTable.setDefaultRenderer(Class.forName("java.lang.String"), renderer); activityTable.setValueAt(formatString(activity.getMeanWaitTime() / timeDivider, decimalPlaces), 0, 1); activityTable.setValueAt(formatString(activity.getMeanExecutionTime() / timeDivider, decimalPlaces), 0, 2); activityTable.setValueAt(formatString(activity.getMeanSojournTime() / timeDivider, decimalPlaces), 0, 3); activityTable.setValueAt(formatString(activity.getMinWaitTime() / timeDivider, decimalPlaces), 1, 1); activityTable.setValueAt(formatString(activity.getMinExecutionTime() / timeDivider, decimalPlaces), 1, 2); activityTable.setValueAt(formatString(activity.getMinSojournTime() / timeDivider, decimalPlaces), 1, 3); activityTable.setValueAt(formatString(activity.getMaxWaitTime() / timeDivider, decimalPlaces), 2, 1); activityTable.setValueAt(formatString(activity.getMaxExecutionTime() / timeDivider, decimalPlaces), 2, 2); activityTable.setValueAt(formatString(activity.getMaxSojournTime() / timeDivider, decimalPlaces), 2, 3); activityTable.setValueAt(formatString(activity.getStdevWaitTime() / timeDivider, decimalPlaces), 3, 1); activityTable.setValueAt(formatString(activity.getStdevExecutionTime() / timeDivider, decimalPlaces), 3, 2); activityTable.setValueAt(formatString(activity.getStdevSojournTime() / timeDivider, decimalPlaces), 3, 3); double[] avgWaitTimes = activity.getAvgWaitTimes(fastestActivityPercentage, slowestActivityPercentage); double[] avgExecutionTimes = activity.getAvgExecutionTimes(fastestActivityPercentage, slowestActivityPercentage); double[] avgThroughputTimes = activity.getAvgSojournTimes(fastestActivityPercentage, slowestActivityPercentage); activityTable.setValueAt(formatString(avgWaitTimes[0] / timeDivider, decimalPlaces), 4, 1); activityTable.setValueAt(formatString(avgExecutionTimes[0] / timeDivider, decimalPlaces), 4, 2); activityTable.setValueAt(formatString(avgThroughputTimes[0] / timeDivider, decimalPlaces), 4, 3); activityTable.setValueAt(formatString(avgWaitTimes[1] / timeDivider, decimalPlaces), 5, 1); activityTable.setValueAt(formatString(avgExecutionTimes[1] / timeDivider, decimalPlaces), 5, 2); activityTable.setValueAt(formatString(avgThroughputTimes[1] / timeDivider, decimalPlaces), 5, 3); activityTable.setValueAt(formatString(avgWaitTimes[2] / timeDivider, decimalPlaces), 6, 1); activityTable.setValueAt(formatString(avgExecutionTimes[2] / timeDivider, decimalPlaces), 6, 2); activityTable.setValueAt(formatString(avgThroughputTimes[2] / timeDivider, decimalPlaces), 6, 3); activityTable.setValueAt(activity.getFrequencyWait() + "", 7, 1); activityTable.setValueAt(activity.getFrequencyExecution() + "", 7, 2); activityTable.setValueAt(activity.getFrequencySojourn() + "", 7, 3); DecimalFormat df = new DecimalFormat("0.00"); activityTable.setValueAt("fast " + df.format(fastestActivityPercentage) + "%", 4, 0); activityTable.setValueAt("slow " + df.format(slowestActivityPercentage) + "%", 5, 0); activityTable.setValueAt( "normal " + df.format(100 - fastestActivityPercentage - slowestActivityPercentage) + "%", 6, 0); ratePlaceLabel.setText(formatString(activity.getArrivalRate() * timeDivider, decimalPlaces) + " visits per " + timeSort.substring(0, timeSort.length() - 1)); //add the table to the tablePanel tablePanel.add(activityTable.getTableHeader(), BorderLayout.PAGE_START); tablePanel.add(activityTable, BorderLayout.CENTER); //display the title titleLabel.setText("Performance information of activity " + activity.getName() + ":"); titleLabel.setVisible(true); arrivalPlaceLabel.setVisible(true); ratePlaceLabel.setVisible(true); changePercentagesButton.setVisible(true); exportButton.setVisible(true); activityTable.repaint(); metricsBottomPanel.revalidate(); } catch (Exception ex) { Message.add("An internal error occured while calculating " + " activity metrics.\n" + ex.toString(), 2); ex.printStackTrace(); } }
From source file:org.signserver.admin.gui.AddWorkerDialog.java
/** Creates new form AddWorkerDialog */ public AddWorkerDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents();/*from w ww . j av a2s .c o m*/ stage = Stage.INITIAL_CONFIG; mode = Mode.LOAD_FROM_FILE; loadFromFileRadioButton.setSelected(true); updateControls(); // initially set the Next button to be greyed-out, so that it can be // enabled based on the state nextApplyButton.setEnabled(false); invalidWorkerIdStatusLabel.setVisible(false); propertiesTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focused, int row, int column) { setEnabled(table == null || table.isEnabled()); super.getTableCellRendererComponent(table, value, selected, focused, row, column); return this; } }); propertiesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final boolean enable = propertiesTable.getSelectedRowCount() == 1; editPropertyButton.setEnabled(enable); removePropertyButton.setEnabled(enable); } } }); // add a document listner to update the UI when the content of the ID // combobox changes final JTextComponent component = (JTextComponent) workerIdComboBox.getEditor().getEditorComponent(); component.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent ev) { updateControls(); } @Override public void removeUpdate(DocumentEvent ev) { updateControls(); } @Override public void changedUpdate(DocumentEvent ev) { updateControls(); } }); // add a document listner to update the UI on updates of the configuration text configurationTextArea.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent ev) { configurationEdited = true; updateControls(); } @Override public void removeUpdate(DocumentEvent ev) { configurationEdited = true; updateControls(); } @Override public void changedUpdate(DocumentEvent ev) { configurationEdited = true; updateControls(); } }); }
From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java
private void initTreeTableDefaultRenderer(JXTreeTable treeTable) { final TableCellRenderer doubleOldTableCellRenderer = treeTable.getDefaultRenderer(Double.class); treeTable.setDefaultRenderer(Double.class, new DefaultTableCellRenderer() { @Override/*from www .j av a 2s . c o m*/ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component c = doubleOldTableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); final String UNITS = GUIBundle.getString("PortfolioManagementJPanel_Units"); // Do not manipulate display for "Units". We do not want 100 // "units" displayed as 100.00 "units". if (false == UNITS.equals(table.getColumnName(column))) { if (value != null) { if (c instanceof JLabel) { // Re-define the displayed value. // Ugly hacking. if (value instanceof DoubleWrapper) { DoubleWrapper v = (DoubleWrapper) value; ((JLabel) c).setText( org.yccheok.jstock.portfolio.Utils.toCurrency(v.decimalPlace, v.value)); } else if (value instanceof DoubleWithCurrency) { DoubleWithCurrency v = (DoubleWithCurrency) value; Currency currency = v.currency(); String content = org.yccheok.jstock.portfolio.Utils.toCurrency(v.decimalPlace(), v.Double()); if (currency == null) { ((JLabel) c).setText(content); } else { String prefix = currency.toString(); if (Currency.GBX.equals(prefix)) { // Special handling. prefix = Currency.GBP; } else if (Currency.ZAC.equals(prefix)) { // Special handling. prefix = Currency.ZAR; } ((JLabel) c).setText(prefix + " " + content); } } else { ((JLabel) c).setText( org.yccheok.jstock.portfolio.Utils.toCurrency(DecimalPlace.Four, value)); } } } } else { if (value != null) { if (c instanceof JLabel) { ((JLabel) c).setText(org.yccheok.jstock.portfolio.Utils.toUnits(value)); } } } return c; } }); treeTable.setDefaultRenderer(SimpleDate.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null) { if (c instanceof JLabel) { DateFormat dateFormat = DateFormat.getDateInstance(); SimpleDate simpleDate = (SimpleDate) value; ((JLabel) c).setText(dateFormat.format(simpleDate.getTime())); } } return c; } }); }