📄 optionsforprojectsdialog.java
字号:
if (i<no.length) { projectsPanel.setSelectedIndex(i); } else { projectsPanel.setSelectedIndex(no.length-1); } //& remakeOptionsPanel(); } } } } } // --------------------- ProjectOptionsPanel --------------------- JTextField configurationFile; OptionsForProjectsPanel optionsPanel; JComboBox activeProject; JTabbedPane projectsPanel; Options[] projects; Options[] originalProjects; int opy; public void checkConfigurationFile() { if (! s.configurationFile.equals(configurationFile.getText())) { jEdit.setProperty(s.configurationFileOption, configurationFile.getText()); JOptionPane.showMessageDialog(s.view, "You have to restart jEdit in order to use new Xrefactory configuration file.", "Xrefactory Message", JOptionPane.INFORMATION_MESSAGE); } } public boolean addNewProject(Component parent) { NewProjectDialog nn; if (parent instanceof Dialog) nn = new NewProjectDialog((Dialog)parent, projects); else if (parent instanceof Frame) nn = new NewProjectDialog((Frame)parent, projects); else {nn=null; s.assertt(false);} NewProjectDialog.NewProjectPanel pp = (NewProjectDialog.NewProjectPanel)nn.getContentPane(); if (! pp.projectName.getText().equals("")) { Options[] no = new Options[projects.length+1]; System.arraycopy(projects,0,no,0,projects.length); no[projects.length] = new Options(pp.projectName.getText(), pp.sourceDirectory.getText() ); no[projects.length].addNewProjectOptions( pp.projectName.getText(), pp.sourceDirectory.getText(), pp.classPath.getText(), pp.sourcePath.getText() ); projects = no; int i = projects.length-1; projectsPanel.add(projects[i].projectName, new OptionsForProjectsPanel(projects[i], Options.OPT_PROJECT, Opt.optionsEditingDisplaysFile)); projectsPanel.setSelectedIndex(i); activeProject.addItem(projects[i].projectName); JOptionPane.showMessageDialog(parent, "New project was created. Please verify that remaining options are correctly set.\nIn particular that Jdk runtime library is the file storing your jdk classes (usualy rt.jar)"); if (pp.makeActive.isSelected()) { Opt.setActiveProject(pp.projectName.getText()); } return(true); } else { return(false); } } public boolean checkOptionsConsistency() { int i,j,rr; for(i=0; i<projects.length; i++) { for(j=i+1; j<projects.length; j++) { PathIterator ii = new PathIterator( projects[i].getProjectAutoDetectionOpt(),s.classPathSeparator); while(ii.hasNext()) { String cpi = ii.next(); PathIterator ji = new PathIterator( projects[j].getProjectAutoDetectionOpt(),s.classPathSeparator); while(ji.hasNext()) { String cpj = ji.next(); if (Options.projectMarkersOverlapps(cpi, cpj)) { rr = JOptionPane.showOptionDialog(s.getProbableParent(this), "Conflict between projects "+projects[i].projectName+" and "+projects[j].projectName+".\nProjects overlap in auto detection paths: "+cpi+" and "+cpj, "Configuration File Problem", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new String[] {"Quit without saving", "Ignore this problem and save", "Ignore all problems and save"}, null); if (rr==0) return(false); if (rr==2) return(true); } } } } } return(true); } public void recreateTagFile(Options o) { DispatchData ndata = new DispatchData(s.xbTask, this); s.activeProject = o.projectName; // this is a hack, new project is active for creation XrefTaskForTagFile.runXrefOnTagFile("-create", "Creating Tags.",true, ndata); } public void checkProjectsModifications() { int i,j,k; for(i=0; i<projects.length; i++) { for(j=0; j<originalProjects.length; j++) { if (projects[i].projectName.equals(originalProjects[j].projectName)) break; } if (j==originalProjects.length) { int confirm = JOptionPane.showConfirmDialog( s.getProbableParent(this), "Project "+ projects[i].projectName + " added. Can I create Tags for it?", "Xrefactory Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (confirm == JOptionPane.YES_OPTION) { recreateTagFile(projects[i]); } } else { // check for modification of important options Options newopt = projects[i]; Options oldopt = originalProjects[j]; for(k=0; k<newopt.optioni; k++) { if (newopt.option[k].option.recreateTagsIfModified) { if (! oldopt.contains(newopt.option[k])) break; } } if (k!=newopt.optioni) { int confirm = JOptionPane.showConfirmDialog( s.getProbableParent(this), "Options in project "+newopt.projectName + " changed. Recreate Tags?", "Xrefactory Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (confirm == JOptionPane.YES_OPTION) { recreateTagFile(newopt); } } } } } public static Options[] crOptionsArrayCopy(Options[] oo) { Options[] res; res = new Options[oo.length]; for(int i=0; i<oo.length; i++) res[i] = new Options(oo[i]); return(res); } class ConfigurationFileListener implements FocusListener { public void focusGained(FocusEvent e) {} public void focusLost(FocusEvent e) { //& createActiveProjectList(); } } void activeProjectListRefresh(ComboBoxModel model) { int n = model.getSize(); String[] projects = new String[n]; projects[0] = s.projectAutoDetectionName; for(int i=1; i<n; i++) projects[i] = (String)model.getElementAt(i); activeProject.setModel(new DefaultComboBoxModel(projects)); } public ProjectOptionsPanel(Options[] projects, String defaultp) { int y = -1; this.projects = projects; this.originalProjects = crOptionsArrayCopy(projects); configurationFile = new JTextField(s.configurationFile); activeProject = new JComboBox(Options.getProjectNames( projects, s.projectAutoDetectionName)); activeProject.setSelectedItem(Opt.activeProject()); projectsPanel = new JTabbedPane(); projectsPanel.add("Common options", new OptionsForProjectsPanel(projects[0], Options.OPT_COMMON, Opt.optionsEditingDisplaysFile)); for(int i=1; i<projects.length; i++) { projectsPanel.add(projects[i].projectName, new OptionsForProjectsPanel(projects[i], Options.OPT_PROJECT, Opt.optionsEditingDisplaysFile)); if (projects[i].projectName.equals(defaultp)) { projectsPanel.setSelectedIndex(i); } } setLayout(new GridBagLayout()); y++; s.addGbcComponent(this, 0, y, 1, 1, 10, 1, GridBagConstraints.HORIZONTAL, new JPanel()); s.addGbcComponent(this, 1, y, 1, 1, 10, 1, GridBagConstraints.HORIZONTAL, new JLabel("Store options in the file: ",SwingConstants.RIGHT)); s.addGbcComponent(this, 2, y, 1, 1, 1, 1, GridBagConstraints.HORIZONTAL, configurationFile); s.addGbcComponent(this, 2, y, 1, 1, 100, 1, GridBagConstraints.HORIZONTAL, new JPanel()); s.addGbcComponent(this, 4, y, 1, 1, 1, 1, GridBagConstraints.HORIZONTAL, new ButtonNewProject()); s.addGbcComponent(this, 5, y, 1, 1, 10, 1, GridBagConstraints.HORIZONTAL, new JPanel()); y++; s.addGbcComponent(this, 0, y, 1, 1, 10, 1, GridBagConstraints.HORIZONTAL, new JPanel()); s.addGbcComponent(this, 1, y, 1, 1, 10, 1, GridBagConstraints.HORIZONTAL, new JLabel("Active Project: ",SwingConstants.RIGHT)); s.addGbcComponent(this, 2, y, 1, 1, 1, 1, GridBagConstraints.HORIZONTAL, activeProject); s.addGbcComponent(this, 3, y, 1, 1, 100, 1, GridBagConstraints.HORIZONTAL, new JPanel()); s.addGbcComponent(this, 4, y, 1, 1, 1, 1, GridBagConstraints.HORIZONTAL, new ButtonDelProject()); s.addGbcComponent(this, 5, y, 1, 1, 10, 1, GridBagConstraints.HORIZONTAL, new JPanel()); y++; s.addGbcComponent(this, 0, y, 1, 1, 10, 1, GridBagConstraints.HORIZONTAL, new JPanel()); s.addGbcComponent(this, 1, y, 4, 1, 1000, 1000, GridBagConstraints.BOTH, projectsPanel); s.addGbcComponent(this, 5, y, 1, 1, 10, 1, GridBagConstraints.HORIZONTAL, new JPanel()); //&y++; //&opy = y; addOptionsPanel(); //&setSize(600,200); //&y++; //&s.addExtraButtonLine(this,0, y,6,1,1,1, buttons,true); } } public static class OptionsForProjectsSelfStandingPanel extends JPanel { ProjectOptionsPanel panel; class ButtonCancel extends JButton implements ActionListener { ButtonCancel() {super("Cancel"); addActionListener(this);} public void actionPerformed(ActionEvent e) { s.getProbableParent(this).setVisible(false); } } class ButtonSave extends JButton implements ActionListener { ButtonSave() {super("Save"); addActionListener(this);} public void actionPerformed(ActionEvent e) { panel.saveProjectSettings(); } } class ButtonClose extends JButton implements ActionListener { ButtonClose() {super("Continue"); addActionListener(this);} public void actionPerformed(ActionEvent e) { panel.saveProjectSettings(); s.getProbableParent(this).setVisible(false); } } OptionsForProjectsSelfStandingPanel(Options[] xrefrc, String defaultp, Component parent) { int y = -1; JButton[] buttons = new JButton[] { new ButtonCancel(), new ButtonSave(), new ButtonClose(), }; setLayout(new GridBagLayout()); panel = new ProjectOptionsPanel(xrefrc, defaultp); y++; s.addGbcComponent(this, 0, y, 1, 1, 10, 10, GridBagConstraints.HORIZONTAL, new JPanel()); y++; s.addGbcComponent(this, 0, y, 1, 1, 1000, 1000, GridBagConstraints.BOTH, panel); y++; s.addGbcComponent(this, 0, y, 1, 1, 10, 10, GridBagConstraints.HORIZONTAL, new JPanel()); y++; s.addExtraButtonLine(this, 0,y, 1,1, 1,1, buttons, true); } } void init(JFrame parent, boolean newProject) { try { OptionParser parser = new OptionParser(new File(s.configurationFile)); Options[] xrefrc = parser.parseFile(); //&Options.dump(xrefrc); String defaultProject = s.projectAutoDetectionName; if (! newProject) defaultProject = s.activeProject; OptionsForProjectsSelfStandingPanel op = new OptionsForProjectsSelfStandingPanel(xrefrc, defaultProject, parent); setContentPane(op); pack(); setSize(600,400); setLocationRelativeTo(parent); if (newProject) { boolean created = op.panel.addNewProject(parent); if (created) setVisible(true); } else { setVisible(true); } } catch(Exception e) { e.printStackTrace(System.err); } } public OptionsForProjectsDialog(JFrame parent) { super(parent); init(parent, false); } public OptionsForProjectsDialog(JFrame parent, boolean newProject) { super(parent); init(parent, newProject); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -