⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metricsanalyzerframe.java

📁 这是04年写的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                                  }                                                                                           String chooseName() throws Exception {                                                    String name =                                                      JOptionPane.showInputDialog(getContentPane(),                                                                                  "Give name for metrics:",                                                                                  "Importing metrics...",                                                                                  JOptionPane.PLAIN_MESSAGE);                                                    if (null == name)                                                      throw new ActionCancelledException();                                                    return name;                                                  }                                                }),                                       new Comp(new JButton("Remove"),                                                new FailableActionListener() {                                                  public void actionPerformed(ActionEvent e) throws Exception {                                                    if (JOptionPane.YES_OPTION !=                                                         JOptionPane.showConfirmDialog(getContentPane(),                                                                                      "Permanently remove selected snapshots?",                                                                                      "Remove confirmation",                                                                                      JOptionPane.YES_NO_OPTION,                                                                                      JOptionPane.WARNING_MESSAGE))                                                      throw new ActionCancelledException();                                                                                                        project.removeSnapshots(historyJList.getSelectedIndices());                                                  }                                                })})}),                 new Comp(newPanelWithBoxLayout(BoxLayout.Y_AXIS),                          new Object[]{                            BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Query"),                            new JScrollPane(queryJList),                            new Comp(new Box(BoxLayout.X_AXIS),                                     new Object[]{                                       new Comp(new JButton("Execute"),                                                new FailableActionListener() {                                                  public void actionPerformed(ActionEvent e) throws Exception {                                                    QueryList.Entry queryEntry = getQueryEntry();                                                    new TableModelBrowserFrame(queryEntry.toString(),                                                                               project.executeQuery(queryEntry.query,                                                                                                    historyJList.getSelectedIndex(),                                                                                                    historyJList.getSelectedIndices()));                                                  }                                                  QueryList.Entry getQueryEntry() throws Exception {                                                    int i = queryJList.getSelectedIndex();                                                    if (-1 == i)                                                      throw new ActionCancelledException("Please select a query.",                                                                                         "Error",                                                                                         JOptionPane.ERROR_MESSAGE);                                                    return (QueryList.Entry)project.getQueryList().getElementAt(i);                                                  }                                                }),                                       new Comp(new JButton("Edit"),                                                new FailableActionListener() {                                                  public void actionPerformed(ActionEvent e) throws Exception {                                                    int i = queryJList.getSelectedIndex();                                                    QueryList.Entry entry = -1 == i                                                      ? new QueryList.Entry(new File(""),"")                                                      : (QueryList.Entry)project.getQueryList().getElementAt(i);                                                    new QueryEditorFrame(entry.file.getPath(), entry.query);                                                  }                                                }),                                       new Comp(new JButton("New"),                                                new FailableActionListener() {                                                  public void actionPerformed(ActionEvent e) throws Exception {                                                    new QueryEditorFrame("", "");                                                  }                                                }),                                       new Comp(new JButton("Load..."),                                                new AbstractFileChooserAction(getContentPane(), queryFileChooser) {                                                  public void actionPerformed(ActionEvent e) throws Exception {                                                    project.loadQuery(openFile());                                                  }                                                }),                                       new Comp(new JButton("Remove"),                                                new FailableActionListener() {                                                  public void actionPerformed(ActionEvent e) throws Exception {                                                    project.removeQueries(queryJList.getSelectedIndices());                                                  }                                                })})})}).build(getContentPane());    tabbedPane = (JTabbedPane)      new Comp(new JTabbedPane(),               new Object[]{                 new ChangeListener() {                   public void stateChanged(ChangeEvent ev) {                     if (null != tabbedPane && tabbedPane.getSelectedComponent() == metricsTab) {                       try {                         project.getDatabase().historyList.updateCache();                       } catch (Exception ex) {                         JOptionPane.showMessageDialog(getContentPane(),                                                       ex.toString(),                                                       "Error",                                                       JOptionPane.ERROR_MESSAGE);                       }                     }                   }},                 settingsTab}).build(getContentPane());        getContentPane().add(tabbedPane);    final Component menu =      new Comp(new JMenuBar(),               new Object[]{                 new Comp(new JMenu("Project"),                          new Object[]{                            new Comp(new JMenuItem("Open.."),                                     new AbstractFileChooserAction(getContentPane(), projectFileChooser) {                                       public void actionPerformed(ActionEvent e) throws Exception {                                         File projectFile = openFile();                                         setProject(projectFile, Project.load(projectFile));                                         ((JTabbedPane)tabbedPane).setSelectedComponent(metricsTab);                                       }                                     }),                            new Comp(new JMenuItem("Save"),                                     new AbstractFileChooserAction(getContentPane(), projectFileChooser) {                                       public void actionPerformed(ActionEvent e) throws Exception {                                         File theProjectFile = projectFile;                                         if (null == theProjectFile)                                           theProjectFile = saveFile();                                         project.save(theProjectFile);                                         setProject(theProjectFile, project);                                       }                                     }),                            new Comp(new JMenuItem("Save as..."),                                     new AbstractFileChooserAction(getContentPane(), projectFileChooser) {                                       public void actionPerformed(ActionEvent e) throws Exception {                                         File projectFile = saveFile();                                         project.save(projectFile);                                         setProject(projectFile, project);                                       }                                     })})}).build(getContentPane());    setJMenuBar((JMenuBar)menu);    if (null != initialProjectFile)      setProject(initialProjectFile, Project.load(initialProjectFile));    else      setProject(null, new Project());  }  static private JPanel newPanelWithBoxLayout(int axis) {    JPanel panel = new JPanel();    panel.setLayout(new BoxLayout(panel, axis));    return panel;  }  private class QueryEditorFrame extends JFrame {    private JTextArea queryArea = new JTextArea();    private JTextField fileNameField = new JTextField(32);    QueryEditorFrame(String fileName, String query) throws Exception {      setSize(640,480);      setTitle("QueryEditor - MetricsAnalyzer");      queryArea.setText(query);      fileNameField.setText(fileName);            Component component =        new Comp(new Box(BoxLayout.Y_AXIS),                 new Object[]{                   new Comp(new Box(BoxLayout.X_AXIS),                            new Object[]{                              new Comp(new JButton("File..."),                                       new AbstractFileChooserAction(getContentPane(), queryFileChooser) {                                         public void actionPerformed(ActionEvent e) throws Exception {                                           fileNameField.setText(saveFile().getPath());                                         }                                       }),                              Comp.limitMaxSizeByPrefSize(fileNameField, false, true)}),                   new JScrollPane(queryArea),                   new Comp(new Box(BoxLayout.X_AXIS),                            new Object[]{                              new Comp(new JButton("Save"),                                       new FailableActionListener() {                                         public void actionPerformed(ActionEvent e) throws Exception {                                           File file = new File(fileNameField.getText());                                           String query = queryArea.getText();                                           if (0 == file.getPath().length() || 0 == query.length())                                             throw new ActionCancelledException("File or query is missing!",                                                                                "Error",                                                                                JOptionPane.ERROR_MESSAGE);                                           if (file.exists() &&                                                JOptionPane.YES_OPTION !=                                                JOptionPane.showConfirmDialog(getContentPane(),                                                                             "A file by the name:\n" +                                                                             "\n" +                                                                             "  " + file.getPath() + "\n" +                                                                             "\n" +                                                                             "already exists. Do you wish to overwrite?",                                                                             "File overwrite confirmation",                                                                             JOptionPane.YES_NO_OPTION,                                                                             JOptionPane.WARNING_MESSAGE))                                             throw new ActionCancelledException();                                           Files.writeFile(file, query);                                           project.loadQuery(file);                                           dispose();                                         }                                       })})}).build();            getContentPane().add(component);      setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);      show();    }  }  private static class TableModelBrowserFrame extends JFrame {    TableModelBrowserFrame(String queryName, TableModel[] results) throws Exception {      setSize(640,480);      setTitle(queryName + " - MetricsAnalyzer");            Box container = new Box(BoxLayout.Y_AXIS);      for (int i=0; i<results.length; ++i)        container.add(new JScrollPane(new JTable(results[i])));      getContentPane().add(container);      setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);      show();    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -