📄 statisticsviewer.java
字号:
(selected[i], !data_aray[selected_index].isEnabled(selected[i])); graph.repaint(); legend_list.repaint(); } else if(e.getActionCommand().compareTo("Change Color") == 0) { Color color; int selected[] = legend_list.getSelectedIndices(); for(int i=0; i < selected.length;i++) { color = Stat_ColorChooser.showDialog (this, "Color Chooser", data_aray[selected_index].getColor(selected[i])); data_aray[selected_index].changeColor (selected[i],color); } need_color_change = true; repaint(); graph.repaint(); } /* else if(e.getActionCommand().compareTo("On") == 0) { graph.setReScale(true); graph.repaint(); } else if(e.getActionCommand().compareTo("Off") == 0) graph.setReScale(false); */ else if((time_listener != null) && (e.getActionCommand().compareTo("Close") == 0)) time_listener.closePreview(); else { for(int ii=0; ii < graph_list.length; ii++) { if(e.getSource() == graph_list[ii]) { if(selected_index != ii) { selected_index = ii; makeGraph(data_aray[selected_index]); } ii = graph_list.length; } } } } class LegendListCellRenderer extends JLabel implements ListCellRenderer { public LegendListCellRenderer() { super(); setBorder(new LineBorder(Color.white,2)); setOpaque(true); } public Component getListCellRendererComponent (JList list, Object value, int index, boolean isselected, boolean cellHasFocus) { if (index == -1) { int selected = list.getSelectedIndex(); if (selected == -1) return this; else index = selected; } setText(" " + data_aray[selected_index].getLabel(index)); if(data_aray[selected_index].isEnabled(index)) setIcon(legend_images_selected[index]); else setIcon(legend_images[index]); if(isselected) { setBackground(Color.black); setForeground(Color.white); } else { setForeground(Color.black); setBackground(Color.white); } repaint(); return this; } } private void removeCurrentFile() { title.setTitle(""); graph.setGraphData(null); legend_images = new ImageIcon[0]; legend_images_selected = new ImageIcon[0]; all_data.setEnabled(false); no_data.setEnabled(false); display_legend.setEnabled(false); hide_legend.setEnabled(false); graph_menu.removeAll(); need_color_change = true; repaint(); legend_dialog.setVisible(false); legend_dialog.getContentPane().removeAll(); String value_labels[] = new String[0]; makeLegendDialog(value_labels); graph.repaint(); title.repaint(); legend_list.repaint(); legend_dialog.repaint(); } public void makeGraph(Statistics_Data data) { String value_labels[]; title.setTitle(data.getTitle()); graph.setGraphData(data); value_labels = new String[data.getNumXValues()]; for(int ii = 0; ii < data.getNumXValues(); ii++) { value_labels[ii] = data.getLabel(ii); } legend_images = new ImageIcon[value_labels.length]; legend_images_selected = new ImageIcon[value_labels.length]; all_data.setEnabled(true); no_data.setEnabled(true); display_legend.setEnabled(true); hide_legend.setEnabled(true); need_color_change = true; legend_dialog.getContentPane().removeAll(); makeLegendDialog(value_labels); graph.repaint(); title.repaint(); /* JLabel temp_label = new JLabel("Time:",JLabel.CENTER); title.add(temp_label); track_time = new JTextField("0.0",7); track_time.setEnabled(false); title.add(track_time); buildConstraints(constraints, 0, 1, 3, 1, GridBagConstraints.HORIZONTAL); add(title,constraints); */ } private void makeLegendDialog(String value_labels[]) { GridBagConstraints constraints = new GridBagConstraints(); Dimension dim; legend_dialog.getContentPane().setLayout(new GridBagLayout()); legend_list = new JList(value_labels); legend_list.setCellRenderer(new LegendListCellRenderer()); constraints.weightx = 100; constraints.weighty = 100; buildConstraints(constraints, 0,0,2,1,GridBagConstraints.BOTH); legend_dialog.getContentPane().add(new JScrollPane(legend_list), constraints); constraints.weightx = 0; constraints.weighty = 0; JButton button = new JButton("Select/Deselect"); button.addActionListener(this); buildConstraints(constraints, 0,1,2,1,GridBagConstraints.BOTH); legend_dialog.getContentPane().add(button,constraints); // legend_dialog.getContentPane().add("Center",button); button = new JButton("All"); button.addActionListener(this); buildConstraints(constraints, 0,2,1,1,GridBagConstraints.BOTH); legend_dialog.getContentPane().add(button,constraints); button = new JButton("None"); button.addActionListener(this); buildConstraints(constraints, 1,2,1,1,GridBagConstraints.BOTH); legend_dialog.getContentPane().add(button,constraints); button = new JButton("Change Color"); button.addActionListener(this); buildConstraints(constraints, 0,3,2,1,GridBagConstraints.BOTH); legend_dialog.getContentPane().add(button,constraints); legend_dialog.pack(); legend_dialog.setVisible(true); legend_dialog.setLocation(getLocation().x + getSize().width, getLocation().y + getSize().height/2); } private static void closeAll() { while(!windows.isEmpty()) { Window w = (Window)windows.firstElement(); w.setVisible(false); windows.removeElement(w); w.dispose(); } if(app_Enabled) System.exit(0); } private void buildConstraints(GridBagConstraints constraints, int gridx, int gridy, int gridwidth, int gridheight, int fill) { constraints.gridx = gridx; constraints.gridy = gridy; constraints.gridwidth = gridwidth; constraints.gridheight = gridheight; constraints.fill = fill; } private void setObjectSize(JComponent obj, Dimension dim) { obj.setPreferredSize(dim); obj.setMaximumSize(dim); obj.setMinimumSize(dim); } private void initializeData(String file_name) { boolean readable_file = true; int option = JFileChooser.APPROVE_OPTION; String exts[] = {"tsv"}; Statistics_Data data; JFileChooser file_chooser = new JFileChooser(System.getProperty("user.dir")); file_chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); StatView_FileFilter filter = new StatView_FileFilter(exts,"tab separated values (*.tsv)"); file_chooser.addChoosableFileFilter(filter); if(file_name == null) { option = file_chooser.showOpenDialog(this); file_name = new String(file_chooser.getSelectedFile().getPath()); } if(option == JFileChooser.APPROVE_OPTION) { Stat_File_Parser filin = null; try { filin = new Stat_File_Parser(file_name); } catch(Exception e) { JOptionPane.showMessageDialog (this, "Error: Unable to open selected file.", "Message", JOptionPane.INFORMATION_MESSAGE); readable_file = false; } if(readable_file) { Vector temp_data_aray = new Vector(); try { data = filin.readGraphData(); while( data != null ) { temp_data_aray.addElement(data); data = filin.readGraphData(); } } catch(Exception e) { JOptionPane.showMessageDialog (this, "Error in reading file", "Message", JOptionPane.INFORMATION_MESSAGE); readable_file = false; } if( !temp_data_aray.isEmpty() && readable_file ) { data_aray = new Statistics_Data[temp_data_aray.size()]; graph_list = new JMenuItem[data_aray.length]; for(int ii = 0; ii < data_aray.length; ii++) { data_aray[ii] = (Statistics_Data)temp_data_aray.elementAt(ii); graph_list[ii] = new JMenuItem(data_aray[ii].getTitle()); graph_menu.add(graph_list[ii]); graph_list[ii].addActionListener(this); } selected_index = 0; makeGraph(data_aray[selected_index]); } else JOptionPane.showMessageDialog (this, "Empty file or error in reading file", "Message", JOptionPane.INFORMATION_MESSAGE); } } } public static void main(String args[]) { StatisticsViewer graph_pane = new StatisticsViewer(true); if(args.length > 0) graph_pane.initializeData(args[0]); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -