📄 bugassistant.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */package edu.udo.cs.yale.gui;import edu.udo.cs.yale.Yale;import edu.udo.cs.yale.tools.BugReport;import javax.swing.*;import javax.swing.text.*;import java.awt.*;import java.awt.event.*;import java.io.File;public class BugAssistant extends JDialog { private static final String INSTRUCTIONS = "<html><h4>Send Bug Report</h4>"+ "This dialog will help you to file a bug report. It will automatically collect most of the data necessary to examine the problem. The assistant will create a zip file containing your experiment setup (xml file), parameter settings, log file, and information about the runtime environment. Yale does <i>not</i> automatically add data files or any other files since these may contain confidential data and may be large. You can attach them using the \"Add file...\" button. When you are done, save the bug report to disc and send it by email to</p><center><b><tt>yale@ls8.cs.uni-dortmund.de</tt></b></center>"; private static final String TEXT_INSTRUCTIONS = "Enter a brief description of what happened into this text field. Please also describe the purpose of your experiment because this cannot always be concluded trivially from the experiment setup."; private JTextArea message = new JTextArea(TEXT_INSTRUCTIONS, 5,20); private JTextComponent name = new JTextField(15); private JList attachments = new JList(new DefaultListModel()); public BugAssistant(final Throwable exception) { super(YaleGUI.getMainFrame(), "Bug Report Assistant", true); GridBagLayout gbl = new GridBagLayout(); getContentPane().setLayout(gbl); GridBagConstraints c = new GridBagConstraints(); c.fill = c.BOTH; c.weightx = 1; c.weighty = 0; c.insets = new Insets(5,5,5,5); c.gridwidth = c.REMAINDER; JLabel instructions = new JLabel(INSTRUCTIONS); instructions.setFont(instructions.getFont().deriveFont(Font.PLAIN)); gbl.setConstraints(instructions, c); getContentPane().add(instructions); JLabel nameLabel = new JLabel("Your email address"); c.gridwidth = 1; gbl.setConstraints(nameLabel, c); getContentPane().add(nameLabel); c.gridwidth = c.REMAINDER; gbl.setConstraints(name, c); getContentPane().add(name); message.setLineWrap(true); message.setWrapStyleWord(true); JScrollPane messagePane = new JScrollPane(message); c.gridwidth = c.REMAINDER; c.weighty = 5; gbl.setConstraints(messagePane, c); getContentPane().add(messagePane); c.weighty = 0; c.gridwidth = 1; c.gridheight = 2; attachments.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane attachmentPane = new JScrollPane(attachments); gbl.setConstraints(attachmentPane, c); getContentPane().add(attachmentPane); c.gridwidth = 1; c.gridheight = 1; c.gridx = 1; c.gridy = 3; JButton add = new JButton("Add file..."); add.addActionListener(new ActionListener () { public void actionPerformed(ActionEvent e) { File file = SwingTools.chooseFile(null, null, true); if (file != null) ((DefaultListModel)attachments.getModel()).addElement(file); } }); gbl.setConstraints(add, c); getContentPane().add(add); c.gridx = 1; c.gridy = 4; JButton remove = new JButton("Remove file"); remove.addActionListener(new ActionListener () { public void actionPerformed(ActionEvent e) { Object value = attachments.getSelectedValue(); if (attachments.getSelectedIndex() >= 0) { ((DefaultListModel)attachments.getModel()).remove(attachments.getSelectedIndex()); } } }); gbl.setConstraints(remove, c); getContentPane().add(remove); c.gridwidth = c.REMAINDER; c.gridheight = 1; c.gridx = 2; c.gridy = 3; JButton save = new JButton("Save Report..."); save.addActionListener(new ActionListener () { public void actionPerformed(ActionEvent e) { String email = name.getText().trim(); if (email.length() == 0) { JOptionPane.showMessageDialog(YaleGUI.getMainFrame(), "Please enter an email address.", "Form incomplete", JOptionPane.ERROR_MESSAGE); return; } File file = SwingTools.chooseFile(null, new File("bugreport.zip"), false, false, new String[] { ".zip" }, "zip archives"); if (file != null) { try { ListModel model = (DefaultListModel)attachments.getModel(); File [] attachments = new File[model.getSize()]; for (int i = 0; i < attachments.length; i++) { attachments[i] = (File)model.getElementAt(i); } BugReport.createBugReport(file, exception, "From: "+name.getText()+"\n"+ "Date: "+new java.util.Date()+"\n\n"+ message.getText(), Yale.getExperiment(), YaleGUI.getMainFrame().getMessageViewer().getLogMessage(), attachments); dispose(); } catch(Throwable t) { SwingTools.showSimpleErrorMessage("Cannot create report file!", t); } } } }); gbl.setConstraints(save, c); getContentPane().add(save); c.gridx = 2; c.gridy = 4; JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener () { public void actionPerformed(ActionEvent e) { dispose(); } }); gbl.setConstraints(cancel, c); getContentPane().add(cancel); pack(); //message.setText(TEXT_INSTRUCTIONS); message.setSelectionStart(0); message.setSelectionEnd(TEXT_INSTRUCTIONS.length()-1); setLocationRelativeTo(YaleGUI.getMainFrame()); } public Dimension getPreferredSize() { return new Dimension(YaleGUI.getMainFrame().getWidth()*3/4, YaleGUI.getMainFrame().getHeight()*3/4); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -