📄 graph_pane.java
字号:
public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e) { if((time_listener != null) /*&& (e.getClickCount()==2)*/) { Point coords = e.getPoint(), graph_origin = graph.getOrigin(); if((coords.x >= graph_origin.x) && (coords.x <= (graph_origin.x + graph.getGraphRange())) && (coords.y <= graph_origin.y) && (coords.y > graph.GRAPH_MARGIN)) time_listener.showTime (graph.mark_time (coords, graph_scroller.getViewport().getViewPosition())); } } public void mouseMoved(MouseEvent e) { Point coords = e.getPoint(), graph_origin = graph.getOrigin(); String time_value_s; if((coords.x >= graph_origin.x) && (coords.x <= (graph_origin.x + graph.getGraphRange())) && (coords.y <= graph_origin.y) && (coords.y > graph.GRAPH_MARGIN)) { graph.setCursor(on_graph); time_value_s = graph.calculateXValueString(coords.x,8); track_time.setText(time_value_s); } else graph.setCursor(default_cur); } public void mouseDragged(MouseEvent e){} public void actionPerformed(ActionEvent e) { if(e.getActionCommand().compareTo("Line") == 0) graph.changeGraphType(Graph.LINE); else if(e.getActionCommand().compareTo("Bar") == 0) graph.changeGraphType(Graph.BAR); else if(e.getActionCommand().compareTo("All") == 0) { for(int i=0; (i < legend_images.length);i++) { graph.setState(i,true); } legend_list.repaint(); graph.repaint(); } else if(e.getActionCommand().compareTo("None") == 0) { for(int i=0; (i < legend_images.length);i++) { graph.setState(i,false); } legend_list.repaint(); graph.repaint(); } else if(e.getActionCommand().compareTo("View Statistics") == 0) { /* String args[]={}; UTEStatsViewer.Main.main(args); */ StatisticsViewer stats_viewer = new StatisticsViewer(); } else if(e.getActionCommand().compareTo("In") == 0) { if(graph.zoomIn() == true) { ((JMenuItem)e.getSource()).setEnabled(true); zoomOut.setEnabled(true); } else ((JMenuItem)e.getSource()).setEnabled(false); graph_scroller.getViewport().setViewPosition (graph.getMarkdView()); repaint(); } else if(e.getActionCommand().compareTo("Out") == 0) { if(graph.zoomOut() == true) { ((JMenuItem)e.getSource()).setEnabled(true); zoomIn.setEnabled(true); } else ((JMenuItem)e.getSource()).setEnabled(false); graph_scroller.getViewport().setViewPosition (graph.getMarkdView()); repaint(); } else if(e.getActionCommand().compareTo("Reset") == 0) { zoomIn.setEnabled(true); zoomOut.setEnabled(false); graph.reset(); repaint(); } else if(e.getActionCommand().compareTo("Display") == 0) { legend_dialog.pack(); legend_list.setSelectedIndex(-1); legend_dialog.setVisible(true); } else if(e.getActionCommand().compareTo("Hide") == 0) { legend_dialog.pack(); legend_list.setSelectedIndex(-1); legend_dialog.setVisible(false); } else if(e.getActionCommand().compareTo("Select/Deselect") == 0) { int selected[] = legend_list.getSelectedIndices(); for(int i=0; i < selected.length;i++) graph.setState(selected[i],!graph.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 = ColorChooser.showDialog (null, "Color Chooser", graph.getColor(selected[i])); graph.changeColor(selected[i],color); } need_color_change = true; repaint(); graph.repaint(); legend_list.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)) { legend_dialog.setVisible(false); legend_dialog.dispose(); time_listener.closePreview(); } } 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) { setText(" " + graph.getLabel(index)); if(isselected) { setBackground(Color.black); setForeground(Color.white); } else { setForeground(Color.black); setBackground(Color.white); } if(graph.isEnabled(index)) setIcon(legend_images_selected[index]); else setIcon(legend_images[index]); repaint(); return this; } } private void makeLegendDialog(String value_labels[]) { int MaxVisibleRowCount = 20; GridBagConstraints constraints = new GridBagConstraints(); Dimension dim; legend_dialog = new JDialog(owner,"Legend"); legend_dialog.getContentPane().setLayout(new GridBagLayout()); legend_list = new JList(value_labels); legend_list.setSelectionBackground(Color.black); legend_list.setCellRenderer(new LegendListCellRenderer()); if ( value_labels.length < MaxVisibleRowCount ) legend_list.setVisibleRowCount( value_labels.length ); else legend_list.setVisibleRowCount( MaxVisibleRowCount ); 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( owner.getLocation().x + owner.getSize().width, owner.getLocation().y + owner.getSize().height/10); } 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); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -