📄 graphpanel.java
字号:
if (classNum >= 0 && statNum >= 0)
graph.draw(rowNum, model.getThroughput()[statNum][classNum]);
else if (classNum <0 && statNum >= 0)
graph.draw(rowNum, model.getPerStationX()[statNum]);
else if (classNum >=0 && statNum < 0)
graph.draw(rowNum, model.getPerClassX()[classNum]);
else
graph.draw(rowNum, model.getGlobalX());
}
// Queue length
if (currentIndex.equals(ExactModel.INDICES_TYPES[1])) {
if (classNum >= 0 && statNum >= 0)
graph.draw(rowNum, model.getQueueLen()[statNum][classNum]);
else if (classNum <0 && statNum >= 0)
graph.draw(rowNum, model.getPerStationQ()[statNum]);
else if (classNum >=0 && statNum < 0)
graph.draw(rowNum, model.getPerClassQ()[classNum]);
else
graph.draw(rowNum, model.getGlobalQ());
}
// Residence times
if (currentIndex.equals(ExactModel.INDICES_TYPES[2])) {
if (classNum >= 0 && statNum >= 0)
graph.draw(rowNum, model.getResTimes()[statNum][classNum]);
else if (classNum <0 && statNum >= 0)
graph.draw(rowNum, model.getPerStationR()[statNum]);
else if (classNum >=0 && statNum < 0)
graph.draw(rowNum, model.getPerClassR()[classNum]);
else
graph.draw(rowNum, model.getGlobalR());
}
// Utilization
if (currentIndex.equals(ExactModel.INDICES_TYPES[3])) {
if (classNum >= 0 && statNum >= 0)
graph.draw(rowNum, model.getUtilization()[statNum][classNum]);
else
graph.draw(rowNum, model.getPerStationU()[statNum]);
}
// Resets view
autosizeGraph();
}
/**
* Paints all performance indices of current table
*/
private void paintAllIndices() {
for (int i=0; i<classes.length; i++)
paintIndexAtRow(i);
}
/**
* AutoResizes graph window
*/
private void autosizeGraph() {
graph.fillPlot();
}
/**
* @return the panel's name
*/
public String getName() {
return "Graphical Results";
}
/**
* Table used to select performance indices to be drawn
*/
protected class LinesTable extends JTable {
/** ComboBoxes used as cell editors */
private ComboEditor classEditor, stationsEditor, uStationsEditor;
/**
* Builds a new LinesTable
*/
public LinesTable() {
super(new LinesTableModel());
setDefaultRenderer(Color.class, new ColorCellEditor());
setDefaultRenderer(String.class, ComboBoxCellEditor.getRendererInstance());
// Sets column sizes
getColumnModel().getColumn(0).setMaxWidth(30);
getColumnModel().getColumn(1).setPreferredWidth(80);
getColumnModel().getColumn(2).setPreferredWidth(80);
setRowHeight(18);
// Creates class editors (one is for utilizations)
JComboBox classCombo = new JComboBox();
// Null elements
classCombo.addItem("");
// Aggregate measures
classCombo.addItem(AGGREGATE);
for (int i=0; i<model.getClasses(); i++) {
classCombo.addItem(model.getClassNames()[i]);
}
// Creates station editor
JComboBox stationsCombo = new JComboBox();
JComboBox uStationsCombo = new JComboBox();
stationsCombo.addItem("");
uStationsCombo.addItem("");
stationsCombo.addItem(AGGREGATE);
uStationsCombo.addItem(ExactModel.GRAY_S+AGGREGATE+ExactModel.GRAY_E);
for (int i=0; i<model.getStations(); i++) {
stationsCombo.addItem(model.getStationNames()[i]);
uStationsCombo.addItem(model.getStationNames()[i]);
}
// Creates editors
classEditor = new ComboEditor(classCombo);
uStationsEditor = new ComboEditor(uStationsCombo);
stationsEditor = new ComboEditor(stationsCombo);
}
/**
* Returns an appropriate editor for the cell specified by
* <code>row</code> and <code>column</code>. If the
* <code>TableColumn</code> for this column has a non-null editor,
* returns that. If not, finds the class of the data in this
* column (using <code>getColumnClass</code>)
* and returns the default editor for this type of data.
* <p/>
*
* @param row the row of the cell to edit, where 0 is the first row
* @param column the column of the cell to edit,
* where 0 is the first column
* @return the editor for this cell;
* if <code>null</code> return the default editor for
* this type of cell
* @see javax.swing.DefaultCellEditor
*/
public TableCellEditor getCellEditor(int row, int column) {
if (column == 1)
return classEditor;
else if (currentIndex.equals(ExactModel.INDICES_TYPES[3]))
return uStationsEditor;
else
return stationsEditor;
}
/**
* Returns an appropriate renderer for the cell specified by this row and
* column. If the <code>TableColumn</code> for this column has a non-null
* renderer, returns that. If not, finds the class of the data in
* this column (using <code>getColumnClass</code>)
* and returns the default renderer for this type of data.
* <p/>
* <b>Note:</b>
* Throughout the table package, the internal implementations always
* use this method to provide renderers so that this default behavior
* can be safely overridden by a subclass.
*
* @param row the row of the cell to render, where 0 is the first row
* @param column the column of the cell to render,
* where 0 is the first column
* @return the assigned renderer; if <code>null</code>
* returns the default renderer
* for this type of object
* @see javax.swing.table.DefaultTableCellRenderer
* @see javax.swing.table.TableColumn#setCellRenderer
* @see #setDefaultRenderer
*/
public TableCellRenderer getCellRenderer(int row, int column) {
if (model.isMultiClass() || column != 1)
return super.getCellRenderer(row, column);
else
return super.getDefaultRenderer(Object.class);
}
/**
* Inner class used as a comboBox editor
*/
protected class ComboEditor extends DefaultCellEditor {
protected JComboBox combo;
/**
* Constructs a <code>DefaultCellEditor</code> object that uses a
* combo box.
*
* @param comboBox a <code>JComboBox</code> object
*/
public ComboEditor(JComboBox comboBox) {
super(comboBox);
combo = comboBox;
}
/**
* Returns selected index - 2 (so -1 means all classes and -2 or -3
* means no selection)
*/
public Object getCellEditorValue() {
int val = combo.getSelectedIndex();
return new Integer(val - 2);
}
}
}
/**
* Table model for LinesTable
*/
protected class LinesTableModel extends AbstractTableModel {
/**
* Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
*
* @param columnIndex the column being queried
* @return the Object.class
*/
public Class getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0:
return Color.class;
case 1:
return String.class;
case 2:
return String.class;
default:
return super.getColumnClass(columnIndex);
}
}
/**
* Returns the number of columns in the model. A
* <code>JTable</code> uses this method to determine how many columns it
* should create and display by default.
*
* @return the number of columns in the model
* @see #getRowCount
*/
public int getColumnCount() {
return 3;
}
/**
* Returns a default name for the column using spreadsheet conventions:
* A, B, C, ... Z, AA, AB, etc. If <code>column</code> cannot be found,
* returns an empty string.
*
* @param column the column being queried
* @return a string containing the default name of <code>column</code>
*/
public String getColumnName(int column) {
switch(column) {
case 0:
return " ";
case 1:
return "Class";
case 2:
return "Station";
}
return super.getColumnName(column); //To change body of overridden methods use File | Settings | File Templates.
}
/**
* Returns the number of rows in the model. A
* <code>JTable</code> uses this method to determine how many rows it
* should display. This method should be quick, as it
* is called frequently during rendering.
*
* @return the number of rows in the model
* @see #getColumnCount
*/
public int getRowCount() {
return graph.getColors().length;
}
/**
* Returns the value for the cell at <code>columnIndex</code> and
* <code>rowIndex</code>.
*
* @param rowIndex the row whose value is to be queried
* @param columnIndex the column whose value is to be queried
* @return the value Object at the specified cell
*/
public Object getValueAt(int rowIndex, int columnIndex) {
int stationNum = stations[rowIndex];
int classNum = classes[rowIndex];
switch(columnIndex) {
case 0:
return graph.getColors()[rowIndex];
case 1:
if (classNum >= 0)
return model.getClassNames()[classNum];
else if (classNum == -1)
return AGGREGATE;
else
return null;
case 2:
if (stationNum >= 0)
return model.getStationNames()[stationNum];
else if (stationNum == -1)
return AGGREGATE;
else
return null;
}
return null;
}
/**
* This empty implementation is provided so users don't have to implement
* this method if their data model is not editable.
*
* @param aValue value to assign to cell
* @param rowIndex row of cell
* @param columnIndex column of cell
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (columnIndex == 2) {
if (currentIndex.equals(ExactModel.INDICES_TYPES[3]) && ((Integer)aValue).intValue() < 0)
stations[rowIndex] = -2;
else
stations[rowIndex] = ((Integer)aValue).intValue();
}
else
classes[rowIndex] = ((Integer)aValue).intValue();
// Paints new index
paintIndexAtRow(rowIndex);
}
/**
* Class and stations are editables
*
* @param rowIndex the row being queried
* @param columnIndex the column being queried
* @return false
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 2 || (columnIndex == 1 && model.isMultiClass());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -